| 16 |
|
#include "random.h" |
| 17 |
|
|
| 18 |
|
#ifndef WFLUSH |
| 19 |
< |
#define WFLUSH 64 /* flush after this many rays */ |
| 19 |
> |
#define WFLUSH 64 /* flush after this many primary rays */ |
| 20 |
|
#endif |
| 21 |
+ |
#ifndef WFLUSH1 |
| 22 |
+ |
#define WFLUSH1 512 /* or this many total rays */ |
| 23 |
+ |
#endif |
| 24 |
|
|
| 25 |
+ |
|
| 26 |
|
#ifdef SMLFLT |
| 27 |
|
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
| 28 |
|
#else |
| 29 |
|
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
| 30 |
|
#endif |
| 31 |
|
|
| 32 |
< |
static unsigned long niflush; /* flushes since newimage() */ |
| 32 |
> |
extern int ray_pnprocs; |
| 33 |
|
|
| 34 |
+ |
static RNUMBER niflush; /* flushes since newimage() */ |
| 35 |
+ |
|
| 36 |
|
int |
| 37 |
|
getrect( /* get a box */ |
| 38 |
|
char *s, |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
|
| 142 |
< |
float * /* keep consistent with COLOR typedef */ |
| 142 |
> |
COLORV * |
| 143 |
|
greyof( /* convert color to greyscale */ |
| 144 |
|
COLOR col |
| 145 |
|
) |
| 152 |
|
return(gcol); |
| 153 |
|
} |
| 154 |
|
|
| 155 |
+ |
static void |
| 156 |
+ |
recolor( /* recolor the given node */ |
| 157 |
+ |
PNODE *p |
| 158 |
+ |
) |
| 159 |
+ |
{ |
| 160 |
+ |
while (p->kid != NULL) { /* need to propogate down */ |
| 161 |
+ |
int mx = (p->xmin + p->xmax) >> 1; |
| 162 |
+ |
int my = (p->ymin + p->ymax) >> 1; |
| 163 |
+ |
int ki; |
| 164 |
+ |
if (p->x >= mx) |
| 165 |
+ |
ki = (p->y >= my) ? UR : DR; |
| 166 |
+ |
else |
| 167 |
+ |
ki = (p->y >= my) ? UL : DL; |
| 168 |
+ |
pcopy(p, p->kid+ki); |
| 169 |
+ |
p = p->kid + ki; |
| 170 |
+ |
} |
| 171 |
|
|
| 172 |
+ |
(*dev->paintr)(greyscale?greyof(p->v):p->v, |
| 173 |
+ |
p->xmin, p->ymin, p->xmax, p->ymax); |
| 174 |
+ |
} |
| 175 |
+ |
|
| 176 |
|
int |
| 177 |
|
paint( /* compute and paint a rectangle */ |
| 178 |
|
PNODE *p |
| 179 |
|
) |
| 180 |
|
{ |
| 155 |
– |
extern int ray_pnprocs; |
| 156 |
– |
static unsigned long lastflush = 0; |
| 181 |
|
static RAY thisray; |
| 158 |
– |
int flushintvl; |
| 182 |
|
double h, v; |
| 183 |
|
|
| 184 |
< |
if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0) { /* empty */ |
| 184 |
> |
if ((p->xmax <= p->xmin) | (p->ymax <= p->ymin)) { /* empty */ |
| 185 |
|
p->x = p->xmin; |
| 186 |
|
p->y = p->ymin; |
| 187 |
|
setcolor(p->v, 0.0, 0.0, 0.0); |
| 194 |
|
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, |
| 195 |
|
h/hresolu, v/vresolu)) < -FTINY) { |
| 196 |
|
setcolor(thisray.rcol, 0.0, 0.0, 0.0); |
| 197 |
< |
} else { |
| 198 |
< |
int rval; |
| 197 |
> |
} else if (!ray_pnprocs) { /* immediate mode */ |
| 198 |
> |
ray_trace(&thisray); |
| 199 |
> |
} else { /* queuing mode */ |
| 200 |
> |
int rval; |
| 201 |
|
rayorigin(&thisray, PRIMARY, NULL, NULL); |
| 202 |
< |
thisray.rno = (unsigned long)p; |
| 202 |
> |
thisray.rno = (RNUMBER)p; |
| 203 |
|
rval = ray_pqueue(&thisray); |
| 204 |
|
if (!rval) |
| 205 |
|
return(0); |
| 206 |
|
if (rval < 0) |
| 207 |
|
return(-1); |
| 208 |
+ |
/* get node for returned ray */ |
| 209 |
|
p = (PNODE *)thisray.rno; |
| 210 |
|
} |
| 211 |
|
|
| 212 |
|
copycolor(p->v, thisray.rcol); |
| 213 |
|
scalecolor(p->v, exposure); |
| 214 |
|
|
| 215 |
< |
(*dev->paintr)(greyscale?greyof(p->v):p->v, |
| 190 |
< |
p->xmin, p->ymin, p->xmax, p->ymax); |
| 215 |
> |
recolor(p); /* paint it */ |
| 216 |
|
|
| 217 |
< |
if (ambounce <= 0) /* shall we check for input? */ |
| 218 |
< |
flushintvl = ray_pnprocs*WFLUSH; |
| 219 |
< |
else if (niflush < WFLUSH) |
| 220 |
< |
flushintvl = ray_pnprocs*niflush/(ambounce+1); |
| 221 |
< |
else |
| 222 |
< |
flushintvl = ray_pnprocs*WFLUSH/(ambounce+1); |
| 217 |
> |
if (dev->flush != NULL) { /* shall we check for input? */ |
| 218 |
> |
static RNUMBER lastflush = 0; |
| 219 |
> |
RNUMBER counter = raynum; |
| 220 |
> |
int flushintvl; |
| 221 |
> |
if (!ray_pnprocs) { |
| 222 |
> |
counter = nrays; |
| 223 |
> |
flushintvl = WFLUSH1; |
| 224 |
> |
} else if (ambounce == 0) |
| 225 |
> |
flushintvl = ray_pnprocs*WFLUSH; |
| 226 |
> |
else if (niflush < WFLUSH) |
| 227 |
> |
flushintvl = ray_pnprocs*niflush/(ambounce+1); |
| 228 |
> |
else |
| 229 |
> |
flushintvl = ray_pnprocs*WFLUSH/(ambounce+1); |
| 230 |
> |
if (lastflush > counter) |
| 231 |
> |
lastflush = 0; /* counter wrapped */ |
| 232 |
|
|
| 233 |
< |
if (dev->flush != NULL && raynum - lastflush >= flushintvl) { |
| 234 |
< |
lastflush = raynum; |
| 235 |
< |
(*dev->flush)(); |
| 236 |
< |
niflush++; |
| 233 |
> |
if (counter - lastflush >= flushintvl) { |
| 234 |
> |
lastflush = counter; |
| 235 |
> |
(*dev->flush)(); |
| 236 |
> |
niflush++; |
| 237 |
> |
} |
| 238 |
|
} |
| 239 |
|
return(1); |
| 240 |
|
} |
| 246 |
|
int nwaited = 0; |
| 247 |
|
int rval; |
| 248 |
|
RAY raydone; |
| 249 |
< |
|
| 249 |
> |
|
| 250 |
> |
if (!ray_pnprocs) /* immediate mode? */ |
| 251 |
> |
return(0); |
| 252 |
|
while ((rval = ray_presult(&raydone, 0)) > 0) { |
| 253 |
|
PNODE *p = (PNODE *)raydone.rno; |
| 254 |
|
copycolor(p->v, raydone.rcol); |
| 255 |
|
scalecolor(p->v, exposure); |
| 256 |
< |
(*dev->paintr)(greyscale?greyof(p->v):p->v, |
| 220 |
< |
p->xmin, p->ymin, p->xmax, p->ymax); |
| 256 |
> |
recolor(p); |
| 257 |
|
nwaited++; |
| 258 |
|
} |
| 259 |
|
if (rval < 0) |
| 267 |
|
char *s |
| 268 |
|
) |
| 269 |
|
{ |
| 270 |
< |
int newnp; |
| 271 |
< |
/* change in nproc? */ |
| 272 |
< |
if (s != NULL && sscanf(s, "%d", &newnp) == 1 && newnp > 0) { |
| 273 |
< |
if (!newparam) { |
| 238 |
< |
if (newnp < nproc) |
| 239 |
< |
ray_pclose(nproc - newnp); |
| 240 |
< |
else |
| 241 |
< |
ray_popen(newnp - nproc); |
| 242 |
< |
} |
| 243 |
< |
nproc = newnp; |
| 244 |
< |
} |
| 270 |
> |
int newnp = 0; |
| 271 |
> |
/* # rendering procs arg? */ |
| 272 |
> |
if (s != NULL) |
| 273 |
> |
sscanf(s, "%d", &newnp); |
| 274 |
|
/* free old image */ |
| 275 |
|
freepkids(&ptrunk); |
| 276 |
|
/* compute resolution */ |
| 285 |
|
(*dev->clear)(hresolu, vresolu); |
| 286 |
|
|
| 287 |
|
if (newparam) { /* (re)start rendering procs */ |
| 288 |
< |
ray_pclose(0); |
| 289 |
< |
ray_popen(nproc); |
| 288 |
> |
if (ray_pnprocs) |
| 289 |
> |
ray_pclose(0); /* should already be closed */ |
| 290 |
> |
if (newnp > 0) |
| 291 |
> |
nproc = newnp; |
| 292 |
> |
if (nproc > 1) |
| 293 |
> |
ray_popen(nproc); |
| 294 |
|
newparam = 0; |
| 295 |
+ |
} else if ((newnp > 0) & (newnp != nproc)) { |
| 296 |
+ |
if (newnp == 1) /* change # rendering procs */ |
| 297 |
+ |
ray_pclose(0); |
| 298 |
+ |
else if (newnp < ray_pnprocs) |
| 299 |
+ |
ray_pclose(ray_pnprocs - newnp); |
| 300 |
+ |
else |
| 301 |
+ |
ray_popen(newnp - ray_pnprocs); |
| 302 |
+ |
nproc = newnp; |
| 303 |
|
} |
| 304 |
|
niflush = 0; /* get first value */ |
| 305 |
|
paint(&ptrunk); |
| 400 |
|
|
| 401 |
|
|
| 402 |
|
void |
| 403 |
+ |
compavg( /* recompute averages */ |
| 404 |
+ |
PNODE *p |
| 405 |
+ |
) |
| 406 |
+ |
{ |
| 407 |
+ |
int i, navg; |
| 408 |
+ |
|
| 409 |
+ |
if (p->kid == NULL) |
| 410 |
+ |
return; |
| 411 |
+ |
|
| 412 |
+ |
setcolor(p->v, .0, .0, .0); |
| 413 |
+ |
navg = 0; |
| 414 |
+ |
for (i = 0; i < 4; i++) { |
| 415 |
+ |
if (p->kid[i].xmin >= p->kid[i].xmax) continue; |
| 416 |
+ |
if (p->kid[i].ymin >= p->kid[i].ymax) continue; |
| 417 |
+ |
compavg(p->kid+i); |
| 418 |
+ |
addcolor(p->v, p->kid[i].v); |
| 419 |
+ |
navg++; |
| 420 |
+ |
} |
| 421 |
+ |
if (navg > 1) |
| 422 |
+ |
scalecolor(p->v, 1./navg); |
| 423 |
+ |
} |
| 424 |
+ |
|
| 425 |
+ |
|
| 426 |
+ |
void |
| 427 |
|
scalepict( /* scale picture values */ |
| 428 |
|
PNODE *p, |
| 429 |
|
double sf |
| 517 |
|
) |
| 518 |
|
{ |
| 519 |
|
double d; |
| 455 |
– |
FVECT v1; |
| 520 |
|
VIEW nv = ourview; |
| 521 |
|
int i; |
| 522 |
|
|
| 523 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
| 524 |
< |
if (elev != 0.0) { |
| 525 |
< |
fcross(v1, ourview.vup, nv.vdir); |
| 526 |
< |
normalize(v1); |
| 463 |
< |
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
| 464 |
< |
} |
| 524 |
> |
if (elev != 0.0) |
| 525 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, elev*(-PI/180.), GEOD_RAD); |
| 526 |
> |
|
| 527 |
|
if (nv.type == VT_PAR) { |
| 528 |
|
nv.horiz /= mag; |
| 529 |
|
nv.vert /= mag; |