Imported Upstream version 9.0.0
[platform/upstream/libGLU.git] / src / libnurbs / internals / mapdesc.h
1 /*
2  * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3  * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice including the dates of first publication and
13  * either this permission notice or a reference to
14  * http://oss.sgi.com/projects/FreeB/
15  * shall be included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *
25  * Except as contained in this notice, the name of Silicon Graphics, Inc.
26  * shall not be used in advertising or otherwise to promote the sale, use or
27  * other dealings in this Software without prior written authorization from
28  * Silicon Graphics, Inc.
29  */
30
31 /*
32  * mapdesc.h
33  *
34  */
35
36 #ifndef __glumapdesc_h_
37 #define __glumapdesc_h_
38
39 #include "mystdio.h"
40 #include "types.h"
41 #include "defines.h"
42 #include "bufpool.h"
43 #include "nurbsconsts.h"
44
45 typedef REAL Maxmatrix[MAXCOORDS][MAXCOORDS];
46
47 class Backend;
48
49 class Mapdesc : public PooledObj {
50     friend class Maplist;
51                         
52 public:
53                         Mapdesc( long, int, int, Backend & );
54     int                 isProperty( long );
55     REAL                getProperty( long );
56     void                setProperty( long, REAL );
57     int                 isConstantSampling( void );
58     int                 isDomainSampling( void );
59     int                 isRangeSampling( void );
60     int                 isSampling( void );
61     int                 isParametricDistanceSampling( void );
62     int                 isObjectSpaceParaSampling( void );
63     int                 isObjectSpacePathSampling( void );
64     int                 isSurfaceAreaSampling( void );
65     int                 isPathLengthSampling( void );
66     int                 isCulling( void );
67     int                 isBboxSubdividing( void );
68     long                getType( void );
69
70     /* curve routines */
71     void                subdivide( REAL *, REAL *, REAL, int, int );
72     int                 cullCheck( REAL *, int, int );
73     void                xformBounding( REAL *, int, int, REAL *, int );
74     void                xformCulling( REAL *, int, int, REAL *, int );
75     void                xformSampling( REAL *, int, int, REAL *, int );
76     void                xformMat( Maxmatrix, REAL *, int, int, REAL *, int );
77     REAL                calcPartialVelocity ( REAL *, int, int, int, REAL );
78     int                 project( REAL *, int, REAL *, int, int );
79     REAL                calcVelocityRational( REAL *, int, int );
80     REAL                calcVelocityNonrational( REAL *, int, int );
81
82     /* surface routines */
83     void                subdivide( REAL *, REAL *, REAL, int, int, int, int );
84     int                 cullCheck( REAL *, int, int, int, int );
85     void                xformBounding( REAL *, int, int, int, int, REAL *, int, int );
86     void                xformCulling( REAL *, int, int, int, int, REAL *, int, int );
87     void                xformSampling( REAL *, int, int, int, int, REAL *, int, int );
88     void                xformMat( Maxmatrix, REAL *, int, int, int, int, REAL *, int, int );
89     REAL                calcPartialVelocity ( REAL *, REAL *, int, int, int, int, int, int, REAL, REAL, int );
90     int                 project( REAL *, int, int, REAL *, int, int, int, int);
91     void                surfbbox( REAL bb[2][MAXCOORDS] );
92
93     int                 bboxTooBig( REAL *, int, int, int, int, REAL [2][MAXCOORDS] );
94     int                 xformAndCullCheck( REAL *, int, int, int, int );
95
96     void                identify( REAL[MAXCOORDS][MAXCOORDS] );
97     void                setBboxsize( INREAL *);
98     inline void         setBmat( INREAL*, long, long );
99     inline void         setCmat( INREAL*, long, long );
100     inline void         setSmat( INREAL*, long, long );
101     inline int          isRational( void );
102     inline int          getNcoords( void );
103
104     REAL                pixel_tolerance;    /* pathlength sampling tolerance */
105     REAL                error_tolerance;    /* parametric error sampling tolerance*/
106     REAL                object_space_error_tolerance;    /* object space tess*/
107     REAL                clampfactor;
108     REAL                minsavings;
109     REAL                maxrate;
110     REAL                maxsrate;
111     REAL                maxtrate;
112     REAL                bboxsize[MAXCOORDS];
113
114 private:
115     long                type;
116     int                 isrational;
117     int                 ncoords;
118     int                 hcoords;
119     int                 inhcoords;
120     int                 mask;
121     Maxmatrix           bmat;
122     Maxmatrix           cmat;
123     Maxmatrix           smat;
124     REAL                s_steps;                /* max samples in s direction */
125     REAL                t_steps;                /* max samples in t direction */
126     REAL                sampling_method;        
127     REAL                culling_method;         /* check for culling */
128     REAL                bbox_subdividing;
129     Mapdesc *           next;
130     Backend &           backend;
131
132     void                bbox( REAL [2][MAXCOORDS], REAL *, int, int, int, int );
133     REAL                maxDifference( int, REAL *, int );
134     static void         copy( Maxmatrix, long, INREAL *, long, long );
135
136     /* individual control point routines */
137     static void         transform4d( float[4], float[4], float[4][4] );
138     static void         multmatrix4d ( float[4][4], const float[4][4],
139                                          const float[4][4] );
140     void                copyPt( REAL *, REAL * );
141     void                sumPt( REAL *, REAL *, REAL *, REAL, REAL );
142     void                xformSampling( REAL *, REAL * );
143     void                xformCulling( REAL *, REAL * );
144     void                xformRational( Maxmatrix, REAL *, REAL * );
145     void                xformNonrational( Maxmatrix, REAL *, REAL * );
146     unsigned int        clipbits( REAL * );
147 };
148
149 inline void
150 Mapdesc::setBmat( INREAL *mat, long rstride, long cstride )
151 {
152     copy( bmat, hcoords, mat, rstride, cstride );
153 }
154
155 inline void
156 Mapdesc::setCmat( INREAL *mat, long rstride, long cstride )
157 {
158     copy( cmat, hcoords, mat, rstride, cstride );
159 }
160
161 inline void
162 Mapdesc::setSmat( INREAL *mat, long rstride, long cstride )
163 {
164     copy( smat, hcoords, mat, rstride, cstride );
165 }
166
167 inline long
168 Mapdesc::getType( void )
169 {
170     return type;
171 }
172
173 inline void
174 Mapdesc::xformCulling( REAL *d, REAL *s )
175 {
176     if( isrational )
177         xformRational( cmat, d, s );
178     else
179         xformNonrational( cmat, d, s );
180 }
181
182 inline void
183 Mapdesc::xformSampling( REAL *d, REAL *s )
184 {
185     if( isrational )
186         xformRational( smat, d, s );
187     else
188         xformNonrational( smat, d, s );
189 }
190
191 inline int 
192 Mapdesc::isRational( void )
193 {
194     return isrational ? 1 : 0;
195 }
196
197 inline int              
198 Mapdesc::getNcoords( void ) 
199 {
200     return ncoords; 
201 }
202
203 inline int                      
204 Mapdesc::isConstantSampling( void ) 
205 {
206     return ((sampling_method == N_FIXEDRATE) ? 1 : 0); 
207 }
208
209 inline int                      
210 Mapdesc::isDomainSampling( void ) 
211
212     return ((sampling_method == N_DOMAINDISTANCE) ? 1 : 0); 
213 }
214
215 inline int                      
216 Mapdesc::isParametricDistanceSampling( void ) 
217 {
218     return ((sampling_method == N_PARAMETRICDISTANCE) ? 1 : 0);
219 }
220
221 inline int                      
222 Mapdesc::isObjectSpaceParaSampling( void ) 
223 {
224     return ((sampling_method == N_OBJECTSPACE_PARA) ? 1 : 0);
225 }
226
227 inline int                      
228 Mapdesc::isObjectSpacePathSampling( void ) 
229 {
230     return ((sampling_method == N_OBJECTSPACE_PATH) ? 1 : 0);
231 }
232
233 inline int                      
234 Mapdesc::isSurfaceAreaSampling( void ) 
235 {
236     return ((sampling_method == N_SURFACEAREA) ? 1 : 0);
237 }
238
239 inline int                      
240 Mapdesc::isPathLengthSampling( void ) 
241 {
242     return ((sampling_method == N_PATHLENGTH) ? 1 : 0);
243 }
244
245 inline int                      
246 Mapdesc::isRangeSampling( void ) 
247 {
248     return ( isParametricDistanceSampling() || isPathLengthSampling() ||
249             isSurfaceAreaSampling() ||
250             isObjectSpaceParaSampling() ||
251             isObjectSpacePathSampling());
252 }
253
254 inline int
255 Mapdesc::isSampling( void )
256 {
257     return isRangeSampling() || isConstantSampling() || isDomainSampling();
258 }
259
260 inline int                      
261 Mapdesc::isCulling( void ) 
262 {
263     return ((culling_method != N_NOCULLING) ? 1 : 0);
264 }
265
266 inline int                      
267 Mapdesc::isBboxSubdividing( void ) 
268 {
269     return ((bbox_subdividing != N_NOBBOXSUBDIVISION) ? 1 : 0);
270 }
271 #endif /* __glumapdesc_h_ */