Debian Codegraph @

apps/nodes/GeneralizedCylinder/Triangulator.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 // Code for a Generalized Cylinder class. This is not really very
39 // robust or well-designed (or complete or...).
40 //
41
42 #include <cstdio>
43 #include <Inventor/SbLinear.h>cxx . . $ `<file>/lib/database/include/Inventor/SbLinear.h`/
44 #include <Inventor/fields/SoMFInt32.h>cxx . . $ `<file>/lib/database/include/Inventor/fields/SoMFInt32.h`/
45 #include <Inventor/fields/SoMFVec3f.h>cxx . . $ `<file>/lib/database/include/Inventor/fields/SoMFVec3f.h`/
46
47 #include "Triangulator.h"cxx . . $ `<file>/apps/nodes/GeneralizedCylinder/Triangulator.h`/
48
49
50
51 //**********************************************************************
52 //
53 // Returns FALSE if the two line segments intersect each other at only
54 // one point.
55 // Returns TRUE if they are parallel or if they intersect at a point
56 // external to either line segment.
57 //
58 // Assumes that the four points lie in the y = 0 plane.
59 //
60 //**********************************************************************
61
62 SbBoolcxx . . $ SbBool#
63 Triangulatorcxx . . $ Triangulator#::triangEdgeTestcxx . . $ Triangulator#triangEdgeTest(be10a0491caab0b2).(const SoMFVec3fcxx . . $ SoMFVec3f# &coords,
64 int32_t e0p0, int32_t e0p1, int32_t e1p0, int32_t e1p1 )
65 {
66 float x00 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) e0p0][cxx . . $ SbVec3f#`operator[]`(c60a38c584b9a5cc).0];
67 float x10 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) e1p0][cxx . . $ SbVec3f#`operator[]`(c60a38c584b9a5cc).0];
68 float z00 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) e0p0][cxx . . $ SbVec3f#`operator[]`(c60a38c584b9a5cc).2];
69 float z10 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) e1p0][cxx . . $ SbVec3f#`operator[]`(c60a38c584b9a5cc).2];
70
71 float dx0 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) e0p1][cxx . . $ SbVec3f#`operator[]`(c60a38c584b9a5cc).0] - x00;
72 float dx1 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) e1p1][cxx . . $ SbVec3f#`operator[]`(c60a38c584b9a5cc).0] - x10;
73 float dz0 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) e0p1][cxx . . $ SbVec3f#`operator[]`(c60a38c584b9a5cc).2] - z00;
74 float dz1 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) e1p1][cxx . . $ SbVec3f#`operator[]`(c60a38c584b9a5cc).2] - z10;
75
76 float diffx = x10 - x00;
77 float diffz = z10 - z00;
78
79 float determ = dx0 * -dz1 - dz0 * -dx1;
80
81 if (determ == 0) // lines are parallel
82 return( TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`! );
83
84 // otherwise, solve for intersection point
85 // first, solve for parametric length on edge 1 from e0p0 to e0p1
86 float parametric_val = (-dz1 * diffx + dx1 * diffz) / determ;
87
88 #define SMALL_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:88:9`! 0.00001
89
90 if (parametric_val > 1.0 - SMALL_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:88:9`! || parametric_val < SMALL_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:88:9`!)
91 // value lies outside line segment
92 return( TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`! );
93
94 // next, solve for parametric length on edge 1 from e1p0 to e1p1
95 parametric_val = (-dz0 * diffx + dx0 * diffz) / determ;
96
97 if (parametric_val > 1.0 - SMALL_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:88:9`! || parametric_val < SMALL_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:88:9`!)
98 // value lies outside line segment
99 return( TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`! );
100
101 #undef SMALL_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:88:9`!
102
103 // otherwise, intersection point lies within both segments
104 return(FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!);
105 }
106
107 SbBoolcxx . . $ SbBool#
108 Triangulatorcxx . . $ Triangulator#::clockWiseTestcxx . . $ Triangulator#clockWiseTest(1fd5b3a20eb236d8).( const SoMFVec3fcxx . . $ SoMFVec3f# &coords,
109 const SoMFInt32cxx . . $ SoMFInt32# &indices, int startVert, int numVerts )
110 {
111 // ARE THE COORDS GIVEN BY THIS POLYGON CLOCKWISE ORDERED WHEN VIEWED
112 // FROM ABOVE?
113 // ASSUME THAT ALL THE POINTS LIE IN THE Y=0 PLANE.
114 // How do we know? Well, the total of the interior angles
115 // for an n-sided polygon is:
116 // interior_angles = (PI * n) - (2 * PI)
117 // while:
118 // exterior_angles = (PI * n) + (2 * PI)
119 // So we total up the interior angles, and reverse the
120 // order of the vertices if it is the wrong amount
121 float angle_total = 0;
122 for( int vNum = 0; vNum < numVerts; vNum++ ) {
123 int nextP = (vNum == numVerts - 1) ? 0 : vNum + 1;
124 int prevP = (vNum == 0) ? numVerts - 1 : vNum - 1;
125 SbVec3fcxx . . $ SbVec3f# nextEdge = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) indices[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).startVert + nextP]] -cxx . . $ operator-(af63bf8d0639b76b).
126 coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) indices[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).startVert + vNum]];
127 SbVec3fcxx . . $ SbVec3f# prevEdge = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) indices[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).startVert + prevP]] -cxx . . $ operator-(af63bf8d0639b76b).
128 coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) indices[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).startVert + vNum]];
129 nextEdge.normalizecxx . . $ SbVec3f#normalize(9b8c9e39889c762c).();
130 prevEdge.normalizecxx . . $ SbVec3f#normalize(9b8c9e39889c762c).();
131
132 // WE WANT ALL ANGLES IN THE SENSE OF ROTATING ABOUT THE
133 // POSITIVE Y AXIS
134 SbVec3fcxx . . $ SbVec3f# crossProd = prevEdge.crosscxx . . $ SbVec3f#cross(d67ad7d0c0b29ebb).( nextEdge );
135 if (crossProd[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).1] > 0.0) {
136 angle_total += acos( prevEdge.dotcxx . . $ SbVec3f#dot(adcfb95606509c95).( nextEdge ) );
137 }
138 else {
139 angle_total += 2 * M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`! - acos( prevEdge.dotcxx . . $ SbVec3f#dot(adcfb95606509c95).( nextEdge ) );
140 }
141 }
142 if ( angle_total > M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`! * numVerts )
143 return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
144 else
145 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
146 }
147
148 //**********************************************************************
149 //
150 // Returns TRUE if the first point lies inside the triangle formed by
151 // the other three.
152 //
153 // Assumes that all of the points lie in the plane y = 0
154 // Assumes that the triangle is ordered clockwise when viewed from above
155 // when travelling in the order: pt0 to pt1 to pt2
156 //
157 // Performs the check by doing a cross product between edges of the
158 // triangle and vectors connecting the vertices to the test point.
159 // If the point is inside the triangle, the cross products are positive.
160 // If any are negative, the point lies outside the trianggle.
161 // We only need to check the y values of the cross product, since the
162 // points lie in a horizontal plane.
163 //**********************************************************************
164
165 SbBoolcxx . . $ SbBool#
166 Triangulatorcxx . . $ Triangulator#::triangInsideTestcxx . . $ Triangulator#triangInsideTest(be10a0491caab0b2).( const SoMFVec3fcxx . . $ SoMFVec3f# &coords,
167 int32_t testPt, int32_t pt0, int32_t pt1, int32_t pt2)
168 {
169 SbVec3fcxx . . $ SbVec3f# edge0 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)pt1] -cxx . . $ operator-(af63bf8d0639b76b). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)pt0];
170 SbVec3fcxx . . $ SbVec3f# edge1 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)pt2] -cxx . . $ operator-(af63bf8d0639b76b). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)pt1];
171 SbVec3fcxx . . $ SbVec3f# edge2 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)pt0] -cxx . . $ operator-(af63bf8d0639b76b). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)pt2];
172
173 SbVec3fcxx . . $ SbVec3f# ptEdge0 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)testPt] -cxx . . $ operator-(af63bf8d0639b76b). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)pt0];
174 SbVec3fcxx . . $ SbVec3f# ptEdge1 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)testPt] -cxx . . $ operator-(af63bf8d0639b76b). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)pt1];
175 SbVec3fcxx . . $ SbVec3f# ptEdge2 = coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)testPt] -cxx . . $ operator-(af63bf8d0639b76b). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)pt2];
176
177 #define TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:177:9`! 0.0000001
178
179 if ( ptEdge0[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2] * edge0[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] - ptEdge0[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] * edge0[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2] > TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:177:9`!
180 && ptEdge1[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2] * edge1[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] - ptEdge1[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] * edge1[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2] > TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:177:9`!
181 && ptEdge2[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2] * edge2[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] - ptEdge2[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] * edge2[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2] > TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:177:9`!)
182 return( TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`! );
183 else
184 return( FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`! );
185
186 #undef TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:177:9`!
187
188 }
189
190 //**********************************************************************
191 //
192 // 1] assume all points lie in the y = 0 plane
193 // 2] perform triangulation on the projected polygon, copy the order later
194 // 3] for each point, find two others that form a triangle which meets
195 // the following conditions:
196 // a] Doesn't cut through any other edges
197 // b] Any new edges are on the interior
198 //
199 //**********************************************************************
200
201 SbBoolcxx . . $ SbBool#
202 Triangulatorcxx . . $ Triangulator#::triangulatecxx . . $ Triangulator#triangulate(ce629b07d8fc162b).(
203 const SoMFVec3fcxx . . $ SoMFVec3f# &coords,
204 const SoMFInt32cxx . . $ SoMFInt32# &inVals, // indices describing the input
205 // polygons
206 SoMFInt32cxx . . $ SoMFInt32# &outVals) // indices describing the output
207 // polygons
208 {
209 // CHECK THAT ALL COORDS LIE IN THE y = 0.0 PLANE
210 for( int i = 0; i < coords.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).(); i++ ){
211 if ( coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).i][cxx . . $ SbVec3f#`operator[]`(c60a38c584b9a5cc).1] != 0.0 ) {
212 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Error in triangulation: not all points \n");
213 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!," lie in the y = 0 plane\n");
214 return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
215 }
216 }
217
218 // COPY THE INPUT INTO THE OUTPUT
219 if ( outVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).() < inVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).() )
220 outVals.insertSpacecxx . . $ SoMField#insertSpace(3e454b8ccf442868).( 0, inVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).() - outVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).());
221 else if ( outVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).() > inVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).() )
222 outVals.deleteValuescxx . . $ SoMField#deleteValues(3e454b8ccf442868).( 0, outVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).() - inVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).());
223 outVals =cxx . . $ SoMFInt32#`operator=`(3f2d52d2d6f9a9fd). inVals;
224
225
226 int curInd0 = 0;
227 int curNumVerts = 0;
228
229 SbBoolcxx . . $ SbBool# got_a_tri, tri_ok, keep_going;
230 SbVec3fcxx . . $ SbVec3f# edge2cxx . . $ SbVec3f#SbVec3f(49f6e7a06ebc5aa8)., edge0cxx . . $ SbVec3f#SbVec3f(49f6e7a06ebc5aa8)., prevEdgecxx . . $ SbVec3f#SbVec3f(49f6e7a06ebc5aa8)., nextEdgecxx . . $ SbVec3f#SbVec3f(49f6e7a06ebc5aa8).;
231 int ind0, ind1, ind2, test_ind0, test_ind1;
232 int vNum;
233
234 //***** WALK DOWN THE LIST OF POLYS *****
235
236 int shift_count = 0;
237
238 for ( curInd0 = 0; curInd0 < outVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).(); ) {
239 int j;
240 for( j = curInd0, curNumVerts = 0; j < outVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).(); j++ ) {
241 if ( outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).j] >= 0 )
242 curNumVerts++;
243 else
244 break;
245 }
246
247 // IF ANY THREE CONSECUTIVE POINTS ARE COLINEAR, REMOVE THE
248 // CENTER POINT
249 // Note: we don't have to check that there are three points.
250 // The algorithm will just wind up removing all the points
251 // if there are two or less, or if all the points in the polygon
252 // are colinear.
253 for( vNum = 0; vNum < curNumVerts; vNum++ ) {
254 int nextP = (vNum == curNumVerts - 1) ? 0 : vNum +1;
255 int prevP = (vNum == 0) ? curNumVerts - 1 : vNum - 1;
256 nextEdge =cxx . . $ SbVec3f#`operator=`(c7808628d070cfbe). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).curInd0 + nextP]] -cxx . . $ operator-(af63bf8d0639b76b).
257 coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).curInd0 + vNum]];
258 prevEdge =cxx . . $ SbVec3f#`operator=`(c7808628d070cfbe). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).curInd0 + prevP]] -cxx . . $ operator-(af63bf8d0639b76b).
259 coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int) outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).curInd0 + vNum]];
260
261 // CROSS PRODUCT IS ZERO IF THEY ARE CO-LINEAR
262 SbVec3fcxx . . $ SbVec3f# crossProd = prevEdge.crosscxx . . $ SbVec3f#cross(d67ad7d0c0b29ebb).( nextEdge );
263
264 #define TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:264:9`! 0.0000001
265 #define IS_COORD_TEENYcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:265:9`!(a) ( (a)[0] < TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:264:9`! && (a)[1] < TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:264:9`! \
266 && (a)[2] < TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:264:9`! && (a)[0] > -TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:264:9`! \
267 && (a)[1] > -TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:264:9`! && (a)[2] > -TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:264:9`! )
268
269 if (IS_COORD_TEENYcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:265:9`!( crossProd) ) {
270 // remove the index of this point from the poly
271 outVals.deleteValuescxx . . $ SoMField#deleteValues(3e454b8ccf442868).( curInd0 + vNum, 1);
272
273 curNumVerts--;
274
275 vNum--; // decrement, because everyone's been shifted
276 // down by 1
277 }
278 #undef TEENY_VALcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:264:9`!
279 #undef IS_COORD_TEENYcxx . . $ `apps/nodes/GeneralizedCylinder/Triangulator.c++:265:9`!
280 }
281
282 if ( curNumVerts == 0) {
283 // The polygon has no vertices (this could happen because the
284 // whole polygon was colinear and got removed in the step above.)
285 // Remove the '-1' index that signals the end of the polygon.
286 outVals.deleteValuescxx . . $ SoMField#deleteValues(3e454b8ccf442868).( curInd0, 1 );
287
288 // Do not increment curInd0. By removing the '-1' entry, the
289 // next polygon moves up a slot to have *ITS* first index at
290 // curInd0.
291 }
292 else if ( curNumVerts <= 3) {
293 // Just move on to the next polygon.
294 // (We add an extra 1, because each polygon has a
295 // extra index entry of -1 to indicate the end of the poly
296 curInd0 += curNumVerts + 1;
297 }
298 else {
299
300 // REVERSE ORDER IF NECESSARY
301 if ( !clockWiseTestcxx . . $ Triangulator#clockWiseTest(1fd5b3a20eb236d8).( coords, outVals, curInd0, curNumVerts) ) {
302 int32_t *outIndices = outVals.startEditingcxx . . $ SoMFInt32#startEditing(a7741f82f5fc3640).();
303
304 int32_t tempI, early, late;
305 for ( early = 0, late = curNumVerts - 1;
306 early < late; early++, late-- ) {
307 tempI = outIndices[curInd0 + early];
308 outIndices[curInd0 + early] = outIndices[curInd0 + late];
309 outIndices[curInd0 + late] = tempI;
310 }
311
312 outVals.finishEditingcxx . . $ SoMFInt32#finishEditing(49f6e7a06ebc5aa8).();
313 }
314
315 // find a triangle formed by the first point and two other points
316 // The new triangle must satisfy the condition that no new
317 // Edges intersect any already existing edges in the polygon
318 ind0 = curInd0;
319 keep_going = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
320 for (ind1 = curInd0 + 1, ind2 = curInd0 + 2, got_a_tri = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
321 got_a_tri == FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`! && keep_going == TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; ) {
322 // TEST EACH NEW EDGE AGAINST ALL OTHER EDGES
323 tri_ok = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
324
325 // make sure ordering of new triangle is clockwise
326 // Normal points down if (edge2 cross edge0)[1] < 0.0
327 edge2 =cxx . . $ SbVec3f#`operator=`(c7808628d070cfbe). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind2]] -cxx . . $ operator-(af63bf8d0639b76b). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind0]];
328 edge0 =cxx . . $ SbVec3f#`operator=`(c7808628d070cfbe). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind1]] -cxx . . $ operator-(af63bf8d0639b76b). coords[cxx . . $ SoMFVec3f#`operator[]`(e550528ef0703ba8).(int)outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind0]];
329 if (edge0[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] * edge2[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2] - edge2[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).0] * edge0[cxx . . $ SbVec3f#`operator[]`(5dbdaf238659ae67).2] <= 0.0)
330 tri_ok = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
331
332 // make sure no other points fall inside the newly formed
333 // triangle
334 if (tri_ok == TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!) {
335 for( vNum = curInd0; vNum < curInd0 + curNumVerts; vNum++) {
336 if (vNum != ind0 && vNum != ind1 && vNum != ind2) {
337 if ( triangInsideTestcxx . . $ Triangulator#triangInsideTest(be10a0491caab0b2).(coords,outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).vNum],outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind0], outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind1], outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind2]))
338 tri_ok = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
339 }
340 }
341 }
342
343 // edge between ind0 and ind1
344 if (ind1 != curInd0 + 1) {
345 // edge between point0 and point1 is ok, since part of
346 // original polygon
347 for( test_ind0 = curInd0, test_ind1 = curInd0 + 1;
348 tri_ok == TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`! && test_ind0 < curInd0 + curNumVerts;
349 test_ind0++, test_ind1++) {
350 if (test_ind1 == curInd0 + curNumVerts)
351 test_ind1 = curInd0;
352 tri_ok = triangEdgeTestcxx . . $ Triangulator#triangEdgeTest(be10a0491caab0b2).(coords, outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind0], outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind1],
353 outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).test_ind0], outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).test_ind1]);
354 }
355 }
356
357 // edge between ind1 and ind2 is part of the original polygon
358 // except when forming tri between v0, v1, and final point
359 if (ind2 != ind1 + 1) {
360 for( test_ind0 = curInd0, test_ind1 = curInd0 + 1;
361 tri_ok == TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`! && test_ind0 < curInd0 + curNumVerts;
362 test_ind0++, test_ind1++) {
363 if (test_ind1 == curInd0 + curNumVerts)
364 test_ind1 = curInd0;
365 tri_ok = triangEdgeTestcxx . . $ Triangulator#triangEdgeTest(be10a0491caab0b2).(coords, outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind1], outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind2],
366 outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).test_ind0], outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).test_ind1]);
367 }
368 }
369
370 // edge between ind2 and ind0
371 if (ind2 != curInd0 + curNumVerts -1) {
372 // edge between point0 and last point in poly is ok,since
373 // part of original polygon
374 for( test_ind0 = curInd0, test_ind1 = curInd0 + 1;
375 tri_ok == TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`! && test_ind0 < curInd0 + curNumVerts;
376 test_ind0++, test_ind1++) {
377 if (test_ind1 == curInd0 + curNumVerts)
378 test_ind1 = curInd0;
379 tri_ok = triangEdgeTestcxx . . $ Triangulator#triangEdgeTest(be10a0491caab0b2).(coords, outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind2], outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).ind0],
380 outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).test_ind0], outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045).test_ind1]);
381 }
382 }
383 if (tri_ok == TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!)
384 got_a_tri = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
385 else {
386 if (ind1 == curInd0 + 1 && ind2 == curInd0 + curNumVerts -1)
387 keep_going = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
388 ind1++;
389 ind2++;
390 if (ind2 == curInd0 + curNumVerts) {
391 // If none others worked, try the case where the
392 // the points are first, second, and last
393 ind1 = curInd0 + 1;
394 ind2 = curInd0 + curNumVerts - 1;
395 }
396 }
397 }
398
399 if (got_a_tri == FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!) {
400 // Could not draw a triangle using the first vertex.
401 // Shift all of the vertices in the polygon over and try again
402 shift_count++;
403
404 int32_t *outIndices = outVals.startEditingcxx . . $ SoMFInt32#startEditing(a7741f82f5fc3640).();
405
406 int32_t temp_index = outIndices[ curInd0 + 0];
407
408 for( vNum = curInd0; vNum < curInd0 + curNumVerts - 1; vNum++ )
409 outIndices[ vNum] = outIndices[ vNum + 1];
410 outIndices[ curInd0 + curNumVerts - 1] = temp_index;
411
412 outVals.finishEditingcxx . . $ SoMFInt32#finishEditing(49f6e7a06ebc5aa8).();
413
414 if (shift_count >= curNumVerts) {
415 printf("Error: could not triangulate this polygon\n");
416 printf("It may look funny!\n");
417 return(FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`! );
418 }
419
420 // Do not increment the value of curInd0.
421 // This will mean that the 'for' loop will repeat the entire
422 // process on this polygon (but THIS time, the indices have
423 // been shifted in order.
424 }
425 else {
426
427 shift_count = 0;
428
429 // Create a new triangle which connects the first point
430 // to these two new points
431 // Add this new triangle to the end of the outVals
432
433 int32_t newIndices[4];
434 newIndices[0] = outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045). ind0];
435 newIndices[1] = outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045). ind1];
436 newIndices[2] = outVals[cxx . . $ SoMFInt32#`operator[]`(7ccb52b1bfe01045). ind2];
437 newIndices[3] = -1;
438
439 outVals.setValuescxx . . $ SoMFInt32#setValues(4ba7fc99d2e6f458).( outVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).(), 4, newIndices );
440
441 // Make necessary changes to the old polygon
442 if (ind1 == curInd0 + 1 && ind2 == curInd0 + curNumVerts - 1) {
443 // triangle was first, second, and last points
444 // we need to get rid of first point in the current poly
445 outVals.deleteValuescxx . . $ SoMField#deleteValues(3e454b8ccf442868).( curInd0, 1);
446 curNumVerts--;
447 }
448 else if (ind1 == curInd0 + 1) {
449 // triangle was first three points
450 // we need to get rid of second point
451 outVals.deleteValuescxx . . $ SoMField#deleteValues(3e454b8ccf442868).( curInd0 + 1, 1 );
452 curNumVerts --;
453 }
454 else if (ind2 == curNumVerts - 1) {
455 // triangle was last three points
456 // we need to get rid of last point
457 outVals.deleteValuescxx . . $ SoMField#deleteValues(3e454b8ccf442868).( curInd0 + curNumVerts - 1, 1 );
458 curNumVerts --;
459 }
460 else {
461 // we need to break the poly into 2, since we just created
462 // an interior-type triangle
463 // The first polygon will go from ind0 to ind1
464 // and will reside in the original polygon data structure
465 // The second will continue from ind2 back to ind0
466 // and will be added to the end of outVals.
467
468 // FIRST, ADD THE LATTER POLY TO THE END OF outVals...
469
470 int newPolNumVerts = curInd0 + curNumVerts - ind2 + 1;
471
472 // Add an extra slot for the '-1' which signifies end
473 // of polygon
474 int newPolInd0 = outVals.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).();
475 outVals.insertSpacecxx . . $ SoMField#insertSpace(3e454b8ccf442868).( newPolInd0, newPolNumVerts + 1 );
476
477 int32_t *outIndices = outVals.startEditingcxx . . $ SoMFInt32#startEditing(a7741f82f5fc3640).();
478 // Copy the points from ind2 to the end of the poly
479 for ( int j = newPolInd0, vNum = ind2;
480 vNum < curInd0 + curNumVerts; j++, vNum++ ) {
481 outIndices[j] = outIndices[vNum];
482 }
483 // Copy the initial point...
484 outIndices[newPolInd0 + newPolNumVerts - 1]
485 = outIndices[curInd0];
486
487 // Add the -1 to signify the end
488 outIndices[newPolInd0 + newPolNumVerts] = -1;
489
490 outVals.finishEditingcxx . . $ SoMFInt32#finishEditing(49f6e7a06ebc5aa8).();
491
492
493 // NEXT, REMOVE THE LATTER HALF OF THE FIRST POLY...
494 outVals.deleteValuescxx . . $ SoMField#deleteValues(3e454b8ccf442868).( ind2, newPolNumVerts - 1 );
495
496 // Reduce the num of coords being used from the original
497 // polygon
498 curNumVerts -= newPolNumVerts - 1;
499 }
500 }
501 }
502 }
503
504 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
505 }
506