Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
32 ClassImp(TEveProjectable);
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// Constructor.
36 
37 TEveProjectable::TEveProjectable()
38 {
39 }
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Destructor.
43 /// Force projected replicas to unreference *this, then destroy them.
44 
45 TEveProjectable::~TEveProjectable()
46 {
47  while ( ! fProjectedList.empty())
48  {
49  TEveProjected* p = fProjectedList.front();
50  p->UnRefProjectable(this);
51  TEveElement* el = p->GetProjectedAsElement();
52  assert(el);
53  {
54  gEve->PreDeleteElement(el);
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 
65 void TEveProjectable::AnnihilateProjecteds()
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 
77 void TEveProjectable::ClearProjectedList()
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 
99 void TEveProjectable::PropagateVizParams(TEveElement* el)
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 
113 void TEveProjectable::PropagateRenderState(Bool_t rnr_self, Bool_t rnr_children)
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 
125 void TEveProjectable::PropagateMainColor(Color_t color, Color_t old_color)
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 
138 void TEveProjectable::PropagateMainTransparency(Char_t t, Char_t old_t)
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 
156 ClassImp(TEveProjected);
157 
158 ////////////////////////////////////////////////////////////////////////////////
159 /// Constructor.
160 
161 TEveProjected::TEveProjected() :
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 
173 TEveProjected::~TEveProjected()
174 {
175  if (fProjectable) fProjectable->RemoveProjected(this);
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 
183 TEveElement* TEveProjected::GetProjectedAsElement()
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 
193 void TEveProjected::SetProjection(TEveProjectionManager* mng, TEveProjectable* model)
194 {
195  fManager = mng;
196  if (fProjectable) fProjectable->RemoveProjected(this);
197  fProjectable = model;
198  if (fProjectable) fProjectable->AddProjected(this);
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 
219 void TEveProjected::SetDepth(Float_t d)
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 
236 void TEveProjected::SetDepthCommon(Float_t d, TEveElement* el, Float_t* bbox)
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 
250 void TEveProjected::SetDepthLocal(Float_t d)
251 {
252  fDepth = d;
253 }