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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines