ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/srcdraw.c
(Generate patch)

Comparing ray/src/rt/srcdraw.c (file contents):
Revision 2.1 by greg, Fri Mar 15 21:26:42 1996 UTC vs.
Revision 2.6 by greg, Tue Feb 25 02:47:23 2003 UTC

# Line 1 | Line 1
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 + #include "copyright.h"
11 +
12   #include  "ray.h"
13  
14   #include  "view.h"
# Line 22 | Line 23 | static char SCCSid[] = "$SunId$ LBL";
23  
24   #define MAXVERT         10
25  
26 + typedef struct splist {
27 +        struct splist   *next;                  /* next source in list */
28 +        int     sn;                             /* source number */
29 +        short   nv;                             /* number of vertices */
30 +        FLOAT   vl[3][2];                       /* vertex array (last) */
31 + } SPLIST;                               /* source polygon list */
32  
33 + extern VIEW     ourview;                /* our view parameters */
34 + extern int      hres, vres;             /* our image resolution */
35 + static SPLIST   *sphead = NULL;         /* our list of source polys */
36 +
37 +
38   static int
39   inregion(p, cv, crit)                   /* check if vertex is in region */
40   FLOAT   p[2];
# Line 220 | Line 232 | FLOAT  vlo[][2];       /* return value */
232   }
233  
234  
235 + static
236 + spinsert(sn, vl, nv)                    /* insert new source polygon */
237 + int     sn;
238 + FLOAT   vl[][2];
239 + int     nv;
240 + {
241 +        register SPLIST *spn;
242 +        register int    i;
243 +
244 +        if (nv < 3)
245 +                return;
246 +        if (nv > 3)
247 +                spn = (SPLIST *)malloc(sizeof(SPLIST)+sizeof(FLOAT)*2*(nv-3));
248 +        else
249 +                spn = (SPLIST *)malloc(sizeof(SPLIST));
250 +        if (spn == NULL)
251 +                error(SYSTEM, "out of memory in spinsert");
252 +        spn->sn = sn;
253 +        for (i = spn->nv = nv; i--; ) {
254 +                spn->vl[i][0] = vl[i][0]; spn->vl[i][1] = vl[i][1];
255 +        }
256 +        spn->next = sphead;             /* push onto global list */
257 +        sphead = spn;
258 + }
259 +
260 +
261   int
262 < sourcepoly(vw, sn, sp)                  /* compute image polygon for source */
225 < VIEW    *vw;
262 > sourcepoly(sn, sp)                      /* compute image polygon for source */
263   int     sn;
264   FLOAT   sp[MAXVERT][2];
265   {
# Line 237 | Line 274 | FLOAT  sp[MAXVERT][2];
274          register int    i, j;
275  
276          if (s->sflags & (SDISTANT|SFLAT)) {
277 <                if (s->sflags & SDISTANT && vw->type == VT_PAR)
277 >                if (s->sflags & SDISTANT && ourview.type == VT_PAR)
278                          return(0);              /* all or nothing case */
279                  if (s->sflags & SFLAT) {
280                          for (i = 0; i < 3; i++)
281 <                                ap[i] = s->sloc[i] - vw->vp[i];
281 >                                ap[i] = s->sloc[i] - ourview.vp[i];
282                          if (DOT(ap, s->snorm) >= 0.)
283                                  return(0);      /* source faces away */
284                  }
# Line 253 | Line 290 | FLOAT  sp[MAXVERT][2];
290                                  if (j==2|j==3) ap[i] += s->ss[SV][i];
291                                  else ap[i] -= s->ss[SV][i];
292                                  if (s->sflags & SDISTANT) {
293 <                                        ap[i] *= 1. + vw->vfore;
294 <                                        ap[i] += vw->vp[i];
293 >                                        ap[i] *= 1. + ourview.vfore;
294 >                                        ap[i] += ourview.vp[i];
295                                  }
296                          }
297 <                        viewloc(ip, vw, ap);            /* find image point */
297 >                        viewloc(ip, &ourview, ap);      /* find image point */
298                          if (ip[2] <= 0.)
299                                  return(0);              /* in front of view */
300                          sp[j][0] = ip[0]; sp[j][1] = ip[1];
# Line 266 | Line 303 | FLOAT  sp[MAXVERT][2];
303          }
304                                          /* identify furthest corner */
305          for (i = 0; i < 3; i++)
306 <                ap[i] = s->sloc[i] - vw->vp[i];
306 >                ap[i] = s->sloc[i] - ourview.vp[i];
307          dir =   (DOT(ap,s->ss[SU])>0.) |
308                  (DOT(ap,s->ss[SV])>0.)<<1 |
309                  (DOT(ap,s->ss[SW])>0.)<<2 ;
# Line 281 | Line 318 | FLOAT  sp[MAXVERT][2];
318                          if (cubeord[dir][j] & 4) ap[i] += s->ss[SW][i];
319                          else ap[i] -= s->ss[SW][i];
320                  }
321 <                viewloc(ip, vw, ap);            /* find image point */
321 >                viewloc(ip, &ourview, ap);      /* find image point */
322                  if (ip[2] <= 0.)
323                          return(0);              /* in front of view */
324                  pt[j][0] = ip[0]; pt[j][1] = ip[1];
# Line 290 | Line 327 | FLOAT  sp[MAXVERT][2];
327   }
328  
329  
330 <                        /* add sources smaller than rad to computed subimage */
331 < drawsources(vw, xr, yr, pic, zbf, x0, xsiz, y0, ysiz, rad)
332 < VIEW    *vw;                            /* full image view */
333 < int     xr, yr;                         /* full image dimensions */
330 >                        /* initialize by finding sources smaller than rad */
331 > init_drawsources(rad)
332 > int     rad;                            /* source sample size */
333 > {
334 >        FLOAT   spoly[MAXVERT][2];
335 >        int     nsv;
336 >        register SPLIST *sp;
337 >        register int    i;
338 >                                        /* free old source list if one */
339 >        for (sp = sphead; sp != NULL; sp = sphead) {
340 >                sphead = sp->next;
341 >                free((void *)sp);
342 >        }
343 >                                        /* loop through all sources */
344 >        for (i = nsources; i--; ) {
345 >                                        /* compute image polygon for source */
346 >                if (!(nsv = sourcepoly(i, spoly)))
347 >                        continue;
348 >                                        /* clip to image boundaries */
349 >                if (!(nsv = box_clip_poly(spoly, nsv, 0., 1., 0., 1., spoly)))
350 >                        continue;
351 >                                        /* big enough for standard sampling? */
352 >                if (minw2(spoly, nsv, ourview.vn2/ourview.hn2) >
353 >                                (double)rad*rad/hres/hres)
354 >                        continue;
355 >                                        /* OK, add to our list */
356 >                spinsert(i, spoly, nsv);
357 >        }
358 > }
359 >
360 > void                    /* add sources smaller than rad to computed subimage */
361 > drawsources(pic, zbf, x0, xsiz, y0, ysiz)
362   COLOR   *pic[];                         /* subimage pixel value array */
363   float   *zbf[];                         /* subimage distance array (opt.) */
364   int     x0, xsiz, y0, ysiz;             /* origin and size of subimage */
300 int     rad;                            /* source sample size */
365   {
302        int     sn;
366          FLOAT   spoly[MAXVERT][2], ppoly[MAXVERT][2];
367          int     nsv, npv;
368 <        int     xmin, xmax, ymin, ymax, x, y, i;
368 >        int     xmin, xmax, ymin, ymax, x, y;
369          FLOAT   cxy[2];
370 <        double  pa;
370 >        double  w;
371          RAY     sr;
372 <                                        /* loop through all sources */
373 <        for (sn = 0; sn < nsources; sn++) {
374 <                                        /* compute image polygon for source */
375 <                if (!(nsv = sourcepoly(vw, sn, spoly)))
313 <                        continue;
372 >        register SPLIST *sp;
373 >        register int    i;
374 >                                        /* check each source in our list */
375 >        for (sp = sphead; sp != NULL; sp = sp->next) {
376                                          /* clip source poly to subimage */
377 <                nsv = box_clip_poly(spoly, nsv,
378 <                                (double)x0/xr, (double)(x0+xsiz)/xr,
379 <                                (double)y0/yr, (double)(y0+ysiz)/yr, spoly);
377 >                nsv = box_clip_poly(sp->vl, sp->nv,
378 >                                (double)x0/hres, (double)(x0+xsiz)/hres,
379 >                                (double)y0/vres, (double)(y0+ysiz)/vres, spoly);
380                  if (!nsv)
381                          continue;
320                                        /* is it big so sampling found it? */
321                if (minw2(spoly, nsv, vw->vn2/vw->hn2) > (double)rad*rad/xr/xr)
322                        continue;
382                                          /* find common subimage (BBox) */
383                  xmin = x0 + xsiz; xmax = x0;
384                  ymin = y0 + ysiz; ymax = y0;
385                  for (i = 0; i < nsv; i++) {
386 <                        if ((double)xmin/xr > spoly[i][0])
387 <                                xmin = spoly[i][0]*xr + FTINY;
388 <                        if ((double)xmax/xr < spoly[i][0])
389 <                                xmax = spoly[i][0]*xr - FTINY;
390 <                        if ((double)ymin/yr > spoly[i][1])
391 <                                ymin = spoly[i][1]*yr + FTINY;
392 <                        if ((double)ymax/yr < spoly[i][1])
393 <                                ymax = spoly[i][1]*yr - FTINY;
386 >                        if ((double)xmin/hres > spoly[i][0])
387 >                                xmin = spoly[i][0]*hres + FTINY;
388 >                        if ((double)xmax/hres < spoly[i][0])
389 >                                xmax = spoly[i][0]*hres - FTINY;
390 >                        if ((double)ymin/vres > spoly[i][1])
391 >                                ymin = spoly[i][1]*vres + FTINY;
392 >                        if ((double)ymax/vres < spoly[i][1])
393 >                                ymax = spoly[i][1]*vres - FTINY;
394                  }
395                                          /* evaluate each pixel in BBox */
396                  for (y = ymin; y <= ymax; y++)
397                          for (x = xmin; x <= xmax; x++) {
398                                                          /* subarea for pixel */
399                                  npv = box_clip_poly(spoly, nsv,
400 <                                                (double)x/xr, (x+1.)/xr,
401 <                                                (double)y/yr, (y+1.)/yr, ppoly);
400 >                                                (double)x/hres, (x+1.)/hres,
401 >                                                (double)y/vres, (y+1.)/vres,
402 >                                                ppoly);
403                                  if (!npv)
404                                          continue;       /* no overlap */
405                                  convex_center(ppoly, npv, cxy);
406 <                                if ((sr.rmax = viewray(sr.rorg, sr.rdir, vw,
407 <                                                cxy[0], cxy[1])) < -FTINY)
406 >                                if ((sr.rmax = viewray(sr.rorg,sr.rdir,&ourview,
407 >                                                cxy[0],cxy[1])) < -FTINY)
408                                          continue;       /* not in view */
409 <                                if (source[sn].sflags & SSPOT &&
410 <                                                spotout(sr, source[sn].sl.s))
409 >                                if (source[sp->sn].sflags & SSPOT &&
410 >                                                spotout(&sr, source[sp->sn].sl.s))
411                                          continue;       /* outside spot */
412                                  rayorigin(&sr, NULL, SHADOW, 1.0);
413 <                                sr.rsrc = sn;
413 >                                sr.rsrc = sp->sn;
414                                  rayvalue(&sr);          /* compute value */
415                                  if (bright(sr.rcol) <= FTINY)
416                                          continue;       /* missed/blocked */
417                                                          /* modify pixel */
418                                  if (zbf[y-y0] != NULL &&
419 <                                                sr.rt < zbf[y-y0][x-x0])
419 >                                                sr.rt < 0.999*zbf[y-y0][x-x0])
420                                          zbf[y-y0][x-x0] = sr.rt;
421 <                                pa = poly_area(ppoly, npv);
422 <                                scalecolor(sr.rcol, pa*xr*yr);
423 <                                scalecolor(pic[y-y0][x-x0], (1.-pa*xr*yr));
421 >                                else if (!bigdiff(sr.rcol, pic[y-y0][x-x0],
422 >                                                0.001)) /* source sample */
423 >                                        setcolor(pic[y-y0][x-x0], 0., 0., 0.);
424 >                                w = poly_area(ppoly, npv) * hres * vres;
425 >                                scalecolor(sr.rcol, w);
426 >                                scalecolor(pic[y-y0][x-x0], 1.-w);
427                                  addcolor(pic[y-y0][x-x0], sr.rcol);
428                          }
429          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines