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> |
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 |
|
|
33 |
|
double dstrsrc = 0.0; /* square source distribution */ |
34 |
|
double shadthresh = .1; /* shadow threshold */ |
35 |
|
double shadcert = .25; /* shadow certainty */ |
36 |
+ |
int directrelay = 0; /* number of source relays */ |
37 |
+ |
int vspretest = 128; /* virtual source pretest density */ |
38 |
+ |
int directinvis = 0; /* sources invisible? */ |
39 |
|
|
40 |
|
int maxdepth = 4; /* maximum recursion depth */ |
41 |
|
double minweight = 1e-2; /* minimum ray weight */ |
50 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
51 |
|
|
52 |
|
int greyscale = 0; /* map colors to brightness? */ |
53 |
< |
char *devname = "X"; /* output device name */ |
53 |
> |
char *devname = dev_default; /* output device name */ |
54 |
|
|
55 |
|
struct driver *dev = NULL; /* driver functions */ |
56 |
|
|
60 |
|
RECT pframe; /* current frame boundaries */ |
61 |
|
int pdepth; /* image depth in current frame */ |
62 |
|
|
63 |
+ |
static char *reserve_mem = NULL; /* pre-allocated reserve memory */ |
64 |
+ |
|
65 |
+ |
#define RESERVE_AMT 8192 /* amount of memory to reserve */ |
66 |
+ |
|
67 |
|
#define CTRL(c) ('c'-'@') |
68 |
|
|
69 |
|
|
121 |
|
char buf[32]; |
122 |
|
|
123 |
|
devopen(devname); /* open device */ |
124 |
< |
newimage(); /* set up image */ |
124 |
> |
newimage(); /* start image (calls fillreserves) */ |
125 |
|
|
126 |
|
for ( ; ; ) { /* quit in command() */ |
127 |
< |
while (hresolu <= 1<<pdepth && |
119 |
< |
vresolu <= 1<<pdepth) |
127 |
> |
while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth) |
128 |
|
command("done: "); |
129 |
< |
|
130 |
< |
if (hresolu <= psample<<pdepth && |
131 |
< |
vresolu <= psample<<pdepth) { |
129 |
> |
while (reserve_mem == NULL) |
130 |
> |
command("out of memory: "); |
131 |
> |
errno = 0; |
132 |
> |
if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) { |
133 |
|
sprintf(buf, "%d sampling...\n", 1<<pdepth); |
134 |
|
(*dev->comout)(buf); |
135 |
|
rsample(); |
138 |
|
(*dev->comout)(buf); |
139 |
|
refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1); |
140 |
|
} |
141 |
< |
if (dev->inpready) |
141 |
> |
if (errno == ENOMEM) /* ran out of memory */ |
142 |
> |
freereserves(); |
143 |
> |
else if (dev->inpready) /* noticed some input */ |
144 |
|
command(": "); |
145 |
< |
else |
145 |
> |
else /* finished this depth */ |
146 |
|
pdepth++; |
147 |
|
} |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
+ |
fillreserves() /* fill memory reserves */ |
152 |
+ |
{ |
153 |
+ |
if (reserve_mem != NULL) |
154 |
+ |
return; |
155 |
+ |
reserve_mem = malloc(RESERVE_AMT); |
156 |
+ |
} |
157 |
+ |
|
158 |
+ |
|
159 |
+ |
freereserves() /* free memory reserves */ |
160 |
+ |
{ |
161 |
+ |
if (reserve_mem == NULL) |
162 |
+ |
return; |
163 |
+ |
free(reserve_mem); |
164 |
+ |
reserve_mem = NULL; |
165 |
+ |
} |
166 |
+ |
|
167 |
+ |
|
168 |
|
command(prompt) /* get/execute command */ |
169 |
|
char *prompt; |
170 |
|
{ |
296 |
|
xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu; |
297 |
|
ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu; |
298 |
|
rl = (RECT *)malloc(xsiz*sizeof(RECT)); |
299 |
+ |
if (rl == NULL) |
300 |
+ |
return; |
301 |
|
pl = (PNODE **)malloc(xsiz*sizeof(PNODE *)); |
302 |
< |
if (rl == NULL || pl == NULL) |
303 |
< |
error(SYSTEM, "out of memory in rsample"); |
302 |
> |
if (pl == NULL) |
303 |
> |
return; |
304 |
|
/* |
305 |
|
* Initialize the bottom row. |
306 |
|
*/ |
387 |
|
if (p->kid == NULL) { /* subdivide */ |
388 |
|
|
389 |
|
if ((p->kid = newptree()) == NULL) |
390 |
< |
error(SYSTEM, "out of memory in refine"); |
390 |
> |
return(growth); |
391 |
|
/* |
392 |
|
* The following paint order can leave a black pixel |
393 |
|
* when redraw() is called in (*dev->paintr)(). |