forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveLine.cxx
372 lines (311 loc) · 9.71 KB
/
TEveLine.cxx
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
/*************************************************************************
* Copyright (C) 1995-2007, 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 "TEveLine.h"
#include "TEveProjectionManager.h"
namespace
{
inline Float_t sqr(Float_t x) { return x*x; }
}
/** \class TEveLine
\ingroup TEve
An arbitrary polyline with fixed line and marker attributes.
*/
ClassImp(TEveLine);
Bool_t TEveLine::fgDefaultSmooth = kFALSE;
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveLine::TEveLine(Int_t n_points, ETreeVarType_e tv_type) :
TEvePointSet("Line", n_points, tv_type),
fRnrLine (kTRUE),
fRnrPoints (kFALSE),
fSmooth (fgDefaultSmooth)
{
fMainColorPtr = &fLineColor;
fMarkerColor = kGreen;
}
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveLine::TEveLine(const char* name, Int_t n_points, ETreeVarType_e tv_type) :
TEvePointSet(name, n_points, tv_type),
fRnrLine (kTRUE),
fRnrPoints (kFALSE),
fSmooth (fgDefaultSmooth)
{
fMainColorPtr = &fLineColor;
fMarkerColor = kGreen;
}
////////////////////////////////////////////////////////////////////////////////
/// Returns list-tree icon for TEveLine.
const TGPicture* TEveLine::GetListTreeIcon(Bool_t)
{
return fgListTreeIcons[8];
}
////////////////////////////////////////////////////////////////////////////////
/// Set marker color. Propagate to projected lines.
void TEveLine::SetMarkerColor(Color_t col)
{
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* l = dynamic_cast<TEveLine*>(*pi);
if (l && fMarkerColor == l->GetMarkerColor())
{
l->SetMarkerColor(col);
l->StampObjProps();
}
++pi;
}
TAttMarker::SetMarkerColor(col);
}
////////////////////////////////////////////////////////////////////////////////
/// Set line-style of the line.
/// The style is propagated to projecteds.
void TEveLine::SetLineStyle(Style_t lstyle)
{
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* pt = dynamic_cast<TEveLine*>(*pi);
if (pt)
{
pt->SetLineStyle(lstyle);
pt->StampObjProps();
}
++pi;
}
TAttLine::SetLineStyle(lstyle);
}
////////////////////////////////////////////////////////////////////////////////
/// Set line-style of the line.
/// The style is propagated to projecteds.
void TEveLine::SetLineWidth(Width_t lwidth)
{
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* pt = dynamic_cast<TEveLine*>(*pi);
if (pt)
{
pt->SetLineWidth(lwidth);
pt->StampObjProps();
}
++pi;
}
TAttLine::SetLineWidth(lwidth);
}
////////////////////////////////////////////////////////////////////////////////
/// Set rendering of line. Propagate to projected lines.
void TEveLine::SetRnrLine(Bool_t r)
{
fRnrLine = r;
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* l = dynamic_cast<TEveLine*>(*pi);
if (l)
{
l->SetRnrLine(r);
l->ElementChanged();
}
++pi;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Set rendering of points. Propagate to projected lines.
void TEveLine::SetRnrPoints(Bool_t r)
{
fRnrPoints = r;
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* l = dynamic_cast<TEveLine*>(*pi);
if (l)
{
l->SetRnrPoints(r);
l->ElementChanged();
}
++pi;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Set smooth rendering. Propagate to projected lines.
void TEveLine::SetSmooth(Bool_t r)
{
fSmooth = r;
std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
while (pi != fProjectedList.end())
{
TEveLine* l = dynamic_cast<TEveLine*>(*pi);
if (l)
{
l->SetSmooth(r);
l->ElementChanged();
}
++pi;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Make sure that no segment is longer than max.
/// Per point references and integer ids are lost.
void TEveLine::ReduceSegmentLengths(Float_t max)
{
const Float_t max2 = max*max;
Float_t *p = GetP();
Int_t s = Size();
TEveVector a, b, d;
std::vector<TEveVector> q;
b.Set(p);
q.push_back(b);
for (Int_t i = 1; i < s; ++i)
{
a = b; b.Set(&p[3*i]); d = b - a;
Float_t m2 = d.Mag2();
if (m2 > max2)
{
Float_t f = TMath::Sqrt(m2) / max;
Int_t n = TMath::FloorNint(f);
d *= 1.0f / (n + 1);
for (Int_t j = 0; j < n; ++j)
{
a += d;
q.push_back(a);
}
}
q.push_back(b);
}
s = q.size();
Reset(s);
for (std::vector<TEveVector>::iterator i = q.begin(); i != q.end(); ++i)
SetNextPoint(i->fX, i->fY, i->fZ);
}
////////////////////////////////////////////////////////////////////////////////
/// Sum-up lengths of individual segments.
Float_t TEveLine::CalculateLineLength() const
{
Float_t sum = 0;
Int_t s = Size();
Float_t *p = GetP();
for (Int_t i = 1; i < s; ++i, p += 3)
{
sum += TMath::Sqrt(sqr(p[3] - p[0]) + sqr(p[4] - p[1]) + sqr(p[5] - p[2]));
}
return sum;
}
////////////////////////////////////////////////////////////////////////////////
/// Return the first point of the line.
/// If there are no points (0,0,0) is returned.
TEveVector TEveLine::GetLineStart() const
{
TEveVector v;
GetPoint(0, v.fX, v.fY, v.fZ);
return v;
}
////////////////////////////////////////////////////////////////////////////////
/// Return the last point of the line.
/// If there are no points (0,0,0) is returned.
TEveVector TEveLine::GetLineEnd() const
{
TEveVector v;
GetPoint(fLastPoint, v.fX, v.fY, v.fZ);
return v;
}
////////////////////////////////////////////////////////////////////////////////
/// Copy visualization parameters from element el.
void TEveLine::CopyVizParams(const TEveElement* el)
{
const TEveLine* m = dynamic_cast<const TEveLine*>(el);
if (m)
{
TAttLine::operator=(*m);
fRnrLine = m->fRnrLine;
fRnrPoints = m->fRnrPoints;
fSmooth = m->fSmooth;
}
TEvePointSet::CopyVizParams(el);
}
////////////////////////////////////////////////////////////////////////////////
/// Write visualization parameters.
void TEveLine::WriteVizParams(std::ostream& out, const TString& var)
{
TEvePointSet::WriteVizParams(out, var);
TString t = " " + var + "->";
TAttLine::SaveLineAttributes(out, var);
out << t << "SetRnrLine(" << ToString(fRnrLine) << ");\n";
out << t << "SetRnrPoints(" << ToString(fRnrPoints) << ");\n";
out << t << "SetSmooth(" << ToString(fSmooth) << ");\n";
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual from TEveProjectable, returns TEvePointSetProjected class.
TClass* TEveLine::ProjectedClass(const TEveProjection*) const
{
return TEveLineProjected::Class();
}
////////////////////////////////////////////////////////////////////////////////
/// Get default value for smooth-line drawing flag.
/// Static function.
Bool_t TEveLine::GetDefaultSmooth()
{
return fgDefaultSmooth;
}
////////////////////////////////////////////////////////////////////////////////
/// Set default value for smooth-line drawing flag (default kFALSE).
/// Static function.
void TEveLine::SetDefaultSmooth(Bool_t r)
{
fgDefaultSmooth = r;
}
/** \class TEveLineProjected
\ingroup TEve
Projected copy of a TEveLine.
*/
ClassImp(TEveLineProjected);
////////////////////////////////////////////////////////////////////////////////
/// Default constructor.
TEveLineProjected::TEveLineProjected() :
TEveLine (),
TEveProjected ()
{
}
////////////////////////////////////////////////////////////////////////////////
/// Set projection manager and projection model.
/// Virtual from TEveProjected.
void TEveLineProjected::SetProjection(TEveProjectionManager* mng,
TEveProjectable* model)
{
TEveProjected::SetProjection(mng, model);
CopyVizParams(dynamic_cast<TEveElement*>(model));
}
////////////////////////////////////////////////////////////////////////////////
/// Set depth (z-coordinate) of the projected points.
void TEveLineProjected::SetDepthLocal(Float_t d)
{
SetDepthCommon(d, this, fBBox);
Int_t n = Size();
Float_t *p = GetP() + 2;
for (Int_t i = 0; i < n; ++i, p+=3)
*p = fDepth;
}
////////////////////////////////////////////////////////////////////////////////
/// Re-apply the projection.
/// Virtual from TEveProjected.
void TEveLineProjected::UpdateProjection()
{
TEveProjection& proj = * fManager->GetProjection();
TEveLine & als = * dynamic_cast<TEveLine*>(fProjectable);
TEveTrans *tr = als.PtrMainTrans(kFALSE);
Int_t n = als.Size();
Reset(n);
fLastPoint = n - 1;
Float_t *o = als.GetP(), *p = GetP();
for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
{
proj.ProjectPointfv(tr, o, p, fDepth);
}
}