ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
graphics
VP1
VP1HEPVis
src
VP1HEPVisUtils.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
7
// //
8
// Implementation of class VP1HEPVisUtils //
9
// //
10
// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11
// Initial version: November 2008 //
12
// Update: Giorgi Gvaberidze (ggvaberi@cern.ch) //
13
// Update version: November 2010 //
14
// //
16
17
#include "
VP1HEPVis/VP1HEPVisUtils.h
"
18
19
#include <Inventor/C/errors/debugerror.h>
20
#include <Inventor/nodes/SoSelection.h>
21
#include <Inventor/nodes/SoSeparator.h>
22
#include <Inventor/nodes/SoSwitch.h>
23
//---
24
#include <Inventor/nodes/SoSphere.h>
25
26
#include "
VP1HEPVis/nodes/SoCons.h
"
27
#include "
VP1HEPVis/nodes/SoGenericBox.h
"
28
#include "
VP1HEPVis/nodes/SoLAr.h
"
29
#include "
VP1HEPVis/nodes/SoPcons.h
"
30
#include "
VP1HEPVis/nodes/SoPolyhedron.h
"
31
#include "
VP1HEPVis/nodes/SoTransparency.h
"
32
#include "
VP1HEPVis/nodes/SoTubs.h
"
33
#include "
VP1HEPVis/nodes/SoTessellated.h
"
34
35
#include <Inventor/nodes/SoIndexedFaceSet.h>
36
#include <Inventor/nodes/SoVertexProperty.h>
37
#include <
VP1HEPVis/SbPolyhedron.h
>
38
39
#include <iostream>
//fixme
40
41
//____________________________________________________________________
42
class
VP1HEPVisUtils::Imp
{
43
public
:
44
template
<
class
T>
45
static
SoNode *
convertToAlternateRep
(SoNode *);
46
47
template
<
class
T>
48
static
void
clearAlternateRep
(SoNode *);
49
50
template
<
class
T>
51
static
void
updateAlternateRepIfNull
(SoNode *);
52
53
static
bool
isGroup
(SoNode* n);
54
static
bool
isNonCustomTree
(SoGroup* g);
55
static
SoGroup *
convertToStandardGroupNode
(SoGroup* g,
bool
transferChildren);
56
static
SoGroup *
convertToStandardScene
(SoGroup* g);
57
static
void
updateAllNullAlternativeReps
(SoGroup*g);
58
};
59
60
//____________________________________________________________________
61
bool
VP1HEPVisUtils::Imp::isNonCustomTree
(SoGroup* g)
62
{
63
if
(!g)
64
return
true
;
//well...
65
66
if
(
isCustomNode
(g))
67
return
false
;
68
69
for
(
int
i = 0; i<g->getNumChildren();++i) {
70
SoNode * n = g->getChild(i);
71
if
(
Imp::isGroup
(n) ) {
72
if
(!
isNonCustomTree
(
static_cast<
SoGroup*
>
(n)))
73
return
false
;
74
}
else
{
75
if
(
isCustomNode
(n))
76
return
false
;
77
}
78
}
79
return
true
;
80
}
81
82
//____________________________________________________________________
83
SoGroup *
VP1HEPVisUtils::Imp::convertToStandardGroupNode
(SoGroup* g,
bool
transferChildren)
84
{
85
//Create new non-custom node and transfer relevant fields:
86
SoGroup * newgroup(0);
87
if
( g->getTypeId().isDerivedFrom(SoSeparator::getClassTypeId()) &&
88
! g->getTypeId().isDerivedFrom(SoSelection::getClassTypeId()) ) {
89
SoSeparator * sep =
new
SoSeparator;
90
SoSeparator * origsep =
static_cast<
SoSeparator*
>
(g);
91
sep->renderCaching.setValue(origsep->renderCaching.getValue());
92
sep->boundingBoxCaching.setValue(origsep->boundingBoxCaching.getValue());
93
sep->renderCulling.setValue(origsep->renderCulling.getValue());
94
sep->pickCulling.setValue(origsep->pickCulling.getValue());
95
newgroup = sep;
96
}
else
if
( g->getTypeId().isDerivedFrom(SoSelection::getClassTypeId()) ) {
97
SoSelection *
sel
=
new
SoSelection;
98
SoSelection * origsel =
static_cast<
SoSelection*
>
(g);
99
sel
->renderCaching.setValue(origsel->renderCaching.getValue());
100
sel
->boundingBoxCaching.setValue(origsel->boundingBoxCaching.getValue());
101
sel
->renderCulling.setValue(origsel->renderCulling.getValue());
102
sel
->pickCulling.setValue(origsel->pickCulling.getValue());
103
sel
->policy.setValue(origsel->policy.getValue());
104
newgroup =
sel
;
105
}
else
if
( g->getTypeId().isDerivedFrom(SoSwitch::getClassTypeId()) ) {
106
SoSwitch *sw =
new
SoSwitch;
107
sw->whichChild.setValue(
static_cast<
SoSwitch*
>
(g)->whichChild.getValue());
108
newgroup = sw;
109
}
else
{
110
//Everything else is just treated like a group (we could add more specialisations):
111
newgroup =
new
SoGroup;
112
}
113
114
//Transfer name:
115
newgroup->setName(g->getName());
116
117
//Transfer children:
118
if
(transferChildren)
119
for
(
int
i = 0; i<g->getNumChildren();++i)
120
newgroup->addChild(g->getChild(i));
121
122
return
newgroup;
123
}
124
125
//____________________________________________________________________
126
SoGroup *
VP1HEPVisUtils::Imp::convertToStandardScene
(SoGroup* g)
127
{
128
if
(
Imp::isNonCustomTree
(g))
129
return
g;
130
131
//We have to change something underneath, so we must get a new (and non-custom) group node:
132
SoGroup * thegroup =
convertToStandardGroupNode
(g,
false
/*don't transfer children*/
);
133
if
(!thegroup)
134
std::cout <<
"BAAAAAAAAAD!"
<<std::endl;
135
for
(
int
i = 0; i<g->getNumChildren();++i) {
136
SoNode * n = g->getChild(i);
137
if
(
isGroup
(n)) {
138
SoGroup * standard =
convertToStandardScene
(
static_cast<
SoGroup*
>
(n));
139
if
(standard)
140
thegroup->addChild(standard);
141
else
142
std::cout <<
"BAD 1"
<<std::endl;
143
}
else
{
144
SoNode * ntoadd =
isCustomNode
(n)?
convertCustomNodeToAlternateRep
(n):n;
145
if
(ntoadd)
146
thegroup->addChild(
isCustomNode
(n)?
convertCustomNodeToAlternateRep
(n):n);
147
else
148
std::cout <<
"BAD 2"
<<std::endl;
149
}
150
}
151
152
return
thegroup;
153
}
154
155
156
//____________________________________________________________________
157
SoGroup *
VP1HEPVisUtils::convertToStandardScene
(SoGroup* g)
158
{
159
if
(!g)
160
return
0;
161
162
initAllCustomClasses
();
163
164
if
(
Imp::isNonCustomTree
(g))
165
return
g;
166
167
168
g->ref();
169
170
updateAllAlternativeReps
(g);
171
172
SoGroup* thegroup =
Imp::convertToStandardScene
(g);
173
thegroup->ref();
174
175
clearAllAlternativeReps
(g);
176
177
g->unrefNoDelete();
178
thegroup->unrefNoDelete();
179
return
thegroup;
180
}
181
182
//____________________________________________________________________
183
bool
VP1HEPVisUtils::isCustomNode
(SoNode* n)
184
{
185
if
(!n)
186
return
false
;
187
188
return
n->getNodeType() & SoNode::EXTENSION;
189
}
190
191
//____________________________________________________________________
192
template
<
class
T>
193
SoNode *
VP1HEPVisUtils::Imp::convertToAlternateRep
(SoNode * n)
194
{
195
if
(!n)
196
return
0;
197
T * t =
static_cast<
T*
>
(n);
198
SoNode * n_alt = t->alternateRep.getValue();
199
if
(n_alt) {
200
//Don't clear the alternateRep, since it was there before.
201
}
else
{
202
t->generateAlternateRep();
203
n_alt = t->alternateRep.getValue();
204
if
(n_alt) {
205
//Clear the alternateRep, since it was not there before.
206
n_alt->ref();
207
t->clearAlternateRep();
208
n_alt->unrefNoDelete();
209
}
else
{
210
return
0;
211
}
212
}
213
n_alt->setName(n->getName());
214
return
n_alt;
215
}
216
217
//____________________________________________________________________
218
template
<
class
T>
219
void
VP1HEPVisUtils::Imp::clearAlternateRep
(SoNode * n)
220
{
221
T * t =
static_cast<
T*
>
(n);
222
if
(t&&t->alternateRep.getValue())
223
t->clearAlternateRep();
224
}
225
226
//____________________________________________________________________
227
template
<
class
T>
228
void
VP1HEPVisUtils::Imp::updateAlternateRepIfNull
(SoNode * n)
229
{
230
T * t =
static_cast<
T*
>
(n);
231
if
(t&&!t->alternateRep.getValue()) {
232
t->generateAlternateRep();
233
t->clearAlternateRep();
234
}
235
}
236
237
//____________________________________________________________________
238
SoNode *
VP1HEPVisUtils::convertCustomNodeToAlternateRep
(SoNode*n)
239
{
240
if
(!n)
241
return
0;
242
243
initAllCustomClasses
();
244
245
if
( n->getTypeId().isDerivedFrom(SoCons::getClassTypeId()) )
return
Imp::convertToAlternateRep<SoCons>
(n);
246
if
( n->getTypeId().isDerivedFrom(SoLAr::getClassTypeId()) )
return
Imp::convertToAlternateRep<SoLAr>
(n);
247
//NOT IMPLEMENTED if ( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) ) return Imp::convertToAlternateRep<SoPcons>(n);
248
if
( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) )
return
Imp::convertToAlternateRep<SoPcons>
(n);
249
if
( n->getTypeId().isDerivedFrom(SoGenericBox::getClassTypeId()) )
return
Imp::convertToAlternateRep<SoGenericBox>
(n);
250
if
( n->getTypeId().isDerivedFrom(SoTubs::getClassTypeId()) )
return
Imp::convertToAlternateRep<SoTubs>
(n);
251
if
( n->getTypeId().isDerivedFrom(SoPolyhedron::getClassTypeId()) )
return
Imp::convertToAlternateRep<SoPolyhedron>
(n);
252
if
( n->getTypeId().isDerivedFrom(SoTessellated::getClassTypeId()) )
return
Imp::convertToAlternateRep<SoTessellated>
(n);
253
254
//A bit special. Probably should not get called here.
255
if
(
Imp::isGroup
(n) )
return
Imp::convertToStandardGroupNode
(
static_cast<
SoGroup*
>
(n),
false
/*transferChildren*/
);
256
SoGroup * g =
new
SoGroup;
257
return
g;
//fixme: share this
258
}
259
260
//____________________________________________________________________
261
bool
VP1HEPVisUtils::Imp::isGroup
(SoNode* n)
262
{
263
return
n->getTypeId().isDerivedFrom(SoGroup::getClassTypeId());
264
}
265
266
//____________________________________________________________________
267
void
VP1HEPVisUtils::Imp::updateAllNullAlternativeReps
(SoGroup*g)
268
{
269
for
(
int
i = 0; i<g->getNumChildren();++i) {
270
SoNode * n = g->getChild(i);
271
if
(
Imp::isGroup
(n) ) {
272
updateAllNullAlternativeReps
(
static_cast<
SoGroup*
>
(n));
273
}
else
if
(
VP1HEPVisUtils::isCustomNode
(n)) {
274
if
( n->getTypeId().isDerivedFrom(SoCons::getClassTypeId()) )
return
Imp::updateAlternateRepIfNull<SoCons>
(n);
275
if
( n->getTypeId().isDerivedFrom(SoLAr::getClassTypeId()) )
return
Imp::updateAlternateRepIfNull<SoLAr>
(n);
276
//NOT IMPLEMENTED if ( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) ) return Imp::updateAlternateRepIfNull<SoPcons>(n);
277
if
( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) )
return
Imp::updateAlternateRepIfNull<SoPcons>
(n);
278
if
( n->getTypeId().isDerivedFrom(SoGenericBox::getClassTypeId()) )
return
Imp::updateAlternateRepIfNull<SoGenericBox>
(n);
279
if
( n->getTypeId().isDerivedFrom(SoTubs::getClassTypeId()) )
return
Imp::updateAlternateRepIfNull<SoTubs>
(n);
280
if
( n->getTypeId().isDerivedFrom(SoPolyhedron::getClassTypeId()) )
return
Imp::updateAlternateRepIfNull<SoPolyhedron>
(n);
281
if
( n->getTypeId().isDerivedFrom(SoTessellated::getClassTypeId()) )
return
Imp::updateAlternateRepIfNull<SoTessellated>
(n);
282
}
283
}
284
}
285
286
//____________________________________________________________________
287
void
VP1HEPVisUtils::updateAllAlternativeReps
(SoGroup*g)
288
{
289
clearAllAlternativeReps
(g);
//To make sure all altReps. are NULL
290
//(thus, we only update those with null,
291
//avoiding repeated updates on shared
292
//instances)
293
Imp::updateAllNullAlternativeReps
(g);
294
}
295
296
//____________________________________________________________________
297
void
VP1HEPVisUtils::clearAllAlternativeReps
(SoGroup*g)
298
{
299
for
(
int
i = 0; i<g->getNumChildren();++i) {
300
SoNode * n = g->getChild(i);
301
if
(
Imp::isGroup
(n) ) {
302
clearAllAlternativeReps
(
static_cast<
SoGroup*
>
(n));
303
}
else
if
(
isCustomNode
(n)) {
304
if
( n->getTypeId().isDerivedFrom(SoCons::getClassTypeId()) )
return
Imp::clearAlternateRep<SoCons>
(n);
305
if
( n->getTypeId().isDerivedFrom(SoLAr::getClassTypeId()) )
return
Imp::clearAlternateRep<SoLAr>
(n);
306
//NOT IMPLEMENTED if ( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) ) return Imp::clearAlternateRep<SoPcons>(n);
307
if
( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) )
return
Imp::clearAlternateRep<SoPcons>
(n);
308
if
( n->getTypeId().isDerivedFrom(SoGenericBox::getClassTypeId()) )
return
Imp::clearAlternateRep<SoGenericBox>
(n);
309
if
( n->getTypeId().isDerivedFrom(SoTubs::getClassTypeId()) )
return
Imp::clearAlternateRep<SoTubs>
(n);
310
if
( n->getTypeId().isDerivedFrom(SoPolyhedron::getClassTypeId()) )
return
Imp::clearAlternateRep<SoPolyhedron>
(n);
311
if
( n->getTypeId().isDerivedFrom(SoTessellated::getClassTypeId()) )
return
Imp::clearAlternateRep<SoTessellated>
(n);
312
}
313
}
314
}
315
316
//____________________________________________________________________
317
void
VP1HEPVisUtils::initAllCustomClasses
()
318
{
319
SoCons::initClass
();
320
SoGenericBox::initClass
();
321
SoLAr::initClass
();
322
SoPcons::initClass
();
323
SoPolyhedron::initClass
();
324
SoTransparency::initClass
();
325
SoTubs::initClass
();
326
SoTessellated::initClass
();
327
}
sel
sel
Definition
SUSYToolsTester.cxx:92
SbPolyhedron.h
SoCons.h
SoGenericBox.h
SoLAr.h
SoPcons.h
SoPolyhedron.h
SoTessellated.h
SoTransparency.h
SoTubs.h
VP1HEPVisUtils.h
SoCons::initClass
static void initClass()
Class Initializer, required.
Definition
SoCons.cxx:59
SoGenericBox::initClass
static void initClass()
Definition
SoGenericBox.cxx:62
SoLAr::initClass
static void initClass()
Class Initializer, required.
Definition
SoLAr.cxx:62
SoPcons::initClass
static void initClass()
Class Initializer, required.
Definition
SoPcons.cxx:67
SoPolyhedron::initClass
static void initClass()
Definition
SoPolyhedron.cxx:47
SoTessellated::initClass
static void initClass()
Definition
SoTessellated.cxx:19
SoTransparency::initClass
static void initClass()
Definition
SoTransparency.cxx:29
SoTubs::initClass
static void initClass()
Class Initializer, required.
Definition
SoTubs.cxx:63
VP1HEPVisUtils::Imp
Definition
VP1HEPVisUtils.cxx:42
VP1HEPVisUtils::Imp::convertToStandardScene
static SoGroup * convertToStandardScene(SoGroup *g)
Definition
VP1HEPVisUtils.cxx:126
VP1HEPVisUtils::Imp::convertToAlternateRep
static SoNode * convertToAlternateRep(SoNode *)
Definition
VP1HEPVisUtils.cxx:193
VP1HEPVisUtils::Imp::updateAlternateRepIfNull
static void updateAlternateRepIfNull(SoNode *)
Definition
VP1HEPVisUtils.cxx:228
VP1HEPVisUtils::Imp::clearAlternateRep
static void clearAlternateRep(SoNode *)
Definition
VP1HEPVisUtils.cxx:219
VP1HEPVisUtils::Imp::convertToStandardGroupNode
static SoGroup * convertToStandardGroupNode(SoGroup *g, bool transferChildren)
Definition
VP1HEPVisUtils.cxx:83
VP1HEPVisUtils::Imp::isGroup
static bool isGroup(SoNode *n)
Definition
VP1HEPVisUtils.cxx:261
VP1HEPVisUtils::Imp::isNonCustomTree
static bool isNonCustomTree(SoGroup *g)
Definition
VP1HEPVisUtils.cxx:61
VP1HEPVisUtils::Imp::updateAllNullAlternativeReps
static void updateAllNullAlternativeReps(SoGroup *g)
Definition
VP1HEPVisUtils.cxx:267
VP1HEPVisUtils::clearAllAlternativeReps
static void clearAllAlternativeReps(SoGroup *)
Definition
VP1HEPVisUtils.cxx:297
VP1HEPVisUtils::isCustomNode
static bool isCustomNode(SoNode *)
Definition
VP1HEPVisUtils.cxx:183
VP1HEPVisUtils::convertCustomNodeToAlternateRep
static SoNode * convertCustomNodeToAlternateRep(SoNode *)
Definition
VP1HEPVisUtils.cxx:238
VP1HEPVisUtils::convertToStandardScene
static SoGroup * convertToStandardScene(SoGroup *)
Definition
VP1HEPVisUtils.cxx:157
VP1HEPVisUtils::initAllCustomClasses
static void initAllCustomClasses()
Definition
VP1HEPVisUtils.cxx:317
VP1HEPVisUtils::updateAllAlternativeReps
static void updateAllAlternativeReps(SoGroup *)
Definition
VP1HEPVisUtils.cxx:287
Generated on
for ATLAS Offline Software by
1.17.0