1 /**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32
33 /*!
34 \class SoCreaseAngleElement Inventor/elements/SoCreaseAngleElement.h
35 \brief The SoCreaseAngleElement class stores the crease angle during a scene graph traversal.
36
37 \ingroup elements
38 */
39
40 #include <Inventor/elements/SoCreaseAngleElement.h>
41
42
43 #include <cassert>
44
45 SO_ELEMENT_SOURCE(SoCreaseAngleElement);
46
47 // doc from parent
48 void
initClass(void)49 SoCreaseAngleElement::initClass(void)
50 {
51 SO_ELEMENT_INIT_CLASS(SoCreaseAngleElement, inherited);
52 }
53
54 /*!
55 The destructor.
56 */
~SoCreaseAngleElement(void)57 SoCreaseAngleElement::~SoCreaseAngleElement(void)
58 {
59 }
60
61 // doc from parent
62 void
init(SoState * state)63 SoCreaseAngleElement::init(SoState * state)
64 {
65 inherited::init(state);
66
67 // a negative value means that the element contains the default
68 // value, which is 0.0 for Inventor 2.1 and 0.5 for VRML1.
69 this->data = -1.0f;
70 }
71
72 /*!
73 Sets the value of this element.
74 */
75 void
set(SoState * const state,SoNode * const node,const float complexity)76 SoCreaseAngleElement::set(SoState * const state, SoNode * const node,
77 const float complexity)
78 {
79 SoFloatElement::set(classStackIndex, state, node, complexity);
80 }
81
82
83 /*!
84 \overload
85 */
86 void
set(SoState * const state,const float complexity)87 SoCreaseAngleElement::set(SoState * const state, const float complexity)
88 {
89 SoCreaseAngleElement::set(state, NULL, complexity);
90 }
91
92 /*!
93 Returns the element value. This method can be used if you know
94 that the node that is going to use the crease angle is an Inventor
95 node.
96 */
97 float
get(SoState * const state)98 SoCreaseAngleElement::get(SoState * const state)
99 {
100 float val = SoFloatElement::get(classStackIndex, state);
101 return val < 0.0f ? SoCreaseAngleElement::getDefault() : val;
102 }
103
104 /*!
105 Returns the element value. \a isvrml1 should be TRUE if the node
106 requesting the value is a VRML1 node.
107
108 This method is an extension versus the Open Inventor API.
109
110 \sa SoNode::getNodeType()
111 */
112 float
get(SoState * const state,const SbBool isvrml1)113 SoCreaseAngleElement::get(SoState * const state, const SbBool isvrml1)
114 {
115 float val = SoFloatElement::get(classStackIndex, state);
116 return val < 0.0f ? SoCreaseAngleElement::getDefault(isvrml1) : val;
117 }
118
119 /*!
120 Returns the default value for Inventor scene graphs (0.0).
121 */
122 float
getDefault(void)123 SoCreaseAngleElement::getDefault(void)
124 {
125 return 0.0f;
126 }
127
128 /*!
129 Returns the default value for this element. \a isvrml1 should
130 be TRUE if the node requesting the value is a VRML1 node.
131
132 This method is an extension versus the Open Inventor API.
133
134 \sa SoNode::getNodeType()
135 */
136 float
getDefault(const SbBool isvrml1)137 SoCreaseAngleElement::getDefault(const SbBool isvrml1)
138 {
139 return isvrml1 ? 0.5f : 0.0f;
140 }
141