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$ $Revision: 1.1 $
39 * $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/internals/quilt.cc,v 1.1 2004/02/02 16:39:12 navaraf Exp $
42 #include "glimports.h"
49 #include "knotvector.h"
50 #include "patchlist.h"
51 #include "math.h" //fglu_abs()
52 #include "simplemath.h" //min()
54 /* local preprocessor definitions */
55 #define DEF_PATCH_STEPSIZE .4
56 #define fsizeof(x) (sizeof(x)/sizeof(REAL))
59 Quilt::Quilt( Mapdesc
*_mapdesc
)
65 Quilt::deleteMe( Pool
& p
)
67 for( Quiltspec
*q
=qspec
; q
!= eqspec
; q
++ ) {
69 if( q
->breakpoints
) delete[] q
->breakpoints
; q
->breakpoints
= 0;
72 delete[] q
->breakpoints
;
78 if( cpts
) delete[] cpts
;
80 PooledObj::deleteMe( p
);
87 int nc
= mapdesc
->getNcoords();
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
] );
103 /*--------------------------------------------------------------------------
104 * Quilt::select - find which map in each quilt contains the points
105 * pta and ptb with pta[i] < ptb[i]
106 *--------------------------------------------------------------------------
110 Quilt::select( REAL
*pta
, REAL
*ptb
)
112 int dim
= eqspec
- qspec
;
114 for( i
=0; i
<dim
; i
++) {
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] ) )
125 Quilt::download( Backend
&backend
)
127 if( getDimension() == 2 ) {
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
,
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] );
144 ps
+= qspec
[0].offset
;
145 ps
+= qspec
[0].index
* qspec
[0].order
* qspec
[0].stride
;
146 backend
.curvpts( mapdesc
->getType(), ps
,
149 qspec
[0].breakpoints
[qspec
[0].index
],
150 qspec
[0].breakpoints
[qspec
[0].index
+1] );
154 /*--------------------------------------------------------------------------
155 * Quilt::downloadAll - download each map that contains the current patch
156 *--------------------------------------------------------------------------
160 Quilt::downloadAll( REAL
*pta
, REAL
*ptb
, Backend
&backend
)
162 for( Quilt
*m
= this; m
; m
=m
->next
) {
163 m
->select( pta
, ptb
);
164 m
->download( backend
);
168 /*--------------------------------------------------------------------------
169 * Quilt::isCulled - determine if an entire quilt is trivially rejected.
170 *--------------------------------------------------------------------------
174 Quilt::isCulled( void )
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
);
184 /*---------------------------------------------------------------------------
185 * Quilt::getRange - retrieve the valid paramater range of a set of quilts
186 *---------------------------------------------------------------------------
189 Quilt::getRange( REAL
*from
, REAL
*to
, Flist
& slist
, Flist
&tlist
)
191 getRange( from
, to
, 0, slist
);
192 getRange( from
, to
, 1, tlist
);
195 /*---------------------------------------------------------------------------
196 * Quilt::getRange - retrieve the valid paramater range of a set of quilts
197 *---------------------------------------------------------------------------
200 Quilt::getRange( REAL
*from
, REAL
*to
, int i
, Flist
&list
)
203 from
[i
] = maps
->qspec
[i
].breakpoints
[0];
204 to
[i
] = maps
->qspec
[i
].breakpoints
[maps
->qspec
[i
].width
];
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;
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
] );
223 list
.taper( from
[i
], to
[i
] );
227 Quilt::getRange( REAL
*from
, REAL
*to
, Flist
& slist
)
229 getRange( from
, to
, 0, slist
);
233 Quilt::findRates( Flist
& slist
, Flist
& tlist
, REAL rate
[2] )
235 findSampleRates( slist
, tlist
);
236 rate
[0] = qspec
[0].step_size
;
237 rate
[1] = qspec
[1].step_size
;
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
;
249 Quilt::findSampleRates( Flist
& slist
, Flist
& tlist
)
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]);
256 for( int i
= slist
.start
; i
< slist
.end
-1; i
++ ) {
257 for( int j
= tlist
.start
; j
< tlist
.end
-1; j
++ ) {
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();
268 float edge_len_s
= min(glu_abs(ptb
[0]-pta
[0]),1.0);
269 float edge_len_t
= min(glu_abs(ptb
[1]-pta
[1]),1.0);
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
;