Debian Codegraph @

lib/database/src/so/nodes/nurbs/clients/softsurfmap.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 * surfacemap.c++ - surface evaluator
39 *
40 * $Revision: 1.1.1.1 $
41 */
42
43 #include <cstdio>
44 #include <inttypes.h> /* defines long and brethren */
45 #include "myassert.h"
46 #include "mystdio.h"
47 #include "mymath.h"
48 #include "types.h"
49 #include "softsurfmap.h"
50
51 _SoNurbsSurfaceMap::_SoNurbsSurfaceMap( long _type, int _rational, int _ncoords )
52 {
53 type = _type;
54 rational = _rational;
55 ncoords = _ncoords;
56 pts = 0;
57 next = 0;
58 cacheline = 0;
59 isdefined = 0;
60 isenabled = 0;
61 }
62
63 _SoNurbsSurfaceMap::~_SoNurbsSurfaceMap()
64 {
65 if( pts ) delete[] pts;
66 if( cacheline ) delete[] cacheline;
67 }
68
69 void _SoNurbsSurfaceMap::domain( float * ){}
70 void _SoNurbsSurfaceMap::point( float * ){}
71 void _SoNurbsSurfaceMap::uderiv( float * ){}
72 void _SoNurbsSurfaceMap::vderiv( float * ){}
73 void _SoNurbsSurfaceMap::uuderiv( float * ){}
74 void _SoNurbsSurfaceMap::uvderiv( float * ){}
75 void _SoNurbsSurfaceMap::vvderiv( float * ){}
76 void _SoNurbsSurfaceMap::startNewTriStrip(){}
77 void _SoNurbsSurfaceMap::swapTriStripVertices(){}
78
79 int
80 _SoNurbsSurfaceMap::isType( long t )
81 {
82 return (type == t) ? 1 : 0;
83 }
84
85 void
86 _SoNurbsSurfaceMap::enable( void )
87 {
88 isenabled = 1;
89 }
90
91 void
92 _SoNurbsSurfaceMap::disable( void )
93 {
94 isenabled = 0;
95 }
96
97 #define SHALLOWCOPY
98
99 /*-------------------------------------------------------------------------
100 * map2f - pass a desription of a surface map
101 *-------------------------------------------------------------------------
102 */
103 void
104 _SoNurbsSurfaceMap::map2f(
105 REAL _ulower, /* u lower domain coord */
106 REAL _uupper, /* u upper domain coord */
107 long _ustride, /* interpoint distance */
108 long _uorder, /* parametric order */
109 REAL _vlower, /* v lower domain coord */
110 REAL _vupper, /* v upper domain coord */
111 long _vstride, /* interpoint distance */
112 long _vorder, /* parametric order */
113 REAL *_ctlpts) /* control points */
114 {
115 assert( _ctlpts );
116 assert( _ustride >= 0 );
117 assert( _vstride >= 0 );
118 assert( _uorder >= 0 );
119 assert( _uorder <= MAXORDER );
120 assert( _vorder >= 0 );
121 assert( _vorder <= MAXORDER );
122 assert( _ulower <= _uupper );
123 assert( _vlower <= _vupper );
124
125 isdefined = 1;
126
127 if( pts == NULL ) {
128 pts = new REAL[MAXCOORDS * MAXORDER * MAXORDER];
129 cacheline = new _SoNurbsCacheLine[MAXCACHECURVES];
130 }
131
132 ulo = _ulower;
133 uhi = _uupper;
134 ustride = (int) _ustride;
135 uorder = (int) _uorder;
136
137 vlo = _vlower;
138 vhi = _vupper;
139 vstride = (int) _vstride;
140 vorder = (int) _vorder;
141
142
143 #ifdef SHALLOWCOPY
144 ctlpts = _ctlpts; /* shallow copy control points */
145 #endif
146
147 #ifdef DEEPCOPY
148 deepCopy( _ctlpts );
149 #endif
150
151 #ifdef HORNER
152 deepCopyAndScale( _ctlpts );
153 #endif
154 }
155
156 /*---------------------------------------------------------------------------
157 * setv - set v coordinate for current isoparametric line
158 *---------------------------------------------------------------------------
159 */
160
161 void
162 _SoNurbsSurfaceMap::setv( REAL _v, int index )
163 {
164 if( !isdefined || !isenabled ) return;
165
166 _SoNurbsCacheLine& cl = cacheline[index];
167 init( vorder, vstride, _v, vlo, vhi );
168 for( int i = uorder-1; i >= 0 ; i-- ) {
169 for( int j = ncoords-1; j >= 0 ; j-- ) {
170 evaluate( &ctlpts[i*ustride + j],
171 &cl.p[i][j], &cl.pv[i][j], &cl.pvv[i][j] );
172 }
173 }
174 }
175
176 /*---------------------------------------------------------------------------
177 * mapeval - evaluate all maps at given point of given isoline
178 *---------------------------------------------------------------------------
179 */
180
181 void
182 _SoNurbsSurfaceMap::mapeval( REAL *domain, int index, int place )
183 {
184 if( !isdefined || !isenabled ) return;
185
186 _SoNurbsCacheLine& cl = cacheline[index];
187 _SoNurbsCacheVal& cv = cl.cacheval[place];
188 init( uorder, MAXCOORDS, domain[0], ulo, uhi );
189 for( int j = ncoords-1; j >= 0; j-- ) {
190 evaluate( &cl.p[0][j], &cv.c[j], &cv.cu[j], &cv.cuu[j] );
191 evaluate( &cl.pv[0][j], &cv.cv[j], &cv.cuv[j], 0 );
192 evaluate( &cl.pvv[0][j], &cv.cvv[j], 0, 0 );
193 }
194 output( domain, index, place );
195 }
196
197 /*-------------------------------------------------------------------------
198 * output - output a point on a map
199 *-------------------------------------------------------------------------
200 */
201 void
202 _SoNurbsSurfaceMap::output( REAL *_domain, int _index, int _place )
203 {
204 if( !isdefined || !isenabled ) return;
205
206 _SoNurbsCacheVal& val = cacheline[_index].cacheval[_place];
207 domain( _domain );
208 uuderiv( val.cuu );
209 uvderiv( val.cuv );
210 vvderiv( val.cvv );
211 uderiv( val.cu );
212 vderiv( val.cv );
213 point( val.c );
214 }
215
216 void
217 _SoNurbsSurfaceMap::deepCopy( REAL *_pts )
218 {
219 int i,j,k;
220 REAL *p, *q, *r;
221 REAL *mp = pts;
222
223 for( p=_pts, i=0; i<uorder; i++, p += ustride )
224 for( q=p, j=0; j<vorder; j++, q += vstride )
225 for( r=q, k=0; k<ncoords; k++ )
226 *(mp++) = *(r++);
227
228 ctlpts = pts;
229 ustride = ncoords * vorder;
230 vstride = ncoords;
231 }
232
233 void
234 _SoNurbsSurfaceMap::deepCopyAndScale( REAL *_ctlpts )
235 {
236 int nc = ncoords;
237 int ou = uorder;
238 int ov = vorder;
239 int su = ustride;
240 int sv = vstride;
241
242 int i,j,k;
243 for( j = 0; j != ov; j++ ) {
244 REAL comb = Ch(ov-1, j);
245 for( i = 0; i != ou; i++ ) {
246 for( k = 0; k < nc; k++ ) {
247 pts[i*nc*ov+j*nc+k] = comb * _ctlpts[i*su+j*sv+k];
248 }
249 }
250 }
251
252 for( i = 0;i != ou; i++ ) {
253 REAL comb = Ch(ou-1, i);
254 for( j = 0; j != ov; j++ ) {
255 for( k = 0; k != nc; k++ ) {
256 pts[i*nc*ov+j*nc+k] *= comb;
257 }
258 }
259 }
260 ctlpts = pts;
261 ustride = ncoords * vorder;
262 vstride = ncoords;
263 }