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