Logo ROOT   6.10/09
Reference Guide
TEveStraightLineSet.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 "TEveStraightLineSet.h"
13 
14 #include "TRandom.h"
15 #include "TEveProjectionManager.h"
16 
17 /** \class TEveStraightLineSet
18 \ingroup TEve
19 Set of straight lines with optional markers along the lines.
20 */
21 
23 
24 ////////////////////////////////////////////////////////////////////////////////
25 /// Constructor.
26 
27 TEveStraightLineSet::TEveStraightLineSet(const char* n, const char* t):
28  TEveElement (),
29  TNamed (n, t),
30 
31  fLinePlex (sizeof(Line_t), 4),
32  fMarkerPlex (sizeof(Marker_t), 8),
33  fOwnLinesIds (kFALSE),
34  fOwnMarkersIds (kFALSE),
35  fRnrMarkers (kTRUE),
36  fRnrLines (kTRUE),
37  fDepthTest (kTRUE),
38  fLastLine (0)
39 {
40  InitMainTrans();
41  fPickable = kTRUE;
42 
44  fLineColor = 4;
45  fMarkerColor = 2;
46  fMarkerStyle = 20;
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Add a line.
51 
54  Float_t x2, Float_t y2, Float_t z2)
55 {
56  fLastLine = new (fLinePlex.NewAtom()) Line_t(x1, y1, z1, x2, y2, z2);
57  fLastLine->fId = fLinePlex.Size() - 1;
58  return fLastLine;
59 }
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Add a line.
63 
66 {
67  return AddLine(p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
68 }
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// Set line vertices with given index.
72 
73 void
75  Float_t x1, Float_t y1, Float_t z1,
76  Float_t x2, Float_t y2, Float_t z2)
77 {
78  Line_t* l = (Line_t*) fLinePlex.Atom(idx);
79 
80  l->fV1[0] = x1; l->fV1[1] = y1; l->fV1[2] = z1;
81  l->fV2[0] = x2; l->fV2[1] = y2; l->fV2[2] = z2;
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Set line vertices with given index.
86 
87 void
89 {
90  SetLine(idx, p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Add a marker with given position.
95 
98 {
99  Marker_t* marker = new (fMarkerPlex.NewAtom()) Marker_t(x, y, z, line_id);
100  return marker;
101 }
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Add a marker with given position.
105 
108 {
109  return AddMarker(p.fX, p.fY, p.fZ, line_id);
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// Add a marker for line with given index on relative position pos.
114 
117 {
118  Line_t& l = * (Line_t*) fLinePlex.Atom(line_id);
119  return AddMarker(l.fV1[0] + (l.fV2[0] - l.fV1[0])*pos,
120  l.fV1[1] + (l.fV2[1] - l.fV1[1])*pos,
121  l.fV1[2] + (l.fV2[2] - l.fV1[2])*pos,
122  line_id);
123 }
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// Copy visualization parameters from element el.
127 
129 {
130  const TEveStraightLineSet* m = dynamic_cast<const TEveStraightLineSet*>(el);
131  if (m)
132  {
136  fRnrLines = m->fRnrLines;
137  fDepthTest = m->fDepthTest;
138  }
139 
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Write visualization parameters.
145 
146 void TEveStraightLineSet::WriteVizParams(std::ostream& out, const TString& var)
147 {
148  TEveElement::WriteVizParams(out, var);
149 
150  TString t = " " + var + "->";
153  out << t << "SetRnrMarkers(" << ToString(fRnrMarkers) << ");\n";
154  out << t << "SetRnrLines(" << ToString(fRnrLines) << ");\n";
155  out << t << "SetDepthTest(" << ToString(fDepthTest) << ");\n";
156 }
157 
158 ////////////////////////////////////////////////////////////////////////////////
159 /// Return class of projected object.
160 /// Virtual from TEveProjectable.
161 
163 {
165 }
166 
167 ////////////////////////////////////////////////////////////////////////////////
168 /// Compute bounding-box.
169 /// Virtual from TAttBBox.
170 
172 {
173  if (fLinePlex.Size() == 0 && fMarkerPlex.Size() == 0) {
174  BBoxZero();
175  return;
176  }
177 
178  BBoxInit();
179 
181  while (li.next()) {
182  BBoxCheckPoint(((Line_t*)li())->fV1);
183  BBoxCheckPoint(((Line_t*)li())->fV2);
184  }
185 
187  while (mi.next())
188  {
189  BBoxCheckPoint(((Marker_t*)mi())->fV);
190  }
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// Paint the line-set.
195 
197 {
198  PaintStandard(this);
199 }
200 
201 /** \class TEveStraightLineSetProjected
202 \ingroup TEve
203 Projected replica of a TEveStraightLineSet.
204 */
205 
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Constructor.
210 
213 {
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Set projection manager and model object.
218 
221 {
222  TEveProjected::SetProjection(mng, model);
223 
224  CopyVizParams(dynamic_cast<TEveElement*>(model));
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Set depth (z-coordinate) of the projected points.
229 
231 {
232  SetDepthCommon(d, this, fBBox);
233 
235  while (li.next())
236  {
238  l.fV1[2] = fDepth;
239  l.fV2[2] = fDepth;
240  }
241 
243  while (mi.next())
244  {
245  Marker_t& m = * (Marker_t*) mi();
246  m.fV[2] = fDepth;
247  }
248 }
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Callback that actually performs the projection.
252 /// Called when projection parameters have been updated.
253 
255 {
257  TEveStraightLineSet& orig = * dynamic_cast<TEveStraightLineSet*>(fProjectable);
258 
259  TEveTrans *trans = orig.PtrMainTrans(kFALSE);
260 
261  BBoxClear();
262 
263  // Lines
264  Int_t num_lines = orig.GetLinePlex().Size();
265  if (proj.HasSeveralSubSpaces())
266  num_lines += TMath::Max(1, num_lines/10);
267  fLinePlex.Reset(sizeof(Line_t), num_lines);
268  TEveVector p1, p2;
270  while (li.next())
271  {
272  Line_t *l = (Line_t*) li();
273 
274  proj.ProjectPointfv(trans, l->fV1, p1, fDepth);
275  proj.ProjectPointfv(trans, l->fV2, p2, fDepth);
276 
277  if (proj.AcceptSegment(p1, p2, 0.1f))
278  {
279  AddLine(p1, p2)->fId = l->fId;
280  }
281  else
282  {
283  TEveVector bp1(l->fV1), bp2(l->fV2);
284  if (trans) {
285  trans->MultiplyIP(bp1);
286  trans->MultiplyIP(bp2);
287  }
288  proj.BisectBreakPoint(bp1, bp2, kTRUE, fDepth);
289 
290  AddLine(p1, bp1)->fId = l->fId;
291  AddLine(bp2, p2)->fId = l->fId;
292  }
293  }
294  if (proj.HasSeveralSubSpaces())
295  fLinePlex.Refit();
296 
297  // Markers
298  fMarkerPlex.Reset(sizeof(Marker_t), orig.GetMarkerPlex().Size());
300  TEveVector pp;
301  while (mi.next())
302  {
303  Marker_t &m = * (Marker_t*) mi();
304 
305  proj.ProjectPointfv(trans, m.fV, pp, fDepth);
306  AddMarker(pp, m.fLineId);
307  }
308 }
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 SetProjection(TEveProjectionManager *mng, TEveProjectable *model)
Set projection manager and model object.
virtual TClass * ProjectedClass(const TEveProjection *p) const
Return class of projected object.
virtual void SetDepthLocal(Float_t d)
Set depth (z-coordinate) of the projected points.
float Float_t
Definition: RtypesCore.h:53
virtual void UpdateProjection()
Callback that actually performs the projection.
const char Option_t
Definition: RtypesCore.h:62
Bool_t fPickable
Definition: TEveElement.h:310
TEveChunkManager fLinePlex
virtual void Paint(Option_t *option="")
Paint the line-set.
virtual void PaintStandard(TObject *id)
Paint object – a generic implementation for EVE elements.
virtual void CopyVizParams(const TEveElement *el)
Copy visualization parameters from element el.
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
virtual void SetProjection(TEveProjectionManager *mng, TEveProjectable *model)
Sets projection manager and reference in the projectable object.
void MultiplyIP(TVector3 &v, Double_t w=1) const
Multiply vector in-place.
Definition: TEveTrans.cxx:729
virtual Bool_t AcceptSegment(TEveVector &, TEveVector &, Float_t) const
static const char * ToString(Bool_t b)
Convert Bool_t to string - kTRUE or kFALSE.
Float_t * fBBox
Definition: TAttBBox.h:20
TEveChunkManager & GetLinePlex()
virtual Bool_t HasSeveralSubSpaces() const
Color_t * fMainColorPtr
Definition: TEveElement.h:97
static const double x2[5]
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition: TAttBBox.h:58
Double_t x[n]
Definition: legend1.C:17
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:260
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
static double p2(double t, double a, double b, double c)
void Refit()
Refit the container so that all current data fits into a single chunk.
void Reset(Int_t atom_size, Int_t chunk_size)
Empty the container and reset it with given atom and chunk sizes.
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttMarker.cxx:244
Base-class for non-linear projections.
short Marker_t
Definition: RtypesCore.h:77
Projected replica of a TEveStraightLineSet.
Int_t Size() const
Manager class for steering of projections and managing projected objects.
TEveChunkManager & GetMarkerPlex()
Char_t * Atom(Int_t idx) const
Style_t fMarkerStyle
Marker style.
Definition: TAttMarker.h:23
Abstract base-class for non-linear projectable objects.
virtual void InitMainTrans(Bool_t can_edit=kTRUE)
Initialize the main transformation to identity matrix.
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write visualization parameters.
TEveProjectable * fProjectable
Color_t fLineColor
Line color.
Definition: TAttLine.h:21
TEveProjectionManager * fManager
TEveStraightLineSet(const TEveStraightLineSet &)
TMarker * m
Definition: textangle.C:8
void BBoxZero(Float_t epsilon=0, Float_t x=0, Float_t y=0, Float_t z=0)
Create cube of volume (2*epsilon)^3 at (x,y,z).
Definition: TAttBBox.cxx:42
virtual void CopyVizParams(const TEveElement *el)
Copy visualization parameters from element el.
TLine * l
Definition: textangle.C:4
virtual void BisectBreakPoint(TEveVector &vL, TEveVector &vR, Float_t eps_sqr)
Find break-point on both sides of the discontinuity.
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:71
static double p1(double t, double a, double b)
void BBoxClear()
Remove BBox information.
Definition: TAttBBox.cxx:54
void ProjectPointfv(Float_t *v, Float_t d)
Project float array.
const Bool_t kFALSE
Definition: RtypesCore.h:92
TEveProjection * GetProjection()
static const double x1[5]
#define ClassImp(name)
Definition: Rtypes.h:336
TEveChunkManager fMarkerPlex
Double_t y[n]
Definition: legend1.C:17
Marker_t * AddMarker(Float_t x, Float_t y, Float_t z, Int_t line_id=-1)
Add a marker with given position.
Binding & operator=(OUT(*fun)(void))
Line_t * AddLine(Float_t x1, Float_t y1, Float_t z1, Float_t x2, Float_t y2, Float_t z2)
Add a line.
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
Bool_t next()
Go to next atom.
void SetDepthCommon(Float_t d, TEveElement *el, Float_t *bbox)
Utility function to update the z-values of the bounding-box.
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write-out visual parameters for this object.
virtual TEveTrans * PtrMainTrans(Bool_t create=kTRUE)
Return pointer to main transformation.
Color_t fMarkerColor
Marker color.
Definition: TAttMarker.h:22
const Bool_t kTRUE
Definition: RtypesCore.h:91
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:33
const Int_t n
Definition: legend1.C:16
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition: TAttBBox.cxx:29
void SetLine(int idx, Float_t x1, Float_t y1, Float_t z1, Float_t x2, Float_t y2, Float_t z2)
Set line vertices with given index.
Set of straight lines with optional markers along the lines.
virtual void ComputeBBox()
Compute bounding-box.