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.9 by greg, Fri Jan 12 00:50:17 2018 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  <stdlib.h>
15   #include  <stdio.h>
16 + #include  <math.h>
17 + #include  <string.h>
18  
19 + #include  "calcomp.h"
20 + #include  "resolu.h"
21 + #include  "rterror.h"
22   #include  "fvect.h"
23  
24 < #define  XNAME          "X_"                    /* x function name */
25 < #define  YNAME          "Y_"                    /* y function name */
26 < #define  ZNAME          "Z_"                    /* z function name */
27 < #define  RNAME          "R_"                    /* r function name */
24 > #define  XNAME          "X`SYS`"                /* x function name */
25 > #define  YNAME          "Y`SYS`"                /* y function name */
26 > #define  ZNAME          "Z`SYS`"                /* z function name */
27 > #define  RNAME          "R`SYS`"                /* r function name */
28  
29   #define  PI             3.14159265358979323846
30  
28 #define  FTINY          1e-7
29
31   #define  max(a,b)       ((a) > (b) ? (a) : (b))
32  
33  
34 < double  funvalue(), l_hermite(), argument();
34 > /* XXX redundant, move to library */
35 > double  l_hermite(char *), l_bezier(char *), l_bspline(char *);
36  
37  
38 + int
39   main(argc, argv)
40   int  argc;
41   char  *argv[];
42   {
43          char  stmp[256];
44 <        double  t, f, lastr, r;
44 >        double  t, f, lastr = 0, r;
45          FVECT  lastp, p;
46          int  i, nseg;
47  
48 <        varset("PI", PI, NULL);
49 <        funset("hermite", 5, l_hermite);
48 >        esupport |= E_VARIABLE|E_FUNCTION|E_RCONST;
49 >        esupport &= ~(E_OUTCHAN|E_INCHAN);
50 >        varset("PI", ':', PI);
51 >        funset("hermite", 5, ':', l_hermite);
52 >        funset("bezier", 5, ':', l_bezier);
53 >        funset("bspline", 5, ':', l_bspline);
54  
55          if (argc < 8)
56                  goto userror;
57  
58          for (i = 8; i < argc; i++)
59                  if (!strcmp(argv[i], "-e"))
60 <                        scompile(NULL, argv[++i]);
60 >                        scompile(argv[++i], NULL, 0);
61                  else if (!strcmp(argv[i], "-f"))
62                          fcompile(argv[++i]);
63                  else
64                          goto userror;
65  
66          sprintf(stmp, "%s(t)=%s;", XNAME, argv[3]);
67 <        scompile(NULL, stmp);
67 >        scompile(stmp, NULL, 0);
68          sprintf(stmp, "%s(t)=%s;", YNAME, argv[4]);
69 <        scompile(NULL, stmp);
69 >        scompile(stmp, NULL, 0);
70          sprintf(stmp, "%s(t)=%s;", ZNAME, argv[5]);
71 <        scompile(NULL, stmp);
71 >        scompile(stmp, NULL, 0);
72          sprintf(stmp, "%s(t)=%s;", RNAME, argv[6]);
73 <        scompile(NULL, stmp);
73 >        scompile(stmp, NULL, 0);
74          nseg = atoi(argv[7]);
75          if (nseg <= 0)
76                  goto userror;
77  
78 <        printhead(argc, argv);
78 >        fputs("# ", stdout);
79 >        printargs(argc, argv, stdout);
80 >        eclock = 0;
81  
82          for (i = 0; i <= nseg; i++) {
83                  t = (double)i/nseg;
# Line 76 | Line 85 | char  *argv[];
85                  p[1] = funvalue(YNAME, 1, &t);
86                  p[2] = funvalue(ZNAME, 1, &t);
87                  r = funvalue(RNAME, 1, &t);
88 <                if (i)
88 >                if (i) {
89                          if (lastr <= r+FTINY && lastr >= r-FTINY) {
90                                  printf("\n%s cylinder %s.c%d\n",
91                                                  argv[1], argv[2], i);
# Line 103 | Line 112 | char  *argv[];
112                                  f = f <= 0.0 ? 0.0 : sqrt(f);
113                                  printf("%18.12g %18.12g\n", f*lastr, f*r);
114                          }
115 +                }
116                  printf("\n%s sphere %s.s%d\n", argv[1], argv[2], i);
117                  printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n",
118                                  p[0], p[1], p[2], r);
119                  VCOPY(lastp, p);
120                  lastr = r;
121          }
122 <        quit(0);
122 >        return 0;
123  
124   userror:
125          fprintf(stderr,
126   "Usage: %s material name x(t) y(t) z(t) r(t) nseg [-e expr] [-f file]\n",
127                          argv[0]);
128 <        quit(1);
128 >        return 1;
129   }
130  
131  
132 < eputs(msg)
133 < char  *msg;
132 > double
133 > l_hermite(char *nm)
134   {
135 <        fputs(msg, stderr);
135 >        double  t;
136 >        
137 >        t = argument(5);
138 >        return( argument(1)*((2.0*t-3.0)*t*t+1.0) +
139 >                argument(2)*(-2.0*t+3.0)*t*t +
140 >                argument(3)*((t-2.0)*t+1.0)*t +
141 >                argument(4)*(t-1.0)*t*t );
142   }
143  
144  
145 < wputs(msg)
146 < char  *msg;
145 > double
146 > l_bezier(char *nm)
147   {
148 <        eputs(msg);
133 < }
148 >        double  t;
149  
150 <
151 < quit(code)
152 < {
153 <        exit(code);
150 >        t = argument(5);
151 >        return( argument(1) * (1.+t*(-3.+t*(3.-t))) +
152 >                argument(2) * 3.*t*(1.+t*(-2.+t)) +
153 >                argument(3) * 3.*t*t*(1.-t) +
154 >                argument(4) * t*t*t );
155   }
156  
157  
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
158   double
159 < l_hermite()                    
159 > l_bspline(char *nm)
160   {
161          double  t;
162 <        
162 >
163          t = argument(5);
164 <        return( argument(1)*((2.0*t-3.0)*t*t+1.0) +
165 <                argument(2)*(-2.0*t+3.0)*t*t +
166 <                argument(3)*((t-2.0)*t+1.0)*t +
167 <                argument(4)*(t-1.0)*t*t );
164 >        return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) +
165 >                argument(2) * (2./3.+t*t*(-1.+1./2.*t)) +
166 >                argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) +
167 >                argument(4) * (1./6.*t*t*t) );
168   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines