--- ray/src/gen/gensurf.c 1989/10/18 18:49:09 1.4 +++ ray/src/gen/gensurf.c 1990/07/09 09:55:47 1.9 @@ -1,9 +1,9 @@ -/* Copyright (c) 1989 Regents of the University of California */ - #ifndef lint static char SCCSid[] = "$SunId$ LBL"; #endif +/* Copyright (c) 1989 Regents of the University of California */ + /* * gensurf.c - program to generate functional surfaces * @@ -16,17 +16,12 @@ static char SCCSid[] = "$SunId$ LBL"; * 4/3/87 */ -#include -#include "fvect.h" +#include "standard.h" #define XNAME "X_" /* x function name */ #define YNAME "Y_" /* y function name */ #define ZNAME "Z_" /* z function name */ -#define PI 3.14159265358979323846 - -#define FTINY 1e-7 - #define ABS(x) ((x)>=0 ? (x) : -(x)) #define pvect(p) printf(vformat, (p)[0], (p)[1], (p)[2]) @@ -39,7 +34,7 @@ int smooth = 0; /* apply smoothing? */ char *modname, *surfname; -double funvalue(), l_hermite(), argument(); +double funvalue(), l_hermite(), l_bezier(), l_bspline(), argument(); typedef struct { FVECT p; /* vertex position */ @@ -51,12 +46,15 @@ main(argc, argv) int argc; char *argv[]; { + extern long eclock; POINT *row0, *row1, *row2, *rp; int i, j, m, n; char stmp[256]; varset("PI", PI); funset("hermite", 5, l_hermite); + funset("bezier", 5, l_bezier); + funset("bspline", 5, l_bspline); if (argc < 8) goto userror; @@ -94,6 +92,7 @@ char *argv[]; row0++; row1++; row2++; /* print header */ printhead(argc, argv); + eclock = 0; /* initialize */ comprow(-1.0/m, row0, n); comprow(0.0, row1, n); @@ -222,14 +221,25 @@ register POINT *row; int siz; { double st[2]; + int end; register int i; - /* compute one past each end */ + + if (smooth) { + i = -1; /* compute one past each end */ + end = siz+1; + } else { + if (s < -FTINY || s > 1.0+FTINY) + return; + i = 0; + end = siz; + } st[0] = s; - for (i = -1; i <= siz+1; i++) { + while (i <= end) { st[1] = (double)i/siz; row[i].p[0] = funvalue(XNAME, 2, st); row[i].p[1] = funvalue(YNAME, 2, st); row[i].p[2] = funvalue(ZNAME, 2, st); + i++; } } @@ -334,7 +344,7 @@ double mat[4][4],inverse[4][4]; register int i,j,k; register double temp; - bcopy(mat, m4tmp, sizeof(m4tmp)); + bcopy((char *)mat, (char *)m4tmp, sizeof(m4tmp)); /* set inverse to identity */ for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) @@ -420,4 +430,30 @@ l_hermite() argument(2)*(-2.0*t+3.0)*t*t + argument(3)*((t-2.0)*t+1.0)*t + argument(4)*(t-1.0)*t*t ); +} + + +double +l_bezier() +{ + double t; + + t = argument(5); + return( argument(1) * (1.+t*(-3.+t*(3.-t))) + + argument(2) * 3.*t*(1.+t*(-2.+t)) + + argument(3) * 3.*t*t*(1.-t) + + argument(4) * t*t*t ); +} + + +double +l_bspline() +{ + double t; + + t = argument(5); + return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) + + argument(2) * (2./3.+t*t*(-1.+1./2.*t)) + + argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) + + argument(4) * (1./6.*t*t*t) ); }