ATLAS Offline Software
Loading...
Searching...
No Matches
TrackLODManager.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7// //
8// Implementation of class TrackLODManager //
9// //
10// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11// Initial version: March 2008 //
12// //
14
16#include "VP1Base/VP1Msg.h"
18#include <Inventor/nodes/SoLevelOfDetail.h>
19#include <Inventor/nodes/SoSeparator.h>
20#include <map>
21
22//____________________________________________________________________
46
47
48//____________________________________________________________________
50 : QObject(parent), VP1HelperClassBase(sys,"TrackLODManager"), m_d(new Imp)
51{
52}
53
54//____________________________________________________________________
56{
57 if (m_d->attachnode) {
58 messageDebug("WARNING: Destructed before event data cleared!");
60 }
61 delete m_d;
62}
63
64//____________________________________________________________________
70
71//____________________________________________________________________
77
78//____________________________________________________________________
80{
81 if ( attachnode && attachnode_lod && attachnode->findChild(attachnode_lod)>-1)
82 attachnode->removeChild(attachnode_lod);
83}
84
85//____________________________________________________________________
87{
88 if (dl == TrackCommonFlags::SIMPLE) {
91 } else {
93 }
94
98 } else {
100 }
101
102 if (dl == TrackCommonFlags::AUTO) {
103 if ( attachnode && attachnode_lod && attachnode->findChild(attachnode_lod)<0)
104 attachnode->addChild(attachnode_lod);
105 } else {
107 }
108}
109
110//____________________________________________________________________
112{
113 if (VP1Msg::verbose())
114 messageVerbose("signal received in setDetailLevel (old = "+TrackCommonFlags::toString(m_d->detailLevel)+", new = "+TrackCommonFlags::toString(dl));
115 if ( m_d->detailLevel == dl )
116 return;
117 m_d->detailLevel = dl;
118 m_d->updateAttachmentForDetailLevel(dl);
119}
120
121//____________________________________________________________________
123{
124 if (!an) {
125 message("setAttachNode ERROR: Received null pointer!");
126 return;
127 }
128 if (m_d->attachnode) {
129 message("setAttachNode ERROR: Received new attachment group pointer while still having previous one!");
131 return;
132 }
133
134 m_d->attachnode = an;
135 m_d->attachnode->ref();
136
137 m_d->attachsep_simple = new SoSeparator;
138 m_d->attachsep_simple->ref();
139 m_d->attachsep_detailed = new SoSeparator;
140 m_d->attachsep_detailed->ref();
141 m_d->attachnode_lod = new SoGroup;
142 m_d->attachnode_lod->ref();
143
144 m_d->attachHelper_simple = new VP1ExtraSepLayerHelper(m_d->attachsep_simple);
145 m_d->attachHelper_detailed = new VP1ExtraSepLayerHelper(m_d->attachsep_detailed);
146
147 m_d->updateAttachmentForDetailLevel(m_d->detailLevel);
148}
149
150//____________________________________________________________________
152{
153 messageVerbose("eraseEventData start");
154 if (!m_d->attachnode) {
155 messageDebug("eraseEventData WARNING: - called before attachment node was set!");
156 return;
157 }
158 m_d->ensureSimpleDetached();
159 m_d->ensureDetailedDetached();
160 m_d->ensureLODDetached();
161
162 std::map<std::pair<int,double>,TrackLODHandle* >::iterator it, itE(m_d->id_2_lodhandle.end());
163 for (it = m_d->id_2_lodhandle.begin(); it!=itE;++it) {
164 delete it->second;
165 }
166 m_d->id_2_lodhandle.clear();
167
168 if (m_d->attachnode_lod) {
169 m_d->attachnode_lod->unref();
170 m_d->attachnode_lod = nullptr;
171 }
172
173 if (m_d->attachsep_simple) {
174 delete m_d->attachHelper_simple;
175 m_d->attachHelper_simple = nullptr;
176 m_d->attachsep_simple->unref();
177 m_d->attachsep_simple = nullptr;
178 }
179
180 if (m_d->attachsep_detailed) {
181 delete m_d->attachHelper_detailed;
182 m_d->attachHelper_detailed = nullptr;
183 m_d->attachsep_detailed->unref();
184 m_d->attachsep_detailed = nullptr;
185 }
186
187 m_d->attachnode->unref();
188 m_d->attachnode = nullptr;
189 messageVerbose("eraseEventData end");
190
191}
192
193//____________________________________________________________________
194TrackLODHandle * TrackLODManager::getLODHandle(int regionindex, const double& crossover_value)
195{
196 std::map<std::pair<int,double>,TrackLODHandle* >::iterator it = m_d->id_2_lodhandle.find(std::make_pair(regionindex,crossover_value));
197 if (it!=m_d->id_2_lodhandle.end())
198 return it->second;
199 if (!m_d->attachnode) {
200 message("getTrackLODHandle ERROR: Called before attachment node was set!");
201 return nullptr;
202 }
203 TrackLODHandle * lh = new TrackLODHandle(m_d->attachnode_lod,m_d->attachHelper_simple,m_d->attachHelper_detailed,regionindex,crossover_value);
204 m_d->id_2_lodhandle[std::make_pair(regionindex,crossover_value)] = lh;
205 return lh;
206}
207
208
210// TrackLODHandle implementation //
212
213
214//____________________________________________________________________
216public:
217 Imp( SoGroup* ag,
220 int i, const double& c)
221 : attachGroup_LOD(ag),
224 regIdx(i),
225 crossVal(c),
226 lod(nullptr),
227 sep_detailed(nullptr),
228 sep_simple(nullptr) {}
233 double crossVal;
234 SoLevelOfDetail * lod;
235 SoSeparator * sep_detailed;
236 SoSeparator * sep_simple;
238 {
239 //Fixme: We should scale this with complexity! I.e. multiply the value with 1.0/(complexity+0.5)
240 // lod->screenArea.setValue(crossVal/sqrt(sep_detailed->getNumChildren()+1.0));
241 lod->screenArea.setValue(crossVal*sqrt(sep_detailed->getNumChildren())+0.1);
242 }
243};
244
245
246//____________________________________________________________________
247TrackLODHandle::TrackLODHandle(SoGroup* attachgroup_LOD,
248 VP1ExtraSepLayerHelper * sephelper_simple,
249 VP1ExtraSepLayerHelper * sephelper_detailed,
250 int regionindex, const double& crossover_value)
251 : m_d(new Imp(attachgroup_LOD,sephelper_simple,sephelper_detailed,regionindex,crossover_value))
252{
253// if (VP1Msg::verbose())
254// VP1Msg::messageVerbose("TrackLODHandle Constructed with regionIndex = "+QString::number(regionindex)
255// +" and nominal crossover value = "+QString::number(crossover_value));
256 if (!attachgroup_LOD||!sephelper_simple||!sephelper_detailed)
257 VP1Msg::messageDebug("TrackLODHandle ERROR: Received null pointer!");
258}
259
260//____________________________________________________________________
262{
263 if (m_d->lod) {
264 if (m_d->attachGroup_LOD->findChild(m_d->lod)>-1) {
265 m_d->attachGroup_LOD->removeChild(m_d->lod);
266 m_d->attachHelper_simple->removeNode(m_d->sep_simple);
267 m_d->attachHelper_detailed->removeNode(m_d->sep_detailed);
268 }
269 m_d->lod->unref();
270 m_d->sep_detailed->unref();
271 m_d->sep_simple->unref();
272 }
273 delete m_d;
274}
275
276//____________________________________________________________________
277void TrackLODHandle::addNodes(SoGroup* simple,SoGroup*detailed )
278{
279 if (!m_d->lod) {
280// if (VP1Msg::verbose())
281// VP1Msg::messageVerbose( "TrackLODHandle addNodes: Initialising nodes: LOD, sep_detailed and sep_simple.");
282 m_d->lod = new SoLevelOfDetail;
283 m_d->sep_detailed = new SoSeparator;
284 m_d->sep_simple = new SoSeparator;
285 m_d->lod->ref();
286 m_d->sep_detailed->ref();
287 m_d->sep_simple->ref();
288 m_d->lod->addChild(m_d->sep_detailed);
289 m_d->lod->addChild(m_d->sep_simple);
290 }
291
292 if (VP1Msg::verbose()) {
293 //Extra sanity checks:
294 if (!detailed) {
295 VP1Msg::messageVerbose("TrackLODHandle ERROR: addNodes received null pointer for detailed node");
296 return;
297 }
298 if (!simple) {
299 VP1Msg::messageVerbose("TrackLODHandle ERROR: addNodes received null pointer for simple node");
300 return;
301 }
302 if (m_d->sep_detailed->findChild(detailed)>=0) {
303 VP1Msg::messageVerbose("TrackLODHandle ERROR: addNodes called for detailed node which is already added");
304 return;
305 }
306 if (m_d->sep_simple->findChild(simple)>=0) {
307 VP1Msg::messageVerbose("TrackLODHandle ERROR: addNodes called for simple node which is already added");
308 return;
309 }
310 }
311
312 m_d->sep_detailed->addChild(detailed);
313 m_d->sep_simple->addChild(simple);
314
315 if (m_d->sep_detailed->getNumChildren()==1) {
316 //We went from 0 to 1 children!
317 if (VP1Msg::verbose()&&m_d->attachGroup_LOD->findChild(m_d->lod)>=0)
318 VP1Msg::messageVerbose("TrackLODHandle ERROR: adding lod, but it is already a child!!");
319 m_d->attachGroup_LOD->addChild(m_d->lod);
320 m_d->attachHelper_simple->addNode(m_d->sep_simple);
321 m_d->attachHelper_detailed->addNode(m_d->sep_detailed);
322 }
323 m_d->updateCrossOverField();
324}
325
326//____________________________________________________________________
327void TrackLODHandle::removeNodes(SoGroup* simple,SoGroup*detailed )
328{
329 if (!m_d->lod)
330 return;
331
332 if (VP1Msg::verbose()) {
333 //Extra sanity checks:
334 if (!detailed) {
335 VP1Msg::messageVerbose("TrackLODHandle ERROR: removeNodes received null pointer for detailed node");
336 return;
337 }
338 if (!simple) {
339 VP1Msg::messageVerbose("TrackLODHandle ERROR: removeNodes received null pointer for simple node");
340 return;
341 }
342 if (m_d->sep_detailed->findChild(detailed)<0) {
343 VP1Msg::messageVerbose("TrackLODHandle ERROR: removeNodes called for detailed node which is not already added");
344 return;
345 }
346 if (m_d->sep_simple->findChild(simple)<0) {
347 VP1Msg::messageVerbose("TrackLODHandle ERROR: removeNodes called for simple node which is not already added");
348 return;
349 }
350 }
351 m_d->sep_detailed->removeChild(detailed);
352 m_d->sep_simple->removeChild(simple);
353
354 if (m_d->sep_detailed->getNumChildren()<1) {
355 //We went from 1 to 0 children
356 if (VP1Msg::verbose()&&m_d->attachGroup_LOD->findChild(m_d->lod)<0)
357 VP1Msg::messageVerbose("TrackLODHandle ERROR: removing child, but node is not currently a child!!");
358 m_d->attachGroup_LOD->removeChild(m_d->lod);
359 m_d->attachHelper_simple->removeNode(m_d->sep_simple);
360 m_d->attachHelper_detailed->removeNode(m_d->sep_detailed);
361 } else {
362 m_d->updateCrossOverField();
363 }
364}
static QString toString(const SELECTIONMODE &)
void updateCrossOverField() const
VP1ExtraSepLayerHelper * attachHelper_simple
VP1ExtraSepLayerHelper * attachHelper_detailed
Imp(SoGroup *ag, VP1ExtraSepLayerHelper *shs, VP1ExtraSepLayerHelper *shd, int i, const double &c)
SoLevelOfDetail * lod
void removeNodes(SoGroup *simple, SoGroup *detailed)
TrackLODHandle(SoGroup *, VP1ExtraSepLayerHelper *, VP1ExtraSepLayerHelper *, int, const double &)
void addNodes(SoGroup *simple, SoGroup *detailed)
void ensureDetailedDetached() const
TrackCommonFlags::DETAILLEVEL detailLevel
SoSeparator * attachsep_simple
VP1ExtraSepLayerHelper * attachHelper_simple
std::map< std::pair< int, double >, TrackLODHandle * > id_2_lodhandle
void updateAttachmentForDetailLevel(TrackCommonFlags::DETAILLEVEL) const
VP1ExtraSepLayerHelper * attachHelper_detailed
void ensureLODDetached() const
SoSeparator * attachsep_detailed
void ensureSimpleDetached() const
friend class TrackLODHandle
TrackLODHandle * getLODHandle(int regionindex, const double &crossover_value)
void setAttachNode(SoGroup *attachnode)
virtual ~TrackLODManager()
TrackLODManager(QObject *parent=0, IVP1System *sys=0)
void setDetailLevel(TrackCommonFlags::DETAILLEVEL)
VP1HelperClassBase(IVP1System *sys=0, QString helpername="")
void messageVerbose(const QString &) const
void message(const QString &) const
void messageDebug(const QString &) const
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static bool verbose()
Definition VP1Msg.h:31
static void messageDebug(const QString &)
Definition VP1Msg.cxx:39