Logo ROOT   6.14/05
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"
13 #include "TEveProjectionManager.h"
14 
15 namespace
16 {
17  inline Float_t sqr(Float_t x) { return x*x; }
18 }
19 
20 /** \class TEveLine
21 \ingroup TEve
22 An 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 
45 TEveLine::TEveLine(const char* name, Int_t n_points, ETreeVarType_e tv_type) :
46  TEvePointSet(name, n_points, tv_type),
47  fRnrLine (kTRUE),
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  }
99  TAttLine::SetLineStyle(lstyle);
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  }
119  TAttLine::SetLineWidth(lwidth);
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;
202  Int_t n = TMath::FloorNint(f);
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 {
241  TEveVector v;
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 {
252  TEveVector v;
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 
277 void 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 {
293  return TEveLineProjected::Class();
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 {
311  fgDefaultSmooth = r;
312 }
313 
314 /** \class TEveLineProjected
315 \ingroup TEve
316 Projected copy of a TEveLine.
317 */
318 
320 
321 ////////////////////////////////////////////////////////////////////////////////
322 /// Default constructor.
323 
325  TEveLine (),
326  TEveProjected ()
327 {
328 }
329 
330 ////////////////////////////////////////////////////////////////////////////////
331 /// Set projection manager and projection model.
332 /// Virtual from TEveProjected.
333 
336 {
337  TEveProjected::SetProjection(mng, model);
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 }
static Bool_t GetDefaultSmooth()
Get default value for smooth-line drawing flag.
Definition: TEveLine.cxx:300
TEveTrans is a 4x4 transformation matrix for homogeneous coordinates stored internally in a column-ma...
Definition: TEveTrans.h:26
Abstract base class for classes that hold results of a non-linear projection transformation.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
static long int sum(long int i)
Definition: Factory.cxx:2258
static constexpr double pi
auto * m
Definition: textangle.C:8
short Style_t
Definition: RtypesCore.h:76
void Set(const Float_t *v)
Definition: TEveVector.h:78
float Float_t
Definition: RtypesCore.h:53
void SetRnrPoints(Bool_t r)
Set rendering of points. Propagate to projected lines.
Definition: TEveLine.cxx:144
An arbitrary polyline with fixed line and marker attributes.
Definition: TEveLine.h:24
virtual void CopyVizParams(const TEveElement *el)
Copy visualization parameters from element el.
Definition: TEveLine.cxx:260
static const TGPicture * fgListTreeIcons[9]
Definition: TEveElement.h:63
Basic string class.
Definition: TString.h:131
virtual void SetDepthLocal(Float_t d)
Set depth (z-coordinate) of the projected points.
Definition: TEveLine.cxx:344
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void SetProjection(TEveProjectionManager *mng, TEveProjectable *model)
Sets projection manager and reference in the projectable object.
Definition: Rtypes.h:59
Int_t FloorNint(Double_t x)
Definition: TMath.h:706
static const char * ToString(Bool_t b)
Convert Bool_t to string - kTRUE or kFALSE.
virtual void SetLineStyle(Style_t lstyle)
Set line-style of the line.
Definition: TEveLine.cxx:86
Float_t * fBBox
Definition: TAttBBox.h:20
Color_t * fMainColorPtr
Definition: TEveElement.h:97
Double_t x[n]
Definition: legend1.C:17
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write visualization parameters.
Definition: TEveLine.cxx:277
virtual void ElementChanged(Bool_t update_scenes=kTRUE, Bool_t redraw=kFALSE)
Call this after an element has been changed so that the state can be propagated around the framework...
void Class()
Definition: Class.C:29
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:262
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
Base-class for non-linear projections.
Bool_t fSmooth
Definition: TEveLine.h:37
virtual void SetProjection(TEveProjectionManager *mng, TEveProjectable *model)
Set projection manager and projection model.
Definition: TEveLine.cxx:334
Manager class for steering of projections and managing projected objects.
short Color_t
Definition: RtypesCore.h:79
Projected copy of a TEveLine.
Definition: TEveLine.h:83
virtual void CopyVizParams(const TEveElement *el)
Copy visualization parameters from element el.
Abstract base-class for non-linear projectable objects.
TEveLine(const TEveLine &)
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...
TPaveText * pt
ROOT::R::TRInterface & r
Definition: Object.C:4
Bool_t fRnrLine
Definition: TEveLine.h:35
SVector< double, 2 > v
Definition: Dict.h:5
auto * a
Definition: textangle.C:12
virtual void SetLineWidth(Width_t lwidth)
Set line-style of the line.
Definition: TEveLine.cxx:106
TEveProjectable * fProjectable
Color_t fLineColor
Line color.
Definition: TAttLine.h:21
virtual const TGPicture * GetListTreeIcon(Bool_t open=kFALSE)
Returns list-tree icon for TEveLine.
Definition: TEveLine.cxx:58
TEveProjectionManager * fManager
void StampObjProps()
Definition: TEveElement.h:397
Bool_t fRnrPoints
Definition: TEveLine.h:36
TEvePointSet is a render-element holding a collection of 3D points with optional per-point TRef and a...
Definition: TEvePointSet.h:31
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
static constexpr double m2
void ReduceSegmentLengths(Float_t max)
Make sure that no segment is longer than max.
Definition: TEveLine.cxx:183
virtual void SetMarkerColor(Color_t col)
Set marker color. Propagate to projected lines.
Definition: TEveLine.cxx:66
short Width_t
Definition: RtypesCore.h:78
void ProjectPointfv(Float_t *v, Float_t d)
Project float array.
const Bool_t kFALSE
Definition: RtypesCore.h:88
void SetRnrLine(Bool_t r)
Set rendering of line. Propagate to projected lines.
Definition: TEveLine.cxx:125
TEveProjection * GetProjection()
virtual Int_t SetNextPoint(Double_t x, Double_t y, Double_t z)
Set point following LastPoint to x, y, z.
TEveVector GetLineStart() const
Return the first point of the line.
Definition: TEveLine.cxx:239
#define d(i)
Definition: RSha256.hxx:102
#define ClassImp(name)
Definition: Rtypes.h:359
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write visualization parameters.
static constexpr double s
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
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.
TEveLineProjected()
Default constructor.
Definition: TEveLine.cxx:324
Binding & operator=(OUT(*fun)(void))
static void SetDefaultSmooth(Bool_t r)
Set default value for smooth-line drawing flag (default kFALSE).
Definition: TEveLine.cxx:309
ProjList_t fProjectedList
TEveVector GetLineEnd() const
Return the last point of the line.
Definition: TEveLine.cxx:250
virtual TClass * ProjectedClass(const TEveProjection *p) const
Virtual from TEveProjectable, returns TEvePointSetProjected class.
Definition: TEveLine.cxx:291
void SetDepthCommon(Float_t d, TEveElement *el, Float_t *bbox)
Utility function to update the z-values of the bounding-box.
auto * l
Definition: textangle.C:4
virtual Float_t * GetP() const
Definition: TPolyMarker3D.h:59
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Float_t CalculateLineLength() const
Sum-up lengths of individual segments.
Definition: TEveLine.cxx:222
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition: TAttMarker.h:31
virtual TEveTrans * PtrMainTrans(Bool_t create=kTRUE)
Return pointer to main transformation.
Double_t Sqrt(Double_t x)
Definition: TMath.h:690
static Bool_t fgDefaultSmooth
Definition: TEveLine.h:39
float * q
Definition: THbookFile.cxx:87
Color_t fMarkerColor
Marker color.
Definition: TAttMarker.h:22
VecExpr< UnaryOp< Sqr< T >, VecExpr< A, T, D >, T >, T, D > sqr(const VecExpr< A, T, D > &rhs)
const Bool_t kTRUE
Definition: RtypesCore.h:87
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:33
TT Mag2() const
Definition: TEveVector.h:94
void SetSmooth(Bool_t r)
Set smooth rendering. Propagate to projected lines.
Definition: TEveLine.cxx:163
virtual void UpdateProjection()
Re-apply the projection.
Definition: TEveLine.cxx:358
const Int_t n
Definition: legend1.C:16
virtual Int_t Size() const
Definition: TPolyMarker3D.h:73
char name[80]
Definition: TGX11.cxx:109