40 #include "glimports.h"
47 #include "knotvector.h"
48 #include "patchlist.h"
50 #include "simplemath.h"
53 #define DEF_PATCH_STEPSIZE .4
54 #define fsizeof(x) (sizeof(x)/sizeof(REAL))
57 Quilt::Quilt(
Mapdesc *_mapdesc )
63 Quilt::deleteMe(
Pool& p )
65 for(
Quiltspec *q=qspec; q != eqspec; q++ ) {
67 if( q->breakpoints)
delete[] q->breakpoints; q->breakpoints = 0;
70 delete[] q->breakpoints;
76 if( cpts )
delete[] cpts;
78 PooledObj::deleteMe( p );
85 int nc = mapdesc->getNcoords();
87 ps += qspec[0].offset;
88 ps += qspec[1].offset;
89 for(
int i=0; i!= qspec[0].order * qspec[0].width; i++ ) {
90 for(
int j = 0; j!= qspec[1].order * qspec[1].width; j++ ) {
91 for(
int k=0; k < nc; k++ )
92 _glu_dprintf(
"%g ", ps[i*qspec[0].stride + j*qspec[1].stride + k] );
108 Quilt::select( REAL *pta, REAL *ptb )
110 int dim = eqspec - qspec;
112 for( i=0; i<dim; i++) {
113 for( j=qspec[i].width-1; j>=0; j-- )
114 if( (qspec[i].breakpoints[j] <= pta[i] ) &&
115 (ptb[i] <= qspec[i].breakpoints[j+1] ) )
123 Quilt::download(
Backend &backend )
125 if( getDimension() == 2 ) {
127 ps += qspec[0].offset;
128 ps += qspec[1].offset;
129 ps += qspec[0].index * qspec[0].order * qspec[0].stride;
130 ps += qspec[1].index * qspec[1].order * qspec[1].stride;
131 backend.surfpts( mapdesc->getType(), ps,
136 qspec[0].breakpoints[qspec[0].index],
137 qspec[0].breakpoints[qspec[0].index+1],
138 qspec[1].breakpoints[qspec[1].index],
139 qspec[1].breakpoints[qspec[1].index+1] );
142 ps += qspec[0].offset;
143 ps += qspec[0].index * qspec[0].order * qspec[0].stride;
144 backend.curvpts( mapdesc->getType(), ps,
147 qspec[0].breakpoints[qspec[0].index],
148 qspec[0].breakpoints[qspec[0].index+1] );
158 Quilt::downloadAll( REAL *pta, REAL *ptb,
Backend &backend )
160 for(
Quilt *m =
this; m; m=m->next ) {
161 m->select( pta, ptb );
162 m->download( backend );
172 Quilt::isCulled(
void )
174 if( mapdesc->isCulling() )
175 return mapdesc->xformAndCullCheck( cpts + qspec[0].offset + qspec[1].offset,
176 qspec[0].order * qspec[0].width, qspec[0].stride,
177 qspec[1].order * qspec[1].width, qspec[1].stride );
187 Quilt::getRange( REAL *from, REAL *to,
Flist& slist,
Flist &tlist )
189 getRange( from, to, 0, slist );
190 getRange( from, to, 1, tlist );
198 Quilt::getRange( REAL *from, REAL *to,
int i,
Flist &list )
201 from[i] = maps->qspec[i].breakpoints[0];
202 to[i] = maps->qspec[i].breakpoints[maps->qspec[i].width];
205 for( m=maps; m; m=m->next ) {
206 if( m->qspec[i].breakpoints[0] > from[i] )
207 from[i] = m->qspec[i].breakpoints[0];
208 if( m->qspec[i].breakpoints[m->qspec[i].width] < to[i] )
209 to[i] = m->qspec[i].breakpoints[m->qspec[i].width];
210 maxpts += m->qspec[i].width + 1;
215 for( m=maps; m; m=m->next )
216 for(
int j=0; j<=m->qspec[i].width; j++ ) {
217 list.add( m->qspec[i].breakpoints[j] );
221 list.taper( from[i], to[i] );
225 Quilt::getRange( REAL *from, REAL *to,
Flist& slist )
227 getRange( from, to, 0, slist );
231 Quilt::findRates(
Flist& slist,
Flist& tlist, REAL rate[2] )
233 findSampleRates( slist, tlist );
234 rate[0] = qspec[0].step_size;
235 rate[1] = qspec[1].step_size;
237 for(
Quilt *q = next; q; q = q->next ) {
238 q->findSampleRates( slist, tlist );
239 if( q->qspec[0].step_size < rate[0] )
240 rate[0] = q->qspec[0].step_size;
241 if( q->qspec[1].step_size < rate[1] )
242 rate[1] = q->qspec[1].step_size;
247 Quilt::findSampleRates(
Flist& slist,
Flist& tlist )
249 qspec[0].step_size = DEF_PATCH_STEPSIZE *
250 (qspec[0].breakpoints[qspec[0].width] - qspec[0].breakpoints[0]);
251 qspec[1].step_size = DEF_PATCH_STEPSIZE *
252 (qspec[1].breakpoints[qspec[1].width] - qspec[1].breakpoints[0]);
254 for(
int i = slist.start; i < slist.end-1; i++ ) {
255 for(
int j = tlist.start; j < tlist.end-1; j++ ) {
258 pta[0] = slist.pts[i];
259 ptb[0] = slist.pts[i+1];
260 pta[1] = tlist.pts[j];
261 ptb[1] = tlist.pts[j+1];
263 patchlist.getstepsize();
266 float edge_len_s = min(glu_abs(ptb[0]-pta[0]),1.0);
267 float edge_len_t = min(glu_abs(ptb[1]-pta[1]),1.0);
269 if( patchlist.getStepsize(0)/edge_len_s < qspec[0].step_size )
270 qspec[0].step_size = patchlist.getStepsize(0)/edge_len_s;
271 if( patchlist.getStepsize(1)/edge_len_t < qspec[1].step_size )
272 qspec[1].step_size = patchlist.getStepsize(1)/edge_len_t;