-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathREveTrackProjected.cxx
More file actions
337 lines (277 loc) · 9.6 KB
/
Copy pathREveTrackProjected.cxx
File metadata and controls
337 lines (277 loc) · 9.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
// @(#)root/eve7:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
/*************************************************************************
* Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include <ROOT/REveTrackProjected.hxx>
#include <ROOT/REveTrackPropagator.hxx>
#include <ROOT/REveProjectionManager.hxx>
#include <ROOT/REveTrans.hxx>
#include <ROOT/REveRenderData.hxx>
#include <nlohmann/json.hpp>
using namespace ROOT::Experimental;
/** \class REveTrackProjected
\ingroup REve
Projected copy of a REveTrack.
*/
REveTrackProjected::~REveTrackProjected()
{
if (fOrigPnts) {
delete [] fOrigPnts;
fOrigPnts = nullptr;
}
}
////////////////////////////////////////////////////////////////////////////////
/// This is virtual method from base-class REveProjected.
void REveTrackProjected::SetProjection(REveProjectionManager* mng, REveProjectable* model)
{
REveProjected::SetProjection(mng, model);
CopyVizParams(dynamic_cast<REveElement*>(model));
REveTrack* otrack = dynamic_cast<REveTrack*>(fProjectable);
SetTrackParams(*otrack);
SetLockPoints(otrack->GetLockPoints());
}
////////////////////////////////////////////////////////////////////////////////
/// Set depth (z-coordinate) of the projected points.
void REveTrackProjected::SetDepthLocal(Float_t d)
{
SetDepthCommon(d, this, fBBox);
for (Int_t i = 0; i < fSize; ++i)
{
fPoints[i].fZ = fDepth;
}
for (auto &pm: fPathMarks)
{
pm.fV.fZ = fDepth;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual method from base-class REveProjected.
void REveTrackProjected::UpdateProjection()
{
MakeTrack(kFALSE); // REveProjectionManager makes recursive calls
}
////////////////////////////////////////////////////////////////////////////////
/// Find index of the last point that lies within the same
/// segment of projected space.
/// For example, rho-z projection separates upper and lower hemisphere
/// and tracks break into two lines when crossing the y=0 plane.
Int_t REveTrackProjected::GetBreakPointIdx(Int_t start)
{
REveProjection *projection = fManager->GetProjection();
Int_t val = fSize - 1;
if (projection->HasSeveralSubSpaces())
{
REveVector v1, v2;
if (fSize > 1)
{
Int_t i = start;
while (i < fSize - 1)
{
v1 = RefPoint(i);
v2 = RefPoint(i+1);
if(projection->AcceptSegment(v1, v2, fPropagator->GetDelta()) == kFALSE)
{
val = i;
break;
}
i++;
}
}
}
return val;
}
////////////////////////////////////////////////////////////////////////////////
/// Calculate the points of the track for drawing.
/// Call base-class, project, find break-points and insert points
/// required for full representation.
void REveTrackProjected::MakeTrack(Bool_t recurse)
{
REveTrack *otrack = dynamic_cast<REveTrack*>(fProjectable);
REveTrans *trans = otrack->PtrMainTrans(kFALSE);
REveProjection *projection = fManager->GetProjection();
fBreakPoints.clear();
fPathMarks.clear();
SetPathMarks(*otrack);
if (GetLockPoints() || otrack->GetSize() > 0)
{
ClonePoints(*otrack);
fLastPMIdx = otrack->GetLastPMIdx();
}
else
{
REveTrack::MakeTrack(recurse);
}
if (fSize == 0) return; // All points can be outside of MaxR / MaxZ limits.
// Break segments additionally if required by the projection.
ReduceSegmentLengths(projection->GetMaxTrackStep());
// XXXX This is stoopid. Need some more flaxible way od doing this.
// XXXX Make it dependant on projection parameters and on individual
// XXXX points (a function of r and z, eg).
// XXXX Also, we could represnet track with a bezier curve, trying
// XXXX to stretch it as far out as we can so the fewest number of
// XXXX points/directions needs to be transferred.
// Project points, store originals (needed for break-points).
Float_t *p = & fPoints[0].fX;
fOrigPnts = new REveVector[fSize];
for (Int_t i = 0; i < fSize; ++i, p+=3)
{
if (trans) trans->MultiplyIP(p);
fOrigPnts[i].Set(p);
projection->ProjectPointfv(p, fDepth);
}
Int_t bL = 0, bR = GetBreakPointIdx(0);
std::vector<REveVector> vvec;
while (kTRUE)
{
for (Int_t i = bL; i <= bR; i++)
{
vvec.push_back( RefPoint(i) );
}
if (bR == fSize - 1)
break;
REveVector vL = fOrigPnts[bR];
REveVector vR = fOrigPnts[bR + 1];
projection->BisectBreakPoint(vL, vR, kTRUE, fDepth);
vvec.push_back(vL);
fBreakPoints.push_back((UInt_t)vvec.size());
vvec.push_back(vR);
bL = bR + 1;
bR = GetBreakPointIdx(bL);
}
fBreakPoints.push_back((UInt_t)vvec.size()); // Mark the track-end for drawing.
// Decide if points need to be fixed.
// This (and the fixing itself) should really be done in REveProjection but
// for now we do it here as RhoZ is the only one that needs it.
Bool_t fix_y = kFALSE;
Float_t sign_y = 0;
if (projection->HasSeveralSubSpaces())
{
switch (fPropagator->GetProjTrackBreaking())
{
case REveTrackPropagator::kPTB_UseFirstPointPos:
{
fix_y = kTRUE;
sign_y = vvec.front().fY;
break;
}
case REveTrackPropagator::kPTB_UseLastPointPos:
{
fix_y = kTRUE;
sign_y = vvec.back().fY;
break;
}
}
}
Reset((Int_t)vvec.size());
for (auto &i: vvec)
{
if (fix_y)
SetNextPoint(i.fX, TMath::Sign(i.fY, sign_y), i.fZ);
else
SetNextPoint(i.fX, i.fY, i.fZ);
}
delete [] fOrigPnts;
fOrigPnts = nullptr;
// Project path-marks
for (auto &pm: fPathMarks)
{
projection->ProjectPointdv(trans, pm.fV.Arr(), pm.fV.Arr(), fDepth);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Print line segments info.
void REveTrackProjected::PrintLineSegments()
{
printf("%s LineSegments:\n", GetCName());
Int_t start = 0;
Int_t segment = 0;
for (auto &bpi: fBreakPoints)
{
Int_t size = bpi - start;
const REveVector &sVec = RefPoint(start);
const REveVector &bPnt = RefPoint(bpi-1);
printf("seg %d size %d start %d ::(%f, %f, %f) (%f, %f, %f)\n",
segment, size, start, sVec.fX, sVec.fY, sVec.fZ,
bPnt.fX, bPnt.fY, bPnt.fZ);
start += size;
segment++;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual method from from base-class REveTrack.
void REveTrackProjected::SecSelected(REveTrack* /*track*/)
{
REveTrack* t = dynamic_cast<REveTrack*>(fProjectable);
if (t)
t->SecSelected(t);
}
/** \class REveTrackListProjected
\ingroup REve
Specialization of REveTrackList for holding REveTrackProjected objects.
*/
////////////////////////////////////////////////////////////////////////////////
/// Default constructor.
REveTrackListProjected::REveTrackListProjected() :
REveTrackList (),
REveProjected ()
{
}
////////////////////////////////////////////////////////////////////////////////
/// This is virtual method from base-class REveProjected.
void REveTrackListProjected::SetProjection(REveProjectionManager* proj, REveProjectable* model)
{
REveProjected::SetProjection(proj, model);
CopyVizParams(dynamic_cast<REveElement*>(model));
REveTrackList& tl = * dynamic_cast<REveTrackList*>(model);
SetPropagator(tl.GetPropagator());
}
////////////////////////////////////////////////////////////////////////////////
/// This is not needed for functionality as SetDepth(Float_t d)
/// is overriden -- but SetDepthLocal() is abstract.
/// Just emits a warning if called.
void REveTrackListProjected::SetDepthLocal(Float_t /*d*/)
{
Warning("SetDepthLocal", "This function only exists to fulfill an abstract interface.");
}
////////////////////////////////////////////////////////////////////////////////
/// Set depth of all children inheriting from REveTrackProjected.
void REveTrackListProjected::SetDepth(Float_t d)
{
SetDepth(d, this);
}
////////////////////////////////////////////////////////////////////////////////
/// Set depth of all children of el inheriting from REveTrackProjected.
void REveTrackListProjected::SetDepth(Float_t d, REveElement *el)
{
for (auto &c: el->RefChildren()) {
auto ptrack = dynamic_cast<REveTrackProjected *>(c);
if (ptrack)
ptrack->SetDepth(d);
if (fRecurse)
SetDepth(d, c);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Creates client representation.
Int_t REveTrackProjected::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
{
Int_t ret = REveTrack::WriteCoreJson(j, rnr_offset);
if (j.contains("render_data"))
j["render_data"]["break_point_size"] = fBreakPoints.size();
return ret;
}
////////////////////////////////////////////////////////////////////////////////
/// Creates client rendering info.
void REveTrackProjected::BuildRenderData()
{
REveTrack::BuildRenderData();
if (fRenderData && !fBreakPoints.empty()) {
fRenderData->Reserve(0, 0, fBreakPoints.size());
fRenderData->PushI(fBreakPoints);
}
}