ATLAS Offline Software
Loading...
Searching...
No Matches
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
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
26SO_NODE_SOURCE(SoTransparency)
27// Initializes the SoTransparency class.
28void
30{
31 [[maybe_unused]] static const bool didInit = [&]() {
32 SO_NODE_INIT_CLASS(SoTransparency, SoNode, "Node");
33 return true;
34 }();
35}
36
37// Constructor
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
52
53// Implements GL render action.
54void
55SoTransparency::GLRender(SoGLRenderAction *action)
56{
58 SoMaterialBundle mb(action);
59 mb.forceSend(0);
60}
61
62// Implements callback action.
63void
64SoTransparency::callback(SoCallbackAction *action)
65{
67}
68
69void
70SoTransparency::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}
virtual void callback(SoCallbackAction *action)
static void initClass()
virtual ~SoTransparency()
virtual void doAction(SoAction *action)
SoSFFloat transparency
virtual void GLRender(SoGLRenderAction *action)