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 SoFaceDetail SoFaceDetail.h Inventor/details/SoFaceDetail.h
35 \brief The SoFaceDetail class is for storing detailed polygon information.
36
37 \ingroup details
38
39 Instances of this class are used among other things for storing
40 information about polygons after pick operations, and for storing
41 information returned to tessellation callbacks.
42
43 Note that a SoFaceDetail instance consists of a set of SoPointDetail
44 instances, one for each vertex of the polygon it represents.
45
46 \sa SoRayPickAction, SoPickedPoint, SoCallbackAction
47 */
48
49 #include <Inventor/details/SoFaceDetail.h>
50 #include <Inventor/SbName.h>
51 #include <cstddef>
52
53 SO_DETAIL_SOURCE(SoFaceDetail);
54
55 /*!
56 Default constructor sets up an empty, non-valid detail
57 specification.
58 */
SoFaceDetail(void)59 SoFaceDetail::SoFaceDetail(void)
60 : pointsarray(NULL),
61 numallocated(0),
62 numpoints(0),
63 faceindex(0),
64 partindex(0)
65 {
66 }
67
68 /*!
69 Destructor, free internal resources used for storing the polygon
70 vertices.
71 */
~SoFaceDetail()72 SoFaceDetail::~SoFaceDetail()
73 {
74 delete [] this->pointsarray;
75 }
76
77 // doc in super
78 void
initClass(void)79 SoFaceDetail::initClass(void)
80 {
81 SO_DETAIL_INIT_CLASS(SoFaceDetail, SoDetail);
82 }
83
84 // doc in super
85 SoDetail *
copy(void) const86 SoFaceDetail::copy(void) const
87 {
88 SoFaceDetail *copy = new SoFaceDetail();
89 if (this->numpoints) {
90 copy->setNumPoints(this->numpoints);
91 for (int i = 0; i < this->numpoints; i++) {
92 copy->setPoint(i, this->getPoint(i));
93 }
94 }
95 copy->faceindex = this->faceindex;
96 copy->partindex = this->partindex;
97 return copy;
98 }
99
100 /*!
101 Number of vertices making up the polygon.
102 */
103 int
getNumPoints(void) const104 SoFaceDetail::getNumPoints(void) const
105 {
106 return this->numpoints;
107 }
108
109 /*!
110 Returns a pointer into the array of vertices, starting at the \a
111 idx'th vertice of the polygon.
112
113 The array will contain (SoFaceDetail::getNumPoints() - \a idx)
114 elements.
115 */
116 const SoPointDetail *
getPoint(const int idx) const117 SoFaceDetail::getPoint(const int idx) const
118 {
119 assert(idx >= 0 && idx < this->numpoints);
120 return &this->pointsarray[idx];
121 }
122
123 /*!
124 Returns the full array of vertice details for the polygon. The array
125 will contain SoFaceDetail::getNumPoints() elements.
126 */
127 SoPointDetail *
getPoints(void)128 SoFaceDetail::getPoints(void)
129 {
130 return this->pointsarray;
131 }
132
133 /*!
134 Returns the index of this polygon within the faceset node it is part
135 of.
136 */
137 int
getFaceIndex(void) const138 SoFaceDetail::getFaceIndex(void) const
139 {
140 return this->faceindex;
141 }
142
143 /*!
144 If this SoFaceDetail represents a triangle tessellated from a complex
145 shape, this method returns the index of the part of the complex
146 shape it was tessellated from.
147 */
148 int
getPartIndex(void) const149 SoFaceDetail::getPartIndex(void) const
150 {
151 return this->partindex;
152 }
153
154 /*!
155 Used internally from library client code setting up a SoFaceDetail
156 instance.
157
158 \sa getNumPoints()
159 */
160 void
setNumPoints(const int num)161 SoFaceDetail::setNumPoints(const int num)
162 {
163 if (num > this->numallocated) {
164 this->numallocated = num;
165 delete [] this->pointsarray;
166 this->pointsarray = new SoPointDetail[this->numallocated];
167 }
168 this->numpoints = num;
169 }
170
171 /*!
172 Used internally from library client code setting up a SoFaceDetail
173 instance.
174
175 \sa getPoint(), getPoints()
176 */
177 void
setPoint(const int idx,const SoPointDetail * const detail)178 SoFaceDetail::setPoint(const int idx, const SoPointDetail * const detail)
179 {
180 assert(idx >= 0 && idx <= this->numpoints);
181 this->pointsarray[idx] = *detail;
182 }
183
184 /*!
185 Used internally from library client code setting up a SoFaceDetail
186 instance.
187
188 \sa getFaceIndex()
189 */
190 void
setFaceIndex(const int idx)191 SoFaceDetail::setFaceIndex(const int idx)
192 {
193 this->faceindex = idx;
194 }
195
196 /*!
197 Used internally from library client code setting up a SoFaceDetail
198 instance.
199
200 \sa getPartIndex()
201 */
202 void
setPartIndex(const int idx)203 SoFaceDetail::setPartIndex(const int idx)
204 {
205 this->partindex = idx;
206 }
207
208 /*!
209 Used internally from library client code setting up a SoFaceDetail
210 instance.
211
212 This function is specific for Coin, and is not present in SGI/TGS
213 Open Inventor.
214 */
215 void
incFaceIndex(void)216 SoFaceDetail::incFaceIndex(void)
217 {
218 this->faceindex++;
219 }
220
221 /*!
222 Used internally from library client code setting up a SoFaceDetail
223 instance.
224
225 This function is specific for Coin, and is not present in SGI/TGS
226 Open Inventor.
227 */
228 void
incPartIndex(void)229 SoFaceDetail::incPartIndex(void)
230 {
231 this->partindex++;
232 }
233