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 |
|
* rview.c - routines and variables for interactive view generation. |
6 |
|
* |
7 |
< |
* 3/24/87 |
7 |
> |
* External symbols declared in rpaint.h |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include "ray.h" |
10 |
> |
#include "copyright.h" |
11 |
|
|
15 |
– |
#include "rpaint.h" |
16 |
– |
|
12 |
|
#include <signal.h> |
18 |
– |
|
13 |
|
#include <ctype.h> |
14 |
|
|
15 |
< |
VIEW ourview = STDVIEW; /* viewing parameters */ |
16 |
< |
int hresolu, vresolu; /* image resolution */ |
15 |
> |
#include "ray.h" |
16 |
> |
#include "rpaint.h" |
17 |
|
|
18 |
+ |
|
19 |
+ |
CUBE thescene; /* our scene */ |
20 |
+ |
OBJECT nsceneobjs; /* number of objects in our scene */ |
21 |
+ |
|
22 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
23 |
|
int ndims = 0; /* number of sampling dimensions */ |
24 |
|
int samplendx = 0; /* index for this sample */ |
25 |
|
|
26 |
+ |
extern void ambnotify(); |
27 |
+ |
void (*addobjnotify[])() = {ambnotify, NULL}; |
28 |
+ |
|
29 |
+ |
VIEW ourview = STDVIEW; /* viewing parameters */ |
30 |
+ |
int hresolu, vresolu; /* image resolution */ |
31 |
+ |
|
32 |
+ |
void (*trace)() = NULL; /* trace call */ |
33 |
+ |
|
34 |
+ |
int do_irrad = 0; /* compute irradiance? */ |
35 |
+ |
|
36 |
+ |
int rand_samp = 0; /* pure Monte Carlo sampling? */ |
37 |
+ |
|
38 |
|
int psample = 8; /* pixel sample size */ |
39 |
< |
double maxdiff = .15; /* max. sample difference */ |
39 |
> |
double maxdiff = .15; /* max. sample difference */ |
40 |
|
|
41 |
< |
double exposure = 1.0; /* exposure for scene */ |
41 |
> |
double exposure = 1.0; /* exposure for scene */ |
42 |
|
|
43 |
< |
double dstrsrc = 0.0; /* square source distribution */ |
44 |
< |
double shadthresh = .1; /* shadow threshold */ |
45 |
< |
double shadcert = .25; /* shadow certainty */ |
43 |
> |
double dstrsrc = 0.0; /* square source distribution */ |
44 |
> |
double shadthresh = .1; /* shadow threshold */ |
45 |
> |
double shadcert = .25; /* shadow certainty */ |
46 |
|
int directrelay = 0; /* number of source relays */ |
47 |
|
int vspretest = 128; /* virtual source pretest density */ |
48 |
< |
int directinvis = 0; /* sources invisible? */ |
49 |
< |
double srcsizerat = 0.; /* maximum ratio source size/dist. */ |
48 |
> |
int directvis = 1; /* sources visible? */ |
49 |
> |
double srcsizerat = 0.; /* maximum ratio source size/dist. */ |
50 |
|
|
51 |
< |
double specthresh = .3; /* specular sampling threshold */ |
52 |
< |
double specjitter = 1.; /* specular sampling jitter */ |
51 |
> |
COLOR cextinction = BLKCOLOR; /* global extinction coefficient */ |
52 |
> |
COLOR salbedo = BLKCOLOR; /* global scattering albedo */ |
53 |
> |
double seccg = 0.; /* global scattering eccentricity */ |
54 |
> |
double ssampdist = 0.; /* scatter sampling distance */ |
55 |
|
|
56 |
< |
int maxdepth = 4; /* maximum recursion depth */ |
57 |
< |
double minweight = 1e-2; /* minimum ray weight */ |
56 |
> |
double specthresh = .3; /* specular sampling threshold */ |
57 |
> |
double specjitter = 1.; /* specular sampling jitter */ |
58 |
|
|
59 |
+ |
int backvis = 1; /* back face visibility */ |
60 |
+ |
|
61 |
+ |
int maxdepth = 6; /* maximum recursion depth */ |
62 |
+ |
double minweight = 1e-2; /* minimum ray weight */ |
63 |
+ |
|
64 |
+ |
char *ambfile = NULL; /* ambient file name */ |
65 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
66 |
< |
double ambacc = 0.2; /* ambient accuracy */ |
67 |
< |
int ambres = 8; /* ambient resolution */ |
68 |
< |
int ambdiv = 32; /* ambient divisions */ |
69 |
< |
int ambssamp = 0; /* ambient super-samples */ |
66 |
> |
int ambvwt = 0; /* initial weight for ambient value */ |
67 |
> |
double ambacc = 0.3; /* ambient accuracy */ |
68 |
> |
int ambres = 32; /* ambient resolution */ |
69 |
> |
int ambdiv = 256; /* ambient divisions */ |
70 |
> |
int ambssamp = 64; /* ambient super-samples */ |
71 |
|
int ambounce = 0; /* ambient bounces */ |
72 |
< |
char *amblist[128]; /* ambient include/exclude list */ |
72 |
> |
char *amblist[AMBLLEN]; /* ambient include/exclude list */ |
73 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
74 |
|
|
75 |
|
int greyscale = 0; /* map colors to brightness? */ |
76 |
< |
char *devname = dev_default; /* output device name */ |
76 |
> |
char *dvcname = dev_default; /* output device name */ |
77 |
|
|
78 |
|
struct driver *dev = NULL; /* driver functions */ |
79 |
|
|
80 |
+ |
char rifname[128]; /* rad input file name */ |
81 |
+ |
|
82 |
|
VIEW oldview; /* previous view parameters */ |
83 |
|
|
84 |
|
PNODE ptrunk; /* the base of our image */ |
89 |
|
|
90 |
|
#define RESERVE_AMT 32768 /* amount of memory to reserve */ |
91 |
|
|
92 |
< |
#define CTRL(c) ((c)-'@') |
92 |
> |
#define CTRL(c) ((c)-'@') |
93 |
|
|
94 |
|
|
95 |
+ |
void |
96 |
|
quit(code) /* quit program */ |
97 |
|
int code; |
98 |
|
{ |
99 |
+ |
#ifdef MSTATS |
100 |
+ |
if (code == 2 && errno == ENOMEM) |
101 |
+ |
printmemstats(stderr); |
102 |
+ |
#endif |
103 |
|
devclose(); |
104 |
|
exit(code); |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
+ |
void |
109 |
|
devopen(dname) /* open device driver */ |
110 |
|
char *dname; |
111 |
|
{ |
116 |
|
id = octname!=NULL ? octname : progname; |
117 |
|
/* check device table */ |
118 |
|
for (i = 0; devtable[i].name; i++) |
119 |
< |
if (!strcmp(dname, devtable[i].name)) |
119 |
> |
if (!strcmp(dname, devtable[i].name)) { |
120 |
|
if ((dev = (*devtable[i].init)(dname, id)) == NULL) { |
121 |
|
sprintf(errmsg, "cannot initialize %s", dname); |
122 |
|
error(USER, errmsg); |
123 |
|
} else |
124 |
|
return; |
125 |
+ |
} |
126 |
|
/* not there, try exec */ |
127 |
|
if ((dev = comm_init(dname, id)) == NULL) { |
128 |
|
sprintf(errmsg, "cannot start device \"%s\"", dname); |
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
+ |
void |
135 |
|
devclose() /* close our device */ |
136 |
|
{ |
137 |
|
if (dev != NULL) |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
+ |
void |
144 |
|
printdevices() /* print list of output devices */ |
145 |
|
{ |
146 |
|
register int i; |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
+ |
void |
154 |
|
rview() /* do a view */ |
155 |
|
{ |
156 |
|
char buf[32]; |
157 |
|
|
158 |
< |
devopen(devname); /* open device */ |
158 |
> |
devopen(dvcname); /* open device */ |
159 |
|
newimage(); /* start image (calls fillreserves) */ |
160 |
|
|
161 |
|
for ( ; ; ) { /* quit in command() */ |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
+ |
void |
187 |
|
fillreserves() /* fill memory reserves */ |
188 |
|
{ |
189 |
|
if (reserve_mem != NULL) |
190 |
|
return; |
191 |
< |
reserve_mem = malloc(RESERVE_AMT); |
191 |
> |
reserve_mem = (char *)malloc(RESERVE_AMT); |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
+ |
void |
196 |
|
freereserves() /* free memory reserves */ |
197 |
|
{ |
198 |
|
if (reserve_mem == NULL) |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
+ |
void |
206 |
|
command(prompt) /* get/execute command */ |
207 |
|
char *prompt; |
208 |
|
{ |
209 |
< |
#define badcom(s) strncmp(s, inpbuf, args-inpbuf-1) |
209 |
> |
#define badcom(s) strncmp(s, inpbuf, args-inpbuf-1) |
210 |
|
char inpbuf[256]; |
211 |
|
char *args; |
212 |
|
again: |
217 |
|
else *++args = '\0'; |
218 |
|
|
219 |
|
switch (inpbuf[0]) { |
220 |
< |
case 'f': /* new frame */ |
221 |
< |
if (badcom("frame")) |
222 |
< |
goto commerr; |
220 |
> |
case 'f': /* new frame (|focus|free) */ |
221 |
> |
if (badcom("frame")) { |
222 |
> |
if (badcom("focus")) { |
223 |
> |
if (badcom("free")) |
224 |
> |
goto commerr; |
225 |
> |
free_objmem(); |
226 |
> |
break; |
227 |
> |
} |
228 |
> |
getfocus(args); |
229 |
> |
break; |
230 |
> |
} |
231 |
|
getframe(args); |
232 |
|
break; |
233 |
|
case 'v': /* view */ |
240 |
|
goto commerr; |
241 |
|
lastview(args); |
242 |
|
break; |
243 |
+ |
case 'V': /* save view */ |
244 |
+ |
if (badcom("V")) |
245 |
+ |
goto commerr; |
246 |
+ |
saveview(args); |
247 |
+ |
break; |
248 |
+ |
case 'L': /* load view */ |
249 |
+ |
if (badcom("L")) |
250 |
+ |
goto commerr; |
251 |
+ |
loadview(args); |
252 |
+ |
break; |
253 |
|
case 'e': /* exposure */ |
254 |
|
if (badcom("exposure")) |
255 |
|
goto commerr; |
256 |
|
getexposure(args); |
257 |
|
break; |
258 |
|
case 's': /* set a parameter */ |
259 |
< |
if (badcom("set")) |
259 |
> |
if (badcom("set")) { |
260 |
> |
#ifdef SIGTSTP |
261 |
> |
if (!badcom("stop")) |
262 |
> |
goto dostop; |
263 |
> |
#endif |
264 |
|
goto commerr; |
265 |
+ |
} |
266 |
|
setparam(args); |
267 |
|
break; |
268 |
|
case 'n': /* new picture */ |
280 |
|
goto commerr; |
281 |
|
getaim(args); |
282 |
|
break; |
283 |
< |
case 'm': /* move camera */ |
283 |
> |
case 'm': /* move camera (or memstats) */ |
284 |
|
if (badcom("move")) |
285 |
< |
#ifdef MSTATS |
285 |
> |
#ifdef MSTATS |
286 |
|
{ |
287 |
|
if (badcom("memory")) |
288 |
|
goto commerr; |
296 |
|
break; |
297 |
|
case 'r': /* rotate/repaint */ |
298 |
|
if (badcom("rotate")) { |
299 |
< |
if (badcom("repaint")) |
300 |
< |
goto commerr; |
299 |
> |
if (badcom("repaint")) { |
300 |
> |
if (badcom("redraw")) |
301 |
> |
goto commerr; |
302 |
> |
redraw(); |
303 |
> |
break; |
304 |
> |
} |
305 |
|
getrepaint(args); |
306 |
|
break; |
307 |
|
} |
308 |
|
getrotate(args); |
309 |
|
break; |
310 |
|
case 'p': /* pivot view */ |
311 |
< |
if (badcom("pivot")) |
312 |
< |
goto commerr; |
311 |
> |
if (badcom("pivot")) { |
312 |
> |
if (badcom("pause")) |
313 |
> |
goto commerr; |
314 |
> |
goto again; |
315 |
> |
} |
316 |
|
getpivot(args); |
317 |
|
break; |
318 |
|
case CTRL('R'): /* redraw */ |
329 |
|
quit(0); |
330 |
|
case CTRL('C'): /* interrupt */ |
331 |
|
goto again; |
332 |
< |
#ifdef SIGTSTP |
333 |
< |
case CTRL('Z'): /* stop */ |
332 |
> |
#ifdef SIGTSTP |
333 |
> |
case CTRL('Z'):; /* stop */ |
334 |
> |
dostop: |
335 |
|
devclose(); |
336 |
|
kill(0, SIGTSTP); |
337 |
|
/* pc stops here */ |
338 |
< |
devopen(devname); |
338 |
> |
devopen(dvcname); |
339 |
|
redraw(); |
340 |
|
break; |
341 |
|
#endif |
351 |
|
error(COMMAND, errmsg); |
352 |
|
break; |
353 |
|
} |
354 |
< |
#undef badcom |
354 |
> |
#undef badcom |
355 |
|
} |
356 |
|
|
357 |
|
|
358 |
+ |
void |
359 |
|
rsample() /* sample the image */ |
360 |
|
{ |
361 |
|
int xsiz, ysiz, y; |
362 |
|
RECT r; |
363 |
|
PNODE *p; |
364 |
|
register RECT *rl; |
365 |
< |
register PNODE **pl; |
365 |
> |
register PNODE **pl; |
366 |
|
register int x; |
367 |
|
/* |
368 |
|
* We initialize the bottom row in the image at our current |
369 |
< |
* resolution. During sampling, we check super-pixels to the |
369 |
> |
* resolution. During sampling, we check super-pixels to the |
370 |
|
* right and above by calling bigdiff(). If there is a significant |
371 |
|
* difference, we subsample the super-pixels. The testing process |
372 |
|
* includes initialization of the next row. |
373 |
|
*/ |
374 |
< |
xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu; |
375 |
< |
ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu; |
374 |
> |
xsiz = (((long)(pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu; |
375 |
> |
ysiz = (((long)(pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu; |
376 |
|
rl = (RECT *)malloc(xsiz*sizeof(RECT)); |
377 |
|
if (rl == NULL) |
378 |
|
return; |
379 |
|
pl = (PNODE **)malloc(xsiz*sizeof(PNODE *)); |
380 |
< |
if (pl == NULL) |
380 |
> |
if (pl == NULL) { |
381 |
> |
free((void *)rl); |
382 |
|
return; |
383 |
+ |
} |
384 |
|
/* |
385 |
|
* Initialize the bottom row. |
386 |
|
*/ |
439 |
|
} |
440 |
|
} |
441 |
|
escape: |
442 |
< |
free((char *)rl); |
443 |
< |
free((char *)pl); |
442 |
> |
free((void *)rl); |
443 |
> |
free((void *)pl); |
444 |
|
} |
445 |
|
|
446 |
|
|
447 |
|
int |
448 |
|
refine(p, xmin, ymin, xmax, ymax, pd) /* refine a node */ |
449 |
< |
register PNODE *p; |
449 |
> |
register PNODE *p; |
450 |
|
int xmin, ymin, xmax, ymax; |
451 |
|
int pd; |
452 |
|
{ |
470 |
|
return(0); |
471 |
|
/* |
472 |
|
* The following paint order can leave a black pixel |
473 |
< |
* when redraw() is called in (*dev->paintr)(). |
473 |
> |
* if redraw() is called in (*dev->paintr)(). |
474 |
|
*/ |
475 |
|
if (p->x >= mx && p->y >= my) |
476 |
|
pcopy(p, p->kid+UR); |