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 SoPrimitiveVertex SoPrimitiveVertex.h Inventor/SoPrimitiveVertex.h
35   \brief The SoPrimitiveVertex class represents a single vertex of a generated primitive.
36 
37   \ingroup general
38 
39   Instances of SoPrimitiveVertex are constructed when generating
40   primitive data, primarily during an SoCallbackAction traversal.
41   Depending on the context the vertex could represent a single 3D
42   point, one of the two vertices in a line or one of the three
43   vertices in a triangle.
44 */
45 
46 #include <Inventor/SoPrimitiveVertex.h>
47 #include <cstdlib>
48 
49 /*!
50   Default constructor, sets up a "void" instance.
51 */
SoPrimitiveVertex(void)52 SoPrimitiveVertex::SoPrimitiveVertex(void)
53   : point(0.0f, 0.0f, 0.0f),
54     normal(0.0f, 0.0f, 1.0f),
55     textureCoords(0.0f, 0.0f, 0.0f, 1.0f),
56     materialIndex(0),
57     detail(NULL),
58     packedColor(0)
59 {
60 }
61 
62 /*!
63   Copy operator.
64 
65   When \a pv is copied into this instance, a \e shallow copy is
66   made. Ie, only the reference to the detail instance is copied (if
67   any), not the detail itself.
68 */
69 
70 SoPrimitiveVertex &
operator =(const SoPrimitiveVertex & pv)71 SoPrimitiveVertex::operator = (const SoPrimitiveVertex & pv)
72 {
73   this->point = pv.point;
74   this->normal = pv.normal;
75   this->textureCoords = pv.textureCoords;
76   this->materialIndex = pv.materialIndex;
77   this->detail = pv.detail;
78   this->packedColor = pv.packedColor;
79   return *this;
80 }
81 
82 /*!
83   Copy constructor. Does a shallow copy.
84 
85   \sa SoPrimitiveVertex::operator=()
86 */
87 
SoPrimitiveVertex(const SoPrimitiveVertex & pv)88 SoPrimitiveVertex::SoPrimitiveVertex(const SoPrimitiveVertex & pv)
89 {
90   *this = pv;
91 }
92 
93 /*!
94   Destructor. The detail instance is owned by client code and will not
95   be destructed here.
96 */
97 
~SoPrimitiveVertex()98 SoPrimitiveVertex::~SoPrimitiveVertex()
99 {
100 }
101 
102 /*!
103   \fn const SbVec3f & SoPrimitiveVertex::getPoint(void) const
104 
105   Returns vertex coordinates, positioned in object space.
106 */
107 
108 /*!
109   \fn const SbVec3f & SoPrimitiveVertex::getNormal(void) const
110 
111   Returns normal vector, oriented in object space.
112 */
113 
114 /*!
115   \fn const SbVec4f & SoPrimitiveVertex::getTextureCoords(void) const
116 
117   Returns texture coordinates for vertex, specified in object space.
118 */
119 
120 /*!
121   \fn int SoPrimitiveVertex::getMaterialIndex(void) const
122 
123   Returns index of the vertex into the currently active material, if
124   any.
125 */
126 
127 /*!
128   \fn uint32_t SoPrimitiveVertex::getPackedColor(void) const
129 
130   Returns the rgba packed color for the given vertex.
131 
132   \since Coin 3.0
133 */
134 
135 /*!
136   \fn const SoDetail * SoPrimitiveVertex::getDetail(void) const
137 
138   Returns pointer to detail instance with more information about the
139   vertex. A detail instance may not be available, and if so \c NULL is
140   returned.
141 */
142 
143 /*!
144   \fn void SoPrimitiveVertex::setPoint(const SbVec3f & pt)
145 
146   Used internally from library client code setting up an
147   SoPrimitiveVertex instance.
148 */
149 
150 /*!
151   \fn void SoPrimitiveVertex::setPoint(float x, float y, float z)
152 
153   Used internally from library client code setting up an
154   SoPrimitiveVertex instance.
155 */
156 
157 /*!
158   \fn void SoPrimitiveVertex::setNormal(const SbVec3f & n)
159 
160   Used internally from library client code setting up an
161   SoPrimitiveVertex instance.
162 */
163 
164 /*!
165   \fn void SoPrimitiveVertex::setNormal(float nx, float ny, float nz)
166 
167   Used internally from library client code setting up an
168   SoPrimitiveVertex instance.
169 */
170 
171 /*!
172   \fn void SoPrimitiveVertex::setTextureCoords(const SbVec2f & texcoords)
173 
174   Used internally from library client code setting up an
175   SoPrimitiveVertex instance.
176 
177   Covenience function. Will fill in 0 and 1 in the last two texture
178   coords in the internal SbVec4f texture coordinate instance.
179 */
180 
181 /*!
182   \fn void SoPrimitiveVertex::setTextureCoords(float tx, float ty)
183 
184   Used internally from library client code setting up an
185   SoPrimitiveVertex instance.
186 
187   Covenience function. Will fill in 0 and 1 in the last two texture
188   coords in the internal SbVec4f texture coordinate instance.
189 */
190 
191 /*!
192   \fn void SoPrimitiveVertex::setTextureCoords(const SbVec3f & texcoords)
193 
194   Covenience function. Will fill in 1 in the last coord.
195 
196   \COIN_FUNCTION_EXTENSION
197 
198   \since Coin 2.0
199 */
200 
201 /*!
202   \fn void SoPrimitiveVertex::setTextureCoords(float tx, float ty, float tz)
203 
204   Covenience function. Will fill in 1 in the last coord.
205 
206   \COIN_FUNCTION_EXTENSION
207   \since Coin 2.5
208 */
209 
210 /*!
211   \fn void SoPrimitiveVertex::setTextureCoords(const SbVec4f & texcoords)
212 
213   Used internally from library client code setting up an
214   SoPrimitiveVertex instance.
215 */
216 
217 /*!
218   \fn void SoPrimitiveVertex::setMaterialIndex(int index)
219 
220   Used internally from library client code setting up an
221   SoPrimitiveVertex instance.
222 */
223 
224 /*!
225   \fn void SoPrimitiveVertex::setPackedColor(uint32_t rgba)
226 
227   Used internally from library client code setting up an
228   SoPrimitiveVertex instance.
229 */
230 
231 /*!
232   \fn void SoPrimitiveVertex::setDetail(SoDetail * detail)
233 
234   Used internally from library client code setting up an
235   SoPrimitiveVertex instance.
236 
237   Note that it's the client's responsibility to do the deallocation of
238   the detail instance after the SoPrimitiveVertex instance has gone
239   out of scope.
240 */
241