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),
47{
48 fPad = new TEvePad;
49 fPad->Add(this);
51 fGLScene->SetName(n);
52 fGLScene->SetAutoDestruct(kFALSE);
53 fGLScene->SetSmartRefresh(kTRUE);
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Constructor.
58
59TEveScene::TEveScene(TGLScenePad* gl_scene, const char* n, const char* t) :
61 fPad (nullptr),
62 fGLScene(gl_scene),
66{
67 fPad = new TEvePad;
68 fPad->Add(this);
69 fGLScene->SetPad(fPad);
70 fGLScene->SetName(n);
71 fGLScene->SetAutoDestruct(kFALSE);
72 fGLScene->SetSmartRefresh(kTRUE);
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Destructor.
77
79{
81
82 gEve->GetViewers()->SceneDestructing(this);
83 gEve->GetScenes()->RemoveElement(this);
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
100void TEveScene::Repaint(Bool_t dropLogicals)
101{
102 if (dropLogicals) fGLScene->SetSmartRefresh(kFALSE);
103 fGLScene->PadPaint(fPad);
104 if (dropLogicals) fGLScene->SetSmartRefresh(kTRUE);
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
114 TGLScene::LogicalShapeMap_t& logs = fGLScene->RefLogicalShapes();
115 TEveElement* elm;
116 for (TGLScene::LogicalShapeMapIt_t li = logs.begin(); li != logs.end(); ++li)
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
138{
139 fGLScene->BeginUpdate();
140
142
143 fGLScene->EndUpdate();
144}
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{
179 fGLScene->SetName(n);
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
202 fGLScene->BeginUpdate();
203 Bool_t changed = fGLScene->DestroyLogical(element->GetRenderObject(eh), kFALSE);
204 fGLScene->EndUpdate(changed, changed);
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
212{
213 fGLScene->BeginUpdate();
214 Bool_t changed = fGLScene->DestroyLogical(rnrObj, kFALSE);
215 fGLScene->EndUpdate(changed, changed);
216}
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 {
266 s->Repaint(dropLogicals);
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;
314 typedef mObjectElement_t::iterator mObjectElement_i;
315
316 mObjectElement_t changed_objects;
317 {
318 Long64_t key, value;
319 TExMapIter stamped_elements(stampMap);
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 {
333 s->Repaint(dropLogicals);
334 }
335 else
336 {
337 Bool_t updateViewers = kFALSE;
338 Bool_t incTimeStamp = kFALSE;
339 Bool_t transbboxChg = kFALSE;
340
341 s->GetGLScene()->BeginUpdate();
342
343 // Process stamps.
345 TGLScene::LogicalShapeMapIt_t li = logs.begin();
346
347 mObjectElement_i ei = changed_objects.begin();
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();
374 incTimeStamp = kTRUE;
375 transbboxChg = kTRUE;
376 }
377
378 if (bits & kCBObjProps)
379 {
380 lshp->DLCacheClear();
381 }
382
383 ++li; ++ei;
384 updateViewers = kTRUE;
385 }
386 else if (li->first < ei->first)
387 {
388 ++li;
389 }
390 else
391 {
392 ++ei;
393 }
394 }
395
396 s->GetGLScene()->EndUpdate(updateViewers, incTimeStamp, updateViewers);
397
398 // Fix positions for hierarchical scenes.
399 if (s->GetHierarchical() && transbboxChg)
400 {
402 }
403 }
404 }
405}
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
Definition RtypesCore.h:52
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
externTEveManager * gEve
TEveElementList(const char *n="TEveElementList", const char *t="", Bool_t doColor=kFALSE, Bool_t doTransparency=kFALSE)
Constructor.
void SetChildClass(TClass *c)
virtual TEveTrans * PtrMainTrans(Bool_t create=kTRUE)
Return pointer to main transformation.
Char_t fDestructing
!
List_t fChildren
Definition TEveElement.h:81
virtual UChar_t GetSelectedLevel() const
Get selection level, needed for rendering selection and highlight feedback.
virtual TEveTrans & RefMainTrans()
Return reference to main transformation.
List_i EndChildren()
std::list< TEveElement * > List_t
Definition TEveElement.h:71
virtual Bool_t GetRnrState() const
virtual void DestroyElements()
Destroy all children of this element.
virtual Color_t GetMainColor() const
virtual TObject * GetRenderObject(const TEveException &eh) const
virtual Bool_t GetRnrChildren() const
TEveElement()
Default constructor.
static const TGPicture * fgListTreeIcons[9]
Definition TEveElement.h:54
virtual Char_t GetMainTransparency() const
virtual void DestroyOrWarn()
Destroy this element. Prints a warning if deny-destroy is in force.
virtual Bool_t GetRnrSelf() const
List_i BeginChildren()
List_t::iterator List_i
Definition TEveElement.h:72
UChar_t GetChangeBits() const
virtual Bool_t HasMainTrans() const
Exception class thrown by TEve classes and macros.
Definition TEveUtil.h:102
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
Bool_t fSmartRefresh
Definition TEveScene.h:37
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
Bool_t Next(ULong64_t &hash, Long64_t &key, Long64_t &value)
Get next entry from TExMap. Returns kFALSE at end of map.
Definition TExMap.cxx:410
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.
virtual void UpdateBoundingBox()
virtual void DLCacheClear()
Clear all entries for all LODs for this drawable from the display list cache but keeping the reserved...
const TGLPhysicalShape * GetFirstPhysical() const
Concrete physical shape - a GL drawable.
void SetTransform(const TGLMatrix &transform)
void SetDiffuseColor(const Float_t rgba[4])
Set color from ROOT color index and transparency [0,100].
void Select(UChar_t select)
Implements VirtualViewer3D interface and fills the base-class visualization structures from pad conte...
Definition TGLScenePad.h:26
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.
LogicalShapeMap_t::iterator LogicalShapeMapIt_t
Definition TGLScene.h:43
std::map< TObject *, TGLLogicalShape * > LogicalShapeMap_t
Definition TGLScene.h:41
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
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1084
TObject()
TObject constructor.
Definition TObject.h:259
const Int_t n
Definition legend1.C:16