1 |
– |
/* Copyright (c) 1987 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 |
|
* rv2.c - command routines used in tracing a view. |
6 |
|
* |
7 |
< |
* 3/24/87 |
7 |
> |
* External symbols declared in rpaint.h |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include "ray.h" |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
< |
#include "octree.h" |
12 |
> |
#include <ctype.h> |
13 |
> |
#include <string.h> |
14 |
|
|
15 |
+ |
#include "platform.h" |
16 |
+ |
#include "rtprocess.h" /* win_popen() */ |
17 |
+ |
#include "paths.h" |
18 |
+ |
#include "ray.h" |
19 |
+ |
#include "source.h" |
20 |
+ |
#include "ambient.h" |
21 |
|
#include "otypes.h" |
18 |
– |
|
22 |
|
#include "rpaint.h" |
23 |
|
|
24 |
< |
#include <ctype.h> |
24 |
> |
extern int psample; /* pixel sample size */ |
25 |
> |
extern double maxdiff; /* max. sample difference */ |
26 |
|
|
27 |
< |
#define CTRL(c) ('c'-'@') |
27 |
> |
#define CTRL(c) ((c)-'@') |
28 |
|
|
29 |
+ |
#ifdef SMLFLT |
30 |
+ |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
31 |
+ |
#else |
32 |
+ |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
33 |
+ |
#endif |
34 |
+ |
|
35 |
+ |
extern char rifname[128]; /* rad input file name */ |
36 |
+ |
|
37 |
|
extern char *progname; |
38 |
+ |
extern char *octname; |
39 |
|
|
40 |
|
|
41 |
< |
getframe(s) /* get a new frame */ |
42 |
< |
char *s; |
41 |
> |
void |
42 |
> |
getframe( /* get a new frame */ |
43 |
> |
char *s |
44 |
> |
) |
45 |
|
{ |
46 |
|
if (getrect(s, &pframe) < 0) |
47 |
|
return; |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
< |
getrepaint(s) /* get area and repaint */ |
53 |
< |
char *s; |
52 |
> |
void |
53 |
> |
getrepaint( /* get area and repaint */ |
54 |
> |
char *s |
55 |
> |
) |
56 |
|
{ |
57 |
|
RECT box; |
58 |
|
|
59 |
|
if (getrect(s, &box) < 0) |
60 |
|
return; |
61 |
< |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box); |
61 |
> |
paintrect(&ptrunk, &box); |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
< |
getview(s) /* get/show view parameters */ |
66 |
< |
char *s; |
65 |
> |
void |
66 |
> |
getview( /* get/show/save view parameters */ |
67 |
> |
char *s |
68 |
> |
) |
69 |
|
{ |
70 |
|
FILE *fp; |
71 |
|
char buf[128]; |
72 |
|
char *fname; |
73 |
|
int change = 0; |
74 |
< |
VIEW nv; |
74 |
> |
VIEW nv = ourview; |
75 |
|
|
76 |
< |
if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ |
76 |
> |
while (isspace(*s)) |
77 |
> |
s++; |
78 |
> |
if (*s == '-') { /* command line parameters */ |
79 |
> |
if (sscanview(&nv, s)) |
80 |
> |
newview(&nv); |
81 |
> |
else |
82 |
> |
error(COMMAND, "bad view option(s)"); |
83 |
> |
return; |
84 |
> |
} |
85 |
> |
if (nextword(buf, sizeof(buf), s) != NULL) { /* write to a file */ |
86 |
|
if ((fname = getpath(buf, NULL, 0)) == NULL || |
87 |
|
(fp = fopen(fname, "a")) == NULL) { |
88 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
92 |
|
fputs(progname, fp); |
93 |
|
fprintview(&ourview, fp); |
94 |
|
fputs(sskip(s), fp); |
95 |
< |
fputs("\n", fp); |
95 |
> |
putc('\n', fp); |
96 |
|
fclose(fp); |
97 |
|
return; |
98 |
|
} |
99 |
|
sprintf(buf, "view type (%c): ", ourview.type); |
100 |
|
(*dev->comout)(buf); |
101 |
|
(*dev->comin)(buf, NULL); |
102 |
< |
if (buf[0] == CTRL(C)) return; |
102 |
> |
if (buf[0] == CTRL('C')) return; |
103 |
|
if (buf[0] && buf[0] != ourview.type) { |
104 |
|
nv.type = buf[0]; |
105 |
|
change++; |
106 |
< |
} else |
79 |
< |
nv.type = ourview.type; |
106 |
> |
} |
107 |
|
sprintf(buf, "view point (%.6g %.6g %.6g): ", |
108 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
109 |
|
(*dev->comout)(buf); |
110 |
|
(*dev->comin)(buf, NULL); |
111 |
< |
if (buf[0] == CTRL(C)) return; |
112 |
< |
if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3) |
111 |
> |
if (buf[0] == CTRL('C')) return; |
112 |
> |
if (sscanvec(buf, nv.vp)) |
113 |
|
change++; |
87 |
– |
else |
88 |
– |
VCOPY(nv.vp, ourview.vp); |
114 |
|
sprintf(buf, "view direction (%.6g %.6g %.6g): ", |
115 |
< |
ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); |
115 |
> |
ourview.vdir[0]*ourview.vdist, |
116 |
> |
ourview.vdir[1]*ourview.vdist, |
117 |
> |
ourview.vdir[2]*ourview.vdist); |
118 |
|
(*dev->comout)(buf); |
119 |
|
(*dev->comin)(buf, NULL); |
120 |
< |
if (buf[0] == CTRL(C)) return; |
121 |
< |
if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3) |
120 |
> |
if (buf[0] == CTRL('C')) return; |
121 |
> |
if (sscanvec(buf, nv.vdir)) { |
122 |
> |
nv.vdist = 1.; |
123 |
|
change++; |
124 |
< |
else |
97 |
< |
VCOPY(nv.vdir, ourview.vdir); |
124 |
> |
} |
125 |
|
sprintf(buf, "view up (%.6g %.6g %.6g): ", |
126 |
|
ourview.vup[0], ourview.vup[1], ourview.vup[2]); |
127 |
|
(*dev->comout)(buf); |
128 |
|
(*dev->comin)(buf, NULL); |
129 |
< |
if (buf[0] == CTRL(C)) return; |
130 |
< |
if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3) |
129 |
> |
if (buf[0] == CTRL('C')) return; |
130 |
> |
if (sscanvec(buf, nv.vup)) |
131 |
|
change++; |
105 |
– |
else |
106 |
– |
VCOPY(nv.vup, ourview.vup); |
132 |
|
sprintf(buf, "view horiz and vert size (%.6g %.6g): ", |
133 |
|
ourview.horiz, ourview.vert); |
134 |
|
(*dev->comout)(buf); |
135 |
|
(*dev->comin)(buf, NULL); |
136 |
< |
if (buf[0] == CTRL(C)) return; |
136 |
> |
if (buf[0] == CTRL('C')) return; |
137 |
|
if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2) |
138 |
|
change++; |
139 |
< |
else { |
140 |
< |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
141 |
< |
} |
139 |
> |
sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ", |
140 |
> |
ourview.vfore, ourview.vaft); |
141 |
> |
(*dev->comout)(buf); |
142 |
> |
(*dev->comin)(buf, NULL); |
143 |
> |
if (buf[0] == CTRL('C')) return; |
144 |
> |
if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2) |
145 |
> |
change++; |
146 |
|
sprintf(buf, "view shift and lift (%.6g %.6g): ", |
147 |
|
ourview.hoff, ourview.voff); |
148 |
|
(*dev->comout)(buf); |
149 |
|
(*dev->comin)(buf, NULL); |
150 |
< |
if (buf[0] == CTRL(C)) return; |
150 |
> |
if (buf[0] == CTRL('C')) return; |
151 |
|
if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2) |
152 |
|
change++; |
124 |
– |
else { |
125 |
– |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
126 |
– |
} |
153 |
|
if (change) |
154 |
|
newview(&nv); |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
< |
lastview(s) /* return to a previous view */ |
159 |
< |
char *s; |
158 |
> |
void |
159 |
> |
lastview( /* return to a previous view */ |
160 |
> |
char *s |
161 |
> |
) |
162 |
|
{ |
163 |
|
char buf[128]; |
164 |
|
char *fname; |
165 |
|
int success; |
166 |
|
VIEW nv; |
167 |
< |
|
168 |
< |
if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ |
169 |
< |
copystruct(&nv, &stdview); |
170 |
< |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
171 |
< |
(success = viewfile(fname, &nv, 0, 0)) == -1) { |
167 |
> |
/* get parameters from a file */ |
168 |
> |
if (nextword(buf, sizeof(buf), s) != NULL) { |
169 |
> |
nv = stdview; |
170 |
> |
if ((fname = getpath(buf, "", R_OK)) == NULL || |
171 |
> |
(success = viewfile(fname, &nv, NULL)) == -1) { |
172 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
173 |
|
error(COMMAND, errmsg); |
174 |
|
return; |
183 |
|
error(COMMAND, "no previous view"); |
184 |
|
return; |
185 |
|
} |
186 |
< |
copystruct(&nv, &ourview); |
187 |
< |
copystruct(&ourview, &oldview); |
188 |
< |
copystruct(&oldview, &nv); |
189 |
< |
newimage(); |
186 |
> |
nv = ourview; |
187 |
> |
ourview = oldview; |
188 |
> |
oldview = nv; |
189 |
> |
newimage(NULL); |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
< |
getaim(s) /* aim camera */ |
194 |
< |
char *s; |
193 |
> |
void |
194 |
> |
saveview( /* save view to rad file */ |
195 |
> |
char *s |
196 |
> |
) |
197 |
|
{ |
198 |
< |
extern double tan(), atan(); |
199 |
< |
double zfact; |
198 |
> |
char view[64]; |
199 |
> |
char *fname; |
200 |
> |
FILE *fp; |
201 |
> |
|
202 |
> |
if (*atos(view, sizeof(view), s)) { |
203 |
> |
if (isint(view)) { |
204 |
> |
error(COMMAND, "cannot write view by number"); |
205 |
> |
return; |
206 |
> |
} |
207 |
> |
s = sskip(s); |
208 |
> |
} |
209 |
> |
if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) { |
210 |
> |
error(COMMAND, "no previous rad file"); |
211 |
> |
return; |
212 |
> |
} |
213 |
> |
if ((fname = getpath(rifname, NULL, 0)) == NULL || |
214 |
> |
(fp = fopen(fname, "a")) == NULL) { |
215 |
> |
sprintf(errmsg, "cannot open \"%s\"", rifname); |
216 |
> |
error(COMMAND, errmsg); |
217 |
> |
return; |
218 |
> |
} |
219 |
> |
fputs("view= ", fp); |
220 |
> |
fputs(view, fp); |
221 |
> |
fprintview(&ourview, fp); |
222 |
> |
putc('\n', fp); |
223 |
> |
fclose(fp); |
224 |
> |
} |
225 |
> |
|
226 |
> |
|
227 |
> |
void |
228 |
> |
loadview( /* load view from rad file */ |
229 |
> |
char *s |
230 |
> |
) |
231 |
> |
{ |
232 |
> |
char buf[512]; |
233 |
> |
char *fname; |
234 |
> |
FILE *fp; |
235 |
|
VIEW nv; |
236 |
|
|
237 |
+ |
strcpy(buf, "rad -n -s -V -v "); |
238 |
+ |
if (sscanf(s, "%s", buf+strlen(buf)) == 1) |
239 |
+ |
s = sskip(s); |
240 |
+ |
else |
241 |
+ |
strcat(buf, "1"); |
242 |
+ |
if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) { |
243 |
+ |
error(COMMAND, "no previous rad file"); |
244 |
+ |
return; |
245 |
+ |
} |
246 |
+ |
if ((fname = getpath(rifname, "", R_OK)) == NULL) { |
247 |
+ |
sprintf(errmsg, "cannot access \"%s\"", rifname); |
248 |
+ |
error(COMMAND, errmsg); |
249 |
+ |
return; |
250 |
+ |
} |
251 |
+ |
sprintf(buf+strlen(buf), " %s", fname); |
252 |
+ |
if ((fp = popen(buf, "r")) == NULL) { |
253 |
+ |
error(COMMAND, "cannot run rad"); |
254 |
+ |
return; |
255 |
+ |
} |
256 |
+ |
buf[0] = '\0'; |
257 |
+ |
fgets(buf, sizeof(buf), fp); |
258 |
+ |
pclose(fp); |
259 |
+ |
nv = stdview; |
260 |
+ |
if (!sscanview(&nv, buf)) { |
261 |
+ |
error(COMMAND, "rad error -- no such view?"); |
262 |
+ |
return; |
263 |
+ |
} |
264 |
+ |
newview(&nv); |
265 |
+ |
} |
266 |
+ |
|
267 |
+ |
|
268 |
+ |
void |
269 |
+ |
getaim( /* aim camera */ |
270 |
+ |
char *s |
271 |
+ |
) |
272 |
+ |
{ |
273 |
+ |
VIEW nv = ourview; |
274 |
+ |
double zfact; |
275 |
+ |
|
276 |
|
if (getinterest(s, 1, nv.vdir, &zfact) < 0) |
277 |
|
return; |
174 |
– |
nv.type = ourview.type; |
175 |
– |
VCOPY(nv.vp, ourview.vp); |
176 |
– |
VCOPY(nv.vup, ourview.vup); |
177 |
– |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
178 |
– |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
278 |
|
zoomview(&nv, zfact); |
279 |
|
newview(&nv); |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
getmove(s) /* move camera */ |
284 |
< |
char *s; |
283 |
> |
void |
284 |
> |
getfocus( /* set focus distance */ |
285 |
> |
char *s |
286 |
> |
) |
287 |
|
{ |
288 |
+ |
char buf[64]; |
289 |
+ |
double dist; |
290 |
+ |
|
291 |
+ |
if (sscanf(s, "%lf", &dist) < 1) { |
292 |
+ |
int x, y; |
293 |
+ |
RAY thisray; |
294 |
+ |
if (dev->getcur == NULL) |
295 |
+ |
return; |
296 |
+ |
(*dev->comout)("Pick focus point\n"); |
297 |
+ |
if ((*dev->getcur)(&x, &y) == ABORT) |
298 |
+ |
return; |
299 |
+ |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
300 |
+ |
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
301 |
+ |
error(COMMAND, "not on image"); |
302 |
+ |
return; |
303 |
+ |
} |
304 |
+ |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
305 |
+ |
if (!localhit(&thisray, &thescene)) { |
306 |
+ |
error(COMMAND, "not a local object"); |
307 |
+ |
return; |
308 |
+ |
} |
309 |
+ |
dist = thisray.rot; |
310 |
+ |
} else if (dist <= .0) { |
311 |
+ |
error(COMMAND, "focus distance must be positive"); |
312 |
+ |
return; |
313 |
+ |
} |
314 |
+ |
ourview.vdist = dist; |
315 |
+ |
sprintf(buf, "Focus distance set to %f\n", dist); |
316 |
+ |
(*dev->comout)(buf); |
317 |
+ |
} |
318 |
+ |
|
319 |
+ |
|
320 |
+ |
void |
321 |
+ |
getmove( /* move camera */ |
322 |
+ |
char *s |
323 |
+ |
) |
324 |
+ |
{ |
325 |
|
FVECT vc; |
326 |
|
double mag; |
327 |
|
|
331 |
|
} |
332 |
|
|
333 |
|
|
334 |
< |
getrotate(s) /* rotate camera */ |
335 |
< |
char *s; |
334 |
> |
void |
335 |
> |
getrotate( /* rotate camera */ |
336 |
> |
char *s |
337 |
> |
) |
338 |
|
{ |
339 |
< |
extern double normalize(), tan(), atan(); |
200 |
< |
VIEW nv; |
339 |
> |
VIEW nv = ourview; |
340 |
|
FVECT v1; |
341 |
|
double angle, elev, zfact; |
342 |
|
|
345 |
|
error(COMMAND, "missing angle"); |
346 |
|
return; |
347 |
|
} |
209 |
– |
nv.type = ourview.type; |
210 |
– |
VCOPY(nv.vp, ourview.vp); |
211 |
– |
VCOPY(nv.vup, ourview.vup); |
212 |
– |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
348 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
349 |
|
if (elev != 0.0) { |
350 |
|
fcross(v1, nv.vdir, ourview.vup); |
351 |
|
normalize(v1); |
352 |
|
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
353 |
|
} |
219 |
– |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
354 |
|
zoomview(&nv, zfact); |
355 |
|
newview(&nv); |
356 |
|
} |
357 |
|
|
358 |
|
|
359 |
< |
getpivot(s) /* pivot viewpoint */ |
360 |
< |
register char *s; |
359 |
> |
void |
360 |
> |
getpivot( /* pivot viewpoint */ |
361 |
> |
char *s |
362 |
> |
) |
363 |
|
{ |
364 |
|
FVECT vc; |
365 |
|
double angle, elev, mag; |
369 |
|
error(COMMAND, "missing angle"); |
370 |
|
return; |
371 |
|
} |
372 |
< |
if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0) |
372 |
> |
if (getinterest(sskip2(s,2), 0, vc, &mag) < 0) |
373 |
|
return; |
374 |
|
moveview(angle, elev, mag, vc); |
375 |
|
} |
376 |
|
|
377 |
|
|
378 |
< |
getexposure(s) /* get new exposure */ |
379 |
< |
char *s; |
378 |
> |
void |
379 |
> |
getexposure( /* get new exposure */ |
380 |
> |
char *s |
381 |
> |
) |
382 |
|
{ |
245 |
– |
double atof(), pow(), fabs(); |
383 |
|
char buf[128]; |
384 |
< |
register char *cp; |
248 |
< |
register PNODE *p; |
249 |
< |
RECT r; |
384 |
> |
char *cp; |
385 |
|
int x, y; |
386 |
< |
double e; |
386 |
> |
PNODE *p = &ptrunk; |
387 |
> |
int adapt = 0; |
388 |
> |
double e = 1.0; |
389 |
|
|
390 |
|
for (cp = s; isspace(*cp); cp++) |
391 |
|
; |
392 |
+ |
if (*cp == '@') { |
393 |
+ |
adapt++; |
394 |
+ |
while (isspace(*++cp)) |
395 |
+ |
; |
396 |
+ |
} |
397 |
|
if (*cp == '\0') { /* normalize to point */ |
398 |
|
if (dev->getcur == NULL) |
399 |
|
return; |
400 |
|
(*dev->comout)("Pick point for exposure\n"); |
401 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
402 |
|
return; |
403 |
< |
r.l = r.d = 0; |
262 |
< |
r.r = hresolu; r.u = vresolu; |
263 |
< |
p = findrect(x, y, &ptrunk, &r, -1); |
264 |
< |
e = 1.0; |
403 |
> |
p = findrect(x, y, &ptrunk, -1); |
404 |
|
} else { |
405 |
|
if (*cp == '=') { /* absolute setting */ |
406 |
|
p = NULL; |
408 |
|
for (cp++; isspace(*cp); cp++) |
409 |
|
; |
410 |
|
if (*cp == '\0') { /* interactive */ |
411 |
< |
sprintf(buf, "exposure (%lf): ", exposure); |
411 |
> |
sprintf(buf, "exposure (%f): ", exposure); |
412 |
|
(*dev->comout)(buf); |
413 |
|
(*dev->comin)(buf, NULL); |
414 |
|
for (cp = buf; isspace(*cp); cp++) |
416 |
|
if (*cp == '\0') |
417 |
|
return; |
418 |
|
} |
280 |
– |
} else { /* normalize to average */ |
281 |
– |
p = &ptrunk; |
282 |
– |
e = 1.0; |
419 |
|
} |
420 |
|
if (*cp == '+' || *cp == '-') /* f-stops */ |
421 |
|
e *= pow(2.0, atof(cp)); |
423 |
|
e *= atof(cp); |
424 |
|
} |
425 |
|
if (p != NULL) { /* relative setting */ |
426 |
< |
if (bright(p->v) <= FTINY) { |
426 |
> |
compavg(p); |
427 |
> |
if (bright(p->v) < 1e-15) { |
428 |
|
error(COMMAND, "cannot normalize to zero"); |
429 |
|
return; |
430 |
|
} |
431 |
< |
e *= 0.5 / bright(p->v); |
431 |
> |
if (adapt) |
432 |
> |
e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure; |
433 |
> |
else |
434 |
> |
e *= 0.5 / bright(p->v); |
435 |
|
} |
436 |
|
if (e <= FTINY || fabs(1.0 - e) <= FTINY) |
437 |
|
return; |
440 |
|
redraw(); |
441 |
|
} |
442 |
|
|
443 |
+ |
typedef union {int i; double d; COLOR C;} *MyUptr; |
444 |
+ |
#define FEQ(x,y) (fabs((x)-(y)) <= FTINY) |
445 |
|
|
446 |
< |
setparam(s) /* get/set program parameter */ |
447 |
< |
register char *s; |
446 |
> |
int |
447 |
> |
getparam( /* get variable from user */ |
448 |
> |
char *str, |
449 |
> |
char *dsc, |
450 |
> |
int typ, |
451 |
> |
void *p |
452 |
> |
) |
453 |
|
{ |
454 |
< |
extern int psample; |
308 |
< |
extern double maxdiff; |
309 |
< |
extern double minweight; |
310 |
< |
extern int maxdepth; |
311 |
< |
extern double dstrsrc; |
312 |
< |
extern double shadthresh; |
313 |
< |
extern double shadcert; |
314 |
< |
extern COLOR ambval; |
315 |
< |
extern double ambacc; |
316 |
< |
extern double minarad; |
317 |
< |
extern int ambres; |
318 |
< |
extern int ambdiv; |
319 |
< |
extern int ambssamp; |
320 |
< |
extern int ambounce; |
321 |
< |
extern int directinvis; |
322 |
< |
extern int do_irrad; |
454 |
> |
MyUptr ptr = (MyUptr)p; |
455 |
|
int i0; |
456 |
|
double d0, d1, d2; |
457 |
< |
char buf[128], ans[4]; |
457 |
> |
char buf[48]; |
458 |
> |
|
459 |
> |
switch (typ) { |
460 |
> |
case 'i': /* integer */ |
461 |
> |
if (sscanf(str, "%d", &i0) != 1) { |
462 |
> |
(*dev->comout)(dsc); |
463 |
> |
sprintf(buf, " (%d): ", ptr->i); |
464 |
> |
(*dev->comout)(buf); |
465 |
> |
(*dev->comin)(buf, NULL); |
466 |
> |
if (sscanf(buf, "%d", &i0) != 1) |
467 |
> |
return(0); |
468 |
> |
} |
469 |
> |
if (ptr->i == i0) |
470 |
> |
return(0); |
471 |
> |
ptr->i = i0; |
472 |
> |
break; |
473 |
> |
case 'r': /* real */ |
474 |
> |
if (sscanf(str, "%lf", &d0) != 1) { |
475 |
> |
(*dev->comout)(dsc); |
476 |
> |
sprintf(buf, " (%.6g): ", ptr->d); |
477 |
> |
(*dev->comout)(buf); |
478 |
> |
(*dev->comin)(buf, NULL); |
479 |
> |
if (sscanf(buf, "%lf", &d0) != 1) |
480 |
> |
return(0); |
481 |
> |
} |
482 |
> |
if (FEQ(ptr->d, d0)) |
483 |
> |
return(0); |
484 |
> |
ptr->d = d0; |
485 |
> |
break; |
486 |
> |
case 'b': /* boolean */ |
487 |
> |
if (sscanf(str, "%1s", buf) != 1) { |
488 |
> |
(*dev->comout)(dsc); |
489 |
> |
sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n'); |
490 |
> |
(*dev->comout)(buf); |
491 |
> |
(*dev->comin)(buf, NULL); |
492 |
> |
if (buf[0] == '\0') |
493 |
> |
return(0); |
494 |
> |
} |
495 |
> |
if (strchr("yY+1tTnN-0fF", buf[0]) == NULL) |
496 |
> |
return(0); |
497 |
> |
i0 = strchr("yY+1tT", buf[0]) != NULL; |
498 |
> |
if (ptr->i == i0) |
499 |
> |
return(0); |
500 |
> |
ptr->i = i0; |
501 |
> |
break; |
502 |
> |
case 'C': /* color */ |
503 |
> |
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
504 |
> |
(*dev->comout)(dsc); |
505 |
> |
sprintf(buf, " (%.6g %.6g %.6g): ", |
506 |
> |
colval(ptr->C,RED), |
507 |
> |
colval(ptr->C,GRN), |
508 |
> |
colval(ptr->C,BLU)); |
509 |
> |
(*dev->comout)(buf); |
510 |
> |
(*dev->comin)(buf, NULL); |
511 |
> |
if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) |
512 |
> |
return(0); |
513 |
> |
} |
514 |
> |
if (FEQ(colval(ptr->C,RED), d0) && |
515 |
> |
FEQ(colval(ptr->C,GRN), d1) && |
516 |
> |
FEQ(colval(ptr->C,BLU), d2)) |
517 |
> |
return(0); |
518 |
> |
setcolor(ptr->C, d0, d1, d2); |
519 |
> |
break; |
520 |
> |
default: |
521 |
> |
return(0); /* shouldn't happen */ |
522 |
> |
} |
523 |
> |
newparam++; |
524 |
> |
return(1); |
525 |
> |
} |
526 |
> |
|
527 |
> |
|
528 |
> |
void |
529 |
> |
setparam( /* get/set program parameter */ |
530 |
> |
char *s |
531 |
> |
) |
532 |
> |
{ |
533 |
> |
int prev_newp = newparam; |
534 |
> |
char buf[128]; |
535 |
|
|
536 |
|
if (s[0] == '\0') { |
537 |
|
(*dev->comout)( |
538 |
< |
"aa ab ad ar as av b dc dj di dt i lr lw sp st: "); |
538 |
> |
"aa ab ad ar as av aw b bv dc dv dj ds dt i lr lw me ma mg ms ps pt ss st u: "); |
539 |
|
(*dev->comin)(buf, NULL); |
540 |
|
s = buf; |
541 |
|
} |
542 |
|
switch (s[0]) { |
543 |
+ |
case 'u': /* uncorrelated sampling */ |
544 |
+ |
getparam(s+1, "uncorrelated sampling", 'b', |
545 |
+ |
(void *)&rand_samp); |
546 |
+ |
break; |
547 |
|
case 'l': /* limit */ |
548 |
|
switch (s[1]) { |
549 |
|
case 'w': /* weight */ |
550 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
551 |
< |
sprintf(buf, "limit weight (%.6g): ", |
339 |
< |
minweight); |
340 |
< |
(*dev->comout)(buf); |
341 |
< |
(*dev->comin)(buf, NULL); |
342 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
343 |
< |
break; |
344 |
< |
} |
345 |
< |
minweight = d0; |
550 |
> |
getparam(s+2, "limit weight", 'r', |
551 |
> |
(void *)&minweight); |
552 |
|
break; |
553 |
|
case 'r': /* reflection */ |
554 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
555 |
< |
sprintf(buf, "limit reflection (%d): ", |
350 |
< |
maxdepth); |
351 |
< |
(*dev->comout)(buf); |
352 |
< |
(*dev->comin)(buf, NULL); |
353 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
354 |
< |
break; |
355 |
< |
} |
356 |
< |
maxdepth = i0; |
554 |
> |
getparam(s+2, "limit reflection", 'i', |
555 |
> |
(void *)&maxdepth); |
556 |
|
break; |
557 |
|
default: |
558 |
|
goto badparam; |
561 |
|
case 'd': /* direct */ |
562 |
|
switch (s[1]) { |
563 |
|
case 'j': /* jitter */ |
564 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
565 |
< |
sprintf(buf, "direct jitter (%.6g): ", |
367 |
< |
dstrsrc); |
368 |
< |
(*dev->comout)(buf); |
369 |
< |
(*dev->comin)(buf, NULL); |
370 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
371 |
< |
break; |
372 |
< |
} |
373 |
< |
dstrsrc = d0; |
564 |
> |
getparam(s+2, "direct jitter", 'r', |
565 |
> |
(void *)&dstrsrc); |
566 |
|
break; |
567 |
|
case 'c': /* certainty */ |
568 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
569 |
< |
sprintf(buf, "direct certainty (%.6g): ", |
378 |
< |
shadcert); |
379 |
< |
(*dev->comout)(buf); |
380 |
< |
(*dev->comin)(buf, NULL); |
381 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
382 |
< |
break; |
383 |
< |
} |
384 |
< |
shadcert = d0; |
568 |
> |
getparam(s+2, "direct certainty", 'r', |
569 |
> |
(void *)&shadcert); |
570 |
|
break; |
571 |
|
case 't': /* threshold */ |
572 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
573 |
< |
sprintf(buf, "direct threshold (%.6g): ", |
389 |
< |
shadthresh); |
390 |
< |
(*dev->comout)(buf); |
391 |
< |
(*dev->comin)(buf, NULL); |
392 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
393 |
< |
break; |
394 |
< |
} |
395 |
< |
shadthresh = d0; |
572 |
> |
getparam(s+2, "direct threshold", 'r', |
573 |
> |
(void *)&shadthresh); |
574 |
|
break; |
575 |
< |
case 'i': /* invisibility */ |
576 |
< |
if (sscanf(s+2, "%1s", ans) != 1) { |
577 |
< |
sprintf(buf, "direct invisibility (%c): ", |
400 |
< |
directinvis ? 'y' : 'n'); |
401 |
< |
(*dev->comout)(buf); |
402 |
< |
(*dev->comin)(buf, NULL); |
403 |
< |
if (sscanf(buf, "%1s", ans) != 1) |
404 |
< |
break; |
405 |
< |
} |
406 |
< |
directinvis = tolower(ans[0]) == 'y'; |
575 |
> |
case 'v': /* visibility */ |
576 |
> |
getparam(s+2, "direct visibility", 'b', |
577 |
> |
(void *)&directvis); |
578 |
|
break; |
579 |
+ |
case 's': /* sampling */ |
580 |
+ |
getparam(s+2, "direct sampling", 'r', |
581 |
+ |
(void *)&srcsizerat); |
582 |
+ |
break; |
583 |
|
default: |
584 |
|
goto badparam; |
585 |
|
} |
586 |
|
break; |
587 |
< |
case 'b': /* black and white */ |
588 |
< |
if (sscanf(s+1, "%1s", ans) != 1) { |
589 |
< |
sprintf(buf, "black and white (%c): ", |
590 |
< |
greyscale ? 'y' : 'n'); |
591 |
< |
(*dev->comout)(buf); |
592 |
< |
(*dev->comin)(buf, NULL); |
593 |
< |
if (sscanf(buf, "%1s", ans) != 1) |
594 |
< |
break; |
587 |
> |
case 'b': /* back faces or black and white */ |
588 |
> |
switch (s[1]) { |
589 |
> |
case 'v': /* back face visibility */ |
590 |
> |
getparam(s+2, "back face visibility", 'b', |
591 |
> |
(void *)&backvis); |
592 |
> |
break; |
593 |
> |
case '\0': /* black and white */ |
594 |
> |
case ' ': |
595 |
> |
case 'y': case 'Y': case 't': case 'T': case '1': case '+': |
596 |
> |
case 'n': case 'N': case 'f': case 'F': case '0': case '-': |
597 |
> |
getparam(s+1, "black and white", 'b', |
598 |
> |
(void *)&greyscale); |
599 |
> |
newparam = prev_newp; |
600 |
> |
break; |
601 |
> |
default: |
602 |
> |
goto badparam; |
603 |
|
} |
421 |
– |
greyscale = tolower(ans[0]) == 'y'; |
604 |
|
break; |
605 |
|
case 'i': /* irradiance */ |
606 |
< |
if (sscanf(s+1, "%1s", ans) != 1) { |
607 |
< |
sprintf(buf, "irradiance (%c): ", |
426 |
< |
do_irrad ? 'y' : 'n'); |
427 |
< |
(*dev->comout)(buf); |
428 |
< |
(*dev->comin)(buf, NULL); |
429 |
< |
if (sscanf(buf, "%1s", ans) != 1) |
430 |
< |
break; |
431 |
< |
} |
432 |
< |
do_irrad = tolower(ans[0]) == 'y'; |
606 |
> |
getparam(s+1, "irradiance", 'b', |
607 |
> |
(void *)&do_irrad); |
608 |
|
break; |
609 |
|
case 'a': /* ambient */ |
610 |
|
switch (s[1]) { |
611 |
|
case 'v': /* value */ |
612 |
< |
if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
613 |
< |
sprintf(buf, |
439 |
< |
"ambient value (%.6g %.6g %.6g): ", |
440 |
< |
colval(ambval,RED), |
441 |
< |
colval(ambval,GRN), |
442 |
< |
colval(ambval,BLU)); |
443 |
< |
(*dev->comout)(buf); |
444 |
< |
(*dev->comin)(buf, NULL); |
445 |
< |
if (sscanf(buf, "%lf %lf %lf", |
446 |
< |
&d0, &d1, &d2) != 3) |
447 |
< |
break; |
448 |
< |
} |
449 |
< |
setcolor(ambval, d0, d1, d2); |
612 |
> |
getparam(s+2, "ambient value", 'C', |
613 |
> |
(void *)ambval); |
614 |
|
break; |
615 |
+ |
case 'w': /* weight */ |
616 |
+ |
getparam(s+2, "ambient value weight", 'i', |
617 |
+ |
(void *)&ambvwt); |
618 |
+ |
break; |
619 |
|
case 'a': /* accuracy */ |
620 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
621 |
< |
sprintf(buf, "ambient accuracy (%.6g): ", |
622 |
< |
ambacc); |
455 |
< |
(*dev->comout)(buf); |
456 |
< |
(*dev->comin)(buf, NULL); |
457 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
458 |
< |
break; |
459 |
< |
} |
460 |
< |
ambacc = d0; |
620 |
> |
if (getparam(s+2, "ambient accuracy", 'r', |
621 |
> |
(void *)&ambacc)) |
622 |
> |
setambacc(ambacc); |
623 |
|
break; |
624 |
|
case 'd': /* divisions */ |
625 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
626 |
< |
sprintf(buf, "ambient divisions (%d): ", |
465 |
< |
ambdiv); |
466 |
< |
(*dev->comout)(buf); |
467 |
< |
(*dev->comin)(buf, NULL); |
468 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
469 |
< |
break; |
470 |
< |
} |
471 |
< |
ambdiv = i0; |
625 |
> |
getparam(s+2, "ambient divisions", 'i', |
626 |
> |
(void *)&ambdiv); |
627 |
|
break; |
628 |
|
case 's': /* samples */ |
629 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
630 |
< |
sprintf(buf, "ambient super-samples (%d): ", |
476 |
< |
ambssamp); |
477 |
< |
(*dev->comout)(buf); |
478 |
< |
(*dev->comin)(buf, NULL); |
479 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
480 |
< |
break; |
481 |
< |
} |
482 |
< |
ambssamp = i0; |
629 |
> |
getparam(s+2, "ambient super-samples", 'i', |
630 |
> |
(void *)&ambssamp); |
631 |
|
break; |
632 |
|
case 'b': /* bounces */ |
633 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
634 |
< |
sprintf(buf, "ambient bounces (%d): ", |
487 |
< |
ambounce); |
488 |
< |
(*dev->comout)(buf); |
489 |
< |
(*dev->comin)(buf, NULL); |
490 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
491 |
< |
break; |
492 |
< |
} |
493 |
< |
ambounce = i0; |
633 |
> |
getparam(s+2, "ambient bounces", 'i', |
634 |
> |
(void *)&ambounce); |
635 |
|
break; |
636 |
|
case 'r': |
637 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
638 |
< |
sprintf(buf, "ambient resolution (%d): ", |
639 |
< |
ambres); |
499 |
< |
(*dev->comout)(buf); |
500 |
< |
(*dev->comin)(buf, NULL); |
501 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
502 |
< |
break; |
503 |
< |
} |
504 |
< |
ambres = i0; |
505 |
< |
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
637 |
> |
if (getparam(s+2, "ambient resolution", 'i', |
638 |
> |
(void *)&ambres)) |
639 |
> |
setambres(ambres); |
640 |
|
break; |
641 |
|
default: |
642 |
|
goto badparam; |
643 |
|
} |
644 |
|
break; |
645 |
< |
case 's': /* sample */ |
645 |
> |
case 'm': /* medium */ |
646 |
|
switch (s[1]) { |
647 |
< |
case 'p': /* pixel */ |
648 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
649 |
< |
sprintf(buf, "sample pixel (%d): ", psample); |
516 |
< |
(*dev->comout)(buf); |
517 |
< |
(*dev->comin)(buf, NULL); |
518 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
519 |
< |
break; |
520 |
< |
} |
521 |
< |
psample = i0; |
522 |
< |
pdepth = 0; |
647 |
> |
case 'e': /* extinction coefficient */ |
648 |
> |
getparam(s+2, "extinction coefficient", 'C', |
649 |
> |
(void *)cextinction); |
650 |
|
break; |
651 |
+ |
case 'a': /* scattering albedo */ |
652 |
+ |
getparam(s+2, "scattering albedo", 'C', |
653 |
+ |
(void *)salbedo); |
654 |
+ |
break; |
655 |
+ |
case 'g': /* scattering eccentricity */ |
656 |
+ |
getparam(s+2, "scattering eccentricity", 'r', |
657 |
+ |
(void *)&seccg); |
658 |
+ |
break; |
659 |
+ |
case 's': /* sampling distance */ |
660 |
+ |
getparam(s+2, "mist sampling distance", 'r', |
661 |
+ |
(void *)&ssampdist); |
662 |
+ |
break; |
663 |
+ |
default: |
664 |
+ |
goto badparam; |
665 |
+ |
} |
666 |
+ |
break; |
667 |
+ |
case 'p': /* pixel */ |
668 |
+ |
switch (s[1]) { |
669 |
+ |
case 's': /* sample */ |
670 |
+ |
if (getparam(s+2, "pixel sample", 'i', |
671 |
+ |
(void *)&psample)) |
672 |
+ |
pdepth = 0; |
673 |
+ |
break; |
674 |
|
case 't': /* threshold */ |
675 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
676 |
< |
sprintf(buf, "sample threshold (%.6g): ", |
677 |
< |
maxdiff); |
528 |
< |
(*dev->comout)(buf); |
529 |
< |
(*dev->comin)(buf, NULL); |
530 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
531 |
< |
break; |
532 |
< |
} |
533 |
< |
maxdiff = d0; |
534 |
< |
pdepth = 0; |
675 |
> |
if (getparam(s+2, "pixel threshold", 'r', |
676 |
> |
(void *)&maxdiff)) |
677 |
> |
pdepth = 0; |
678 |
|
break; |
679 |
|
default: |
680 |
|
goto badparam; |
681 |
|
} |
682 |
+ |
newparam = prev_newp; |
683 |
|
break; |
684 |
+ |
case 's': /* specular */ |
685 |
+ |
switch (s[1]) { |
686 |
+ |
case 's': /* sampling */ |
687 |
+ |
getparam(s+2, "specular sampling", 'r', |
688 |
+ |
(void *)&specjitter); |
689 |
+ |
break; |
690 |
+ |
case 't': /* threshold */ |
691 |
+ |
getparam(s+2, "specular threshold", 'r', |
692 |
+ |
(void *)&specthresh); |
693 |
+ |
break; |
694 |
+ |
default: |
695 |
+ |
goto badparam; |
696 |
+ |
} |
697 |
+ |
break; |
698 |
|
case '\0': /* nothing */ |
699 |
|
break; |
700 |
|
default:; |
701 |
|
badparam: |
702 |
+ |
*sskip(s) = '\0'; |
703 |
|
sprintf(errmsg, "%s: unknown variable", s); |
704 |
|
error(COMMAND, errmsg); |
705 |
|
break; |
707 |
|
} |
708 |
|
|
709 |
|
|
710 |
< |
traceray(s) /* trace a single ray */ |
711 |
< |
char *s; |
710 |
> |
void |
711 |
> |
traceray( /* trace a single ray */ |
712 |
> |
char *s |
713 |
> |
) |
714 |
|
{ |
715 |
< |
char buf[128]; |
716 |
< |
int x, y; |
556 |
< |
RAY thisray; |
715 |
> |
RAY thisray; |
716 |
> |
char buf[512]; |
717 |
|
|
718 |
< |
if (sscanf(s, "%lf %lf %lf %lf %lf %lf", |
559 |
< |
&thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2], |
560 |
< |
&thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) { |
718 |
> |
thisray.rmax = 0.0; |
719 |
|
|
720 |
+ |
if (!sscanvec(s, thisray.rorg) || |
721 |
+ |
!sscanvec(sskip2(s,3), thisray.rdir)) { |
722 |
+ |
int x, y; |
723 |
+ |
|
724 |
|
if (dev->getcur == NULL) |
725 |
|
return; |
726 |
|
(*dev->comout)("Pick ray\n"); |
727 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
728 |
|
return; |
729 |
|
|
730 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
731 |
< |
(x+.5)/hresolu, (y+.5)/vresolu) < 0) { |
730 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
731 |
> |
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
732 |
|
error(COMMAND, "not on image"); |
733 |
|
return; |
734 |
|
} |
738 |
|
return; |
739 |
|
} |
740 |
|
|
741 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
580 |
< |
|
581 |
< |
rayvalue(&thisray); |
741 |
> |
ray_trace(&thisray); |
742 |
|
|
743 |
|
if (thisray.ro == NULL) |
744 |
|
(*dev->comout)("ray hit nothing"); |
745 |
|
else { |
746 |
< |
sprintf(buf, "ray hit %s %s \"%s\"", |
747 |
< |
objptr(thisray.ro->omod)->oname, |
746 |
> |
OBJREC *mat = NULL; |
747 |
> |
OBJREC *mod = NULL; |
748 |
> |
char matspec[256]; |
749 |
> |
OBJREC *ino; |
750 |
> |
|
751 |
> |
matspec[0] = '\0'; |
752 |
> |
if (thisray.ro->omod != OVOID) { |
753 |
> |
mod = objptr(thisray.ro->omod); |
754 |
> |
mat = findmaterial(mod); |
755 |
> |
} |
756 |
> |
if (thisray.rod < 0.0) |
757 |
> |
strcpy(matspec, "back of "); |
758 |
> |
if (mod != NULL) { |
759 |
> |
strcat(matspec, mod->oname); |
760 |
> |
if (mat != mod && mat != NULL) |
761 |
> |
sprintf(matspec+strlen(matspec), |
762 |
> |
" (%s)", mat->oname); |
763 |
> |
} else |
764 |
> |
strcat(matspec, VOIDID); |
765 |
> |
sprintf(buf, "ray hit %s %s \"%s\"", matspec, |
766 |
|
ofun[thisray.ro->otype].funame, |
767 |
|
thisray.ro->oname); |
768 |
+ |
if ((ino = objptr(thisray.robj)) != thisray.ro) |
769 |
+ |
sprintf(buf+strlen(buf), " in %s \"%s\"", |
770 |
+ |
ofun[ino->otype].funame, ino->oname); |
771 |
|
(*dev->comout)(buf); |
772 |
|
(*dev->comin)(buf, NULL); |
773 |
|
if (thisray.rot >= FHUGE) |
774 |
|
(*dev->comout)("at infinity"); |
775 |
|
else { |
776 |
< |
sprintf(buf, "at (%.6g %.6g %.6g)", thisray.rop[0], |
777 |
< |
thisray.rop[1], thisray.rop[2]); |
776 |
> |
sprintf(buf, "at (%.6g %.6g %.6g) (%.6g)", |
777 |
> |
thisray.rop[0], thisray.rop[1], |
778 |
> |
thisray.rop[2], thisray.rt); |
779 |
|
(*dev->comout)(buf); |
780 |
|
} |
781 |
|
(*dev->comin)(buf, NULL); |
782 |
< |
sprintf(buf, "with value (%.6g %.6g %.6g)", |
782 |
> |
sprintf(buf, "value (%.5g %.5g %.5g) (%.3gL)", |
783 |
|
colval(thisray.rcol,RED), |
784 |
|
colval(thisray.rcol,GRN), |
785 |
< |
colval(thisray.rcol,BLU)); |
785 |
> |
colval(thisray.rcol,BLU), |
786 |
> |
luminance(thisray.rcol)); |
787 |
|
(*dev->comout)(buf); |
788 |
|
} |
789 |
|
(*dev->comin)(buf, NULL); |
790 |
|
} |
791 |
|
|
792 |
|
|
793 |
< |
writepict(s) /* write the picture to a file */ |
794 |
< |
char *s; |
793 |
> |
void |
794 |
> |
writepict( /* write the picture to a file */ |
795 |
> |
char *s |
796 |
> |
) |
797 |
|
{ |
798 |
|
static char buf[128]; |
799 |
|
char *fname; |
800 |
|
FILE *fp; |
801 |
|
COLR *scanline; |
802 |
|
int y; |
803 |
< |
|
804 |
< |
if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') { |
803 |
> |
/* XXX relies on words.c 2.11 behavior */ |
804 |
> |
if (nextword(buf, sizeof(buf), s) == NULL && !buf[0]) { |
805 |
|
error(COMMAND, "no file"); |
806 |
|
return; |
807 |
|
} |
811 |
|
error(COMMAND, errmsg); |
812 |
|
return; |
813 |
|
} |
814 |
+ |
SET_FILE_BINARY(fp); |
815 |
|
(*dev->comout)("writing \""); |
816 |
|
(*dev->comout)(fname); |
817 |
|
(*dev->comout)("\"...\n"); |
818 |
|
/* write header */ |
819 |
+ |
newheader("RADIANCE", fp); |
820 |
|
fputs(progname, fp); |
821 |
|
fprintview(&ourview, fp); |
822 |
< |
putc('\n', fp); |
822 |
> |
if (octname != NULL) |
823 |
> |
fprintf(fp, " %s\n", octname); |
824 |
> |
else |
825 |
> |
putc('\n', fp); |
826 |
> |
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
827 |
> |
fputnow(fp); |
828 |
|
if (exposure != 1.0) |
829 |
|
fputexpos(exposure, fp); |
830 |
|
if (dev->pixaspect != 1.0) |
831 |
|
fputaspect(dev->pixaspect, fp); |
832 |
|
fputformat(COLRFMT, fp); |
833 |
|
putc('\n', fp); |
834 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp); |
834 |
> |
fprtresolu(hresolu, vresolu, fp); |
835 |
|
|
836 |
|
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
837 |
< |
if (scanline == NULL) |
838 |
< |
error(SYSTEM, "out of memory in writepict"); |
837 |
> |
if (scanline == NULL) { |
838 |
> |
error(COMMAND, "not enough memory!"); |
839 |
> |
fclose(fp); |
840 |
> |
unlink(fname); |
841 |
> |
return; |
842 |
> |
} |
843 |
|
for (y = vresolu-1; y >= 0; y--) { |
844 |
|
getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); |
845 |
|
if (fwritecolrs(scanline, hresolu, fp) < 0) |
846 |
|
break; |
847 |
|
} |
848 |
+ |
free((void *)scanline); |
849 |
|
if (fclose(fp) < 0) |
850 |
|
error(COMMAND, "write error"); |
654 |
– |
free((char *)scanline); |
851 |
|
} |