| 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 |
|
|
| 21 |
– |
#include <setjmp.h> |
| 22 |
– |
|
| 19 |
|
#include <ctype.h> |
| 20 |
|
|
| 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 = 32; /* virtual source pretest density */ |
| 38 |
|
|
| 39 |
|
int maxdepth = 4; /* maximum recursion depth */ |
| 40 |
|
double minweight = 1e-2; /* minimum ray weight */ |
| 59 |
|
RECT pframe; /* current frame boundaries */ |
| 60 |
|
int pdepth; /* image depth in current frame */ |
| 61 |
|
|
| 60 |
– |
static jmp_buf mainloop; /* longjmp back to main loop */ |
| 62 |
|
static char *reserve_mem = NULL; /* pre-allocated reserve memory */ |
| 63 |
|
|
| 64 |
|
#define RESERVE_AMT 8192 /* amount of memory to reserve */ |
| 120 |
|
char buf[32]; |
| 121 |
|
|
| 122 |
|
devopen(devname); /* open device */ |
| 123 |
< |
newimage(); /* set up image */ |
| 124 |
< |
setjmp(mainloop); |
| 123 |
> |
newimage(); /* start image (calls fillreserves) */ |
| 124 |
> |
|
| 125 |
|
for ( ; ; ) { /* quit in command() */ |
| 126 |
< |
while (hresolu <= 1<<pdepth && |
| 126 |
< |
vresolu <= 1<<pdepth) |
| 126 |
> |
while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth) |
| 127 |
|
command("done: "); |
| 128 |
< |
|
| 129 |
< |
if (hresolu <= psample<<pdepth && |
| 130 |
< |
vresolu <= psample<<pdepth) { |
| 128 |
> |
while (reserve_mem == NULL) |
| 129 |
> |
command("out of memory: "); |
| 130 |
> |
errno = 0; |
| 131 |
> |
if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) { |
| 132 |
|
sprintf(buf, "%d sampling...\n", 1<<pdepth); |
| 133 |
|
(*dev->comout)(buf); |
| 134 |
|
rsample(); |
| 137 |
|
(*dev->comout)(buf); |
| 138 |
|
refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1); |
| 139 |
|
} |
| 140 |
< |
if (dev->inpready) |
| 140 |
> |
if (errno == ENOMEM) /* ran out of memory */ |
| 141 |
> |
freereserves(); |
| 142 |
> |
else if (dev->inpready) /* noticed some input */ |
| 143 |
|
command(": "); |
| 144 |
< |
else |
| 144 |
> |
else /* finished this depth */ |
| 145 |
|
pdepth++; |
| 146 |
|
} |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
< |
memreserve() /* fill memory reserves */ |
| 150 |
> |
fillreserves() /* fill memory reserves */ |
| 151 |
|
{ |
| 152 |
|
if (reserve_mem != NULL) |
| 153 |
< |
return; /* got some already */ |
| 153 |
> |
return; |
| 154 |
|
reserve_mem = malloc(RESERVE_AMT); |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
< |
memerror(detail) /* try and rescue a memory error */ |
| 156 |
< |
char *detail; |
| 158 |
> |
freereserves() /* free memory reserves */ |
| 159 |
|
{ |
| 160 |
< |
if (reserve_mem == NULL) { |
| 161 |
< |
sprintf(errmsg, "out of memory %s", detail); |
| 160 |
< |
error(SYSTEM, errmsg); |
| 161 |
< |
} |
| 160 |
> |
if (reserve_mem == NULL) |
| 161 |
> |
return; |
| 162 |
|
free(reserve_mem); |
| 163 |
|
reserve_mem = NULL; |
| 164 |
– |
do |
| 165 |
– |
command("out of memory: "); |
| 166 |
– |
while (reserve_mem == NULL); |
| 167 |
– |
longjmp(mainloop, 1); |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
|
| 296 |
|
ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu; |
| 297 |
|
rl = (RECT *)malloc(xsiz*sizeof(RECT)); |
| 298 |
|
if (rl == NULL) |
| 299 |
< |
memerror("in rsample"); |
| 299 |
> |
return; |
| 300 |
|
pl = (PNODE **)malloc(xsiz*sizeof(PNODE *)); |
| 301 |
|
if (pl == NULL) |
| 302 |
< |
memerror("in rsample"); |
| 302 |
> |
return; |
| 303 |
|
/* |
| 304 |
|
* Initialize the bottom row. |
| 305 |
|
*/ |
| 386 |
|
if (p->kid == NULL) { /* subdivide */ |
| 387 |
|
|
| 388 |
|
if ((p->kid = newptree()) == NULL) |
| 389 |
< |
memerror("in refine"); |
| 389 |
> |
return(growth); |
| 390 |
|
/* |
| 391 |
|
* The following paint order can leave a black pixel |
| 392 |
|
* when redraw() is called in (*dev->paintr)(). |