Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveLine.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, 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 "TEveLine.h"
14
15namespace
16{
17 inline Float_t sqr(Float_t x) { return x*x; }
18}
19
20/** \class TEveLine
21\ingroup TEve
22An arbitrary polyline with fixed line and marker attributes.
23*/
24
25
27
28////////////////////////////////////////////////////////////////////////////////
29/// Constructor.
30
33 fRnrLine (kTRUE),
34 fRnrPoints (kFALSE),
35 fSmooth (fgDefaultSmooth)
36{
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// Constructor.
43
46 fRnrLine (kTRUE),
47 fRnrPoints (kFALSE),
48 fSmooth (fgDefaultSmooth)
49{
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// Returns list-tree icon for TEveLine.
56
61
62////////////////////////////////////////////////////////////////////////////////
63/// Set marker color. Propagate to projected lines.
64
66{
67 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
68 while (pi != fProjectedList.end())
69 {
70 TEveLine* l = dynamic_cast<TEveLine*>(*pi);
71 if (l && fMarkerColor == l->GetMarkerColor())
72 {
73 l->SetMarkerColor(col);
74 l->StampObjProps();
75 }
76 ++pi;
77 }
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Set line-style of the line.
83/// The style is propagated to projecteds.
84
86{
87 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
88 while (pi != fProjectedList.end())
89 {
90 TEveLine* pt = dynamic_cast<TEveLine*>(*pi);
91 if (pt)
92 {
94 pt->StampObjProps();
95 }
96 ++pi;
97 }
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Set line-style of the line.
103/// The style is propagated to projecteds.
104
106{
107 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
108 while (pi != fProjectedList.end())
109 {
110 TEveLine* pt = dynamic_cast<TEveLine*>(*pi);
111 if (pt)
112 {
114 pt->StampObjProps();
115 }
116 ++pi;
117 }
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Set rendering of line. Propagate to projected lines.
123
125{
126 fRnrLine = r;
127 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
128 while (pi != fProjectedList.end())
129 {
130 TEveLine* l = dynamic_cast<TEveLine*>(*pi);
131 if (l)
132 {
133 l->SetRnrLine(r);
134 l->ElementChanged();
135 }
136 ++pi;
137 }
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Set rendering of points. Propagate to projected lines.
142
144{
145 fRnrPoints = r;
146 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
147 while (pi != fProjectedList.end())
148 {
149 TEveLine* l = dynamic_cast<TEveLine*>(*pi);
150 if (l)
151 {
152 l->SetRnrPoints(r);
153 l->ElementChanged();
154 }
155 ++pi;
156 }
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// Set smooth rendering. Propagate to projected lines.
161
163{
164 fSmooth = r;
165 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
166 while (pi != fProjectedList.end())
167 {
168 TEveLine* l = dynamic_cast<TEveLine*>(*pi);
169 if (l)
170 {
171 l->SetSmooth(r);
172 l->ElementChanged();
173 }
174 ++pi;
175 }
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Make sure that no segment is longer than max.
180/// Per point references and integer ids are lost.
181
183{
184 const Float_t max2 = max*max;
185
186 Float_t *p = GetP();
187 Int_t s = Size();
188 TEveVector a, b, d;
189
190 std::vector<TEveVector> q;
191
192 b.Set(p);
193 q.push_back(b);
194 for (Int_t i = 1; i < s; ++i)
195 {
196 a = b; b.Set(&p[3*i]); d = b - a;
197 Float_t m2 = d.Mag2();
198 if (m2 > max2)
199 {
200 Float_t f = TMath::Sqrt(m2) / max;
202 d *= 1.0f / (n + 1);
203 for (Int_t j = 0; j < n; ++j)
204 {
205 a += d;
206 q.push_back(a);
207 }
208 }
209 q.push_back(b);
210 }
211
212 s = q.size();
213 Reset(s);
214 for (std::vector<TEveVector>::iterator i = q.begin(); i != q.end(); ++i)
215 SetNextPoint(i->fX, i->fY, i->fZ);
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// Sum-up lengths of individual segments.
220
222{
223 Float_t sum = 0;
224
225 Int_t s = Size();
226 Float_t *p = GetP();
227 for (Int_t i = 1; i < s; ++i, p += 3)
228 {
229 sum += TMath::Sqrt(sqr(p[3] - p[0]) + sqr(p[4] - p[1]) + sqr(p[5] - p[2]));
230 }
231 return sum;
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// Return the first point of the line.
236/// If there are no points (0,0,0) is returned.
237
239{
241 GetPoint(0, v.fX, v.fY, v.fZ);
242 return v;
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Return the last point of the line.
247/// If there are no points (0,0,0) is returned.
248
250{
252 GetPoint(fLastPoint, v.fX, v.fY, v.fZ);
253 return v;
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// Copy visualization parameters from element el.
258
260{
261 const TEveLine* m = dynamic_cast<const TEveLine*>(el);
262 if (m)
263 {
264 TAttLine::operator=(*m);
265 fRnrLine = m->fRnrLine;
266 fRnrPoints = m->fRnrPoints;
267 fSmooth = m->fSmooth;
268 }
269
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Write visualization parameters.
275
276void TEveLine::WriteVizParams(std::ostream& out, const TString& var)
277{
279
280 TString t = " " + var + "->";
282 out << t << "SetRnrLine(" << ToString(fRnrLine) << ");\n";
283 out << t << "SetRnrPoints(" << ToString(fRnrPoints) << ");\n";
284 out << t << "SetSmooth(" << ToString(fSmooth) << ");\n";
285}
286
287////////////////////////////////////////////////////////////////////////////////
288/// Virtual from TEveProjectable, returns TEvePointSetProjected class.
289
294
295////////////////////////////////////////////////////////////////////////////////
296/// Get default value for smooth-line drawing flag.
297/// Static function.
298
303
304////////////////////////////////////////////////////////////////////////////////
305/// Set default value for smooth-line drawing flag (default kFALSE).
306/// Static function.
307
312
313/** \class TEveLineProjected
314\ingroup TEve
315Projected copy of a TEveLine.
316*/
317
318
319////////////////////////////////////////////////////////////////////////////////
320/// Default constructor.
321
327
328////////////////////////////////////////////////////////////////////////////////
329/// Set projection manager and projection model.
330/// Virtual from TEveProjected.
331
338
339////////////////////////////////////////////////////////////////////////////////
340/// Set depth (z-coordinate) of the projected points.
341
343{
344 SetDepthCommon(d, this, fBBox);
345
346 Int_t n = Size();
347 Float_t *p = GetP() + 2;
348 for (Int_t i = 0; i < n; ++i, p+=3)
349 *p = fDepth;
350}
351
352////////////////////////////////////////////////////////////////////////////////
353/// Re-apply the projection.
354/// Virtual from TEveProjected.
355
357{
359 TEveLine & als = * dynamic_cast<TEveLine*>(fProjectable);
360 TEveTrans *tr = als.PtrMainTrans(kFALSE);
361
362 Int_t n = als.Size();
363 Reset(n);
364 fLastPoint = n - 1;
365 Float_t *o = als.GetP(), *p = GetP();
366 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
367 {
368 proj.ProjectPointfv(tr, o, p, fDepth);
369 }
370}
#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:96
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
short Color_t
Color number (short)
Definition RtypesCore.h:99
short Width_t
Line width (short)
Definition RtypesCore.h:98
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kGreen
Definition Rtypes.h:67
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:110
float * q
Float_t * fBBox
Definition TAttBBox.h:20
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:44
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:45
Color_t fLineColor
Line color.
Definition TAttLine.h:23
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:274
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:39
Color_t fMarkerColor
Marker color.
Definition TAttMarker.h:23
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
Color_t * fMainColorPtr
Definition TEveElement.h:99
static const char * ToString(Bool_t b)
Convert Bool_t to string - kTRUE or kFALSE.
static const TGPicture * fgListTreeIcons[9]
Definition TEveElement.h:54
void UpdateProjection() override
Re-apply the projection.
Definition TEveLine.cxx:356
static TClass * Class()
TEveLineProjected()
Default constructor.
Definition TEveLine.cxx:322
void SetDepthLocal(Float_t d) override
Set depth (z-coordinate) of the projected points.
Definition TEveLine.cxx:342
void SetProjection(TEveProjectionManager *mng, TEveProjectable *model) override
Set projection manager and projection model.
Definition TEveLine.cxx:332
An arbitrary polyline with fixed line and marker attributes.
Definition TEveLine.h:26
Float_t CalculateLineLength() const
Sum-up lengths of individual segments.
Definition TEveLine.cxx:221
Bool_t fSmooth
Definition TEveLine.h:37
void ReduceSegmentLengths(Float_t max)
Make sure that no segment is longer than max.
Definition TEveLine.cxx:182
void SetLineStyle(Style_t lstyle) override
Set line-style of the line.
Definition TEveLine.cxx:85
static void SetDefaultSmooth(Bool_t r)
Set default value for smooth-line drawing flag (default kFALSE).
Definition TEveLine.cxx:308
static Bool_t fgDefaultSmooth
Definition TEveLine.h:39
void SetLineWidth(Width_t lwidth) override
Set line-style of the line.
Definition TEveLine.cxx:105
TEveVector GetLineStart() const
Return the first point of the line.
Definition TEveLine.cxx:238
TClass * ProjectedClass(const TEveProjection *p) const override
Virtual from TEveProjectable, returns TEvePointSetProjected class.
Definition TEveLine.cxx:290
Bool_t fRnrLine
Definition TEveLine.h:35
void SetRnrLine(Bool_t r)
Set rendering of line. Propagate to projected lines.
Definition TEveLine.cxx:124
TEveLine(const TEveLine &)
void WriteVizParams(std::ostream &out, const TString &var) override
Write visualization parameters.
Definition TEveLine.cxx:276
const TGPicture * GetListTreeIcon(Bool_t open=kFALSE) override
Returns list-tree icon for TEveLine.
Definition TEveLine.cxx:57
void CopyVizParams(const TEveElement *el) override
Copy visualization parameters from element el.
Definition TEveLine.cxx:259
void SetMarkerColor(Color_t col) override
Set marker color. Propagate to projected lines.
Definition TEveLine.cxx:65
Bool_t fRnrPoints
Definition TEveLine.h:36
void SetSmooth(Bool_t r)
Set smooth rendering. Propagate to projected lines.
Definition TEveLine.cxx:162
void SetRnrPoints(Bool_t r)
Set rendering of points. Propagate to projected lines.
Definition TEveLine.cxx:143
static Bool_t GetDefaultSmooth()
Get default value for smooth-line drawing flag.
Definition TEveLine.cxx:299
TEveVector GetLineEnd() const
Return the last point of the line.
Definition TEveLine.cxx:249
TEvePointSet is a render-element holding a collection of 3D points with optional per-point TRef and a...
void CopyVizParams(const TEveElement *el) override
Copy visualization parameters from element el.
void Reset(Int_t n_points=0, Int_t n_int_ids=0)
Drop all data and set-up the data structures to recive new data.
void WriteVizParams(std::ostream &out, const TString &var) override
Write visualization parameters.
Abstract base-class for non-linear projectable objects.
Abstract base class for classes that hold results of a non-linear projection transformation.
TEveProjectable * fProjectable
TEveProjectionManager * fManager
virtual void SetProjection(TEveProjectionManager *mng, TEveProjectable *model)
Sets projection manager and reference in the projectable object.
void SetDepthCommon(Float_t d, TEveElement *el, Float_t *bbox)
Utility function to update the z-values of the bounding-box.
Manager class for steering of projections and managing projected objects.
TEveProjection * GetProjection()
Base-class for non-linear projections.
TEveTrans is a 4x4 transformation matrix for homogeneous coordinates stored internally in a column-ma...
Definition TEveTrans.h:27
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
virtual void GetPoint(Int_t n, Float_t &x, Float_t &y, Float_t &z) const
Fills the parameters x, y, z with the coordinate of the n-th point n must be between 0 and Size() - 1...
virtual Int_t Size() const
virtual Float_t * GetP() const
virtual Int_t SetNextPoint(Double_t x, Double_t y, Double_t z)
Set point following LastPoint to x, y, z.
Basic string class.
Definition TString.h:138
TPaveText * pt
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
VecExpr< UnaryOp< Sqr< T >, VecExpr< A, T, D >, T >, T, D > sqr(const VecExpr< A, T, D > &rhs)
Int_t FloorNint(Double_t x)
Returns the nearest integer of TMath::Floor(x).
Definition TMath.h:697
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2339