--- ray/src/rt/srcdraw.c 1996/06/08 21:16:04 2.3 +++ ray/src/rt/srcdraw.c 2003/10/01 22:07:19 2.9 @@ -1,13 +1,14 @@ -/* Copyright (c) 1996 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: srcdraw.c,v 2.9 2003/10/01 22:07:19 greg Exp $"; #endif - /* * Draw small sources into image in case we missed them. + * + * External symbols declared in ray.h */ +#include "copyright.h" + #include "ray.h" #include "view.h" @@ -26,7 +27,7 @@ typedef struct splist { struct splist *next; /* next source in list */ int sn; /* source number */ short nv; /* number of vertices */ - FLOAT vl[3][2]; /* vertex array (last) */ + RREAL vl[3][2]; /* vertex array (last) */ } SPLIST; /* source polygon list */ extern VIEW ourview; /* our view parameters */ @@ -36,7 +37,7 @@ static SPLIST *sphead = NULL; /* our list of source p static int inregion(p, cv, crit) /* check if vertex is in region */ -FLOAT p[2]; +RREAL p[2]; double cv; int crit; { @@ -56,10 +57,10 @@ int crit; static clipregion(a, b, cv, crit, r) /* find intersection with boundary */ -register FLOAT a[2], b[2]; +register RREAL a[2], b[2]; double cv; int crit; -FLOAT r[2]; /* return value */ +RREAL r[2]; /* return value */ { switch (crit) { case CLIP_ABOVE: @@ -78,13 +79,13 @@ FLOAT r[2]; /* return value */ static int hp_clip_poly(vl, nv, cv, crit, vlo) /* clip polygon to half-plane */ -FLOAT vl[][2]; +RREAL vl[][2]; int nv; double cv; int crit; -FLOAT vlo[][2]; /* return value */ +RREAL vlo[][2]; /* return value */ { - FLOAT *s, *p; + RREAL *s, *p; register int j, nvo; s = vl[nv-1]; @@ -105,12 +106,12 @@ FLOAT vlo[][2]; /* return value */ static int box_clip_poly(vl, nv, xl, xr, yb, ya, vlo) /* clip polygon to box */ -FLOAT vl[MAXVERT][2]; +RREAL vl[MAXVERT][2]; int nv; double xl, xr, yb, ya; -FLOAT vlo[MAXVERT][2]; /* return value */ +RREAL vlo[MAXVERT][2]; /* return value */ { - FLOAT vlt[MAXVERT][2]; + RREAL vlt[MAXVERT][2]; int nvt, nvo; nvt = hp_clip_poly(vl, nv, yb, CLIP_BELOW, vlt); @@ -124,12 +125,12 @@ FLOAT vlo[MAXVERT][2]; /* return value */ static double minw2(vl, nv, ar2) /* compute square of minimum width */ -FLOAT vl[][2]; +RREAL vl[][2]; int nv; double ar2; { double d2, w2, w2min, w2max; - register FLOAT *p0, *p1, *p2; + register RREAL *p0, *p1, *p2; int i, j; /* find minimum for all widths */ w2min = FHUGE; @@ -157,9 +158,9 @@ double ar2; static convex_center(vl, nv, cv) /* compute center of convex polygon */ -register FLOAT vl[][2]; +register RREAL vl[][2]; int nv; -FLOAT cv[2]; /* return value */ +RREAL cv[2]; /* return value */ { register int i; /* simple average (suboptimal) */ @@ -175,11 +176,11 @@ FLOAT cv[2]; /* return value */ static double poly_area(vl, nv) /* compute area of polygon */ -register FLOAT vl[][2]; +register RREAL vl[][2]; int nv; { double a; - FLOAT v0[2], v1[2]; + RREAL v0[2], v1[2]; register int i; a = 0.; @@ -197,12 +198,12 @@ int nv; static int convex_hull(vl, nv, vlo) /* compute polygon's convex hull */ -FLOAT vl[][2]; +RREAL vl[][2]; int nv; -FLOAT vlo[][2]; /* return value */ +RREAL vlo[][2]; /* return value */ { int nvo, nvt; - FLOAT vlt[MAXVERT][2]; + RREAL vlt[MAXVERT][2]; double voa, vta; register int i, j; /* start with original polygon */ @@ -234,7 +235,7 @@ FLOAT vlo[][2]; /* return value */ static spinsert(sn, vl, nv) /* insert new source polygon */ int sn; -FLOAT vl[][2]; +RREAL vl[][2]; int nv; { register SPLIST *spn; @@ -243,7 +244,7 @@ int nv; if (nv < 3) return; if (nv > 3) - spn = (SPLIST *)malloc(sizeof(SPLIST)+sizeof(FLOAT)*2*(nv-3)); + spn = (SPLIST *)malloc(sizeof(SPLIST)+sizeof(RREAL)*2*(nv-3)); else spn = (SPLIST *)malloc(sizeof(SPLIST)); if (spn == NULL) @@ -260,15 +261,15 @@ int nv; int sourcepoly(sn, sp) /* compute image polygon for source */ int sn; -FLOAT sp[MAXVERT][2]; +RREAL sp[MAXVERT][2]; { - static char cubeord[8][6] = {{1,3,2,6,4,5},{0,4,5,7,3,2}, + static short cubeord[8][6] = {{1,3,2,6,4,5},{0,4,5,7,3,2}, {0,1,3,7,6,4},{0,1,5,7,6,2}, {0,2,6,7,5,1},{0,4,6,7,3,1}, {0,2,3,7,5,4},{1,5,4,6,2,3}}; register SRCREC *s = source + sn; FVECT ap, ip; - FLOAT pt[6][2]; + RREAL pt[6][2]; int dir; register int i, j; @@ -284,9 +285,9 @@ FLOAT sp[MAXVERT][2]; for (j = 0; j < 4; j++) { /* four corners */ for (i = 0; i < 3; i++) { ap[i] = s->sloc[i]; - if (j==1|j==2) ap[i] += s->ss[SU][i]; + if ((j==1)|(j==2)) ap[i] += s->ss[SU][i]; else ap[i] -= s->ss[SU][i]; - if (j==2|j==3) ap[i] += s->ss[SV][i]; + if ((j==2)|(j==3)) ap[i] += s->ss[SV][i]; else ap[i] -= s->ss[SV][i]; if (s->sflags & SDISTANT) { ap[i] *= 1. + ourview.vfore; @@ -330,14 +331,14 @@ FLOAT sp[MAXVERT][2]; init_drawsources(rad) int rad; /* source sample size */ { - FLOAT spoly[MAXVERT][2]; + RREAL spoly[MAXVERT][2]; int nsv; register SPLIST *sp; register int i; /* free old source list if one */ for (sp = sphead; sp != NULL; sp = sphead) { sphead = sp->next; - free((char *)sp); + free((void *)sp); } /* loop through all sources */ for (i = nsources; i--; ) { @@ -356,17 +357,17 @@ int rad; /* source sample size */ } } - /* add sources smaller than rad to computed subimage */ +void /* add sources smaller than rad to computed subimage */ drawsources(pic, zbf, x0, xsiz, y0, ysiz) COLOR *pic[]; /* subimage pixel value array */ float *zbf[]; /* subimage distance array (opt.) */ int x0, xsiz, y0, ysiz; /* origin and size of subimage */ { - FLOAT spoly[MAXVERT][2], ppoly[MAXVERT][2]; + RREAL spoly[MAXVERT][2], ppoly[MAXVERT][2]; int nsv, npv; int xmin, xmax, ymin, ymax, x, y; - FLOAT cxy[2]; - double pa; + RREAL cxy[2]; + double w; RAY sr; register SPLIST *sp; register int i; @@ -408,18 +409,24 @@ int x0, xsiz, y0, ysiz; /* origin and size of subimag if (source[sp->sn].sflags & SSPOT && spotout(&sr, source[sp->sn].sl.s)) continue; /* outside spot */ - rayorigin(&sr, NULL, SHADOW, 1.0); - sr.rsrc = sp->sn; + w = poly_area(ppoly, npv) * hres * vres; + if (w < .95) { /* subpixel source */ + rayorigin(&sr, NULL, SHADOW, 1.0); + sr.rsrc = sp->sn; + } else + rayorigin(&sr, NULL, PRIMARY, 1.0); rayvalue(&sr); /* compute value */ if (bright(sr.rcol) <= FTINY) continue; /* missed/blocked */ /* modify pixel */ if (zbf[y-y0] != NULL && - sr.rt < zbf[y-y0][x-x0]) + sr.rt < 0.999*zbf[y-y0][x-x0]) zbf[y-y0][x-x0] = sr.rt; - pa = poly_area(ppoly, npv); - scalecolor(sr.rcol, pa*hres*vres); - scalecolor(pic[y-y0][x-x0], (1.-pa*hres*vres)); + else if (!bigdiff(sr.rcol, pic[y-y0][x-x0], + 0.01)) /* source sample */ + setcolor(pic[y-y0][x-x0], 0., 0., 0.); + scalecolor(sr.rcol, w); + scalecolor(pic[y-y0][x-x0], 1.-w); addcolor(pic[y-y0][x-x0], sr.rcol); } }