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
37
38////////////////////////////////////////////////////////////////////////////////
39/// Constructor.
40
41TEveScene::TEveScene(const char* n, const char* t) :
43 fPad (0),
44 fGLScene(0),
45 fChanged (kFALSE),
46 fSmartRefresh (kTRUE),
47 fHierarchical (kFALSE)
48{
49 fPad = new TEvePad;
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// Constructor.
59
60TEveScene::TEveScene(TGLScenePad* gl_scene, const char* n, const char* t) :
62 fPad (0),
63 fGLScene(gl_scene),
64 fChanged (kFALSE),
65 fSmartRefresh (kTRUE),
66 fHierarchical (kFALSE)
67{
68 fPad = new TEvePad;
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// Destructor.
78
80{
82
85 delete fGLScene;
86 delete fPad;
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Virtual from TEveElement; here we simply append this scene to
91/// the list.
92
94{
95 scenes.push_back(this);
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Repaint the scene.
100
101void TEveScene::Repaint(Bool_t dropLogicals)
102{
103 if (dropLogicals) fGLScene->SetSmartRefresh(kFALSE);
105 if (dropLogicals) fGLScene->SetSmartRefresh(kTRUE);
107
108 // Hack to propagate selection state to physical shapes.
109 //
110 // Should actually be published in PadPaint() following a direct
111 // AddObject() call, but would need some other stuff for that.
112 // Optionally, this could be exported via the TAtt3D and everything
113 // would be sweet.
114
116 TEveElement* elm;
117 for (TGLScene::LogicalShapeMapIt_t li = logs.begin(); li != logs.end(); ++li)
118 {
119 elm = dynamic_cast<TEveElement*>(li->first);
120 if (elm && li->second->Ref() == 1)
121 {
122 TGLPhysicalShape* pshp = const_cast<TGLPhysicalShape*>(li->second->GetFirstPhysical());
123 pshp->Select(elm->GetSelectedLevel());
124 }
125 }
126
127 // Fix positions for hierarchical scenes.
128 if (fHierarchical)
129 {
131 }
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// Entry point for hierarchical transformation update.
136/// Calls the recursive variant on all children.
137
139{
141
143
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Set transformation matrix for physical shape of element el in
149/// the GL-scene and recursively descend into children (if enabled).
150
152{
153 static const TEveException eh("TEveScene::RetransHierarchicallyRecurse ");
154
155 TEveTrans t(tp);
156 if (el->HasMainTrans())
157 t *= el->RefMainTrans();
158
159 if (el->GetRnrSelf() && el != this)
160 {
162 }
163
164 if (el->GetRnrChildren())
165 {
166 for (List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
167 {
168 if ((*i)->GetRnrAnything())
170 }
171 }
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// Set scene's name.
176
177void TEveScene::SetName(const char* n)
178{
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Paint the scene. Iterate over children and calls PadPaint().
185
187{
188 if (GetRnrState())
189 {
190 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
191 (*i)->PadPaint(option);
192 }
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// Remove element from the scene.
197/// It is not an error if the element is not found in the scene.
198
200{
201 static const TEveException eh("TEveScene::DestroyElementRenderers ");
202
204 Bool_t changed = fGLScene->DestroyLogical(element->GetRenderObject(eh), kFALSE);
205 fGLScene->EndUpdate(changed, changed);
206}
207
208////////////////////////////////////////////////////////////////////////////////
209/// Remove element represented by object rnrObj from the scene.
210/// It is not an error if the element is not found in the scene.
211
213{
215 Bool_t changed = fGLScene->DestroyLogical(rnrObj, kFALSE);
216 fGLScene->EndUpdate(changed, changed);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Return icon for scene.
221
223{
225}
226
227/** \class TEveSceneList
228\ingroup TEve
229List of Scenes providing common operations on TEveScene collections.
230*/
231
233
234////////////////////////////////////////////////////////////////////////////////
235/// Constructor.
236
237TEveSceneList::TEveSceneList(const char* n, const char* t) :
239{
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Destroy all scenes and their contents.
245/// Tho object with non-zero deny-destroy will still survive.
246
248{
249 List_i i = fChildren.begin();
250 while (i != fChildren.end())
251 {
252 TEveScene* s = (TEveScene*) *(i++);
253 s->DestroyElements();
254 s->DestroyOrWarn();
255 }
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Repaint scenes that are tagged as changed.
260
262{
263 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
264 {
265 TEveScene* s = (TEveScene*) *i;
266 if (s->IsChanged())
267 {
268 s->Repaint(dropLogicals);
269 }
270 }
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Repaint all scenes.
275
277{
278 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
279 {
280 ((TEveScene*) *i)->Repaint(dropLogicals);
281 }
282}
283
284////////////////////////////////////////////////////////////////////////////////
285/// Loop over all scenes and remove all instances of element from them.
286
288{
289 static const TEveException eh("TEveSceneList::DestroyElementRenderers ");
290
291 TObject* obj = element->GetRenderObject(eh);
292 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
293 {
294 ((TEveScene*)*i)->DestroyElementRenderers(obj);
295 }
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Loop over all scenes and update them accordingly:
300/// 1. if scene is marked as changed, it is repainted;
301/// 2. otherwise iteration is done over the set of stamped elements and
302/// their physical/logical shapes are updated accordingly.
303///
304/// This allows much finer update granularity without resetting of
305/// complex GL-viewer and GL-scene state.
306
308{
309 // We need changed elements sorted by their "render object" as we do
310 // parallel iteration over this list and the list of logical shapes
311 // in every scene.
312
313 static const TEveException eh("TEveSceneList::ProcessSceneChanges ");
314
315 typedef std::map<TObject*, TEveElement*> mObjectElement_t;
316 typedef mObjectElement_t::iterator mObjectElement_i;
317
318 mObjectElement_t changed_objects;
319 {
320 Long64_t key, value;
321 TExMapIter stamped_elements(stampMap);
322 while (stamped_elements.Next(key, value))
323 {
324 TEveElement *el = reinterpret_cast<TEveElement*>(key);
325 changed_objects.insert(std::make_pair(el->GetRenderObject(eh), el));
326 }
327 }
328
329 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
330 {
331 TEveScene* s = (TEveScene*) *i;
332
333 if (s->IsChanged())
334 {
335 s->Repaint(dropLogicals);
336 }
337 else
338 {
339 Bool_t updateViewers = kFALSE;
340 Bool_t incTimeStamp = kFALSE;
341 Bool_t transbboxChg = kFALSE;
342
343 s->GetGLScene()->BeginUpdate();
344
345 // Process stamps.
347 TGLScene::LogicalShapeMapIt_t li = logs.begin();
348
349 mObjectElement_i ei = changed_objects.begin();
350
351 while (li != logs.end() && ei != changed_objects.end())
352 {
353 if (li->first == ei->first)
354 {
355 if (li->second->Ref() != 1)
356 Warning("TEveSceneList::ProcessSceneChanges",
357 "Expect one physical, cnt=%u.", li->second->Ref());
358
359 TGLLogicalShape *lshp = li->second;
360 TGLPhysicalShape *pshp = const_cast<TGLPhysicalShape*>(lshp->GetFirstPhysical());
361 TEveElement *el = ei->second;
362 UChar_t bits = el->GetChangeBits();
363
364 if (bits & kCBColorSelection)
365 {
366 pshp->Select(el->GetSelectedLevel());
367 pshp->SetDiffuseColor(el->GetMainColor(),
368 el->GetMainTransparency());
369 }
370
371 if (bits & kCBTransBBox)
372 {
373 if (el->HasMainTrans())
374 pshp->SetTransform(el->PtrMainTrans()->Array());
375 lshp->UpdateBoundingBox();
376 incTimeStamp = kTRUE;
377 transbboxChg = kTRUE;
378 }
379
380 if (bits & kCBObjProps)
381 {
382 lshp->DLCacheClear();
383 }
384
385 ++li; ++ei;
386 updateViewers = kTRUE;
387 }
388 else if (li->first < ei->first)
389 {
390 ++li;
391 }
392 else
393 {
394 ++ei;
395 }
396 }
397
398 s->GetGLScene()->EndUpdate(updateViewers, incTimeStamp, updateViewers);
399
400 // Fix positions for hierarchical scenes.
401 if (s->GetHierarchical() && transbboxChg)
402 {
404 }
405 }
406 }
407}
unsigned char UChar_t
Definition RtypesCore.h:38
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
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
A list of TEveElements.
void SetChildClass(TClass *c)
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
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 void RemoveElement(TEveElement *el)
Remove el from the list of children.
virtual Bool_t GetRnrChildren() const
static const TGPicture * fgListTreeIcons[9]
Definition TEveElement.h:65
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
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
List of Scenes providing common operations on TEveScene collections.
Definition TEveScene.h:80
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:79
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:93
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.
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:412
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)
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
void Add(TObject *obj) override
Definition TList.h:81
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
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:973
TList * GetListOfPrimitives() const override
Definition TPad.h:243
const Int_t n
Definition legend1.C:16