| 13 |
|
|
| 14 |
|
#include "ray.h" |
| 15 |
|
#include "rpaint.h" |
| 16 |
+ |
#include "otypes.h" |
| 17 |
+ |
#include "otspecial.h" |
| 18 |
|
#include "random.h" |
| 19 |
|
|
| 20 |
|
#ifndef WFLUSH |
| 21 |
< |
#define WFLUSH 64 /* flush after this many rays */ |
| 21 |
> |
#define WFLUSH 64 /* flush after this many primary rays */ |
| 22 |
|
#endif |
| 23 |
+ |
#ifndef WFLUSH1 |
| 24 |
+ |
#define WFLUSH1 512 /* or this many total rays */ |
| 25 |
+ |
#endif |
| 26 |
|
|
| 27 |
+ |
|
| 28 |
|
#ifdef SMLFLT |
| 29 |
|
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
| 30 |
|
#else |
| 31 |
|
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
| 32 |
|
#endif |
| 33 |
|
|
| 34 |
+ |
extern int ray_pnprocs; |
| 35 |
|
|
| 36 |
+ |
static RNUMBER niflush; /* flushes since newimage() */ |
| 37 |
+ |
|
| 38 |
|
int |
| 39 |
|
getrect( /* get a box */ |
| 40 |
|
char *s, |
| 91 |
|
double *mp |
| 92 |
|
) |
| 93 |
|
{ |
| 85 |
– |
int x, y; |
| 86 |
– |
RAY thisray; |
| 87 |
– |
int i; |
| 88 |
– |
|
| 94 |
|
if (sscanf(s, "%lf", mp) != 1) |
| 95 |
|
*mp = 1.0; |
| 96 |
|
else if (*mp < -FTINY) /* negative zoom is reduction */ |
| 100 |
|
return(-1); |
| 101 |
|
} |
| 102 |
|
if (!sscanvec(sskip(s), vec)) { |
| 103 |
+ |
RAY thisray; |
| 104 |
+ |
int x, y; |
| 105 |
|
if (dev->getcur == NULL) |
| 106 |
|
return(-1); |
| 107 |
|
(*dev->comout)("Pick view center\n"); |
| 113 |
|
return(-1); |
| 114 |
|
} |
| 115 |
|
if (!direc || ourview.type == VT_PAR) { |
| 116 |
+ |
int weakhit = 0; |
| 117 |
+ |
FVECT weakpt; |
| 118 |
|
rayorigin(&thisray, PRIMARY, NULL, NULL); |
| 119 |
< |
if (!localhit(&thisray, &thescene)) { |
| 120 |
< |
error(COMMAND, "not a local object"); |
| 121 |
< |
return(-1); |
| 119 |
> |
while (localhit(&thisray, &thescene)) { |
| 120 |
> |
OBJREC *m = NULL; |
| 121 |
> |
if (thisray.clipset == NULL || |
| 122 |
> |
!inset(thisray.clipset, |
| 123 |
> |
thisray.ro->omod)) |
| 124 |
> |
m = findmaterial(thisray.ro); |
| 125 |
> |
if ((m != NULL) & !weakhit && |
| 126 |
> |
istransp(m->otype) && |
| 127 |
> |
m->otype != MAT_MIST) { |
| 128 |
> |
weakhit = 1; |
| 129 |
> |
VCOPY(weakpt, thisray.rop); |
| 130 |
> |
} else if (m != NULL && !istransp(m->otype) && |
| 131 |
> |
!isBSDFproxy(m)) |
| 132 |
> |
break; /* something solid */ |
| 133 |
> |
VCOPY(thisray.rorg, thisray.rop); |
| 134 |
> |
rayclear(&thisray); /* skip invisible */ |
| 135 |
|
} |
| 136 |
+ |
if ((thisray.ro == NULL) | (thisray.ro == &Aftplane)) { |
| 137 |
+ |
if (!weakhit) { |
| 138 |
+ |
error(COMMAND, "not a local object"); |
| 139 |
+ |
return(-1); |
| 140 |
+ |
} /* else use weak obj. */ |
| 141 |
+ |
VCOPY(thisray.rop, weakpt); |
| 142 |
+ |
} |
| 143 |
|
} |
| 144 |
|
if (direc) |
| 145 |
|
if (ourview.type == VT_PAR) |
| 146 |
< |
for (i = 0; i < 3; i++) |
| 118 |
< |
vec[i] = thisray.rop[i] - ourview.vp[i]; |
| 146 |
> |
VSUB(vec, thisray.rop, ourview.vp); |
| 147 |
|
else |
| 148 |
|
VCOPY(vec, thisray.rdir); |
| 149 |
|
else |
| 150 |
|
VCOPY(vec, thisray.rop); |
| 151 |
|
} else if (direc) { |
| 152 |
< |
for (i = 0; i < 3; i++) |
| 125 |
< |
vec[i] -= ourview.vp[i]; |
| 152 |
> |
VSUB(vec, vec, ourview.vp); |
| 153 |
|
if (normalize(vec) == 0.0) { |
| 154 |
|
error(COMMAND, "point at view origin"); |
| 155 |
|
return(-1); |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
|
| 162 |
< |
float * /* keep consistent with COLOR typedef */ |
| 162 |
> |
COLORV * |
| 163 |
|
greyof( /* convert color to greyscale */ |
| 164 |
|
COLOR col |
| 165 |
|
) |
| 172 |
|
return(gcol); |
| 173 |
|
} |
| 174 |
|
|
| 175 |
+ |
static void |
| 176 |
+ |
recolor( /* recolor the given node */ |
| 177 |
+ |
PNODE *p |
| 178 |
+ |
) |
| 179 |
+ |
{ |
| 180 |
+ |
while (p->kid != NULL) { /* need to propogate down */ |
| 181 |
+ |
int mx = (p->xmin + p->xmax) >> 1; |
| 182 |
+ |
int my = (p->ymin + p->ymax) >> 1; |
| 183 |
+ |
int ki; |
| 184 |
+ |
if (p->x >= mx) |
| 185 |
+ |
ki = (p->y >= my) ? UR : DR; |
| 186 |
+ |
else |
| 187 |
+ |
ki = (p->y >= my) ? UL : DL; |
| 188 |
+ |
pcopy(p, p->kid+ki); |
| 189 |
+ |
p = p->kid + ki; |
| 190 |
+ |
} |
| 191 |
|
|
| 192 |
+ |
(*dev->paintr)(greyscale?greyof(p->v):p->v, |
| 193 |
+ |
p->xmin, p->ymin, p->xmax, p->ymax); |
| 194 |
+ |
} |
| 195 |
+ |
|
| 196 |
|
int |
| 197 |
|
paint( /* compute and paint a rectangle */ |
| 198 |
|
PNODE *p |
| 199 |
|
) |
| 200 |
|
{ |
| 154 |
– |
extern int ray_pnprocs; |
| 155 |
– |
static unsigned long lastflush = 0; |
| 201 |
|
static RAY thisray; |
| 202 |
|
double h, v; |
| 203 |
|
|
| 204 |
< |
if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0) { /* empty */ |
| 204 |
> |
if ((p->xmax <= p->xmin) | (p->ymax <= p->ymin)) { /* empty */ |
| 205 |
|
p->x = p->xmin; |
| 206 |
|
p->y = p->ymin; |
| 207 |
|
setcolor(p->v, 0.0, 0.0, 0.0); |
| 213 |
|
|
| 214 |
|
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, |
| 215 |
|
h/hresolu, v/vresolu)) < -FTINY) { |
| 216 |
< |
setcolor(thisray.rcol, 0.0, 0.0, 0.0); |
| 217 |
< |
} else { |
| 218 |
< |
int rval; |
| 216 |
> |
scolorblack(thisray.rcol); |
| 217 |
> |
} else if (!ray_pnprocs) { /* immediate mode */ |
| 218 |
> |
ray_trace(&thisray); |
| 219 |
> |
} else { /* queuing mode */ |
| 220 |
> |
int rval; |
| 221 |
|
rayorigin(&thisray, PRIMARY, NULL, NULL); |
| 222 |
< |
thisray.rno = (unsigned long)p; |
| 222 |
> |
thisray.rno = (RNUMBER)p; |
| 223 |
|
rval = ray_pqueue(&thisray); |
| 224 |
|
if (!rval) |
| 225 |
|
return(0); |
| 226 |
|
if (rval < 0) |
| 227 |
|
return(-1); |
| 228 |
+ |
/* get node for returned ray */ |
| 229 |
|
p = (PNODE *)thisray.rno; |
| 230 |
|
} |
| 231 |
|
|
| 232 |
< |
copycolor(p->v, thisray.rcol); |
| 232 |
> |
scolor_rgb(p->v, thisray.rcol); |
| 233 |
|
scalecolor(p->v, exposure); |
| 234 |
|
|
| 235 |
< |
(*dev->paintr)(greyscale?greyof(p->v):p->v, p->xmin, p->ymin, p->xmax, p->ymax); |
| 235 |
> |
recolor(p); /* paint it */ |
| 236 |
|
|
| 237 |
< |
if (dev->flush != NULL && raynum - lastflush >= WFLUSH*ray_pnprocs) { |
| 238 |
< |
lastflush = raynum; |
| 239 |
< |
(*dev->flush)(); |
| 237 |
> |
if (dev->flush != NULL) { /* shall we check for input? */ |
| 238 |
> |
static RNUMBER lastflush = 0; |
| 239 |
> |
RNUMBER counter = raynum; |
| 240 |
> |
int flushintvl; |
| 241 |
> |
if (!ray_pnprocs) { |
| 242 |
> |
counter = nrays; |
| 243 |
> |
flushintvl = WFLUSH1; |
| 244 |
> |
} else if (ambounce == 0) |
| 245 |
> |
flushintvl = ray_pnprocs*WFLUSH; |
| 246 |
> |
else if (niflush < WFLUSH) |
| 247 |
> |
flushintvl = ray_pnprocs*niflush/(ambounce*(ambounce>0)+1); |
| 248 |
> |
else |
| 249 |
> |
flushintvl = ray_pnprocs*WFLUSH/(ambounce*(ambounce>0)+1); |
| 250 |
> |
if (lastflush > counter) |
| 251 |
> |
lastflush = 0; /* counter wrapped */ |
| 252 |
> |
|
| 253 |
> |
if (counter - lastflush >= flushintvl) { |
| 254 |
> |
lastflush = counter; |
| 255 |
> |
(*dev->flush)(); |
| 256 |
> |
niflush++; |
| 257 |
> |
} |
| 258 |
|
} |
| 259 |
|
return(1); |
| 260 |
|
} |
| 261 |
|
|
| 262 |
|
|
| 263 |
|
int |
| 264 |
< |
waitrays(void) /* finish up pending rays */ |
| 264 |
> |
waitrays(void) /* finish up pending rays */ |
| 265 |
|
{ |
| 266 |
|
int nwaited = 0; |
| 267 |
|
int rval; |
| 268 |
|
RAY raydone; |
| 269 |
< |
|
| 269 |
> |
|
| 270 |
> |
if (!ray_pnprocs) /* immediate mode? */ |
| 271 |
> |
return(0); |
| 272 |
|
while ((rval = ray_presult(&raydone, 0)) > 0) { |
| 273 |
|
PNODE *p = (PNODE *)raydone.rno; |
| 274 |
< |
copycolor(p->v, raydone.rcol); |
| 274 |
> |
scolor_rgb(p->v, raydone.rcol); |
| 275 |
|
scalecolor(p->v, exposure); |
| 276 |
< |
(*dev->paintr)(greyscale?greyof(p->v):p->v, |
| 209 |
< |
p->xmin, p->ymin, p->xmax, p->ymax); |
| 276 |
> |
recolor(p); |
| 277 |
|
nwaited++; |
| 278 |
|
} |
| 279 |
|
if (rval < 0) |
| 287 |
|
char *s |
| 288 |
|
) |
| 289 |
|
{ |
| 290 |
< |
int newnp; |
| 291 |
< |
/* change in nproc? */ |
| 292 |
< |
if (s != NULL && sscanf(s, "%d", &newnp) == 1 && newnp > 0) { |
| 293 |
< |
if (!newparam) { |
| 227 |
< |
if (newnp < nproc) |
| 228 |
< |
ray_pclose(nproc - newnp); |
| 229 |
< |
else |
| 230 |
< |
ray_popen(newnp - nproc); |
| 231 |
< |
} |
| 232 |
< |
nproc = newnp; |
| 233 |
< |
} |
| 290 |
> |
int newnp = 0; |
| 291 |
> |
/* # rendering procs arg? */ |
| 292 |
> |
if (s != NULL) |
| 293 |
> |
sscanf(s, "%d", &newnp); |
| 294 |
|
/* free old image */ |
| 295 |
|
freepkids(&ptrunk); |
| 296 |
|
/* compute resolution */ |
| 305 |
|
(*dev->clear)(hresolu, vresolu); |
| 306 |
|
|
| 307 |
|
if (newparam) { /* (re)start rendering procs */ |
| 308 |
< |
ray_pclose(0); |
| 309 |
< |
ray_popen(nproc); |
| 308 |
> |
if (ray_pnprocs) |
| 309 |
> |
ray_pclose(0); /* should already be closed */ |
| 310 |
> |
if (newnp > 0) |
| 311 |
> |
nproc = newnp; |
| 312 |
> |
if (nproc > 1) |
| 313 |
> |
ray_popen(nproc); |
| 314 |
|
newparam = 0; |
| 315 |
+ |
} else if ((newnp > 0) & (newnp != nproc)) { |
| 316 |
+ |
if (newnp == 1) /* change # rendering procs */ |
| 317 |
+ |
ray_pclose(0); |
| 318 |
+ |
else if (newnp < ray_pnprocs) |
| 319 |
+ |
ray_pclose(ray_pnprocs - newnp); |
| 320 |
+ |
else |
| 321 |
+ |
ray_popen(newnp - ray_pnprocs); |
| 322 |
+ |
nproc = newnp; |
| 323 |
|
} |
| 324 |
< |
/* get first value */ |
| 324 |
> |
niflush = 0; /* get first value */ |
| 325 |
|
paint(&ptrunk); |
| 326 |
|
} |
| 327 |
|
|
| 420 |
|
|
| 421 |
|
|
| 422 |
|
void |
| 423 |
+ |
compavg( /* recompute averages */ |
| 424 |
+ |
PNODE *p |
| 425 |
+ |
) |
| 426 |
+ |
{ |
| 427 |
+ |
int i, navg; |
| 428 |
+ |
|
| 429 |
+ |
if (p->kid == NULL) |
| 430 |
+ |
return; |
| 431 |
+ |
|
| 432 |
+ |
setcolor(p->v, .0, .0, .0); |
| 433 |
+ |
navg = 0; |
| 434 |
+ |
for (i = 0; i < 4; i++) { |
| 435 |
+ |
if (p->kid[i].xmin >= p->kid[i].xmax) continue; |
| 436 |
+ |
if (p->kid[i].ymin >= p->kid[i].ymax) continue; |
| 437 |
+ |
compavg(p->kid+i); |
| 438 |
+ |
addcolor(p->v, p->kid[i].v); |
| 439 |
+ |
navg++; |
| 440 |
+ |
} |
| 441 |
+ |
if (navg > 1) |
| 442 |
+ |
scalecolor(p->v, 1./navg); |
| 443 |
+ |
} |
| 444 |
+ |
|
| 445 |
+ |
|
| 446 |
+ |
void |
| 447 |
|
scalepict( /* scale picture values */ |
| 448 |
|
PNODE *p, |
| 449 |
|
double sf |
| 537 |
|
) |
| 538 |
|
{ |
| 539 |
|
double d; |
| 444 |
– |
FVECT v1; |
| 540 |
|
VIEW nv = ourview; |
| 541 |
|
int i; |
| 542 |
|
|
| 543 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
| 544 |
< |
if (elev != 0.0) { |
| 545 |
< |
fcross(v1, ourview.vup, nv.vdir); |
| 546 |
< |
normalize(v1); |
| 452 |
< |
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
| 453 |
< |
} |
| 544 |
> |
if (elev != 0.0) |
| 545 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, elev*(-PI/180.), GEOD_RAD); |
| 546 |
> |
|
| 547 |
|
if (nv.type == VT_PAR) { |
| 548 |
|
nv.horiz /= mag; |
| 549 |
|
nv.vert /= mag; |