Debian Codegraph @

lib/database/src/so/nodes/nurbs/libnurbs/backend.c++

raw
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 * backend.c++ - $Revision: 1.2 $
39 * Derrick Burns - 1991
40 */
41
42 /* Bezier surface backend
43 - interprets display mode (wireframe,shaded,...)
44 */
45
46 #include "glimports.h"
47 #include "mystdio.h"
48 #include "backend.h"
49 #include "basiccrveval.h"
50 #include "basicsurfeval.h"
51 #include "nurbsconsts.h"
52
53 /*-------------------------------------------------------------------------
54 * bgnsurf - preamble to surface definition and evaluations
55 *-------------------------------------------------------------------------
56 */
57 void
58 Backend::bgnsurf( int wiretris, int wirequads, long nuid )
59 {
60 #ifndef NOWIREFRAME
61 wireframetris = wiretris;
62 wireframequads = wirequads;
63 #endif
64 surfaceEvaluator.bgnmap2f( nuid );
65 }
66
67 void
68 Backend::patch( REAL ulo, REAL uhi, REAL vlo, REAL vhi )
69 {
70 surfaceEvaluator.domain2f( ulo, uhi, vlo, vhi );
71 }
72
73 void
74 Backend::surfbbox( long type, REAL *from, REAL *to )
75 {
76 surfaceEvaluator.range2f( type, from, to );
77 }
78
79 /*-------------------------------------------------------------------------
80 * surfpts - pass a desription of a surface map
81 *-------------------------------------------------------------------------
82 */
83 void
84 Backend::surfpts(
85 long type, /* geometry, color, texture, normal */
86 REAL *pts, /* control points */
87 long ustride, /* distance to next point in u direction */
88 long vstride, /* distance to next point in v direction */
89 int uorder, /* u parametric order */
90 int vorder, /* v parametric order */
91 REAL ulo, /* u lower bound */
92 REAL uhi, /* u upper bound */
93 REAL vlo, /* v lower bound */
94 REAL vhi ) /* v upper bound */
95 {
96 surfaceEvaluator.map2f( type,ulo,uhi,ustride,uorder,vlo,vhi,vstride,vorder,pts );
97 surfaceEvaluator.enable( type );
98 }
99
100 /*-------------------------------------------------------------------------
101 * surfgrid - define a lattice of points with origin and offset
102 *-------------------------------------------------------------------------
103 */
104 void
105 Backend::surfgrid( REAL u0, REAL u1, long nu, REAL v0, REAL v1, long nv )
106 {
107 surfaceEvaluator.mapgrid2f( nu, u0, u1, nv, v0, v1 );
108 }
109
110 /*-------------------------------------------------------------------------
111 * surfmesh - evaluate a mesh of points on lattice
112 *-------------------------------------------------------------------------
113 */
114 void
115 Backend::surfmesh( long u, long v, long n, long m )
116 {
117 #ifndef NOWIREFRAME
118 if( wireframequads ) {
119 long v0, v1;
120 long u0f = u, u1f = u+n;
121 long v0f = v, v1f = v+m;
122 long parity = (u & 1);
123
124 for( v0 = v0f, v1 = v0f++ ; v0<v1f; v0 = v1, v1++ ) {
125 surfaceEvaluator.bgnline();
126 for( long u = u0f; u<=u1f; u++ ) {
127 if( parity ) {
128 surfaceEvaluator.evalpoint2i( u, v0 );
129 surfaceEvaluator.evalpoint2i( u, v1 );
130 } else {
131 surfaceEvaluator.evalpoint2i( u, v1 );
132 surfaceEvaluator.evalpoint2i( u, v0 );
133 }
134 parity = 1 - parity;
135 }
136 surfaceEvaluator.endline();
137 }
138 } else {
139 surfaceEvaluator.mapmesh2f( N_MESHFILL, u, u+n, v, v+m );
140 }
141 #else
142 if( wireframequads ) {
143 surfaceEvaluator.mapmesh2f( N_MESHLINE, u, u+n, v, v+m );
144 } else {
145 surfaceEvaluator.mapmesh2f( N_MESHFILL, u, u+n, v, v+m );
146 }
147 #endif
148 }
149
150 /*-------------------------------------------------------------------------
151 * endsurf - postamble to surface
152 *-------------------------------------------------------------------------
153 */
154 void
155 Backend::endsurf( void )
156 {
157 surfaceEvaluator.endmap2f();
158 }
159
160
161 /*-------------------------------------------------------------------------
162 * bgntmesh - preamble to a triangle mesh
163 *-------------------------------------------------------------------------
164 */
165 void
166 Backend::bgntmesh( char * )
167 {
168 #ifndef NOWIREFRAME
169
170 meshindex = 0; /* I think these need to be initialized to zero */
171 npts = 0;
172
173 if( !wireframetris ) {
174 surfaceEvaluator.bgntmesh();
175 }
176 #else
177 if( wireframetris ) {
178 surfaceEvaluator.polymode( N_MESHLINE );
179 surfaceEvaluator.bgntmesh();
180 } else {
181 surfaceEvaluator.polymode( N_MESHFILL );
182 surfaceEvaluator.bgntmesh();
183 }
184 #endif
185 }
186
187 void
188 Backend::tmeshvert( GridTrimVertex *v )
189 {
190 if( v->isGridVert() ) {
191 tmeshvert( v->g );
192 } else {
193 tmeshvert( v->t );
194 }
195 }
196
197 /*-------------------------------------------------------------------------
198 * tmeshvert - evaluate a point on a triangle mesh
199 *-------------------------------------------------------------------------
200 */
201 void
202 Backend::tmeshvert( TrimVertex *t )
203 {
204 const long nuid = t->nuid;
205 const REAL u = t->param[0];
206 const REAL v = t->param[1];
207
208 #ifndef NOWIREFRAME
209 npts++;
210 if( wireframetris ) {
211 if( npts >= 3 ) {
212 surfaceEvaluator.bgnclosedline();
213 if( mesh[0][2] == 0 )
214 surfaceEvaluator.evalcoord2f( (long) mesh[0][3], mesh[0][0], mesh[0][1] );
215 else
216 surfaceEvaluator.evalpoint2i( (long) mesh[0][0], (long) mesh[0][1] );
217 if( mesh[1][2] == 0 )
218 surfaceEvaluator.evalcoord2f( (long) mesh[1][3], mesh[1][0], mesh[1][1] );
219 else
220 surfaceEvaluator.evalpoint2i( (long) mesh[1][0], (long) mesh[1][1] );
221 surfaceEvaluator.evalcoord2f( nuid, u, v );
222 surfaceEvaluator.endclosedline();
223 }
224 mesh[meshindex][0] = u;
225 mesh[meshindex][1] = v;
226 mesh[meshindex][2] = 0;
227 mesh[meshindex][3] = nuid;
228 meshindex = (meshindex+1) % 2;
229 } else {
230 surfaceEvaluator.evalcoord2f( nuid, u, v );
231 }
232 #else
233 surfaceEvaluator.evalcoord2f( nuid, u, v );
234 #endif
235 }
236
237 /*-------------------------------------------------------------------------
238 * tmeshvert - evaluate a grid point of a triangle mesh
239 *-------------------------------------------------------------------------
240 */
241 void
242 Backend::tmeshvert( GridVertex *g )
243 {
244 const long u = g->gparam[0];
245 const long v = g->gparam[1];
246
247 #ifndef NOWIREFRAME
248 npts++;
249 if( wireframetris ) {
250 if( npts >= 3 ) {
251 surfaceEvaluator.bgnclosedline();
252 if( mesh[0][2] == 0 )
253 surfaceEvaluator.evalcoord2f( (long) mesh[0][3], mesh[0][0], mesh[0][1] );
254 else
255 surfaceEvaluator.evalpoint2i( (long) mesh[0][0], (long) mesh[0][1] );
256 if( mesh[1][2] == 0 )
257 surfaceEvaluator.evalcoord2f( (long) mesh[1][3], mesh[1][0], mesh[1][1] );
258 else
259 surfaceEvaluator.evalpoint2i( (long) mesh[1][0], (long) mesh[1][1] );
260 surfaceEvaluator.evalpoint2i( u, v );
261 surfaceEvaluator.endclosedline();
262 }
263 mesh[meshindex][0] = u;
264 mesh[meshindex][1] = v;
265 mesh[meshindex][2] = 1;
266 meshindex = (meshindex+1) % 2;
267 } else {
268 surfaceEvaluator.evalpoint2i( u, v );
269 }
270 #else
271 surfaceEvaluator.evalpoint2i( u, v );
272 #endif
273 }
274
275 /*-------------------------------------------------------------------------
276 * swaptmesh - perform a swap of the triangle mesh pointers
277 *-------------------------------------------------------------------------
278 */
279 void
280 Backend::swaptmesh( void )
281 {
282 #ifndef NOWIREFRAME
283 if( wireframetris ) {
284 meshindex = 1 - meshindex;
285 } else {
286 surfaceEvaluator.swaptmesh();
287 }
288 #else
289 surfaceEvaluator.swaptmesh();
290 #endif
291 }
292
293 /*-------------------------------------------------------------------------
294 * endtmesh - postamble to triangle mesh
295 *-------------------------------------------------------------------------
296 */
297 void
298 Backend::endtmesh( void )
299 {
300 #ifndef NOWIREFRAME
301 if( ! wireframetris )
302 surfaceEvaluator.endtmesh();
303 #else
304 surfaceEvaluator.endtmesh();
305 surfaceEvaluator.polymode( N_MESHFILL );
306 #endif
307 }
308
309
310 /*-------------------------------------------------------------------------
311 * bgnoutline - preamble to outlined rendering
312 *-------------------------------------------------------------------------
313 */
314 void
315 Backend::bgnoutline( void )
316 {
317 surfaceEvaluator.bgnline();
318 }
319
320 /*-------------------------------------------------------------------------
321 * linevert - evaluate a point on an outlined contour
322 *-------------------------------------------------------------------------
323 */
324 void
325 Backend::linevert( TrimVertex *t )
326 {
327 surfaceEvaluator.evalcoord2f( t->nuid, t->param[0], t->param[1] );
328 }
329
330 /*-------------------------------------------------------------------------
331 * linevert - evaluate a grid point of an outlined contour
332 *-------------------------------------------------------------------------
333 */
334 void
335 Backend::linevert( GridVertex *g )
336 {
337 surfaceEvaluator.evalpoint2i( g->gparam[0], g->gparam[1] );
338 }
339
340 /*-------------------------------------------------------------------------
341 * endoutline - postamble to outlined rendering
342 *-------------------------------------------------------------------------
343 */
344 void
345 Backend::endoutline( void )
346 {
347 surfaceEvaluator.endline();
348 }
349
350 /*-------------------------------------------------------------------------
351 * triangle - output a triangle
352 *-------------------------------------------------------------------------
353 */
354 void
355 Backend::triangle( TrimVertex *a, TrimVertex *b, TrimVertex *c )
356 {
357 bgntmesh( "spittriangle" );
358 tmeshvert( a );
359 tmeshvert( b );
360 tmeshvert( c );
361 endtmesh();
362 }
363
364 void
365 Backend::bgncurv( void )
366 {
367 curveEvaluator.bgnmap1f( 0 );
368 }
369
370 void
371 Backend::segment( REAL ulo, REAL uhi )
372 {
373 curveEvaluator.domain1f( ulo, uhi );
374 }
375
376 void
377 Backend::curvpts(
378 long type, /* geometry, color, texture, normal */
379 REAL *pts, /* control points */
380 long stride, /* distance to next point */
381 int order, /* parametric order */
382 REAL ulo, /* lower parametric bound */
383 REAL uhi ) /* upper parametric bound */
384
385 {
386 curveEvaluator.map1f( type, ulo, uhi, stride, order, pts );
387 curveEvaluator.enable( type );
388 }
389
390 void
391 Backend::curvgrid( REAL u0, REAL u1, long nu )
392 {
393 curveEvaluator.mapgrid1f( nu, u0, u1 );
394 }
395
396 void
397 Backend::curvmesh( long from, long n )
398 {
399 curveEvaluator.mapmesh1f( N_MESHFILL, from, from+n );
400 }
401
402 void
403 Backend::curvpt(REAL u)
404 {
405 curveEvaluator.evalcoord1f( 0, u );
406 }
407
408 void
409 Backend::bgnline( void )
410 {
411 curveEvaluator.bgnline();
412 }
413
414 void
415 Backend::endline( void )
416 {
417 curveEvaluator.endline();
418 }
419
420 void
421 Backend::endcurv( void )
422 {
423 curveEvaluator.endmap1f();
424 }