Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TEveProjectionManager.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
13#include "TEveManager.h"
14#include "TEveProjectionBases.h"
15#include "TEveCompound.h"
16
17#include "TBuffer3D.h"
18#include "TBuffer3DTypes.h"
19#include "TVirtualViewer3D.h"
20
21#include "TClass.h"
22
23#include <list>
24
25/** \class TEveProjectionManager
26\ingroup TEve
27Manager class for steering of projections and managing projected objects.
28
29Recursively projects TEveElement's and draws axis in the projected
30scene. It enables to interactively set TEveProjection parameters
31and updates projected scene accordingly.
32*/
33
34
35////////////////////////////////////////////////////////////////////////////////
36/// Constructor.
37
39 TEveElementList("TEveProjectionManager",""),
40 TAttBBox(),
41 fProjection (nullptr),
44{
45 for (Int_t i = 0; i < TEveProjection::kPT_End; ++i)
46 fProjections[i] = nullptr;
47
49 SetProjection(type);
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Destructor.
54/// Destroys also dependent elements.
55
57{
58 for (Int_t i = 0; i < TEveProjection::kPT_End; ++i)
59 {
60 delete fProjections[i];
61 }
62 while ( ! fDependentEls.empty())
63 {
64 fDependentEls.front()->Destroy();
65 }
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Add el as dependent element.
70
75
76////////////////////////////////////////////////////////////////////////////////
77/// Remove el as dependent element.
78
83
84////////////////////////////////////////////////////////////////////////////////
85/// Updates name to have consistent information with projection.
86
88{
89 if (fProjection->Is2D())
90 SetName(Form ("%s (%3.1f)", fProjection->GetName(), fProjection->GetDistortion()*1000));
91 else
92 SetName(fProjection->GetName());
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Set projection type and distortion.
97
99{
100 static const TEveException eH("TEveProjectionManager::SetProjection ");
101
102 if (fProjections[type] == nullptr)
103 {
104 switch (type)
105 {
107 {
108 fProjections[type] = new TEveRhoZProjection();
109 break;
110 }
112 {
113 fProjections[type] = new TEveRPhiProjection();
114 break;
115 }
117 {
118 fProjections[type] = new TEveXZProjection();
119 break;
120 }
122 {
123 fProjections[type] = new TEveYZProjection();
124 break;
125 }
127 {
128 fProjections[type] = new TEveZXProjection();
129 break;
130 }
132 {
133 fProjections[type] = new TEveZYProjection();
134 break;
135 }
137 {
138 fProjections[type] = new TEve3DProjection();
139 break;
140 }
141 default:
142 throw eH + "projection type not valid.";
143 break;
144 }
145 }
146
147 if (fProjection && fProjection->Is2D() != fProjections[type]->Is2D())
148 {
149 throw eH + "switching between 2D and 3D projections not implemented.";
150 }
151
153 fProjection->SetCenter(fCenter);
154 UpdateName();
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// Set projection center and rebuild projected scene.
159
161{
162 fCenter.Set(x, y, z);
163 fProjection->SetCenter(fCenter);
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// React to element being pasted or dnd-ed.
169/// Return true if redraw is needed (virtual method).
170
172{
173 List_t::size_type n_children = fChildren.size();
174 ImportElements(el);
175 return n_children != fChildren.size();
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Returns true if element el should be imported.
180///
181/// Behaviour depends on the value of the fImportEmpty member:
182/// false - el or any of its children must be projectable (default);
183/// true - always import.
184
186{
187 if (fImportEmpty)
188 return kTRUE;
189
191 return kTRUE;
192 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
193 if (ShouldImport(*i))
194 return kTRUE;
195 return kFALSE;
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Update dependent elements' bounding box and mark scenes
200/// containing element root or its children as requiring a repaint.
201
203{
204 for (List_i i=fDependentEls.begin(); i!=fDependentEls.end(); ++i)
205 {
206 TAttBBox* bbox = dynamic_cast<TAttBBox*>(*i);
207 if (bbox)
208 bbox->ComputeBBox();
209 }
210
211 List_t scenes;
212 root->CollectSceneParentsFromChildren(scenes, nullptr);
213 gEve->ScenesChanged(scenes);
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// If el is TEveProjectable add projected instance else add plain
218/// TEveElementList to parent. Call the same function on el's
219/// children.
220///
221/// Returns the projected replica of el. Can be 0, if el and none of
222/// its children are projectable.
223
225 TEveElement* parent)
226{
227 static const TEveException eh("TEveProjectionManager::ImportElementsRecurse ");
228
229 TEveElement *new_el = nullptr;
230
231 if (ShouldImport(el))
232 {
233 TEveProjected *new_pr = nullptr;
234 TEveProjectable *pble = dynamic_cast<TEveProjectable*>(el);
235 if (pble)
236 {
237 new_el = (TEveElement*) pble->ProjectedClass(fProjection)->New();
238 new_pr = dynamic_cast<TEveProjected*>(new_el);
239 new_pr->SetProjection(this, pble);
240 new_pr->SetDepth(fCurrentDepth);
241 }
242 else
243 {
244 new_el = new TEveElementList;
245 }
246 new_el->SetElementName (Form("%s [P]", el->GetElementName()));
247 new_el->SetElementTitle(Form("Projected replica.\n%s", el->GetElementTitle()));
248 new_el->SetRnrSelf (el->GetRnrSelf());
249 new_el->SetRnrChildren (el->GetRnrChildren());
250 new_el->SetPickable (el->IsPickable());
251 parent->AddElement(new_el);
252
253 TEveCompound *cmpnd = dynamic_cast<TEveCompound*>(el);
254 TEveCompound *cmpnd_pr = dynamic_cast<TEveCompound*>(new_el);
255 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
256 {
257 TEveElement* child_pr = ImportElementsRecurse(*i, new_el);
258 if (cmpnd && (*i)->GetCompound() == cmpnd)
259 child_pr->SetCompound(cmpnd_pr);
260 }
261 }
262
263 return new_el;
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// Recursively import elements and apply projection to the newly
268/// imported objects.
269///
270/// If ext_list is not 0 the new element is also added to the list.
271/// This simplifies construction of complex views where projected
272/// elements are distributed into several scenes for optimization of
273/// updates and rendering.
274///
275/// Returns the projected replica of el. Can be 0, if el and none of
276/// its children are projectable.
277
279 TEveElement* ext_list)
280{
281 TEveElement* new_el = ImportElementsRecurse(el, this);
282 if (new_el)
283 {
284 AssertBBox();
288
290
291 if (ext_list)
292 ext_list->AddElement(new_el);
293 }
294 return new_el;
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// Recursively import elements and apply projection to the newly
299/// imported objects.
300///
301/// The proj_parent argument should be a projected replica of parent
302/// of element 'el'. This allows to insert projected children of
303/// a given element when they are added after the projection has
304/// been already performed on the parent.
305/// This is called from TEveElement::ProjectChild().
306///
307/// Returns the projected replica of el. Can be 0, if el and none of
308/// its children are projectable.
309
311 TEveElement* proj_parent)
312{
313 TEveElement* new_el = ImportElementsRecurse(el, proj_parent);
314 if (new_el)
315 {
316 AssertBBox();
320
322 }
323 return new_el;
324}
325
326////////////////////////////////////////////////////////////////////////////////
327/// Recursively import children elements of el and apply projection
328/// to the newly imported objects.
329///
330/// The proj_parent argument should be a projected replica of
331/// element 'el'. This allows to insert projected children of
332/// a given element when they are added after the projection has
333/// been already performed on the parent.
334/// This is called from TEveElement::ProjectChild().
335///
336/// Returns the projected replica of el. Can be 0, if el and none of
337/// its children are projectable.
338
340{
341 List_t new_els;
342 for (List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
343 {
344 TEveElement* new_el = ImportElementsRecurse(*i, proj_parent);
345 if (new_el)
346 new_els.push_back(new_el);
347 }
348
349 if ( ! new_els.empty())
350 {
351 AssertBBox();
352 for (List_i i = new_els.begin(); i != new_els.end(); ++i)
353 {
355 }
358
359 UpdateDependentElsAndScenes(proj_parent);
360 }
361 return (Int_t) new_els.size();
362}
363
364////////////////////////////////////////////////////////////////////////////////
365/// Project el (via TEveProjected::UpdateProjection()) and recurse
366/// through el's children.
367/// Bounding-box is updated along the recursion.
368
370{
371 TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
372 if (pted)
373 {
374 pted->UpdateProjection();
375 TAttBBox* bb = dynamic_cast<TAttBBox*>(pted);
376 if (bb)
377 {
378 Float_t* b = bb->AssertBBox();
379 BBoxCheckPoint(b[0], b[2], b[4]);
380 BBoxCheckPoint(b[1], b[3], b[5]);
381 }
383 }
384
385 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
387}
388
389////////////////////////////////////////////////////////////////////////////////
390/// Project all children recursively, update bounding-box and notify
391/// TEveManger about the scenes that have been changed.
392
403
404////////////////////////////////////////////////////////////////////////////////
405/// Virtual from TAttBBox; fill bounding-box information.
406///
407/// The bounding-box information is kept coherent during addition of
408/// projected elements and projection parameter updates. This is
409/// called only in case the manager has not been populated at all.
410
412{
413 static const TEveException eH("TEveProjectionManager::ComputeBBox ");
414
415 if (HasChildren() == kFALSE) {
416 BBoxZero();
417 return;
418 }
419
420 BBoxInit();
421}
#define b(i)
Definition RSha256.hxx:100
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
externTEveManager * gEve
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2496
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition TAttBBox.h:69
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:41
void AssertBBoxExtents(Float_t epsilon=0.005)
Assert extents of all sides of the bounding-box are at least epsilon.
Definition TAttBBox.cxx:61
Float_t * AssertBBox()
Definition TAttBBox.h:56
void BBoxInit(Float_t infinity=1e6)
Allocate and prepare for incremental filling.
Definition TAttBBox.cxx:28
TAttBBox(const TAttBBox &tab)
Definition TAttBBox.h:31
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:5048
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4932
3D scaling projection.
Description of TEveCompound.
TEveElementList(const char *n="TEveElementList", const char *t="", Bool_t doColor=kFALSE, Bool_t doTransparency=kFALSE)
Constructor.
static TClass * Class()
virtual void AddElement(TEveElement *el)
Add el to the list of children.
List_t fChildren
Definition TEveElement.h:81
virtual TClass * IsA() const
Bool_t IsPickable() const
void StampTransBBox()
List_i EndChildren()
Bool_t HasChildren() const
std::list< TEveElement * > List_t
Definition TEveElement.h:71
virtual const char * GetElementTitle() const
Virtual function for retrieving title of the render-element.
virtual void SetElementTitle(const char *title)
Virtual function for setting of title of an element.
virtual Bool_t SetRnrChildren(Bool_t rnr)
Set render state of this element's children, i.e.
TEveCompound * GetCompound()
virtual void SetElementName(const char *name)
Virtual function for setting of name of an element.
void SetCompound(TEveCompound *c)
virtual void ElementChanged(Bool_t update_scenes=kTRUE, Bool_t redraw=kFALSE)
Call this after an element has been changed so that the state can be propagated around the framework.
virtual Bool_t GetRnrChildren() const
virtual void CollectSceneParentsFromChildren(List_t &scenes, TEveElement *parent)
Collect scene-parents from all children.
virtual const char * GetElementName() const
Virtual function for retrieving name of the element.
TEveElement()
Default constructor.
void SetPickable(Bool_t p)
virtual Bool_t GetRnrSelf() const
List_i BeginChildren()
List_t::iterator List_i
Definition TEveElement.h:72
virtual Bool_t SetRnrSelf(Bool_t rnr)
Set render state of this element, i.e.
Exception class thrown by TEve classes and macros.
Definition TEveUtil.h:102
TEveProjectable(const TEveProjectable &)
static TClass * Class()
virtual TClass * ProjectedClass(const TEveProjection *p) const =0
Abstract base class for classes that hold results of a non-linear projection transformation.
virtual void SetDepth(Float_t d)
Set depth coordinate for the element.
virtual void UpdateProjection()=0
virtual void SetProjection(TEveProjectionManager *mng, TEveProjectable *model)
Sets projection manager and reference in the projectable object.
virtual TEveElement * ImportElements(TEveElement *el, TEveElement *ext_list=nullptr)
Recursively import elements and apply projection to the newly imported objects.
void RemoveDependent(TEveElement *el)
Remove el as dependent element.
virtual void ProjectChildrenRecurse(TEveElement *el)
Project el (via TEveProjected::UpdateProjection()) and recurse through el's children.
void AddDependent(TEveElement *el)
Add el as dependent element.
TEveProjection * fProjections[TEveProjection::kPT_End]
virtual TEveElement * ImportElementsRecurse(TEveElement *el, TEveElement *parent)
If el is TEveProjectable add projected instance else add plain TEveElementList to parent.
Bool_t HandleElementPaste(TEveElement *el) override
React to element being pasted or dnd-ed.
void SetCenter(Float_t x, Float_t y, Float_t z)
Set projection center and rebuild projected scene.
void ComputeBBox() override
Virtual from TAttBBox; fill bounding-box information.
virtual void UpdateName()
Updates name to have consistent information with projection.
TEveProjectionManager(const TEveProjectionManager &)
virtual Int_t SubImportChildren(TEveElement *el, TEveElement *proj_parent)
Recursively import children elements of el and apply projection to the newly imported objects.
virtual void UpdateDependentElsAndScenes(TEveElement *root)
Update dependent elements' bounding box and mark scenes containing element root or its children as re...
~TEveProjectionManager() override
Destructor.
void SetProjection(TEveProjection::EPType_e type)
Set projection type and distortion.
virtual TEveElement * SubImportElements(TEveElement *el, TEveElement *proj_parent)
Recursively import elements and apply projection to the newly imported objects.
virtual Bool_t ShouldImport(TEveElement *el)
Returns true if element el should be imported.
virtual void ProjectChildren()
Project all children recursively, update bounding-box and notify TEveManger about the scenes that hav...
XY projection with distortion around given center.
Transformation from 3D to 2D.
XZ projection with distortion around given center.
YZ projection with distortion around given center.
ZX projection with distortion around given center.
ZY projection with distortion around given center.
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17