Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveLine.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007, 2018
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <ROOT/REveLine.hxx>
15#include <ROOT/REveTrans.hxx>
16
17#include "TClass.h"
18
19#include <nlohmann/json.hpp>
20
21using namespace ROOT::Experimental;
22
23/** \class REveLine
24\ingroup REve
25An arbitrary polyline with fixed line and marker attributes.
26
27The render data is one entry, `pos`, f32 x 3: the fSize points, primitive
28line strip. The client draws the segments between consecutive points; a
29projected track gives `pos` one range per piece, see REveTrackProjected.
30*/
31
32Bool_t REveLine::fgDefaultSmooth = kFALSE;
33
34
35////////////////////////////////////////////////////////////////////////////////
36/// Constructor.
37
38REveLine::REveLine(const std::string &name, const std::string &title, Int_t n_points) :
39 REvePointSet(name, title, n_points),
40 fRnrLine (kTRUE),
41 fRnrPoints (kFALSE),
42 fSmooth (fgDefaultSmooth)
43{
46}
47
48////////////////////////////////////////////////////////////////////////////////
49/// Copy constructor.
50
53 TAttLine (l),
54 fRnrLine (l.fRnrLine),
55 fRnrPoints (l.fRnrPoints),
56 fSmooth (l.fSmooth)
57{
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// Set marker color. Propagate to projected lines.
62
64{
65 for (auto &pi: fProjectedList)
66 {
67 REveLine* l = dynamic_cast<REveLine*>(pi);
68 if (l && fMarkerColor == l->GetMarkerColor())
69 {
70 l->SetMarkerColor(col);
71 l->StampObjProps();
72 }
73 }
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Set line-style of the line.
79/// The style is propagated to projecteds.
80
82{
83 for (auto &pi: fProjectedList)
84 {
85 REveLine* pt = dynamic_cast<REveLine*>(pi);
86 if (pt)
87 {
88 pt->SetLineStyle(lstyle);
89 pt->StampObjProps();
90 }
91 }
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Set line-style of the line.
97/// The style is propagated to projecteds.
98
100{
101 for (auto &pi: fProjectedList)
102 {
103 REveLine* pt = dynamic_cast<REveLine*>(pi);
104 if (pt)
105 {
106 pt->SetLineWidth(lwidth);
107 pt->StampObjProps();
108 }
109 }
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Set rendering of line. Propagate to projected lines.
116
118{
119 fRnrLine = r;
120 for (auto &pi: fProjectedList)
121 {
122 REveLine* l = dynamic_cast<REveLine*>(pi);
123 if (l)
124 {
125 l->SetRnrLine(r);
126 l->StampObjProps();
127 }
128 }
130}
131
132////////////////////////////////////////////////////////////////////////////////
133/// Set rendering of points. Propagate to projected lines.
134
136{
137 fRnrPoints = r;
138 for (auto &pi: fProjectedList)
139 {
140 REveLine *l = dynamic_cast<REveLine*>(pi);
141 if (l)
142 {
143 l->SetRnrPoints(r);
144 l->StampObjProps();
145 }
146 }
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Set smooth rendering. Propagate to projected lines.
152
154{
155 fSmooth = r;
156 for (auto &pi: fProjectedList)
157 {
158 REveLine* l = dynamic_cast<REveLine*>(pi);
159 if (l)
160 {
161 l->SetSmooth(r);
162 l->StampObjProps();
163 }
164 }
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Make sure that no segment is longer than max.
170/// Per point references and integer ids are lost.
171
173{
174 // XXXX rewrite
175
176 const Float_t max2 = max*max;
177
178 Float_t *p = & fPoints[0].fX;
179 Int_t s = fSize;
180 REveVector a, b, d;
181
182 std::vector<REveVector> q;
183
184 b.Set(p);
185 q.push_back(b);
186 for (Int_t i = 1; i < s; ++i)
187 {
188 a = b; b.Set(&p[3*i]); d = b - a;
189 Float_t m2 = d.Mag2();
190 if (m2 > max2)
191 {
192 Float_t f = TMath::Sqrt(m2) / max;
194 d *= 1.0f / (n + 1);
195 for (Int_t j = 0; j < n; ++j)
196 {
197 a += d;
198 q.push_back(a);
199 }
200 }
201 q.push_back(b);
202 }
203
204 s = q.size();
205 Reset(s);
206 for (auto &i: q)
207 SetNextPoint(i.fX, i.fY, i.fZ);
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Sum-up lengths of individual segments.
212
214{
215 Float_t sum = 0;
216
217 for (Int_t i = 1; i < fSize; ++i)
218 {
219 sum += fPoints[i - 1].Distance(fPoints[i]);
220 }
221
222 return sum;
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Return the first point of the line.
227/// If there are no points (0,0,0) is returned.
228
230{
232 if (fSize > 0) v = RefPoint(0);
233 return v;
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Return the last point of the line.
238/// If there are no points (0,0,0) is returned.
239
241{
243 if (fSize > 0) v = RefPoint(fSize - 1);
244 return v;
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Copy visualization parameters from element el.
249
251{
252 const REveLine* m = dynamic_cast<const REveLine*>(el);
253 if (m)
254 {
255 TAttLine::operator=(*m);
256 fRnrLine = m->fRnrLine;
257 fRnrPoints = m->fRnrPoints;
258 fSmooth = m->fSmooth;
259 }
260
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// Write visualization parameters.
266
267void REveLine::WriteVizParams(std::ostream& out, const TString& var)
268{
270
271 TString t = " " + var + "->";
273 out << t << "SetRnrLine(" << ToString(fRnrLine) << ");\n";
274 out << t << "SetRnrPoints(" << ToString(fRnrPoints) << ");\n";
275 out << t << "SetSmooth(" << ToString(fSmooth) << ");\n";
276}
277
278////////////////////////////////////////////////////////////////////////////////
279/// Virtual from REveProjectable, returns REvePointSetProjected class.
280
282{
283 return TClass::GetClass<REveLineProjected>();
284}
285
286//------------------------------------------------------------------------------
287
288Int_t REveLine::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
289{
290 Int_t ret = REvePointSet::WriteCoreJson(j, rnr_offset);
291
292 j["fLineWidth"] = GetLineWidth();
293 j["fLineStyle"] = GetLineStyle();
294 j["fLineColor"] = GetLineColor();
295
296 return ret;
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Write the render data entry `pos`, see the class description. A line
301/// without points has no render data.
302
304{
305 if (fSize <= 0)
306 return;
307
308 using RD = REveRenderData;
309 fRenderData = std::make_unique<RD>("makeTrack");
310 fRenderData->NewEntry("pos", RD::EType::kF32, 3)
311 .Role(RD::ERole::kVertex)
312 .Prim(RD::EPrim::kLineStrip)
313 .Push(&fPoints[0].fX, 3 * fSize);
314}
315
316////////////////////////////////////////////////////////////////////////////////
317/// Get default value for smooth-line drawing flag.
318/// Static function.
319
324
325////////////////////////////////////////////////////////////////////////////////
326/// Set default value for smooth-line drawing flag (default kFALSE).
327/// Static function.
328
333
334/** \class REveLineProjected
335\ingroup REve
336Projected copy of a REveLine.
337*/
338
339
340////////////////////////////////////////////////////////////////////////////////
341/// Default constructor.
342
348
349////////////////////////////////////////////////////////////////////////////////
350/// Set projection manager and projection model.
351/// Virtual from REveProjected.
352
354 REveProjectable* model)
355{
357 CopyVizParams(dynamic_cast<REveElement*>(model));
358}
359
360////////////////////////////////////////////////////////////////////////////////
361/// Set depth (z-coordinate) of the projected points.
362
364{
365 SetDepthCommon(d, this);
366
367 for (Int_t i = 0; i < fSize; ++i)
368 fPoints[i].fZ = fDepth;
369}
370
371////////////////////////////////////////////////////////////////////////////////
372/// Re-apply the projection.
373/// Virtual from REveProjected.
374
376{
378 REveLine & als = * dynamic_cast<REveLine*>(fProjectable);
379 REveTrans mt;
380 const REveTrans *tr = fManager->GetModelTrans(&als, mt);
381
382 Int_t n = als.GetSize();
383 Reset(n);
384 fSize = n;
385 const Float_t *o = & als.RefPoint(0).fX;
386 Float_t *p = & fPoints[0].fX;
387 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
388 {
389 proj.ProjectPointfv(tr, o, p, fDepth);
390 }
391}
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
short Style_t
Style number (short)
Definition RtypesCore.h:97
short Color_t
Color number (short)
Definition RtypesCore.h:100
short Width_t
Line width (short)
Definition RtypesCore.h:99
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
@ kGreen
Definition Rtypes.h:66
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
char name[80]
Definition TGX11.cxx:142
float * q
std::unique_ptr< REveRenderData > fRenderData
! Render data entries for the client's maker, see REveRenderData.
static const std::string & ToString(Bool_t b)
Convert Bool_t to string - kTRUE or kFALSE.
REveLineProjected()
Default constructor.
Definition REveLine.cxx:343
void SetDepthLocal(Float_t d) override
Set depth (z-coordinate) of the projected points.
Definition REveLine.cxx:363
void SetProjection(REveProjectionManager *mng, REveProjectable *model) override
Set projection manager and projection model.
Definition REveLine.cxx:353
void UpdateProjection() override
Re-apply the projection.
Definition REveLine.cxx:375
REveLine An arbitrary polyline with fixed line and marker attributes.
Definition REveLine.hxx:30
REveVector GetLineEnd() const
Return the last point of the line.
Definition REveLine.cxx:240
void ReduceSegmentLengths(Float_t max)
Make sure that no segment is longer than max.
Definition REveLine.cxx:172
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
Definition REveLine.cxx:250
void SetSmooth(Bool_t r)
Set smooth rendering. Propagate to projected lines.
Definition REveLine.cxx:153
void SetMarkerColor(Color_t col) override
Set marker color. Propagate to projected lines.
Definition REveLine.cxx:63
void WriteVizParams(std::ostream &out, const TString &var) override
Write visualization parameters.
Definition REveLine.cxx:267
REveVector GetLineStart() const
Return the first point of the line.
Definition REveLine.cxx:229
REveLine(const std::string &name="", const std::string &title="", Int_t n_points=0)
Constructor.
Definition REveLine.cxx:38
void SetLineWidth(Width_t lwidth) override
Set line-style of the line.
Definition REveLine.cxx:99
static Bool_t GetDefaultSmooth()
Get default value for smooth-line drawing flag.
Definition REveLine.cxx:320
static void SetDefaultSmooth(Bool_t r)
Set default value for smooth-line drawing flag (default kFALSE).
Definition REveLine.cxx:329
static Bool_t fgDefaultSmooth
Definition REveLine.hxx:39
void SetLineStyle(Style_t lstyle) override
Set line-style of the line.
Definition REveLine.cxx:81
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override
Write core json.
Definition REveLine.cxx:288
void SetRnrLine(Bool_t r)
Set rendering of line. Propagate to projected lines.
Definition REveLine.cxx:117
Float_t CalculateLineLength() const
Sum-up lengths of individual segments.
Definition REveLine.cxx:213
void SetRnrPoints(Bool_t r)
Set rendering of points. Propagate to projected lines.
Definition REveLine.cxx:135
TClass * ProjectedClass(const REveProjection *p) const override
Virtual from REveProjectable, returns REvePointSetProjected class.
Definition REveLine.cxx:281
void BuildRenderData() override
Write the render data entry pos, see the class description.
Definition REveLine.cxx:303
void WriteVizParams(std::ostream &out, const TString &var) override
Write visualization parameters.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
std::vector< REveVector > fPoints
int SetNextPoint(float x, float y, float z)
void Reset(Int_t n_points=0)
Drop all data and set-up the data structures to recive new data.
virtual void SetProjection(REveProjectionManager *mng, REveProjectable *model)
Sets projection manager and reference in the projectable object.
void SetDepthCommon(Float_t d, REveElement *el)
Set the depth and stamp el for a rebuild.
REveProjectionManager Manager class for steering of projections and managing projected objects.
const REveTrans * GetModelTrans(REveElement *model, REveTrans &t)
Return the matrix that takes the coordinates of model into the frame of this manager,...
REveProjection Base for specific classes that implement non-linear projections.
void ProjectPointfv(Float_t *v, Float_t d)
Project float array.
Render data of an element: a client maker name and a list of tagged entries, each a typed array with ...
Line Attributes class.
Definition TAttLine.h:21
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:46
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:37
Color_t fLineColor
Line color.
Definition TAttLine.h:24
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:289
Color_t fMarkerColor
Marker color.
Definition TAttMarker.h:25
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
Basic string class.
Definition TString.h:137
TPaveText * pt
const Int_t n
Definition legend1.C:16
Namespace for ROOT features in testing.
Definition TROOT.h:100
Int_t FloorNint(Double_t x)
Returns the nearest integer of TMath::Floor(x).
Definition TMath.h:699
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:675
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2335