Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveProjectionManager.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, 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
14#include <ROOT/REveManager.hxx>
16#include <ROOT/REveCompound.hxx>
17
18#include "TBuffer3D.h"
19#include "TBuffer3DTypes.h"
20
21#include "TClass.h"
22
23#include <list>
24
25/** \class REveProjectionManager
26\ingroup REve
27Manager class for steering of projections and managing projected objects.
28
29Recursively projects REveElement's and draws axis in the projected
30scene. It enables to interactively set REveProjection parameters
31and updates projected scene accordingly.
32*/
33
34using namespace ROOT::Experimental;
35namespace REX = ROOT::Experimental;
36
37////////////////////////////////////////////////////////////////////////////////
38/// Constructor.
39
40REveProjectionManager::REveProjectionManager(REveProjection::EPType_e type):
41 REveElement("REveProjectionManager","")
42{
43 for (Int_t i = 0; i < REveProjection::kPT_End; ++i)
44 fProjections[i] = nullptr;
45
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Destructor.
52/// Destroys also dependent elements.
53
55{
56 for (Int_t i = 0; i < REveProjection::kPT_End; ++i) {
57 delete fProjections[i];
58 }
59 while ( ! fDependentEls.empty()) {
60 fDependentEls.front()->Destroy();
61 }
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Add el as dependent element.
66
71
72////////////////////////////////////////////////////////////////////////////////
73/// Remove el as dependent element.
74
79
80////////////////////////////////////////////////////////////////////////////////
81/// Updates name to have consistent information with projection.
82
83////////////////////////////////////////////////////////////////////////////////
84/// Add `steps` * 1e-4 to the distortion of the current projection, clamped at
85/// zero, reproject, and refresh the REveProjectionAxis nieces. Called by MIR.
86
88{
89 if (!fProjection)
90 return;
91
92 Float_t d = fProjection->GetDistortion() + steps * 1e-4f;
93 if (d < 0.f)
94 d = 0.f;
96
97 UpdateName();
99
100 // Refresh the axes among the nieces.
101 for (auto &n : fNieces) {
102 if (auto ax = dynamic_cast<REveProjectionAxis *>(n)) {
103 ax->UpdateTicks();
104 ax->UpdateDistortionLabel();
105 }
106 }
107}
108
110{
111 if (fProjection->Is2D())
112 SetName(Form ("%s (%3.1f)", fProjection->GetName(), fProjection->GetDistortion()*1000));
113 else
115}
116
117////////////////////////////////////////////////////////////////////////////////
118/// Set projection type and distortion.
119
121{
122 static const REveException eH("REveProjectionManager::SetProjection ");
123
124 if (fProjections[type] == nullptr)
125 {
126 switch (type)
127 {
129 {
131 break;
132 }
134 {
136 break;
137 }
139 {
141 break;
142 }
144 {
146 break;
147 }
149 {
151 break;
152 }
154 {
156 break;
157 }
159 {
161 break;
162 }
163 default:
164 throw eH + "projection type not valid.";
165 break;
166 }
167 }
168
170 {
171 throw eH + "switching between 2D and 3D projections not implemented.";
172 }
173
176 UpdateName();
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Set projection center and rebuild projected scene.
181
188
189////////////////////////////////////////////////////////////////////////////////
190/// Returns true if element el should be imported.
191///
192/// Behaviour depends on the value of the fImportEmpty member:
193/// false - el or any of its children must be projectable (default);
194/// true - always import.
195
197{
198 if (fImportEmpty)
199 return kTRUE;
200
201 if (el->IsA()->InheritsFrom(TClass::GetClass<REveProjectable>()))
202 return kTRUE;
203 for (auto &c: el->RefChildren())
204 if (ShouldImport(c))
205 return kTRUE;
206 return kFALSE;
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Update dependent elements' bounding boxes.
211
213{
214 for (auto &d: fDependentEls) {
215 TAttBBox* bbox = dynamic_cast<TAttBBox *>(d);
216 if (bbox)
217 bbox->ComputeBBox();
218 }
219}
220
221////////////////////////////////////////////////////////////////////////////////
222/// If el is REveProjectable add projected instance else add plain
223/// REveElementList to parent. Call the same function on el's
224/// children.
225///
226/// Returns the projected replica of el. Can be 0, if el and none of
227/// its children are projectable.
228
230 REveElement* parent)
231{
232 static const REveException eh("REveProjectionManager::ImportElementsRecurse ");
233
234 REveElement *new_el = nullptr;
235
236 if (ShouldImport(el))
237 {
238 REveProjected *new_pr = nullptr;
239 REveProjectable *pble = dynamic_cast<REveProjectable*>(el);
240 if (pble)
241 {
242 new_el = (REveElement*) pble->ProjectedClass(fProjection)->New();
243 new_pr = dynamic_cast<REveProjected*>(new_el);
244 new_pr->SetProjection(this, pble);
245 new_pr->SetDepth(fCurrentDepth);
246 }
247 else
248 {
249 new_el = new REveElement;
250 }
251 new_el->SetName (Form("%s [P]", el->GetCName()));
252 new_el->SetTitle(Form("Projected replica.\n%s", el->GetCTitle()));
253 new_el->SetRnrSelf (el->GetRnrSelf());
254 new_el->SetRnrChildren (el->GetRnrChildren());
255 new_el->SetPickable (el->IsPickable());
256
257 parent->AddElement(new_el);
258
259 REveCompound *cmpnd = dynamic_cast<REveCompound*>(el);
260 REveCompound *cmpnd_pr = dynamic_cast<REveCompound*>(new_el);
261 for (auto &c: el->RefChildren()) {
262 REveElement *child_pr = ImportElementsRecurse(c, new_el);
263 if (cmpnd && c->GetCompound() == cmpnd)
264 child_pr->SetCompound(cmpnd_pr);
265 }
266 }
267
268 return new_el;
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Recursively import elements and apply projection to the newly
273/// imported objects.
274///
275/// If ext_list is not 0 the new element is also added to the list.
276/// This simplifies construction of complex views where projected
277/// elements are distributed into several scenes for optimization of
278/// updates and rendering.
279///
280/// Returns the projected replica of el. Can be 0, if el and none of
281/// its children are projectable.
282
284 REveElement* ext_list)
285{
286 REveElement* new_el = ImportElementsRecurse(el, ext_list ? ext_list : this);
287 if (new_el)
288 {
289 AssertBBox();
293
295
296 if (ext_list)
297 AddNiece(new_el);
298 }
299 return new_el;
300}
301
302////////////////////////////////////////////////////////////////////////////////
303/// Recursively import elements and apply projection to the newly
304/// imported objects.
305///
306/// The proj_parent argument should be a projected replica of parent
307/// of element 'el'. This allows to insert projected children of
308/// a given element when they are added after the projection has
309/// been already performed on the parent.
310/// This is called from REveElement::ProjectChild().
311///
312/// Returns the projected replica of el. Can be 0, if el and none of
313/// its children are projectable.
314
316 REveElement* proj_parent)
317{
318 REveElement* new_el = ImportElementsRecurse(el, proj_parent);
319 if (new_el)
320 {
321 AssertBBox();
325
327 }
328 return new_el;
329}
330
331////////////////////////////////////////////////////////////////////////////////
332/// Recursively import children elements of el and apply projection
333/// to the newly imported objects.
334///
335/// The proj_parent argument should be a projected replica of
336/// element 'el'. This allows to insert projected children of
337/// a given element when they are added after the projection has
338/// been already performed on the parent.
339/// This is called from REveElement::ProjectChild().
340///
341/// Returns the projected replica of el. Can be 0, if el and none of
342/// its children are projectable.
343
345{
346 List_t new_els;
347 for (auto &c: el->RefChildren()) {
348 auto new_el = ImportElementsRecurse(c, proj_parent);
349 if (new_el)
350 new_els.push_back(new_el);
351 }
352
353 if (!new_els.empty())
354 {
355 AssertBBox();
356 for (auto &nel: new_els)
360
361 UpdateDependentElements(proj_parent);
362 }
363 return (Int_t) new_els.size();
364}
365
366////////////////////////////////////////////////////////////////////////////////
367/// Project el (via REveProjected::UpdateProjection()) and recurse
368/// through el's children.
369/// Bounding-box is updated along the recursion.
370
372{
373 REveProjected* pted = dynamic_cast<REveProjected*>(el);
374 if (pted)
375 {
376 pted->UpdateProjection();
377 TAttBBox* bb = dynamic_cast<TAttBBox*>(pted);
378 if (bb)
379 {
380 Float_t* b = bb->AssertBBox();
381 BBoxCheckPoint(b[0], b[2], b[4]);
382 BBoxCheckPoint(b[1], b[3], b[5]);
383 }
384 el->StampObjProps();
385 }
386
387 for (auto &c : el->RefChildren()) ProjectChildrenRecurse(c);
388}
389
390////////////////////////////////////////////////////////////////////////////////
391/// Project all children recursively, update bounding-box and notify
392/// EveManger about the scenes that have been changed.
393
395{
396 BBoxInit();
397
398 for (auto &c : fChildren) ProjectChildrenRecurse(c);
399
400 for (auto &n : fNieces) ProjectChildrenRecurse(n);
401
404
406}
407
408////////////////////////////////////////////////////////////////////////////////
409/// Virtual from TAttBBox; fill bounding-box information.
410///
411/// The bounding-box information is kept coherent during addition of
412/// projected elements and projection parameter updates. This is
413/// called only in case the manager has not been populated at all.
414
416{
417 static const REveException eH("REveProjectionManager::ComputeBBox ");
418
419 if ( ! HasChildren() && ! HasNieces())
420 {
421 BBoxZero();
422 return;
423 }
424
425 BBoxInit();
426}
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
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:2571
virtual void AddNiece(REveElement *el)
TClass * IsA() const
Return class for this element Return REveElement class in case dicitonary is not exisiting.
const char * GetCTitle() const
void SetCompound(REveCompound *c)
const char * GetCName() const
virtual void AddElement(REveElement *el)
Add el to the list of children.
virtual Bool_t GetRnrSelf() const
virtual Bool_t SetRnrChildren(Bool_t rnr)
Set render state of this element's children, i.e.
void SetTitle(const std::string &title)
Set title of an element.
virtual Bool_t SetRnrSelf(Bool_t rnr)
Set render state of this element, i.e.
virtual Bool_t GetRnrChildren() const
std::list< REveElement * > List_t
REveElement(const std::string &name="", const std::string &title="")
Default constructor.
void SetName(const std::string &name)
Set name of an element.
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:42
virtual TClass * ProjectedClass(const REveProjection *p) const =0
virtual void SetProjection(REveProjectionManager *mng, REveProjectable *model)
Sets projection manager and reference in the projectable object.
virtual void SetDepth(Float_t d)
Set depth coordinate for the element.
REveProjection * fProjections[REveProjection::kPT_End]
void AddDependent(REveElement *el)
Add el as dependent element.
virtual REveElement * ImportElements(REveElement *el, REveElement *ext_list=nullptr)
Recursively import elements and apply projection to the newly imported objects.
virtual void UpdateDependentElements(REveElement *root)
Update dependent elements' bounding boxes.
void SetProjection(REveProjection::EPType_e type)
Set projection type and distortion.
virtual REveElement * ImportElementsRecurse(REveElement *el, REveElement *parent)
If el is REveProjectable add projected instance else add plain REveElementList to parent.
void ComputeBBox() override
Virtual from TAttBBox; fill bounding-box information.
virtual REveElement * SubImportElements(REveElement *el, REveElement *proj_parent)
Recursively import elements and apply projection to the newly imported objects.
void RemoveDependent(REveElement *el)
Remove el as dependent element.
void BumpDistortion(Int_t steps)
Updates name to have consistent information with projection.
virtual void ProjectChildren()
Project all children recursively, update bounding-box and notify EveManger about the scenes that have...
virtual void ProjectChildrenRecurse(REveElement *el)
Project el (via REveProjected::UpdateProjection()) and recurse through el's children.
void SetCenter(Float_t x, Float_t y, Float_t z)
Set projection center and rebuild projected scene.
virtual Bool_t ShouldImport(REveElement *el)
Returns true if element el should be imported.
virtual Int_t SubImportChildren(REveElement *el, REveElement *proj_parent)
Recursively import children elements of el and apply projection to the newly imported objects.
virtual void SetCenter(REveVector &v)
virtual Bool_t Is2D() const =0
void SetDistortion(Float_t d)
Set distortion.
void Set(const Float_t *v)
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)
Allocate and prepare for incremental filling.
Definition TAttBBox.cxx:28
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:5111
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4995
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Namespace for ROOT features in testing.
Definition TROOT.h:100