10 |
|
* 3/24/87 |
11 |
|
*/ |
12 |
|
|
13 |
< |
#include "standard.h" |
13 |
> |
#include "ray.h" |
14 |
|
|
15 |
– |
#include "color.h" |
16 |
– |
|
15 |
|
#include "rpaint.h" |
16 |
|
|
17 |
|
#include <signal.h> |
18 |
|
|
19 |
|
#include <ctype.h> |
20 |
|
|
21 |
< |
VIEW ourview = STDVIEW(470); /* viewing parameters */ |
21 |
> |
VIEW ourview = STDVIEW; /* viewing parameters */ |
22 |
> |
int hresolu, vresolu; /* image resolution */ |
23 |
|
|
24 |
+ |
int dimlist[MAXDIM]; /* sampling dimensions */ |
25 |
+ |
int ndims = 0; /* number of sampling dimensions */ |
26 |
+ |
int samplendx = 0; /* index for this sample */ |
27 |
+ |
|
28 |
|
int psample = 8; /* pixel sample size */ |
29 |
|
double maxdiff = .15; /* max. sample difference */ |
30 |
|
|
31 |
|
double exposure = 1.0; /* exposure for scene */ |
32 |
|
|
33 |
|
double dstrsrc = 0.0; /* square source distribution */ |
34 |
+ |
double shadthresh = .1; /* shadow threshold */ |
35 |
+ |
double shadcert = .25; /* shadow certainty */ |
36 |
|
|
37 |
|
int maxdepth = 4; /* maximum recursion depth */ |
38 |
|
double minweight = 1e-2; /* minimum ray weight */ |
39 |
|
|
40 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
41 |
|
double ambacc = 0.2; /* ambient accuracy */ |
42 |
< |
int ambres = 64; /* ambient resolution */ |
42 |
> |
int ambres = 8; /* ambient resolution */ |
43 |
|
int ambdiv = 32; /* ambient divisions */ |
44 |
|
int ambssamp = 0; /* ambient super-samples */ |
45 |
|
int ambounce = 0; /* ambient bounces */ |
47 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
48 |
|
|
49 |
|
int greyscale = 0; /* map colors to brightness? */ |
50 |
< |
char *devname = "X"; /* output device name */ |
50 |
> |
char *devname = dev_default; /* output device name */ |
51 |
|
|
52 |
|
struct driver *dev = NULL; /* driver functions */ |
53 |
|
|
57 |
|
RECT pframe; /* current frame boundaries */ |
58 |
|
int pdepth; /* image depth in current frame */ |
59 |
|
|
60 |
+ |
static char *reserve_mem = NULL; /* pre-allocated reserve memory */ |
61 |
+ |
|
62 |
+ |
#define RESERVE_AMT 8192 /* amount of memory to reserve */ |
63 |
+ |
|
64 |
|
#define CTRL(c) ('c'-'@') |
65 |
|
|
66 |
|
|
75 |
|
devopen(dname) /* open device driver */ |
76 |
|
char *dname; |
77 |
|
{ |
78 |
< |
extern char *progname; |
79 |
< |
char *devargv[3]; |
78 |
> |
extern char *progname, *octname; |
79 |
> |
char *id; |
80 |
|
register int i; |
81 |
+ |
|
82 |
+ |
id = octname!=NULL ? octname : progname; |
83 |
|
/* check device table */ |
84 |
|
for (i = 0; devtable[i].name; i++) |
85 |
|
if (!strcmp(dname, devtable[i].name)) |
86 |
< |
if ((dev = (*devtable[i].init)(progname)) == NULL) { |
86 |
> |
if ((dev = (*devtable[i].init)(dname, id)) == NULL) { |
87 |
|
sprintf(errmsg, "cannot initialize %s", dname); |
88 |
|
error(USER, errmsg); |
89 |
|
} else |
90 |
|
return; |
91 |
|
/* not there, try exec */ |
92 |
< |
devargv[0] = dname; |
82 |
< |
devargv[1] = progname; |
83 |
< |
devargv[2] = NULL; |
84 |
< |
if ((dev = comm_init(devargv)) == NULL) { |
92 |
> |
if ((dev = comm_init(dname, id)) == NULL) { |
93 |
|
sprintf(errmsg, "cannot start device \"%s\"", dname); |
94 |
|
error(USER, errmsg); |
95 |
|
} |
118 |
|
char buf[32]; |
119 |
|
|
120 |
|
devopen(devname); /* open device */ |
121 |
< |
newimage(); /* set up image */ |
121 |
> |
newimage(); /* start image (calls fillreserves) */ |
122 |
|
|
123 |
|
for ( ; ; ) { /* quit in command() */ |
124 |
< |
while (ourview.hresolu <= 1<<pdepth && |
117 |
< |
ourview.vresolu <= 1<<pdepth) |
124 |
> |
while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth) |
125 |
|
command("done: "); |
126 |
< |
|
127 |
< |
if (ourview.hresolu <= psample<<pdepth && |
128 |
< |
ourview.vresolu <= psample<<pdepth) { |
126 |
> |
while (reserve_mem == NULL) |
127 |
> |
command("out of memory: "); |
128 |
> |
errno = 0; |
129 |
> |
if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) { |
130 |
|
sprintf(buf, "%d sampling...\n", 1<<pdepth); |
131 |
|
(*dev->comout)(buf); |
132 |
|
rsample(); |
133 |
|
} else { |
134 |
|
sprintf(buf, "%d refining...\n", 1<<pdepth); |
135 |
|
(*dev->comout)(buf); |
136 |
< |
refine(&ptrunk, 0, 0, ourview.hresolu, |
129 |
< |
ourview.vresolu, pdepth+1); |
136 |
> |
refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1); |
137 |
|
} |
138 |
< |
if (dev->inpready) |
138 |
> |
if (errno == ENOMEM) /* ran out of memory */ |
139 |
> |
freereserves(); |
140 |
> |
else if (dev->inpready) /* noticed some input */ |
141 |
|
command(": "); |
142 |
< |
else |
142 |
> |
else /* finished this depth */ |
143 |
|
pdepth++; |
144 |
|
} |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
+ |
fillreserves() /* fill memory reserves */ |
149 |
+ |
{ |
150 |
+ |
if (reserve_mem != NULL) |
151 |
+ |
return; |
152 |
+ |
reserve_mem = malloc(RESERVE_AMT); |
153 |
+ |
} |
154 |
+ |
|
155 |
+ |
|
156 |
+ |
freereserves() /* free memory reserves */ |
157 |
+ |
{ |
158 |
+ |
if (reserve_mem == NULL) |
159 |
+ |
return; |
160 |
+ |
free(reserve_mem); |
161 |
+ |
reserve_mem = NULL; |
162 |
+ |
} |
163 |
+ |
|
164 |
+ |
|
165 |
|
command(prompt) /* get/execute command */ |
166 |
|
char *prompt; |
167 |
|
{ |
170 |
|
char inpbuf[256]; |
171 |
|
char *args; |
172 |
|
again: |
173 |
< |
(*dev->comout)(prompt); /* get command + arguments */ |
148 |
< |
(*dev->comin)(inpbuf); |
173 |
> |
(*dev->comin)(inpbuf, prompt); /* get command + arguments */ |
174 |
|
for (args = inpbuf; *args && *args != ' '; args++) |
175 |
|
; |
176 |
|
if (*args) *args++ = '\0'; |
222 |
|
goto commerr; |
223 |
|
getmove(args); |
224 |
|
break; |
225 |
< |
case 'r': /* rotate camera */ |
226 |
< |
if (badcom("rotate")) |
227 |
< |
goto commerr; |
225 |
> |
case 'r': /* rotate/repaint */ |
226 |
> |
if (badcom("rotate")) { |
227 |
> |
if (badcom("repaint")) |
228 |
> |
goto commerr; |
229 |
> |
getrepaint(args); |
230 |
> |
break; |
231 |
> |
} |
232 |
|
getrotate(args); |
233 |
|
break; |
234 |
|
case 'p': /* pivot view */ |
290 |
|
* difference, we subsample the super-pixels. The testing process |
291 |
|
* includes initialization of the next row. |
292 |
|
*/ |
293 |
< |
xsiz = (((pframe.r-pframe.l)<<pdepth)+ourview.hresolu-1) / |
294 |
< |
ourview.hresolu; |
266 |
< |
ysiz = (((pframe.u-pframe.d)<<pdepth)+ourview.vresolu-1) / |
267 |
< |
ourview.vresolu; |
293 |
> |
xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu; |
294 |
> |
ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu; |
295 |
|
rl = (RECT *)malloc(xsiz*sizeof(RECT)); |
296 |
+ |
if (rl == NULL) |
297 |
+ |
return; |
298 |
|
pl = (PNODE **)malloc(xsiz*sizeof(PNODE *)); |
299 |
< |
if (rl == NULL || pl == NULL) |
300 |
< |
error(SYSTEM, "out of memory in rsample"); |
299 |
> |
if (pl == NULL) |
300 |
> |
return; |
301 |
|
/* |
302 |
|
* Initialize the bottom row. |
303 |
|
*/ |
304 |
|
rl[0].l = rl[0].d = 0; |
305 |
< |
rl[0].r = ourview.hresolu; rl[0].u = ourview.vresolu; |
305 |
> |
rl[0].r = hresolu; rl[0].u = vresolu; |
306 |
|
pl[0] = findrect(pframe.l, pframe.d, &ptrunk, rl, pdepth); |
307 |
|
for (x = 1; x < xsiz; x++) { |
308 |
|
rl[x].l = rl[x].d = 0; |
309 |
< |
rl[x].r = ourview.hresolu; rl[x].u = ourview.vresolu; |
310 |
< |
pl[x] = findrect(pframe.l+((x*ourview.hresolu)>>pdepth), |
309 |
> |
rl[x].r = hresolu; rl[x].u = vresolu; |
310 |
> |
pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth), |
311 |
|
pframe.d, &ptrunk, rl+x, pdepth); |
312 |
|
} |
313 |
|
/* sample the image */ |
335 |
|
* Find super-pixel at this position in next row. |
336 |
|
*/ |
337 |
|
r.l = r.d = 0; |
338 |
< |
r.r = ourview.hresolu; r.u = ourview.vresolu; |
339 |
< |
p = findrect(pframe.l+((x*ourview.hresolu)>>pdepth), |
340 |
< |
pframe.d+(((y+1)*ourview.vresolu)>>pdepth), |
338 |
> |
r.r = hresolu; r.u = vresolu; |
339 |
> |
p = findrect(pframe.l+((x*hresolu)>>pdepth), |
340 |
> |
pframe.d+(((y+1)*vresolu)>>pdepth), |
341 |
|
&ptrunk, &r, pdepth); |
342 |
|
/* |
343 |
|
* Test super-pixel in next row. |
384 |
|
if (p->kid == NULL) { /* subdivide */ |
385 |
|
|
386 |
|
if ((p->kid = newptree()) == NULL) |
387 |
< |
error(SYSTEM, "out of memory in refine"); |
387 |
> |
return(growth); |
388 |
|
/* |
389 |
|
* The following paint order can leave a black pixel |
390 |
|
* when redraw() is called in (*dev->paintr)(). |