Debian Codegraph @

lib/database/src/so/nodes/nurbs/libnurbs/mapdescv.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 * mapdescv.c++ - $Revision: 1.1.1.1 $
39 * Derrick Burns - 1991
40 */
41
42 #include "glimports.h"
43 #include "mystdio.h"
44 #include "myassert.h"
45 #include "mystring.h"
46 #include "mymath.h"
47 #include "nurbsconsts.h"
48 #include "mapdesc.h"
49
50 /*--------------------------------------------------------------------------
51 * calcPartialVelocity - calculate maximum magnitude of a given partial
52 * derivative
53 *--------------------------------------------------------------------------
54 */
55 REAL
56 Mapdesc::calcPartialVelocity (
57 REAL *p,
58 int stride,
59 int ncols,
60 int partial,
61 REAL range )
62 {
63 REAL tmp[MAXORDER][MAXCOORDS];
64 REAL mag[MAXORDER];
65
66 assert( ncols <= MAXORDER );
67
68 int j, k, t;
69 // copy inhomogeneous control points into temporary array
70 for( j=0; j != ncols; j++ )
71 for( k=0; k != inhcoords; k++ )
72 tmp[j][k] = p[j*stride + k];
73
74 for( t=0; t != partial; t++ )
75 for( j=0; j != ncols-t-1; j++ )
76 for( k=0; k != inhcoords; k++ )
77 tmp[j][k] = tmp[j+1][k] - tmp[j][k];
78
79 // compute magnitude and store in mag array
80 for( j=0; j != ncols-partial; j++ ) {
81 mag[j] = 0.0;
82 for( k=0; k != inhcoords; k++ )
83 mag[j] += tmp[j][k] * tmp[j][k];
84 }
85
86 // compute scale factor
87 REAL fac = 1;
88 REAL invt = 1.0 / range;
89 for( t = ncols-1; t != ncols-1-partial; t-- )
90 fac *= t * invt;
91
92 // compute max magnitude of all entries in array
93 REAL max = 0.0;
94 for( j=0; j != ncols-partial; j++ )
95 if( mag[j] > max ) max = mag[j];
96 max = fac * ::sqrtf( (float) max );
97
98 return max;
99 }
100
101 /*--------------------------------------------------------------------------
102 * calcPartialVelocity - calculate maximum magnitude of a given partial
103 * derivative
104 *--------------------------------------------------------------------------
105 */
106 REAL
107 Mapdesc::calcPartialVelocity (
108 REAL *dist,
109 REAL *p,
110 int rstride,
111 int cstride,
112 int nrows,
113 int ncols,
114 int spartial,
115 int tpartial,
116 REAL srange,
117 REAL trange,
118 int side )
119 {
120 REAL tmp[MAXORDER][MAXORDER][MAXCOORDS];
121 REAL mag[MAXORDER][MAXORDER];
122
123 assert( nrows <= MAXORDER );
124 assert( ncols <= MAXORDER );
125
126 REAL *tp = &tmp[0][0][0];
127 REAL *mp = &mag[0][0];
128 const int istride = sizeof( tmp[0]) / sizeof( tmp[0][0][0] );
129 const int jstride = sizeof( tmp[0][0]) / sizeof( tmp[0][0][0] );
130 const int kstride = sizeof( tmp[0][0][0]) / sizeof( tmp[0][0][0] );
131 const int mistride = sizeof( mag[0]) / sizeof( mag[0][0] );
132 const int mjstride = sizeof( mag[0][0]) / sizeof( mag[0][0] );
133 const int idist = nrows * istride;
134 const int jdist = ncols * jstride;
135 const int kdist = inhcoords * kstride;
136 const int id = idist - spartial * istride;
137 const int jd = jdist - tpartial * jstride;
138
139 {
140 // copy control points
141 REAL *ti = tp;
142 REAL *qi = p;
143 REAL *til = tp + idist;
144 for( ; ti != til; ) {
145 REAL *tj = ti;
146 REAL *qj = qi;
147 REAL *tjl = ti + jdist;
148 for( ; tj != tjl; ) {
149 for( int k=0; k != inhcoords; k++ ) {
150 tj[k] = qj[k];
151 }
152 tj += jstride;
153 qj += cstride;
154 }
155 ti += istride;
156 qi += rstride;
157 }
158 }
159
160 {
161 // compute (s)-partial derivative control points
162 REAL *til = tp + idist - istride;
163 const REAL *till = til - ( spartial * istride );
164 for( ; til != till; til -= istride )
165 for( REAL *ti = tp; ti != til; ti += istride )
166 for( REAL *tj = ti, *tjl = tj + jdist; tj != tjl; tj += jstride )
167 for( int k=0; k != inhcoords; k++ )
168 tj[k] = tj[k+istride] - tj[k];
169 }
170
171 {
172 // compute (s,t)-partial derivative control points
173 REAL *tjl = tp + jdist - jstride;
174 const REAL *tjll = tjl - ( tpartial * jstride );
175 for( ; tjl != tjll; tjl -= jstride )
176 for( REAL *tj = tp; tj != tjl; tj += jstride )
177 for( REAL *ti = tj, *til = ti + id; ti != til; ti += istride )
178 for( int k=0; k != inhcoords; k++ )
179 ti[k] = ti[k+jstride] - ti[k];
180
181 }
182
183 REAL max = 0.0;
184 {
185 // compute magnitude and store in mag array
186 memset( (void *) mp, 0, sizeof( mag ) );
187 for( REAL *ti = tp, *mi = mp, *til = tp + id; ti != til; ti += istride, mi += mistride )
188 for( REAL *tj = ti, *mj = mi, *tjl = ti + jd; tj != tjl; tj += jstride, mj += mjstride ) {
189 for( int k=0; k != inhcoords; k++ )
190 *mj += tj[k] * tj[k];
191 if( *mj > max ) max = *mj;
192 }
193
194 }
195
196 int i, j;
197
198 // compute scale factor
199 REAL fac = 1.0;
200 {
201 REAL invs = 1.0 / srange;
202 REAL invt = 1.0 / trange;
203 for( int s = nrows-1, slast = s-spartial; s != slast; s-- )
204 fac *= s * invs;
205 for( int t = ncols-1, tlast = t-tpartial; t != tlast; t-- )
206 fac *= t * invt;
207 }
208
209 if( side == 0 ) {
210 // compute max magnitude of first and last column
211 dist[0] = 0.0;
212 dist[1] = 0.0;
213 for( i=0; i != nrows-spartial; i++ ) {
214 j = 0;
215 if( mag[i][j] > dist[0] ) dist[0] = mag[i][j];
216
217 j = ncols-tpartial-1;
218 if( mag[i][j] > dist[1] ) dist[1] = mag[i][j];
219 }
220 dist[0] = fac * ::sqrtf( dist[0] );
221 dist[1] = fac * ::sqrtf( dist[1] );
222 } else if( side == 1 ) {
223 // compute max magnitude of first and last row
224 dist[0] = 0.0;
225 dist[1] = 0.0;
226 for( j=0; j != ncols-tpartial; j++ ) {
227 i = 0;
228 if( mag[i][j] > dist[0] ) dist[0] = mag[i][j];
229
230 i = nrows-spartial-1;
231 if( mag[i][j] > dist[1] ) dist[1] = mag[i][j];
232 }
233 dist[0] = fac * ::sqrtf( dist[0] );
234 dist[1] = fac * ::sqrtf( dist[1] );
235 }
236
237 max = fac * ::sqrtf( (float) max );
238
239 return max;
240 }
241