ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genrev.c
Revision: 2.11
Committed: Fri Jan 12 00:50:17 2018 UTC (6 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.10: +3 -1 lines
Log Message:
Added missing esupport settings for constant expression reduction

File Contents

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