Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveTrackProjected.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
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
15#include <ROOT/REveTrans.hxx>
17
18#include <nlohmann/json.hpp>
19
20using namespace ROOT::Experimental;
21
22/** \class REveTrackProjected
23\ingroup REve
24Projected copy of a REveTrack.
25*/
26
27
28REveTrackProjected::~REveTrackProjected()
29{
30 if (fOrigPnts) {
31 delete [] fOrigPnts;
32 fOrigPnts = nullptr;
33 }
34}
35
36
37////////////////////////////////////////////////////////////////////////////////
38/// This is virtual method from base-class REveProjected.
39
41{
43 CopyVizParams(dynamic_cast<REveElement*>(model));
44
45 REveTrack* otrack = dynamic_cast<REveTrack*>(fProjectable);
46 SetTrackParams(*otrack);
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Set depth (z-coordinate) of the projected points.
52
54{
55 SetDepthCommon(d, this);
56
57 for (Int_t i = 0; i < fSize; ++i)
58 {
59 fPoints[i].fZ = fDepth;
60 }
61
62 for (auto &pm: fPathMarks)
63 {
64 pm.fV.fZ = fDepth;
65 }
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Virtual method from base-class REveProjected.
70
72{
73 MakeTrack(kFALSE); // REveProjectionManager makes recursive calls
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// Find index of the last point that lies within the same
78/// segment of projected space.
79/// For example, rho-z projection separates upper and lower hemisphere
80/// and tracks break into two lines when crossing the y=0 plane.
81
83{
84 REveProjection *projection = fManager->GetProjection();
85
86 Int_t val = fSize - 1;
87
88 if (projection->HasSeveralSubSpaces())
89 {
91 if (fSize > 1)
92 {
93 Int_t i = start;
94 while (i < fSize - 1)
95 {
96 v1 = RefPoint(i);
97 v2 = RefPoint(i+1);
98 if(projection->AcceptSegment(v1, v2, fPropagator->GetDelta()) == kFALSE)
99 {
100 val = i;
101 break;
102 }
103 i++;
104 }
105 }
106 }
107 return val;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Calculate the points of the track for drawing.
112/// Call base-class, project, find break-points and insert points
113/// required for full representation.
114
116{
117 REveTrack *otrack = dynamic_cast<REveTrack*>(fProjectable);
118 REveTrans mt;
119 const REveTrans *trans = fManager->GetModelTrans(otrack, mt);
120 REveProjection *projection = fManager->GetProjection();
121
122 fBreakPoints.clear();
123
124 fPathMarks.clear();
125 SetPathMarks(*otrack);
126 if (GetLockPoints() || otrack->GetSize() > 0)
127 {
128 ClonePoints(*otrack);
129 fLastPMIdx = otrack->GetLastPMIdx();
130 }
131 else
132 {
133 REveTrack::MakeTrack(recurse);
134 }
135 if (fSize == 0) return; // All points can be outside of MaxR / MaxZ limits.
136
137 // Break segments additionally if required by the projection.
139 // XXXX This is stoopid. Need some more flaxible way od doing this.
140 // XXXX Make it dependant on projection parameters and on individual
141 // XXXX points (a function of r and z, eg).
142 // XXXX Also, we could represnet track with a bezier curve, trying
143 // XXXX to stretch it as far out as we can so the fewest number of
144 // XXXX points/directions needs to be transferred.
145
146 // Project points, store originals (needed for break-points).
147 Float_t *p = & fPoints[0].fX;
149 for (Int_t i = 0; i < fSize; ++i, p+=3)
150 {
151 if (trans) trans->MultiplyIP(p);
152 fOrigPnts[i].Set(p);
153 projection->ProjectPointfv(p, fDepth);
154 }
155
156 Int_t bL = 0, bR = GetBreakPointIdx(0);
157 std::vector<REveVector> vvec;
158 while (kTRUE)
159 {
160 for (Int_t i = bL; i <= bR; i++)
161 {
162 vvec.push_back( RefPoint(i) );
163 }
164 if (bR == fSize - 1)
165 break;
166
167 REveVector vL = fOrigPnts[bR];
168 REveVector vR = fOrigPnts[bR + 1];
169 projection->BisectBreakPoint(vL, vR, kTRUE, fDepth);
170 vvec.push_back(vL);
171 fBreakPoints.push_back((UInt_t)vvec.size());
172 vvec.push_back(vR);
173
174 bL = bR + 1;
175 bR = GetBreakPointIdx(bL);
176 }
177 fBreakPoints.push_back((UInt_t)vvec.size()); // Mark the track-end for drawing.
178
179 // Decide if points need to be fixed.
180 // This (and the fixing itself) should really be done in REveProjection but
181 // for now we do it here as RhoZ is the only one that needs it.
182 Bool_t fix_y = kFALSE;
183 Float_t sign_y = 0;
184 if (projection->HasSeveralSubSpaces())
185 {
187 {
189 {
190 fix_y = kTRUE;
191 sign_y = vvec.front().fY;
192 break;
193 }
195 {
196 fix_y = kTRUE;
197 sign_y = vvec.back().fY;
198 break;
199 }
200 }
201 }
202
203 Reset((Int_t)vvec.size());
204 for (auto &i: vvec)
205 {
206 if (fix_y)
207 SetNextPoint(i.fX, TMath::Sign(i.fY, sign_y), i.fZ);
208 else
209 SetNextPoint(i.fX, i.fY, i.fZ);
210 }
211 delete [] fOrigPnts;
212 fOrigPnts = nullptr;
213
214 // Project path-marks
215 for (auto &pm: fPathMarks)
216 {
217 projection->ProjectPointdv(trans, pm.fV.Arr(), pm.fV.Arr(), fDepth);
218 }
219}
220
221////////////////////////////////////////////////////////////////////////////////
222/// Print line segments info.
223
225{
226 printf("%s LineSegments:\n", GetCName());
227
228 Int_t start = 0;
229 Int_t segment = 0;
230
231 for (auto &bpi: fBreakPoints)
232 {
233 Int_t size = bpi - start;
234
235 const REveVector &sVec = RefPoint(start);
236 const REveVector &bPnt = RefPoint(bpi-1);
237 printf("seg %d size %d start %d ::(%f, %f, %f) (%f, %f, %f)\n",
238 segment, size, start, sVec.fX, sVec.fY, sVec.fZ,
239 bPnt.fX, bPnt.fY, bPnt.fZ);
240 start += size;
241 segment++;
242 }
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Virtual method from from base-class REveTrack.
247
249{
250 REveTrack* t = dynamic_cast<REveTrack*>(fProjectable);
251 if (t)
252 t->SecSelected(t);
253}
254
255
256/** \class REveTrackListProjected
257\ingroup REve
258Specialization of REveTrackList for holding REveTrackProjected objects.
259*/
260
261////////////////////////////////////////////////////////////////////////////////
262/// Default constructor.
263
269
270////////////////////////////////////////////////////////////////////////////////
271/// This is virtual method from base-class REveProjected.
272
274{
275 REveProjected::SetProjection(proj, model);
276 CopyVizParams(dynamic_cast<REveElement*>(model));
277
278 REveTrackList& tl = * dynamic_cast<REveTrackList*>(model);
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// This is not needed for functionality as SetDepth(Float_t d)
284/// is overriden -- but SetDepthLocal() is abstract.
285/// Just emits a warning if called.
286
288{
289 Warning("SetDepthLocal", "This function only exists to fulfill an abstract interface.");
290}
291
292////////////////////////////////////////////////////////////////////////////////
293/// Set depth of all children inheriting from REveTrackProjected.
294
299
300////////////////////////////////////////////////////////////////////////////////
301/// Set depth of all children of el inheriting from REveTrackProjected.
302
304{
305 for (auto &c: el->RefChildren()) {
306 auto ptrack = dynamic_cast<REveTrackProjected *>(c);
307 if (ptrack)
308 ptrack->SetDepth(d);
309 if (fRecurse)
310 SetDepth(d, c);
311 }
312}
313
314////////////////////////////////////////////////////////////////////////////////
315/// Creates client representation.
316
317Int_t REveTrackProjected::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
318{
319 Int_t ret = REveTrack::WriteCoreJson(j, rnr_offset);
320
321 if (j.contains("render_data"))
322 j["render_data"]["break_point_size"] = fBreakPoints.size();
323
324 return ret;
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Creates client rendering info.
329
331{
333
334 if (fRenderData && !fBreakPoints.empty()) {
335 fRenderData->Reserve(0, 0, fBreakPoints.size());
337 }
338}
#define d(i)
Definition RSha256.hxx:102
#define c(i)
Definition RSha256.hxx:101
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
winID h TVirtualViewer3D TVirtualGLPainter p
const char * GetCName() const
std::unique_ptr< REveRenderData > fRenderData
! Vertex / normal / triangle index information for rendering.
void ReduceSegmentLengths(Float_t max)
Make sure that no segment is longer than max.
Definition REveLine.cxx:168
virtual void ClonePoints(const REvePointSet &e)
Clone points and all point-related information from point-set 'e'.
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.
virtual void SetDepth(Float_t d)
Set depth coordinate for the element.
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.
void ProjectPointdv(Double_t *v, Float_t d)
Project double array.
virtual Bool_t HasSeveralSubSpaces() const
virtual Bool_t AcceptSegment(REveVector &, REveVector &, Float_t) const
virtual void BisectBreakPoint(REveVector &vL, REveVector &vR, Float_t eps_sqr)
Find break-point on both sides of the discontinuity.
void SetDepthLocal(Float_t d) override
This is not needed for functionality as SetDepth(Float_t d) is overriden – but SetDepthLocal() is abs...
void SetProjection(REveProjectionManager *proj, REveProjectable *model) override
This is virtual method from base-class REveProjected.
void SetDepth(Float_t d) override
Set depth of all children inheriting from REveTrackProjected.
REveTrackList A list of tracks supporting change of common attributes and selection based on track pa...
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
void SetPropagator(REveTrackPropagator *prop)
Set default propagator for tracks.
REveTrackPropagator * GetPropagator()
REveTrackProjected Projected copy of a REveTrack.
void SecSelected(REveTrack *) override
Virtual method from from base-class REveTrack.
void SetDepthLocal(Float_t d) override
Set depth (z-coordinate) of the projected points.
void BuildRenderData() override
Creates client rendering info.
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override
Creates client representation.
void UpdateProjection() override
Virtual method from base-class REveProjected.
Int_t GetBreakPointIdx(Int_t start)
Find index of the last point that lies within the same segment of projected space.
void MakeTrack(Bool_t recurse=kTRUE) override
Calculate the points of the track for drawing.
void SetProjection(REveProjectionManager *mng, REveProjectable *model) override
This is virtual method from base-class REveProjected.
void PrintLineSegments()
Print line segments info.
REveTrack Track with given vertex, momentum and optional referece-points (path-marks) along its path.
Definition REveTrack.hxx:40
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override
Fill core part of JSON representation.
virtual void SecSelected(REveTrack *)
Emits "SecSelected(REveTrack*)" signal.
REveTrackPropagator * fPropagator
Definition REveTrack.hxx:68
Int_t fLastPMIdx
! Last path-mark index tried in track-propagation.
Definition REveTrack.hxx:66
virtual void SetTrackParams(const REveTrack &t)
Copy track parameters from t.
virtual void MakeTrack(Bool_t recurse=kTRUE)
Calculate track representation based on track data and current settings of the propagator.
virtual void SetPathMarks(const REveTrack &t)
Copy path-marks from t.
void BuildRenderData() override
Crates 3D point array for rendering.
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
void MultiplyIP(TVector3 &v, Double_t w=1) const
Multiply vector in-place.
void Set(const Float_t *v)
Namespace for ROOT features in testing.
Definition TROOT.h:100
T1 Sign(T1 a, T2 b)
Returns a value with the magnitude of a and the sign of b.
Definition TMathBase.h:174