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]; |
142 |
|
} |
143 |
|
row0++; row1++; row2++; |
144 |
|
/* print header */ |
145 |
< |
printhead(argc, argv); |
145 |
> |
fputs("# ", stdout); |
146 |
> |
printargs(argc, argv, stdout); |
147 |
|
eclock = 0; |
148 |
|
/* initialize */ |
149 |
|
comprow(-1.0/m, row0, n); |
182 |
|
} |
183 |
|
} |
184 |
|
|
185 |
< |
quit(0); |
185 |
> |
return 0; |
186 |
|
|
187 |
|
userror: |
188 |
|
fprintf(stderr, "Usage: %s material name ", argv[0]); |
189 |
< |
fprintf(stderr, "x(s,t) y(s,t) z(s,t) m n [-s][-e expr][-f file]\n"); |
190 |
< |
quit(1); |
189 |
> |
fprintf(stderr, "x(s,t) y(s,t) z(s,t) m n [-s][-o][-e expr][-f file]\n"); |
190 |
> |
return 1; |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
< |
loaddata(file, m, n, pointsize) /* load point data from file */ |
195 |
< |
char *file; |
196 |
< |
int m, n; |
197 |
< |
int pointsize; |
194 |
> |
void |
195 |
> |
loaddata( /* load point data from file */ |
196 |
> |
char *file, |
197 |
> |
int m, |
198 |
> |
int n, |
199 |
> |
int pointsize |
200 |
> |
) |
201 |
|
{ |
202 |
|
FILE *fp; |
203 |
|
char word[64]; |
204 |
< |
register int size; |
205 |
< |
register FLOAT *dp; |
204 |
> |
int size; |
205 |
> |
RREAL *dp; |
206 |
|
|
207 |
|
datarec.flags = HASBORDER; /* assume border values */ |
208 |
|
datarec.m = m+1; |
210 |
|
size = datarec.m*datarec.n*pointsize; |
211 |
|
if (pointsize == 3) |
212 |
|
datarec.flags |= TRIPLETS; |
213 |
< |
dp = (FLOAT *)malloc(size*sizeof(FLOAT)); |
213 |
> |
dp = (RREAL *)malloc(size*sizeof(RREAL)); |
214 |
|
if ((datarec.data = dp) == NULL) { |
215 |
|
fputs("Out of memory\n", stderr); |
216 |
|
exit(1); |
233 |
|
size--; |
234 |
|
} |
235 |
|
if (size == (m+n+1)*pointsize) { /* no border after all */ |
236 |
< |
dp = (FLOAT *)realloc((void *)datarec.data, |
237 |
< |
m*n*pointsize*sizeof(FLOAT)); |
236 |
> |
dp = (RREAL *)realloc(datarec.data, |
237 |
> |
m*n*pointsize*sizeof(RREAL)); |
238 |
|
if (dp != NULL) |
239 |
|
datarec.data = dp; |
240 |
|
datarec.flags &= ~HASBORDER; |
253 |
|
|
254 |
|
|
255 |
|
double |
256 |
< |
l_dataval(nam) /* return recorded data value */ |
257 |
< |
char *nam; |
256 |
> |
l_dataval( /* return recorded data value */ |
257 |
> |
char *nam |
258 |
> |
) |
259 |
|
{ |
260 |
|
double u, v; |
261 |
< |
register int i, j; |
262 |
< |
register FLOAT *dp; |
261 |
> |
int i, j; |
262 |
> |
RREAL *dp; |
263 |
|
double d00, d01, d10, d11; |
264 |
|
/* compute coordinates */ |
265 |
|
u = argument(1); v = argument(2); |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
< |
putobjrow(rp, n) /* output vertex row to .OBJ */ |
299 |
< |
register POINT *rp; |
300 |
< |
int n; |
298 |
> |
void |
299 |
> |
putobjrow( /* output vertex row to .OBJ */ |
300 |
> |
POINT *rp, |
301 |
> |
int n |
302 |
> |
) |
303 |
|
{ |
279 |
– |
static int nverts = 0; |
280 |
– |
|
304 |
|
for ( ; n-- >= 0; rp++) { |
305 |
|
if (!rp->valid) |
306 |
|
continue; |
307 |
|
fputs("v ", stdout); |
308 |
|
pvect(rp->p); |
309 |
< |
if (smooth && !ZEROVECT(rp->n)) |
309 |
> |
if (smooth && !ZEROVECT(rp->n)) { |
310 |
|
printf("\tvn %.9g %.9g %.9g\n", |
311 |
|
rp->n[0], rp->n[1], rp->n[2]); |
312 |
+ |
rp->nvalid = ++nnorms; |
313 |
+ |
} else |
314 |
+ |
rp->nvalid = 0; |
315 |
|
printf("\tvt %.9g %.9g\n", rp->uv[0], rp->uv[1]); |
316 |
|
rp->valid = ++nverts; |
317 |
|
} |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
< |
putsquare(p0, p1, p2, p3) /* put out a square */ |
322 |
< |
POINT *p0, *p1, *p2, *p3; |
321 |
> |
void |
322 |
> |
putobjvert( /* put out OBJ vertex index triplet */ |
323 |
> |
POINT *p |
324 |
> |
) |
325 |
|
{ |
326 |
+ |
int pti = p->valid ? p->valid-nverts-1 : 0; |
327 |
+ |
int ni = p->nvalid ? p->nvalid-nnorms-1 : 0; |
328 |
+ |
|
329 |
+ |
printf(" %d/%d/%d", pti, pti, ni); |
330 |
+ |
} |
331 |
+ |
|
332 |
+ |
|
333 |
+ |
void |
334 |
+ |
putsquare( /* put out a square */ |
335 |
+ |
POINT *p0, |
336 |
+ |
POINT *p1, |
337 |
+ |
POINT *p2, |
338 |
+ |
POINT *p3 |
339 |
+ |
) |
340 |
+ |
{ |
341 |
|
static int nout = 0; |
342 |
|
FVECT norm[4]; |
343 |
|
int axis; |
361 |
|
if (!(ok1 | ok2)) |
362 |
|
return; |
363 |
|
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 |
– |
} |
364 |
|
if (ok1 & ok2 && fdot(vc1,vc2) >= 1.0-FTINY*FTINY) { |
365 |
< |
printf("f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d\n", |
366 |
< |
p0->valid, p0->valid, p0n, |
367 |
< |
p1->valid, p1->valid, p1n, |
368 |
< |
p3->valid, p3->valid, p3n, |
337 |
< |
p2->valid, p2->valid, p2n); |
365 |
> |
putc('f', stdout); |
366 |
> |
putobjvert(p0); putobjvert(p1); |
367 |
> |
putobjvert(p3); putobjvert(p2); |
368 |
> |
putc('\n', stdout); |
369 |
|
return; |
370 |
|
} |
371 |
< |
if (ok1) |
372 |
< |
printf("f %d/%d/%d %d/%d/%d %d/%d/%d\n", |
373 |
< |
p0->valid, p0->valid, p0n, |
374 |
< |
p1->valid, p1->valid, p1n, |
375 |
< |
p2->valid, p2->valid, p2n); |
376 |
< |
if (ok2) |
377 |
< |
printf("f %d/%d/%d %d/%d/%d %d/%d/%d\n", |
378 |
< |
p2->valid, p2->valid, p2n, |
379 |
< |
p1->valid, p1->valid, p1n, |
380 |
< |
p3->valid, p3->valid, p3n); |
371 |
> |
if (ok1) { |
372 |
> |
putc('f', stdout); |
373 |
> |
putobjvert(p0); putobjvert(p1); putobjvert(p2); |
374 |
> |
putc('\n', stdout); |
375 |
> |
} |
376 |
> |
if (ok2) { |
377 |
> |
putc('f', stdout); |
378 |
> |
putobjvert(p2); putobjvert(p1); putobjvert(p3); |
379 |
> |
putc('\n', stdout); |
380 |
> |
} |
381 |
|
return; |
382 |
|
} |
383 |
|
/* compute normal interpolation */ |
387 |
|
if (ok1 & ok2 && fdot(vc1,vc2) >= 1.0-FTINY*FTINY) { |
388 |
|
printf("\n%s ", modname); |
389 |
|
if (axis != -1) { |
390 |
< |
printf("texfunc %s\n", texname); |
360 |
< |
printf(tsargs); |
390 |
> |
printf("texfunc %s\n%s\n", texname, tsargs); |
391 |
|
printf("0\n13\t%d\n", axis); |
392 |
|
pvect(norm[0]); |
393 |
|
pvect(norm[1]); |
409 |
|
if (ok1) { |
410 |
|
printf("\n%s ", modname); |
411 |
|
if (axis != -1) { |
412 |
< |
printf("texfunc %s\n", texname); |
383 |
< |
printf(tsargs); |
412 |
> |
printf("texfunc %s\n%s\n", texname, tsargs); |
413 |
|
printf("0\n13\t%d\n", axis); |
414 |
|
pvect(norm[0]); |
415 |
|
pvect(norm[1]); |
427 |
|
if (ok2) { |
428 |
|
printf("\n%s ", modname); |
429 |
|
if (axis != -1) { |
430 |
< |
printf("texfunc %s\n", texname); |
402 |
< |
printf(tsargs); |
430 |
> |
printf("texfunc %s\n%s\n", texname, tsargs); |
431 |
|
printf("0\n13\t%d\n", axis); |
432 |
|
pvect(norm[0]); |
433 |
|
pvect(norm[1]); |
445 |
|
} |
446 |
|
|
447 |
|
|
448 |
< |
comprow(s, row, siz) /* compute row of values */ |
449 |
< |
double s; |
450 |
< |
register POINT *row; |
451 |
< |
int siz; |
448 |
> |
void |
449 |
> |
comprow( /* compute row of values */ |
450 |
> |
double s, |
451 |
> |
POINT *row, |
452 |
> |
int siz |
453 |
> |
) |
454 |
|
{ |
455 |
|
double st[2]; |
456 |
|
int end; |
457 |
|
int checkvalid; |
458 |
< |
register int i; |
458 |
> |
int i; |
459 |
|
|
460 |
|
if (smooth) { |
461 |
|
i = -1; /* compute one past each end */ |
487 |
|
} |
488 |
|
|
489 |
|
|
490 |
< |
compnorms(r0, r1, r2, siz) /* compute row of averaged normals */ |
491 |
< |
register POINT *r0, *r1, *r2; |
492 |
< |
int siz; |
490 |
> |
void |
491 |
> |
compnorms( /* compute row of averaged normals */ |
492 |
> |
POINT *r0, |
493 |
> |
POINT *r1, |
494 |
> |
POINT *r2, |
495 |
> |
int siz |
496 |
> |
) |
497 |
|
{ |
498 |
|
FVECT v1, v2; |
499 |
|
|
531 |
|
|
532 |
|
|
533 |
|
int |
534 |
< |
norminterp(resmat, p0, p1, p2, p3) /* compute normal interpolation */ |
535 |
< |
register FVECT resmat[4]; |
536 |
< |
POINT *p0, *p1, *p2, *p3; |
534 |
> |
norminterp( /* compute normal interpolation */ |
535 |
> |
FVECT resmat[4], |
536 |
> |
POINT *p0, |
537 |
> |
POINT *p1, |
538 |
> |
POINT *p2, |
539 |
> |
POINT *p3 |
540 |
> |
) |
541 |
|
{ |
542 |
|
#define u ((ax+1)%3) |
543 |
|
#define v ((ax+2)%3) |
544 |
|
|
545 |
< |
register int ax; |
545 |
> |
int ax; |
546 |
|
MAT4 eqnmat; |
547 |
|
FVECT v1; |
548 |
< |
register int i, j; |
548 |
> |
int i, j; |
549 |
|
|
550 |
|
if (!smooth) /* no interpolation if no smoothing */ |
551 |
|
return(-1); |
590 |
|
} |
591 |
|
|
592 |
|
|
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 |
– |
|
593 |
|
double |
594 |
< |
l_hermite() |
594 |
> |
l_hermite(char *nm) |
595 |
|
{ |
596 |
|
double t; |
597 |
|
|
604 |
|
|
605 |
|
|
606 |
|
double |
607 |
< |
l_bezier() |
607 |
> |
l_bezier(char *nm) |
608 |
|
{ |
609 |
|
double t; |
610 |
|
|
617 |
|
|
618 |
|
|
619 |
|
double |
620 |
< |
l_bspline() |
620 |
> |
l_bspline(char *nm) |
621 |
|
{ |
622 |
|
double t; |
623 |
|
|