ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
graphics
VP1
VP1HEPVis
src
SoTransparency.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
// Header file for class SoTransparency //
9
// //
10
// Description: Custom node for VP1 which sets the absolute //
11
// or relative transparency of the current //
12
// state. //
13
// //
14
// Author: Troels Kofoed Jacobsen //
15
// Initial version: July 2008 //
16
// //
18
19
#include "
VP1HEPVis/nodes/SoTransparency.h
"
20
#include <Inventor/actions/SoCallbackAction.h>
21
#include <Inventor/actions/SoGLRenderAction.h>
22
#include <Inventor/bundles/SoMaterialBundle.h>
23
#include <Inventor/elements/SoTransparencyElement.h>
24
#include <algorithm>
//for min/max
25
26
SO_NODE_SOURCE(
SoTransparency
)
27
// Initializes the SoTransparency class.
28
void
29
SoTransparency::initClass
()
30
{
31
[[maybe_unused]]
static
const
bool
didInit = [&]() {
32
SO_NODE_INIT_CLASS(
SoTransparency
, SoNode,
"Node"
);
33
return
true
;
34
}();
35
}
36
37
// Constructor
38
SoTransparency::SoTransparency
()
39
{
40
SO_NODE_CONSTRUCTOR(
SoTransparency
);
41
42
SO_NODE_ADD_FIELD(
transparency
, (0.5));
43
SO_NODE_ADD_FIELD(
relative
, (
true
));
44
setNodeType(EXTENSION);
45
46
}
47
48
// Destructor
49
SoTransparency::~SoTransparency
()
50
{
51
}
52
53
// Implements GL render action.
54
void
55
SoTransparency::GLRender
(SoGLRenderAction *action)
56
{
57
SoTransparency::doAction
(action);
58
SoMaterialBundle mb(action);
59
mb.forceSend(0);
60
}
61
62
// Implements callback action.
63
void
64
SoTransparency::callback
(SoCallbackAction *action)
65
{
66
SoTransparency::doAction
(action);
67
}
68
69
void
70
SoTransparency::doAction
(SoAction *action)
71
{
72
// Make sure the "transparency" field is not ignored. If it is,
73
// then we don't need to change anything in the state.
74
if
(
transparency
.isIgnored())
75
return
;
76
77
const
float
isRelative =
relative
.getValue();
78
const
float
transpVal =
transparency
.getValue();
79
if
( isRelative && transpVal<=0.0f )
80
return
;
//No effect
81
82
const
SoTransparencyElement * STE = SoTransparencyElement::getInstance( action->getState() );
83
const
int
n = STE->getNum();
84
if
(n<=0)
85
return
;
//Nothing to modify
86
87
float
* finalTransparency =
new
float
[n];
//NB: Who takes care of deleting finalTransparency??
88
for
(
int
i = 0; i < n; i++)
89
finalTransparency[i] = std::min<float>( 1.0f, std::max<float>( 0.0f, ( isRelative ? ( 1.0 - (1.0 - transpVal) * (1.0 - STE->get(0)) ) : transpVal ) ) );
90
91
SoTransparencyElement::set(action->getState(),
this
, n, finalTransparency);
92
93
}
SoTransparency.h
SoTransparency
Definition
SoTransparency.h:20
SoTransparency::relative
SoSFBool relative
Definition
SoTransparency.h:28
SoTransparency::callback
virtual void callback(SoCallbackAction *action)
Definition
SoTransparency.cxx:64
SoTransparency::initClass
static void initClass()
Definition
SoTransparency.cxx:29
SoTransparency::~SoTransparency
virtual ~SoTransparency()
Definition
SoTransparency.cxx:49
SoTransparency::doAction
virtual void doAction(SoAction *action)
Definition
SoTransparency.cxx:70
SoTransparency::transparency
SoSFFloat transparency
Definition
SoTransparency.h:27
SoTransparency::SoTransparency
SoTransparency()
Definition
SoTransparency.cxx:38
SoTransparency::GLRender
virtual void GLRender(SoGLRenderAction *action)
Definition
SoTransparency.cxx:55
Generated on
for ATLAS Offline Software by
1.17.0