2
** License Applicability. Except to the extent portions of this file are
3
** made subject to an alternative license as permitted in the SGI Free
4
** Software License B, Version 1.1 (the "License"), the contents of this
5
** file are subject only to the provisions of the License. You may not use
6
** this file except in compliance with the License. You may obtain a copy
7
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10
** http://oss.sgi.com/projects/FreeB
12
** Note that, as provided in the License, the Software is distributed on an
13
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18
** Original Code. The Original Code is: OpenGL Sample Implementation,
19
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21
** Copyright in any portions created by third parties is as indicated
22
** elsewhere herein. All Rights Reserved.
24
** Additional Notice Provisions: The application programming interfaces
25
** established by SGI in conjunction with the Original Code are The
26
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29
** Window System(R) (Version 1.3), released October 19, 1998. This software
30
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31
** published by SGI, but has not been independently verified as being
32
** compliant with the OpenGL(R) version 1.2.1 Specification.
39
* $Header: //depot/main/gfx/lib/glu/libnurbs/internals/mesher.cc#3 $
42
#include "glimports.h"
46
#include "gridvertex.h"
47
#include "gridtrimvertex.h"
55
const float Mesher::ZERO = 0.0;
57
Mesher::Mesher( Backend& b )
59
p( sizeof( GridTrimVertex ), 100, "GridTrimVertexPool" )
63
lastedge = 0; //needed to prevent purify UMR
66
Mesher::~Mesher( void )
68
if( vdata ) delete[] vdata;
72
Mesher::init( unsigned int npts )
75
if( stacksize < npts ) {
77
if( vdata ) delete[] vdata;
78
vdata = new GridTrimVertex_p[stacksize];
83
Mesher::push( GridTrimVertex *gt )
85
assert( itop+1 != stacksize );
97
backend.bgntmesh( "addedge" );
120
Mesher::finishLower( GridTrimVertex *gtlower )
123
nextlower( gtlower=new(p) GridTrimVertex );
130
Mesher::finishUpper( GridTrimVertex *gtupper )
133
nextupper( gtupper=new(p) GridTrimVertex );
142
GridTrimVertex *gtlower, *gtupper;
145
nextupper( gtupper = new(p) GridTrimVertex );
146
nextlower( gtlower = new(p) GridTrimVertex );
152
nextupper( gtupper = new(p) GridTrimVertex );
153
nextlower( gtlower );
155
assert( gtupper->t && gtlower->t );
157
if( gtupper->t->param[0] < gtlower->t->param[0] ) {
160
if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) {
161
finishLower(gtlower);
164
} else if( gtupper->t->param[0] > gtlower->t->param[0] ) {
167
if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
168
finishUpper(gtupper);
172
if( lastedge == 0 ) {
175
if( nextupper(gtupper=new(p) GridTrimVertex) == 0 ) {
176
finishLower(gtlower);
182
if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
183
finishUpper(gtupper);
190
if( gtupper->t->param[0] < gtlower->t->param[0] ) {
193
if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) {
194
finishLower(gtlower);
197
} else if( gtupper->t->param[0] > gtlower->t->param[0] ) {
200
if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
201
finishUpper(gtupper);
205
if( lastedge == 0 ) {
208
if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) {
209
finishLower(gtlower);
215
if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
216
finishUpper(gtupper);
225
Mesher::isCcw( int ilast )
227
REAL area = det3( vdata[ilast]->t, vdata[itop-1]->t, vdata[itop-2]->t );
228
return (area < ZERO) ? 0 : 1;
232
Mesher::isCw( int ilast )
234
REAL area = det3( vdata[ilast]->t, vdata[itop-1]->t, vdata[itop-2]->t );
235
return (area > -ZERO) ? 0 : 1;
239
Mesher::equal( int x, int y )
241
return( last[0] == vdata[x] && last[1] == vdata[y] );
245
Mesher::copy( int x, int y )
247
last[0] = vdata[x]; last[1] = vdata[y];
251
Mesher::move( int x, int y )
257
Mesher::output( int x )
259
backend.tmeshvert( vdata[x] );
262
/*---------------------------------------------------------------------------
263
* addedge - addedge an edge to the triangulation
265
* This code has been re-written to generate large triangle meshes
266
* from a monotone polygon. Although smaller triangle meshes
267
* could be generated faster and with less code, larger meshes
268
* actually give better SYSTEM performance. This is because
269
* vertices are processed in the backend slower than they are
270
* generated by this code and any decrease in the number of vertices
271
* results in a decrease in the time spent in the backend.
272
*---------------------------------------------------------------------------
278
register int ilast = itop;
280
if( lastedge == 0 ) {
281
if( equal( 0, 1 ) ) {
284
for( register int i = 2; i < ilast; i++ ) {
288
copy( ilast, ilast-1 );
289
} else if( equal( ilast-2, ilast-1) ) {
292
for( register int i = ilast-3; i >= 0; i-- ) {
298
closeMesh(); openMesh();
301
for( register int i = 1; i < ilast; i++ ) {
305
copy( ilast, ilast-1 );
311
for( register int i = 2; i < ilast; i++ ) {
315
copy( ilast-1, ilast );
316
} else if( equal( ilast-1, ilast-2) ) {
319
for( register int i = ilast-3; i >= 0; i-- ) {
325
closeMesh(); openMesh();
328
for( register int i = 1; i < ilast; i++ ) {
332
copy( ilast-1, ilast );
336
//for( register long k=0; k<=ilast; k++ ) pop( k );
342
register int ilast = itop;
344
if( lastedge == 0 ) {
345
if( equal( 0, 1 ) ) {
348
for( register int i = 2; i < ilast; i++ ) {
352
copy( ilast, ilast-1 );
353
} else if( equal( ilast-2, ilast-1) ) {
356
for( register int i = ilast-3; i >= 0; i-- ) {
362
closeMesh(); openMesh();
365
for( register int i = 1; i < ilast; i++ ) {
369
copy( ilast, ilast-1 );
372
//for( register long k=0; k<ilast-1; k++ ) pop( k );
377
if( ! isCcw( ilast ) ) return;
380
} while( (itop > 1) && isCcw( ilast ) );
382
if( equal( ilast-1, ilast-2 ) ) {
385
for( register int i=ilast-3; i>=itop-1; i-- ) {
389
copy( ilast, itop-1 );
390
} else if( equal( itop, itop-1 ) ) {
393
for( register int i = itop+1; i < ilast; i++ ) {
397
copy( ilast-1, ilast );
399
closeMesh(); openMesh();
402
for( register int i=ilast-2; i>=itop-1; i-- ) {
406
copy( ilast, itop-1 );
408
//for( register int k=itop; k<ilast; k++ ) pop( k );
416
register int ilast = itop;
418
if( lastedge == 1 ) {
422
for( register int i = 2; i < ilast; i++ ) {
426
copy( ilast-1, ilast );
427
} else if( equal( ilast-1, ilast-2) ) {
430
for( register int i = ilast-3; i >= 0; i-- ) {
436
closeMesh(); openMesh();
439
for( register int i = 1; i < ilast; i++ ) {
443
copy( ilast-1, ilast );
447
//for( register long k=0; k<ilast-1; k++ ) pop( k );
452
if( ! isCw( ilast ) ) return;
455
} while( (itop > 1) && isCw( ilast ) );
457
if( equal( ilast-2, ilast-1) ) {
460
for( register int i=ilast-3; i>=itop-1; i--) {
464
copy( itop-1, ilast );
465
} else if( equal( itop-1, itop) ) {
468
for( register int i=itop+1; i<ilast; i++ ) {
472
copy( ilast, ilast-1 );
474
closeMesh(); openMesh();
477
for( register int i=ilast-2; i>=itop-1; i-- ) {
481
copy( itop-1, ilast );
483
//for( register int k=itop; k<ilast; k++ ) pop( k );