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),
42 fCurrentDepth(0),
43 fImportEmpty (kFALSE)
44{
45 for (Int_t i = 0; i < TEveProjection::kPT_End; ++i)
46 fProjections[i] = nullptr;
47
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
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 {
109 break;
110 }
112 {
114 break;
115 }
117 {
119 break;
120 }
122 {
124 break;
125 }
127 {
129 break;
130 }
132 {
134 break;
135 }
137 {
139 break;
140 }
141 default:
142 throw eH + "projection type not valid.";
143 break;
144 }
145 }
146
148 {
149 throw eH + "switching between 2D and 3D projections not implemented.";
150 }
151
154 UpdateName();
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// Set projection center and rebuild projected scene.
159
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();
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
190 if (el->IsA() != TEveElementList::Class() && el->IsA()->InheritsFrom(TEveProjectable::Class()))
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
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 {
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 {
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
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
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{
342 for (List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
343 {
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
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 }
382 el->ElementChanged(kFALSE);
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
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:2495
const_iterator begin() const
const_iterator end() const
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: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)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition TAttBBox.cxx:28
3D scaling projection.
Description of TEveCompound.
A list of TEveElements.
TEveElementList(const char *n="TEveElementList", const char *t="", Bool_t doColor=kFALSE, Bool_t doTransparency=kFALSE)
Constructor.
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
void StampTransBBox()
List_i EndChildren()
Bool_t HasChildren() const
std::list< TEveElement * > List_t
Definition TEveElement.h:71
virtual void CollectSceneParentsFromChildren(List_t &scenes, TEveElement *parent)
Collect scene-parents from all children.
List_i BeginChildren()
List_t::iterator List_i
Definition TEveElement.h:72
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()
Abstract base class for classes that hold results of a non-linear projection transformation.
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...
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:149
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17