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.
38 * $Date: 2001/03/17 00:25:41 $ $Revision: 1.1 $
39 * $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/glu/sgi/libnurbs/internals/monotonizer.cc,v 1.1 2001/03/17 00:25:41 brianp Exp $
42 #include "glimports.h"
47 #include "bezierarc.h"
50 #include "nurbsconsts.h"
51 #include "subdivider.h"
53 /*-----------------------------------------------------------------------------
54 * Subdivider::decompose - break all curves into monotone arcs
55 *-----------------------------------------------------------------------------
58 Subdivider::decompose( Bin
& bin
, REAL geo_stepsize
)
61 for( jarc
=bin
.firstarc(); jarc
; jarc
=bin
.nextarc() ) {
62 if( ! jarc
->isTessellated() ) {
63 /* points have not been transformed, therefore they may be either
64 homogeneous or inhomogeneous */
65 tessellate( jarc
, geo_stepsize
);
66 if( jarc
->isDisconnected() || jarc
->next
->isDisconnected() )
71 for( jarc
=bin
.firstarc(); jarc
; jarc
=bin
.nextarc() ) {
72 monotonize( jarc
, bin
);
76 for( jarc
=bin
.firstarc(); jarc
; jarc
=bin
.nextarc() ) {
77 assert( isMonotone( jarc
) != 0 );
85 Subdivider::tessellate( Arc_ptr jarc
, REAL geo_stepsize
)
87 BezierArc
*b
= jarc
->bezierArc
;
88 Mapdesc
*mapdesc
= b
->mapdesc
;
90 if( mapdesc
->isRational() ) {
91 REAL max
= mapdesc
->calcVelocityRational( b
->cpts
, b
->stride
, b
->order
);
92 REAL arc_stepsize
= (max
> 1.0) ? (1.0/max
) : 1.0;
93 if( jarc
->bezierArc
->order
!= 2 )
94 arctessellator
.tessellateNonlinear( jarc
, geo_stepsize
, arc_stepsize
, 1 );
96 arctessellator
.tessellateLinear( jarc
, geo_stepsize
, arc_stepsize
, 1 );
99 REAL max
= mapdesc
->calcVelocityNonrational( b
->cpts
, b
->stride
, b
->order
);
100 REAL arc_stepsize
= (max
> 1.0) ? (1.0/max
) : 1.0;
101 if( jarc
->bezierArc
->order
!= 2 )
102 arctessellator
.tessellateNonlinear( jarc
, geo_stepsize
, arc_stepsize
, 0 );
104 arctessellator
.tessellateLinear( jarc
, geo_stepsize
, arc_stepsize
, 0 );
109 /*-------------------------------------------------------------------------
110 * Subdivider::monotonize - break up a jordan arc into s,t-monotone
111 * components. This code will remove degenerate segments, including
112 * arcs of only a single point.
113 *-------------------------------------------------------------------------
116 Subdivider::monotonize( Arc_ptr jarc
, Bin
& bin
)
118 TrimVertex
*firstvert
= jarc
->pwlArc
->pts
;
119 TrimVertex
*lastvert
= firstvert
+ (jarc
->pwlArc
->npts
- 1);
120 long uid
= jarc
->nuid
;
121 arc_side side
= jarc
->getside();
130 for( vert
= firstvert
; vert
!= lastvert
; vert
++ ) {
135 /* check change relative to s axis, clear degenerate bit if needed */
136 REAL sdiff
= vert
[1].param
[0] - vert
[0].param
[0];
142 } else if( sdiff
< 0.0 ) {
156 /* check change relative to t axis, clear degenerate bit if needed */
157 REAL tdiff
= vert
[1].param
[1] - vert
[0].param
[1];
163 } else if( tdiff
< 0.0 ) {
179 /* make last segment into separate pwl curve */
180 jarc
->pwlArc
->npts
= vert
- firstvert
+ 1;
181 jarc
= (new(arcpool
) Arc( side
, uid
))->append( jarc
);
182 jarc
->pwlArc
= new(pwlarcpool
) PwlArc();
185 firstvert
= jarc
->pwlArc
->pts
= vert
;
186 degenerate
= nudegenerate
;
189 jarc
->pwlArc
->npts
= vert
- firstvert
+ 1;
192 /* remove jarc from circularly linked list */
193 jarc
->prev
->next
= jarc
->next
;
194 jarc
->next
->prev
= jarc
->prev
;
196 assert( jarc
->prev
->check( ) != 0 );
197 assert( jarc
->next
->check( ) != 0 );
199 /* remove jarc from bin */
200 bin
.remove_this_arc( jarc
);
202 jarc
->pwlArc
->deleteMe( pwlarcpool
); jarc
->pwlArc
= 0;
203 jarc
->deleteMe( arcpool
);
207 /*-------------------------------------------------------------------------
208 * Subdivider::isMonotone - return true if arc is monotone AND non-degenerate
209 *-------------------------------------------------------------------------
212 Subdivider::isMonotone( Arc_ptr jarc
)
214 TrimVertex
*firstvert
= jarc
->pwlArc
->pts
;
215 TrimVertex
*lastvert
= firstvert
+ (jarc
->pwlArc
->npts
- 1);
217 if( firstvert
== lastvert
) return 1;
219 TrimVertex
*vert
= firstvert
;
223 REAL diff
= vert
[1].param
[0] - vert
[0].param
[0];
226 else if( diff
< 0.0 )
231 diff
= vert
[1].param
[1] - vert
[0].param
[1];
234 else if( diff
< 0.0 )
239 if( (sdir
== same
) && (tdir
== same
) ) return 0;
241 for( ++vert
; vert
!= lastvert
; vert
++ ) {
242 diff
= vert
[1].param
[0] - vert
[0].param
[0];
244 if( sdir
!= same
) return 0;
245 } else if( diff
< 0.0 ) {
246 if( sdir
!= down
) return 0;
248 if( sdir
!= up
) return 0;
251 diff
= vert
[1].param
[1] - vert
[0].param
[1];
253 if( tdir
!= same
) return 0;
254 } else if( diff
< 0.0 ) {
255 if( tdir
!= down
) return 0;
257 if( tdir
!= up
) return 0;