Logo ROOT   6.10/09
Reference Guide
TEveProjectionBases.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 "TEveProjectionBases.h"
13 #include "TEveProjectionManager.h"
14 #include "TEveManager.h"
15 
16 #include <cassert>
17 
18 /** \class TEveProjectable
19 \ingroup TEve
20 Abstract base-class for non-linear projectable objects.
21 
22 Via ProjectedClass(const TEveProjection* p) method it returns a
23 TClass instance for the projected class and keeps references to the
24 projected objects.
25 
26 It is assumed that all classes deriving from TEveProjectable are also
27 derived from TEveElement.
28 
29 See also TEveProjectionManager::ImportElements().
30 */
31 
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// Constructor.
36 
38 {
39 }
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Destructor.
43 /// Force projected replicas to unreference *this, then destroy them.
44 
46 {
47  while ( ! fProjectedList.empty())
48  {
49  TEveProjected* p = fProjectedList.front();
50  p->UnRefProjectable(this);
52  assert(el);
53  {
55  delete el;
56  }
57  }
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Optimized destroy of projected elements with condition
62 /// there is only one parent for projected element. Method is
63 /// called from TEveElement::Annihilate().
64 
66 {
67  for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
68  {
69  (*i)->UnRefProjectable(this, kFALSE);
70  (*i)->GetProjectedAsElement()->Annihilate();
71  }
72  fProjectedList.clear();
73 }
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 
78 {
79  fProjectedList.clear();
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Add the projected elements to the set, dyn-casting them to
84 /// TEveElement.
85 
86 void TEveProjectable::AddProjectedsToSet(std::set<TEveElement*>& set)
87 {
88  for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
89  {
90  set.insert((*i)->GetProjectedAsElement());
91  }
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// Set visualization parameters of projecteds.
96 /// Use element el as model. If el == 0 (default), this casted to
97 /// TEveElement is used.
98 
100 {
101  if (el == 0)
102  el = dynamic_cast<TEveElement*>(this);
103 
104  for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
105  {
106  (*i)->GetProjectedAsElement()->CopyVizParams(el);
107  }
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Set render state of projecteds.
112 
114 {
115  for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
116  {
117  if ((*i)->GetProjectedAsElement()->SetRnrSelfChildren(rnr_self, rnr_children))
118  (*i)->GetProjectedAsElement()->ElementChanged();
119  }
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Set main color of projecteds if their color is the same as old_color.
124 
126 {
127  for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
128  {
129  if ((*i)->GetProjectedAsElement()->GetMainColor() == old_color)
130  (*i)->GetProjectedAsElement()->SetMainColor(color);
131  }
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// Set main transparency of projecteds if their transparency is the
136 /// same as the old one.
137 
139 {
140  for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
141  {
142  if ((*i)->GetProjectedAsElement()->GetMainTransparency() == old_t)
143  (*i)->GetProjectedAsElement()->SetMainTransparency(t);
144  }
145 }
146 
147 /** \class TEveProjected
148 \ingroup TEve
149 Abstract base class for classes that hold results of a non-linear
150 projection transformation.
151 
152 It is assumed that all classes deriving from TEveProjected are also
153 derived from TEveElement.
154 */
155 
157 
158 ////////////////////////////////////////////////////////////////////////////////
159 /// Constructor.
160 
162  fManager (0),
163  fProjectable (0),
164  fDepth (0)
165 {
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Destructor.
170 /// If fProjectable is non-null, *this is removed from its list of
171 /// projected replicas.
172 
174 {
176 }
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Returns this projected dynamic-casted to TEveElement.
180 /// This is needed as class TEveProjected is used as secondary
181 /// inheritance.
182 
184 {
185  return dynamic_cast<TEveElement*>(this);
186 }
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Sets projection manager and reference in the projectable object. Method called
190 /// immediately after default constructor.
191 /// See also TEveProjectionManager::ImportElements().
192 
194 {
195  fManager = mng;
199 }
200 
201 ////////////////////////////////////////////////////////////////////////////////
202 /// Remove reference to projectable.
203 
204 void TEveProjected::UnRefProjectable(TEveProjectable* assumed_parent, bool notifyParent)
205 {
206  static const TEveException eH("TEveProjected::UnRefProjectable ");
207 
208  R__ASSERT(fProjectable == assumed_parent);
209 
210  if (notifyParent) fProjectable->RemoveProjected(this);
211  fProjectable = 0;
212 }
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 /// Set depth coordinate for the element.
216 /// Bounding-box should also be updated.
217 /// If projection type is 3D, this only sets fDepth member.
218 
220 {
221  if (fManager->GetProjection()->Is2D())
222  {
223  SetDepthLocal(d);
224  }
225  else
226  {
227  fDepth = d;
228  }
229 }
230 
231 ////////////////////////////////////////////////////////////////////////////////
232 /// Utility function to update the z-values of the bounding-box.
233 /// As this is an abstract interface, the element and bbox pointers
234 /// must be passed from outside.
235 
237 {
238  Float_t delta = d - fDepth;
239  fDepth = d;
240  if (bbox) {
241  bbox[4] += delta;
242  bbox[5] += delta;
243  el->StampTransBBox();
244  }
245 }
246 
247 ////////////////////////////////////////////////////////////////////////////////
248 /// Base-class implementation -- just sets fDepth.
249 
251 {
252  fDepth = d;
253 }
virtual void AnnihilateProjecteds()
Optimized destroy of projected elements with condition there is only one parent for projected element...
Abstract base class for classes that hold results of a non-linear projection transformation.
float Float_t
Definition: RtypesCore.h:53
virtual Bool_t Is2D() const =0
#define R__ASSERT(e)
Definition: TError.h:96
virtual void PropagateMainTransparency(Char_t t, Char_t old_t)
Set main transparency of projecteds if their transparency is the same as the old one.
virtual void CopyVizParams(const TEveElement *el)
Copy visualization parameters from element el.
TEveProjected()
Constructor.
bool Bool_t
Definition: RtypesCore.h:59
virtual void RemoveProjected(TEveProjected *p)
virtual void SetProjection(TEveProjectionManager *mng, TEveProjectable *model)
Sets projection manager and reference in the projectable object.
Float_t delta
virtual ~TEveProjectable()
Destructor.
virtual void PropagateRenderState(Bool_t rnr_self, Bool_t rnr_children)
Set render state of projecteds.
Manager class for steering of projections and managing projected objects.
short Color_t
Definition: RtypesCore.h:79
virtual void SetDepth(Float_t d)
Set depth coordinate for the element.
Abstract base-class for non-linear projectable objects.
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
TEveProjectable * fProjectable
TEveProjectionManager * fManager
std::list< TEveProjected * >::iterator ProjList_i
virtual void ClearProjectedList()
virtual ~TEveProjected()
Destructor.
const Bool_t kFALSE
Definition: RtypesCore.h:92
virtual void SetDepthLocal(Float_t d)
Base-class implementation – just sets fDepth.
TEveProjection * GetProjection()
void StampTransBBox()
Definition: TEveElement.h:396
#define ClassImp(name)
Definition: Rtypes.h:336
virtual TEveElement * GetProjectedAsElement()
Returns this projected dynamic-casted to TEveElement.
virtual void UnRefProjectable(TEveProjectable *assumed_parent, bool notifyParent=true)
Remove reference to projectable.
virtual void PropagateVizParams(TEveElement *el=0)
Set visualization parameters of projecteds.
char Char_t
Definition: RtypesCore.h:29
ProjList_t fProjectedList
virtual void AddProjectedsToSet(std::set< TEveElement *> &set)
Add the projected elements to the set, dyn-casting them to TEveElement.
void SetDepthCommon(Float_t d, TEveElement *el, Float_t *bbox)
Utility function to update the z-values of the bounding-box.
virtual void AddProjected(TEveProjected *p)
Exception class thrown by TEve classes and macros.
Definition: TEveUtil.h:102
TEveProjectable()
Constructor.
virtual void PropagateMainColor(Color_t color, Color_t old_color)
Set main color of projecteds if their color is the same as old_color.
void PreDeleteElement(TEveElement *element)
Called from TEveElement prior to its destruction so the framework components (like object editor) can...
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:33