forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveProjectionManager.cxx
422 lines (361 loc) · 12.8 KB
/
TEveProjectionManager.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
// @(#)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 "TEveProjectionManager.h"
#include "TEveManager.h"
#include "TEveProjectionBases.h"
#include "TEveCompound.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TVirtualViewer3D.h"
#include "TClass.h"
#include <list>
/** \class TEveProjectionManager
\ingroup TEve
Manager class for steering of projections and managing projected objects.
Recursively projects TEveElement's and draws axis in the projected
scene. It enables to interactively set TEveProjection parameters
and updates projected scene accordingly.
*/
ClassImp(TEveProjectionManager);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveProjectionManager::TEveProjectionManager(TEveProjection::EPType_e type):
TEveElementList("TEveProjectionManager",""),
TAttBBox(),
fProjection (0),
fCurrentDepth(0),
fImportEmpty (kFALSE)
{
for (Int_t i = 0; i < TEveProjection::kPT_End; ++i)
fProjections[i] = 0;
if (type != TEveProjection::kPT_Unknown)
SetProjection(type);
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
/// Destroys also dependent elements.
TEveProjectionManager::~TEveProjectionManager()
{
for (Int_t i = 0; i < TEveProjection::kPT_End; ++i)
{
delete fProjections[i];
}
while ( ! fDependentEls.empty())
{
fDependentEls.front()->Destroy();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Add el as dependent element.
void TEveProjectionManager::AddDependent(TEveElement* el)
{
fDependentEls.push_back(el);
}
////////////////////////////////////////////////////////////////////////////////
/// Remove el as dependent element.
void TEveProjectionManager::RemoveDependent(TEveElement* el)
{
fDependentEls.remove(el);
}
////////////////////////////////////////////////////////////////////////////////
/// Updates name to have consistent information with projection.
void TEveProjectionManager::UpdateName()
{
if (fProjection->Is2D())
SetName(Form ("%s (%3.1f)", fProjection->GetName(), fProjection->GetDistortion()*1000));
else
SetName(fProjection->GetName());
}
////////////////////////////////////////////////////////////////////////////////
/// Set projection type and distortion.
void TEveProjectionManager::SetProjection(TEveProjection::EPType_e type)
{
static const TEveException eH("TEveProjectionManager::SetProjection ");
if (fProjections[type] == 0)
{
switch (type)
{
case TEveProjection::kPT_RhoZ:
{
fProjections[type] = new TEveRhoZProjection();
break;
}
case TEveProjection::kPT_RPhi:
{
fProjections[type] = new TEveRPhiProjection();
break;
}
case TEveProjection::kPT_XZ:
{
fProjections[type] = new TEveXZProjection();
break;
}
case TEveProjection::kPT_YZ:
{
fProjections[type] = new TEveYZProjection();
break;
}
case TEveProjection::kPT_ZX:
{
fProjections[type] = new TEveZXProjection();
break;
}
case TEveProjection::kPT_ZY:
{
fProjections[type] = new TEveZYProjection();
break;
}
case TEveProjection::kPT_3D:
{
fProjections[type] = new TEve3DProjection();
break;
}
default:
throw eH + "projection type not valid.";
break;
}
}
if (fProjection && fProjection->Is2D() != fProjections[type]->Is2D())
{
throw eH + "switching between 2D and 3D projections not implemented.";
}
fProjection = fProjections[type];
fProjection->SetCenter(fCenter);
UpdateName();
}
////////////////////////////////////////////////////////////////////////////////
/// Set projection center and rebuild projected scene.
void TEveProjectionManager::SetCenter(Float_t x, Float_t y, Float_t z)
{
fCenter.Set(x, y, z);
fProjection->SetCenter(fCenter);
ProjectChildren();
}
////////////////////////////////////////////////////////////////////////////////
/// React to element being pasted or dnd-ed.
/// Return true if redraw is needed (virtual method).
Bool_t TEveProjectionManager::HandleElementPaste(TEveElement* el)
{
List_t::size_type n_children = fChildren.size();
ImportElements(el);
return n_children != fChildren.size();
}
////////////////////////////////////////////////////////////////////////////////
/// Returns true if element el should be imported.
///
/// Behaviour depends on the value of the fImportEmpty member:
/// false - el or any of its children must be projectable (default);
/// true - always import.
Bool_t TEveProjectionManager::ShouldImport(TEveElement* el)
{
if (fImportEmpty)
return kTRUE;
if (el->IsA() != TEveElementList::Class() && el->IsA()->InheritsFrom(TEveProjectable::Class()))
return kTRUE;
for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
if (ShouldImport(*i))
return kTRUE;
return kFALSE;
}
////////////////////////////////////////////////////////////////////////////////
/// Update dependent elements' bounding box and mark scenes
/// containing element root or its children as requiring a repaint.
void TEveProjectionManager::UpdateDependentElsAndScenes(TEveElement* root)
{
for (List_i i=fDependentEls.begin(); i!=fDependentEls.end(); ++i)
{
TAttBBox* bbox = dynamic_cast<TAttBBox*>(*i);
if (bbox)
bbox->ComputeBBox();
}
List_t scenes;
root->CollectSceneParentsFromChildren(scenes, 0);
gEve->ScenesChanged(scenes);
}
////////////////////////////////////////////////////////////////////////////////
/// If el is TEveProjectable add projected instance else add plain
/// TEveElementList to parent. Call the same function on el's
/// children.
///
/// Returns the projected replica of el. Can be 0, if el and none of
/// its children are projectable.
TEveElement* TEveProjectionManager::ImportElementsRecurse(TEveElement* el,
TEveElement* parent)
{
static const TEveException eh("TEveProjectionManager::ImportElementsRecurse ");
TEveElement *new_el = 0;
if (ShouldImport(el))
{
TEveProjected *new_pr = 0;
TEveProjectable *pble = dynamic_cast<TEveProjectable*>(el);
if (pble)
{
new_el = (TEveElement*) pble->ProjectedClass(fProjection)->New();
new_pr = dynamic_cast<TEveProjected*>(new_el);
new_pr->SetProjection(this, pble);
new_pr->SetDepth(fCurrentDepth);
}
else
{
new_el = new TEveElementList;
}
new_el->SetElementName (Form("%s [P]", el->GetElementName()));
new_el->SetElementTitle(Form("Projected replica.\n%s", el->GetElementTitle()));
new_el->SetRnrSelf (el->GetRnrSelf());
new_el->SetRnrChildren (el->GetRnrChildren());
new_el->SetPickable (el->IsPickable());
parent->AddElement(new_el);
TEveCompound *cmpnd = dynamic_cast<TEveCompound*>(el);
TEveCompound *cmpnd_pr = dynamic_cast<TEveCompound*>(new_el);
for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
{
TEveElement* child_pr = ImportElementsRecurse(*i, new_el);
if (cmpnd && (*i)->GetCompound() == cmpnd)
child_pr->SetCompound(cmpnd_pr);
}
}
return new_el;
}
////////////////////////////////////////////////////////////////////////////////
/// Recursively import elements and apply projection to the newly
/// imported objects.
///
/// If ext_list is not 0 the new element is also added to the list.
/// This simplifies construction of complex views where projected
/// elements are distributed into several scenes for optimization of
/// updates and rendering.
///
/// Returns the projected replica of el. Can be 0, if el and none of
/// its children are projectable.
TEveElement* TEveProjectionManager::ImportElements(TEveElement* el,
TEveElement* ext_list)
{
TEveElement* new_el = ImportElementsRecurse(el, this);
if (new_el)
{
AssertBBox();
ProjectChildrenRecurse(new_el);
AssertBBoxExtents(0.1);
StampTransBBox();
UpdateDependentElsAndScenes(new_el);
if (ext_list)
ext_list->AddElement(new_el);
}
return new_el;
}
////////////////////////////////////////////////////////////////////////////////
/// Recursively import elements and apply projection to the newly
/// imported objects.
///
/// The proj_parent argument should be a projected replica of parent
/// of element 'el'. This allows to insert projected children of
/// a given element when they are added after the projection has
/// been already performed on the parent.
/// This is called from TEveElement::ProjectChild().
///
/// Returns the projected replica of el. Can be 0, if el and none of
/// its children are projectable.
TEveElement* TEveProjectionManager::SubImportElements(TEveElement* el,
TEveElement* proj_parent)
{
TEveElement* new_el = ImportElementsRecurse(el, proj_parent);
if (new_el)
{
AssertBBox();
ProjectChildrenRecurse(new_el);
AssertBBoxExtents(0.1);
StampTransBBox();
UpdateDependentElsAndScenes(new_el);
}
return new_el;
}
////////////////////////////////////////////////////////////////////////////////
/// Recursively import children elements of el and apply projection
/// to the newly imported objects.
///
/// The proj_parent argument should be a projected replica of
/// element 'el'. This allows to insert projected children of
/// a given element when they are added after the projection has
/// been already performed on the parent.
/// This is called from TEveElement::ProjectChild().
///
/// Returns the projected replica of el. Can be 0, if el and none of
/// its children are projectable.
Int_t TEveProjectionManager::SubImportChildren(TEveElement* el, TEveElement* proj_parent)
{
List_t new_els;
for (List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
{
TEveElement* new_el = ImportElementsRecurse(*i, proj_parent);
if (new_el)
new_els.push_back(new_el);
}
if ( ! new_els.empty())
{
AssertBBox();
for (List_i i = new_els.begin(); i != new_els.end(); ++i)
{
ProjectChildrenRecurse(*i);
}
AssertBBoxExtents(0.1);
StampTransBBox();
UpdateDependentElsAndScenes(proj_parent);
}
return (Int_t) new_els.size();
}
////////////////////////////////////////////////////////////////////////////////
/// Project el (via TEveProjected::UpdateProjection()) and recurse
/// through el's children.
/// Bounding-box is updated along the recursion.
void TEveProjectionManager::ProjectChildrenRecurse(TEveElement* el)
{
TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
if (pted)
{
pted->UpdateProjection();
TAttBBox* bb = dynamic_cast<TAttBBox*>(pted);
if (bb)
{
Float_t* b = bb->AssertBBox();
BBoxCheckPoint(b[0], b[2], b[4]);
BBoxCheckPoint(b[1], b[3], b[5]);
}
el->ElementChanged(kFALSE);
}
for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
ProjectChildrenRecurse(*i);
}
////////////////////////////////////////////////////////////////////////////////
/// Project all children recursively, update bounding-box and notify
/// TEveManger about the scenes that have been changed.
void TEveProjectionManager::ProjectChildren()
{
BBoxInit();
for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
ProjectChildrenRecurse(*i);
AssertBBoxExtents(0.1);
StampTransBBox();
UpdateDependentElsAndScenes(this);
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual from TAttBBox; fill bounding-box information.
///
/// The bounding-box information is kept coherent during addition of
/// projected elements and projection parameter updates. This is
/// called only in case the manager has not been populated at all.
void TEveProjectionManager::ComputeBBox()
{
static const TEveException eH("TEveProjectionManager::ComputeBBox ");
if (HasChildren() == kFALSE) {
BBoxZero();
return;
}
BBoxInit();
}