| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
* quilt.c++ - $Revision: 1.1.1.1 $ |
| 39 |
* Derrick Burns - 1991 |
| 40 |
*/ |
| 41 |
|
| 42 |
#include "glimports.h" |
| 43 |
#include "mystdio.h" |
| 44 |
#include "myassert.h" |
| 45 |
#include "quilt.h" |
| 46 |
#include "backend.h" |
| 47 |
#include "mapdesc.h" |
| 48 |
#include "flist.h" |
| 49 |
#include "knotvector.h" |
| 50 |
#include "patchlist.h" |
| 51 |
#include <cmath> //fabs() |
| 52 |
#include "simplemath.h" //min() |
| 53 |
|
| 54 |
/* local preprocessor definitions */ |
| 55 |
#define DEF_PATCH_STEPSIZE .2 |
| 56 |
#define fsizeof(x) (sizeof(x)/sizeof(REAL)) |
| 57 |
|
| 58 |
|
| 59 |
Quilt::Quilt( Mapdesc *_mapdesc ) |
| 60 |
{ |
| 61 |
mapdesc = _mapdesc; |
| 62 |
} |
| 63 |
|
| 64 |
void |
| 65 |
Quilt::deleteMe( Pool& p ) |
| 66 |
{ |
| 67 |
for( Quiltspec *q=qspec; q != eqspec; q++ ) { |
| 68 |
#if 1 |
| 69 |
if( q->breakpoints) delete[] q->breakpoints; q->breakpoints = 0; |
| 70 |
#else |
| 71 |
if( q->breakpoints) { |
| 72 |
delete[] q->breakpoints; |
| 73 |
q->breakpoints = 0; |
| 74 |
printf("in here\n"); |
| 75 |
} |
| 76 |
#endif |
| 77 |
} |
| 78 |
if( cpts ) delete[] cpts; |
| 79 |
cpts = 0; |
| 80 |
PooledObj::deleteMe( p ); |
| 81 |
} |
| 82 |
|
| 83 |
void |
| 84 |
Quilt::show( void ) |
| 85 |
{ |
| 86 |
#ifndef NDEBUG |
| 87 |
int nc = mapdesc->getNcoords(); |
| 88 |
REAL *ps = cpts; |
| 89 |
ps += qspec[0].offset; |
| 90 |
ps += qspec[1].offset; |
| 91 |
for( int i=0; i!= qspec[0].order * qspec[0].width; i++ ) { |
| 92 |
for( int j = 0; j!= qspec[1].order * qspec[1].width; j++ ) { |
| 93 |
for( int k=0; k < nc; k++ ) |
| 94 |
dprintf( "%g ", ps[i*qspec[0].stride + j*qspec[1].stride + k] ); |
| 95 |
dprintf( "\n" ); |
| 96 |
} |
| 97 |
dprintf( "\n" ); |
| 98 |
} |
| 99 |
dprintf( "\n" ); |
| 100 |
#endif |
| 101 |
} |
| 102 |
|
| 103 |
/*-------------------------------------------------------------------------- |
| 104 |
* Quilt::select - find which map in each quilt contains the points |
| 105 |
* pta and ptb with pta[i] < ptb[i] |
| 106 |
*-------------------------------------------------------------------------- |
| 107 |
*/ |
| 108 |
|
| 109 |
void |
| 110 |
Quilt::select( REAL *pta, REAL *ptb ) |
| 111 |
{ |
| 112 |
int dim = eqspec - qspec; |
| 113 |
for( int i=0; i<dim; i++) { |
| 114 |
int j; |
| 115 |
for( j=qspec[i].width-1; j>=0; j-- ) |
| 116 |
if( (qspec[i].breakpoints[j] <= pta[i] ) && |
| 117 |
(ptb[i] <= qspec[i].breakpoints[j+1] ) ) |
| 118 |
break; |
| 119 |
assert( j != -1 ); |
| 120 |
qspec[i].index = j; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
void |
| 125 |
Quilt::download( Backend &backend ) |
| 126 |
{ |
| 127 |
if( getDimension() == 2 ) { |
| 128 |
REAL *ps = cpts; |
| 129 |
ps += qspec[0].offset; |
| 130 |
ps += qspec[1].offset; |
| 131 |
ps += qspec[0].index * qspec[0].order * qspec[0].stride; |
| 132 |
ps += qspec[1].index * qspec[1].order * qspec[1].stride; |
| 133 |
backend.surfpts( mapdesc->getType(), ps, |
| 134 |
qspec[0].stride, |
| 135 |
qspec[1].stride, |
| 136 |
qspec[0].order, |
| 137 |
qspec[1].order, |
| 138 |
qspec[0].breakpoints[qspec[0].index], |
| 139 |
qspec[0].breakpoints[qspec[0].index+1], |
| 140 |
qspec[1].breakpoints[qspec[1].index], |
| 141 |
qspec[1].breakpoints[qspec[1].index+1] ); |
| 142 |
} else { |
| 143 |
REAL *ps = cpts; |
| 144 |
ps += qspec[0].offset; |
| 145 |
ps += qspec[0].index * qspec[0].order * qspec[0].stride; |
| 146 |
backend.curvpts( mapdesc->getType(), ps, |
| 147 |
qspec[0].stride, |
| 148 |
qspec[0].order, |
| 149 |
qspec[0].breakpoints[qspec[0].index], |
| 150 |
qspec[0].breakpoints[qspec[0].index+1] ); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
/*-------------------------------------------------------------------------- |
| 155 |
* Quilt::downloadAll - download each map that contains the current patch |
| 156 |
*-------------------------------------------------------------------------- |
| 157 |
*/ |
| 158 |
|
| 159 |
void |
| 160 |
Quilt::downloadAll( REAL *pta, REAL *ptb, Backend &backend ) |
| 161 |
{ |
| 162 |
for( Quilt *m = this; m; m=m->next ) { |
| 163 |
m->select( pta, ptb ); |
| 164 |
m->download( backend ); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
/*-------------------------------------------------------------------------- |
| 169 |
* Quilt::isCulled - determine if an entire quilt is trivially rejected. |
| 170 |
*-------------------------------------------------------------------------- |
| 171 |
*/ |
| 172 |
|
| 173 |
int |
| 174 |
Quilt::isCulled( void ) |
| 175 |
{ |
| 176 |
if( mapdesc->isCulling() ) |
| 177 |
return mapdesc->xformAndCullCheck( cpts + qspec[0].offset + qspec[1].offset, |
| 178 |
qspec[0].order * qspec[0].width, qspec[0].stride, |
| 179 |
qspec[1].order * qspec[1].width, qspec[1].stride ); |
| 180 |
else |
| 181 |
return CULL_ACCEPT; |
| 182 |
} |
| 183 |
|
| 184 |
/*--------------------------------------------------------------------------- |
| 185 |
* Quilt::getRange - retrieve the valid paramater range of a set of quilts |
| 186 |
*--------------------------------------------------------------------------- |
| 187 |
*/ |
| 188 |
void |
| 189 |
Quilt::getRange( REAL *from, REAL *to, Flist& slist, Flist &tlist ) |
| 190 |
{ |
| 191 |
getRange( from, to, 0, slist ); |
| 192 |
getRange( from, to, 1, tlist ); |
| 193 |
} |
| 194 |
|
| 195 |
/*--------------------------------------------------------------------------- |
| 196 |
* Quilt::getRange - retrieve the valid paramater range of a set of quilts |
| 197 |
*--------------------------------------------------------------------------- |
| 198 |
*/ |
| 199 |
void |
| 200 |
Quilt::getRange( REAL *from, REAL *to, int i, Flist &list ) |
| 201 |
{ |
| 202 |
Quilt *maps = this; |
| 203 |
from[i] = maps->qspec[i].breakpoints[0]; |
| 204 |
to[i] = maps->qspec[i].breakpoints[maps->qspec[i].width]; |
| 205 |
int maxpts = 0; |
| 206 |
Quilt_ptr m; |
| 207 |
for( m=maps; m; m=m->next ) { |
| 208 |
if( m->qspec[i].breakpoints[0] > from[i] ) |
| 209 |
from[i] = m->qspec[i].breakpoints[0]; |
| 210 |
if( m->qspec[i].breakpoints[m->qspec[i].width] < to[i] ) |
| 211 |
to[i] = m->qspec[i].breakpoints[m->qspec[i].width]; |
| 212 |
maxpts += m->qspec[i].width + 1; |
| 213 |
} |
| 214 |
|
| 215 |
list.grow( maxpts ); |
| 216 |
|
| 217 |
for( m=maps; m; m=m->next ) |
| 218 |
for( int j=0; j<=m->qspec[i].width; j++ ) { |
| 219 |
list.add( m->qspec[i].breakpoints[j] ); |
| 220 |
} |
| 221 |
|
| 222 |
list.filter( ); |
| 223 |
list.taper( from[i], to[i] ); |
| 224 |
} |
| 225 |
|
| 226 |
void |
| 227 |
Quilt::getRange( REAL *from, REAL *to, Flist& slist ) |
| 228 |
{ |
| 229 |
getRange( from, to, 0, slist ); |
| 230 |
} |
| 231 |
|
| 232 |
void |
| 233 |
Quilt::findRates( Flist& slist, Flist& tlist, REAL rate[2] ) |
| 234 |
{ |
| 235 |
findSampleRates( slist, tlist ); |
| 236 |
rate[0] = qspec[0].step_size; |
| 237 |
rate[1] = qspec[1].step_size; |
| 238 |
|
| 239 |
for( Quilt *q = next; q; q = q->next ) { |
| 240 |
q->findSampleRates( slist, tlist ); |
| 241 |
if( q->qspec[0].step_size < rate[0] ) |
| 242 |
rate[0] = q->qspec[0].step_size; |
| 243 |
if( q->qspec[1].step_size < rate[1] ) |
| 244 |
rate[1] = q->qspec[1].step_size; |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
void |
| 249 |
Quilt::findSampleRates( Flist& slist, Flist& tlist ) |
| 250 |
{ |
| 251 |
qspec[0].step_size = DEF_PATCH_STEPSIZE * |
| 252 |
(qspec[0].breakpoints[qspec[0].width] - qspec[0].breakpoints[0]); |
| 253 |
qspec[1].step_size = DEF_PATCH_STEPSIZE * |
| 254 |
(qspec[1].breakpoints[qspec[1].width] - qspec[1].breakpoints[0]); |
| 255 |
|
| 256 |
for( int i = slist.start; i < slist.end-1; i++ ) { |
| 257 |
for( int j = tlist.start; j < tlist.end-1; j++ ) { |
| 258 |
|
| 259 |
REAL pta[2], ptb[2]; |
| 260 |
pta[0] = slist.pts[i]; |
| 261 |
ptb[0] = slist.pts[i+1]; |
| 262 |
pta[1] = tlist.pts[j]; |
| 263 |
ptb[1] = tlist.pts[j+1]; |
| 264 |
Patchlist patchlist( this, pta, ptb ); |
| 265 |
patchlist.getstepsize(); |
| 266 |
|
| 267 |
{ |
| 268 |
float edge_len_s = min(float(fabs(ptb[0]-pta[0])),1.f); |
| 269 |
float edge_len_t = min(float(fabs(ptb[1]-pta[1])),1.f); |
| 270 |
|
| 271 |
if( patchlist.getStepsize(0)/edge_len_s < qspec[0].step_size ) |
| 272 |
qspec[0].step_size = patchlist.getStepsize(0)/edge_len_s; |
| 273 |
if( patchlist.getStepsize(1)/edge_len_t < qspec[1].step_size ) |
| 274 |
qspec[1].step_size = patchlist.getStepsize(1)/edge_len_t; |
| 275 |
} |
| 276 |
} |
| 277 |
} |
| 278 |
} |