1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
– |
|
5 |
– |
/* Copyright (c) 1989 Regents of the University of California */ |
6 |
– |
|
4 |
|
/* |
5 |
|
* gensurf.c - program to generate functional surfaces |
6 |
|
* |
11 |
|
* rule applied to (s,t). |
12 |
|
* |
13 |
|
* 4/3/87 |
14 |
+ |
* |
15 |
+ |
* 4/16/02 Added conditional vertex output |
16 |
|
*/ |
17 |
|
|
18 |
|
#include "standard.h" |
19 |
|
|
20 |
< |
#define XNAME "X_" /* x function name */ |
21 |
< |
#define YNAME "Y_" /* y function name */ |
22 |
< |
#define ZNAME "Z_" /* z function name */ |
20 |
> |
#include "paths.h" |
21 |
> |
#include "resolu.h" |
22 |
> |
#include "rterror.h" |
23 |
> |
#include "calcomp.h" |
24 |
|
|
25 |
+ |
char XNAME[] = "X`SYS"; /* x function name */ |
26 |
+ |
char YNAME[] = "Y`SYS"; /* y function name */ |
27 |
+ |
char ZNAME[] = "Z`SYS"; /* z function name */ |
28 |
+ |
|
29 |
+ |
char VNAME[] = "valid"; /* valid vertex name */ |
30 |
+ |
|
31 |
|
#define ABS(x) ((x)>=0 ? (x) : -(x)) |
32 |
|
|
33 |
+ |
#define ZEROVECT(v) (DOT(v,v) <= FTINY*FTINY) |
34 |
+ |
|
35 |
|
#define pvect(p) printf(vformat, (p)[0], (p)[1], (p)[2]) |
36 |
|
|
37 |
< |
char vformat[] = "%15.9g %15.9g %15.9g\n"; |
38 |
< |
char tsargs[] = "4 surf_dx surf_dy surf_dz surf.cal\n"; |
37 |
> |
char vformat[] = "%18.12g %18.12g %18.12g\n"; |
38 |
> |
char tsargs[] = "4 surf_dx surf_dy surf_dz surf.cal"; |
39 |
|
char texname[] = "Phong"; |
40 |
|
|
41 |
|
int smooth = 0; /* apply smoothing? */ |
42 |
+ |
int objout = 0; /* output .OBJ format? */ |
43 |
+ |
int rev = 0; /* invert normal directions? */ |
44 |
|
|
45 |
|
char *modname, *surfname; |
46 |
|
|
47 |
< |
double funvalue(), l_hermite(), l_bezier(), l_bspline(), argument(); |
47 |
> |
/* recorded data flags */ |
48 |
> |
#define HASBORDER 01 |
49 |
> |
#define TRIPLETS 02 |
50 |
> |
/* a data structure */ |
51 |
> |
struct { |
52 |
> |
int flags; /* data type */ |
53 |
> |
short m, n; /* number of s and t values */ |
54 |
> |
RREAL *data; /* the data itself, s major sort */ |
55 |
> |
} datarec; /* our recorded data */ |
56 |
|
|
57 |
+ |
/* XXX this is redundant with rt/noise3.c, should go to a library */ |
58 |
+ |
double l_hermite(), l_bezier(), l_bspline(), l_dataval(); |
59 |
+ |
|
60 |
|
typedef struct { |
61 |
+ |
int valid; /* point is valid (vertex number) */ |
62 |
+ |
int nvalid; /* normal is valid (normal number) */ |
63 |
|
FVECT p; /* vertex position */ |
64 |
|
FVECT n; /* average normal */ |
65 |
+ |
RREAL uv[2]; /* (u,v) position */ |
66 |
|
} POINT; |
67 |
|
|
68 |
+ |
int nverts = 0; /* vertex output count */ |
69 |
+ |
int nnorms = 0; /* normal output count */ |
70 |
|
|
71 |
< |
main(argc, argv) |
72 |
< |
int argc; |
73 |
< |
char *argv[]; |
71 |
> |
void loaddata(char *file, int m, int n, int pointsize); |
72 |
> |
double l_dataval(char *nam); |
73 |
> |
void putobjrow(POINT *rp, int n); |
74 |
> |
void putobjvert(POINT *p); |
75 |
> |
void putsquare(POINT *p0, POINT *p1, POINT *p2, POINT *p3); |
76 |
> |
void comprow(double s, POINT *row, int siz); |
77 |
> |
void compnorms(POINT *r0, POINT *r1, POINT *r2, int siz); |
78 |
> |
int norminterp(FVECT resmat[4], POINT *p0, POINT *p1, POINT *p2, POINT *p3); |
79 |
> |
|
80 |
> |
|
81 |
> |
int |
82 |
> |
main(int argc, char *argv[]) |
83 |
|
{ |
49 |
– |
extern long eclock; |
84 |
|
POINT *row0, *row1, *row2, *rp; |
85 |
|
int i, j, m, n; |
86 |
|
char stmp[256]; |
87 |
|
|
88 |
< |
varset("PI", PI); |
89 |
< |
funset("hermite", 5, l_hermite); |
90 |
< |
funset("bezier", 5, l_bezier); |
91 |
< |
funset("bspline", 5, l_bspline); |
88 |
> |
esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; |
89 |
> |
esupport &= ~(E_OUTCHAN|E_INCHAN); |
90 |
> |
varset("PI", ':', PI); |
91 |
> |
funset("hermite", 5, ':', l_hermite); |
92 |
> |
funset("bezier", 5, ':', l_bezier); |
93 |
> |
funset("bspline", 5, ':', l_bspline); |
94 |
|
|
95 |
|
if (argc < 8) |
96 |
|
goto userror; |
98 |
|
for (i = 8; i < argc; i++) |
99 |
|
if (!strcmp(argv[i], "-e")) |
100 |
|
scompile(argv[++i], NULL, 0); |
101 |
< |
else if (!strcmp(argv[i], "-f")) |
102 |
< |
fcompile(argv[++i]); |
103 |
< |
else if (!strcmp(argv[i], "-s")) |
101 |
> |
else if (!strcmp(argv[i], "-f")) { |
102 |
> |
char *fpath = getpath(argv[++i], getrlibpath(), 0); |
103 |
> |
if (fpath == NULL) { |
104 |
> |
fprintf(stderr, "%s: cannot find file '%s'\n", |
105 |
> |
argv[0], argv[i]); |
106 |
> |
quit(1); |
107 |
> |
} |
108 |
> |
fcompile(fpath); |
109 |
> |
} else if (!strcmp(argv[i], "-s")) |
110 |
|
smooth++; |
111 |
+ |
else if (!strcmp(argv[i], "-o")) |
112 |
+ |
objout++; |
113 |
+ |
else if (!strcmp(argv[i], "-i")) |
114 |
+ |
rev = 1; |
115 |
|
else |
116 |
|
goto userror; |
117 |
|
|
118 |
|
modname = argv[1]; |
119 |
|
surfname = argv[2]; |
120 |
< |
sprintf(stmp, "%s(s,t)=%s;", XNAME, argv[3]); |
121 |
< |
scompile(stmp, NULL, 0); |
76 |
< |
sprintf(stmp, "%s(s,t)=%s;", YNAME, argv[4]); |
77 |
< |
scompile(stmp, NULL, 0); |
78 |
< |
sprintf(stmp, "%s(s,t)=%s;", ZNAME, argv[5]); |
79 |
< |
scompile(stmp, NULL, 0); |
80 |
< |
m = atoi(argv[6]); |
81 |
< |
n = atoi(argv[7]); |
120 |
> |
m = eval(argv[6]) + .5; |
121 |
> |
n = eval(argv[7]) + .5; |
122 |
|
if (m <= 0 || n <= 0) |
123 |
|
goto userror; |
124 |
< |
|
124 |
> |
if (!strcmp(argv[5], "-") || access(argv[5], 4) == 0) { /* file? */ |
125 |
> |
funset(ZNAME, 2, ':', l_dataval); |
126 |
> |
if (!strcmp(argv[5],argv[3]) && !strcmp(argv[5],argv[4])) { |
127 |
> |
loaddata(argv[5], m, n, 3); |
128 |
> |
funset(XNAME, 2, ':', l_dataval); |
129 |
> |
funset(YNAME, 2, ':', l_dataval); |
130 |
> |
} else { |
131 |
> |
loaddata(argv[5], m, n, 1); |
132 |
> |
sprintf(stmp, "%s(s,t)=%s;", XNAME, argv[3]); |
133 |
> |
scompile(stmp, NULL, 0); |
134 |
> |
sprintf(stmp, "%s(s,t)=%s;", YNAME, argv[4]); |
135 |
> |
scompile(stmp, NULL, 0); |
136 |
> |
} |
137 |
> |
} else { |
138 |
> |
sprintf(stmp, "%s(s,t)=%s;", XNAME, argv[3]); |
139 |
> |
scompile(stmp, NULL, 0); |
140 |
> |
sprintf(stmp, "%s(s,t)=%s;", YNAME, argv[4]); |
141 |
> |
scompile(stmp, NULL, 0); |
142 |
> |
sprintf(stmp, "%s(s,t)=%s;", ZNAME, argv[5]); |
143 |
> |
scompile(stmp, NULL, 0); |
144 |
> |
} |
145 |
|
row0 = (POINT *)malloc((n+3)*sizeof(POINT)); |
146 |
|
row1 = (POINT *)malloc((n+3)*sizeof(POINT)); |
147 |
|
row2 = (POINT *)malloc((n+3)*sizeof(POINT)); |
151 |
|
} |
152 |
|
row0++; row1++; row2++; |
153 |
|
/* print header */ |
154 |
< |
printhead(argc, argv); |
155 |
< |
eclock = 0; |
154 |
> |
fputs("# ", stdout); |
155 |
> |
printargs(argc, argv, stdout); |
156 |
> |
doptimize(1); |
157 |
> |
eclock++; |
158 |
|
/* initialize */ |
159 |
|
comprow(-1.0/m, row0, n); |
160 |
|
comprow(0.0, row1, n); |
161 |
|
comprow(1.0/m, row2, n); |
162 |
|
compnorms(row0, row1, row2, n); |
163 |
+ |
if (objout) { |
164 |
+ |
printf("\nusemtl %s\n\n", modname); |
165 |
+ |
printf("o %s\n\n", surfname); |
166 |
+ |
putobjrow(row1, n); |
167 |
+ |
} |
168 |
|
/* for each row */ |
169 |
|
for (i = 0; i < m; i++) { |
170 |
|
/* compute next row */ |
174 |
|
row2 = rp; |
175 |
|
comprow((double)(i+2)/m, row2, n); |
176 |
|
compnorms(row0, row1, row2, n); |
177 |
+ |
if (objout) |
178 |
+ |
putobjrow(row1, n); |
179 |
|
|
180 |
|
for (j = 0; j < n; j++) { |
181 |
+ |
int orient = (j & 1); |
182 |
|
/* put polygons */ |
183 |
< |
if ((i+j) & 1) |
183 |
> |
if (!(row0[j].valid && row1[j+1].valid)) |
184 |
> |
orient = 1; |
185 |
> |
else if (!(row1[j].valid && row0[j+1].valid)) |
186 |
> |
orient = 0; |
187 |
> |
if (orient) |
188 |
|
putsquare(&row0[j], &row1[j], |
189 |
|
&row0[j+1], &row1[j+1]); |
190 |
|
else |
193 |
|
} |
194 |
|
} |
195 |
|
|
196 |
< |
quit(0); |
196 |
> |
return 0; |
197 |
|
|
198 |
|
userror: |
199 |
|
fprintf(stderr, "Usage: %s material name ", argv[0]); |
200 |
< |
fprintf(stderr, "x(s,t) y(s,t) z(s,t) m n [-s][-e expr][-f file]\n"); |
201 |
< |
quit(1); |
200 |
> |
fprintf(stderr, "x(s,t) y(s,t) z(s,t) m n [-s][-o][-e expr][-f file]\n"); |
201 |
> |
return 1; |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
< |
putsquare(p0, p1, p2, p3) /* put out a square */ |
206 |
< |
POINT *p0, *p1, *p2, *p3; |
205 |
> |
void |
206 |
> |
loaddata( /* load point data from file */ |
207 |
> |
char *file, |
208 |
> |
int m, |
209 |
> |
int n, |
210 |
> |
int pointsize |
211 |
> |
) |
212 |
|
{ |
213 |
+ |
FILE *fp; |
214 |
+ |
char word[64]; |
215 |
+ |
int size; |
216 |
+ |
RREAL *dp; |
217 |
+ |
|
218 |
+ |
datarec.flags = HASBORDER; /* assume border values */ |
219 |
+ |
datarec.m = m+1; |
220 |
+ |
datarec.n = n+1; |
221 |
+ |
size = datarec.m*datarec.n*pointsize; |
222 |
+ |
if (pointsize == 3) |
223 |
+ |
datarec.flags |= TRIPLETS; |
224 |
+ |
dp = (RREAL *)malloc(size*sizeof(RREAL)); |
225 |
+ |
if ((datarec.data = dp) == NULL) { |
226 |
+ |
fputs("Out of memory\n", stderr); |
227 |
+ |
exit(1); |
228 |
+ |
} |
229 |
+ |
if (!strcmp(file, "-")) { |
230 |
+ |
file = "<stdin>"; |
231 |
+ |
fp = stdin; |
232 |
+ |
} else if ((fp = fopen(file, "r")) == NULL) { |
233 |
+ |
fputs(file, stderr); |
234 |
+ |
fputs(": cannot open\n", stderr); |
235 |
+ |
exit(1); |
236 |
+ |
} |
237 |
+ |
while (size > 0 && fgetword(word, sizeof(word), fp) != NULL) { |
238 |
+ |
if (!isflt(word)) { |
239 |
+ |
fprintf(stderr, "%s: garbled data value: %s\n", |
240 |
+ |
file, word); |
241 |
+ |
exit(1); |
242 |
+ |
} |
243 |
+ |
*dp++ = atof(word); |
244 |
+ |
size--; |
245 |
+ |
} |
246 |
+ |
if (size == (m+n+1)*pointsize) { /* no border after all */ |
247 |
+ |
dp = (RREAL *)realloc(datarec.data, |
248 |
+ |
m*n*pointsize*sizeof(RREAL)); |
249 |
+ |
if (dp != NULL) |
250 |
+ |
datarec.data = dp; |
251 |
+ |
datarec.flags &= ~HASBORDER; |
252 |
+ |
datarec.m = m; |
253 |
+ |
datarec.n = n; |
254 |
+ |
size = 0; |
255 |
+ |
} |
256 |
+ |
if (datarec.m < 2 || datarec.n < 2 || size != 0 || |
257 |
+ |
fgetword(word, sizeof(word), fp) != NULL) { |
258 |
+ |
fputs(file, stderr); |
259 |
+ |
fputs(": bad number of data points\n", stderr); |
260 |
+ |
exit(1); |
261 |
+ |
} |
262 |
+ |
fclose(fp); |
263 |
+ |
} |
264 |
+ |
|
265 |
+ |
|
266 |
+ |
double |
267 |
+ |
l_dataval( /* return recorded data value */ |
268 |
+ |
char *nam |
269 |
+ |
) |
270 |
+ |
{ |
271 |
+ |
double u, v; |
272 |
+ |
int i, j; |
273 |
+ |
RREAL *dp; |
274 |
+ |
double d00, d01, d10, d11; |
275 |
+ |
/* compute coordinates */ |
276 |
+ |
u = argument(1); v = argument(2); |
277 |
+ |
if (datarec.flags & HASBORDER) { |
278 |
+ |
i = u *= datarec.m-1; |
279 |
+ |
j = v *= datarec.n-1; |
280 |
+ |
} else { |
281 |
+ |
i = u = u*datarec.m - .5; |
282 |
+ |
j = v = v*datarec.n - .5; |
283 |
+ |
} |
284 |
+ |
if (i < 0) i = 0; |
285 |
+ |
else if (i > datarec.m-2) i = datarec.m-2; |
286 |
+ |
if (j < 0) j = 0; |
287 |
+ |
else if (j > datarec.n-2) j = datarec.n-2; |
288 |
+ |
/* compute value */ |
289 |
+ |
if (datarec.flags & TRIPLETS) { |
290 |
+ |
dp = datarec.data + 3*(j*datarec.m + i); |
291 |
+ |
if (nam == ZNAME) |
292 |
+ |
dp += 2; |
293 |
+ |
else if (nam == YNAME) |
294 |
+ |
dp++; |
295 |
+ |
d00 = dp[0]; d01 = dp[3]; |
296 |
+ |
dp += 3*datarec.m; |
297 |
+ |
d10 = dp[0]; d11 = dp[3]; |
298 |
+ |
} else { |
299 |
+ |
dp = datarec.data + j*datarec.m + i; |
300 |
+ |
d00 = dp[0]; d01 = dp[1]; |
301 |
+ |
dp += datarec.m; |
302 |
+ |
d10 = dp[0]; d11 = dp[1]; |
303 |
+ |
} |
304 |
+ |
/* bilinear interpolation */ |
305 |
+ |
return((j+1-v)*((i+1-u)*d00+(u-i)*d01)+(v-j)*((i+1-u)*d10+(u-i)*d11)); |
306 |
+ |
} |
307 |
+ |
|
308 |
+ |
|
309 |
+ |
void |
310 |
+ |
putobjrow( /* output vertex row to .OBJ */ |
311 |
+ |
POINT *rp, |
312 |
+ |
int n |
313 |
+ |
) |
314 |
+ |
{ |
315 |
+ |
static FVECT prevNorm; |
316 |
+ |
|
317 |
+ |
for ( ; n-- >= 0; rp++) { |
318 |
+ |
if (!rp->valid) |
319 |
+ |
continue; |
320 |
+ |
fputs("v ", stdout); |
321 |
+ |
pvect(rp->p); |
322 |
+ |
rp->valid = ++nverts; |
323 |
+ |
printf("\tvt %.9g %.9g\n", rp->uv[0], rp->uv[1]); |
324 |
+ |
if (!smooth || ZEROVECT(rp->n)) |
325 |
+ |
rp->nvalid = 0; |
326 |
+ |
else if (VABSEQ(rp->n, prevNorm)) |
327 |
+ |
rp->nvalid = nnorms; |
328 |
+ |
else { |
329 |
+ |
printf("\tvn %.9g %.9g %.9g\n", |
330 |
+ |
rp->n[0], rp->n[1], rp->n[2]); |
331 |
+ |
rp->nvalid = ++nnorms; |
332 |
+ |
VCOPY(prevNorm, rp->n); |
333 |
+ |
} |
334 |
+ |
} |
335 |
+ |
} |
336 |
+ |
|
337 |
+ |
|
338 |
+ |
void |
339 |
+ |
putobjvert( /* put out OBJ vertex index triplet */ |
340 |
+ |
POINT *p |
341 |
+ |
) |
342 |
+ |
{ |
343 |
+ |
int pti = p->valid ? p->valid-nverts-1 : 0; |
344 |
+ |
int ni = p->nvalid ? p->nvalid-nnorms-1 : 0; |
345 |
+ |
|
346 |
+ |
printf(" %d/%d/%d", pti, pti, ni); |
347 |
+ |
} |
348 |
+ |
|
349 |
+ |
|
350 |
+ |
void |
351 |
+ |
putsquare( /* put out a square */ |
352 |
+ |
POINT *p0, |
353 |
+ |
POINT *p1, |
354 |
+ |
POINT *p2, |
355 |
+ |
POINT *p3 |
356 |
+ |
) |
357 |
+ |
{ |
358 |
|
static int nout = 0; |
359 |
|
FVECT norm[4]; |
360 |
|
int axis; |
361 |
|
FVECT v1, v2, vc1, vc2; |
362 |
|
int ok1, ok2; |
363 |
+ |
|
364 |
+ |
if (rev) { /* reverse normals? */ |
365 |
+ |
POINT *pt = p1; p1 = p2; p2 = pt; |
366 |
+ |
} |
367 |
|
/* compute exact normals */ |
368 |
< |
fvsum(v1, p1->p, p0->p, -1.0); |
369 |
< |
fvsum(v2, p2->p, p0->p, -1.0); |
370 |
< |
fcross(vc1, v1, v2); |
371 |
< |
ok1 = normalize(vc1) != 0.0; |
372 |
< |
fvsum(v1, p2->p, p3->p, -1.0); |
373 |
< |
fvsum(v2, p1->p, p3->p, -1.0); |
374 |
< |
fcross(vc2, v1, v2); |
375 |
< |
ok2 = normalize(vc2) != 0.0; |
368 |
> |
ok1 = (p0->valid && p1->valid && p2->valid); |
369 |
> |
if (ok1) { |
370 |
> |
VSUB(v1, p1->p, p0->p); |
371 |
> |
VSUB(v2, p2->p, p0->p); |
372 |
> |
fcross(vc1, v1, v2); |
373 |
> |
ok1 = (normalize(vc1) != 0.0); |
374 |
> |
} |
375 |
> |
ok2 = (p1->valid && p2->valid && p3->valid); |
376 |
> |
if (ok2) { |
377 |
> |
VSUB(v1, p2->p, p3->p); |
378 |
> |
VSUB(v2, p1->p, p3->p); |
379 |
> |
fcross(vc2, v1, v2); |
380 |
> |
ok2 = (normalize(vc2) != 0.0); |
381 |
> |
} |
382 |
|
if (!(ok1 | ok2)) |
383 |
|
return; |
384 |
+ |
if (objout) { /* output .OBJ faces */ |
385 |
+ |
if (ok1 & ok2 && fdot(vc1,vc2) >= 1.0-FTINY*FTINY) { |
386 |
+ |
putc('f', stdout); |
387 |
+ |
putobjvert(p0); putobjvert(p1); |
388 |
+ |
putobjvert(p3); putobjvert(p2); |
389 |
+ |
putc('\n', stdout); |
390 |
+ |
return; |
391 |
+ |
} |
392 |
+ |
if (ok1) { |
393 |
+ |
putc('f', stdout); |
394 |
+ |
putobjvert(p0); putobjvert(p1); putobjvert(p2); |
395 |
+ |
putc('\n', stdout); |
396 |
+ |
} |
397 |
+ |
if (ok2) { |
398 |
+ |
putc('f', stdout); |
399 |
+ |
putobjvert(p2); putobjvert(p1); putobjvert(p3); |
400 |
+ |
putc('\n', stdout); |
401 |
+ |
} |
402 |
+ |
return; |
403 |
+ |
} |
404 |
|
/* compute normal interpolation */ |
405 |
|
axis = norminterp(norm, p0, p1, p2, p3); |
406 |
|
|
408 |
|
if (ok1 & ok2 && fdot(vc1,vc2) >= 1.0-FTINY*FTINY) { |
409 |
|
printf("\n%s ", modname); |
410 |
|
if (axis != -1) { |
411 |
< |
printf("texfunc %s\n", texname); |
158 |
< |
printf(tsargs); |
411 |
> |
printf("texfunc %s\n%s\n", texname, tsargs); |
412 |
|
printf("0\n13\t%d\n", axis); |
413 |
|
pvect(norm[0]); |
414 |
|
pvect(norm[1]); |
430 |
|
if (ok1) { |
431 |
|
printf("\n%s ", modname); |
432 |
|
if (axis != -1) { |
433 |
< |
printf("texfunc %s\n", texname); |
181 |
< |
printf(tsargs); |
433 |
> |
printf("texfunc %s\n%s\n", texname, tsargs); |
434 |
|
printf("0\n13\t%d\n", axis); |
435 |
|
pvect(norm[0]); |
436 |
|
pvect(norm[1]); |
448 |
|
if (ok2) { |
449 |
|
printf("\n%s ", modname); |
450 |
|
if (axis != -1) { |
451 |
< |
printf("texfunc %s\n", texname); |
200 |
< |
printf(tsargs); |
451 |
> |
printf("texfunc %s\n%s\n", texname, tsargs); |
452 |
|
printf("0\n13\t%d\n", axis); |
453 |
|
pvect(norm[0]); |
454 |
|
pvect(norm[1]); |
466 |
|
} |
467 |
|
|
468 |
|
|
469 |
< |
comprow(s, row, siz) /* compute row of values */ |
470 |
< |
double s; |
471 |
< |
register POINT *row; |
472 |
< |
int siz; |
469 |
> |
void |
470 |
> |
comprow( /* compute row of values */ |
471 |
> |
double s, |
472 |
> |
POINT *row, |
473 |
> |
int siz |
474 |
> |
) |
475 |
|
{ |
476 |
|
double st[2]; |
477 |
|
int end; |
478 |
< |
register int i; |
478 |
> |
int checkvalid; |
479 |
> |
int i; |
480 |
|
|
481 |
|
if (smooth) { |
482 |
|
i = -1; /* compute one past each end */ |
488 |
|
end = siz; |
489 |
|
} |
490 |
|
st[0] = s; |
491 |
+ |
checkvalid = (fundefined(VNAME) == 2); |
492 |
|
while (i <= end) { |
493 |
|
st[1] = (double)i/siz; |
494 |
< |
row[i].p[0] = funvalue(XNAME, 2, st); |
495 |
< |
row[i].p[1] = funvalue(YNAME, 2, st); |
496 |
< |
row[i].p[2] = funvalue(ZNAME, 2, st); |
494 |
> |
if (checkvalid && funvalue(VNAME, 2, st) <= 0.0) { |
495 |
> |
row[i].valid = 0; |
496 |
> |
row[i].p[0] = row[i].p[1] = row[i].p[2] = 0.0; |
497 |
> |
row[i].uv[0] = row[i].uv[1] = 0.0; |
498 |
> |
} else { |
499 |
> |
row[i].valid = 1; |
500 |
> |
row[i].p[0] = funvalue(XNAME, 2, st); |
501 |
> |
row[i].p[1] = funvalue(YNAME, 2, st); |
502 |
> |
row[i].p[2] = funvalue(ZNAME, 2, st); |
503 |
> |
row[i].uv[0] = st[0]; |
504 |
> |
row[i].uv[1] = st[1]; |
505 |
> |
} |
506 |
|
i++; |
507 |
|
} |
508 |
|
} |
509 |
|
|
510 |
|
|
511 |
< |
compnorms(r0, r1, r2, siz) /* compute row of averaged normals */ |
512 |
< |
register POINT *r0, *r1, *r2; |
513 |
< |
int siz; |
511 |
> |
void |
512 |
> |
compnorms( /* compute row of averaged normals */ |
513 |
> |
POINT *r0, |
514 |
> |
POINT *r1, |
515 |
> |
POINT *r2, |
516 |
> |
int siz |
517 |
> |
) |
518 |
|
{ |
519 |
< |
FVECT v1, v2, vc; |
252 |
< |
register int i; |
519 |
> |
FVECT v1, v2; |
520 |
|
|
521 |
|
if (!smooth) /* not needed if no smoothing */ |
522 |
|
return; |
523 |
< |
/* compute middle points */ |
523 |
> |
/* compute row 1 normals */ |
524 |
|
while (siz-- >= 0) { |
525 |
< |
fvsum(v1, r2[0].p, r1[0].p, -1.0); |
526 |
< |
fvsum(v2, r1[1].p, r1[0].p, -1.0); |
527 |
< |
fcross(r1[0].n, v1, v2); |
528 |
< |
fvsum(v1, r0[0].p, r1[0].p, -1.0); |
529 |
< |
fcross(vc, v2, v1); |
530 |
< |
fvsum(r1[0].n, r1[0].n, vc, 1.0); |
531 |
< |
fvsum(v2, r1[-1].p, r1[0].p, -1.0); |
532 |
< |
fcross(vc, v1, v2); |
533 |
< |
fvsum(r1[0].n, r1[0].n, vc, 1.0); |
534 |
< |
fvsum(v1, r2[0].p, r1[0].p, -1.0); |
535 |
< |
fcross(vc, v2, v1); |
536 |
< |
fvsum(r1[0].n, r1[0].n, vc, 1.0); |
525 |
> |
if (!r1[0].valid) |
526 |
> |
goto skip; |
527 |
> |
if (!r0[0].valid) { |
528 |
> |
if (!r2[0].valid) { |
529 |
> |
r1[0].n[0] = r1[0].n[1] = r1[0].n[2] = 0.0; |
530 |
> |
goto skip; |
531 |
> |
} |
532 |
> |
fvsum(v1, r2[0].p, r1[0].p, -1.0); |
533 |
> |
} else if (!r2[0].valid) |
534 |
> |
fvsum(v1, r1[0].p, r0[0].p, -1.0); |
535 |
> |
else |
536 |
> |
fvsum(v1, r2[0].p, r0[0].p, -1.0); |
537 |
> |
if (!r1[-1].valid) { |
538 |
> |
if (!r1[1].valid) { |
539 |
> |
r1[0].n[0] = r1[0].n[1] = r1[0].n[2] = 0.0; |
540 |
> |
goto skip; |
541 |
> |
} |
542 |
> |
fvsum(v2, r1[1].p, r1[0].p, -1.0); |
543 |
> |
} else if (!r1[1].valid) |
544 |
> |
fvsum(v2, r1[0].p, r1[-1].p, -1.0); |
545 |
> |
else |
546 |
> |
fvsum(v2, r1[1].p, r1[-1].p, -1.0); |
547 |
> |
if (rev) |
548 |
> |
fcross(r1[0].n, v2, v1); |
549 |
> |
else |
550 |
> |
fcross(r1[0].n, v1, v2); |
551 |
|
normalize(r1[0].n); |
552 |
+ |
skip: |
553 |
|
r0++; r1++; r2++; |
554 |
|
} |
555 |
|
} |
556 |
|
|
557 |
|
|
558 |
|
int |
559 |
< |
norminterp(resmat, p0, p1, p2, p3) /* compute normal interpolation */ |
560 |
< |
register FVECT resmat[4]; |
561 |
< |
POINT *p0, *p1, *p2, *p3; |
559 |
> |
norminterp( /* compute normal interpolation */ |
560 |
> |
FVECT resmat[4], |
561 |
> |
POINT *p0, |
562 |
> |
POINT *p1, |
563 |
> |
POINT *p2, |
564 |
> |
POINT *p3 |
565 |
> |
) |
566 |
|
{ |
567 |
|
#define u ((ax+1)%3) |
568 |
|
#define v ((ax+2)%3) |
569 |
|
|
570 |
< |
register int ax; |
571 |
< |
double eqnmat[4][4]; |
570 |
> |
int ax; |
571 |
> |
MAT4 eqnmat; |
572 |
|
FVECT v1; |
573 |
< |
register int i, j; |
573 |
> |
int i, j; |
574 |
|
|
575 |
|
if (!smooth) /* no interpolation if no smoothing */ |
576 |
|
return(-1); |
599 |
|
eqnmat[3][2] = p3->p[v]; |
600 |
|
eqnmat[3][3] = 1.0; |
601 |
|
/* invert matrix (solve system) */ |
602 |
< |
if (!invmat(eqnmat, eqnmat)) |
602 |
> |
if (!invmat4(eqnmat, eqnmat)) |
603 |
|
return(-1); /* no solution */ |
604 |
|
/* compute result matrix */ |
605 |
|
for (j = 0; j < 4; j++) |
615 |
|
} |
616 |
|
|
617 |
|
|
332 |
– |
/* |
333 |
– |
* invmat - computes the inverse of mat into inverse. Returns 1 |
334 |
– |
* if there exists an inverse, 0 otherwise. It uses Gaussian Elimination |
335 |
– |
* method. |
336 |
– |
*/ |
337 |
– |
|
338 |
– |
invmat(inverse,mat) |
339 |
– |
double mat[4][4],inverse[4][4]; |
340 |
– |
{ |
341 |
– |
#define SWAP(a,b,t) (t=a,a=b,b=t) |
342 |
– |
|
343 |
– |
double m4tmp[4][4]; |
344 |
– |
register int i,j,k; |
345 |
– |
register double temp; |
346 |
– |
|
347 |
– |
bcopy((char *)mat, (char *)m4tmp, sizeof(m4tmp)); |
348 |
– |
/* set inverse to identity */ |
349 |
– |
for (i = 0; i < 4; i++) |
350 |
– |
for (j = 0; j < 4; j++) |
351 |
– |
inverse[i][j] = i==j ? 1.0 : 0.0; |
352 |
– |
|
353 |
– |
for(i = 0; i < 4; i++) { |
354 |
– |
/* Look for raw with largest pivot and swap raws */ |
355 |
– |
temp = FTINY; j = -1; |
356 |
– |
for(k = i; k < 4; k++) |
357 |
– |
if(ABS(m4tmp[k][i]) > temp) { |
358 |
– |
temp = ABS(m4tmp[k][i]); |
359 |
– |
j = k; |
360 |
– |
} |
361 |
– |
if(j == -1) /* No replacing raw -> no inverse */ |
362 |
– |
return(0); |
363 |
– |
if (j != i) |
364 |
– |
for(k = 0; k < 4; k++) { |
365 |
– |
SWAP(m4tmp[i][k],m4tmp[j][k],temp); |
366 |
– |
SWAP(inverse[i][k],inverse[j][k],temp); |
367 |
– |
} |
368 |
– |
|
369 |
– |
temp = m4tmp[i][i]; |
370 |
– |
for(k = 0; k < 4; k++) { |
371 |
– |
m4tmp[i][k] /= temp; |
372 |
– |
inverse[i][k] /= temp; |
373 |
– |
} |
374 |
– |
for(j = 0; j < 4; j++) { |
375 |
– |
if(j != i) { |
376 |
– |
temp = m4tmp[j][i]; |
377 |
– |
for(k = 0; k < 4; k++) { |
378 |
– |
m4tmp[j][k] -= m4tmp[i][k]*temp; |
379 |
– |
inverse[j][k] -= inverse[i][k]*temp; |
380 |
– |
} |
381 |
– |
} |
382 |
– |
} |
383 |
– |
} |
384 |
– |
return(1); |
385 |
– |
|
386 |
– |
#undef SWAP |
387 |
– |
} |
388 |
– |
|
389 |
– |
|
390 |
– |
eputs(msg) |
391 |
– |
char *msg; |
392 |
– |
{ |
393 |
– |
fputs(msg, stderr); |
394 |
– |
} |
395 |
– |
|
396 |
– |
|
397 |
– |
wputs(msg) |
398 |
– |
char *msg; |
399 |
– |
{ |
400 |
– |
eputs(msg); |
401 |
– |
} |
402 |
– |
|
403 |
– |
|
404 |
– |
quit(code) |
405 |
– |
{ |
406 |
– |
exit(code); |
407 |
– |
} |
408 |
– |
|
409 |
– |
|
410 |
– |
printhead(ac, av) /* print command header */ |
411 |
– |
register int ac; |
412 |
– |
register char **av; |
413 |
– |
{ |
414 |
– |
putchar('#'); |
415 |
– |
while (ac--) { |
416 |
– |
putchar(' '); |
417 |
– |
fputs(*av++, stdout); |
418 |
– |
} |
419 |
– |
putchar('\n'); |
420 |
– |
} |
421 |
– |
|
422 |
– |
|
618 |
|
double |
619 |
< |
l_hermite() |
619 |
> |
l_hermite(char *nm) |
620 |
|
{ |
621 |
|
double t; |
622 |
|
|
629 |
|
|
630 |
|
|
631 |
|
double |
632 |
< |
l_bezier() |
632 |
> |
l_bezier(char *nm) |
633 |
|
{ |
634 |
|
double t; |
635 |
|
|
642 |
|
|
643 |
|
|
644 |
|
double |
645 |
< |
l_bspline() |
645 |
> |
l_bspline(char *nm) |
646 |
|
{ |
647 |
|
double t; |
648 |
|
|