Debian Codegraph @

lib/database/src/so/nodes/nurbs/clients/softcurveval.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 * softcurveval.c++ - curve evaluator
39 *
40 * $Revision: 1.1.1.1 $
41 */
42
43 #include "../SoAddPrefix.h"
44 #include <GL/gl.h>
45 #include "myassert.h"
46 #include "softcurveval.h"
47 #include "softcurvmap.h"
48 #include "cachingeval.h"
49
50
51 _SoNurbsCurveEvaluator::_SoNurbsCurveEvaluator( void )
52 {
53 maps = 0;
54 }
55
56 _SoNurbsCurveEvaluator::~_SoNurbsCurveEvaluator( void )
57 {
58 for( _SoNurbsCurveMap *next; maps; maps = next ) {
59 next = maps->next;
60 delete maps;
61 }
62 }
63
64 void
65 _SoNurbsCurveEvaluator::addMap( _SoNurbsCurveMap *m )
66 {
67 m->next = maps;
68 maps = m;
69 }
70
71 _SoNurbsCurveMap *
72 _SoNurbsCurveEvaluator::firstMap( void )
73 {
74 return maps;
75 }
76
77 _SoNurbsCurveMap *
78 _SoNurbsCurveEvaluator::nextMap( _SoNurbsCurveMap *m )
79 {
80 return m->next;
81 }
82
83 int
84 _SoNurbsCurveEvaluator::isMap( _SoNurbsCurveMap *m )
85 {
86 return (m ? 1 : 0);
87 }
88
89 void
90 _SoNurbsCurveEvaluator::range1f( long, REAL *, REAL * )
91 {
92 }
93
94 void
95 _SoNurbsCurveEvaluator::domain1f( REAL, REAL )
96 {
97 }
98
99 void
100 _SoNurbsCurveEvaluator::bgnline( void )
101 {
102 glBegin( GL_LINE_STRIP );
103 }
104
105 void
106 _SoNurbsCurveEvaluator::endline( void )
107 {
108 glEnd();
109 }
110
111 /*---------------------------------------------------------------------------
112 * disable - turn off a curve map
113 *---------------------------------------------------------------------------
114 */
115 void
116 _SoNurbsCurveEvaluator::disable( long type )
117 {
118 _SoNurbsCurveMap *map = typeToMap(type);
119 assert( map );
120 map->disable();
121 }
122
123 /*---------------------------------------------------------------------------
124 * enable - turn on a curve map
125 *---------------------------------------------------------------------------
126 */
127 void
128 _SoNurbsCurveEvaluator::enable( long type )
129 {
130 _SoNurbsCurveMap *map = typeToMap(type);
131 assert( map );
132 map->enable();
133 }
134
135 /*-------------------------------------------------------------------------
136 * mapgrid1f - define a lattice of points with origin and offset
137 *-------------------------------------------------------------------------
138 */
139 void
140 _SoNurbsCurveEvaluator::mapgrid1f( long nu, REAL u0, REAL u1 )
141 {
142 cus = u0;
143 cdus = (u1 - u0)/(REAL)nu;
144 }
145
146 /*-------------------------------------------------------------------------
147 * bgnmap1 - preamble to curve definition and evaluations
148 *-------------------------------------------------------------------------
149 */
150 void
151 _SoNurbsCurveEvaluator::bgnmap1f( long )
152 {
153 for( _SoNurbsCurveMap *map = firstMap(); isMap(map); map = nextMap(map) )
154 map->disable();
155 }
156
157 /*-------------------------------------------------------------------------
158 * endmap1 - postamble to a curve map
159 *-------------------------------------------------------------------------
160 */
161 void
162 _SoNurbsCurveEvaluator::endmap1f( void )
163 {
164 for( _SoNurbsCurveMap *map = firstMap(); isMap(map); map = nextMap(map) )
165 map->disable();
166 }
167
168 /*-------------------------------------------------------------------------
169 * map1f - pass a desription of a curve map
170 *-------------------------------------------------------------------------
171 */
172 void
173 _SoNurbsCurveEvaluator::map1f(
174 long type, /* map type */
175 REAL ulo, /* lower parametric bound */
176 REAL uhi, /* upper parametric bound */
177 long stride, /* distance to next point in REALS */
178 long order, /* parametric order */
179 REAL *pts /* control points */
180 )
181 {
182 _SoNurbsCurveMap *map = typeToMap(type);
183 assert( map );
184 assert( map->isType( type ) );
185 map->map1f( ulo, uhi, stride, order, pts );
186 }
187
188 /*-------------------------------------------------------------------------
189 * mapmesh1f - evaluate a mesh of points on lattice
190 *-------------------------------------------------------------------------
191 */
192 void _SoNurbsCurveEvaluator::mapmesh1f( long, long from, long to )
193 {
194 assert( to - from >= 0 );
195 bgnline();
196 for( long i = from; i <= to; i++ )
197 evalcoord1f( 0, cus + i * cdus );
198 endline();
199 }
200
201 /*-------------------------------------------------------------------------
202 * evalpoint1i - evaluate a point on a curve
203 *-------------------------------------------------------------------------
204 */
205 void _SoNurbsCurveEvaluator::evalpoint1i( long i )
206 {
207 for( _SoNurbsCurveMap *map = firstMap(); isMap(map); map = nextMap(map) )
208 map->evalcoord1f( cus + i * cdus );
209 }
210
211 /*-------------------------------------------------------------------------
212 * evalcoord1f - evaluate a point on a curve
213 *-------------------------------------------------------------------------
214 */
215 void _SoNurbsCurveEvaluator::evalcoord1f( long, REAL u )
216 {
217 for( _SoNurbsCurveMap *map = firstMap(); isMap(map); map = nextMap(map) )
218 map->evalcoord1f( u );
219 }
220
221 /*---------------------------------------------------------------------------
222 * typeToMap - translate a type symbol to a map pointer
223 *---------------------------------------------------------------------------
224 */
225
226 _SoNurbsCurveMap *
227 _SoNurbsCurveEvaluator::typeToMap( long type )
228 {
229 _SoNurbsCurveMap *map;
230 for( map = firstMap(); map; map = nextMap(map) )
231 if( map->isType( type ) ) break;
232 return map;
233 }
234
235 int
236 _SoNurbsCurveEvaluator::canRecord( void )
237 {
238 return 0;
239 }
240
241 int
242 _SoNurbsCurveEvaluator::canPlayAndRecord( void )
243 {
244 return 0;
245 }
246
247 int
248 _SoNurbsCurveEvaluator::createHandle( int )
249 {
250 return 0;
251 }
252
253 void
254 _SoNurbsCurveEvaluator::beginOutput( ServiceMode, int )
255 {
256 }
257
258 void
259 _SoNurbsCurveEvaluator::endOutput( void )
260 {
261 }
262
263 void
264 _SoNurbsCurveEvaluator::discardRecording( int )
265 {
266 }
267
268 void
269 _SoNurbsCurveEvaluator::playRecording( int )
270 {
271 }