Logo ROOT  
Reference Guide
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
26
28
29////////////////////////////////////////////////////////////////////////////////
30/// Constructor.
31
33 TEvePointSet("Line", n_points, tv_type),
34 fRnrLine (kTRUE),
35 fRnrPoints (kFALSE),
36 fSmooth (fgDefaultSmooth)
37{
40}
41
42////////////////////////////////////////////////////////////////////////////////
43/// Constructor.
44
45TEveLine::TEveLine(const char* name, Int_t n_points, ETreeVarType_e tv_type) :
46 TEvePointSet(name, n_points, tv_type),
47 fRnrLine (kTRUE),
48 fRnrPoints (kFALSE),
49 fSmooth (fgDefaultSmooth)
50{
53}
54
55////////////////////////////////////////////////////////////////////////////////
56/// Returns list-tree icon for TEveLine.
57
59{
60 return fgListTreeIcons[8];
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Set marker color. Propagate to projected lines.
65
67{
68 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
69 while (pi != fProjectedList.end())
70 {
71 TEveLine* l = dynamic_cast<TEveLine*>(*pi);
72 if (l && fMarkerColor == l->GetMarkerColor())
73 {
74 l->SetMarkerColor(col);
75 l->StampObjProps();
76 }
77 ++pi;
78 }
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Set line-style of the line.
84/// The style is propagated to projecteds.
85
87{
88 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
89 while (pi != fProjectedList.end())
90 {
91 TEveLine* pt = dynamic_cast<TEveLine*>(*pi);
92 if (pt)
93 {
94 pt->SetLineStyle(lstyle);
95 pt->StampObjProps();
96 }
97 ++pi;
98 }
100}
101
102////////////////////////////////////////////////////////////////////////////////
103/// Set line-style of the line.
104/// The style is propagated to projecteds.
105
107{
108 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
109 while (pi != fProjectedList.end())
110 {
111 TEveLine* pt = dynamic_cast<TEveLine*>(*pi);
112 if (pt)
113 {
114 pt->SetLineWidth(lwidth);
115 pt->StampObjProps();
116 }
117 ++pi;
118 }
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Set rendering of line. Propagate to projected lines.
124
126{
127 fRnrLine = r;
128 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
129 while (pi != fProjectedList.end())
130 {
131 TEveLine* l = dynamic_cast<TEveLine*>(*pi);
132 if (l)
133 {
134 l->SetRnrLine(r);
135 l->ElementChanged();
136 }
137 ++pi;
138 }
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Set rendering of points. Propagate to projected lines.
143
145{
146 fRnrPoints = r;
147 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
148 while (pi != fProjectedList.end())
149 {
150 TEveLine* l = dynamic_cast<TEveLine*>(*pi);
151 if (l)
152 {
153 l->SetRnrPoints(r);
154 l->ElementChanged();
155 }
156 ++pi;
157 }
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Set smooth rendering. Propagate to projected lines.
162
164{
165 fSmooth = r;
166 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
167 while (pi != fProjectedList.end())
168 {
169 TEveLine* l = dynamic_cast<TEveLine*>(*pi);
170 if (l)
171 {
172 l->SetSmooth(r);
173 l->ElementChanged();
174 }
175 ++pi;
176 }
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Make sure that no segment is longer than max.
181/// Per point references and integer ids are lost.
182
184{
185 const Float_t max2 = max*max;
186
187 Float_t *p = GetP();
188 Int_t s = Size();
189 TEveVector a, b, d;
190
191 std::vector<TEveVector> q;
192
193 b.Set(p);
194 q.push_back(b);
195 for (Int_t i = 1; i < s; ++i)
196 {
197 a = b; b.Set(&p[3*i]); d = b - a;
198 Float_t m2 = d.Mag2();
199 if (m2 > max2)
200 {
201 Float_t f = TMath::Sqrt(m2) / max;
203 d *= 1.0f / (n + 1);
204 for (Int_t j = 0; j < n; ++j)
205 {
206 a += d;
207 q.push_back(a);
208 }
209 }
210 q.push_back(b);
211 }
212
213 s = q.size();
214 Reset(s);
215 for (std::vector<TEveVector>::iterator i = q.begin(); i != q.end(); ++i)
216 SetNextPoint(i->fX, i->fY, i->fZ);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Sum-up lengths of individual segments.
221
223{
224 Float_t sum = 0;
225
226 Int_t s = Size();
227 Float_t *p = GetP();
228 for (Int_t i = 1; i < s; ++i, p += 3)
229 {
230 sum += TMath::Sqrt(sqr(p[3] - p[0]) + sqr(p[4] - p[1]) + sqr(p[5] - p[2]));
231 }
232 return sum;
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// Return the first point of the line.
237/// If there are no points (0,0,0) is returned.
238
240{
242 GetPoint(0, v.fX, v.fY, v.fZ);
243 return v;
244}
245
246////////////////////////////////////////////////////////////////////////////////
247/// Return the last point of the line.
248/// If there are no points (0,0,0) is returned.
249
251{
253 GetPoint(fLastPoint, v.fX, v.fY, v.fZ);
254 return v;
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Copy visualization parameters from element el.
259
261{
262 const TEveLine* m = dynamic_cast<const TEveLine*>(el);
263 if (m)
264 {
266 fRnrLine = m->fRnrLine;
267 fRnrPoints = m->fRnrPoints;
268 fSmooth = m->fSmooth;
269 }
270
272}
273
274////////////////////////////////////////////////////////////////////////////////
275/// Write visualization parameters.
276
277void TEveLine::WriteVizParams(std::ostream& out, const TString& var)
278{
280
281 TString t = " " + var + "->";
283 out << t << "SetRnrLine(" << ToString(fRnrLine) << ");\n";
284 out << t << "SetRnrPoints(" << ToString(fRnrPoints) << ");\n";
285 out << t << "SetSmooth(" << ToString(fSmooth) << ");\n";
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Virtual from TEveProjectable, returns TEvePointSetProjected class.
290
292{
294}
295
296////////////////////////////////////////////////////////////////////////////////
297/// Get default value for smooth-line drawing flag.
298/// Static function.
299
301{
302 return fgDefaultSmooth;
303}
304
305////////////////////////////////////////////////////////////////////////////////
306/// Set default value for smooth-line drawing flag (default kFALSE).
307/// Static function.
308
310{
312}
313
314/** \class TEveLineProjected
315\ingroup TEve
316Projected copy of a TEveLine.
317*/
318
320
321////////////////////////////////////////////////////////////////////////////////
322/// Default constructor.
323
325 TEveLine (),
327{
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Set projection manager and projection model.
332/// Virtual from TEveProjected.
333
335 TEveProjectable* model)
336{
338 CopyVizParams(dynamic_cast<TEveElement*>(model));
339}
340
341////////////////////////////////////////////////////////////////////////////////
342/// Set depth (z-coordinate) of the projected points.
343
345{
346 SetDepthCommon(d, this, fBBox);
347
348 Int_t n = Size();
349 Float_t *p = GetP() + 2;
350 for (Int_t i = 0; i < n; ++i, p+=3)
351 *p = fDepth;
352}
353
354////////////////////////////////////////////////////////////////////////////////
355/// Re-apply the projection.
356/// Virtual from TEveProjected.
357
359{
361 TEveLine & als = * dynamic_cast<TEveLine*>(fProjectable);
362 TEveTrans *tr = als.PtrMainTrans(kFALSE);
363
364 Int_t n = als.Size();
365 Reset(n);
366 fLastPoint = n - 1;
367 Float_t *o = als.GetP(), *p = GetP();
368 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
369 {
370 proj.ProjectPointfv(tr, o, p, fDepth);
371 }
372}
void Class()
Definition: Class.C:29
ROOT::R::TRInterface & r
Definition: Object.C:4
#define d(i)
Definition: RSha256.hxx:102
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
const Bool_t kFALSE
Definition: RtypesCore.h:90
short Width_t
Definition: RtypesCore.h:80
bool Bool_t
Definition: RtypesCore.h:61
short Color_t
Definition: RtypesCore.h:81
short Style_t
Definition: RtypesCore.h:78
float Float_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
@ kGreen
Definition: Rtypes.h:64
char name[80]
Definition: TGX11.cxx:109
float * q
Definition: THbookFile.cxx:87
Binding & operator=(OUT(*fun)(void))
Float_t * fBBox
Definition: TAttBBox.h:20
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
Color_t fLineColor
Line color.
Definition: TAttLine.h:21
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:270
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
Color_t fMarkerColor
Marker color.
Definition: TAttMarker.h:22
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:34
virtual TEveTrans * PtrMainTrans(Bool_t create=kTRUE)
Return pointer to main transformation.
Color_t * fMainColorPtr
Definition: TEveElement.h:97
static const char * ToString(Bool_t b)
Convert Bool_t to string - kTRUE or kFALSE.
static const TGPicture * fgListTreeIcons[9]
Definition: TEveElement.h:63
Projected copy of a TEveLine.
Definition: TEveLine.h:85
virtual void UpdateProjection()
Re-apply the projection.
Definition: TEveLine.cxx:358
virtual void SetDepthLocal(Float_t d)
Set depth (z-coordinate) of the projected points.
Definition: TEveLine.cxx:344
virtual void SetProjection(TEveProjectionManager *mng, TEveProjectable *model)
Set projection manager and projection model.
Definition: TEveLine.cxx:334
TEveLineProjected()
Default constructor.
Definition: TEveLine.cxx:324
An arbitrary polyline with fixed line and marker attributes.
Definition: TEveLine.h:26
virtual void SetLineStyle(Style_t lstyle)
Set line-style of the line.
Definition: TEveLine.cxx:86
Float_t CalculateLineLength() const
Sum-up lengths of individual segments.
Definition: TEveLine.cxx:222
Bool_t fSmooth
Definition: TEveLine.h:37
virtual void SetLineWidth(Width_t lwidth)
Set line-style of the line.
Definition: TEveLine.cxx:106
void ReduceSegmentLengths(Float_t max)
Make sure that no segment is longer than max.
Definition: TEveLine.cxx:183
static void SetDefaultSmooth(Bool_t r)
Set default value for smooth-line drawing flag (default kFALSE).
Definition: TEveLine.cxx:309
static Bool_t fgDefaultSmooth
Definition: TEveLine.h:39
TEveVector GetLineStart() const
Return the first point of the line.
Definition: TEveLine.cxx:239
virtual TClass * ProjectedClass(const TEveProjection *p) const
Virtual from TEveProjectable, returns TEvePointSetProjected class.
Definition: TEveLine.cxx:291
virtual const TGPicture * GetListTreeIcon(Bool_t open=kFALSE)
Returns list-tree icon for TEveLine.
Definition: TEveLine.cxx:58
Bool_t fRnrLine
Definition: TEveLine.h:35
void SetRnrLine(Bool_t r)
Set rendering of line. Propagate to projected lines.
Definition: TEveLine.cxx:125
TEveLine(const TEveLine &)
virtual void CopyVizParams(const TEveElement *el)
Copy visualization parameters from element el.
Definition: TEveLine.cxx:260
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write visualization parameters.
Definition: TEveLine.cxx:277
Bool_t fRnrPoints
Definition: TEveLine.h:36
void SetSmooth(Bool_t r)
Set smooth rendering. Propagate to projected lines.
Definition: TEveLine.cxx:163
void SetRnrPoints(Bool_t r)
Set rendering of points. Propagate to projected lines.
Definition: TEveLine.cxx:144
static Bool_t GetDefaultSmooth()
Get default value for smooth-line drawing flag.
Definition: TEveLine.cxx:300
virtual void SetMarkerColor(Color_t col)
Set marker color. Propagate to projected lines.
Definition: TEveLine.cxx:66
TEveVector GetLineEnd() const
Return the last point of the line.
Definition: TEveLine.cxx:250
TEvePointSet is a render-element holding a collection of 3D points with optional per-point TRef and a...
Definition: TEvePointSet.h:36
virtual void CopyVizParams(const TEveElement *el)
Copy visualization parameters from element el.
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write visualization parameters.
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.
Abstract base-class for non-linear projectable objects.
ProjList_t fProjectedList
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.
void ProjectPointfv(Float_t *v, Float_t d)
Project float array.
TEveTrans is a 4x4 transformation matrix for homogeneous coordinates stored internally in a column-ma...
Definition: TEveTrans.h:27
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
Definition: TPolyMarker3D.h:73
virtual Float_t * GetP() const
Definition: TPolyMarker3D.h:59
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:131
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)
static constexpr double s
static constexpr double pi
static constexpr double m2
Int_t FloorNint(Double_t x)
Definition: TMath.h:697
Double_t Sqrt(Double_t x)
Definition: TMath.h:681
auto * m
Definition: textangle.C:8
auto * l
Definition: textangle.C:4
auto * a
Definition: textangle.C:12
static long int sum(long int i)
Definition: Factory.cxx:2275