40 #include "glimports.h"
45 #include "bezierarc.h"
48 #include "nurbsconsts.h"
49 #include "subdivider.h"
56 Subdivider::decompose(
Bin& bin, REAL geo_stepsize )
59 for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
60 if( ! jarc->isTessellated() ) {
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 )
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 );
114 Subdivider::monotonize( Arc_ptr jarc,
Bin& bin )
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++ ) {
134 REAL sdiff = vert[1].param[0] - vert[0].param[0];
140 }
else if( sdiff < 0.0 ) {
155 REAL tdiff = vert[1].param[1] - vert[0].param[1];
161 }
else if( tdiff < 0.0 ) {
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;
191 jarc->prev->next = jarc->next;
192 jarc->next->prev = jarc->prev;
194 assert( jarc->prev->check( ) != 0 );
195 assert( jarc->next->check( ) != 0 );
198 bin.remove_this_arc( jarc );
200 jarc->pwlArc->deleteMe( pwlarcpool ); jarc->pwlArc = 0;
201 jarc->deleteMe( arcpool );
210 Subdivider::isMonotone( Arc_ptr jarc )
213 TrimVertex *lastvert = firstvert + (jarc->pwlArc->npts - 1);
215 if( firstvert == lastvert )
return 1;
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;