Debian Codegraph @

lib/database/src/so/nodes/nurbs/clients/isocurveeval.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 * isocurveevaluator.c++ - isocurve evaluator
39 *
40 * $Revision: 1.1.1.1 $
41 */
42
43 #include "myassert.h"
44 #include "defines.h"
45 #include "isocurveeval.h"
46
47
48 const
49 int _SoNurbsIsocurveEvaluator::Comb[157] =
50 {
51 1,
52 1,
53 1,2,
54 1,3,
55 1,4,6,
56 1,5,10,
57 1,6,15,20,
58 1,7,21,35,
59 1,8,28,56,70,
60 1,9,36,84,126,
61 1,10,45,120,210,252,
62 1,11,55,165,330,462,
63 1,12,66,220,495,792,924,
64 1,13,78,286,715,1287,1716,
65 1,14,91,364,1001,2002,3003,3432,
66 1,15,105,455,1365,3003,5005,6435,
67 1,16,120,560,1820,4368,8008,11440,12870,
68 1,17,136,680,2380,6188,12376,19448,24310,
69 1,18,153,816,3060,8568,18564,31824,43758,48620,
70 1,19,171,969,3876,11628,27132,50388,75582,92378,
71 1,20,190,1140,4845,15504,38760,77520,125970,167960,184756,
72 1,21,210,1330,5985,20349,54264,116280,203490,293930,352716,
73 1,22,231,1540,7315,26334,74613,170544,319770,497420,646646,705432,
74 1,23,253,1771,8855,33649,100947,245157,490314,817190,1144066,1352078
75 };
76
77
78 /*
79 * Ch(n,m)
80 * retrieves the binomial coefficient (n) from the above array.
81 * (m)
82 */
83
84 unsigned int
85 _SoNurbsIsocurveEvaluator::Ch( unsigned int n, unsigned int m )
86 {
87 /*
88 * given the n and m find the index into the Comb array
89 */
90 unsigned int index;
91 if( n < 24 ) {
92 if(m>(n>>1)) /*store 1/2 array since (n chs m)=(n chs n-m)*/
93 m = n - m;
94 index = (n>>1) * ((n>>1) + 1) + m + (n&1) * ((n+1)>>1);
95 return Comb[index];
96 } else { /* n > table entries, use Pascal's triangle */
97 if( m==0 || m==n ) {
98 return 1;
99 } else {
100 return (Ch(n-1,m-1) + Ch(n-1,m));
101 }
102 }
103 }
104
105 /*---------------------------------------------------------------------------
106 * eval_init - initialize evaluation parameters
107 *---------------------------------------------------------------------------
108 */
109
110 void
111 _SoNurbsIsocurveEvaluator::init( int order, int stride, REAL param, REAL lo, REAL hi )
112 {
113 #ifdef DEBUG
114 assert( order < MAXORDER );
115 #endif
116 Evaluation_order = (int) order;
117 Evaluation_stride = stride;
118 REAL range = 1.0 / ( hi - lo);
119 Evaluation_param = (param - lo) * range;
120 Evaluation_nparam = (hi - param) * range;
121 Evaluation_order1 = (double) (order-1) * range;
122 Evaluation_order2 = (double) ((order-1) * (order-2) * range * range);
123 }
124
125 /*---------------------------------------------------------------------------
126 * eval_row - evaluate a row of control points
127 *---------------------------------------------------------------------------
128 */
129
130 #ifndef HORNER
131 void
132 _SoNurbsIsocurveEvaluator::evaluate( REAL *ptr, REAL *p, REAL *dp, REAL *ddp )
133 {
134 double tmp[MAXORDER];
135 int order = Evaluation_order;
136 double order1 = Evaluation_order1;
137 double order2 = Evaluation_order2;
138 register int stride = Evaluation_stride;
139 register double param = Evaluation_param;
140 register double nparam = Evaluation_nparam;
141
142 if( p == 0 && dp == 0 && ddp == 0 ) return;
143
144 if( p ) *p = 0.0;
145 if( dp ) *dp = 0.0;
146 if( ddp ) *ddp = 0.0;
147
148 {
149
150 register int offset = (order-1) * stride;
151 switch( order ) {
152 case 8: tmp[7] = ptr[offset]; offset -= stride;
153 case 7: tmp[6] = ptr[offset]; offset -= stride;
154 case 6: tmp[5] = ptr[offset]; offset -= stride;
155 case 5: tmp[4] = ptr[offset]; offset -= stride;
156 case 4: tmp[3] = ptr[offset]; offset -= stride;
157 case 3: tmp[2] = ptr[offset];
158 case 2: tmp[1] = ptr[stride];
159 case 1: tmp[0] = ptr[0];
160 break;
161 default: {
162 for( register int j=0; j<order; j++ )
163 tmp[j] = ptr[stride * j];
164 }
165 }
166 }
167
168 if( order > 8 ) {
169 for( register int i=order-1; i>=8; i-- )
170 for( register int j=0; j<i; j++)
171 tmp[j] = tmp[j] * nparam + tmp[j+1] * param;
172 }
173
174 register double a, b, c, d, e, f, g, h;
175
176 switch( order ) {
177 case 8: h = tmp[7];
178 case 7: g = tmp[6];
179 case 6: f = tmp[5];
180 case 5: e = tmp[4];
181 case 4: d = tmp[3];
182 case 3: c = tmp[2];
183 case 2: b = tmp[1];
184 case 1: a = tmp[0];
185 }
186
187 switch( order ) {
188 case 8:
189 a = a * nparam + b * param;
190 b = b * nparam + c * param;
191 c = c * nparam + d * param;
192 d = d * nparam + e * param;
193 e = e * nparam + f * param;
194 f = f * nparam + g * param;
195 g = g * nparam + h * param;
196 case 7:
197 a = a * nparam + b * param;
198 b = b * nparam + c * param;
199 c = c * nparam + d * param;
200 d = d * nparam + e * param;
201 e = e * nparam + f * param;
202 f = f * nparam + g * param;
203 case 6:
204 a = a * nparam + b * param;
205 b = b * nparam + c * param;
206 c = c * nparam + d * param;
207 d = d * nparam + e * param;
208 e = e * nparam + f * param;
209 case 5:
210 a = a * nparam + b * param;
211 b = b * nparam + c * param;
212 c = c * nparam + d * param;
213 d = d * nparam + e * param;
214 case 4:
215 a = a * nparam + b * param;
216 b = b * nparam + c * param;
217 c = c * nparam + d * param;
218 case 3:
219 if( ddp ) *ddp = ((c-b)-(b-a)) * order2;
220 a = a * nparam + b * param;
221 b = b * nparam + c * param;
222 case 2:
223 if( dp ) *dp = (b-a) * order1;
224 a = a * nparam + b * param;
225 case 1:
226 if( p ) *p = a;
227 break;
228 }
229 }
230
231 #else
232
233 void
234 _SoNurbsIsocurveEvaluator::evaluate( REAL *ptr, REAL *p, REAL *dp, REAL *ddp )
235 {
236 int i,j;
237 int str = Evaluation_stride;
238 int ord = Evaluation_order;
239 int deg = ord - 1;
240 REAL t = Evaluation_param;
241 REAL tc = Evaluation_nparam;
242 REAL t_pow = 1.;
243 REAL res;
244
245 if( p == 0 && dp == 0 && ddp == 0 ) return;
246 if( p ) {
247 unsigned int l;
248 res = ptr[0] * tc;
249 for(i = 1, l = str; i < deg; i++, l+= str) {
250 t_pow *= t;
251 res = (res + t_pow * ptr[l]) * tc;
252 }
253 res += t * t_pow * ptr[l];
254 *p = res;
255 }
256
257 if( dp ) {
258 unsigned int l;
259 REAL fdeg = deg;
260 REAL fip; /* i + 1 */
261 REAL fi;
262 t_pow = 1.;
263 res = (ptr[str] - fdeg*ptr[0]) * tc;
264 for(i = 1,l=str,fi=1.,fip=2.; i < deg-1; i++,l+=str,fi+=1,fip+=1.) {
265 t_pow *= t;
266 res = (res + t_pow*(fip*ptr[l+str]-(fdeg-fi)*ptr[l]))*tc;
267 }
268 res += t * t_pow * (fdeg *ptr[l+str]-ptr[l]);
269 *dp = res;
270 }
271 }
272
273 #endif /* HORNER */