Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
REveProjectionBases.cxx
Go to the documentation of this file.
1 // @(#)root/eve7:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2019, 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 
14 #include <ROOT/REveManager.hxx>
15 
16 #include <cassert>
17 
18 using namespace ROOT::Experimental;
19 namespace REX = ROOT::Experimental;
20 
21 /** \class REveProjectable
22 \ingroup REve
23 Abstract base-class for non-linear projectable objects.
24 
25 Via ProjectedClass(const REveProjection* p) method it returns a
26 TClass instance for the projected class and keeps references to the
27 projected objects.
28 
29 It is assumed that all classes deriving from REveProjectable are also
30 derived from REveElement.
31 
32 See also REveProjectionManager::ImportElements().
33 */
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Constructor.
37 
38 REveProjectable::REveProjectable()
39 {
40 }
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Copy constructor. Does shallow copy
44 
45 REveProjectable::REveProjectable(const REveProjectable &)
46 {
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Destructor.
51 /// Force projected replicas to unreference *this, then destroy them.
52 
53 REveProjectable::~REveProjectable()
54 {
55  // FIXME: fomr SL: how list becomes empty here???
56 
57  while ( ! fProjectedList.empty())
58  {
59  REveProjected* p = fProjectedList.front();
60 
61  p->UnRefProjectable(this);
62  REveElement* el = p->GetProjectedAsElement();
63  assert(el);
64  {
65  // FIXME: SL: no any globals !!!
66  REX::gEve->PreDeleteElement(el);
67  delete el;
68  }
69  }
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Optimized destroy of projected elements with condition
74 /// there is only one parent for projected element. Method is
75 /// called from REveElement::Annihilate().
76 
77 void REveProjectable::AnnihilateProjecteds()
78 {
79  for (auto &&proj : fProjectedList) {
80  proj->UnRefProjectable(this, kFALSE);
81  proj->GetProjectedAsElement()->Annihilate();
82  }
83  fProjectedList.clear();
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 
88 void REveProjectable::ClearProjectedList()
89 {
90  fProjectedList.clear();
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Add the projected elements to the set, dyn-casting them to
95 /// REveElement.
96 
97 void REveProjectable::AddProjectedsToSet(std::set<REveElement*> &set)
98 {
99  for (auto &proj : fProjectedList)
100  set.insert(proj->GetProjectedAsElement());
101 }
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Set visualization parameters of projecteds.
105 /// Use element el as model. If el == 0 (default), this casted to
106 /// REveElement is used.
107 
108 void REveProjectable::PropagateVizParams(REveElement *el)
109 {
110  if (el == nullptr)
111  el = dynamic_cast<REveElement*>(this);
112 
113  for (auto &proj : fProjectedList)
114  proj->GetProjectedAsElement()->CopyVizParams(el);
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Set render state of projecteds.
119 
120 void REveProjectable::PropagateRenderState(Bool_t rnr_self, Bool_t rnr_children)
121 {
122  for (auto &&proj : fProjectedList) {
123  if (proj->GetProjectedAsElement()->SetRnrSelfChildren(rnr_self, rnr_children))
124  proj->GetProjectedAsElement()->StampVisibility();
125  }
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// Set main color of projecteds if their color is the same as old_color.
130 
131 void REveProjectable::PropagateMainColor(Color_t color, Color_t old_color)
132 {
133  for (auto &&proj : fProjectedList) {
134  auto p_as_el = proj->GetProjectedAsElement();
135  if (p_as_el->GetMainColor() == old_color) {
136  p_as_el->SetMainColor(color);
137  p_as_el->StampColorSelection();
138  }
139  }
140 }
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Set main transparency of projecteds if their transparency is the
144 /// same as the old one.
145 
146 void REveProjectable::PropagateMainTransparency(Char_t t, Char_t old_t)
147 {
148  for (auto &&proj : fProjectedList) {
149  auto p_as_el = proj->GetProjectedAsElement();
150  if (p_as_el->GetMainTransparency() == old_t) {
151  p_as_el->SetMainTransparency(t);
152  p_as_el->StampColorSelection();
153  }
154  }
155 }
156 
157 /** \class REveProjected
158 \ingroup REve
159 Abstract base class for classes that hold results of a non-linear
160 projection transformation.
161 
162 It is assumed that all classes deriving from REveProjected are also
163 derived from REveElement.
164 */
165 
166 ////////////////////////////////////////////////////////////////////////////////
167 /// Destructor.
168 /// If fProjectable is non-null, *this is removed from its list of
169 /// projected replicas.
170 
171 REveProjected::~REveProjected()
172 {
173  if (fProjectable) fProjectable->RemoveProjected(this);
174 }
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Returns this projected dynamic-casted to REveElement.
178 /// This is needed as class REveProjected is used as secondary
179 /// inheritance.
180 
181 REveElement* REveProjected::GetProjectedAsElement()
182 {
183  return dynamic_cast<REveElement*>(this);
184 }
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// Sets projection manager and reference in the projectable object. Method called
188 /// immediately after default constructor.
189 /// See also REveProjectionManager::ImportElements().
190 
191 void REveProjected::SetProjection(REveProjectionManager* mng, REveProjectable* model)
192 {
193  fManager = mng;
194  if (fProjectable) fProjectable->RemoveProjected(this);
195  fProjectable = model;
196  if (fProjectable) fProjectable->AddProjected(this);
197 }
198 
199 ////////////////////////////////////////////////////////////////////////////////
200 /// Remove reference to projectable.
201 
202 void REveProjected::UnRefProjectable(REveProjectable* assumed_parent, bool notifyParent)
203 {
204  static const REveException eH("REveProjected::UnRefProjectable ");
205 
206  R__ASSERT(fProjectable == assumed_parent);
207 
208  if (notifyParent) fProjectable->RemoveProjected(this);
209  fProjectable = nullptr;
210 }
211 
212 ////////////////////////////////////////////////////////////////////////////////
213 /// Set depth coordinate for the element.
214 /// Bounding-box should also be updated.
215 /// If projection type is 3D, this only sets fDepth member.
216 
217 void REveProjected::SetDepth(Float_t d)
218 {
219  if (fManager->GetProjection()->Is2D()) {
220  SetDepthLocal(d);
221  } else {
222  fDepth = d;
223  }
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Utility function to update the z-values of the bounding-box.
228 /// As this is an abstract interface, the element and bbox pointers
229 /// must be passed from outside.
230 
231 void REveProjected::SetDepthCommon(Float_t d, REveElement* el, Float_t* bbox)
232 {
233  Float_t delta = d - fDepth;
234  fDepth = d;
235  if (bbox) {
236  bbox[4] += delta;
237  bbox[5] += delta;
238  el->StampTransBBox();
239  }
240 }
241 
242 ////////////////////////////////////////////////////////////////////////////////
243 /// Base-class implementation -- just sets fDepth.
244 
245 void REveProjected::SetDepthLocal(Float_t d)
246 {
247  fDepth = d;
248 }