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.3 by greg, Fri Mar 2 17:24:05 1990 UTC vs.
Revision 2.11 by greg, Sat Dec 7 02:21:42 2019 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  "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  
28 #define  FTINY          1e-7
29
32   #define  max(a,b)       ((a) > (b) ? (a) : (b))
33  
34  
35 < double  funvalue(), l_hermite(), l_bezier(), 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);
51 <        funset("bezier", 5, l_bezier);
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);
81 <        nseg = atoi(argv[7]);
80 >        scompile(stmp, NULL, 0);
81 >        nseg = eval(argv[7]) + .5;
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 77 | 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 104 | 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  
123 eputs(msg)
124 char  *msg;
125 {
126        fputs(msg, stderr);
127 }
128
129
130 wputs(msg)
131 char  *msg;
132 {
133        eputs(msg);
134 }
135
136
137 quit(code)
138 {
139        exit(code);
140 }
141
142
143 printhead(ac, av)               /* print command header */
144 register int  ac;
145 register char  **av;
146 {
147        putchar('#');
148        while (ac--) {
149                putchar(' ');
150                fputs(*av++, stdout);
151        }
152        putchar('\n');
153 }
154
155
139   double
140 < l_hermite()                    
140 > l_hermite(char *nm)
141   {
142          double  t;
143          
# Line 167 | Line 150 | l_hermite()                    
150  
151  
152   double
153 < l_bezier()
153 > l_bezier(char *nm)
154   {
155          double  t;
156  
# Line 176 | Line 159 | l_bezier()
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 +
165 + double
166 + l_bspline(char *nm)
167 + {
168 +        double  t;
169 +
170 +        t = argument(5);
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