ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genworm.c
(Generate patch)

Comparing ray/src/gen/genworm.c (file contents):
Revision 1.1 by greg, Thu Feb 2 11:16:31 1989 UTC vs.
Revision 2.12 by greg, Sat Dec 28 18:05:14 2019 UTC

# Line 1 | Line 1
1 /*
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
4 + /*
5   *  genworm.c - program to generate worms (strings with varying thickness).
6   *
7   *      The program takes as input the functions of t for x, y,
# Line 12 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11   *      9/24/87
12   */
13  
14 < #include  <stdio.h>
14 > #include  <stdlib.h>
15 > #include  <math.h>
16  
17 + #include  "calcomp.h"
18 + #include  "rtio.h"
19 + #include  "resolu.h"
20 + #include  "rterror.h"
21   #include  "fvect.h"
22  
23 < #define  XNAME          "X_"                    /* x function name */
24 < #define  YNAME          "Y_"                    /* y function name */
25 < #define  ZNAME          "Z_"                    /* z function name */
26 < #define  RNAME          "R_"                    /* r function name */
23 > #define  XNAME          "X`SYS`"                /* x function name */
24 > #define  YNAME          "Y`SYS`"                /* y function name */
25 > #define  ZNAME          "Z`SYS`"                /* z function name */
26 > #define  RNAME          "R`SYS`"                /* r function name */
27  
28   #define  PI             3.14159265358979323846
29  
26 #define  FTINY          1e-7
27
30   #define  max(a,b)       ((a) > (b) ? (a) : (b))
31  
32  
33 < double  funvalue(), l_hermite(), argument();
33 > /* XXX redundant, move to library */
34 > double  l_hermite(char *), l_bezier(char *), l_bspline(char *);
35  
36  
37 + int
38   main(argc, argv)
39   int  argc;
40   char  *argv[];
41   {
42          char  stmp[256];
43 <        double  t, f, lastr, r;
43 >        double  t, f, lastr = 0, r;
44          FVECT  lastp, p;
45          int  i, nseg;
46  
47 <        varset("PI", PI, NULL);
48 <        funset("hermite", 5, l_hermite);
47 >        esupport |= E_VARIABLE|E_FUNCTION|E_RCONST;
48 >        esupport &= ~(E_OUTCHAN|E_INCHAN);
49 >        varset("PI", ':', PI);
50 >        funset("hermite", 5, ':', l_hermite);
51 >        funset("bezier", 5, ':', l_bezier);
52 >        funset("bspline", 5, ':', l_bspline);
53  
54          if (argc < 8)
55                  goto userror;
56  
57          for (i = 8; i < argc; i++)
58                  if (!strcmp(argv[i], "-e"))
59 <                        scompile(NULL, argv[++i]);
60 <                else if (!strcmp(argv[i], "-f"))
61 <                        fcompile(argv[++i]);
62 <                else
59 >                        scompile(argv[++i], NULL, 0);
60 >                else if (!strcmp(argv[i], "-f")) {
61 >                        char  *fpath = getpath(argv[++i], getrlibpath(), 0);
62 >                        if (fpath == NULL) {
63 >                                fprintf(stderr, "%s: cannot find file '%s'\n",
64 >                                                argv[0], argv[i]);
65 >                                quit(1);
66 >                        }
67 >                        fcompile(fpath);
68 >                } else
69                          goto userror;
70  
71          sprintf(stmp, "%s(t)=%s;", XNAME, argv[3]);
72 <        scompile(NULL, stmp);
72 >        scompile(stmp, NULL, 0);
73          sprintf(stmp, "%s(t)=%s;", YNAME, argv[4]);
74 <        scompile(NULL, stmp);
74 >        scompile(stmp, NULL, 0);
75          sprintf(stmp, "%s(t)=%s;", ZNAME, argv[5]);
76 <        scompile(NULL, stmp);
76 >        scompile(stmp, NULL, 0);
77          sprintf(stmp, "%s(t)=%s;", RNAME, argv[6]);
78 <        scompile(NULL, stmp);
79 <        nseg = atoi(argv[7]);
78 >        scompile(stmp, NULL, 0);
79 >        nseg = eval(argv[7]) + .5;
80          if (nseg <= 0)
81                  goto userror;
82  
83 <        printhead(argc, argv);
83 >        fputs("# ", stdout);
84 >        printargs(argc, argv, stdout);
85 >        eclock = 0;
86  
87          for (i = 0; i <= nseg; i++) {
88                  t = (double)i/nseg;
# Line 74 | Line 90 | char  *argv[];
90                  p[1] = funvalue(YNAME, 1, &t);
91                  p[2] = funvalue(ZNAME, 1, &t);
92                  r = funvalue(RNAME, 1, &t);
93 <                if (i)
93 >                if (i) {
94                          if (lastr <= r+FTINY && lastr >= r-FTINY) {
95                                  printf("\n%s cylinder %s.c%d\n",
96                                                  argv[1], argv[2], i);
# Line 101 | Line 117 | char  *argv[];
117                                  f = f <= 0.0 ? 0.0 : sqrt(f);
118                                  printf("%18.12g %18.12g\n", f*lastr, f*r);
119                          }
120 +                }
121                  printf("\n%s sphere %s.s%d\n", argv[1], argv[2], i);
122                  printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n",
123                                  p[0], p[1], p[2], r);
124                  VCOPY(lastp, p);
125                  lastr = r;
126          }
127 <        quit(0);
127 >        return 0;
128  
129   userror:
130          fprintf(stderr,
131   "Usage: %s material name x(t) y(t) z(t) r(t) nseg [-e expr] [-f file]\n",
132                          argv[0]);
133 <        quit(1);
133 >        return 1;
134   }
135  
136  
137 < eputs(msg)
138 < char  *msg;
137 > double
138 > l_hermite(char *nm)
139   {
140 <        fputs(msg, stderr);
140 >        double  t;
141 >        
142 >        t = argument(5);
143 >        return( argument(1)*((2.0*t-3.0)*t*t+1.0) +
144 >                argument(2)*(-2.0*t+3.0)*t*t +
145 >                argument(3)*((t-2.0)*t+1.0)*t +
146 >                argument(4)*(t-1.0)*t*t );
147   }
148  
149  
150 < wputs(msg)
151 < char  *msg;
150 > double
151 > l_bezier(char *nm)
152   {
153 <        eputs(msg);
131 < }
153 >        double  t;
154  
155 <
156 < quit(code)
157 < {
158 <        exit(code);
155 >        t = argument(5);
156 >        return( argument(1) * (1.+t*(-3.+t*(3.-t))) +
157 >                argument(2) * 3.*t*(1.+t*(-2.+t)) +
158 >                argument(3) * 3.*t*t*(1.-t) +
159 >                argument(4) * t*t*t );
160   }
161  
162  
140 printhead(ac, av)               /* print command header */
141 register int  ac;
142 register char  **av;
143 {
144        putchar('#');
145        while (ac--) {
146                putchar(' ');
147                fputs(*av++, stdout);
148        }
149        putchar('\n');
150 }
151
152
163   double
164 < l_hermite()                    
164 > l_bspline(char *nm)
165   {
166          double  t;
167 <        
167 >
168          t = argument(5);
169 <        return( argument(1)*((2.0*t-3.0)*t*t+1.0) +
170 <                argument(2)*(-2.0*t+3.0)*t*t +
171 <                argument(3)*((t-2.0)*t+1.0)*t +
172 <                argument(4)*(t-1.0)*t*t );
169 >        return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) +
170 >                argument(2) * (2./3.+t*t*(-1.+1./2.*t)) +
171 >                argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) +
172 >                argument(4) * (1./6.*t*t*t) );
173   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines