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.8 by schorsch, Sun Jul 27 22:12:03 2003 UTC vs.
Revision 2.15 by greg, Tue Oct 26 19:04:32 2004 UTC

# Line 10 | Line 10 | static const char      RCSid[] = "$Id$";
10   #include "copyright.h"
11  
12   #include  "ray.h"
13
13   #include  "view.h"
14 <
14 > #include  "otypes.h"
15   #include  "source.h"
16  
17  
# Line 34 | Line 33 | extern VIEW    ourview;                /* our view parameters */
33   extern int      hres, vres;             /* our image resolution */
34   static SPLIST   *sphead = NULL;         /* our list of source polys */
35  
36 + static int inregion(RREAL p[2], double cv, int crit);
37 + static void clipregion(RREAL a[2], RREAL b[2], double cv, int crit, RREAL r[2]);
38 + static int hp_clip_poly(RREAL vl[][2], int nv, double cv, int crit,
39 +                RREAL vlo[][2]);
40 + static int box_clip_poly(RREAL vl[MAXVERT][2], int nv,
41 +                double xl, double xr, double yb, double ya, RREAL vlo[MAXVERT][2]);
42 + static double minw2(RREAL vl[][2], int nv, double ar2);
43 + static void convex_center(RREAL vl[][2], int nv, RREAL cv[2]);
44 + static double poly_area(RREAL vl[][2], int nv);
45 + static int convex_hull(RREAL vl[][2], int nv, RREAL vlo[][2]);
46 + static void spinsert(int sn, RREAL vl[][2], int nv);
47 + static int sourcepoly(int sn, RREAL sp[MAXVERT][2]);
48  
49 +
50   static int
51 < inregion(p, cv, crit)                   /* check if vertex is in region */
52 < RREAL   p[2];
53 < double  cv;
54 < int     crit;
51 > inregion(                       /* check if vertex is in region */
52 >        RREAL   p[2],
53 >        double  cv,
54 >        int     crit
55 > )
56   {
57          switch (crit) {
58          case CLIP_ABOVE:
# Line 55 | Line 68 | int    crit;
68   }
69  
70  
71 < static
72 < clipregion(a, b, cv, crit, r)           /* find intersection with boundary */
73 < register RREAL  a[2], b[2];
74 < double  cv;
75 < int     crit;
76 < RREAL   r[2];   /* return value */
71 > static void
72 > clipregion(             /* find intersection with boundary */
73 >        register RREAL  a[2],
74 >        register RREAL  b[2],
75 >        double  cv,
76 >        int     crit,
77 >        RREAL   r[2]    /* return value */
78 > )
79   {
80          switch (crit) {
81          case CLIP_ABOVE:
# Line 78 | Line 93 | RREAL  r[2];   /* return value */
93  
94  
95   static int
96 < hp_clip_poly(vl, nv, cv, crit, vlo)     /* clip polygon to half-plane */
97 < RREAL   vl[][2];
98 < int     nv;
99 < double  cv;
100 < int     crit;
101 < RREAL   vlo[][2];       /* return value */
96 > hp_clip_poly(   /* clip polygon to half-plane */
97 >        RREAL   vl[][2],
98 >        int     nv,
99 >        double  cv,
100 >        int     crit,
101 >        RREAL   vlo[][2]        /* return value */
102 > )
103   {
104          RREAL   *s, *p;
105          register int    j, nvo;
# Line 105 | Line 121 | RREAL  vlo[][2];       /* return value */
121  
122  
123   static int
124 < box_clip_poly(vl, nv, xl, xr, yb, ya, vlo)      /* clip polygon to box */
125 < RREAL   vl[MAXVERT][2];
126 < int     nv;
127 < double  xl, xr, yb, ya;
128 < RREAL   vlo[MAXVERT][2];        /* return value */
124 > box_clip_poly(  /* clip polygon to box */
125 >        RREAL   vl[MAXVERT][2],
126 >        int     nv,
127 >        double  xl,
128 >        double  xr,
129 >        double  yb,
130 >        double  ya,
131 >        RREAL   vlo[MAXVERT][2] /* return value */
132 > )
133   {
134          RREAL   vlt[MAXVERT][2];
135          int     nvt, nvo;
# Line 124 | Line 144 | RREAL  vlo[MAXVERT][2];        /* return value */
144  
145  
146   static double
147 < minw2(vl, nv, ar2)                      /* compute square of minimum width */
148 < RREAL   vl[][2];
149 < int     nv;
150 < double  ar2;
147 > minw2(                  /* compute square of minimum width */
148 >        RREAL   vl[][2],
149 >        int     nv,
150 >        double  ar2
151 > )
152   {
153          double  d2, w2, w2min, w2max;
154          register RREAL  *p0, *p1, *p2;
# Line 156 | Line 177 | double ar2;
177   }
178  
179  
180 < static
181 < convex_center(vl, nv, cv)               /* compute center of convex polygon */
182 < register RREAL  vl[][2];
183 < int     nv;
184 < RREAL   cv[2];          /* return value */
180 > static void
181 > convex_center(          /* compute center of convex polygon */
182 >        register RREAL  vl[][2],
183 >        int     nv,
184 >        RREAL   cv[2]           /* return value */
185 > )
186   {
187          register int    i;
188                                          /* simple average (suboptimal) */
# Line 175 | Line 197 | RREAL  cv[2];          /* return value */
197  
198  
199   static double
200 < poly_area(vl, nv)                       /* compute area of polygon */
201 < register RREAL  vl[][2];
202 < int     nv;
200 > poly_area(                      /* compute area of polygon */
201 >        register RREAL  vl[][2],
202 >        int     nv
203 > )
204   {
205          double  a;
206          RREAL   v0[2], v1[2];
# Line 197 | Line 220 | int    nv;
220  
221  
222   static int
223 < convex_hull(vl, nv, vlo)                /* compute polygon's convex hull */
224 < RREAL   vl[][2];
225 < int     nv;
226 < RREAL   vlo[][2];       /* return value */
223 > convex_hull(            /* compute polygon's convex hull */
224 >        RREAL   vl[][2],
225 >        int     nv,
226 >        RREAL   vlo[][2]        /* return value */
227 > )
228   {
229          int     nvo, nvt;
230          RREAL   vlt[MAXVERT][2];
# Line 232 | Line 256 | RREAL  vlo[][2];       /* return value */
256   }
257  
258  
259 < static
260 < spinsert(sn, vl, nv)                    /* insert new source polygon */
261 < int     sn;
262 < RREAL   vl[][2];
263 < int     nv;
259 > static void
260 > spinsert(                       /* insert new source polygon */
261 >        int     sn,
262 >        RREAL   vl[][2],
263 >        int     nv
264 > )
265   {
266          register SPLIST *spn;
267          register int    i;
# Line 258 | Line 283 | int    nv;
283   }
284  
285  
286 < int
287 < sourcepoly(sn, sp)                      /* compute image polygon for source */
288 < int     sn;
289 < RREAL   sp[MAXVERT][2];
286 > static int
287 > sourcepoly(                     /* compute image polygon for source */
288 >        int     sn,
289 >        RREAL   sp[MAXVERT][2]
290 > )
291   {
292 <        static char     cubeord[8][6] = {{1,3,2,6,4,5},{0,4,5,7,3,2},
292 >        static short    cubeord[8][6] = {{1,3,2,6,4,5},{0,4,5,7,3,2},
293                                           {0,1,3,7,6,4},{0,1,5,7,6,2},
294                                           {0,2,6,7,5,1},{0,4,6,7,3,1},
295                                           {0,2,3,7,5,4},{1,5,4,6,2,3}};
# Line 274 | Line 300 | RREAL  sp[MAXVERT][2];
300          register int    i, j;
301  
302          if (s->sflags & (SDISTANT|SFLAT)) {
303 <                if (s->sflags & SDISTANT && ourview.type == VT_PAR)
304 <                        return(0);              /* all or nothing case */
303 >                if (s->sflags & SDISTANT) {
304 >                        if (ourview.type == VT_PAR)
305 >                                return(0);      /* all or nothing case */
306 >                        if (s->srad >= 0.05)
307 >                                return(0);      /* should never be a problem */
308 >                }
309                  if (s->sflags & SFLAT) {
310                          for (i = 0; i < 3; i++)
311                                  ap[i] = s->sloc[i] - ourview.vp[i];
# Line 328 | Line 358 | RREAL  sp[MAXVERT][2];
358  
359  
360                          /* initialize by finding sources smaller than rad */
361 < init_drawsources(rad)
362 < int     rad;                            /* source sample size */
361 > extern void
362 > init_drawsources(
363 >        int     rad                             /* source sample size */
364 > )
365   {
366          RREAL   spoly[MAXVERT][2];
367          int     nsv;
# Line 342 | Line 374 | int    rad;                            /* source sample size */
374          }
375                                          /* loop through all sources */
376          for (i = nsources; i--; ) {
377 +                                        /* skip illum's */
378 +                if (findmaterial(source[i].so)->otype == MAT_ILLUM)
379 +                        continue;
380                                          /* compute image polygon for source */
381                  if (!(nsv = sourcepoly(i, spoly)))
382                          continue;
# Line 357 | Line 392 | int    rad;                            /* source sample size */
392          }
393   }
394  
395 < void                    /* add sources smaller than rad to computed subimage */
396 < drawsources(pic, zbf, x0, xsiz, y0, ysiz)
397 < COLOR   *pic[];                         /* subimage pixel value array */
398 < float   *zbf[];                         /* subimage distance array (opt.) */
399 < int     x0, xsiz, y0, ysiz;             /* origin and size of subimage */
395 > extern void                     /* add sources smaller than rad to computed subimage */
396 > drawsources(
397 >        COLOR   *pic[],                         /* subimage pixel value array */
398 >        float   *zbf[],                         /* subimage distance array (opt.) */
399 >        int     x0,                             /* origin and size of subimage */
400 >        int     xsiz,
401 >        int     y0,
402 >        int     ysiz
403 > )
404   {
405          RREAL   spoly[MAXVERT][2], ppoly[MAXVERT][2];
406          int     nsv, npv;
# Line 415 | Line 454 | int    x0, xsiz, y0, ysiz;             /* origin and size of subimag
454                                  if (bright(sr.rcol) <= FTINY)
455                                          continue;       /* missed/blocked */
456                                                          /* modify pixel */
457 +                                w = poly_area(ppoly, npv) * hres * vres;
458                                  if (zbf[y-y0] != NULL &&
459 <                                                sr.rt < 0.999*zbf[y-y0][x-x0])
459 >                                                sr.rt < 0.99*zbf[y-y0][x-x0]) {
460                                          zbf[y-y0][x-x0] = sr.rt;
461 <                                else if (!bigdiff(sr.rcol, pic[y-y0][x-x0],
462 <                                                0.001)) /* source sample */
463 <                                        setcolor(pic[y-y0][x-x0], 0., 0., 0.);
464 <                                w = poly_area(ppoly, npv) * hres * vres;
461 >                                } else if (!bigdiff(sr.rcol, pic[y-y0][x-x0],
462 >                                                0.01)) { /* source sample */
463 >                                        scalecolor(pic[y-y0][x-x0], w);
464 >                                        continue;
465 >                                }
466                                  scalecolor(sr.rcol, w);
467                                  scalecolor(pic[y-y0][x-x0], 1.-w);
468                                  addcolor(pic[y-y0][x-x0], sr.rcol);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines