| 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 |
|
|
| 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 */ |
| 49 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
| 50 |
|
|
| 51 |
|
int greyscale = 0; /* map colors to brightness? */ |
| 52 |
< |
char *devname = "X"; /* output device name */ |
| 52 |
> |
char *devname = dev_default; /* output device name */ |
| 53 |
|
|
| 54 |
|
struct driver *dev = NULL; /* driver functions */ |
| 55 |
|
|
| 59 |
|
RECT pframe; /* current frame boundaries */ |
| 60 |
|
int pdepth; /* image depth in current frame */ |
| 61 |
|
|
| 62 |
+ |
static char *reserve_mem = NULL; /* pre-allocated reserve memory */ |
| 63 |
+ |
|
| 64 |
+ |
#define RESERVE_AMT 8192 /* amount of memory to reserve */ |
| 65 |
+ |
|
| 66 |
|
#define CTRL(c) ('c'-'@') |
| 67 |
|
|
| 68 |
|
|
| 77 |
|
devopen(dname) /* open device driver */ |
| 78 |
|
char *dname; |
| 79 |
|
{ |
| 80 |
< |
extern char *progname; |
| 81 |
< |
char *devargv[3]; |
| 80 |
> |
extern char *progname, *octname; |
| 81 |
> |
char *id; |
| 82 |
|
register int i; |
| 83 |
+ |
|
| 84 |
+ |
id = octname!=NULL ? octname : progname; |
| 85 |
|
/* check device table */ |
| 86 |
|
for (i = 0; devtable[i].name; i++) |
| 87 |
|
if (!strcmp(dname, devtable[i].name)) |
| 88 |
< |
if ((dev = (*devtable[i].init)(progname)) == NULL) { |
| 88 |
> |
if ((dev = (*devtable[i].init)(dname, id)) == NULL) { |
| 89 |
|
sprintf(errmsg, "cannot initialize %s", dname); |
| 90 |
|
error(USER, errmsg); |
| 91 |
|
} else |
| 92 |
|
return; |
| 93 |
|
/* not there, try exec */ |
| 94 |
< |
devargv[0] = dname; |
| 84 |
< |
devargv[1] = progname; |
| 85 |
< |
devargv[2] = NULL; |
| 86 |
< |
if ((dev = comm_init(devargv)) == NULL) { |
| 94 |
> |
if ((dev = comm_init(dname, id)) == NULL) { |
| 95 |
|
sprintf(errmsg, "cannot start device \"%s\"", dname); |
| 96 |
|
error(USER, errmsg); |
| 97 |
|
} |
| 120 |
|
char buf[32]; |
| 121 |
|
|
| 122 |
|
devopen(devname); /* open device */ |
| 123 |
< |
newimage(); /* set up image */ |
| 123 |
> |
newimage(); /* start image (calls fillreserves) */ |
| 124 |
|
|
| 125 |
|
for ( ; ; ) { /* quit in command() */ |
| 126 |
< |
while (ourview.hresolu <= 1<<pdepth && |
| 119 |
< |
ourview.vresolu <= 1<<pdepth) |
| 126 |
> |
while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth) |
| 127 |
|
command("done: "); |
| 128 |
< |
|
| 129 |
< |
if (ourview.hresolu <= psample<<pdepth && |
| 130 |
< |
ourview.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(); |
| 135 |
|
} else { |
| 136 |
|
sprintf(buf, "%d refining...\n", 1<<pdepth); |
| 137 |
|
(*dev->comout)(buf); |
| 138 |
< |
refine(&ptrunk, 0, 0, ourview.hresolu, |
| 131 |
< |
ourview.vresolu, pdepth+1); |
| 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 |
+ |
fillreserves() /* fill memory reserves */ |
| 151 |
+ |
{ |
| 152 |
+ |
if (reserve_mem != NULL) |
| 153 |
+ |
return; |
| 154 |
+ |
reserve_mem = malloc(RESERVE_AMT); |
| 155 |
+ |
} |
| 156 |
+ |
|
| 157 |
+ |
|
| 158 |
+ |
freereserves() /* free memory reserves */ |
| 159 |
+ |
{ |
| 160 |
+ |
if (reserve_mem == NULL) |
| 161 |
+ |
return; |
| 162 |
+ |
free(reserve_mem); |
| 163 |
+ |
reserve_mem = NULL; |
| 164 |
+ |
} |
| 165 |
+ |
|
| 166 |
+ |
|
| 167 |
|
command(prompt) /* get/execute command */ |
| 168 |
|
char *prompt; |
| 169 |
|
{ |
| 172 |
|
char inpbuf[256]; |
| 173 |
|
char *args; |
| 174 |
|
again: |
| 175 |
< |
(*dev->comout)(prompt); /* get command + arguments */ |
| 150 |
< |
(*dev->comin)(inpbuf); |
| 175 |
> |
(*dev->comin)(inpbuf, prompt); /* get command + arguments */ |
| 176 |
|
for (args = inpbuf; *args && *args != ' '; args++) |
| 177 |
|
; |
| 178 |
|
if (*args) *args++ = '\0'; |
| 224 |
|
goto commerr; |
| 225 |
|
getmove(args); |
| 226 |
|
break; |
| 227 |
< |
case 'r': /* rotate camera */ |
| 228 |
< |
if (badcom("rotate")) |
| 229 |
< |
goto commerr; |
| 227 |
> |
case 'r': /* rotate/repaint */ |
| 228 |
> |
if (badcom("rotate")) { |
| 229 |
> |
if (badcom("repaint")) |
| 230 |
> |
goto commerr; |
| 231 |
> |
getrepaint(args); |
| 232 |
> |
break; |
| 233 |
> |
} |
| 234 |
|
getrotate(args); |
| 235 |
|
break; |
| 236 |
|
case 'p': /* pivot view */ |
| 292 |
|
* difference, we subsample the super-pixels. The testing process |
| 293 |
|
* includes initialization of the next row. |
| 294 |
|
*/ |
| 295 |
< |
xsiz = (((pframe.r-pframe.l)<<pdepth)+ourview.hresolu-1) / |
| 296 |
< |
ourview.hresolu; |
| 268 |
< |
ysiz = (((pframe.u-pframe.d)<<pdepth)+ourview.vresolu-1) / |
| 269 |
< |
ourview.vresolu; |
| 295 |
> |
xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu; |
| 296 |
> |
ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu; |
| 297 |
|
rl = (RECT *)malloc(xsiz*sizeof(RECT)); |
| 298 |
+ |
if (rl == NULL) |
| 299 |
+ |
return; |
| 300 |
|
pl = (PNODE **)malloc(xsiz*sizeof(PNODE *)); |
| 301 |
< |
if (rl == NULL || pl == NULL) |
| 302 |
< |
error(SYSTEM, "out of memory in rsample"); |
| 301 |
> |
if (pl == NULL) |
| 302 |
> |
return; |
| 303 |
|
/* |
| 304 |
|
* Initialize the bottom row. |
| 305 |
|
*/ |
| 306 |
|
rl[0].l = rl[0].d = 0; |
| 307 |
< |
rl[0].r = ourview.hresolu; rl[0].u = ourview.vresolu; |
| 307 |
> |
rl[0].r = hresolu; rl[0].u = vresolu; |
| 308 |
|
pl[0] = findrect(pframe.l, pframe.d, &ptrunk, rl, pdepth); |
| 309 |
|
for (x = 1; x < xsiz; x++) { |
| 310 |
|
rl[x].l = rl[x].d = 0; |
| 311 |
< |
rl[x].r = ourview.hresolu; rl[x].u = ourview.vresolu; |
| 312 |
< |
pl[x] = findrect(pframe.l+((x*ourview.hresolu)>>pdepth), |
| 311 |
> |
rl[x].r = hresolu; rl[x].u = vresolu; |
| 312 |
> |
pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth), |
| 313 |
|
pframe.d, &ptrunk, rl+x, pdepth); |
| 314 |
|
} |
| 315 |
|
/* sample the image */ |
| 337 |
|
* Find super-pixel at this position in next row. |
| 338 |
|
*/ |
| 339 |
|
r.l = r.d = 0; |
| 340 |
< |
r.r = ourview.hresolu; r.u = ourview.vresolu; |
| 341 |
< |
p = findrect(pframe.l+((x*ourview.hresolu)>>pdepth), |
| 342 |
< |
pframe.d+(((y+1)*ourview.vresolu)>>pdepth), |
| 340 |
> |
r.r = hresolu; r.u = vresolu; |
| 341 |
> |
p = findrect(pframe.l+((x*hresolu)>>pdepth), |
| 342 |
> |
pframe.d+(((y+1)*vresolu)>>pdepth), |
| 343 |
|
&ptrunk, &r, pdepth); |
| 344 |
|
/* |
| 345 |
|
* Test super-pixel in next row. |
| 386 |
|
if (p->kid == NULL) { /* subdivide */ |
| 387 |
|
|
| 388 |
|
if ((p->kid = newptree()) == NULL) |
| 389 |
< |
error(SYSTEM, "out of memory in refine"); |
| 389 |
> |
return(growth); |
| 390 |
|
/* |
| 391 |
|
* The following paint order can leave a black pixel |
| 392 |
|
* when redraw() is called in (*dev->paintr)(). |