| 1 |
– |
/* Copyright (c) 1996 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Draw small sources into image in case we missed them. |
| 6 |
+ |
* |
| 7 |
+ |
* External symbols declared in ray.h |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
+ |
/* ==================================================================== |
| 11 |
+ |
* The Radiance Software License, Version 1.0 |
| 12 |
+ |
* |
| 13 |
+ |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
| 14 |
+ |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
| 15 |
+ |
* |
| 16 |
+ |
* Redistribution and use in source and binary forms, with or without |
| 17 |
+ |
* modification, are permitted provided that the following conditions |
| 18 |
+ |
* are met: |
| 19 |
+ |
* |
| 20 |
+ |
* 1. Redistributions of source code must retain the above copyright |
| 21 |
+ |
* notice, this list of conditions and the following disclaimer. |
| 22 |
+ |
* |
| 23 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright |
| 24 |
+ |
* notice, this list of conditions and the following disclaimer in |
| 25 |
+ |
* the documentation and/or other materials provided with the |
| 26 |
+ |
* distribution. |
| 27 |
+ |
* |
| 28 |
+ |
* 3. The end-user documentation included with the redistribution, |
| 29 |
+ |
* if any, must include the following acknowledgment: |
| 30 |
+ |
* "This product includes Radiance software |
| 31 |
+ |
* (http://radsite.lbl.gov/) |
| 32 |
+ |
* developed by the Lawrence Berkeley National Laboratory |
| 33 |
+ |
* (http://www.lbl.gov/)." |
| 34 |
+ |
* Alternately, this acknowledgment may appear in the software itself, |
| 35 |
+ |
* if and wherever such third-party acknowledgments normally appear. |
| 36 |
+ |
* |
| 37 |
+ |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
| 38 |
+ |
* and "The Regents of the University of California" must |
| 39 |
+ |
* not be used to endorse or promote products derived from this |
| 40 |
+ |
* software without prior written permission. For written |
| 41 |
+ |
* permission, please contact [email protected]. |
| 42 |
+ |
* |
| 43 |
+ |
* 5. Products derived from this software may not be called "Radiance", |
| 44 |
+ |
* nor may "Radiance" appear in their name, without prior written |
| 45 |
+ |
* permission of Lawrence Berkeley National Laboratory. |
| 46 |
+ |
* |
| 47 |
+ |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
| 48 |
+ |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 49 |
+ |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 50 |
+ |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
| 51 |
+ |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 52 |
+ |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 53 |
+ |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 54 |
+ |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 55 |
+ |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 56 |
+ |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 57 |
+ |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 58 |
+ |
* SUCH DAMAGE. |
| 59 |
+ |
* ==================================================================== |
| 60 |
+ |
* |
| 61 |
+ |
* This software consists of voluntary contributions made by many |
| 62 |
+ |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
| 63 |
+ |
* information on Lawrence Berkeley National Laboratory, please see |
| 64 |
+ |
* <http://www.lbl.gov/>. |
| 65 |
+ |
*/ |
| 66 |
+ |
|
| 67 |
|
#include "ray.h" |
| 68 |
|
|
| 69 |
|
#include "view.h" |
| 78 |
|
|
| 79 |
|
#define MAXVERT 10 |
| 80 |
|
|
| 81 |
+ |
typedef struct splist { |
| 82 |
+ |
struct splist *next; /* next source in list */ |
| 83 |
+ |
int sn; /* source number */ |
| 84 |
+ |
short nv; /* number of vertices */ |
| 85 |
+ |
FLOAT vl[3][2]; /* vertex array (last) */ |
| 86 |
+ |
} SPLIST; /* source polygon list */ |
| 87 |
|
|
| 88 |
+ |
extern VIEW ourview; /* our view parameters */ |
| 89 |
+ |
extern int hres, vres; /* our image resolution */ |
| 90 |
+ |
static SPLIST *sphead = NULL; /* our list of source polys */ |
| 91 |
+ |
|
| 92 |
+ |
|
| 93 |
|
static int |
| 94 |
|
inregion(p, cv, crit) /* check if vertex is in region */ |
| 95 |
|
FLOAT p[2]; |
| 287 |
|
} |
| 288 |
|
|
| 289 |
|
|
| 290 |
+ |
static |
| 291 |
+ |
spinsert(sn, vl, nv) /* insert new source polygon */ |
| 292 |
+ |
int sn; |
| 293 |
+ |
FLOAT vl[][2]; |
| 294 |
+ |
int nv; |
| 295 |
+ |
{ |
| 296 |
+ |
register SPLIST *spn; |
| 297 |
+ |
register int i; |
| 298 |
+ |
|
| 299 |
+ |
if (nv < 3) |
| 300 |
+ |
return; |
| 301 |
+ |
if (nv > 3) |
| 302 |
+ |
spn = (SPLIST *)malloc(sizeof(SPLIST)+sizeof(FLOAT)*2*(nv-3)); |
| 303 |
+ |
else |
| 304 |
+ |
spn = (SPLIST *)malloc(sizeof(SPLIST)); |
| 305 |
+ |
if (spn == NULL) |
| 306 |
+ |
error(SYSTEM, "out of memory in spinsert"); |
| 307 |
+ |
spn->sn = sn; |
| 308 |
+ |
for (i = spn->nv = nv; i--; ) { |
| 309 |
+ |
spn->vl[i][0] = vl[i][0]; spn->vl[i][1] = vl[i][1]; |
| 310 |
+ |
} |
| 311 |
+ |
spn->next = sphead; /* push onto global list */ |
| 312 |
+ |
sphead = spn; |
| 313 |
+ |
} |
| 314 |
+ |
|
| 315 |
+ |
|
| 316 |
|
int |
| 317 |
< |
sourcepoly(vw, sn, sp) /* compute image polygon for source */ |
| 225 |
< |
VIEW *vw; |
| 317 |
> |
sourcepoly(sn, sp) /* compute image polygon for source */ |
| 318 |
|
int sn; |
| 319 |
|
FLOAT sp[MAXVERT][2]; |
| 320 |
|
{ |
| 329 |
|
register int i, j; |
| 330 |
|
|
| 331 |
|
if (s->sflags & (SDISTANT|SFLAT)) { |
| 332 |
< |
if (s->sflags & SDISTANT && vw->type == VT_PAR) |
| 332 |
> |
if (s->sflags & SDISTANT && ourview.type == VT_PAR) |
| 333 |
|
return(0); /* all or nothing case */ |
| 334 |
|
if (s->sflags & SFLAT) { |
| 335 |
|
for (i = 0; i < 3; i++) |
| 336 |
< |
ap[i] = s->sloc[i] - vw->vp[i]; |
| 336 |
> |
ap[i] = s->sloc[i] - ourview.vp[i]; |
| 337 |
|
if (DOT(ap, s->snorm) >= 0.) |
| 338 |
|
return(0); /* source faces away */ |
| 339 |
|
} |
| 345 |
|
if (j==2|j==3) ap[i] += s->ss[SV][i]; |
| 346 |
|
else ap[i] -= s->ss[SV][i]; |
| 347 |
|
if (s->sflags & SDISTANT) { |
| 348 |
< |
ap[i] *= 1. + vw->vfore; |
| 349 |
< |
ap[i] += vw->vp[i]; |
| 348 |
> |
ap[i] *= 1. + ourview.vfore; |
| 349 |
> |
ap[i] += ourview.vp[i]; |
| 350 |
|
} |
| 351 |
|
} |
| 352 |
< |
viewloc(ip, vw, ap); /* find image point */ |
| 352 |
> |
viewloc(ip, &ourview, ap); /* find image point */ |
| 353 |
|
if (ip[2] <= 0.) |
| 354 |
|
return(0); /* in front of view */ |
| 355 |
|
sp[j][0] = ip[0]; sp[j][1] = ip[1]; |
| 358 |
|
} |
| 359 |
|
/* identify furthest corner */ |
| 360 |
|
for (i = 0; i < 3; i++) |
| 361 |
< |
ap[i] = s->sloc[i] - vw->vp[i]; |
| 361 |
> |
ap[i] = s->sloc[i] - ourview.vp[i]; |
| 362 |
|
dir = (DOT(ap,s->ss[SU])>0.) | |
| 363 |
|
(DOT(ap,s->ss[SV])>0.)<<1 | |
| 364 |
|
(DOT(ap,s->ss[SW])>0.)<<2 ; |
| 373 |
|
if (cubeord[dir][j] & 4) ap[i] += s->ss[SW][i]; |
| 374 |
|
else ap[i] -= s->ss[SW][i]; |
| 375 |
|
} |
| 376 |
< |
viewloc(ip, vw, ap); /* find image point */ |
| 376 |
> |
viewloc(ip, &ourview, ap); /* find image point */ |
| 377 |
|
if (ip[2] <= 0.) |
| 378 |
|
return(0); /* in front of view */ |
| 379 |
|
pt[j][0] = ip[0]; pt[j][1] = ip[1]; |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
|
| 385 |
< |
/* add sources smaller than rad to computed subimage */ |
| 386 |
< |
drawsources(vw, xr, yr, pic, zbf, x0, xsiz, y0, ysiz, rad) |
| 387 |
< |
VIEW *vw; /* full image view */ |
| 388 |
< |
int xr, yr; /* full image dimensions */ |
| 385 |
> |
/* initialize by finding sources smaller than rad */ |
| 386 |
> |
init_drawsources(rad) |
| 387 |
> |
int rad; /* source sample size */ |
| 388 |
> |
{ |
| 389 |
> |
FLOAT spoly[MAXVERT][2]; |
| 390 |
> |
int nsv; |
| 391 |
> |
register SPLIST *sp; |
| 392 |
> |
register int i; |
| 393 |
> |
/* free old source list if one */ |
| 394 |
> |
for (sp = sphead; sp != NULL; sp = sphead) { |
| 395 |
> |
sphead = sp->next; |
| 396 |
> |
free((void *)sp); |
| 397 |
> |
} |
| 398 |
> |
/* loop through all sources */ |
| 399 |
> |
for (i = nsources; i--; ) { |
| 400 |
> |
/* compute image polygon for source */ |
| 401 |
> |
if (!(nsv = sourcepoly(i, spoly))) |
| 402 |
> |
continue; |
| 403 |
> |
/* clip to image boundaries */ |
| 404 |
> |
if (!(nsv = box_clip_poly(spoly, nsv, 0., 1., 0., 1., spoly))) |
| 405 |
> |
continue; |
| 406 |
> |
/* big enough for standard sampling? */ |
| 407 |
> |
if (minw2(spoly, nsv, ourview.vn2/ourview.hn2) > |
| 408 |
> |
(double)rad*rad/hres/hres) |
| 409 |
> |
continue; |
| 410 |
> |
/* OK, add to our list */ |
| 411 |
> |
spinsert(i, spoly, nsv); |
| 412 |
> |
} |
| 413 |
> |
} |
| 414 |
> |
|
| 415 |
> |
void /* add sources smaller than rad to computed subimage */ |
| 416 |
> |
drawsources(pic, zbf, x0, xsiz, y0, ysiz) |
| 417 |
|
COLOR *pic[]; /* subimage pixel value array */ |
| 418 |
|
float *zbf[]; /* subimage distance array (opt.) */ |
| 419 |
|
int x0, xsiz, y0, ysiz; /* origin and size of subimage */ |
| 300 |
– |
int rad; /* source sample size */ |
| 420 |
|
{ |
| 302 |
– |
int sn; |
| 421 |
|
FLOAT spoly[MAXVERT][2], ppoly[MAXVERT][2]; |
| 422 |
|
int nsv, npv; |
| 423 |
< |
int xmin, xmax, ymin, ymax, x, y, i; |
| 423 |
> |
int xmin, xmax, ymin, ymax, x, y; |
| 424 |
|
FLOAT cxy[2]; |
| 425 |
< |
double pa; |
| 425 |
> |
double w; |
| 426 |
|
RAY sr; |
| 427 |
< |
/* loop through all sources */ |
| 428 |
< |
for (sn = 0; sn < nsources; sn++) { |
| 429 |
< |
/* compute image polygon for source */ |
| 430 |
< |
if (!(nsv = sourcepoly(vw, sn, spoly))) |
| 313 |
< |
continue; |
| 314 |
< |
/* big enough for standard sampling? */ |
| 315 |
< |
if (minw2(spoly, nsv, vw->vn2/vw->hn2) > (double)rad*rad/xr/xr) |
| 316 |
< |
continue; |
| 427 |
> |
register SPLIST *sp; |
| 428 |
> |
register int i; |
| 429 |
> |
/* check each source in our list */ |
| 430 |
> |
for (sp = sphead; sp != NULL; sp = sp->next) { |
| 431 |
|
/* clip source poly to subimage */ |
| 432 |
< |
nsv = box_clip_poly(spoly, nsv, |
| 433 |
< |
(double)x0/xr, (double)(x0+xsiz)/xr, |
| 434 |
< |
(double)y0/yr, (double)(y0+ysiz)/yr, spoly); |
| 432 |
> |
nsv = box_clip_poly(sp->vl, sp->nv, |
| 433 |
> |
(double)x0/hres, (double)(x0+xsiz)/hres, |
| 434 |
> |
(double)y0/vres, (double)(y0+ysiz)/vres, spoly); |
| 435 |
|
if (!nsv) |
| 436 |
|
continue; |
| 437 |
|
/* find common subimage (BBox) */ |
| 438 |
|
xmin = x0 + xsiz; xmax = x0; |
| 439 |
|
ymin = y0 + ysiz; ymax = y0; |
| 440 |
|
for (i = 0; i < nsv; i++) { |
| 441 |
< |
if ((double)xmin/xr > spoly[i][0]) |
| 442 |
< |
xmin = spoly[i][0]*xr + FTINY; |
| 443 |
< |
if ((double)xmax/xr < spoly[i][0]) |
| 444 |
< |
xmax = spoly[i][0]*xr - FTINY; |
| 445 |
< |
if ((double)ymin/yr > spoly[i][1]) |
| 446 |
< |
ymin = spoly[i][1]*yr + FTINY; |
| 447 |
< |
if ((double)ymax/yr < spoly[i][1]) |
| 448 |
< |
ymax = spoly[i][1]*yr - FTINY; |
| 441 |
> |
if ((double)xmin/hres > spoly[i][0]) |
| 442 |
> |
xmin = spoly[i][0]*hres + FTINY; |
| 443 |
> |
if ((double)xmax/hres < spoly[i][0]) |
| 444 |
> |
xmax = spoly[i][0]*hres - FTINY; |
| 445 |
> |
if ((double)ymin/vres > spoly[i][1]) |
| 446 |
> |
ymin = spoly[i][1]*vres + FTINY; |
| 447 |
> |
if ((double)ymax/vres < spoly[i][1]) |
| 448 |
> |
ymax = spoly[i][1]*vres - FTINY; |
| 449 |
|
} |
| 450 |
|
/* evaluate each pixel in BBox */ |
| 451 |
|
for (y = ymin; y <= ymax; y++) |
| 452 |
|
for (x = xmin; x <= xmax; x++) { |
| 453 |
|
/* subarea for pixel */ |
| 454 |
|
npv = box_clip_poly(spoly, nsv, |
| 455 |
< |
(double)x/xr, (x+1.)/xr, |
| 456 |
< |
(double)y/yr, (y+1.)/yr, ppoly); |
| 455 |
> |
(double)x/hres, (x+1.)/hres, |
| 456 |
> |
(double)y/vres, (y+1.)/vres, |
| 457 |
> |
ppoly); |
| 458 |
|
if (!npv) |
| 459 |
|
continue; /* no overlap */ |
| 460 |
|
convex_center(ppoly, npv, cxy); |
| 461 |
< |
if ((sr.rmax = viewray(sr.rorg, sr.rdir, vw, |
| 462 |
< |
cxy[0], cxy[1])) < -FTINY) |
| 461 |
> |
if ((sr.rmax = viewray(sr.rorg,sr.rdir,&ourview, |
| 462 |
> |
cxy[0],cxy[1])) < -FTINY) |
| 463 |
|
continue; /* not in view */ |
| 464 |
< |
if (source[sn].sflags & SSPOT && |
| 465 |
< |
spotout(&sr, source[sn].sl.s)) |
| 464 |
> |
if (source[sp->sn].sflags & SSPOT && |
| 465 |
> |
spotout(&sr, source[sp->sn].sl.s)) |
| 466 |
|
continue; /* outside spot */ |
| 467 |
|
rayorigin(&sr, NULL, SHADOW, 1.0); |
| 468 |
< |
sr.rsrc = sn; |
| 468 |
> |
sr.rsrc = sp->sn; |
| 469 |
|
rayvalue(&sr); /* compute value */ |
| 470 |
|
if (bright(sr.rcol) <= FTINY) |
| 471 |
|
continue; /* missed/blocked */ |
| 472 |
|
/* modify pixel */ |
| 473 |
|
if (zbf[y-y0] != NULL && |
| 474 |
< |
sr.rt < zbf[y-y0][x-x0]) |
| 474 |
> |
sr.rt < 0.999*zbf[y-y0][x-x0]) |
| 475 |
|
zbf[y-y0][x-x0] = sr.rt; |
| 476 |
< |
pa = poly_area(ppoly, npv); |
| 477 |
< |
scalecolor(sr.rcol, pa*xr*yr); |
| 478 |
< |
scalecolor(pic[y-y0][x-x0], (1.-pa*xr*yr)); |
| 476 |
> |
else if (!bigdiff(sr.rcol, pic[y-y0][x-x0], |
| 477 |
> |
0.001)) /* source sample */ |
| 478 |
> |
setcolor(pic[y-y0][x-x0], 0., 0., 0.); |
| 479 |
> |
w = poly_area(ppoly, npv) * hres * vres; |
| 480 |
> |
scalecolor(sr.rcol, w); |
| 481 |
> |
scalecolor(pic[y-y0][x-x0], 1.-w); |
| 482 |
|
addcolor(pic[y-y0][x-x0], sr.rcol); |
| 483 |
|
} |
| 484 |
|
} |