Debian Codegraph @

lib/database/src/so/nodes/SoIndexedShape.c++

raw symbols SCIP
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1990,91 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.2 $
44 |
45 | Classes:
46 | SoIndexedShape
47 |
48 | Author(s) : Paul S. Strauss, Gavin Bell
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include <Inventor/actions/SoGetBoundingBoxAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoGetBoundingBoxAction.h`/
55 #include <Inventor/elements/SoCoordinateElement.h>cxx . . $ `<file>/lib/database/include/Inventor/elements/SoCoordinateElement.h`/
56 #include <Inventor/elements/SoTextureCoordinateBindingElement.h>cxx . . $ `<file>/lib/database/include/Inventor/elements/SoTextureCoordinateBindingElement.h`/
57 #include <Inventor/errors/SoDebugError.h>cxx . . $ `<file>/lib/database/include/Inventor/errors/SoDebugError.h`/
58 #include <Inventor/nodes/SoIndexedShape.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoIndexedShape.h`/
59
60 SO_NODE_ABSTRACT_SOURCEcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:245:9`!(SoIndexedShape);
61
62 int32_tcxx . . $ int32_t# *SoIndexedShapecxx . . $ SoIndexedShape#::consecutiveIndicescxx . . $ SoIndexedShape#consecutiveIndices. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
63 int SoIndexedShapecxx . . $ SoIndexedShape#::numConsecutiveIndicesAllocatedcxx . . $ SoIndexedShape#numConsecutiveIndicesAllocated. = 0;
64
65 ////////////////////////////////////////////////////////////////////////
66 //
67 // Description:
68 // Constructor
69 //
70 // Use: protected
71
72 SoIndexedShapecxx . . $ SoIndexedShape#::SoIndexedShapecxx . . $ SoIndexedShape#SoIndexedShape(49f6e7a06ebc5aa8).()
73 //
74 ////////////////////////////////////////////////////////////////////////
75 {
76 SO_NODE_CONSTRUCTORcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:309:9`!(SoIndexedShape);
77
78 SO_NODE_ADD_FIELDcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:346:9`!(coordIndex, (0));
79 SO_NODE_ADD_FIELDcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:346:9`!(materialIndex, (-1));
80 SO_NODE_ADD_FIELDcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:346:9`!(normalIndex, (-1));
81 SO_NODE_ADD_FIELDcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:346:9`!(textureCoordIndex, (-1));
82 colorIcxx . . $ SoIndexedShape#colorI. = normalIcxx . . $ SoIndexedShape#normalI. = texCoordIcxx . . $ SoIndexedShape#texCoordI. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
83 // force reevaluation of binding:
84 materialBindingcxx . . $ SoIndexedShape#materialBinding. = normalBindingcxx . . $ SoIndexedShape#normalBinding. = texCoordBindingcxx . . $ SoIndexedShape#texCoordBinding. = 0;
85 }
86
87 ////////////////////////////////////////////////////////////////////////
88 //
89 // Description:
90 // Destructor
91 //
92 // Use: private
93
94 SoIndexedShapecxx . . $ SoIndexedShape#::~cxx . . $ SoIndexedShape#`~SoIndexedShape`(49f6e7a06ebc5aa8).SoIndexedShapecxx . . $ SoIndexedShape#()
95 //
96 ////////////////////////////////////////////////////////////////////////
97 {
98 if (materialBindingcxx . . $ SoIndexedShape#materialBinding. == SoMaterialBindingElementcxx . . $ SoMaterialBindingElement#::PER_VERTEXcxx . . $ SoMaterialBindingElement#PER_VERTEX.)
99 delete[] ((int32_tcxx . . $ int32_t# *)colorIcxx . . $ SoIndexedShape#colorI.);
100
101 if (normalBindingcxx . . $ SoIndexedShape#normalBinding. == SoNormalBindingElementcxx . . $ SoNormalBindingElement#::PER_VERTEXcxx . . $ SoNormalBindingElement#PER_VERTEX.)
102 delete[] ((int32_tcxx . . $ int32_t# *)normalIcxx . . $ SoIndexedShape#normalI.);
103
104 if (texCoordBindingcxx . . $ SoIndexedShape#texCoordBinding. == SoTextureCoordinateBindingElementcxx . . $ SoTextureCoordinateBindingElement#::PER_VERTEXcxx . . $ SoTextureCoordinateBindingElement#PER_VERTEX.)
105 delete[] ((int32_tcxx . . $ int32_t# *)texCoordIcxx . . $ SoIndexedShape#texCoordI.);
106
107 }
108
109 ////////////////////////////////////////////////////////////////////////
110 //
111 // Description:
112 // Keep things up to date when my fields change
113 //
114 // Use: protected
115
116 void
117 SoIndexedShapecxx . . $ SoIndexedShape#::notifycxx . . $ SoIndexedShape#notify(f43de791d8d2eb5a).(SoNotListcxx . . $ SoNotList# *list)
118 //
119 ////////////////////////////////////////////////////////////////////////
120 {
121 if (list->getLastReccxx . . $ SoNotList#getLastRec(a39986cdb7d7aef6).()->getTypecxx . . $ SoNotRec#getType(30fb18e4d3ac32aa).() == SoNotReccxx . . $ SoNotRec#::CONTAINERcxx . . $ SoNotRec#CONTAINER.) {
122 if (list->getLastFieldcxx . . $ SoNotList#getLastField(c4a4d937024b6702).() == &coordIndexcxx . . $ SoIndexedShape#coordIndex. ||
123 list->getLastFieldcxx . . $ SoNotList#getLastField(c4a4d937024b6702).() == &materialIndexcxx . . $ SoIndexedShape#materialIndex. ||
124 list->getLastFieldcxx . . $ SoNotList#getLastField(c4a4d937024b6702).() == &normalIndexcxx . . $ SoIndexedShape#normalIndex. ||
125 list->getLastFieldcxx . . $ SoNotList#getLastField(c4a4d937024b6702).() == &textureCoordIndexcxx . . $ SoIndexedShape#textureCoordIndex.) {
126
127 // Force re-evaluation:
128 materialBindingcxx . . $ SoIndexedShape#materialBinding. = normalBindingcxx . . $ SoIndexedShape#normalBinding. = texCoordBindingcxx . . $ SoIndexedShape#texCoordBinding. = 0;
129 }
130 }
131
132 SoVertexShapecxx . . $ SoVertexShape#::notifycxx . . $ SoVertexShape#notify(f43de791d8d2eb5a).(list);
133 }
134
135 ////////////////////////////////////////////////////////////////////////
136 //
137 // Description:
138 // This handles bounding box computation for all shapes derived
139 // from this class. It sets the bounding box to contain all
140 // vertices of the shape, assuming that the shape uses the
141 // coordinates indexed by all non-negative values in the coordIndex
142 // field. It also sets the center to the average of the vertices'
143 // coordinates.
144 //
145 // Use: protected
146
147 void
148 SoIndexedShapecxx . . $ SoIndexedShape#::computeBBoxcxx . . $ SoIndexedShape#computeBBox(263a5bbe2b28e9a1).(SoActioncxx . . $ SoAction# *action, SbBox3fcxx . . $ SbBox3f# &box, SbVec3fcxx . . $ SbVec3f# &center)
149 //
150 ////////////////////////////////////////////////////////////////////////
151 {
152 int32_tcxx . . $ int32_t# i, numIndices, numUsed;
153 const int32_tcxx . . $ int32_t# *indices;
154 const SoCoordinateElementcxx . . $ SoCoordinateElement# *ce = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
155 const SbVec3fcxx . . $ SbVec3f# *vpCoords = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
156
157 SoVertexPropertycxx . . $ SoVertexProperty# *vp = (SoVertexPropertycxx . . $ SoVertexProperty# *)vertexPropertycxx . . $ SoVertexShape#vertexProperty..getValuecxx . . $ SoSFNode#getValue(b794963b450d51b3).();
158 if (vp && vp->vertexcxx . . $ SoVertexProperty#vertex..getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).() > 0) {
159 vpCoords = vp->vertexcxx . . $ SoVertexProperty#vertex..getValuescxx . . $ SoMFVec3f#getValues(aa6f7bb3bba6ed95).(0);
160 } else {
161 ce = SoCoordinateElementcxx . . $ SoCoordinateElement#::getInstancecxx . . $ SoCoordinateElement#getInstance(297609619ca4e687).(action->getStatecxx . . $ SoAction#getState(5c8eb8fe6550a03).());
162 }
163
164 // Start with an empty box and zero sum
165 center.setValuecxx . . $ SbVec3f#setValue(4e87f9d875f2d08d).(0, 0, 0);
166 box.makeEmptycxx . . $ SbBox3f#makeEmpty(49f6e7a06ebc5aa8).();
167
168 // Loop through coordinates, keeping bounding box and sum of coords
169 numIndices = coordIndexcxx . . $ SoIndexedShape#coordIndex..getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).();
170 indices = coordIndexcxx . . $ SoIndexedShape#coordIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
171 numUsed = 0;
172 for (i = 0; i < numIndices; i++) {
173
174 // Look only at non-negative index values
175 if (indices[i] >= 0) {
176 const SbVec3fcxx . . $ SbVec3f# &v = (ce ? ce->get3cxx . . $ SoCoordinateElement#get3(e550528ef0703ba8).((int) indices[i]) :
177 vpCoords[indices[i]]);
178 box.extendBycxx . . $ SbBox3f#extendBy(65a601b9d70571d6).(v);
179 center +=cxx . . $ SbVec3f#`operator+=`(13422326b1abca17). v;
180 numUsed++;
181 }
182 }
183
184 // Center is average of all coordinates
185 center /=cxx . . $ SbVec3f#`operator/=`(3aaca777b5795e29). (float) numUsed;
186 }
187
188 ////////////////////////////////////////////////////////////////////////
189 //
190 // Description:
191 // Returns TRUE if texture coordinates should be indexed.
192 //
193 // Use: protected, static
194
195 SbBoolcxx . . $ SbBool#
196 SoIndexedShapecxx . . $ SoIndexedShape#::areTexCoordsIndexedcxx . . $ SoIndexedShape#areTexCoordsIndexed(f0260ffa0c6925e7).(SoActioncxx . . $ SoAction# *action)
197 //
198 ////////////////////////////////////////////////////////////////////////
199 {
200 return SoTextureCoordinateBindingElementcxx . . $ SoTextureCoordinateBindingElement#::getcxx . . $ SoTextureCoordinateBindingElement#get(2b8b0c64f5b7c323).(action->getStatecxx . . $ SoAction#getState(5c8eb8fe6550a03).())
201 == SoTextureCoordinateBindingElementcxx . . $ SoTextureCoordinateBindingElement#::PER_VERTEX_INDEXEDcxx . . $ SoTextureCoordinateBindingElement#PER_VERTEX_INDEXED.;
202 }
203
204 ////////////////////////////////////////////////////////////////////////
205 //
206 // Description:
207 // Starting at a given index in the coordIndex array, figure out
208 // how many vertices there are before either the end of the array
209 // or the next 'border' index:
210 //
211 // Use: protected
212
213 int
214 SoIndexedShapecxx . . $ SoIndexedShape#::getNumVertscxx . . $ SoIndexedShape#getNumVerts(7864480464b09eea).(int startCoord)
215 //
216 ////////////////////////////////////////////////////////////////////////
217 {
218 int result = 0;
219 int numIndices = coordIndexcxx . . $ SoIndexedShape#coordIndex..getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).();
220
221 while (startCoord+result < numIndices &&
222 coordIndexcxx . . $ SoIndexedShape#coordIndex.[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).startCoord+result] >= 0) {
223 result++;
224 }
225
226 return result;
227 }
228
229 ////////////////////////////////////////////////////////////////////////
230 //
231 // Description:
232 //
233 // Setup for fast rendering. This should be called by subclasses,
234 // which can then use the texCoordI/colorI/normalI arrays (which
235 // will either point to one of the coordIndex arrays, or to a
236 // consective array of integers. This must be called AFTER the
237 // vpCache has been filled in.
238 //
239 // Use: protected
240
241 void
242 SoIndexedShapecxx . . $ SoIndexedShape#::setupIndicescxx . . $ SoIndexedShape#setupIndices(748afa4755bc9595).(int numParts, int numFaces,
243 SbBoolcxx . . $ SbBool# needNormals, SbBoolcxx . . $ SbBool# needTexCoords)
244 //
245 ////////////////////////////////////////////////////////////////////////
246 {
247 #ifdef DEBUG
248 if (vpCache.vertexPtr == NULL) {
249 SoDebugError::post("SoIndexedShape::setupIndices",
250 "vpCache.fillInCache must be called first!\n");
251 }
252 //Check for valid indices:
253 int j;
254 for (j = 0; j < coordIndex.getNum(); j++){
255 if (coordIndex[j] != -1) {
256 if (coordIndex[j] >= vpCache.getNumVertices() ||
257 coordIndex[j] < 0 ){
258 SoDebugError::post("SoIndexedShape",
259 "vertex index %d is out of range 0 - %d",
260 coordIndex[j], vpCache.getNumVertices());
261 }
262 }
263 }
264 for (j = 0; j < materialIndex.getNum(); j++){
265 if (materialIndex[j] != -1) {
266 if (materialIndex[j] >= vpCache.getNumColors() ||
267 materialIndex[j] < 0 ){
268 SoDebugError::post("SoIndexedShape",
269 "material index %d is out of range 0 - %d",
270 materialIndex[j], vpCache.getNumColors());
271 }
272 }
273 }
274 if (needNormals) {
275 for (j = 0; j < normalIndex.getNum(); j++){
276 if (normalIndex[j] != -1) {
277 if (normalIndex[j] >= vpCache.getNumNormals() ||
278 normalIndex[j] < 0 ){
279 SoDebugError::post("SoIndexedShape",
280 "normal index %d is out of range 0 - %d",
281 normalIndex[j], vpCache.getNumNormals());
282 }
283 }
284 }
285 }
286 if (needTexCoords){
287 for (j = 0; j < textureCoordIndex.getNum(); j++){
288 if (textureCoordIndex[j] != -1) {
289 if (textureCoordIndex[j] >= vpCache.getNumTexCoords() ||
290 textureCoordIndex[j] < 0 ){
291 SoDebugError::post("SoIndexedShape",
292 "texture coordinate index %d is out of range 0 - %d",
293 textureCoordIndex[j], vpCache.getNumTexCoords());
294 }
295 }
296 }
297 }
298 #endif /*DEBUG*/
299
300 if (materialBindingcxx . . $ SoIndexedShape#materialBinding. != vpCachecxx . . $ SoVertexShape#vpCache..getMaterialBindingcxx . . $ SoVertexPropertyCache#getMaterialBinding(27124d36ee72513f).()) {
301 // Free if old binding was PER_VERTEX:
302 if (materialBindingcxx . . $ SoIndexedShape#materialBinding. == SoMaterialBindingElementcxx . . $ SoMaterialBindingElement#::PER_VERTEXcxx . . $ SoMaterialBindingElement#PER_VERTEX.) {
303 // Ok to cast const away here:
304 delete[] ((int32_tcxx . . $ int32_t# *)colorIcxx . . $ SoIndexedShape#colorI.);
305 colorIcxx . . $ SoIndexedShape#colorI. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
306 }
307 materialBindingcxx . . $ SoIndexedShape#materialBinding. = vpCachecxx . . $ SoVertexShape#vpCache..getMaterialBindingcxx . . $ SoVertexPropertyCache#getMaterialBinding(27124d36ee72513f).();
308
309 #ifdef DEBUG
310 int numIndices = 0;
311 int numIndicesNeeded = 0;
312 SbBool useCoordIndexOK = TRUE;
313 int numColorsNeeded = 0;
314 const char *bindingString = NULL;
315 #endif
316
317 switch (vpCachecxx . . $ SoVertexShape#vpCache..getMaterialBindingcxx . . $ SoVertexPropertyCache#getMaterialBinding(27124d36ee72513f).()) {
318 case SoMaterialBindingElementcxx . . $ SoMaterialBindingElement#::OVERALLcxx . . $ SoMaterialBindingElement#OVERALL.:
319 break;
320 case SoMaterialBindingElementcxx . . $ SoMaterialBindingElement#::PER_PARTcxx . . $ SoMaterialBindingElement#PER_PART.:
321 allocateSequentialcxx . . $ SoIndexedShape#allocateSequential(d4f767463ce0a6b3).(numParts);
322 colorIcxx . . $ SoIndexedShape#colorI. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
323 #ifdef DEBUG
324 numColorsNeeded = numParts;
325 bindingString = "PER_PART";
326 #endif
327 break;
328 case SoMaterialBindingElementcxx . . $ SoMaterialBindingElement#::PER_FACEcxx . . $ SoMaterialBindingElement#PER_FACE.:
329 allocateSequentialcxx . . $ SoIndexedShape#allocateSequential(d4f767463ce0a6b3).(numFaces);
330 colorIcxx . . $ SoIndexedShape#colorI. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
331 #ifdef DEBUG
332 numColorsNeeded = numFaces;
333 bindingString = "PER_FACE";
334 #endif
335 break;
336
337 case SoMaterialBindingElementcxx . . $ SoMaterialBindingElement#::PER_VERTEXcxx . . $ SoMaterialBindingElement#PER_VERTEX.:
338 // The annoying case:
339 colorIcxx . . $ SoIndexedShape#colorI. = allocateSequentialWithHolescxx . . $ SoIndexedShape#allocateSequentialWithHoles(a7741f82f5fc3640).();
340 #ifdef DEBUG
341 for (int i = 0; i < coordIndex.getNum(); i++) {
342 if (coordIndex[i] >= 0) ++numColorsNeeded;
343 }
344 bindingString = "PER_VERTEX";
345 #endif
346 break;
347
348 case SoMaterialBindingElementcxx . . $ SoMaterialBindingElement#::PER_PART_INDEXEDcxx . . $ SoMaterialBindingElement#PER_PART_INDEXED.:
349 if (materialIndexcxx . . $ SoIndexedShape#materialIndex.[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).0] < 0)
350 colorIcxx . . $ SoIndexedShape#colorI. = coordIndexcxx . . $ SoIndexedShape#coordIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
351 else
352 colorIcxx . . $ SoIndexedShape#colorI. = materialIndexcxx . . $ SoIndexedShape#materialIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
353 #ifdef DEBUG
354 useCoordIndexOK = FALSE;
355 numIndicesNeeded = numParts;
356 bindingString = "PER_PART_INDEXED";
357 if (colorI == coordIndex.getValues(0)) {
358 numIndices = coordIndex.getNum();
359 } else {
360 numIndices = materialIndex.getNum();
361 }
362 #endif
363 break;
364 case SoMaterialBindingElementcxx . . $ SoMaterialBindingElement#::PER_FACE_INDEXEDcxx . . $ SoMaterialBindingElement#PER_FACE_INDEXED.:
365 if (materialIndexcxx . . $ SoIndexedShape#materialIndex.[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).0] < 0)
366 colorIcxx . . $ SoIndexedShape#colorI. = coordIndexcxx . . $ SoIndexedShape#coordIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
367 else
368 colorIcxx . . $ SoIndexedShape#colorI. = materialIndexcxx . . $ SoIndexedShape#materialIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
369 #ifdef DEBUG
370 useCoordIndexOK = FALSE;
371 numIndicesNeeded = numFaces;
372 bindingString = "PER_FACE_INDEXED";
373 if (colorI == coordIndex.getValues(0)) {
374 numIndices = coordIndex.getNum();
375 } else {
376 numIndices = materialIndex.getNum();
377 }
378 #endif
379 break;
380 case SoMaterialBindingElementcxx . . $ SoMaterialBindingElement#::PER_VERTEX_INDEXEDcxx . . $ SoMaterialBindingElement#PER_VERTEX_INDEXED.:
381 if (materialIndexcxx . . $ SoIndexedShape#materialIndex.[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).0] < 0)
382 colorIcxx . . $ SoIndexedShape#colorI. = coordIndexcxx . . $ SoIndexedShape#coordIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
383 else
384 colorIcxx . . $ SoIndexedShape#colorI. = materialIndexcxx . . $ SoIndexedShape#materialIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
385 #ifdef DEBUG
386 useCoordIndexOK = TRUE;
387 numIndicesNeeded = coordIndex.getNum();
388 bindingString = "PER_VERTEX_INDEXED";
389 if (colorI == coordIndex.getValues(0)) {
390 numIndices = coordIndex.getNum();
391 } else {
392 numIndices = materialIndex.getNum();
393 }
394 #endif
395 break;
396 }
397
398 #ifdef DEBUG
399 // Check for mis-use of default materialIndex field
400 if (useCoordIndexOK == FALSE &&
401 colorI == coordIndex.getValues(0)) {
402 SoDebugError::post("SoIndexedShape",
403 "Material binding is %s"
404 " but materialIndex[0] < 0; coordIndex"
405 " will be used, which is probably not what"
406 " you want", bindingString);
407 }
408 // Check for enough indices:
409 if (numIndices < numIndicesNeeded) {
410 SoDebugError::post("SoIndexedShape",
411 "Need %d indices for %s "
412 " material binding, have only %d",
413 numIndicesNeeded, bindingString, numIndices);
414 }
415 else if (numIndices > 0) {
416 // Find greatest index:
417 for (int i = 0; i < numIndices; i++) {
418 if (colorI[i] > numColorsNeeded)
419 numColorsNeeded = colorI[i];
420 }
421 }
422 if (vpCache.getNumColors() < numColorsNeeded) {
423 SoDebugError::post("SoIndexedShape",
424 "Material binding is %s, but only %d"
425 " colors given (%d needed)",
426 bindingString, vpCache.getNumColors(), numColorsNeeded);
427 }
428 #endif
429 }
430 if (needNormals && (normalBindingcxx . . $ SoIndexedShape#normalBinding. != vpCachecxx . . $ SoVertexShape#vpCache..getNormalBindingcxx . . $ SoVertexPropertyCache#getNormalBinding(88d1b33e1596809a).())) {
431 // Free if old binding was PER_VERTEX:
432 if (normalBindingcxx . . $ SoIndexedShape#normalBinding. == SoNormalBindingElementcxx . . $ SoNormalBindingElement#::PER_VERTEXcxx . . $ SoNormalBindingElement#PER_VERTEX.) {
433 // Ok to cast const away here:
434 delete[] ((int32_tcxx . . $ int32_t# *)normalIcxx . . $ SoIndexedShape#normalI.);
435 normalIcxx . . $ SoIndexedShape#normalI. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
436 }
437 normalBindingcxx . . $ SoIndexedShape#normalBinding. = vpCachecxx . . $ SoVertexShape#vpCache..getNormalBindingcxx . . $ SoVertexPropertyCache#getNormalBinding(88d1b33e1596809a).();
438
439 #ifdef DEBUG
440 int numIndices = 0;
441 int numIndicesNeeded = 0;
442 SbBool useCoordIndexOK = TRUE;
443 int numNormalsNeeded = 0;
444 const char *bindingString = NULL;
445 #endif
446
447 switch (vpCachecxx . . $ SoVertexShape#vpCache..getNormalBindingcxx . . $ SoVertexPropertyCache#getNormalBinding(88d1b33e1596809a).()) {
448 case SoNormalBindingElementcxx . . $ SoNormalBindingElement#::OVERALLcxx . . $ SoNormalBindingElement#OVERALL.:
449 break;
450 case SoNormalBindingElementcxx . . $ SoNormalBindingElement#::PER_PARTcxx . . $ SoNormalBindingElement#PER_PART.:
451 allocateSequentialcxx . . $ SoIndexedShape#allocateSequential(d4f767463ce0a6b3).(numParts);
452 normalIcxx . . $ SoIndexedShape#normalI. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
453 #ifdef DEBUG
454 numNormalsNeeded = numParts;
455 bindingString = "PER_PART";
456 #endif
457 break;
458 case SoNormalBindingElementcxx . . $ SoNormalBindingElement#::PER_FACEcxx . . $ SoNormalBindingElement#PER_FACE.:
459 allocateSequentialcxx . . $ SoIndexedShape#allocateSequential(d4f767463ce0a6b3).(numFaces);
460 normalIcxx . . $ SoIndexedShape#normalI. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
461 #ifdef DEBUG
462 numNormalsNeeded = numFaces;
463 bindingString = "PER_FACE";
464 #endif
465 break;
466
467 case SoNormalBindingElementcxx . . $ SoNormalBindingElement#::PER_VERTEXcxx . . $ SoNormalBindingElement#PER_VERTEX.:
468 // The annoying case:
469 normalIcxx . . $ SoIndexedShape#normalI. = allocateSequentialWithHolescxx . . $ SoIndexedShape#allocateSequentialWithHoles(a7741f82f5fc3640).();
470 #ifdef DEBUG
471 for (int i = 0; i < coordIndex.getNum(); i++) {
472 if (coordIndex[i] >= 0) ++numNormalsNeeded;
473 }
474 bindingString = "PER_VERTEX";
475 #endif
476 break;
477
478 case SoNormalBindingElementcxx . . $ SoNormalBindingElement#::PER_PART_INDEXEDcxx . . $ SoNormalBindingElement#PER_PART_INDEXED.:
479 if (normalIndexcxx . . $ SoIndexedShape#normalIndex.[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).0] < 0)
480 normalIcxx . . $ SoIndexedShape#normalI. = coordIndexcxx . . $ SoIndexedShape#coordIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
481 else
482 normalIcxx . . $ SoIndexedShape#normalI. = normalIndexcxx . . $ SoIndexedShape#normalIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
483 #ifdef DEBUG
484 useCoordIndexOK = FALSE;
485 numIndicesNeeded = numParts;
486 bindingString = "PER_PART_INDEXED";
487 if (normalI == coordIndex.getValues(0)) {
488 numIndices = coordIndex.getNum();
489 } else {
490 numIndices = normalIndex.getNum();
491 }
492 #endif
493 break;
494 case SoNormalBindingElementcxx . . $ SoNormalBindingElement#::PER_FACE_INDEXEDcxx . . $ SoNormalBindingElement#PER_FACE_INDEXED.:
495 if (normalIndexcxx . . $ SoIndexedShape#normalIndex.[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).0] < 0)
496 normalIcxx . . $ SoIndexedShape#normalI. = coordIndexcxx . . $ SoIndexedShape#coordIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
497 else
498 normalIcxx . . $ SoIndexedShape#normalI. = normalIndexcxx . . $ SoIndexedShape#normalIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
499 #ifdef DEBUG
500 useCoordIndexOK = FALSE;
501 numIndicesNeeded = numFaces;
502 bindingString = "PER_FACE_INDEXED";
503 if (normalI == coordIndex.getValues(0)) {
504 numIndices = coordIndex.getNum();
505 } else {
506 numIndices = normalIndex.getNum();
507 }
508 #endif
509 break;
510 case SoNormalBindingElementcxx . . $ SoNormalBindingElement#::PER_VERTEX_INDEXEDcxx . . $ SoNormalBindingElement#PER_VERTEX_INDEXED.:
511 if (normalIndexcxx . . $ SoIndexedShape#normalIndex.[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).0] < 0)
512 normalIcxx . . $ SoIndexedShape#normalI. = coordIndexcxx . . $ SoIndexedShape#coordIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
513 else
514 normalIcxx . . $ SoIndexedShape#normalI. = normalIndexcxx . . $ SoIndexedShape#normalIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
515 #ifdef DEBUG
516 useCoordIndexOK = TRUE;
517 numIndicesNeeded = coordIndex.getNum();
518 bindingString = "PER_VERTEX_INDEXED";
519 if (normalI == coordIndex.getValues(0)) {
520 numIndices = coordIndex.getNum();
521 } else {
522 numIndices = normalIndex.getNum();
523 }
524 #endif
525 break;
526 }
527
528 #ifdef DEBUG
529 // Check for mis-use of default normalIndex field
530 if (useCoordIndexOK == FALSE &&
531 normalI == coordIndex.getValues(0)) {
532 SoDebugError::post("SoIndexedShape",
533 "Normal binding is %s"
534 " but normalIndex[0] < 0; coordIndex"
535 " will be used, which is probably not what"
536 " you want", bindingString);
537 }
538 // Check for enough indices:
539 if (numIndices < numIndicesNeeded) {
540 SoDebugError::post("SoIndexedShape",
541 "Need %d indices for %s "
542 " normal binding, have only %d",
543 numIndicesNeeded, bindingString, numIndices);
544 }
545 else if (numIndices > 0) {
546 // Find greatest index:
547 for (int i = 0; i < numIndices; i++) {
548 if (normalI[i] > numNormalsNeeded)
549 numNormalsNeeded = normalI[i];
550 }
551 }
552 if (vpCache.getNumNormals() < numNormalsNeeded) {
553 SoDebugError::post("SoIndexedShape",
554 "Normal binding is %s, but only %d"
555 " normals given (%d needed)",
556 bindingString, vpCache.getNumNormals(), numNormalsNeeded);
557 }
558 #endif
559 }
560
561 if (needTexCoords && (texCoordBindingcxx . . $ SoIndexedShape#texCoordBinding. != vpCachecxx . . $ SoVertexShape#vpCache..getTexCoordBindingcxx . . $ SoVertexPropertyCache#getTexCoordBinding(327dacc443b4bfc2).())) {
562 // Free if old binding was PER_VERTEX:
563 if (texCoordBindingcxx . . $ SoIndexedShape#texCoordBinding. == SoTextureCoordinateBindingElementcxx . . $ SoTextureCoordinateBindingElement#::PER_VERTEXcxx . . $ SoTextureCoordinateBindingElement#PER_VERTEX.) {
564 // Ok to cast const away here:
565 delete[] ((int32_tcxx . . $ int32_t# *)texCoordIcxx . . $ SoIndexedShape#texCoordI.);
566 texCoordIcxx . . $ SoIndexedShape#texCoordI. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
567 }
568 texCoordBindingcxx . . $ SoIndexedShape#texCoordBinding. = vpCachecxx . . $ SoVertexShape#vpCache..getTexCoordBindingcxx . . $ SoVertexPropertyCache#getTexCoordBinding(327dacc443b4bfc2).();
569
570 #ifdef DEBUG
571 int numIndices = 0;
572 int numIndicesNeeded = 0;
573 int numTexCoordsNeeded = 0;
574 const char *bindingString = NULL;
575 #endif
576 switch (vpCachecxx . . $ SoVertexShape#vpCache..getTexCoordBindingcxx . . $ SoVertexPropertyCache#getTexCoordBinding(327dacc443b4bfc2).()) {
577 case SoTextureCoordinateBindingElementcxx . . $ SoTextureCoordinateBindingElement#::PER_VERTEXcxx . . $ SoTextureCoordinateBindingElement#PER_VERTEX.:
578 // The annoying case:
579 texCoordIcxx . . $ SoIndexedShape#texCoordI. = allocateSequentialWithHolescxx . . $ SoIndexedShape#allocateSequentialWithHoles(a7741f82f5fc3640).();
580 #ifdef DEBUG
581 for (int i = 0; i < coordIndex.getNum(); i++) {
582 if (coordIndex[i] >= 0) ++numTexCoordsNeeded;
583 }
584 bindingString = "PER_VERTEX";
585 #endif
586 break;
587
588 case SoTextureCoordinateBindingElementcxx . . $ SoTextureCoordinateBindingElement#::PER_VERTEX_INDEXEDcxx . . $ SoTextureCoordinateBindingElement#PER_VERTEX_INDEXED.:
589 if (textureCoordIndexcxx . . $ SoIndexedShape#textureCoordIndex.[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).0] < 0)
590 texCoordIcxx . . $ SoIndexedShape#texCoordI. = coordIndexcxx . . $ SoIndexedShape#coordIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
591 else
592 texCoordIcxx . . $ SoIndexedShape#texCoordI. = textureCoordIndexcxx . . $ SoIndexedShape#textureCoordIndex..getValuescxx . . $ SoMFInt32#getValues(7547fac9af83ee5e).(0);
593 #ifdef DEBUG
594 numIndicesNeeded = numFaces;
595 bindingString = "PER_VERTEX_INDEXED";
596 if (texCoordI == coordIndex.getValues(0)) {
597 numIndices = coordIndex.getNum();
598 } else {
599 numIndices = textureCoordIndex.getNum();
600 }
601 #endif
602 break;
603 }
604 #ifdef DEBUG
605 // Check for enough indices:
606 if (numIndices < numIndicesNeeded) {
607 SoDebugError::post("SoIndexedShape",
608 "Need %d indices for %s "
609 " texCoord binding, have only %d",
610 bindingString, numFaces, numIndices);
611 }
612 else if (numIndices > 0) {
613 // Find greatest index:
614 for (int i = 0; i < numIndices; i++) {
615 if (texCoordI[i] > numTexCoordsNeeded)
616 numTexCoordsNeeded = texCoordI[i];
617 }
618 }
619 if (vpCache.getNumTexCoords() < numTexCoordsNeeded) {
620 SoDebugError::post("SoIndexedShape",
621 "TexCoord binding is %s, but only %d"
622 " texCoords given (%d needed)",
623 bindingString, vpCache.getNumTexCoords(), numTexCoordsNeeded);
624 }
625 #endif
626 }
627 }
628
629 ////////////////////////////////////////////////////////////////////////
630 //
631 // Description:
632 // Re-allocate the consecutiveIndices array, if necessary
633 //
634 // Use: private
635
636 void
637 SoIndexedShapecxx . . $ SoIndexedShape#::allocateSequentialcxx . . $ SoIndexedShape#allocateSequential(d4f767463ce0a6b3).(int howMany)
638 //
639 ////////////////////////////////////////////////////////////////////////
640 {
641 if (howMany > numConsecutiveIndicesAllocatedcxx . . $ SoIndexedShape#numConsecutiveIndicesAllocated.) {
642 numConsecutiveIndicesAllocatedcxx . . $ SoIndexedShape#numConsecutiveIndicesAllocated. = howMany;
643 if (consecutiveIndicescxx . . $ SoIndexedShape#consecutiveIndices. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
644 delete[] consecutiveIndicescxx . . $ SoIndexedShape#consecutiveIndices.;
645 }
646 consecutiveIndicescxx . . $ SoIndexedShape#consecutiveIndices. = new int32_tcxx . . $ int32_t#[howMany];
647 for (int i = 0; i < howMany; i++) {
648 consecutiveIndicescxx . . $ SoIndexedShape#consecutiveIndices.[i] = i;
649 }
650 }
651 }
652
653 ////////////////////////////////////////////////////////////////////////
654 //
655 // Description:
656 // Return an array for PER_VERTEX bindings (with -1's in the right
657 // spots)
658 //
659 // Use: private
660
661 int32_tcxx . . $ int32_t# *
662 SoIndexedShapecxx . . $ SoIndexedShape#::allocateSequentialWithHolescxx . . $ SoIndexedShape#allocateSequentialWithHoles(a7741f82f5fc3640).()
663 //
664 ////////////////////////////////////////////////////////////////////////
665 {
666 int count = 0;
667 int num = coordIndexcxx . . $ SoIndexedShape#coordIndex..getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).();
668 int32_tcxx . . $ int32_t# *result = new int32_tcxx . . $ int32_t#[num];
669 for (int i = 0; i < num; i++) {
670 if (coordIndexcxx . . $ SoIndexedShape#coordIndex.[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).i] >= 0) {
671 result[i] = count;
672 count++;
673 }
674 else
675 result[i] = coordIndexcxx . . $ SoIndexedShape#coordIndex.[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).i]; // Just copy-over negatives
676 }
677 return result;
678 }