ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genrev.c
Revision: 1.2
Committed: Sun Sep 10 16:45:14 1989 UTC (34 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +3 -1 lines
Log Message:
fixed location of SCCSid

File Contents

# Content
1 /* Copyright (c) 1989 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * genrev.c - program to generate functions of rotation about z
9 *
10 * The program takes as input the functions of t for z and r
11 * (the radius). If z is increasing, the normal points
12 * outward, inward for decreasing z. Negative radii are forbidden.
13 *
14 * 8/6/86
15 */
16
17 #include <stdio.h>
18
19 #define ZNAME "Z_" /* z function name */
20 #define RNAME "R_" /* r function name */
21
22 #define PI 3.14159265358979323846
23
24 #define FTINY 1e-9
25 /* orientation */
26 #define OUT 01
27 #define IN 02
28 #define UP 04
29 #define DOWN 010
30
31 double funvalue(), l_hermite(), argument();
32
33
34 main(argc, argv)
35 int argc;
36 char *argv[];
37 {
38 char stmp[256];
39 char *modname;
40 int smooth = 0;
41 double t, lastz, z, nextz, lastr, r, nextr;
42 double lastnz, lastnr, nz, nr, nextnz, nextnr;
43 int i, nseg;
44 int orient;
45
46 varset("PI", PI);
47 funset("hermite", 5, l_hermite);
48
49 if (argc < 6)
50 goto userror;
51
52 for (i = 6; i < argc; i++)
53 if (!strcmp(argv[i], "-e"))
54 scompile(NULL, argv[++i]);
55 else if (!strcmp(argv[i], "-f"))
56 fcompile(argv[++i]);
57 else if (!strcmp(argv[i], "-s"))
58 smooth = 1;
59 else
60 goto userror;
61
62 sprintf(stmp, "%s(t)=%s;", ZNAME, argv[3]);
63 scompile(NULL, stmp);
64 sprintf(stmp, "%s(t)=%s;", RNAME, argv[4]);
65 scompile(NULL, stmp);
66 nseg = atoi(argv[5]);
67 if (nseg <= 0)
68 goto userror;
69 modname = smooth ? "phong" : argv[1];
70
71 printhead(argc, argv);
72
73 lastnz = lastnr = 0.0;
74 t = 0.0;
75 lastz = funvalue(ZNAME, 1, &t);
76 lastr = funvalue(RNAME, 1, &t);
77 t = 1.0/nseg;
78 z = funvalue(ZNAME, 1, &t);
79 r = funvalue(RNAME, 1, &t);
80 computen(&nz, &nr, lastz, lastr, z, r);
81 for (i = 1; i <= nseg; i++) {
82 if (i < nseg) {
83 t = (double)(i+1)/nseg;
84 nextz = funvalue(ZNAME, 1, &t);
85 nextr = funvalue(RNAME, 1, &t);
86 computen(&nextnz, &nextnr, z, r, nextz, nextr);
87 } else
88 nextnz = nextnr = 0.0;
89 orient = 0;
90 if (z < lastz-FTINY)
91 orient |= DOWN;
92 else if (z > lastz+FTINY)
93 orient |= UP;
94 if (r < lastr-FTINY)
95 orient |= IN;
96 else if (r > lastr+FTINY)
97 orient |= OUT;
98 if (!orient)
99 goto endfor;
100 if (smooth) {
101 printf("\n%s texfunc phong\n", argv[1]);
102 printf("4 rev_dx rev_dy rev_dz rev.cal\n");
103 printf("0\n4\n");
104 if (orient&(UP|DOWN)) {
105 t = (nextnz - lastnz)/(z - lastz);
106 printf("\t%15.9g\t%15.9g\n",
107 t, lastnz - t*lastz);
108 } else
109 printf("\t0\t%d\n", orient&IN ? 1 : -1);
110 if (orient&(OUT|IN)) {
111 t = (nextnr - lastnr)/(r - lastr);
112 printf("\t%15.9g\t%15.9g\n",
113 t, lastnr - t*lastr);
114 } else
115 printf("\t0\t%d\n", orient&UP ? 1 : -1);
116 }
117 if (!(orient&(IN|OUT))) {
118 printf("\n%s %s %s.%d\n", modname,
119 orient&DOWN ? "tube" : "cylinder",
120 argv[2], i);
121 printf("0\n0\n7\n");
122 printf("\t0\t0\t%15.9g\n", lastz);
123 printf("\t0\t0\t%15.9g\n", z);
124 printf("\t%15.9g\n", r);
125 } else if (!(orient&(UP|DOWN))) {
126 printf("\n%s ring %s.%d\n", modname, argv[2], i);
127 printf("0\n0\n8\n");
128 printf("\t0\t0\t%15.9g\n", z);
129 printf("\t0\t0\t%15.9g\n", orient&IN ? 1.0 : -1.0);
130 printf("\t%15.9g\t%15.9g\n", lastr, r);
131 } else {
132 printf("\n%s %s %s.%d\n", modname,
133 orient&DOWN ? "cup" : "cone",
134 argv[2], i);
135 printf("0\n0\n8\n");
136 printf("\t0\t0\t%15.9g\n", lastz);
137 printf("\t0\t0\t%15.9g\n", z);
138 printf("\t%15.9g\t%15.9g\n", lastr, r);
139 }
140 endfor:
141 lastz = z; lastr = r;
142 z = nextz; r = nextr;
143 lastnz = nz; lastnr = nr;
144 nz = nextnz; nr = nextnr;
145 }
146 quit(0);
147
148 userror:
149 fprintf(stderr,
150 "Usage: %s material name z(t) r(t) nseg [-e expr] [-f file] [-s]\n",
151 argv[0]);
152 quit(1);
153 }
154
155
156 computen(nzp, nrp, z0, r0, z1, r1) /* compute normal */
157 double *nzp, *nrp, z0, r0, z1, r1;
158 {
159 extern double sqrt();
160 double dr, dz, len;
161
162 dz = r0 - r1; /* right angle vector */
163 dr = z1 - z0;
164 len = sqrt(dr*dr + dz*dz);
165 *nzp = dz/len;
166 *nrp = dr/len;
167 }
168
169
170 eputs(msg)
171 char *msg;
172 {
173 fputs(msg, stderr);
174 }
175
176
177 wputs(msg)
178 char *msg;
179 {
180 eputs(msg);
181 }
182
183
184 quit(code)
185 {
186 exit(code);
187 }
188
189
190 printhead(ac, av) /* print command header */
191 register int ac;
192 register char **av;
193 {
194 putchar('#');
195 while (ac--) {
196 putchar(' ');
197 fputs(*av++, stdout);
198 }
199 putchar('\n');
200 }
201
202
203 double
204 l_hermite()
205 {
206 double t;
207
208 t = argument(5);
209 return( argument(1)*((2.0*t-3.0)*t*t+1.0) +
210 argument(2)*(-2.0*t+3.0)*t*t +
211 argument(3)*((t-2.0)*t+1.0)*t +
212 argument(4)*(t-1.0)*t*t );
213 }