17 |
|
|
18 |
|
#include "standard.h" |
19 |
|
|
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 */ |
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? */ |
50 |
|
struct { |
51 |
|
int flags; /* data type */ |
52 |
|
short m, n; /* number of s and t values */ |
53 |
< |
FLOAT *data; /* the data itself, s major sort */ |
53 |
> |
RREAL *data; /* the data itself, s major sort */ |
54 |
|
} datarec; /* our recorded data */ |
55 |
|
|
56 |
+ |
/* XXX this is redundant with rt/noise3.c, should go to a library */ |
57 |
|
double l_hermite(), l_bezier(), l_bspline(), l_dataval(); |
52 |
– |
extern double funvalue(), argument(); |
58 |
|
|
59 |
|
typedef struct { |
60 |
|
int valid; /* point is valid (vertex number) */ |
61 |
+ |
int nvalid; /* normal is valid */ |
62 |
|
FVECT p; /* vertex position */ |
63 |
|
FVECT n; /* average normal */ |
64 |
< |
FLOAT uv[2]; /* (u,v) position */ |
64 |
> |
RREAL uv[2]; /* (u,v) position */ |
65 |
|
} POINT; |
66 |
|
|
67 |
+ |
int nverts = 0; /* vertex output count */ |
68 |
+ |
int nnorms = 0; /* normal output count */ |
69 |
|
|
70 |
+ |
void loaddata(char *file, int m, int n, int pointsize); |
71 |
+ |
double l_dataval(char *nam); |
72 |
+ |
void putobjrow(POINT *rp, int n); |
73 |
+ |
void putobjvert(POINT *p); |
74 |
+ |
void putsquare(POINT *p0, POINT *p1, POINT *p2, POINT *p3); |
75 |
+ |
void comprow(double s, POINT *row, int siz); |
76 |
+ |
void compnorms(POINT *r0, POINT *r1, POINT *r2, int siz); |
77 |
+ |
int norminterp(FVECT resmat[4], POINT *p0, POINT *p1, POINT *p2, POINT *p3); |
78 |
+ |
|
79 |
+ |
|
80 |
+ |
int |
81 |
|
main(argc, argv) |
82 |
|
int argc; |
83 |
|
char *argv[]; |
84 |
|
{ |
66 |
– |
extern long eclock; |
85 |
|
POINT *row0, *row1, *row2, *rp; |
86 |
|
int i, j, m, n; |
87 |
|
char stmp[256]; |
88 |
|
|
89 |
+ |
esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; |
90 |
+ |
esupport &= ~(E_OUTCHAN|E_INCHAN); |
91 |
|
varset("PI", ':', PI); |
92 |
|
funset("hermite", 5, ':', l_hermite); |
93 |
|
funset("bezier", 5, ':', l_bezier); |
99 |
|
for (i = 8; i < argc; i++) |
100 |
|
if (!strcmp(argv[i], "-e")) |
101 |
|
scompile(argv[++i], NULL, 0); |
102 |
< |
else if (!strcmp(argv[i], "-f")) |
103 |
< |
fcompile(argv[++i]); |
104 |
< |
else if (!strcmp(argv[i], "-s")) |
102 |
> |
else if (!strcmp(argv[i], "-f")) { |
103 |
> |
char *fpath = getpath(argv[++i], getrlibpath(), 0); |
104 |
> |
if (fpath == NULL) { |
105 |
> |
fprintf(stderr, "%s: cannot find file '%s'\n", |
106 |
> |
argv[0], argv[i]); |
107 |
> |
quit(1); |
108 |
> |
} |
109 |
> |
fcompile(fpath); |
110 |
> |
} else if (!strcmp(argv[i], "-s")) |
111 |
|
smooth++; |
112 |
|
else if (!strcmp(argv[i], "-o")) |
113 |
|
objout++; |
150 |
|
} |
151 |
|
row0++; row1++; row2++; |
152 |
|
/* print header */ |
153 |
< |
printhead(argc, argv); |
153 |
> |
fputs("# ", stdout); |
154 |
> |
printargs(argc, argv, stdout); |
155 |
|
eclock = 0; |
156 |
|
/* initialize */ |
157 |
|
comprow(-1.0/m, row0, n); |
190 |
|
} |
191 |
|
} |
192 |
|
|
193 |
< |
quit(0); |
193 |
> |
return 0; |
194 |
|
|
195 |
|
userror: |
196 |
|
fprintf(stderr, "Usage: %s material name ", argv[0]); |
197 |
< |
fprintf(stderr, "x(s,t) y(s,t) z(s,t) m n [-s][-e expr][-f file]\n"); |
198 |
< |
quit(1); |
197 |
> |
fprintf(stderr, "x(s,t) y(s,t) z(s,t) m n [-s][-o][-e expr][-f file]\n"); |
198 |
> |
return 1; |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
< |
loaddata(file, m, n, pointsize) /* load point data from file */ |
203 |
< |
char *file; |
204 |
< |
int m, n; |
205 |
< |
int pointsize; |
202 |
> |
void |
203 |
> |
loaddata( /* load point data from file */ |
204 |
> |
char *file, |
205 |
> |
int m, |
206 |
> |
int n, |
207 |
> |
int pointsize |
208 |
> |
) |
209 |
|
{ |
210 |
|
FILE *fp; |
211 |
|
char word[64]; |
212 |
< |
register int size; |
213 |
< |
register FLOAT *dp; |
212 |
> |
int size; |
213 |
> |
RREAL *dp; |
214 |
|
|
215 |
|
datarec.flags = HASBORDER; /* assume border values */ |
216 |
|
datarec.m = m+1; |
218 |
|
size = datarec.m*datarec.n*pointsize; |
219 |
|
if (pointsize == 3) |
220 |
|
datarec.flags |= TRIPLETS; |
221 |
< |
dp = (FLOAT *)malloc(size*sizeof(FLOAT)); |
221 |
> |
dp = (RREAL *)malloc(size*sizeof(RREAL)); |
222 |
|
if ((datarec.data = dp) == NULL) { |
223 |
|
fputs("Out of memory\n", stderr); |
224 |
|
exit(1); |
241 |
|
size--; |
242 |
|
} |
243 |
|
if (size == (m+n+1)*pointsize) { /* no border after all */ |
244 |
< |
dp = (FLOAT *)realloc((char *)datarec.data, |
245 |
< |
m*n*pointsize*sizeof(FLOAT)); |
244 |
> |
dp = (RREAL *)realloc(datarec.data, |
245 |
> |
m*n*pointsize*sizeof(RREAL)); |
246 |
|
if (dp != NULL) |
247 |
|
datarec.data = dp; |
248 |
|
datarec.flags &= ~HASBORDER; |
261 |
|
|
262 |
|
|
263 |
|
double |
264 |
< |
l_dataval(nam) /* return recorded data value */ |
265 |
< |
char *nam; |
264 |
> |
l_dataval( /* return recorded data value */ |
265 |
> |
char *nam |
266 |
> |
) |
267 |
|
{ |
268 |
|
double u, v; |
269 |
< |
register int i, j; |
270 |
< |
register FLOAT *dp; |
269 |
> |
int i, j; |
270 |
> |
RREAL *dp; |
271 |
|
double d00, d01, d10, d11; |
272 |
|
/* compute coordinates */ |
273 |
|
u = argument(1); v = argument(2); |
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
< |
putobjrow(rp, n) /* output vertex row to .OBJ */ |
307 |
< |
register POINT *rp; |
308 |
< |
int n; |
306 |
> |
void |
307 |
> |
putobjrow( /* output vertex row to .OBJ */ |
308 |
> |
POINT *rp, |
309 |
> |
int n |
310 |
> |
) |
311 |
|
{ |
279 |
– |
static int nverts = 0; |
280 |
– |
|
312 |
|
for ( ; n-- >= 0; rp++) { |
313 |
|
if (!rp->valid) |
314 |
|
continue; |
315 |
|
fputs("v ", stdout); |
316 |
|
pvect(rp->p); |
317 |
< |
if (smooth && !ZEROVECT(rp->n)) |
317 |
> |
if (smooth && !ZEROVECT(rp->n)) { |
318 |
|
printf("\tvn %.9g %.9g %.9g\n", |
319 |
|
rp->n[0], rp->n[1], rp->n[2]); |
320 |
+ |
rp->nvalid = ++nnorms; |
321 |
+ |
} else |
322 |
+ |
rp->nvalid = 0; |
323 |
|
printf("\tvt %.9g %.9g\n", rp->uv[0], rp->uv[1]); |
324 |
|
rp->valid = ++nverts; |
325 |
|
} |
326 |
|
} |
327 |
|
|
328 |
|
|
329 |
< |
putsquare(p0, p1, p2, p3) /* put out a square */ |
330 |
< |
POINT *p0, *p1, *p2, *p3; |
329 |
> |
void |
330 |
> |
putobjvert( /* put out OBJ vertex index triplet */ |
331 |
> |
POINT *p |
332 |
> |
) |
333 |
|
{ |
334 |
+ |
int pti = p->valid ? p->valid-nverts-1 : 0; |
335 |
+ |
int ni = p->nvalid ? p->nvalid-nnorms-1 : 0; |
336 |
+ |
|
337 |
+ |
printf(" %d/%d/%d", pti, pti, ni); |
338 |
+ |
} |
339 |
+ |
|
340 |
+ |
|
341 |
+ |
void |
342 |
+ |
putsquare( /* put out a square */ |
343 |
+ |
POINT *p0, |
344 |
+ |
POINT *p1, |
345 |
+ |
POINT *p2, |
346 |
+ |
POINT *p3 |
347 |
+ |
) |
348 |
+ |
{ |
349 |
|
static int nout = 0; |
350 |
|
FVECT norm[4]; |
351 |
|
int axis; |
369 |
|
if (!(ok1 | ok2)) |
370 |
|
return; |
371 |
|
if (objout) { /* output .OBJ faces */ |
321 |
– |
int p0n=0, p1n=0, p2n=0, p3n=0; |
322 |
– |
if (smooth) { |
323 |
– |
if (!ZEROVECT(p0->n)) |
324 |
– |
p0n = p0->valid; |
325 |
– |
if (!ZEROVECT(p1->n)) |
326 |
– |
p1n = p1->valid; |
327 |
– |
if (!ZEROVECT(p2->n)) |
328 |
– |
p2n = p2->valid; |
329 |
– |
if (!ZEROVECT(p3->n)) |
330 |
– |
p3n = p3->valid; |
331 |
– |
} |
372 |
|
if (ok1 & ok2 && fdot(vc1,vc2) >= 1.0-FTINY*FTINY) { |
373 |
< |
printf("f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d\n", |
374 |
< |
p0->valid, p0->valid, p0n, |
375 |
< |
p1->valid, p1->valid, p1n, |
376 |
< |
p3->valid, p3->valid, p3n, |
337 |
< |
p2->valid, p2->valid, p2n); |
373 |
> |
putc('f', stdout); |
374 |
> |
putobjvert(p0); putobjvert(p1); |
375 |
> |
putobjvert(p3); putobjvert(p2); |
376 |
> |
putc('\n', stdout); |
377 |
|
return; |
378 |
|
} |
379 |
< |
if (ok1) |
380 |
< |
printf("f %d/%d/%d %d/%d/%d %d/%d/%d\n", |
381 |
< |
p0->valid, p0->valid, p0n, |
382 |
< |
p1->valid, p1->valid, p1n, |
383 |
< |
p2->valid, p2->valid, p2n); |
384 |
< |
if (ok2) |
385 |
< |
printf("f %d/%d/%d %d/%d/%d %d/%d/%d\n", |
386 |
< |
p2->valid, p2->valid, p2n, |
387 |
< |
p1->valid, p1->valid, p1n, |
388 |
< |
p3->valid, p3->valid, p3n); |
379 |
> |
if (ok1) { |
380 |
> |
putc('f', stdout); |
381 |
> |
putobjvert(p0); putobjvert(p1); putobjvert(p2); |
382 |
> |
putc('\n', stdout); |
383 |
> |
} |
384 |
> |
if (ok2) { |
385 |
> |
putc('f', stdout); |
386 |
> |
putobjvert(p2); putobjvert(p1); putobjvert(p3); |
387 |
> |
putc('\n', stdout); |
388 |
> |
} |
389 |
|
return; |
390 |
|
} |
391 |
|
/* compute normal interpolation */ |
395 |
|
if (ok1 & ok2 && fdot(vc1,vc2) >= 1.0-FTINY*FTINY) { |
396 |
|
printf("\n%s ", modname); |
397 |
|
if (axis != -1) { |
398 |
< |
printf("texfunc %s\n", texname); |
360 |
< |
printf(tsargs); |
398 |
> |
printf("texfunc %s\n%s\n", texname, tsargs); |
399 |
|
printf("0\n13\t%d\n", axis); |
400 |
|
pvect(norm[0]); |
401 |
|
pvect(norm[1]); |
417 |
|
if (ok1) { |
418 |
|
printf("\n%s ", modname); |
419 |
|
if (axis != -1) { |
420 |
< |
printf("texfunc %s\n", texname); |
383 |
< |
printf(tsargs); |
420 |
> |
printf("texfunc %s\n%s\n", texname, tsargs); |
421 |
|
printf("0\n13\t%d\n", axis); |
422 |
|
pvect(norm[0]); |
423 |
|
pvect(norm[1]); |
435 |
|
if (ok2) { |
436 |
|
printf("\n%s ", modname); |
437 |
|
if (axis != -1) { |
438 |
< |
printf("texfunc %s\n", texname); |
402 |
< |
printf(tsargs); |
438 |
> |
printf("texfunc %s\n%s\n", texname, tsargs); |
439 |
|
printf("0\n13\t%d\n", axis); |
440 |
|
pvect(norm[0]); |
441 |
|
pvect(norm[1]); |
453 |
|
} |
454 |
|
|
455 |
|
|
456 |
< |
comprow(s, row, siz) /* compute row of values */ |
457 |
< |
double s; |
458 |
< |
register POINT *row; |
459 |
< |
int siz; |
456 |
> |
void |
457 |
> |
comprow( /* compute row of values */ |
458 |
> |
double s, |
459 |
> |
POINT *row, |
460 |
> |
int siz |
461 |
> |
) |
462 |
|
{ |
463 |
|
double st[2]; |
464 |
|
int end; |
465 |
|
int checkvalid; |
466 |
< |
register int i; |
466 |
> |
int i; |
467 |
|
|
468 |
|
if (smooth) { |
469 |
|
i = -1; /* compute one past each end */ |
495 |
|
} |
496 |
|
|
497 |
|
|
498 |
< |
compnorms(r0, r1, r2, siz) /* compute row of averaged normals */ |
499 |
< |
register POINT *r0, *r1, *r2; |
500 |
< |
int siz; |
498 |
> |
void |
499 |
> |
compnorms( /* compute row of averaged normals */ |
500 |
> |
POINT *r0, |
501 |
> |
POINT *r1, |
502 |
> |
POINT *r2, |
503 |
> |
int siz |
504 |
> |
) |
505 |
|
{ |
506 |
|
FVECT v1, v2; |
507 |
|
|
539 |
|
|
540 |
|
|
541 |
|
int |
542 |
< |
norminterp(resmat, p0, p1, p2, p3) /* compute normal interpolation */ |
543 |
< |
register FVECT resmat[4]; |
544 |
< |
POINT *p0, *p1, *p2, *p3; |
542 |
> |
norminterp( /* compute normal interpolation */ |
543 |
> |
FVECT resmat[4], |
544 |
> |
POINT *p0, |
545 |
> |
POINT *p1, |
546 |
> |
POINT *p2, |
547 |
> |
POINT *p3 |
548 |
> |
) |
549 |
|
{ |
550 |
|
#define u ((ax+1)%3) |
551 |
|
#define v ((ax+2)%3) |
552 |
|
|
553 |
< |
register int ax; |
553 |
> |
int ax; |
554 |
|
MAT4 eqnmat; |
555 |
|
FVECT v1; |
556 |
< |
register int i, j; |
556 |
> |
int i, j; |
557 |
|
|
558 |
|
if (!smooth) /* no interpolation if no smoothing */ |
559 |
|
return(-1); |
598 |
|
} |
599 |
|
|
600 |
|
|
555 |
– |
void |
556 |
– |
eputs(msg) |
557 |
– |
char *msg; |
558 |
– |
{ |
559 |
– |
fputs(msg, stderr); |
560 |
– |
} |
561 |
– |
|
562 |
– |
|
563 |
– |
void |
564 |
– |
wputs(msg) |
565 |
– |
char *msg; |
566 |
– |
{ |
567 |
– |
eputs(msg); |
568 |
– |
} |
569 |
– |
|
570 |
– |
|
571 |
– |
void |
572 |
– |
quit(code) |
573 |
– |
int code; |
574 |
– |
{ |
575 |
– |
exit(code); |
576 |
– |
} |
577 |
– |
|
578 |
– |
|
579 |
– |
printhead(ac, av) /* print command header */ |
580 |
– |
register int ac; |
581 |
– |
register char **av; |
582 |
– |
{ |
583 |
– |
putchar('#'); |
584 |
– |
while (ac--) { |
585 |
– |
putchar(' '); |
586 |
– |
fputs(*av++, stdout); |
587 |
– |
} |
588 |
– |
putchar('\n'); |
589 |
– |
} |
590 |
– |
|
591 |
– |
|
601 |
|
double |
602 |
< |
l_hermite() |
602 |
> |
l_hermite(char *nm) |
603 |
|
{ |
604 |
|
double t; |
605 |
|
|
612 |
|
|
613 |
|
|
614 |
|
double |
615 |
< |
l_bezier() |
615 |
> |
l_bezier(char *nm) |
616 |
|
{ |
617 |
|
double t; |
618 |
|
|
625 |
|
|
626 |
|
|
627 |
|
double |
628 |
< |
l_bspline() |
628 |
> |
l_bspline(char *nm) |
629 |
|
{ |
630 |
|
double t; |
631 |
|
|