Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveScene.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 "TEveScene.h"
13#include "TEveViewer.h"
14#include "TEveManager.h"
15#include "TEveTrans.h"
16#include "TEvePad.h"
17
18#include "TGLScenePad.h"
19#include "TGLLogicalShape.h"
20#include "TGLPhysicalShape.h"
21
22#include "TList.h"
23#include "TExMap.h"
24
25/** \class TEveScene
26\ingroup TEve
27Eve representation of TGLScene.
28The GLScene is owned by this class - it is created on construction
29time and deleted at destruction.
30
31Normally all objects are positioned directly in global scene-space.
32By setting the fHierarchical flag, positions of children get
33calculated by multiplying the transformation matrices of all parents.
34*/
35
36
37////////////////////////////////////////////////////////////////////////////////
38/// Constructor.
39
40TEveScene::TEveScene(const char* n, const char* t) :
42 fPad (nullptr),
43 fGLScene(nullptr),
44 fChanged (kFALSE),
45 fSmartRefresh (kTRUE),
46 fHierarchical (kFALSE)
47{
48 fPad = new TEvePad;
49 fPad->Add(this);
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Constructor.
58
59TEveScene::TEveScene(TGLScenePad* gl_scene, const char* n, const char* t) :
61 fPad (nullptr),
62 fGLScene(gl_scene),
63 fChanged (kFALSE),
64 fSmartRefresh (kTRUE),
65 fHierarchical (kFALSE)
66{
67 fPad = new TEvePad;
68 fPad->Add(this);
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Destructor.
77
79{
81
84 delete fGLScene;
85 delete fPad;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Virtual from TEveElement; here we simply append this scene to
90/// the list.
91
93{
94 scenes.push_back(this);
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Repaint the scene.
99
101{
106
107 // Hack to propagate selection state to physical shapes.
108 //
109 // Should actually be published in PadPaint() following a direct
110 // AddObject() call, but would need some other stuff for that.
111 // Optionally, this could be exported via the TAtt3D and everything
112 // would be sweet.
113
117 {
118 elm = dynamic_cast<TEveElement*>(li->first);
119 if (elm && li->second->Ref() == 1)
120 {
121 TGLPhysicalShape* pshp = const_cast<TGLPhysicalShape*>(li->second->GetFirstPhysical());
122 pshp->Select(elm->GetSelectedLevel());
123 }
124 }
125
126 // Fix positions for hierarchical scenes.
127 if (fHierarchical)
128 {
130 }
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Entry point for hierarchical transformation update.
135/// Calls the recursive variant on all children.
136
145
146////////////////////////////////////////////////////////////////////////////////
147/// Set transformation matrix for physical shape of element el in
148/// the GL-scene and recursively descend into children (if enabled).
149
151{
152 static const TEveException eh("TEveScene::RetransHierarchicallyRecurse ");
153
154 TEveTrans t(tp);
155 if (el->HasMainTrans())
156 t *= el->RefMainTrans();
157
158 if (el->GetRnrSelf() && el != this)
159 {
160 fGLScene->UpdatePhysioLogical(el->GetRenderObject(eh), t.Array(), nullptr);
161 }
162
163 if (el->GetRnrChildren())
164 {
165 for (List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
166 {
167 if ((*i)->GetRnrAnything())
169 }
170 }
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Set scene's name.
175
176void TEveScene::SetName(const char* n)
177{
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Paint the scene. Iterate over children and calls PadPaint().
184
186{
187 if (GetRnrState())
188 {
189 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
190 (*i)->PadPaint(option);
191 }
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// Remove element from the scene.
196/// It is not an error if the element is not found in the scene.
197
199{
200 static const TEveException eh("TEveScene::DestroyElementRenderers ");
201
203 Bool_t changed = fGLScene->DestroyLogical(element->GetRenderObject(eh), kFALSE);
205}
206
207////////////////////////////////////////////////////////////////////////////////
208/// Remove element represented by object rnrObj from the scene.
209/// It is not an error if the element is not found in the scene.
210
217
218////////////////////////////////////////////////////////////////////////////////
219/// Return icon for scene.
220
225
226/** \class TEveSceneList
227\ingroup TEve
228List of Scenes providing common operations on TEveScene collections.
229*/
230
231
232////////////////////////////////////////////////////////////////////////////////
233/// Constructor.
234
235TEveSceneList::TEveSceneList(const char* n, const char* t) :
237{
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Destroy all scenes and their contents.
243/// Tho object with non-zero deny-destroy will still survive.
244
246{
247 List_i i = fChildren.begin();
248 while (i != fChildren.end())
249 {
250 TEveScene* s = (TEveScene*) *(i++);
251 s->DestroyElements();
252 s->DestroyOrWarn();
253 }
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// Repaint scenes that are tagged as changed.
258
260{
261 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
262 {
263 TEveScene* s = (TEveScene*) *i;
264 if (s->IsChanged())
265 {
267 }
268 }
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Repaint all scenes.
273
275{
276 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
277 {
278 ((TEveScene*) *i)->Repaint(dropLogicals);
279 }
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Loop over all scenes and remove all instances of element from them.
284
286{
287 static const TEveException eh("TEveSceneList::DestroyElementRenderers ");
288
289 TObject* obj = element->GetRenderObject(eh);
290 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
291 {
292 ((TEveScene*)*i)->DestroyElementRenderers(obj);
293 }
294}
295
296////////////////////////////////////////////////////////////////////////////////
297/// Loop over all scenes and update them accordingly:
298/// 1. if scene is marked as changed, it is repainted;
299/// 2. otherwise iteration is done over the set of stamped elements and
300/// their physical/logical shapes are updated accordingly.
301///
302/// This allows much finer update granularity without resetting of
303/// complex GL-viewer and GL-scene state.
304
306{
307 // We need changed elements sorted by their "render object" as we do
308 // parallel iteration over this list and the list of logical shapes
309 // in every scene.
310
311 static const TEveException eh("TEveSceneList::ProcessSceneChanges ");
312
313 typedef std::map<TObject*, TEveElement*> mObjectElement_t;
315
317 {
318 Long64_t key, value;
320 while (stamped_elements.Next(key, value))
321 {
322 TEveElement *el = reinterpret_cast<TEveElement*>(key);
323 changed_objects.insert(std::make_pair(el->GetRenderObject(eh), el));
324 }
325 }
326
327 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
328 {
329 TEveScene* s = (TEveScene*) *i;
330
331 if (s->IsChanged())
332 {
334 }
335 else
336 {
340
341 s->GetGLScene()->BeginUpdate();
342
343 // Process stamps.
346
348
349 while (li != logs.end() && ei != changed_objects.end())
350 {
351 if (li->first == ei->first)
352 {
353 if (li->second->Ref() != 1)
354 Warning("TEveSceneList::ProcessSceneChanges",
355 "Expect one physical, cnt=%u.", li->second->Ref());
356
357 TGLLogicalShape *lshp = li->second;
358 TGLPhysicalShape *pshp = const_cast<TGLPhysicalShape*>(lshp->GetFirstPhysical());
359 TEveElement *el = ei->second;
360 UChar_t bits = el->GetChangeBits();
361
362 if (bits & kCBColorSelection)
363 {
364 pshp->Select(el->GetSelectedLevel());
365 pshp->SetDiffuseColor(el->GetMainColor(),
366 el->GetMainTransparency());
367 }
368
369 if (bits & kCBTransBBox)
370 {
371 if (el->HasMainTrans())
372 pshp->SetTransform(el->PtrMainTrans()->Array());
373 lshp->UpdateBoundingBox();
376 }
377
378 if (bits & kCBObjProps)
379 {
380 lshp->DLCacheClear();
381 }
382
383 ++li; ++ei;
385 }
386 else if (li->first < ei->first)
387 {
388 ++li;
389 }
390 else
391 {
392 ++ei;
393 }
394 }
395
397
398 // Fix positions for hierarchical scenes.
399 if (s->GetHierarchical() && transbboxChg)
400 {
402 }
403 }
404 }
405}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
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 option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
const_iterator begin() const
const_iterator end() const
A list of TEveElements.
void SetChildClass(TClass *c)
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
Char_t fDestructing
List_t fChildren
Definition TEveElement.h:81
virtual TEveTrans & RefMainTrans()
Return reference to main transformation.
std::list< TEveElement * > List_t
Definition TEveElement.h:71
virtual Bool_t GetRnrState() const
virtual void DestroyElements()
Destroy all children of this element.
virtual void RemoveElement(TEveElement *el)
Remove el from the list of children.
static const TGPicture * fgListTreeIcons[9]
Definition TEveElement.h:54
virtual void DestroyOrWarn()
Destroy this element. Prints a warning if deny-destroy is in force.
List_t::iterator List_i
Definition TEveElement.h:72
Exception class thrown by TEve classes and macros.
Definition TEveUtil.h:102
TEveViewerList * GetViewers() const
TEveSceneList * GetScenes() const
This was intended as a TPad wrapper to allow smart updates of groups of pads.
Definition TEvePad.h:18
void DestroyScenes()
Destroy all scenes and their contents.
void DestroyElementRenderers(TEveElement *element)
Loop over all scenes and remove all instances of element from them.
void RepaintAllScenes(Bool_t dropLogicals)
Repaint all scenes.
TEveSceneList(const TEveSceneList &)
void ProcessSceneChanges(Bool_t dropLogicals, TExMap *stampMap)
Loop over all scenes and update them accordingly:
void RepaintChangedScenes(Bool_t dropLogicals)
Repaint scenes that are tagged as changed.
Eve representation of TGLScene.
Definition TEveScene.h:27
TEvePad * fPad
Definition TEveScene.h:33
void DestroyElementRenderers(TEveElement *element)
Remove element from the scene.
~TEveScene() override
Destructor.
Definition TEveScene.cxx:78
const TGPicture * GetListTreeIcon(Bool_t open=kFALSE) override
Return icon for scene.
void RetransHierarchicallyRecurse(TEveElement *el, const TEveTrans &tp)
Set transformation matrix for physical shape of element el in the GL-scene and recursively descend in...
Bool_t IsChanged() const
Definition TEveScene.h:52
Bool_t fChanged
Definition TEveScene.h:36
void Repaint(Bool_t dropLogicals=kFALSE)
Repaint the scene.
void RetransHierarchically()
Entry point for hierarchical transformation update.
TEveScene(const TEveScene &)
Bool_t fHierarchical
Definition TEveScene.h:38
Bool_t GetHierarchical() const
Definition TEveScene.h:55
static TClass * Class()
void Paint(Option_t *option="") override
Paint the scene. Iterate over children and calls PadPaint().
TGLScenePad * fGLScene
Definition TEveScene.h:34
void CollectSceneParents(List_t &scenes) override
Virtual from TEveElement; here we simply append this scene to the list.
Definition TEveScene.cxx:92
TGLScenePad * GetGLScene() const
Definition TEveScene.h:60
void SetName(const char *n) override
Set scene's name.
TEveTrans is a 4x4 transformation matrix for homogeneous coordinates stored internally in a column-ma...
Definition TEveTrans.h:27
Double_t * Array()
Definition TEveTrans.h:94
void SceneDestructing(TEveScene *scene)
Callback done from a TEveScene destructor allowing proper removal of the scene from affected viewers.
This class stores a (key,value) pair using an external hash.
Definition TExMap.h:33
Abstract logical shape - a GL 'drawable' - base for all shapes - faceset sphere etc.
Concrete physical shape - a GL drawable.
void SetAutoDestruct(Bool_t a)
virtual void SetName(const char *name)
Implements VirtualViewer3D interface and fills the base-class visualization structures from pad conte...
Definition TGLScenePad.h:26
void PadPaint(TVirtualPad *pad) override
Entry point for updating scene contents via VirtualViewer3D interface.
void SetSmartRefresh(Bool_t smart_ref)
Definition TGLScenePad.h:73
void SetPad(TVirtualPad *p)
Definition TGLScenePad.h:63
virtual Bool_t BeginUpdate()
Put scene in update mode, return true if lock acquired.
virtual void EndUpdate(Bool_t minorChange=kTRUE, Bool_t sceneChanged=kTRUE, Bool_t updateViewers=kTRUE)
Exit scene update mode.
virtual Bool_t DestroyLogical(TObject *logid, Bool_t mustFind=kTRUE)
Destroy logical shape defined by unique 'ID'.
LogicalShapeMap_t::iterator LogicalShapeMapIt_t
Definition TGLScene.h:43
std::map< TObject *, TGLLogicalShape * > LogicalShapeMap_t
Definition TGLScene.h:41
virtual void UpdatePhysioLogical(TObject *logid, Double_t *trans, UChar_t *col)
Reposition/recolor physical for given logical (assume TGLObject and a single physical).
LogicalShapeMap_t & RefLogicalShapes()
Definition TGLScene.h:216
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
void Add(TObject *obj, Option_t *opt="", Bool_t modified=kTRUE) override
Add an object to list of primitives with speicified draw option When.
Definition TPad.cxx:416
const Int_t n
Definition legend1.C:16