ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genworm.c
Revision: 2.12
Committed: Sat Dec 28 18:05:14 2019 UTC (4 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R3, HEAD
Changes since 2.11: +1 -3 lines
Log Message:
Removed redundant include files

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: genworm.c,v 2.11 2019/12/07 02:21:42 greg Exp $";
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,
8 * z and r (the radius). Cylinders and cones will be
9 * joined by spheres. Negative radii are forbidden.
10 *
11 * 9/24/87
12 */
13
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`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
30 #define max(a,b) ((a) > (b) ? (a) : (b))
31
32
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 = 0, r;
44 FVECT lastp, p;
45 int i, nseg;
46
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(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(stmp, NULL, 0);
73 sprintf(stmp, "%s(t)=%s;", YNAME, argv[4]);
74 scompile(stmp, NULL, 0);
75 sprintf(stmp, "%s(t)=%s;", ZNAME, argv[5]);
76 scompile(stmp, NULL, 0);
77 sprintf(stmp, "%s(t)=%s;", RNAME, argv[6]);
78 scompile(stmp, NULL, 0);
79 nseg = eval(argv[7]) + .5;
80 if (nseg <= 0)
81 goto userror;
82
83 fputs("# ", stdout);
84 printargs(argc, argv, stdout);
85 eclock = 0;
86
87 for (i = 0; i <= nseg; i++) {
88 t = (double)i/nseg;
89 p[0] = funvalue(XNAME, 1, &t);
90 p[1] = funvalue(YNAME, 1, &t);
91 p[2] = funvalue(ZNAME, 1, &t);
92 r = funvalue(RNAME, 1, &t);
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);
97 printf("0\n0\n7\n");
98 printf("%18.12g %18.12g %18.12g\n",
99 lastp[0], lastp[1], lastp[2]);
100 printf("%18.12g %18.12g %18.12g\n",
101 p[0], p[1], p[2]);
102 printf("%18.12g\n", r);
103 } else {
104 printf("\n%s cone %s.c%d\n",
105 argv[1], argv[2], i);
106 printf("0\n0\n8\n");
107 f = (lastr - r)/dist2(lastp,p);
108 printf("%18.12g %18.12g %18.12g\n",
109 lastp[0] + f*lastr*(p[0] - lastp[0]),
110 lastp[1] + f*lastr*(p[1] - lastp[1]),
111 lastp[2] + f*lastr*(p[2] - lastp[2]));
112 printf("%18.12g %18.12g %18.12g\n",
113 p[0] + f*r*(p[0] - lastp[0]),
114 p[1] + f*r*(p[1] - lastp[1]),
115 p[2] + f*r*(p[2] - lastp[2]));
116 f = 1.0 - (lastr-r)*f;
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 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 return 1;
134 }
135
136
137 double
138 l_hermite(char *nm)
139 {
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 double
151 l_bezier(char *nm)
152 {
153 double t;
154
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
163 double
164 l_bspline(char *nm)
165 {
166 double t;
167
168 t = argument(5);
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 }