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.2 by greg, Sun Sep 10 16:45:18 1989 UTC vs.
Revision 2.15 by greg, Sat Jun 7 05:09:45 2025 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1989 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  genworm.c - program to generate worms (strings with varying thickness).
6   *
# Line 14 | 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  "paths.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  
28 #define  FTINY          1e-7
29
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 >        doptimize(1);
86 >        eclock++;
87  
88          for (i = 0; i <= nseg; i++) {
89                  t = (double)i/nseg;
# Line 76 | Line 91 | char  *argv[];
91                  p[1] = funvalue(YNAME, 1, &t);
92                  p[2] = funvalue(ZNAME, 1, &t);
93                  r = funvalue(RNAME, 1, &t);
94 <                if (i)
94 >                if (i) {
95                          if (lastr <= r+FTINY && lastr >= r-FTINY) {
96                                  printf("\n%s cylinder %s.c%d\n",
97                                                  argv[1], argv[2], i);
# Line 103 | Line 118 | char  *argv[];
118                                  f = f <= 0.0 ? 0.0 : sqrt(f);
119                                  printf("%18.12g %18.12g\n", f*lastr, f*r);
120                          }
121 +                }
122                  printf("\n%s sphere %s.s%d\n", argv[1], argv[2], i);
123                  printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n",
124                                  p[0], p[1], p[2], r);
125                  VCOPY(lastp, p);
126                  lastr = r;
127          }
128 <        quit(0);
128 >        return 0;
129  
130   userror:
131          fprintf(stderr,
132   "Usage: %s material name x(t) y(t) z(t) r(t) nseg [-e expr] [-f file]\n",
133                          argv[0]);
134 <        quit(1);
134 >        return 1;
135   }
136  
137  
138 < eputs(msg)
139 < char  *msg;
138 > double
139 > l_hermite(char *nm)
140   {
141 <        fputs(msg, stderr);
141 >        double  t;
142 >        
143 >        t = argument(5);
144 >        return( argument(1)*((2.0*t-3.0)*t*t+1.0) +
145 >                argument(2)*(-2.0*t+3.0)*t*t +
146 >                argument(3)*((t-2.0)*t+1.0)*t +
147 >                argument(4)*(t-1.0)*t*t );
148   }
149  
150  
151 < wputs(msg)
152 < char  *msg;
151 > double
152 > l_bezier(char *nm)
153   {
154 <        eputs(msg);
133 < }
154 >        double  t;
155  
156 <
157 < quit(code)
158 < {
159 <        exit(code);
156 >        t = argument(5);
157 >        return( argument(1) * (1.+t*(-3.+t*(3.-t))) +
158 >                argument(2) * 3.*t*(1.+t*(-2.+t)) +
159 >                argument(3) * 3.*t*t*(1.-t) +
160 >                argument(4) * t*t*t );
161   }
162  
163  
142 printhead(ac, av)               /* print command header */
143 register int  ac;
144 register char  **av;
145 {
146        putchar('#');
147        while (ac--) {
148                putchar(' ');
149                fputs(*av++, stdout);
150        }
151        putchar('\n');
152 }
153
154
164   double
165 < l_hermite()                    
165 > l_bspline(char *nm)
166   {
167          double  t;
168 <        
168 >
169          t = argument(5);
170 <        return( argument(1)*((2.0*t-3.0)*t*t+1.0) +
171 <                argument(2)*(-2.0*t+3.0)*t*t +
172 <                argument(3)*((t-2.0)*t+1.0)*t +
173 <                argument(4)*(t-1.0)*t*t );
170 >        return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) +
171 >                argument(2) * (2./3.+t*t*(-1.+1./2.*t)) +
172 >                argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) +
173 >                argument(4) * (1./6.*t*t*t) );
174   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines