1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.38 |
static const char RCSid[] = "$Id$"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* rv2.c - command routines used in tracing a view. |
6 |
|
|
* |
7 |
greg |
2.38 |
* External symbols declared in rpaint.h |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
/* ==================================================================== |
11 |
|
|
* The Radiance Software License, Version 1.0 |
12 |
|
|
* |
13 |
|
|
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
14 |
|
|
* through Lawrence Berkeley National Laboratory. All rights reserved. |
15 |
|
|
* |
16 |
|
|
* Redistribution and use in source and binary forms, with or without |
17 |
|
|
* modification, are permitted provided that the following conditions |
18 |
|
|
* are met: |
19 |
|
|
* |
20 |
|
|
* 1. Redistributions of source code must retain the above copyright |
21 |
|
|
* notice, this list of conditions and the following disclaimer. |
22 |
|
|
* |
23 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
24 |
|
|
* notice, this list of conditions and the following disclaimer in |
25 |
|
|
* the documentation and/or other materials provided with the |
26 |
|
|
* distribution. |
27 |
|
|
* |
28 |
|
|
* 3. The end-user documentation included with the redistribution, |
29 |
|
|
* if any, must include the following acknowledgment: |
30 |
|
|
* "This product includes Radiance software |
31 |
|
|
* (http://radsite.lbl.gov/) |
32 |
|
|
* developed by the Lawrence Berkeley National Laboratory |
33 |
|
|
* (http://www.lbl.gov/)." |
34 |
|
|
* Alternately, this acknowledgment may appear in the software itself, |
35 |
|
|
* if and wherever such third-party acknowledgments normally appear. |
36 |
|
|
* |
37 |
|
|
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
38 |
|
|
* and "The Regents of the University of California" must |
39 |
|
|
* not be used to endorse or promote products derived from this |
40 |
|
|
* software without prior written permission. For written |
41 |
|
|
* permission, please contact [email protected]. |
42 |
|
|
* |
43 |
|
|
* 5. Products derived from this software may not be called "Radiance", |
44 |
|
|
* nor may "Radiance" appear in their name, without prior written |
45 |
|
|
* permission of Lawrence Berkeley National Laboratory. |
46 |
|
|
* |
47 |
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
48 |
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
49 |
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
50 |
|
|
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
51 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
52 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
53 |
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
54 |
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
55 |
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
56 |
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
57 |
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 |
|
|
* SUCH DAMAGE. |
59 |
|
|
* ==================================================================== |
60 |
|
|
* |
61 |
|
|
* This software consists of voluntary contributions made by many |
62 |
|
|
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
63 |
|
|
* information on Lawrence Berkeley National Laboratory, please see |
64 |
|
|
* <http://www.lbl.gov/>. |
65 |
greg |
1.1 |
*/ |
66 |
|
|
|
67 |
|
|
#include "ray.h" |
68 |
|
|
|
69 |
|
|
#include "otypes.h" |
70 |
|
|
|
71 |
|
|
#include "rpaint.h" |
72 |
|
|
|
73 |
greg |
2.38 |
#include <ctype.h> |
74 |
greg |
1.33 |
|
75 |
greg |
2.38 |
extern int psample; /* pixel sample size */ |
76 |
|
|
extern double maxdiff; /* max. sample difference */ |
77 |
greg |
1.1 |
|
78 |
greg |
2.4 |
#define CTRL(c) ((c)-'@') |
79 |
greg |
1.1 |
|
80 |
greg |
2.6 |
#ifdef SMLFLT |
81 |
|
|
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
82 |
|
|
#else |
83 |
|
|
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
84 |
|
|
#endif |
85 |
|
|
|
86 |
greg |
2.20 |
extern char rifname[128]; /* rad input file name */ |
87 |
greg |
2.18 |
|
88 |
greg |
1.1 |
extern char *progname; |
89 |
greg |
1.29 |
extern char *octname; |
90 |
greg |
1.1 |
|
91 |
|
|
|
92 |
greg |
2.38 |
void |
93 |
greg |
1.1 |
getframe(s) /* get a new frame */ |
94 |
|
|
char *s; |
95 |
|
|
{ |
96 |
greg |
1.12 |
if (getrect(s, &pframe) < 0) |
97 |
greg |
1.1 |
return; |
98 |
|
|
pdepth = 0; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
|
102 |
greg |
2.38 |
void |
103 |
greg |
1.12 |
getrepaint(s) /* get area and repaint */ |
104 |
|
|
char *s; |
105 |
|
|
{ |
106 |
|
|
RECT box; |
107 |
|
|
|
108 |
|
|
if (getrect(s, &box) < 0) |
109 |
|
|
return; |
110 |
greg |
1.14 |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box); |
111 |
greg |
1.12 |
} |
112 |
|
|
|
113 |
|
|
|
114 |
greg |
2.38 |
void |
115 |
greg |
1.1 |
getview(s) /* get/show view parameters */ |
116 |
|
|
char *s; |
117 |
|
|
{ |
118 |
|
|
FILE *fp; |
119 |
|
|
char buf[128]; |
120 |
greg |
1.10 |
char *fname; |
121 |
greg |
1.3 |
int change = 0; |
122 |
greg |
1.1 |
VIEW nv; |
123 |
|
|
|
124 |
greg |
2.9 |
while (isspace(*s)) |
125 |
|
|
s++; |
126 |
|
|
if (*s == '-') { /* command line parameters */ |
127 |
|
|
copystruct(&nv, &ourview); |
128 |
|
|
if (sscanview(&nv, s)) |
129 |
|
|
newview(&nv); |
130 |
|
|
else |
131 |
|
|
error(COMMAND, "bad view option(s)"); |
132 |
|
|
return; |
133 |
|
|
} |
134 |
greg |
1.1 |
if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ |
135 |
greg |
1.10 |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
136 |
greg |
1.1 |
(fp = fopen(fname, "a")) == NULL) { |
137 |
|
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
138 |
|
|
error(COMMAND, errmsg); |
139 |
|
|
return; |
140 |
|
|
} |
141 |
greg |
1.2 |
fputs(progname, fp); |
142 |
greg |
1.1 |
fprintview(&ourview, fp); |
143 |
greg |
1.19 |
fputs(sskip(s), fp); |
144 |
greg |
2.18 |
putc('\n', fp); |
145 |
greg |
1.1 |
fclose(fp); |
146 |
|
|
return; |
147 |
|
|
} |
148 |
|
|
sprintf(buf, "view type (%c): ", ourview.type); |
149 |
|
|
(*dev->comout)(buf); |
150 |
greg |
1.18 |
(*dev->comin)(buf, NULL); |
151 |
greg |
2.4 |
if (buf[0] == CTRL('C')) return; |
152 |
greg |
1.3 |
if (buf[0] && buf[0] != ourview.type) { |
153 |
greg |
1.1 |
nv.type = buf[0]; |
154 |
greg |
1.3 |
change++; |
155 |
|
|
} else |
156 |
greg |
1.1 |
nv.type = ourview.type; |
157 |
|
|
sprintf(buf, "view point (%.6g %.6g %.6g): ", |
158 |
|
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
159 |
|
|
(*dev->comout)(buf); |
160 |
greg |
1.18 |
(*dev->comin)(buf, NULL); |
161 |
greg |
2.4 |
if (buf[0] == CTRL('C')) return; |
162 |
greg |
2.6 |
if (sscanvec(buf, nv.vp)) |
163 |
greg |
1.3 |
change++; |
164 |
|
|
else |
165 |
greg |
1.1 |
VCOPY(nv.vp, ourview.vp); |
166 |
|
|
sprintf(buf, "view direction (%.6g %.6g %.6g): ", |
167 |
|
|
ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); |
168 |
|
|
(*dev->comout)(buf); |
169 |
greg |
1.18 |
(*dev->comin)(buf, NULL); |
170 |
greg |
2.4 |
if (buf[0] == CTRL('C')) return; |
171 |
greg |
2.6 |
if (sscanvec(buf, nv.vdir)) |
172 |
greg |
1.3 |
change++; |
173 |
|
|
else |
174 |
greg |
1.1 |
VCOPY(nv.vdir, ourview.vdir); |
175 |
|
|
sprintf(buf, "view up (%.6g %.6g %.6g): ", |
176 |
|
|
ourview.vup[0], ourview.vup[1], ourview.vup[2]); |
177 |
|
|
(*dev->comout)(buf); |
178 |
greg |
1.18 |
(*dev->comin)(buf, NULL); |
179 |
greg |
2.4 |
if (buf[0] == CTRL('C')) return; |
180 |
greg |
2.6 |
if (sscanvec(buf, nv.vup)) |
181 |
greg |
1.3 |
change++; |
182 |
|
|
else |
183 |
greg |
1.1 |
VCOPY(nv.vup, ourview.vup); |
184 |
|
|
sprintf(buf, "view horiz and vert size (%.6g %.6g): ", |
185 |
|
|
ourview.horiz, ourview.vert); |
186 |
|
|
(*dev->comout)(buf); |
187 |
greg |
1.18 |
(*dev->comin)(buf, NULL); |
188 |
greg |
2.4 |
if (buf[0] == CTRL('C')) return; |
189 |
greg |
1.3 |
if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2) |
190 |
|
|
change++; |
191 |
|
|
else { |
192 |
greg |
1.1 |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
193 |
|
|
} |
194 |
greg |
2.26 |
sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ", |
195 |
|
|
ourview.vfore, ourview.vaft); |
196 |
|
|
(*dev->comout)(buf); |
197 |
|
|
(*dev->comin)(buf, NULL); |
198 |
|
|
if (buf[0] == CTRL('C')) return; |
199 |
|
|
if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2) |
200 |
|
|
change++; |
201 |
|
|
else { |
202 |
|
|
nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; |
203 |
|
|
} |
204 |
greg |
1.14 |
sprintf(buf, "view shift and lift (%.6g %.6g): ", |
205 |
|
|
ourview.hoff, ourview.voff); |
206 |
greg |
1.1 |
(*dev->comout)(buf); |
207 |
greg |
1.18 |
(*dev->comin)(buf, NULL); |
208 |
greg |
2.4 |
if (buf[0] == CTRL('C')) return; |
209 |
greg |
1.14 |
if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2) |
210 |
greg |
1.3 |
change++; |
211 |
|
|
else { |
212 |
greg |
1.14 |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
213 |
greg |
1.1 |
} |
214 |
greg |
1.3 |
if (change) |
215 |
|
|
newview(&nv); |
216 |
greg |
1.1 |
} |
217 |
|
|
|
218 |
|
|
|
219 |
greg |
2.38 |
void |
220 |
greg |
1.1 |
lastview(s) /* return to a previous view */ |
221 |
|
|
char *s; |
222 |
|
|
{ |
223 |
|
|
char buf[128]; |
224 |
greg |
1.10 |
char *fname; |
225 |
greg |
1.1 |
int success; |
226 |
|
|
VIEW nv; |
227 |
|
|
|
228 |
|
|
if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ |
229 |
greg |
1.17 |
copystruct(&nv, &stdview); |
230 |
greg |
2.19 |
if ((fname = getpath(buf, "", R_OK)) == NULL || |
231 |
greg |
1.33 |
(success = viewfile(fname, &nv, NULL)) == -1) { |
232 |
greg |
1.1 |
sprintf(errmsg, "cannot open \"%s\"", buf); |
233 |
|
|
error(COMMAND, errmsg); |
234 |
|
|
return; |
235 |
|
|
} |
236 |
|
|
if (!success) |
237 |
|
|
error(COMMAND, "wrong file format"); |
238 |
|
|
else |
239 |
|
|
newview(&nv); |
240 |
|
|
return; |
241 |
|
|
} |
242 |
greg |
1.20 |
if (oldview.type == 0) { /* no old view! */ |
243 |
greg |
1.1 |
error(COMMAND, "no previous view"); |
244 |
|
|
return; |
245 |
|
|
} |
246 |
greg |
1.17 |
copystruct(&nv, &ourview); |
247 |
|
|
copystruct(&ourview, &oldview); |
248 |
|
|
copystruct(&oldview, &nv); |
249 |
greg |
1.1 |
newimage(); |
250 |
greg |
2.18 |
} |
251 |
|
|
|
252 |
|
|
|
253 |
greg |
2.38 |
void |
254 |
greg |
2.18 |
saveview(s) /* save view to rad file */ |
255 |
|
|
char *s; |
256 |
|
|
{ |
257 |
|
|
char view[64]; |
258 |
|
|
char *fname; |
259 |
|
|
FILE *fp; |
260 |
|
|
|
261 |
greg |
2.19 |
if (*atos(view, sizeof(view), s)) { |
262 |
|
|
if (isint(view)) { |
263 |
|
|
error(COMMAND, "cannot write view by number"); |
264 |
|
|
return; |
265 |
|
|
} |
266 |
greg |
2.18 |
s = sskip(s); |
267 |
greg |
2.19 |
} |
268 |
greg |
2.20 |
while (isspace(*s)) |
269 |
|
|
s++; |
270 |
|
|
if (*s) |
271 |
|
|
atos(rifname, sizeof(rifname), s); |
272 |
|
|
else if (rifname[0] == '\0') { |
273 |
greg |
2.18 |
error(COMMAND, "no previous rad file"); |
274 |
|
|
return; |
275 |
|
|
} |
276 |
|
|
if ((fname = getpath(rifname, NULL, 0)) == NULL || |
277 |
|
|
(fp = fopen(fname, "a")) == NULL) { |
278 |
|
|
sprintf(errmsg, "cannot open \"%s\"", rifname); |
279 |
|
|
error(COMMAND, errmsg); |
280 |
|
|
return; |
281 |
|
|
} |
282 |
|
|
fputs("view= ", fp); |
283 |
|
|
fputs(view, fp); |
284 |
|
|
fprintview(&ourview, fp); |
285 |
|
|
putc('\n', fp); |
286 |
|
|
fclose(fp); |
287 |
|
|
} |
288 |
|
|
|
289 |
|
|
|
290 |
greg |
2.38 |
void |
291 |
greg |
2.18 |
loadview(s) /* load view from rad file */ |
292 |
|
|
char *s; |
293 |
|
|
{ |
294 |
|
|
char buf[512]; |
295 |
|
|
char *fname; |
296 |
|
|
FILE *fp; |
297 |
|
|
VIEW nv; |
298 |
|
|
|
299 |
|
|
strcpy(buf, "rad -n -s -V -v "); |
300 |
|
|
if (sscanf(s, "%s", buf+strlen(buf)) == 1) |
301 |
|
|
s = sskip(s); |
302 |
|
|
else |
303 |
|
|
strcat(buf, "1"); |
304 |
greg |
2.20 |
if (*s) |
305 |
|
|
atos(rifname, sizeof(rifname), s); |
306 |
|
|
else if (rifname[0] == '\0') { |
307 |
greg |
2.18 |
error(COMMAND, "no previous rad file"); |
308 |
|
|
return; |
309 |
|
|
} |
310 |
greg |
2.19 |
if ((fname = getpath(rifname, "", R_OK)) == NULL) { |
311 |
greg |
2.18 |
sprintf(errmsg, "cannot access \"%s\"", rifname); |
312 |
|
|
error(COMMAND, errmsg); |
313 |
|
|
return; |
314 |
|
|
} |
315 |
|
|
sprintf(buf+strlen(buf), " %s", fname); |
316 |
|
|
if ((fp = popen(buf, "r")) == NULL) { |
317 |
|
|
error(COMMAND, "cannot run rad"); |
318 |
|
|
return; |
319 |
|
|
} |
320 |
|
|
buf[0] = '\0'; |
321 |
|
|
fgets(buf, sizeof(buf), fp); |
322 |
|
|
pclose(fp); |
323 |
|
|
copystruct(&nv, &stdview); |
324 |
|
|
if (!sscanview(&nv, buf)) { |
325 |
|
|
error(COMMAND, "rad error -- no such view?"); |
326 |
|
|
return; |
327 |
|
|
} |
328 |
|
|
newview(&nv); |
329 |
greg |
1.1 |
} |
330 |
|
|
|
331 |
|
|
|
332 |
greg |
2.38 |
void |
333 |
greg |
1.1 |
getaim(s) /* aim camera */ |
334 |
|
|
char *s; |
335 |
|
|
{ |
336 |
|
|
double zfact; |
337 |
|
|
VIEW nv; |
338 |
|
|
|
339 |
|
|
if (getinterest(s, 1, nv.vdir, &zfact) < 0) |
340 |
|
|
return; |
341 |
greg |
1.21 |
nv.type = ourview.type; |
342 |
greg |
1.1 |
VCOPY(nv.vp, ourview.vp); |
343 |
|
|
VCOPY(nv.vup, ourview.vup); |
344 |
greg |
2.28 |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
345 |
|
|
nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; |
346 |
greg |
1.14 |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
347 |
greg |
1.21 |
zoomview(&nv, zfact); |
348 |
greg |
1.1 |
newview(&nv); |
349 |
|
|
} |
350 |
|
|
|
351 |
|
|
|
352 |
greg |
2.38 |
void |
353 |
greg |
1.1 |
getmove(s) /* move camera */ |
354 |
|
|
char *s; |
355 |
|
|
{ |
356 |
|
|
FVECT vc; |
357 |
|
|
double mag; |
358 |
|
|
|
359 |
|
|
if (getinterest(s, 0, vc, &mag) < 0) |
360 |
|
|
return; |
361 |
greg |
1.4 |
moveview(0.0, 0.0, mag, vc); |
362 |
greg |
1.1 |
} |
363 |
|
|
|
364 |
|
|
|
365 |
greg |
2.38 |
void |
366 |
greg |
1.1 |
getrotate(s) /* rotate camera */ |
367 |
|
|
char *s; |
368 |
|
|
{ |
369 |
|
|
VIEW nv; |
370 |
|
|
FVECT v1; |
371 |
greg |
1.4 |
double angle, elev, zfact; |
372 |
greg |
1.1 |
|
373 |
greg |
1.4 |
elev = 0.0; zfact = 1.0; |
374 |
|
|
if (sscanf(s, "%lf %lf %lf", &angle, &elev, &zfact) < 1) { |
375 |
greg |
1.1 |
error(COMMAND, "missing angle"); |
376 |
|
|
return; |
377 |
|
|
} |
378 |
greg |
1.21 |
nv.type = ourview.type; |
379 |
greg |
1.1 |
VCOPY(nv.vp, ourview.vp); |
380 |
|
|
VCOPY(nv.vup, ourview.vup); |
381 |
greg |
1.14 |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
382 |
greg |
2.28 |
nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; |
383 |
greg |
1.1 |
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
384 |
|
|
if (elev != 0.0) { |
385 |
|
|
fcross(v1, nv.vdir, ourview.vup); |
386 |
|
|
normalize(v1); |
387 |
|
|
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
388 |
|
|
} |
389 |
greg |
1.21 |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
390 |
|
|
zoomview(&nv, zfact); |
391 |
greg |
1.1 |
newview(&nv); |
392 |
|
|
} |
393 |
|
|
|
394 |
|
|
|
395 |
greg |
2.38 |
void |
396 |
greg |
1.1 |
getpivot(s) /* pivot viewpoint */ |
397 |
|
|
register char *s; |
398 |
|
|
{ |
399 |
|
|
FVECT vc; |
400 |
greg |
1.4 |
double angle, elev, mag; |
401 |
greg |
1.1 |
|
402 |
greg |
1.4 |
elev = 0.0; |
403 |
|
|
if (sscanf(s, "%lf %lf", &angle, &elev) < 1) { |
404 |
greg |
1.1 |
error(COMMAND, "missing angle"); |
405 |
|
|
return; |
406 |
|
|
} |
407 |
greg |
2.33 |
if (getinterest(sskip2(s,2), 0, vc, &mag) < 0) |
408 |
greg |
1.1 |
return; |
409 |
greg |
1.4 |
moveview(angle, elev, mag, vc); |
410 |
greg |
1.1 |
} |
411 |
|
|
|
412 |
|
|
|
413 |
greg |
2.38 |
void |
414 |
greg |
1.1 |
getexposure(s) /* get new exposure */ |
415 |
|
|
char *s; |
416 |
|
|
{ |
417 |
|
|
char buf[128]; |
418 |
|
|
register char *cp; |
419 |
|
|
RECT r; |
420 |
|
|
int x, y; |
421 |
greg |
2.16 |
register PNODE *p = &ptrunk; |
422 |
|
|
int adapt = 0; |
423 |
|
|
double e = 1.0; |
424 |
greg |
2.25 |
|
425 |
greg |
1.1 |
for (cp = s; isspace(*cp); cp++) |
426 |
|
|
; |
427 |
greg |
2.16 |
if (*cp == '@') { |
428 |
|
|
adapt++; |
429 |
greg |
2.25 |
while (isspace(*++cp)) |
430 |
|
|
; |
431 |
greg |
2.16 |
} |
432 |
greg |
1.1 |
if (*cp == '\0') { /* normalize to point */ |
433 |
|
|
if (dev->getcur == NULL) |
434 |
|
|
return; |
435 |
|
|
(*dev->comout)("Pick point for exposure\n"); |
436 |
|
|
if ((*dev->getcur)(&x, &y) == ABORT) |
437 |
|
|
return; |
438 |
|
|
r.l = r.d = 0; |
439 |
greg |
1.14 |
r.r = hresolu; r.u = vresolu; |
440 |
greg |
1.1 |
p = findrect(x, y, &ptrunk, &r, -1); |
441 |
|
|
} else { |
442 |
|
|
if (*cp == '=') { /* absolute setting */ |
443 |
|
|
p = NULL; |
444 |
|
|
e = 1.0/exposure; |
445 |
|
|
for (cp++; isspace(*cp); cp++) |
446 |
|
|
; |
447 |
|
|
if (*cp == '\0') { /* interactive */ |
448 |
greg |
2.15 |
sprintf(buf, "exposure (%f): ", exposure); |
449 |
greg |
1.1 |
(*dev->comout)(buf); |
450 |
greg |
1.18 |
(*dev->comin)(buf, NULL); |
451 |
greg |
1.1 |
for (cp = buf; isspace(*cp); cp++) |
452 |
|
|
; |
453 |
|
|
if (*cp == '\0') |
454 |
|
|
return; |
455 |
|
|
} |
456 |
|
|
} |
457 |
|
|
if (*cp == '+' || *cp == '-') /* f-stops */ |
458 |
|
|
e *= pow(2.0, atof(cp)); |
459 |
|
|
else /* multiplier */ |
460 |
|
|
e *= atof(cp); |
461 |
|
|
} |
462 |
|
|
if (p != NULL) { /* relative setting */ |
463 |
greg |
2.14 |
if (bright(p->v) < 1e-15) { |
464 |
greg |
1.1 |
error(COMMAND, "cannot normalize to zero"); |
465 |
|
|
return; |
466 |
|
|
} |
467 |
greg |
2.16 |
if (adapt) |
468 |
|
|
e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure; |
469 |
|
|
else |
470 |
|
|
e *= 0.5 / bright(p->v); |
471 |
greg |
1.1 |
} |
472 |
|
|
if (e <= FTINY || fabs(1.0 - e) <= FTINY) |
473 |
|
|
return; |
474 |
|
|
scalepict(&ptrunk, e); |
475 |
|
|
exposure *= e; |
476 |
|
|
redraw(); |
477 |
|
|
} |
478 |
|
|
|
479 |
greg |
2.38 |
typedef union {int i; double d; COLOR C;} *MyUptr; |
480 |
greg |
1.1 |
|
481 |
greg |
2.38 |
int |
482 |
|
|
getparam(str, dsc, typ, p) /* get variable from user */ |
483 |
greg |
1.24 |
char *str, *dsc; |
484 |
|
|
int typ; |
485 |
greg |
2.38 |
void *p; |
486 |
greg |
1.24 |
{ |
487 |
greg |
2.38 |
register MyUptr ptr = (MyUptr)p; |
488 |
greg |
1.24 |
int i0; |
489 |
|
|
double d0, d1, d2; |
490 |
|
|
char buf[48]; |
491 |
|
|
|
492 |
|
|
switch (typ) { |
493 |
|
|
case 'i': /* integer */ |
494 |
|
|
if (sscanf(str, "%d", &i0) != 1) { |
495 |
|
|
(*dev->comout)(dsc); |
496 |
|
|
sprintf(buf, " (%d): ", ptr->i); |
497 |
|
|
(*dev->comout)(buf); |
498 |
|
|
(*dev->comin)(buf, NULL); |
499 |
|
|
if (sscanf(buf, "%d", &i0) != 1) |
500 |
greg |
1.31 |
return(0); |
501 |
greg |
1.24 |
} |
502 |
|
|
ptr->i = i0; |
503 |
greg |
1.31 |
return(1); |
504 |
greg |
1.24 |
case 'r': /* real */ |
505 |
|
|
if (sscanf(str, "%lf", &d0) != 1) { |
506 |
|
|
(*dev->comout)(dsc); |
507 |
|
|
sprintf(buf, " (%.6g): ", ptr->d); |
508 |
|
|
(*dev->comout)(buf); |
509 |
|
|
(*dev->comin)(buf, NULL); |
510 |
|
|
if (sscanf(buf, "%lf", &d0) != 1) |
511 |
greg |
1.31 |
return(0); |
512 |
greg |
1.24 |
} |
513 |
|
|
ptr->d = d0; |
514 |
greg |
1.31 |
return(1); |
515 |
greg |
1.24 |
case 'b': /* boolean */ |
516 |
|
|
if (sscanf(str, "%1s", buf) != 1) { |
517 |
|
|
(*dev->comout)(dsc); |
518 |
greg |
2.2 |
sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n'); |
519 |
greg |
1.24 |
(*dev->comout)(buf); |
520 |
|
|
(*dev->comin)(buf, NULL); |
521 |
greg |
1.25 |
if (buf[0] == '\0' || |
522 |
|
|
index("yY+1tTnN-0fF", buf[0]) == NULL) |
523 |
greg |
1.31 |
return(0); |
524 |
greg |
1.24 |
} |
525 |
greg |
1.25 |
ptr->i = index("yY+1tT", buf[0]) != NULL; |
526 |
greg |
1.31 |
return(1); |
527 |
greg |
1.24 |
case 'C': /* color */ |
528 |
|
|
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
529 |
|
|
(*dev->comout)(dsc); |
530 |
|
|
sprintf(buf, " (%.6g %.6g %.6g): ", |
531 |
|
|
colval(ptr->C,RED), |
532 |
|
|
colval(ptr->C,GRN), |
533 |
|
|
colval(ptr->C,BLU)); |
534 |
|
|
(*dev->comout)(buf); |
535 |
|
|
(*dev->comin)(buf, NULL); |
536 |
|
|
if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) |
537 |
greg |
1.31 |
return(0); |
538 |
greg |
1.24 |
} |
539 |
|
|
setcolor(ptr->C, d0, d1, d2); |
540 |
greg |
1.31 |
return(1); |
541 |
greg |
1.24 |
} |
542 |
|
|
} |
543 |
|
|
|
544 |
|
|
|
545 |
greg |
2.38 |
void |
546 |
greg |
1.1 |
setparam(s) /* get/set program parameter */ |
547 |
|
|
register char *s; |
548 |
|
|
{ |
549 |
greg |
1.24 |
char buf[128]; |
550 |
greg |
1.1 |
|
551 |
|
|
if (s[0] == '\0') { |
552 |
greg |
1.23 |
(*dev->comout)( |
553 |
greg |
2.34 |
"aa ab ad ar as av aw b dc dv dj ds dt i lr lw me ma mg ms ps pt sj st bv: "); |
554 |
greg |
1.18 |
(*dev->comin)(buf, NULL); |
555 |
greg |
1.1 |
s = buf; |
556 |
|
|
} |
557 |
|
|
switch (s[0]) { |
558 |
|
|
case 'l': /* limit */ |
559 |
|
|
switch (s[1]) { |
560 |
|
|
case 'w': /* weight */ |
561 |
greg |
2.38 |
getparam(s+2, "limit weight", 'r', |
562 |
|
|
(void *)&minweight); |
563 |
greg |
1.1 |
break; |
564 |
|
|
case 'r': /* reflection */ |
565 |
greg |
2.38 |
getparam(s+2, "limit reflection", 'i', |
566 |
|
|
(void *)&maxdepth); |
567 |
greg |
1.1 |
break; |
568 |
|
|
default: |
569 |
|
|
goto badparam; |
570 |
|
|
} |
571 |
|
|
break; |
572 |
greg |
1.5 |
case 'd': /* direct */ |
573 |
|
|
switch (s[1]) { |
574 |
|
|
case 'j': /* jitter */ |
575 |
greg |
2.38 |
getparam(s+2, "direct jitter", 'r', |
576 |
|
|
(void *)&dstrsrc); |
577 |
greg |
1.9 |
break; |
578 |
|
|
case 'c': /* certainty */ |
579 |
greg |
2.38 |
getparam(s+2, "direct certainty", 'r', |
580 |
|
|
(void *)&shadcert); |
581 |
greg |
1.5 |
break; |
582 |
greg |
1.8 |
case 't': /* threshold */ |
583 |
greg |
2.38 |
getparam(s+2, "direct threshold", 'r', |
584 |
|
|
(void *)&shadthresh); |
585 |
greg |
1.5 |
break; |
586 |
greg |
2.13 |
case 'v': /* visibility */ |
587 |
greg |
2.38 |
getparam(s+2, "direct visibility", 'b', |
588 |
|
|
(void *)&directvis); |
589 |
greg |
1.30 |
break; |
590 |
|
|
case 's': /* sampling */ |
591 |
greg |
2.38 |
getparam(s+2, "direct sampling", 'r', |
592 |
|
|
(void *)&srcsizerat); |
593 |
greg |
1.23 |
break; |
594 |
greg |
1.5 |
default: |
595 |
greg |
1.1 |
goto badparam; |
596 |
|
|
} |
597 |
greg |
1.23 |
break; |
598 |
greg |
2.27 |
case 'b': /* back faces or black and white */ |
599 |
|
|
switch (s[1]) { |
600 |
|
|
case 'v': /* back face visibility */ |
601 |
greg |
2.38 |
getparam(s+2, "back face visibility", 'b', |
602 |
|
|
(void *)&backvis); |
603 |
greg |
2.27 |
break; |
604 |
|
|
case '\0': /* black and white */ |
605 |
greg |
2.29 |
case ' ': |
606 |
greg |
2.27 |
case 'y': case 'Y': case 't': case 'T': case '1': case '+': |
607 |
|
|
case 'n': case 'N': case 'f': case 'F': case '0': case '-': |
608 |
greg |
2.38 |
getparam(s+1, "black and white", 'b', |
609 |
|
|
(void *)&greyscale); |
610 |
greg |
2.27 |
break; |
611 |
|
|
default: |
612 |
|
|
goto badparam; |
613 |
|
|
} |
614 |
greg |
1.23 |
break; |
615 |
|
|
case 'i': /* irradiance */ |
616 |
greg |
2.38 |
getparam(s+1, "irradiance", 'b', |
617 |
|
|
(void *)&do_irrad); |
618 |
greg |
1.1 |
break; |
619 |
|
|
case 'a': /* ambient */ |
620 |
|
|
switch (s[1]) { |
621 |
|
|
case 'v': /* value */ |
622 |
greg |
2.38 |
getparam(s+2, "ambient value", 'C', |
623 |
|
|
(void *)ambval); |
624 |
greg |
2.34 |
break; |
625 |
|
|
case 'w': /* weight */ |
626 |
greg |
2.38 |
getparam(s+2, "ambient value weight", 'i', |
627 |
|
|
(void *)&ambvwt); |
628 |
greg |
1.1 |
break; |
629 |
|
|
case 'a': /* accuracy */ |
630 |
greg |
2.38 |
if (getparam(s+2, "ambient accuracy", 'r', |
631 |
|
|
(void *)&ambacc)) |
632 |
greg |
2.17 |
setambacc(ambacc); |
633 |
greg |
1.1 |
break; |
634 |
|
|
case 'd': /* divisions */ |
635 |
greg |
2.38 |
getparam(s+2, "ambient divisions", 'i', |
636 |
|
|
(void *)&ambdiv); |
637 |
greg |
1.1 |
break; |
638 |
|
|
case 's': /* samples */ |
639 |
greg |
2.38 |
getparam(s+2, "ambient super-samples", 'i', |
640 |
|
|
(void *)&ambssamp); |
641 |
greg |
1.1 |
break; |
642 |
|
|
case 'b': /* bounces */ |
643 |
greg |
2.38 |
getparam(s+2, "ambient bounces", 'i', |
644 |
|
|
(void *)&ambounce); |
645 |
greg |
1.1 |
break; |
646 |
|
|
case 'r': |
647 |
greg |
2.38 |
if (getparam(s+2, "ambient resolution", 'i', |
648 |
|
|
(void *)&ambres)) |
649 |
greg |
2.8 |
setambres(ambres); |
650 |
greg |
2.32 |
break; |
651 |
|
|
default: |
652 |
|
|
goto badparam; |
653 |
|
|
} |
654 |
|
|
break; |
655 |
|
|
case 'm': /* medium */ |
656 |
|
|
switch (s[1]) { |
657 |
|
|
case 'e': /* extinction coefficient */ |
658 |
|
|
getparam(s+2, "extinction coefficient", 'C', |
659 |
greg |
2.38 |
(void *)cextinction); |
660 |
greg |
2.32 |
break; |
661 |
|
|
case 'a': /* scattering albedo */ |
662 |
greg |
2.35 |
getparam(s+2, "scattering albedo", 'C', |
663 |
greg |
2.38 |
(void *)salbedo); |
664 |
greg |
2.32 |
break; |
665 |
|
|
case 'g': /* scattering eccentricity */ |
666 |
greg |
2.38 |
getparam(s+2, "scattering eccentricity", 'r', |
667 |
|
|
(void *)&seccg); |
668 |
greg |
2.32 |
break; |
669 |
|
|
case 's': /* sampling distance */ |
670 |
|
|
getparam(s+2, "mist sampling distance", 'r', |
671 |
greg |
2.38 |
(void *)&ssampdist); |
672 |
greg |
1.1 |
break; |
673 |
|
|
default: |
674 |
|
|
goto badparam; |
675 |
|
|
} |
676 |
|
|
break; |
677 |
greg |
2.5 |
case 'p': /* pixel */ |
678 |
greg |
1.1 |
switch (s[1]) { |
679 |
greg |
2.5 |
case 's': /* sample */ |
680 |
greg |
2.38 |
if (getparam(s+2, "pixel sample", 'i', |
681 |
|
|
(void *)&psample)) |
682 |
greg |
1.31 |
pdepth = 0; |
683 |
greg |
1.1 |
break; |
684 |
greg |
1.8 |
case 't': /* threshold */ |
685 |
greg |
2.38 |
if (getparam(s+2, "pixel threshold", 'r', |
686 |
|
|
(void *)&maxdiff)) |
687 |
greg |
1.31 |
pdepth = 0; |
688 |
greg |
2.5 |
break; |
689 |
|
|
default: |
690 |
|
|
goto badparam; |
691 |
|
|
} |
692 |
|
|
break; |
693 |
|
|
case 's': /* specular */ |
694 |
|
|
switch (s[1]) { |
695 |
|
|
case 'j': /* jitter */ |
696 |
greg |
2.38 |
getparam(s+2, "specular jitter", 'r', |
697 |
|
|
(void *)&specjitter); |
698 |
greg |
2.5 |
break; |
699 |
|
|
case 't': /* threshold */ |
700 |
greg |
2.38 |
getparam(s+2, "specular threshold", 'r', |
701 |
|
|
(void *)&specthresh); |
702 |
greg |
1.1 |
break; |
703 |
|
|
default: |
704 |
|
|
goto badparam; |
705 |
|
|
} |
706 |
|
|
break; |
707 |
|
|
case '\0': /* nothing */ |
708 |
|
|
break; |
709 |
|
|
default:; |
710 |
|
|
badparam: |
711 |
greg |
1.26 |
*sskip(s) = '\0'; |
712 |
greg |
1.1 |
sprintf(errmsg, "%s: unknown variable", s); |
713 |
|
|
error(COMMAND, errmsg); |
714 |
|
|
break; |
715 |
|
|
} |
716 |
|
|
} |
717 |
|
|
|
718 |
|
|
|
719 |
greg |
2.38 |
void |
720 |
greg |
1.1 |
traceray(s) /* trace a single ray */ |
721 |
|
|
char *s; |
722 |
|
|
{ |
723 |
|
|
char buf[128]; |
724 |
|
|
int x, y; |
725 |
greg |
2.37 |
OBJREC *ino; |
726 |
greg |
1.1 |
RAY thisray; |
727 |
|
|
|
728 |
greg |
2.26 |
thisray.rmax = 0.0; |
729 |
|
|
|
730 |
greg |
2.6 |
if (!sscanvec(s, thisray.rorg) || |
731 |
greg |
2.33 |
!sscanvec(sskip2(s,3), thisray.rdir)) { |
732 |
greg |
1.1 |
|
733 |
|
|
if (dev->getcur == NULL) |
734 |
|
|
return; |
735 |
|
|
(*dev->comout)("Pick ray\n"); |
736 |
|
|
if ((*dev->getcur)(&x, &y) == ABORT) |
737 |
|
|
return; |
738 |
|
|
|
739 |
greg |
2.26 |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
740 |
|
|
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
741 |
greg |
1.21 |
error(COMMAND, "not on image"); |
742 |
|
|
return; |
743 |
|
|
} |
744 |
|
|
|
745 |
greg |
1.1 |
} else if (normalize(thisray.rdir) == 0.0) { |
746 |
|
|
error(COMMAND, "zero ray direction"); |
747 |
|
|
return; |
748 |
|
|
} |
749 |
|
|
|
750 |
|
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
751 |
|
|
|
752 |
|
|
rayvalue(&thisray); |
753 |
|
|
|
754 |
|
|
if (thisray.ro == NULL) |
755 |
|
|
(*dev->comout)("ray hit nothing"); |
756 |
|
|
else { |
757 |
greg |
2.23 |
sprintf(buf, "ray hit %s%s %s \"%s\"", |
758 |
|
|
thisray.rod < 0.0 ? "back of " : "", |
759 |
greg |
2.22 |
thisray.ro->omod == OVOID ? VOIDID : |
760 |
|
|
objptr(thisray.ro->omod)->oname, |
761 |
greg |
1.1 |
ofun[thisray.ro->otype].funame, |
762 |
|
|
thisray.ro->oname); |
763 |
greg |
2.37 |
if ((ino = objptr(thisray.robj)) != thisray.ro) |
764 |
|
|
sprintf(buf+strlen(buf), " in %s \"%s\"", |
765 |
|
|
ofun[ino->otype].funame, ino->oname); |
766 |
greg |
1.1 |
(*dev->comout)(buf); |
767 |
greg |
1.18 |
(*dev->comin)(buf, NULL); |
768 |
greg |
1.1 |
if (thisray.rot >= FHUGE) |
769 |
|
|
(*dev->comout)("at infinity"); |
770 |
|
|
else { |
771 |
greg |
2.30 |
sprintf(buf, "at (%.6g %.6g %.6g) (%.6g)", |
772 |
|
|
thisray.rop[0], thisray.rop[1], |
773 |
|
|
thisray.rop[2], thisray.rt); |
774 |
greg |
1.1 |
(*dev->comout)(buf); |
775 |
|
|
} |
776 |
greg |
1.18 |
(*dev->comin)(buf, NULL); |
777 |
greg |
2.38 |
sprintf(buf, "value (%.5g %.5g %.5g) (%.3gL)", |
778 |
greg |
1.1 |
colval(thisray.rcol,RED), |
779 |
|
|
colval(thisray.rcol,GRN), |
780 |
greg |
1.32 |
colval(thisray.rcol,BLU), |
781 |
|
|
luminance(thisray.rcol)); |
782 |
greg |
1.1 |
(*dev->comout)(buf); |
783 |
|
|
} |
784 |
greg |
1.18 |
(*dev->comin)(buf, NULL); |
785 |
greg |
1.1 |
} |
786 |
|
|
|
787 |
|
|
|
788 |
greg |
2.38 |
void |
789 |
greg |
1.1 |
writepict(s) /* write the picture to a file */ |
790 |
|
|
char *s; |
791 |
|
|
{ |
792 |
|
|
static char buf[128]; |
793 |
greg |
1.10 |
char *fname; |
794 |
greg |
1.1 |
FILE *fp; |
795 |
|
|
COLR *scanline; |
796 |
|
|
int y; |
797 |
|
|
|
798 |
greg |
2.20 |
while (isspace(*s)) |
799 |
|
|
s++; |
800 |
|
|
if (*s) |
801 |
|
|
atos(buf, sizeof(buf), s); |
802 |
|
|
else if (buf[0] == '\0') { |
803 |
greg |
1.1 |
error(COMMAND, "no file"); |
804 |
|
|
return; |
805 |
|
|
} |
806 |
greg |
1.10 |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
807 |
greg |
1.1 |
(fp = fopen(fname, "w")) == NULL) { |
808 |
|
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
809 |
|
|
error(COMMAND, errmsg); |
810 |
|
|
return; |
811 |
|
|
} |
812 |
greg |
2.12 |
#ifdef MSDOS |
813 |
|
|
setmode(fileno(fp), O_BINARY); |
814 |
|
|
#endif |
815 |
greg |
1.1 |
(*dev->comout)("writing \""); |
816 |
|
|
(*dev->comout)(fname); |
817 |
|
|
(*dev->comout)("\"...\n"); |
818 |
|
|
/* write header */ |
819 |
greg |
2.24 |
newheader("RADIANCE", fp); |
820 |
greg |
1.1 |
fputs(progname, fp); |
821 |
|
|
fprintview(&ourview, fp); |
822 |
greg |
1.29 |
if (octname != NULL) |
823 |
|
|
fprintf(fp, " %s\n", octname); |
824 |
|
|
else |
825 |
|
|
putc('\n', fp); |
826 |
greg |
1.28 |
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
827 |
greg |
2.38 |
fputnow(fp); |
828 |
greg |
1.1 |
if (exposure != 1.0) |
829 |
greg |
1.13 |
fputexpos(exposure, fp); |
830 |
greg |
1.15 |
if (dev->pixaspect != 1.0) |
831 |
|
|
fputaspect(dev->pixaspect, fp); |
832 |
greg |
1.22 |
fputformat(COLRFMT, fp); |
833 |
greg |
1.11 |
putc('\n', fp); |
834 |
greg |
1.33 |
fprtresolu(hresolu, vresolu, fp); |
835 |
greg |
1.1 |
|
836 |
greg |
1.14 |
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
837 |
greg |
1.27 |
if (scanline == NULL) { |
838 |
|
|
error(COMMAND, "not enough memory!"); |
839 |
|
|
fclose(fp); |
840 |
|
|
unlink(fname); |
841 |
|
|
return; |
842 |
|
|
} |
843 |
greg |
1.14 |
for (y = vresolu-1; y >= 0; y--) { |
844 |
|
|
getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); |
845 |
|
|
if (fwritecolrs(scanline, hresolu, fp) < 0) |
846 |
greg |
1.1 |
break; |
847 |
|
|
} |
848 |
greg |
2.38 |
free((void *)scanline); |
849 |
greg |
1.1 |
if (fclose(fp) < 0) |
850 |
|
|
error(COMMAND, "write error"); |
851 |
|
|
} |