Logo ROOT  
Reference Guide
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 
12 #include "TEveProjectionManager.h"
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
27 Manager class for steering of projections and managing projected objects.
28 
29 Recursively projects TEveElement's and draws axis in the projected
30 scene. It enables to interactively set TEveProjection parameters
31 and 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  }
127  default:
128  throw eH + "projection type not valid.";
129  break;
130  }
131  }
132 
134  {
135  throw eH + "switching between 2D and 3D projections not implemented.";
136  }
137 
140  UpdateName();
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Set projection center and rebuild projected scene.
145 
147 {
148  fCenter.Set(x, y, z);
150  ProjectChildren();
151 }
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// React to element being pasted or dnd-ed.
155 /// Return true if redraw is needed (virtual method).
156 
158 {
159  List_t::size_type n_children = fChildren.size();
160  ImportElements(el);
161  return n_children != fChildren.size();
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Returns true if element el should be imported.
166 ///
167 /// Behaviour depends on the value of the fImportEmpty member:
168 /// false - el or any of its children must be projectable (default);
169 /// true - always import.
170 
172 {
173  if (fImportEmpty)
174  return kTRUE;
175 
176  if (el->IsA() != TEveElementList::Class() && el->IsA()->InheritsFrom(TEveProjectable::Class()))
177  return kTRUE;
178  for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
179  if (ShouldImport(*i))
180  return kTRUE;
181  return kFALSE;
182 }
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// Update dependent elements' bounding box and mark scenes
186 /// containing element root or its children as requiring a repaint.
187 
189 {
190  for (List_i i=fDependentEls.begin(); i!=fDependentEls.end(); ++i)
191  {
192  TAttBBox* bbox = dynamic_cast<TAttBBox*>(*i);
193  if (bbox)
194  bbox->ComputeBBox();
195  }
196 
197  List_t scenes;
198  root->CollectSceneParentsFromChildren(scenes, 0);
199  gEve->ScenesChanged(scenes);
200 }
201 
202 ////////////////////////////////////////////////////////////////////////////////
203 /// If el is TEveProjectable add projected instance else add plain
204 /// TEveElementList to parent. Call the same function on el's
205 /// children.
206 ///
207 /// Returns the projected replica of el. Can be 0, if el and none of
208 /// its children are projectable.
209 
211  TEveElement* parent)
212 {
213  static const TEveException eh("TEveProjectionManager::ImportElementsRecurse ");
214 
215  TEveElement *new_el = 0;
216 
217  if (ShouldImport(el))
218  {
219  TEveProjected *new_pr = 0;
220  TEveProjectable *pble = dynamic_cast<TEveProjectable*>(el);
221  if (pble)
222  {
223  new_el = (TEveElement*) pble->ProjectedClass(fProjection)->New();
224  new_pr = dynamic_cast<TEveProjected*>(new_el);
225  new_pr->SetProjection(this, pble);
226  new_pr->SetDepth(fCurrentDepth);
227  }
228  else
229  {
230  new_el = new TEveElementList;
231  }
232  new_el->SetElementName (Form("%s [P]", el->GetElementName()));
233  new_el->SetElementTitle(Form("Projected replica.\n%s", el->GetElementTitle()));
234  new_el->SetRnrSelf (el->GetRnrSelf());
235  new_el->SetRnrChildren (el->GetRnrChildren());
236  new_el->SetPickable (el->IsPickable());
237  parent->AddElement(new_el);
238 
239  TEveCompound *cmpnd = dynamic_cast<TEveCompound*>(el);
240  TEveCompound *cmpnd_pr = dynamic_cast<TEveCompound*>(new_el);
241  for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
242  {
243  TEveElement* child_pr = ImportElementsRecurse(*i, new_el);
244  if (cmpnd && (*i)->GetCompound() == cmpnd)
245  child_pr->SetCompound(cmpnd_pr);
246  }
247  }
248 
249  return new_el;
250 }
251 
252 ////////////////////////////////////////////////////////////////////////////////
253 /// Recursively import elements and apply projection to the newly
254 /// imported objects.
255 ///
256 /// If ext_list is not 0 the new element is also added to the list.
257 /// This simplifies construction of complex views where projected
258 /// elements are distributed into several scenes for optimization of
259 /// updates and rendering.
260 ///
261 /// Returns the projected replica of el. Can be 0, if el and none of
262 /// its children are projectable.
263 
265  TEveElement* ext_list)
266 {
267  TEveElement* new_el = ImportElementsRecurse(el, this);
268  if (new_el)
269  {
270  AssertBBox();
271  ProjectChildrenRecurse(new_el);
272  AssertBBoxExtents(0.1);
273  StampTransBBox();
274 
276 
277  if (ext_list)
278  ext_list->AddElement(new_el);
279  }
280  return new_el;
281 }
282 
283 ////////////////////////////////////////////////////////////////////////////////
284 /// Recursively import elements and apply projection to the newly
285 /// imported objects.
286 ///
287 /// The proj_parent argument should be a projected replica of parent
288 /// of element 'el'. This allows to insert projected children of
289 /// a given element when they are added after the projection has
290 /// been already performed on the parent.
291 /// This is called from TEveElement::ProjectChild().
292 ///
293 /// Returns the projected replica of el. Can be 0, if el and none of
294 /// its children are projectable.
295 
297  TEveElement* proj_parent)
298 {
299  TEveElement* new_el = ImportElementsRecurse(el, proj_parent);
300  if (new_el)
301  {
302  AssertBBox();
303  ProjectChildrenRecurse(new_el);
304  AssertBBoxExtents(0.1);
305  StampTransBBox();
306 
308  }
309  return new_el;
310 }
311 
312 ////////////////////////////////////////////////////////////////////////////////
313 /// Recursively import children elements of el and apply projection
314 /// to the newly imported objects.
315 ///
316 /// The proj_parent argument should be a projected replica of
317 /// element 'el'. This allows to insert projected children of
318 /// a given element when they are added after the projection has
319 /// been already performed on the parent.
320 /// This is called from TEveElement::ProjectChild().
321 ///
322 /// Returns the projected replica of el. Can be 0, if el and none of
323 /// its children are projectable.
324 
326 {
327  List_t new_els;
328  for (List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
329  {
330  TEveElement* new_el = ImportElementsRecurse(*i, proj_parent);
331  if (new_el)
332  new_els.push_back(new_el);
333  }
334 
335  if ( ! new_els.empty())
336  {
337  AssertBBox();
338  for (List_i i = new_els.begin(); i != new_els.end(); ++i)
339  {
341  }
342  AssertBBoxExtents(0.1);
343  StampTransBBox();
344 
345  UpdateDependentElsAndScenes(proj_parent);
346  }
347  return (Int_t) new_els.size();
348 }
349 
350 ////////////////////////////////////////////////////////////////////////////////
351 /// Project el (via TEveProjected::UpdateProjection()) and recurse
352 /// through el's children.
353 /// Bounding-box is updated along the recursion.
354 
356 {
357  TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
358  if (pted)
359  {
360  pted->UpdateProjection();
361  TAttBBox* bb = dynamic_cast<TAttBBox*>(pted);
362  if (bb)
363  {
364  Float_t* b = bb->AssertBBox();
365  BBoxCheckPoint(b[0], b[2], b[4]);
366  BBoxCheckPoint(b[1], b[3], b[5]);
367  }
368  el->ElementChanged(kFALSE);
369  }
370 
371  for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
373 }
374 
375 ////////////////////////////////////////////////////////////////////////////////
376 /// Project all children recursively, update bounding-box and notify
377 /// TEveManger about the scenes that have been changed.
378 
380 {
381  BBoxInit();
382  for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
384  AssertBBoxExtents(0.1);
385  StampTransBBox();
386 
388 }
389 
390 ////////////////////////////////////////////////////////////////////////////////
391 /// Virtual from TAttBBox; fill bounding-box information.
392 ///
393 /// The bounding-box information is kept coherent during addition of
394 /// projected elements and projection parameter updates. This is
395 /// called only in case the manager has not been populated at all.
396 
398 {
399  static const TEveException eH("TEveProjectionManager::ComputeBBox ");
400 
401  if (HasChildren() == kFALSE) {
402  BBoxZero();
403  return;
404  }
405 
406  BBoxInit();
407 }
TEveElement::SetPickable
void SetPickable(Bool_t p)
Definition: TEveElement.h:342
TEveElement::HasChildren
Bool_t HasChildren() const
Definition: TEveElement.h:171
TAttBBox::AssertBBox
Float_t * AssertBBox()
Definition: TAttBBox.h:45
TEveProjection::kPT_RPhi
@ kPT_RPhi
Definition: TEveProjections.h:29
TEveProjectionManager::fImportEmpty
Bool_t fImportEmpty
Definition: TEveProjectionManager.h:36
TEveProjectionManager::fDependentEls
List_t fDependentEls
Definition: TEveProjectionManager.h:34
TEveProjection::kPT_RhoZ
@ kPT_RhoZ
Definition: TEveProjections.h:29
TEveElement
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:36
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TEveProjected::UpdateProjection
virtual void UpdateProjection()=0
TEveElement::SetElementName
virtual void SetElementName(const char *name)
Virtual function for setting of name of an element.
Definition: TEveElement.cxx:292
TEveProjectionManager::HandleElementPaste
virtual Bool_t HandleElementPaste(TEveElement *el)
React to element being pasted or dnd-ed.
Definition: TEveProjectionManager.cxx:157
TNamed::SetName
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
TEveProjected::SetProjection
virtual void SetProjection(TEveProjectionManager *mng, TEveProjectable *model)
Sets projection manager and reference in the projectable object.
Definition: TEveProjectionBases.cxx:193
TEveProjectionManager::SubImportChildren
virtual Int_t SubImportChildren(TEveElement *el, TEveElement *proj_parent)
Recursively import children elements of el and apply projection to the newly imported objects.
Definition: TEveProjectionManager.cxx:325
TEveProjectionManager::AddDependent
void AddDependent(TEveElement *el)
Add el as dependent element.
Definition: TEveProjectionManager.cxx:72
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
TEveElementList::TEveElementList
TEveElementList(const char *n="TEveElementList", const char *t="", Bool_t doColor=kFALSE, Bool_t doTransparency=kFALSE)
Constructor.
Definition: TEveElement.cxx:2089
TEveProjectionManager::ProjectChildrenRecurse
virtual void ProjectChildrenRecurse(TEveElement *el)
Project el (via TEveProjected::UpdateProjection()) and recurse through el's children.
Definition: TEveProjectionManager.cxx:355
TEveProjection::kPT_3D
@ kPT_3D
Definition: TEveProjections.h:29
TEveElement::GetRnrSelf
virtual Bool_t GetRnrSelf() const
Definition: TEveElement.h:256
TEveCompound
Description of TEveCompound.
Definition: TEveCompound.h:24
Float_t
float Float_t
Definition: RtypesCore.h:57
TAttBBox::BBoxZero
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
x
Double_t x[n]
Definition: legend1.C:17
TEveProjection::EPType_e
EPType_e
Definition: TEveProjections.h:29
TEveElement::SetElementTitle
virtual void SetElementTitle(const char *title)
Virtual function for setting of title of an element.
Definition: TEveElement.cxx:309
TClass.h
TEveProjection::Is2D
virtual Bool_t Is2D() const =0
TEveElement::fChildren
List_t fChildren
Definition: TEveElement.h:81
TAttBBox::AssertBBoxExtents
void AssertBBoxExtents(Float_t epsilon=0.005)
Assert extents of all sides of the bounding-box are at least epsilon.
Definition: TAttBBox.cxx:62
TEve3DProjection
3D scaling projection.
Definition: TEveProjections.h:236
TEveProjectionManager::TEveProjectionManager
TEveProjectionManager(const TEveProjectionManager &)
TEveElement::List_i
List_t::iterator List_i
Definition: TEveElement.h:72
TEveManager::ScenesChanged
void ScenesChanged(TEveElement::List_t &scenes)
Mark all scenes from the given list as changed.
Definition: TEveManager.cxx:458
TEveProjection::kPT_End
@ kPT_End
Definition: TEveProjections.h:29
TEveElementList
A list of TEveElements.
Definition: TEveElement.h:433
TEveProjectionBases.h
gEve
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
b
#define b(i)
Definition: RSha256.hxx:100
TEveRPhiProjection
XY projection with distortion around given center.
Definition: TEveProjections.h:191
bool
TAttBBox
Helper for management of bounding-box information.
Definition: TAttBBox.h:18
TAttBBox::BBoxCheckPoint
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition: TAttBBox.h:58
TEveElement::GetRnrChildren
virtual Bool_t GetRnrChildren() const
Definition: TEveElement.h:257
TEveProjectionManager::fProjection
TEveProjection * fProjection
Definition: TEveProjectionManager.h:30
TEveProjection::kPT_Unknown
@ kPT_Unknown
Definition: TEveProjections.h:29
TEveProjectable
Abstract base-class for non-linear projectable objects.
Definition: TEveProjectionBases.h:35
TEveElement::SetRnrSelf
virtual Bool_t SetRnrSelf(Bool_t rnr)
Set render state of this element, i.e.
Definition: TEveElement.cxx:1061
TEveProjection::GetName
const Char_t * GetName() const
Definition: TEveProjections.h:94
TEveProjectionManager.h
TEveElement::IsPickable
Bool_t IsPickable() const
Definition: TEveElement.h:341
TEveProjectionManager::UpdateName
virtual void UpdateName()
Updates name to have consistent information with projection.
Definition: TEveProjectionManager.cxx:88
TEveElement::GetElementName
virtual const char * GetElementName() const
Virtual function for retrieving name of the element.
Definition: TEveElement.cxx:265
TEveProjectable::ProjectedClass
virtual TClass * ProjectedClass(const TEveProjection *p) const =0
TEveProjection::SetCenter
virtual void SetCenter(TEveVector &v)
Definition: TEveProjections.h:98
TEveElement::ElementChanged
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.
Definition: TEveElement.cxx:1852
TEveProjectionManager
Manager class for steering of projections and managing projected objects.
Definition: TEveProjectionManager.h:22
TEveProjectionManager::SetCenter
void SetCenter(Float_t x, Float_t y, Float_t z)
Set projection center and rebuild projected scene.
Definition: TEveProjectionManager.cxx:146
TClass::New
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition: TClass.cxx:4962
TEveCompound.h
TEveProjectionManager::ComputeBBox
virtual void ComputeBBox()
Virtual from TAttBBox; fill bounding-box information.
Definition: TEveProjectionManager.cxx:397
TEveProjectionManager::UpdateDependentElsAndScenes
virtual void UpdateDependentElsAndScenes(TEveElement *root)
Update dependent elements' bounding box and mark scenes containing element root or its children as re...
Definition: TEveProjectionManager.cxx:188
TVirtualViewer3D.h
TBuffer3D.h
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TEveElement::SetCompound
void SetCompound(TEveCompound *c)
Definition: TEveElement.h:149
TEveProjectionManager::ImportElements
virtual TEveElement * ImportElements(TEveElement *el, TEveElement *ext_list=0)
Recursively import elements and apply projection to the newly imported objects.
Definition: TEveProjectionManager.cxx:264
TAttBBox::ComputeBBox
virtual void ComputeBBox()=0
TEveElement::AddElement
virtual void AddElement(TEveElement *el)
Add el to the list of children.
Definition: TEveElement.cxx:1324
TEveProjection::GetDistortion
Float_t GetDistortion() const
Definition: TEveProjections.h:120
TAttBBox::BBoxInit
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition: TAttBBox.cxx:29
TBuffer3DTypes.h
TEveProjectionManager::fCenter
TEveVector fCenter
Definition: TEveProjectionManager.h:31
TEveProjectionManager::ImportElementsRecurse
virtual TEveElement * ImportElementsRecurse(TEveElement *el, TEveElement *parent)
If el is TEveProjectable add projected instance else add plain TEveElementList to parent.
Definition: TEveProjectionManager.cxx:210
TEveProjectionManager::SubImportElements
virtual TEveElement * SubImportElements(TEveElement *el, TEveElement *proj_parent)
Recursively import elements and apply projection to the newly imported objects.
Definition: TEveProjectionManager.cxx:296
TEveProjected::SetDepth
virtual void SetDepth(Float_t d)
Set depth coordinate for the element.
Definition: TEveProjectionBases.cxx:219
y
Double_t y[n]
Definition: legend1.C:17
TEveElement::StampTransBBox
void StampTransBBox()
Definition: TEveElement.h:398
TEveProjectionManager::~TEveProjectionManager
virtual ~TEveProjectionManager()
Destructor.
Definition: TEveProjectionManager.cxx:57
TEveProjectionManager::ProjectChildren
virtual void ProjectChildren()
Project all children recursively, update bounding-box and notify TEveManger about the scenes that hav...
Definition: TEveProjectionManager.cxx:379
TEveProjectionManager::ShouldImport
virtual Bool_t ShouldImport(TEveElement *el)
Returns true if element el should be imported.
Definition: TEveProjectionManager.cxx:171
TEveManager.h
TEveException
Exception class thrown by TEve classes and macros.
Definition: TEveUtil.h:102
TEveProjected
Abstract base class for classes that hold results of a non-linear projection transformation.
Definition: TEveProjectionBases.h:84
TEveElement::GetCompound
TEveCompound * GetCompound()
Definition: TEveElement.h:148
TEveElement::GetElementTitle
virtual const char * GetElementTitle() const
Virtual function for retrieving title of the render-element.
Definition: TEveElement.cxx:278
TEveElement::SetRnrChildren
virtual Bool_t SetRnrChildren(Bool_t rnr)
Set render state of this element's children, i.e.
Definition: TEveElement.cxx:1083
TEveElement::BeginChildren
List_i BeginChildren()
Definition: TEveElement.h:166
TEveElement::List_t
std::list< TEveElement * > List_t
Definition: TEveElement.h:71
TEveXZProjection
XZ projection with distortion around given center.
Definition: TEveProjections.h:210
TEveProjectionManager::SetProjection
void SetProjection(TEveProjection::EPType_e type)
Set projection type and distortion.
Definition: TEveProjectionManager.cxx:99
TEveElement::EndChildren
List_i EndChildren()
Definition: TEveElement.h:167
type
int type
Definition: TGX11.cxx:121
Class
void Class()
Definition: Class.C:29
TEveProjection::kPT_XZ
@ kPT_XZ
Definition: TEveProjections.h:29
TEveProjectionManager::fProjections
TEveProjection * fProjections[TEveProjection::kPT_End]
Definition: TEveProjectionManager.h:28
TEveProjectionManager::fCurrentDepth
Float_t fCurrentDepth
Definition: TEveProjectionManager.h:32
TEveElement::CollectSceneParentsFromChildren
virtual void CollectSceneParentsFromChildren(List_t &scenes, TEveElement *parent)
Collect scene-parents from all children.
Definition: TEveElement.cxx:705
TEveRhoZProjection
Transformation from 3D to 2D.
Definition: TEveProjections.h:160
TEveVectorT::Set
void Set(const Float_t *v)
Definition: TEveVector.h:82
TEveProjectionManager::RemoveDependent
void RemoveDependent(TEveElement *el)
Remove el as dependent element.
Definition: TEveProjectionManager.cxx:80
int