1 |
< |
/* Copyright (c) 1987 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
18 |
|
|
19 |
|
#include "rpaint.h" |
20 |
|
|
21 |
+ |
#include "resolu.h" |
22 |
+ |
|
23 |
|
#include <ctype.h> |
24 |
|
|
25 |
< |
#define CTRL(c) ('c'-'@') |
25 |
> |
#define CTRL(c) ((c)-'@') |
26 |
|
|
27 |
+ |
#ifdef SMLFLT |
28 |
+ |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
29 |
+ |
#else |
30 |
+ |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
31 |
+ |
#endif |
32 |
+ |
|
33 |
+ |
|
34 |
+ |
extern char VersionID[]; |
35 |
|
extern char *progname; |
36 |
+ |
extern char *octname; |
37 |
|
|
38 |
|
|
39 |
|
getframe(s) /* get a new frame */ |
40 |
|
char *s; |
41 |
|
{ |
42 |
< |
int x0, y0, x1, y1; |
32 |
< |
|
33 |
< |
if (!strcmp("all", s)) { |
34 |
< |
pframe.l = pframe.d = 0; |
35 |
< |
pframe.r = ourview.hresolu; |
36 |
< |
pframe.u = ourview.vresolu; |
37 |
< |
pdepth = 0; |
42 |
> |
if (getrect(s, &pframe) < 0) |
43 |
|
return; |
39 |
– |
} |
40 |
– |
if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) { |
41 |
– |
if (dev->getcur == NULL) |
42 |
– |
return; |
43 |
– |
(*dev->comout)("Pick first corner\n"); |
44 |
– |
if ((*dev->getcur)(&x0, &y0) == ABORT) |
45 |
– |
return; |
46 |
– |
(*dev->comout)("Pick second corner\n"); |
47 |
– |
if ((*dev->getcur)(&x1, &y1) == ABORT) |
48 |
– |
return; |
49 |
– |
} |
50 |
– |
if (x0 < x1) { |
51 |
– |
pframe.l = x0; |
52 |
– |
pframe.r = x1; |
53 |
– |
} else { |
54 |
– |
pframe.l = x1; |
55 |
– |
pframe.r = x0; |
56 |
– |
} |
57 |
– |
if (y0 < y1) { |
58 |
– |
pframe.d = y0; |
59 |
– |
pframe.u = y1; |
60 |
– |
} else { |
61 |
– |
pframe.d = y1; |
62 |
– |
pframe.u = y0; |
63 |
– |
} |
64 |
– |
if (pframe.l < 0) pframe.l = 0; |
65 |
– |
if (pframe.d < 0) pframe.d = 0; |
66 |
– |
if (pframe.r > ourview.hresolu) pframe.r = ourview.hresolu; |
67 |
– |
if (pframe.u > ourview.vresolu) pframe.u = ourview.vresolu; |
44 |
|
pdepth = 0; |
45 |
|
} |
46 |
|
|
47 |
|
|
48 |
+ |
getrepaint(s) /* get area and repaint */ |
49 |
+ |
char *s; |
50 |
+ |
{ |
51 |
+ |
RECT box; |
52 |
+ |
|
53 |
+ |
if (getrect(s, &box) < 0) |
54 |
+ |
return; |
55 |
+ |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box); |
56 |
+ |
} |
57 |
+ |
|
58 |
+ |
|
59 |
|
getview(s) /* get/show view parameters */ |
60 |
|
char *s; |
61 |
|
{ |
62 |
|
FILE *fp; |
63 |
|
char buf[128]; |
64 |
< |
char *fname, *getpath(); |
64 |
> |
char *fname; |
65 |
> |
int change = 0; |
66 |
|
VIEW nv; |
67 |
|
|
68 |
+ |
while (isspace(*s)) |
69 |
+ |
s++; |
70 |
+ |
if (*s == '-') { /* command line parameters */ |
71 |
+ |
copystruct(&nv, &ourview); |
72 |
+ |
if (sscanview(&nv, s)) |
73 |
+ |
newview(&nv); |
74 |
+ |
else |
75 |
+ |
error(COMMAND, "bad view option(s)"); |
76 |
+ |
return; |
77 |
+ |
} |
78 |
|
if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ |
79 |
< |
if ((fname = getpath(buf, NULL)) == NULL || |
79 |
> |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
80 |
|
(fp = fopen(fname, "a")) == NULL) { |
81 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
82 |
|
error(COMMAND, errmsg); |
83 |
|
return; |
84 |
|
} |
85 |
< |
fputs(VIEWSTR, fp); |
85 |
> |
fputs(progname, fp); |
86 |
|
fprintview(&ourview, fp); |
87 |
+ |
fputs(sskip(s), fp); |
88 |
|
fputs("\n", fp); |
89 |
|
fclose(fp); |
90 |
|
return; |
91 |
|
} |
92 |
|
sprintf(buf, "view type (%c): ", ourview.type); |
93 |
|
(*dev->comout)(buf); |
94 |
< |
(*dev->comin)(buf); |
95 |
< |
if (buf[0] == CTRL(C)) return; |
96 |
< |
if (buf[0]) |
94 |
> |
(*dev->comin)(buf, NULL); |
95 |
> |
if (buf[0] == CTRL('C')) return; |
96 |
> |
if (buf[0] && buf[0] != ourview.type) { |
97 |
|
nv.type = buf[0]; |
98 |
< |
else |
98 |
> |
change++; |
99 |
> |
} else |
100 |
|
nv.type = ourview.type; |
101 |
|
sprintf(buf, "view point (%.6g %.6g %.6g): ", |
102 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
103 |
|
(*dev->comout)(buf); |
104 |
< |
(*dev->comin)(buf); |
105 |
< |
if (buf[0] == CTRL(C)) return; |
106 |
< |
if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) != 3) |
104 |
> |
(*dev->comin)(buf, NULL); |
105 |
> |
if (buf[0] == CTRL('C')) return; |
106 |
> |
if (sscanvec(buf, nv.vp)) |
107 |
> |
change++; |
108 |
> |
else |
109 |
|
VCOPY(nv.vp, ourview.vp); |
110 |
|
sprintf(buf, "view direction (%.6g %.6g %.6g): ", |
111 |
|
ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); |
112 |
|
(*dev->comout)(buf); |
113 |
< |
(*dev->comin)(buf); |
114 |
< |
if (buf[0] == CTRL(C)) return; |
115 |
< |
if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) != 3) |
113 |
> |
(*dev->comin)(buf, NULL); |
114 |
> |
if (buf[0] == CTRL('C')) return; |
115 |
> |
if (sscanvec(buf, nv.vdir)) |
116 |
> |
change++; |
117 |
> |
else |
118 |
|
VCOPY(nv.vdir, ourview.vdir); |
119 |
|
sprintf(buf, "view up (%.6g %.6g %.6g): ", |
120 |
|
ourview.vup[0], ourview.vup[1], ourview.vup[2]); |
121 |
|
(*dev->comout)(buf); |
122 |
< |
(*dev->comin)(buf); |
123 |
< |
if (buf[0] == CTRL(C)) return; |
124 |
< |
if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) != 3) |
122 |
> |
(*dev->comin)(buf, NULL); |
123 |
> |
if (buf[0] == CTRL('C')) return; |
124 |
> |
if (sscanvec(buf, nv.vup)) |
125 |
> |
change++; |
126 |
> |
else |
127 |
|
VCOPY(nv.vup, ourview.vup); |
128 |
|
sprintf(buf, "view horiz and vert size (%.6g %.6g): ", |
129 |
|
ourview.horiz, ourview.vert); |
130 |
|
(*dev->comout)(buf); |
131 |
< |
(*dev->comin)(buf); |
132 |
< |
if (buf[0] == CTRL(C)) return; |
133 |
< |
if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) != 2) { |
131 |
> |
(*dev->comin)(buf, NULL); |
132 |
> |
if (buf[0] == CTRL('C')) return; |
133 |
> |
if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2) |
134 |
> |
change++; |
135 |
> |
else { |
136 |
|
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
137 |
|
} |
138 |
< |
sprintf(buf, "x and y resolution (%d %d): ", |
139 |
< |
ourview.hresolu, ourview.vresolu); |
138 |
> |
sprintf(buf, "view shift and lift (%.6g %.6g): ", |
139 |
> |
ourview.hoff, ourview.voff); |
140 |
|
(*dev->comout)(buf); |
141 |
< |
(*dev->comin)(buf); |
142 |
< |
if (buf[0] == CTRL(C)) return; |
143 |
< |
if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) != 2) { |
144 |
< |
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
141 |
> |
(*dev->comin)(buf, NULL); |
142 |
> |
if (buf[0] == CTRL('C')) return; |
143 |
> |
if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2) |
144 |
> |
change++; |
145 |
> |
else { |
146 |
> |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
147 |
|
} |
148 |
< |
newview(&nv); |
148 |
> |
if (change) |
149 |
> |
newview(&nv); |
150 |
|
} |
151 |
|
|
152 |
|
|
154 |
|
char *s; |
155 |
|
{ |
156 |
|
char buf[128]; |
157 |
< |
char *fname, *getpath(); |
157 |
> |
char *fname; |
158 |
|
int success; |
159 |
|
VIEW nv; |
160 |
|
|
161 |
|
if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ |
162 |
< |
bcopy(&stdview, &nv, sizeof(VIEW)); |
163 |
< |
if ((fname = getpath(buf, NULL)) == NULL || |
164 |
< |
(success = viewfile(fname, &nv)) == -1) { |
162 |
> |
copystruct(&nv, &stdview); |
163 |
> |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
164 |
> |
(success = viewfile(fname, &nv, NULL)) == -1) { |
165 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
166 |
|
error(COMMAND, errmsg); |
167 |
|
return; |
172 |
|
newview(&nv); |
173 |
|
return; |
174 |
|
} |
175 |
< |
if (oldview.hresolu == 0) { /* no old view! */ |
175 |
> |
if (oldview.type == 0) { /* no old view! */ |
176 |
|
error(COMMAND, "no previous view"); |
177 |
|
return; |
178 |
|
} |
179 |
< |
bcopy(&ourview, &nv, sizeof(VIEW)); |
180 |
< |
bcopy(&oldview, &ourview, sizeof(VIEW)); |
181 |
< |
bcopy(&nv, &oldview, sizeof(VIEW)); |
179 |
> |
copystruct(&nv, &ourview); |
180 |
> |
copystruct(&ourview, &oldview); |
181 |
> |
copystruct(&oldview, &nv); |
182 |
|
newimage(); |
183 |
|
} |
184 |
|
|
185 |
|
|
175 |
– |
getinterest(s, direc, vec, mp) /* get area of interest */ |
176 |
– |
char *s; |
177 |
– |
int direc; |
178 |
– |
FVECT vec; |
179 |
– |
double *mp; |
180 |
– |
{ |
181 |
– |
int x, y; |
182 |
– |
RAY thisray; |
183 |
– |
register int i; |
184 |
– |
|
185 |
– |
if (sscanf(s, "%lf", mp) != 1) |
186 |
– |
*mp = 1.0; |
187 |
– |
else if (*mp < -FTINY) /* negative zoom is reduction */ |
188 |
– |
*mp = -1.0 / *mp; |
189 |
– |
else if (*mp <= FTINY) { /* too small */ |
190 |
– |
error(COMMAND, "illegal magnification"); |
191 |
– |
return(-1); |
192 |
– |
} |
193 |
– |
if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) { |
194 |
– |
if (dev->getcur == NULL) |
195 |
– |
return(-1); |
196 |
– |
(*dev->comout)("Pick view center\n"); |
197 |
– |
if ((*dev->getcur)(&x, &y) == ABORT) |
198 |
– |
return(-1); |
199 |
– |
rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5); |
200 |
– |
if (!direc || ourview.type == VT_PAR) { |
201 |
– |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
202 |
– |
if (!localhit(&thisray, &thescene)) { |
203 |
– |
error(COMMAND, "not a local object"); |
204 |
– |
return(-1); |
205 |
– |
} |
206 |
– |
} |
207 |
– |
if (direc) |
208 |
– |
if (ourview.type == VT_PAR) |
209 |
– |
for (i = 0; i < 3; i++) |
210 |
– |
vec[i] = thisray.rop[i] - ourview.vp[i]; |
211 |
– |
else |
212 |
– |
VCOPY(vec, thisray.rdir); |
213 |
– |
else |
214 |
– |
VCOPY(vec, thisray.rop); |
215 |
– |
} else if (direc) |
216 |
– |
for (i = 0; i < 3; i++) |
217 |
– |
vec[i] -= ourview.vp[i]; |
218 |
– |
return(0); |
219 |
– |
} |
220 |
– |
|
221 |
– |
|
186 |
|
getaim(s) /* aim camera */ |
187 |
|
char *s; |
188 |
|
{ |
225 |
– |
extern double tan(), atan(); |
189 |
|
double zfact; |
190 |
|
VIEW nv; |
191 |
|
|
192 |
|
if (getinterest(s, 1, nv.vdir, &zfact) < 0) |
193 |
|
return; |
194 |
+ |
nv.type = ourview.type; |
195 |
|
VCOPY(nv.vp, ourview.vp); |
196 |
|
VCOPY(nv.vup, ourview.vup); |
197 |
< |
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
198 |
< |
if ((nv.type = ourview.type) == VT_PAR) { |
199 |
< |
nv.horiz = ourview.horiz / zfact; |
236 |
< |
nv.vert = ourview.vert / zfact; |
237 |
< |
} else { |
238 |
< |
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
239 |
< |
(PI/180./2.); |
240 |
< |
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
241 |
< |
(PI/180./2.); |
242 |
< |
} |
197 |
> |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
198 |
> |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
199 |
> |
zoomview(&nv, zfact); |
200 |
|
newview(&nv); |
201 |
|
} |
202 |
|
|
209 |
|
|
210 |
|
if (getinterest(s, 0, vc, &mag) < 0) |
211 |
|
return; |
212 |
< |
moveview(0.0, mag, vc); |
212 |
> |
moveview(0.0, 0.0, mag, vc); |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
|
getrotate(s) /* rotate camera */ |
217 |
|
char *s; |
218 |
|
{ |
262 |
– |
extern double normalize(); |
219 |
|
VIEW nv; |
220 |
|
FVECT v1; |
221 |
< |
double angle, elev; |
221 |
> |
double angle, elev, zfact; |
222 |
|
|
223 |
< |
elev = 0.0; |
224 |
< |
if (sscanf(s, "%lf %lf", &angle, &elev) < 1) { |
223 |
> |
elev = 0.0; zfact = 1.0; |
224 |
> |
if (sscanf(s, "%lf %lf %lf", &angle, &elev, &zfact) < 1) { |
225 |
|
error(COMMAND, "missing angle"); |
226 |
|
return; |
227 |
|
} |
228 |
|
nv.type = ourview.type; |
229 |
|
VCOPY(nv.vp, ourview.vp); |
230 |
|
VCOPY(nv.vup, ourview.vup); |
231 |
< |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
276 |
< |
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
231 |
> |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
232 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
233 |
|
if (elev != 0.0) { |
234 |
|
fcross(v1, nv.vdir, ourview.vup); |
235 |
|
normalize(v1); |
236 |
|
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
237 |
|
} |
238 |
+ |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
239 |
+ |
zoomview(&nv, zfact); |
240 |
|
newview(&nv); |
241 |
|
} |
242 |
|
|
245 |
|
register char *s; |
246 |
|
{ |
247 |
|
FVECT vc; |
248 |
< |
double angle, mag; |
248 |
> |
double angle, elev, mag; |
249 |
|
|
250 |
< |
if (sscanf(s, "%lf", &angle) != 1) { |
250 |
> |
elev = 0.0; |
251 |
> |
if (sscanf(s, "%lf %lf", &angle, &elev) < 1) { |
252 |
|
error(COMMAND, "missing angle"); |
253 |
|
return; |
254 |
|
} |
255 |
< |
if (getinterest(sskip(s), 0, vc, &mag) < 0) |
255 |
> |
if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0) |
256 |
|
return; |
257 |
< |
moveview(angle, mag, vc); |
257 |
> |
moveview(angle, elev, mag, vc); |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
|
getexposure(s) /* get new exposure */ |
262 |
|
char *s; |
263 |
|
{ |
306 |
– |
double atof(), pow(), fabs(); |
264 |
|
char buf[128]; |
265 |
|
register char *cp; |
266 |
|
register PNODE *p; |
277 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
278 |
|
return; |
279 |
|
r.l = r.d = 0; |
280 |
< |
r.r = ourview.hresolu; r.u = ourview.vresolu; |
280 |
> |
r.r = hresolu; r.u = vresolu; |
281 |
|
p = findrect(x, y, &ptrunk, &r, -1); |
282 |
|
e = 1.0; |
283 |
|
} else { |
289 |
|
if (*cp == '\0') { /* interactive */ |
290 |
|
sprintf(buf, "exposure (%lf): ", exposure); |
291 |
|
(*dev->comout)(buf); |
292 |
< |
(*dev->comin)(buf); |
292 |
> |
(*dev->comin)(buf, NULL); |
293 |
|
for (cp = buf; isspace(*cp); cp++) |
294 |
|
; |
295 |
|
if (*cp == '\0') |
305 |
|
e *= atof(cp); |
306 |
|
} |
307 |
|
if (p != NULL) { /* relative setting */ |
308 |
< |
if (intens(p->v) <= FTINY) { |
308 |
> |
if (bright(p->v) < 1e-25) { |
309 |
|
error(COMMAND, "cannot normalize to zero"); |
310 |
|
return; |
311 |
|
} |
312 |
< |
e *= 0.5 / intens(p->v); |
312 |
> |
e *= 0.5 / bright(p->v); |
313 |
|
} |
314 |
|
if (e <= FTINY || fabs(1.0 - e) <= FTINY) |
315 |
|
return; |
319 |
|
} |
320 |
|
|
321 |
|
|
322 |
+ |
getparam(str, dsc, typ, ptr) /* get variable from user */ |
323 |
+ |
char *str, *dsc; |
324 |
+ |
int typ; |
325 |
+ |
register union {int i; double d; COLOR C;} *ptr; |
326 |
+ |
{ |
327 |
+ |
extern char *index(); |
328 |
+ |
int i0; |
329 |
+ |
double d0, d1, d2; |
330 |
+ |
char buf[48]; |
331 |
+ |
|
332 |
+ |
switch (typ) { |
333 |
+ |
case 'i': /* integer */ |
334 |
+ |
if (sscanf(str, "%d", &i0) != 1) { |
335 |
+ |
(*dev->comout)(dsc); |
336 |
+ |
sprintf(buf, " (%d): ", ptr->i); |
337 |
+ |
(*dev->comout)(buf); |
338 |
+ |
(*dev->comin)(buf, NULL); |
339 |
+ |
if (sscanf(buf, "%d", &i0) != 1) |
340 |
+ |
return(0); |
341 |
+ |
} |
342 |
+ |
ptr->i = i0; |
343 |
+ |
return(1); |
344 |
+ |
case 'r': /* real */ |
345 |
+ |
if (sscanf(str, "%lf", &d0) != 1) { |
346 |
+ |
(*dev->comout)(dsc); |
347 |
+ |
sprintf(buf, " (%.6g): ", ptr->d); |
348 |
+ |
(*dev->comout)(buf); |
349 |
+ |
(*dev->comin)(buf, NULL); |
350 |
+ |
if (sscanf(buf, "%lf", &d0) != 1) |
351 |
+ |
return(0); |
352 |
+ |
} |
353 |
+ |
ptr->d = d0; |
354 |
+ |
return(1); |
355 |
+ |
case 'b': /* boolean */ |
356 |
+ |
if (sscanf(str, "%1s", buf) != 1) { |
357 |
+ |
(*dev->comout)(dsc); |
358 |
+ |
sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n'); |
359 |
+ |
(*dev->comout)(buf); |
360 |
+ |
(*dev->comin)(buf, NULL); |
361 |
+ |
if (buf[0] == '\0' || |
362 |
+ |
index("yY+1tTnN-0fF", buf[0]) == NULL) |
363 |
+ |
return(0); |
364 |
+ |
} |
365 |
+ |
ptr->i = index("yY+1tT", buf[0]) != NULL; |
366 |
+ |
return(1); |
367 |
+ |
case 'C': /* color */ |
368 |
+ |
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
369 |
+ |
(*dev->comout)(dsc); |
370 |
+ |
sprintf(buf, " (%.6g %.6g %.6g): ", |
371 |
+ |
colval(ptr->C,RED), |
372 |
+ |
colval(ptr->C,GRN), |
373 |
+ |
colval(ptr->C,BLU)); |
374 |
+ |
(*dev->comout)(buf); |
375 |
+ |
(*dev->comin)(buf, NULL); |
376 |
+ |
if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) |
377 |
+ |
return(0); |
378 |
+ |
} |
379 |
+ |
setcolor(ptr->C, d0, d1, d2); |
380 |
+ |
return(1); |
381 |
+ |
} |
382 |
+ |
} |
383 |
+ |
|
384 |
+ |
|
385 |
|
setparam(s) /* get/set program parameter */ |
386 |
|
register char *s; |
387 |
|
{ |
390 |
|
extern double minweight; |
391 |
|
extern int maxdepth; |
392 |
|
extern double dstrsrc; |
393 |
+ |
extern double shadthresh; |
394 |
+ |
extern double shadcert; |
395 |
|
extern COLOR ambval; |
396 |
|
extern double ambacc; |
375 |
– |
extern double minarad; |
397 |
|
extern int ambres; |
398 |
|
extern int ambdiv; |
399 |
|
extern int ambssamp; |
400 |
|
extern int ambounce; |
401 |
< |
int i0; |
402 |
< |
double d0, d1, d2; |
401 |
> |
extern int directinvis; |
402 |
> |
extern double srcsizerat; |
403 |
> |
extern int do_irrad; |
404 |
> |
extern double specjitter; |
405 |
> |
extern double specthresh; |
406 |
|
char buf[128]; |
407 |
|
|
408 |
|
if (s[0] == '\0') { |
409 |
< |
(*dev->comout)("aa ab ad ar as av ds lr lw sd sp: "); |
410 |
< |
(*dev->comin)(buf); |
409 |
> |
(*dev->comout)( |
410 |
> |
"aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: "); |
411 |
> |
(*dev->comin)(buf, NULL); |
412 |
|
s = buf; |
413 |
|
} |
414 |
|
switch (s[0]) { |
415 |
|
case 'l': /* limit */ |
416 |
|
switch (s[1]) { |
417 |
|
case 'w': /* weight */ |
418 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
394 |
< |
sprintf(buf, "limit weight (%.6g): ", |
395 |
< |
minweight); |
396 |
< |
(*dev->comout)(buf); |
397 |
< |
(*dev->comin)(buf); |
398 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
399 |
< |
break; |
400 |
< |
} |
401 |
< |
minweight = d0; |
418 |
> |
getparam(s+2, "limit weight", 'r', &minweight); |
419 |
|
break; |
420 |
|
case 'r': /* reflection */ |
421 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
405 |
< |
sprintf(buf, "limit reflection (%d): ", |
406 |
< |
maxdepth); |
407 |
< |
(*dev->comout)(buf); |
408 |
< |
(*dev->comin)(buf); |
409 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
410 |
< |
break; |
411 |
< |
} |
412 |
< |
maxdepth = i0; |
421 |
> |
getparam(s+2, "limit reflection", 'i', &maxdepth); |
422 |
|
break; |
423 |
|
default: |
424 |
|
goto badparam; |
425 |
|
} |
426 |
|
break; |
427 |
< |
case 'd': /* distribute source */ |
428 |
< |
if (s[1] != 's') |
427 |
> |
case 'd': /* direct */ |
428 |
> |
switch (s[1]) { |
429 |
> |
case 'j': /* jitter */ |
430 |
> |
getparam(s+2, "direct jitter", 'r', &dstrsrc); |
431 |
> |
break; |
432 |
> |
case 'c': /* certainty */ |
433 |
> |
getparam(s+2, "direct certainty", 'r', &shadcert); |
434 |
> |
break; |
435 |
> |
case 't': /* threshold */ |
436 |
> |
getparam(s+2, "direct threshold", 'r', &shadthresh); |
437 |
> |
break; |
438 |
> |
case 'i': /* invisibility */ |
439 |
> |
getparam(s+2, "direct invisibility", |
440 |
> |
'b', &directinvis); |
441 |
> |
break; |
442 |
> |
case 's': /* sampling */ |
443 |
> |
getparam(s+2, "direct sampling", 'r', &srcsizerat); |
444 |
> |
break; |
445 |
> |
default: |
446 |
|
goto badparam; |
421 |
– |
if (sscanf(s+2, "%lf", &d0) != 1) { |
422 |
– |
sprintf(buf, "distribute source (%.6g): ", dstrsrc); |
423 |
– |
(*dev->comout)(buf); |
424 |
– |
(*dev->comin)(buf); |
425 |
– |
if (sscanf(buf, "%lf", &d0) != 1) |
426 |
– |
break; |
447 |
|
} |
428 |
– |
dstrsrc = d0; |
448 |
|
break; |
449 |
+ |
case 'b': /* black and white */ |
450 |
+ |
getparam(s+1, "black and white", 'b', &greyscale); |
451 |
+ |
break; |
452 |
+ |
case 'i': /* irradiance */ |
453 |
+ |
getparam(s+1, "irradiance", 'b', &do_irrad); |
454 |
+ |
break; |
455 |
|
case 'a': /* ambient */ |
456 |
|
switch (s[1]) { |
457 |
|
case 'v': /* value */ |
458 |
< |
if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
434 |
< |
sprintf(buf, |
435 |
< |
"ambient value (%.6g %.6g %.6g): ", |
436 |
< |
colval(ambval,RED), |
437 |
< |
colval(ambval,GRN), |
438 |
< |
colval(ambval,BLU)); |
439 |
< |
(*dev->comout)(buf); |
440 |
< |
(*dev->comin)(buf); |
441 |
< |
if (sscanf(buf, "%lf %lf %lf", |
442 |
< |
&d0, &d1, &d2) != 3) |
443 |
< |
break; |
444 |
< |
} |
445 |
< |
setcolor(ambval, d0, d1, d2); |
458 |
> |
getparam(s+2, "ambient value", 'C', ambval); |
459 |
|
break; |
460 |
|
case 'a': /* accuracy */ |
461 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
449 |
< |
sprintf(buf, "ambient accuracy (%.6g): ", |
450 |
< |
ambacc); |
451 |
< |
(*dev->comout)(buf); |
452 |
< |
(*dev->comin)(buf); |
453 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
454 |
< |
break; |
455 |
< |
} |
456 |
< |
ambacc = d0; |
461 |
> |
getparam(s+2, "ambient accuracy", 'r', &ambacc); |
462 |
|
break; |
463 |
|
case 'd': /* divisions */ |
464 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
460 |
< |
sprintf(buf, "ambient divisions (%d): ", |
461 |
< |
ambdiv); |
462 |
< |
(*dev->comout)(buf); |
463 |
< |
(*dev->comin)(buf); |
464 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
465 |
< |
break; |
466 |
< |
} |
467 |
< |
ambdiv = i0; |
464 |
> |
getparam(s+2, "ambient divisions", 'i', &ambdiv); |
465 |
|
break; |
466 |
|
case 's': /* samples */ |
467 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
471 |
< |
sprintf(buf, "ambient super-samples (%d): ", |
472 |
< |
ambssamp); |
473 |
< |
(*dev->comout)(buf); |
474 |
< |
(*dev->comin)(buf); |
475 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
476 |
< |
break; |
477 |
< |
} |
478 |
< |
ambssamp = i0; |
467 |
> |
getparam(s+2, "ambient super-samples", 'i', &ambssamp); |
468 |
|
break; |
469 |
|
case 'b': /* bounces */ |
470 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
482 |
< |
sprintf(buf, "ambient bounces (%d): ", |
483 |
< |
ambounce); |
484 |
< |
(*dev->comout)(buf); |
485 |
< |
(*dev->comin)(buf); |
486 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
487 |
< |
break; |
488 |
< |
} |
489 |
< |
ambounce = i0; |
470 |
> |
getparam(s+2, "ambient bounces", 'i', &ambounce); |
471 |
|
break; |
472 |
|
case 'r': |
473 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
474 |
< |
sprintf(buf, "ambient resolution (%d): ", |
494 |
< |
ambres); |
495 |
< |
(*dev->comout)(buf); |
496 |
< |
(*dev->comin)(buf); |
497 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
498 |
< |
break; |
499 |
< |
} |
500 |
< |
ambres = i0; |
501 |
< |
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
473 |
> |
if (getparam(s+2, "ambient resolution", 'i', &ambres)) |
474 |
> |
setambres(ambres); |
475 |
|
break; |
476 |
|
default: |
477 |
|
goto badparam; |
478 |
|
} |
479 |
|
break; |
480 |
< |
case 's': /* sample */ |
480 |
> |
case 'p': /* pixel */ |
481 |
|
switch (s[1]) { |
482 |
< |
case 'p': /* pixel */ |
483 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
484 |
< |
sprintf(buf, "sample pixel (%d): ", psample); |
512 |
< |
(*dev->comout)(buf); |
513 |
< |
(*dev->comin)(buf); |
514 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
515 |
< |
break; |
516 |
< |
} |
517 |
< |
psample = i0; |
518 |
< |
pdepth = 0; |
482 |
> |
case 's': /* sample */ |
483 |
> |
if (getparam(s+2, "pixel sample", 'i', &psample)) |
484 |
> |
pdepth = 0; |
485 |
|
break; |
486 |
< |
case 'd': /* difference */ |
487 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
488 |
< |
sprintf(buf, "sample difference (%.6g): ", |
523 |
< |
maxdiff); |
524 |
< |
(*dev->comout)(buf); |
525 |
< |
(*dev->comin)(buf); |
526 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
527 |
< |
break; |
528 |
< |
} |
529 |
< |
maxdiff = d0; |
530 |
< |
pdepth = 0; |
486 |
> |
case 't': /* threshold */ |
487 |
> |
if (getparam(s+2, "pixel threshold", 'r', &maxdiff)) |
488 |
> |
pdepth = 0; |
489 |
|
break; |
490 |
|
default: |
491 |
|
goto badparam; |
492 |
|
} |
493 |
|
break; |
494 |
+ |
case 's': /* specular */ |
495 |
+ |
switch (s[1]) { |
496 |
+ |
case 'j': /* jitter */ |
497 |
+ |
getparam(s+2, "specular jitter", 'r', &specjitter); |
498 |
+ |
break; |
499 |
+ |
case 't': /* threshold */ |
500 |
+ |
getparam(s+2, "specular threshold", 'r', &specthresh); |
501 |
+ |
break; |
502 |
+ |
default: |
503 |
+ |
goto badparam; |
504 |
+ |
} |
505 |
+ |
break; |
506 |
|
case '\0': /* nothing */ |
507 |
|
break; |
508 |
|
default:; |
509 |
|
badparam: |
510 |
+ |
*sskip(s) = '\0'; |
511 |
|
sprintf(errmsg, "%s: unknown variable", s); |
512 |
|
error(COMMAND, errmsg); |
513 |
|
break; |
522 |
|
int x, y; |
523 |
|
RAY thisray; |
524 |
|
|
525 |
< |
if (sscanf(s, "%lf %lf %lf %lf %lf %lf", |
526 |
< |
&thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2], |
556 |
< |
&thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) { |
525 |
> |
if (!sscanvec(s, thisray.rorg) || |
526 |
> |
!sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) { |
527 |
|
|
528 |
|
if (dev->getcur == NULL) |
529 |
|
return; |
531 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
532 |
|
return; |
533 |
|
|
534 |
< |
rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5); |
535 |
< |
|
534 |
> |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
535 |
> |
(x+.5)/hresolu, (y+.5)/vresolu) < 0) { |
536 |
> |
error(COMMAND, "not on image"); |
537 |
> |
return; |
538 |
> |
} |
539 |
> |
|
540 |
|
} else if (normalize(thisray.rdir) == 0.0) { |
541 |
|
error(COMMAND, "zero ray direction"); |
542 |
|
return; |
554 |
|
ofun[thisray.ro->otype].funame, |
555 |
|
thisray.ro->oname); |
556 |
|
(*dev->comout)(buf); |
557 |
< |
(*dev->comin)(buf); |
557 |
> |
(*dev->comin)(buf, NULL); |
558 |
|
if (thisray.rot >= FHUGE) |
559 |
|
(*dev->comout)("at infinity"); |
560 |
|
else { |
562 |
|
thisray.rop[1], thisray.rop[2]); |
563 |
|
(*dev->comout)(buf); |
564 |
|
} |
565 |
< |
(*dev->comin)(buf); |
566 |
< |
sprintf(buf, "with value (%.6g %.6g %.6g)", |
565 |
> |
(*dev->comin)(buf, NULL); |
566 |
> |
sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)", |
567 |
|
colval(thisray.rcol,RED), |
568 |
|
colval(thisray.rcol,GRN), |
569 |
< |
colval(thisray.rcol,BLU)); |
569 |
> |
colval(thisray.rcol,BLU), |
570 |
> |
luminance(thisray.rcol)); |
571 |
|
(*dev->comout)(buf); |
572 |
|
} |
573 |
< |
(*dev->comin)(buf); |
573 |
> |
(*dev->comin)(buf, NULL); |
574 |
|
} |
575 |
|
|
576 |
|
|
578 |
|
char *s; |
579 |
|
{ |
580 |
|
static char buf[128]; |
581 |
< |
char *fname, *getpath(); |
581 |
> |
char *fname; |
582 |
|
FILE *fp; |
583 |
|
COLR *scanline; |
584 |
|
int y; |
587 |
|
error(COMMAND, "no file"); |
588 |
|
return; |
589 |
|
} |
590 |
< |
if ((fname = getpath(buf, NULL)) == NULL || |
590 |
> |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
591 |
|
(fp = fopen(fname, "w")) == NULL) { |
592 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
593 |
|
error(COMMAND, errmsg); |
599 |
|
/* write header */ |
600 |
|
fputs(progname, fp); |
601 |
|
fprintview(&ourview, fp); |
602 |
< |
fputs("\n", fp); |
602 |
> |
if (octname != NULL) |
603 |
> |
fprintf(fp, " %s\n", octname); |
604 |
> |
else |
605 |
> |
putc('\n', fp); |
606 |
> |
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
607 |
|
if (exposure != 1.0) |
608 |
< |
fprintf(fp, "EXPOSURE=%e\n", exposure); |
609 |
< |
fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu); |
608 |
> |
fputexpos(exposure, fp); |
609 |
> |
if (dev->pixaspect != 1.0) |
610 |
> |
fputaspect(dev->pixaspect, fp); |
611 |
> |
fputformat(COLRFMT, fp); |
612 |
> |
putc('\n', fp); |
613 |
> |
fprtresolu(hresolu, vresolu, fp); |
614 |
|
|
615 |
< |
scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR)); |
616 |
< |
if (scanline == NULL) |
617 |
< |
error(SYSTEM, "out of memory in writepict"); |
618 |
< |
for (y = ourview.vresolu-1; y >= 0; y--) { |
619 |
< |
getpictcolrs(y, scanline, &ptrunk, |
620 |
< |
ourview.hresolu, ourview.vresolu); |
621 |
< |
if (fwritecolrs(scanline, ourview.hresolu, fp) < 0) |
615 |
> |
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
616 |
> |
if (scanline == NULL) { |
617 |
> |
error(COMMAND, "not enough memory!"); |
618 |
> |
fclose(fp); |
619 |
> |
unlink(fname); |
620 |
> |
return; |
621 |
> |
} |
622 |
> |
for (y = vresolu-1; y >= 0; y--) { |
623 |
> |
getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); |
624 |
> |
if (fwritecolrs(scanline, hresolu, fp) < 0) |
625 |
|
break; |
626 |
|
} |
627 |
+ |
free((char *)scanline); |
628 |
|
if (fclose(fp) < 0) |
629 |
|
error(COMMAND, "write error"); |
643 |
– |
free((char *)scanline); |
630 |
|
} |