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
35
36////////////////////////////////////////////////////////////////////////////////
37/// Constructor.
38
40 TEveElementList("TEveProjectionManager",""),
41 TAttBBox(),
42 fProjection (0),
43 fCurrentDepth(0),
44 fImportEmpty (kFALSE)
45{
46 for (Int_t i = 0; i < TEveProjection::kPT_End; ++i)
47 fProjections[i] = 0;
48
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Destructor.
55/// Destroys also dependent elements.
56
58{
59 for (Int_t i = 0; i < TEveProjection::kPT_End; ++i)
60 {
61 delete fProjections[i];
62 }
63 while ( ! fDependentEls.empty())
64 {
65 fDependentEls.front()->Destroy();
66 }
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Add el as dependent element.
71
73{
74 fDependentEls.push_back(el);
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Remove el as dependent element.
79
81{
82 fDependentEls.remove(el);
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Updates name to have consistent information with projection.
87
89{
90 if (fProjection->Is2D())
91 SetName(Form ("%s (%3.1f)", fProjection->GetName(), fProjection->GetDistortion()*1000));
92 else
94}
95
96////////////////////////////////////////////////////////////////////////////////
97/// Set projection type and distortion.
98
100{
101 static const TEveException eH("TEveProjectionManager::SetProjection ");
102
103 if (fProjections[type] == 0)
104 {
105 switch (type)
106 {
108 {
110 break;
111 }
113 {
115 break;
116 }
118 {
120 break;
121 }
123 {
125 break;
126 }
128 {
130 break;
131 }
133 {
135 break;
136 }
138 {
140 break;
141 }
142 default:
143 throw eH + "projection type not valid.";
144 break;
145 }
146 }
147
149 {
150 throw eH + "switching between 2D and 3D projections not implemented.";
151 }
152
155 UpdateName();
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Set projection center and rebuild projected scene.
160
162{
163 fCenter.Set(x, y, z);
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// React to element being pasted or dnd-ed.
170/// Return true if redraw is needed (virtual method).
171
173{
174 List_t::size_type n_children = fChildren.size();
175 ImportElements(el);
176 return n_children != fChildren.size();
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Returns true if element el should be imported.
181///
182/// Behaviour depends on the value of the fImportEmpty member:
183/// false - el or any of its children must be projectable (default);
184/// true - always import.
185
187{
188 if (fImportEmpty)
189 return kTRUE;
190
192 return kTRUE;
193 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
194 if (ShouldImport(*i))
195 return kTRUE;
196 return kFALSE;
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// Update dependent elements' bounding box and mark scenes
201/// containing element root or its children as requiring a repaint.
202
204{
205 for (List_i i=fDependentEls.begin(); i!=fDependentEls.end(); ++i)
206 {
207 TAttBBox* bbox = dynamic_cast<TAttBBox*>(*i);
208 if (bbox)
209 bbox->ComputeBBox();
210 }
211
212 List_t scenes;
213 root->CollectSceneParentsFromChildren(scenes, 0);
214 gEve->ScenesChanged(scenes);
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// If el is TEveProjectable add projected instance else add plain
219/// TEveElementList to parent. Call the same function on el's
220/// children.
221///
222/// Returns the projected replica of el. Can be 0, if el and none of
223/// its children are projectable.
224
226 TEveElement* parent)
227{
228 static const TEveException eh("TEveProjectionManager::ImportElementsRecurse ");
229
230 TEveElement *new_el = 0;
231
232 if (ShouldImport(el))
233 {
234 TEveProjected *new_pr = 0;
235 TEveProjectable *pble = dynamic_cast<TEveProjectable*>(el);
236 if (pble)
237 {
238 new_el = (TEveElement*) pble->ProjectedClass(fProjection)->New();
239 new_pr = dynamic_cast<TEveProjected*>(new_el);
240 new_pr->SetProjection(this, pble);
241 new_pr->SetDepth(fCurrentDepth);
242 }
243 else
244 {
245 new_el = new TEveElementList;
246 }
247 new_el->SetElementName (Form("%s [P]", el->GetElementName()));
248 new_el->SetElementTitle(Form("Projected replica.\n%s", el->GetElementTitle()));
249 new_el->SetRnrSelf (el->GetRnrSelf());
250 new_el->SetRnrChildren (el->GetRnrChildren());
251 new_el->SetPickable (el->IsPickable());
252 parent->AddElement(new_el);
253
254 TEveCompound *cmpnd = dynamic_cast<TEveCompound*>(el);
255 TEveCompound *cmpnd_pr = dynamic_cast<TEveCompound*>(new_el);
256 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
257 {
258 TEveElement* child_pr = ImportElementsRecurse(*i, new_el);
259 if (cmpnd && (*i)->GetCompound() == cmpnd)
260 child_pr->SetCompound(cmpnd_pr);
261 }
262 }
263
264 return new_el;
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Recursively import elements and apply projection to the newly
269/// imported objects.
270///
271/// If ext_list is not 0 the new element is also added to the list.
272/// This simplifies construction of complex views where projected
273/// elements are distributed into several scenes for optimization of
274/// updates and rendering.
275///
276/// Returns the projected replica of el. Can be 0, if el and none of
277/// its children are projectable.
278
280 TEveElement* ext_list)
281{
282 TEveElement* new_el = ImportElementsRecurse(el, this);
283 if (new_el)
284 {
285 AssertBBox();
289
291
292 if (ext_list)
293 ext_list->AddElement(new_el);
294 }
295 return new_el;
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Recursively import elements and apply projection to the newly
300/// imported objects.
301///
302/// The proj_parent argument should be a projected replica of parent
303/// of element 'el'. This allows to insert projected children of
304/// a given element when they are added after the projection has
305/// been already performed on the parent.
306/// This is called from TEveElement::ProjectChild().
307///
308/// Returns the projected replica of el. Can be 0, if el and none of
309/// its children are projectable.
310
312 TEveElement* proj_parent)
313{
314 TEveElement* new_el = ImportElementsRecurse(el, proj_parent);
315 if (new_el)
316 {
317 AssertBBox();
321
323 }
324 return new_el;
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Recursively import children elements of el and apply projection
329/// to the newly imported objects.
330///
331/// The proj_parent argument should be a projected replica of
332/// element 'el'. This allows to insert projected children of
333/// a given element when they are added after the projection has
334/// been already performed on the parent.
335/// This is called from TEveElement::ProjectChild().
336///
337/// Returns the projected replica of el. Can be 0, if el and none of
338/// its children are projectable.
339
341{
342 List_t new_els;
343 for (List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
344 {
345 TEveElement* new_el = ImportElementsRecurse(*i, proj_parent);
346 if (new_el)
347 new_els.push_back(new_el);
348 }
349
350 if ( ! new_els.empty())
351 {
352 AssertBBox();
353 for (List_i i = new_els.begin(); i != new_els.end(); ++i)
354 {
356 }
359
360 UpdateDependentElsAndScenes(proj_parent);
361 }
362 return (Int_t) new_els.size();
363}
364
365////////////////////////////////////////////////////////////////////////////////
366/// Project el (via TEveProjected::UpdateProjection()) and recurse
367/// through el's children.
368/// Bounding-box is updated along the recursion.
369
371{
372 TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
373 if (pted)
374 {
375 pted->UpdateProjection();
376 TAttBBox* bb = dynamic_cast<TAttBBox*>(pted);
377 if (bb)
378 {
379 Float_t* b = bb->AssertBBox();
380 BBoxCheckPoint(b[0], b[2], b[4]);
381 BBoxCheckPoint(b[1], b[3], b[5]);
382 }
384 }
385
386 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
388}
389
390////////////////////////////////////////////////////////////////////////////////
391/// Project all children recursively, update bounding-box and notify
392/// TEveManger about the scenes that have been changed.
393
395{
396 BBoxInit();
397 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
401
403}
404
405////////////////////////////////////////////////////////////////////////////////
406/// Virtual from TAttBBox; fill bounding-box information.
407///
408/// The bounding-box information is kept coherent during addition of
409/// projected elements and projection parameter updates. This is
410/// called only in case the manager has not been populated at all.
411
413{
414 static const TEveException eH("TEveProjectionManager::ComputeBBox ");
415
416 if (HasChildren() == kFALSE) {
417 BBoxZero();
418 return;
419 }
420
421 BBoxInit();
422}
#define b(i)
Definition RSha256.hxx:100
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
R__EXTERN TEveManager * gEve
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
Helper for management of bounding-box information.
Definition TAttBBox.h:18
virtual void ComputeBBox()=0
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:42
void AssertBBoxExtents(Float_t epsilon=0.005)
Assert extents of all sides of the bounding-box are at least epsilon.
Definition TAttBBox.cxx:62
Float_t * AssertBBox()
Definition TAttBBox.h:56
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition TAttBBox.cxx:29
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:4978
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4874
3D scaling projection.
Description of TEveCompound.
A list of TEveElements.
static TClass * Class()
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
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.
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
void ScenesChanged(TEveElement::List_t &scenes)
Mark all scenes from the given list as changed.
Abstract base-class for non-linear projectable objects.
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.
Manager class for steering of projections and managing projected objects.
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 Bool_t HandleElementPaste(TEveElement *el)
React to element being pasted or dnd-ed.
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.
void SetCenter(Float_t x, Float_t y, Float_t z)
Set projection center and rebuild projected scene.
virtual void UpdateName()
Updates name to have consistent information with projection.
virtual void ComputeBBox()
Virtual from TAttBBox; fill bounding-box information.
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...
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 ~TEveProjectionManager()
Destructor.
virtual void ProjectChildren()
Project all children recursively, update bounding-box and notify TEveManger about the scenes that hav...
virtual void SetCenter(TEveVector &v)
virtual Bool_t Is2D() const =0
Float_t GetDistortion() const
const Char_t * GetName() const
XY projection with distortion around given center.
Transformation from 3D to 2D.
void Set(const Float_t *v)
Definition TEveVector.h:82
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:140
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17