Debian Codegraph @

lib/database/src/so/nodes/nurbs/libnurbs/arc.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 * arc.c++ - $Revision: 1.1.1.1 $
39 * Derrick Burns - 1991
40 */
41
42
43 #include "glimports.h"cxx . . $ `<file>/lib/database/src/so/nodes/nurbs/head/glimports.h`/
44 #include "mystdio.h"cxx . . $ `<file>/lib/database/src/so/nodes/nurbs/head/mystdio.h`/
45 #include "myassert.h"cxx . . $ `<file>/lib/database/src/so/nodes/nurbs/head/myassert.h`/
46 #include "arc.h"cxx . . $ `<file>/lib/database/src/so/nodes/nurbs/head/arc.h`/
47 #include "bin.h"cxx . . $ `<file>/lib/database/src/so/nodes/nurbs/head/bin.h`/
48 #include "bezierarc.h"cxx . . $ `<file>/lib/database/src/so/nodes/nurbs/head/bezierarc.h`/
49 #include "pwlarc.h"cxx . . $ `<file>/lib/database/src/so/nodes/nurbs/head/pwlarc.h`/
50 #include "simplemath.h"cxx . . $ `<file>/lib/database/src/so/nodes/nurbs/head/simplemath.h`/
51
52 /* local preprocessor definitions */
53 #define ZEROcxx . . $ `lib/database/src/so/nodes/nurbs/libnurbs/arc.c++:53:9`! 0.000001
54
55 const int Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::bezier_tagcxx . . $ _SoNurbsArc#bezier_tag. = (1<<13);
56 const int Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::arc_tagcxx . . $ _SoNurbsArc#arc_tag. = (1<<3);
57 const int Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::tail_tagcxx . . $ _SoNurbsArc#tail_tag. = (1<<6);
58
59 /*--------------------------------------------------------------------------
60 * makeSide - attach a pwl arc to an arc and mark it as a border arc
61 *--------------------------------------------------------------------------
62 */
63
64 void
65 Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::makeSidecxx . . $ _SoNurbsArc#makeSide(b6a2db0dd715013d).( PwlArccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:86:9`! *pwl, arc_sidecxx . . $ arc_side# side )
66 {
67 assertcxx . . $ `/usr/include/assert.h:50:10`!( pwl );
68 assertcxx . . $ `/usr/include/assert.h:50:10`!( pwlArc == 0 );
69 assertcxx . . $ `/usr/include/assert.h:50:10`!( pwl->npts > 0 );
70 assertcxx . . $ `/usr/include/assert.h:50:10`!( pwl->pts );
71 pwlArccxx . . $ _SoNurbsArc#pwlArc. = pwl;
72 clearbeziercxx . . $ _SoNurbsArc#clearbezier(49f6e7a06ebc5aa8).();
73 setsidecxx . . $ _SoNurbsArc#setside(59530057c34e08ed).( side );
74 }
75
76
77 /*--------------------------------------------------------------------------
78 * numpts - count number of points on arc loop
79 *--------------------------------------------------------------------------
80 */
81
82 int
83 Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::numptscxx . . $ _SoNurbsArc#numpts(b126dc7c1de90089).( void )
84 {
85 Arc_ptrcxx . . $ Arc_ptr# jarc = this;
86 int npts = 0;
87 do {
88 npts += jarc->pwlArccxx . . $ _SoNurbsArc#pwlArc.->nptscxx . . $ _SoNurbsPwlArc#npts.;
89 jarc = jarc->nextcxx . . $ _SoNurbsArc#next.;
90 } while( jarc != this );
91 return npts;
92 }
93
94 /*--------------------------------------------------------------------------
95 * markverts - mark each point with id of arc
96 *--------------------------------------------------------------------------
97 */
98
99 void
100 Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::markvertscxx . . $ _SoNurbsArc#markverts(49f6e7a06ebc5aa8).( void )
101 {
102 Arc_ptrcxx . . $ Arc_ptr# jarc = this;
103
104 do {
105 TrimVertexcxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:96:9`! *p = jarc->pwlArccxx . . $ _SoNurbsArc#pwlArc.->ptscxx . . $ _SoNurbsPwlArc#pts.;
106 for( int i=0; i<jarc->pwlArccxx . . $ _SoNurbsArc#pwlArc.->nptscxx . . $ _SoNurbsPwlArc#npts.; i++ )
107 p[i].nuidcxx . . $ _SoNurbsTrimVertex#nuid. = jarc->nuidcxx . . $ _SoNurbsArc#nuid.;
108 jarc = jarc->nextcxx . . $ _SoNurbsArc#next.;
109 } while( jarc != this );
110 }
111
112 /*--------------------------------------------------------------------------
113 * getextrema - find axis extrema on arc loop
114 *--------------------------------------------------------------------------
115 */
116
117 void
118 Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::getextremacxx . . $ _SoNurbsArc#getextrema(59a99a3b4d8a62f5).( Arc_ptrcxx . . $ Arc_ptr# extrema[4] )
119 {
120 REALcxx . . $ REAL# leftpt, botpt, rightpt, toppt;
121
122 extrema[0] = extrema[1] = extrema[2] = extrema[3] = this;
123
124 leftpt = rightpt = this->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[0];
125 botpt = toppt = this->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[1];
126
127 for( Arc_ptrcxx . . $ Arc_ptr# jarc = this->nextcxx . . $ _SoNurbsArc#next.; jarc != this; jarc = jarc->nextcxx . . $ _SoNurbsArc#next. ) {
128 if ( jarc->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[0] < leftpt ||
129 (jarc->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[0] <= leftpt && jarc->rheadcxx . . $ _SoNurbsArc#rhead(a3aba87f01dec7c2).()[0]<=leftpt)) {
130 leftpt = jarc->pwlArccxx . . $ _SoNurbsArc#pwlArc.->ptscxx . . $ _SoNurbsPwlArc#pts.->paramcxx . . $ _SoNurbsTrimVertex#param.[0];
131 extrema[1] = jarc;
132 }
133 if ( jarc->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[0] > rightpt ||
134 (jarc->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[0] >= rightpt && jarc->rheadcxx . . $ _SoNurbsArc#rhead(a3aba87f01dec7c2).()[0] >= rightpt)) {
135 rightpt = jarc->pwlArccxx . . $ _SoNurbsArc#pwlArc.->ptscxx . . $ _SoNurbsPwlArc#pts.->paramcxx . . $ _SoNurbsTrimVertex#param.[0];
136 extrema[3] = jarc;
137 }
138 if ( jarc->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[1] < botpt ||
139 (jarc->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[1] <= botpt && jarc->rheadcxx . . $ _SoNurbsArc#rhead(a3aba87f01dec7c2).()[1] <= botpt )) {
140 botpt = jarc->pwlArccxx . . $ _SoNurbsArc#pwlArc.->ptscxx . . $ _SoNurbsPwlArc#pts.->paramcxx . . $ _SoNurbsTrimVertex#param.[1];
141 extrema[2] = jarc;
142 }
143 if ( jarc->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[1] > toppt ||
144 (jarc->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[1] >= toppt && jarc->rheadcxx . . $ _SoNurbsArc#rhead(a3aba87f01dec7c2).()[1] >= toppt)) {
145 toppt = jarc->pwlArccxx . . $ _SoNurbsArc#pwlArc.->ptscxx . . $ _SoNurbsPwlArc#pts.->paramcxx . . $ _SoNurbsTrimVertex#param.[1];
146 extrema[0] = jarc;
147 }
148 }
149 }
150
151
152 /*-------------------------------------------------------------------------
153 * show - print to the stdout the vertices of a pwl arc
154 *-------------------------------------------------------------------------
155 */
156
157 void
158 Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::showcxx . . $ _SoNurbsArc#show(49f6e7a06ebc5aa8).()
159 {
160 /*#ifndef NDEBUG*/
161 printf( "\tPWLARC NP: %d FL: 1\n", pwlArccxx . . $ _SoNurbsArc#pwlArc.->nptscxx . . $ _SoNurbsPwlArc#npts. );
162 for( int i = 0; i < pwlArccxx . . $ _SoNurbsArc#pwlArc.->nptscxx . . $ _SoNurbsPwlArc#npts.; i++ ) {
163 printf( "\t\tVERTEX %f %f\n", pwlArccxx . . $ _SoNurbsArc#pwlArc.->ptscxx . . $ _SoNurbsPwlArc#pts.[i].paramcxx . . $ _SoNurbsTrimVertex#param.[0],
164 pwlArccxx . . $ _SoNurbsArc#pwlArc.->ptscxx . . $ _SoNurbsPwlArc#pts.[i].paramcxx . . $ _SoNurbsTrimVertex#param.[1] );
165 }
166 /*#endif*/
167 }
168
169 /*-------------------------------------------------------------------------
170 * print - print out the vertices of all pwl arcs on a loop
171 *-------------------------------------------------------------------------
172 */
173
174 void
175 Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::printcxx . . $ _SoNurbsArc#print(49f6e7a06ebc5aa8).( void )
176 {
177 Arc_ptrcxx . . $ Arc_ptr# jarc = this;
178
179 if( ! this ) {
180 #ifndef NDEBUGcxx . . $ `<built-in>:440:9`!
181 dprintf( "\n\nEMPTY TRIM\n\n" );
182 #endif
183 return;
184 }
185
186 #ifndef NDEBUGcxx . . $ `<built-in>:440:9`!
187 dprintf( "BGNTRIM\n" );
188 #endif
189 do {
190 jarc->showcxx . . $ _SoNurbsArc#show(49f6e7a06ebc5aa8).( );
191 jarc = jarc->nextcxx . . $ _SoNurbsArc#next.;
192 } while (jarc != this);
193 #ifndef NDEBUGcxx . . $ `<built-in>:440:9`!
194 dprintf("ENDTRIM\n" );
195 #endif
196 }
197
198 /*-------------------------------------------------------------------------
199 * isDisconnected - check if tail of arc and head of prev meet
200 *-------------------------------------------------------------------------
201 */
202
203 int
204 Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::isDisconnectedcxx . . $ _SoNurbsArc#isDisconnected(b126dc7c1de90089).( void )
205 {
206 if( pwlArccxx . . $ _SoNurbsArc#pwlArc. == 0 ) return 0;
207 if( prevcxx . . $ _SoNurbsArc#prev.->pwlArccxx . . $ _SoNurbsArc#pwlArc. == 0 ) return 0;
208
209 REALcxx . . $ REAL# *p0 = tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).();
210 REALcxx . . $ REAL# *p1 = prevcxx . . $ _SoNurbsArc#prev.->rheadcxx . . $ _SoNurbsArc#rhead(a3aba87f01dec7c2).();
211
212 if( ((p0[0] - p1[0]) > ZEROcxx . . $ `lib/database/src/so/nodes/nurbs/libnurbs/arc.c++:53:9`!) || ((p1[0] - p0[0]) > ZEROcxx . . $ `lib/database/src/so/nodes/nurbs/libnurbs/arc.c++:53:9`!) ||
213 ((p0[1] - p1[1]) > ZEROcxx . . $ `lib/database/src/so/nodes/nurbs/libnurbs/arc.c++:53:9`!) || ((p1[1] - p0[1]) > ZEROcxx . . $ `lib/database/src/so/nodes/nurbs/libnurbs/arc.c++:53:9`!) ) {
214 #ifndef NDEBUGcxx . . $ `<built-in>:440:9`!
215 dprintf( "x coord = %f %f %f\n", p0[0], p1[0], p0[0] - p1[0] );
216 dprintf( "y coord = %f %f %f\n", p0[1], p1[1], p0[1] - p1[1] );
217 #endif
218 return 1;
219 } else {
220 /* average two points together */
221 p0[0] = p1[0] = (p1[0] + p0[0]) * 0.5;
222 p0[1] = p1[1] = (p1[1] + p0[1]) * 0.5;
223 return 0;
224 }
225 }
226
227 /*-------------------------------------------------------------------------
228 * neq_vert - assert that two 2D vertices are not equal
229 *-------------------------------------------------------------------------
230 */
231
232 inline static int
233 neq_vertcxx . . $ neq_vert(1618fcc08c015880).( REALcxx . . $ REAL# *v1, REALcxx . . $ REAL# *v2 )
234 {
235 return ((v1[0] != v2[0]) || (v1[1] != v2[1] )) ? 1 : 0;
236 }
237
238 /*-------------------------------------------------------------------------
239 * check - verify consistency of a loop, including
240 * 1) if pwl, no two consecutive vertices are identical
241 * 2) the circular link pointers are valid
242 * 3) the geometric info at the head and tail are consistent
243 *-------------------------------------------------------------------------
244 */
245
246 int
247 Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::checkcxx . . $ _SoNurbsArc#check(b126dc7c1de90089).( void )
248 {
249 if( this == 0 ) return 1;
250 Arc_ptrcxx . . $ Arc_ptr# jarc = this;
251 do {
252 assertcxx . . $ `/usr/include/assert.h:50:10`!( jarc->pwlArc || jarc->bezierArc );
253
254 if (jarc->prevcxx . . $ _SoNurbsArc#prev. == 0 || jarc->nextcxx . . $ _SoNurbsArc#next. == 0) {
255 #ifndef NDEBUGcxx . . $ `<built-in>:440:9`!
256 dprintf( "checkjarc:null next/prev pointer\n");
257 jarc->print( );
258 #endif
259 return 0;
260 }
261
262 if (jarc->nextcxx . . $ _SoNurbsArc#next.->prevcxx . . $ _SoNurbsArc#prev. != jarc) {
263 #ifndef NDEBUGcxx . . $ `<built-in>:440:9`!
264 dprintf( "checkjarc: pointer linkage screwed up\n");
265 jarc->print( );
266 #endif
267 return 0;
268 }
269
270 if( jarc->pwlArccxx . . $ _SoNurbsArc#pwlArc. ) {
271 #ifndef NDEBUGcxx . . $ `<built-in>:440:9`!
272 assert( jarc->pwlArc->npts > 1 );
273 assert( jarc->pwlArc->npts < 100000 );
274 /*
275 for( int i=0; i < jarc->pwlArc->npts-1; i++ )
276 assert( neq_vert( jarc->pwlArc->pts[i].param,
277 jarc->pwlArc->pts[i+1].param) );
278 */
279 #endif
280 if( jarc->prevcxx . . $ _SoNurbsArc#prev.->pwlArccxx . . $ _SoNurbsArc#pwlArc. ) {
281 if( jarc->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[1] != jarc->prevcxx . . $ _SoNurbsArc#prev.->rheadcxx . . $ _SoNurbsArc#rhead(a3aba87f01dec7c2).()[1] ) {
282 #ifndef NDEBUGcxx . . $ `<built-in>:440:9`!
283 dprintf( "checkjarc: geometric linkage screwed up 1\n");
284 jarc->prev->show();
285 jarc->show();
286 #endif
287 return 0;
288 }
289 if( jarc->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[0] != jarc->prevcxx . . $ _SoNurbsArc#prev.->rheadcxx . . $ _SoNurbsArc#rhead(a3aba87f01dec7c2).()[0] ) {
290
291 #ifndef NDEBUGcxx . . $ `<built-in>:440:9`!
292 dprintf( "checkjarc: geometric linkage screwed up 2\n");
293 jarc->prev->show();
294 jarc->show();
295 #endif
296 return 0;
297 }
298 }
299 if( jarc->nextcxx . . $ _SoNurbsArc#next.->pwlArccxx . . $ _SoNurbsArc#pwlArc. ) {
300 if( jarc->nextcxx . . $ _SoNurbsArc#next.->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[0] != jarc->rheadcxx . . $ _SoNurbsArc#rhead(a3aba87f01dec7c2).()[0] ) {
301 #ifndef NDEBUGcxx . . $ `<built-in>:440:9`!
302 dprintf( "checkjarc: geometric linkage screwed up 3\n");
303 jarc->show();
304 jarc->next->show();
305 #endif
306 return 0;
307 }
308 if( jarc->nextcxx . . $ _SoNurbsArc#next.->tailcxx . . $ _SoNurbsArc#tail(a3aba87f01dec7c2).()[1] != jarc->rheadcxx . . $ _SoNurbsArc#rhead(a3aba87f01dec7c2).()[1] ) {
309 #ifndef NDEBUGcxx . . $ `<built-in>:440:9`!
310 dprintf( "checkjarc: geometric linkage screwed up 4\n");
311 jarc->show();
312 jarc->next->show();
313 #endif
314 return 0;
315 }
316 }
317 if( jarc->isbeziercxx . . $ _SoNurbsArc#isbezier(da6335ded91d79c2).() ) {
318 assertcxx . . $ `/usr/include/assert.h:50:10`!( jarc->pwlArc->npts == 2 );
319 assertcxx . . $ `/usr/include/assert.h:50:10`!( (jarc->pwlArc->pts[0].param[0] == \
320 jarc->pwlArc->pts[1].param[0]) ||\
321 (jarc->pwlArc->pts[0].param[1] == \
322 jarc->pwlArc->pts[1].param[1]) );
323 }
324 }
325 jarc = jarc->nextcxx . . $ _SoNurbsArc#next.;
326 } while (jarc != this);
327 return 1;
328 }
329
330
331 #define TOLcxx . . $ `lib/database/src/so/nodes/nurbs/libnurbs/arc.c++:331:9`! 0.00001
332
333 inline long tooclosecxx . . $ tooclose(90b9015872b09d90).( REALcxx . . $ REAL# x, REALcxx . . $ REAL# y )
334 {
335 return (abscxx . . $ abs(fbcf3211dfe1bfd1).(x-y) < TOLcxx . . $ `lib/database/src/so/nodes/nurbs/libnurbs/arc.c++:331:9`!) ? 1 : 0;
336 }
337
338
339 /*--------------------------------------------------------------------------
340 * append - append a jordan arc to a circularly linked list
341 *--------------------------------------------------------------------------
342 */
343
344 Arc_ptrcxx . . $ Arc_ptr#
345 Arccxx . . $ `lib/database/src/so/nodes/nurbs/_defines.h:37:9`!::appendcxx . . $ _SoNurbsArc#append(73b8c7fc7e49a461).( Arc_ptrcxx . . $ Arc_ptr# jarc )
346 {
347 if( jarc != 0 ) {
348 nextcxx . . $ _SoNurbsArc#next. = jarc->nextcxx . . $ _SoNurbsArc#next.;
349 prevcxx . . $ _SoNurbsArc#prev. = jarc;
350 nextcxx . . $ _SoNurbsArc#next.->prevcxx . . $ _SoNurbsArc#prev. = prevcxx . . $ _SoNurbsArc#prev.->nextcxx . . $ _SoNurbsArc#next. = this;
351 } else {
352 nextcxx . . $ _SoNurbsArc#next. = prevcxx . . $ _SoNurbsArc#prev. = this;
353 }
354 return this;
355 }
356
357
358 #undef ZEROcxx . . $ `lib/database/src/so/nodes/nurbs/libnurbs/arc.c++:53:9`! /* be nice where Inventor #include's c++ files */