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.
40 #include "glimports.h"
45 #include "bezierarc.h"
48 #include "nurbsconsts.h"
49 #include "subdivider.h"
51 /*-----------------------------------------------------------------------------
52 * Subdivider::decompose - break all curves into monotone arcs
53 *-----------------------------------------------------------------------------
56 Subdivider::decompose( Bin& bin, REAL geo_stepsize )
59 for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
60 if( ! jarc->isTessellated() ) {
61 /* points have not been transformed, therefore they may be either
62 homogeneous or inhomogeneous */
63 tessellate( jarc, geo_stepsize );
64 if( jarc->isDisconnected() || jarc->next->isDisconnected() )
69 for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
70 monotonize( jarc, bin );
74 for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
75 assert( isMonotone( jarc ) != 0 );
83 Subdivider::tessellate( Arc_ptr jarc, REAL geo_stepsize )
85 BezierArc *b = jarc->bezierArc;
86 Mapdesc *mapdesc = b->mapdesc;
88 if( mapdesc->isRational() ) {
89 REAL max = mapdesc->calcVelocityRational( b->cpts, b->stride, b->order );
90 REAL arc_stepsize = (max > 1.0) ? (1.0/max) : 1.0;
91 if( jarc->bezierArc->order != 2 )
92 arctessellator.tessellateNonlinear( jarc, geo_stepsize, arc_stepsize, 1 );
94 arctessellator.tessellateLinear( jarc, geo_stepsize, arc_stepsize, 1 );
97 REAL max = mapdesc->calcVelocityNonrational( b->cpts, b->stride, b->order );
98 REAL arc_stepsize = (max > 1.0) ? (1.0/max) : 1.0;
99 if( jarc->bezierArc->order != 2 )
100 arctessellator.tessellateNonlinear( jarc, geo_stepsize, arc_stepsize, 0 );
102 arctessellator.tessellateLinear( jarc, geo_stepsize, arc_stepsize, 0 );
107 /*-------------------------------------------------------------------------
108 * Subdivider::monotonize - break up a jordan arc into s,t-monotone
109 * components. This code will remove degenerate segments, including
110 * arcs of only a single point.
111 *-------------------------------------------------------------------------
114 Subdivider::monotonize( Arc_ptr jarc, Bin& bin )
116 TrimVertex *firstvert = jarc->pwlArc->pts;
117 TrimVertex *lastvert = firstvert + (jarc->pwlArc->npts - 1);
118 long uid = jarc->nuid;
119 arc_side side = jarc->getside();
128 for( vert = firstvert; vert != lastvert; vert++ ) {
133 /* check change relative to s axis, clear degenerate bit if needed */
134 REAL sdiff = vert[1].param[0] - vert[0].param[0];
140 } else if( sdiff < 0.0 ) {
154 /* check change relative to t axis, clear degenerate bit if needed */
155 REAL tdiff = vert[1].param[1] - vert[0].param[1];
161 } else if( tdiff < 0.0 ) {
177 /* make last segment into separate pwl curve */
178 jarc->pwlArc->npts = vert - firstvert + 1;
179 jarc = (new(arcpool) Arc( side, uid ))->append( jarc );
180 jarc->pwlArc = new(pwlarcpool) PwlArc();
183 firstvert = jarc->pwlArc->pts = vert;
184 degenerate = nudegenerate;
187 jarc->pwlArc->npts = vert - firstvert + 1;
190 /* remove jarc from circularly linked list */
191 jarc->prev->next = jarc->next;
192 jarc->next->prev = jarc->prev;
194 assert( jarc->prev->check( ) != 0 );
195 assert( jarc->next->check( ) != 0 );
197 /* remove jarc from bin */
198 bin.remove_this_arc( jarc );
200 jarc->pwlArc->deleteMe( pwlarcpool ); jarc->pwlArc = 0;
201 jarc->deleteMe( arcpool );
205 /*-------------------------------------------------------------------------
206 * Subdivider::isMonotone - return true if arc is monotone AND non-degenerate
207 *-------------------------------------------------------------------------
210 Subdivider::isMonotone( Arc_ptr jarc )
212 TrimVertex *firstvert = jarc->pwlArc->pts;
213 TrimVertex *lastvert = firstvert + (jarc->pwlArc->npts - 1);
215 if( firstvert == lastvert ) return 1;
217 TrimVertex *vert = firstvert;
221 REAL diff = vert[1].param[0] - vert[0].param[0];
224 else if( diff < 0.0 )
229 diff = vert[1].param[1] - vert[0].param[1];
232 else if( diff < 0.0 )
237 if( (sdir == same) && (tdir == same) ) return 0;
239 for( ++vert ; vert != lastvert; vert++ ) {
240 diff = vert[1].param[0] - vert[0].param[0];
242 if( sdir != same ) return 0;
243 } else if( diff < 0.0 ) {
244 if( sdir != down ) return 0;
246 if( sdir != up ) return 0;
249 diff = vert[1].param[1] - vert[0].param[1];
251 if( tdir != same ) return 0;
252 } else if( diff < 0.0 ) {
253 if( tdir != down ) return 0;
255 if( tdir != up ) return 0;