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.3 by greg, Sat Jun 8 21:16:04 1996 UTC vs.
Revision 2.17 by greg, Tue Jul 8 18:25:00 2014 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  "ray.h"
10 > #include "copyright.h"
11  
12 + #include  "ray.h"
13   #include  "view.h"
14 <
14 > #include  "otypes.h"
15   #include  "source.h"
16  
17  
# Line 26 | Line 26 | typedef struct splist {
26          struct splist   *next;                  /* next source in list */
27          int     sn;                             /* source number */
28          short   nv;                             /* number of vertices */
29 <        FLOAT   vl[3][2];                       /* vertex array (last) */
29 >        RREAL   vl[3][2];                       /* vertex array (last) */
30   } SPLIST;                               /* source polygon list */
31  
32   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 < FLOAT   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 54 | Line 68 | int    crit;
68   }
69  
70  
71 < static
72 < clipregion(a, b, cv, crit, r)           /* find intersection with boundary */
73 < register FLOAT  a[2], b[2];
74 < double  cv;
75 < int     crit;
76 < FLOAT   r[2];   /* return value */
71 > static void
72 > clipregion(             /* find intersection with boundary */
73 >        RREAL   a[2],
74 >        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 77 | Line 93 | FLOAT  r[2];   /* return value */
93  
94  
95   static int
96 < hp_clip_poly(vl, nv, cv, crit, vlo)     /* clip polygon to half-plane */
97 < FLOAT   vl[][2];
98 < int     nv;
99 < double  cv;
100 < int     crit;
101 < FLOAT   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 <        FLOAT   *s, *p;
105 <        register int    j, nvo;
104 >        RREAL   *s, *p;
105 >        int     j, nvo;
106  
107          s = vl[nv-1];
108          nvo = 0;
# Line 104 | Line 121 | FLOAT  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 < FLOAT   vl[MAXVERT][2];
126 < int     nv;
127 < double  xl, xr, yb, ya;
128 < FLOAT   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 <        FLOAT   vlt[MAXVERT][2];
134 >        RREAL   vlt[MAXVERT][2];
135          int     nvt, nvo;
136  
137          nvt = hp_clip_poly(vl, nv, yb, CLIP_BELOW, vlt);
# Line 123 | Line 144 | FLOAT  vlo[MAXVERT][2];        /* return value */
144  
145  
146   static double
147 < minw2(vl, nv, ar2)                      /* compute square of minimum width */
148 < FLOAT   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 FLOAT  *p0, *p1, *p2;
154 >        RREAL   *p0, *p1, *p2;
155          int     i, j;
156                                  /* find minimum for all widths */
157          w2min = FHUGE;
# Line 155 | Line 177 | double ar2;
177   }
178  
179  
180 < static
181 < convex_center(vl, nv, cv)               /* compute center of convex polygon */
182 < register FLOAT  vl[][2];
183 < int     nv;
184 < FLOAT   cv[2];          /* return value */
180 > static void
181 > convex_center(          /* compute center of convex polygon */
182 >        RREAL   vl[][2],
183 >        int     nv,
184 >        RREAL   cv[2]           /* return value */
185 > )
186   {
187 <        register int    i;
187 >        int     i;
188                                          /* simple average (suboptimal) */
189          cv[0] = cv[1] = 0.;
190          for (i = 0; i < nv; i++) {
# Line 174 | Line 197 | FLOAT  cv[2];          /* return value */
197  
198  
199   static double
200 < poly_area(vl, nv)                       /* compute area of polygon */
201 < register FLOAT  vl[][2];
202 < int     nv;
200 > poly_area(                      /* compute area of polygon */
201 >        RREAL   vl[][2],
202 >        int     nv
203 > )
204   {
205          double  a;
206 <        FLOAT   v0[2], v1[2];
207 <        register int    i;
206 >        RREAL   v0[2], v1[2];
207 >        int     i;
208  
209          a = 0.;
210          v0[0] = vl[1][0] - vl[0][0];
# Line 196 | Line 220 | int    nv;
220  
221  
222   static int
223 < convex_hull(vl, nv, vlo)                /* compute polygon's convex hull */
224 < FLOAT   vl[][2];
225 < int     nv;
226 < FLOAT   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 <        FLOAT   vlt[MAXVERT][2];
230 >        RREAL   vlt[MAXVERT][2];
231          double  voa, vta;
232 <        register int    i, j;
232 >        int     i, j;
233                                          /* start with original polygon */
234          for (i = nvo = nv; i--; ) {
235                  vlo[i][0] = vl[i][0]; vlo[i][1] = vl[i][1];
# Line 231 | Line 256 | FLOAT  vlo[][2];       /* return value */
256   }
257  
258  
259 < static
260 < spinsert(sn, vl, nv)                    /* insert new source polygon */
261 < int     sn;
262 < FLOAT   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;
266 >        SPLIST  *spn;
267 >        int     i;
268  
269          if (nv < 3)
270                  return;
271          if (nv > 3)
272 <                spn = (SPLIST *)malloc(sizeof(SPLIST)+sizeof(FLOAT)*2*(nv-3));
272 >                spn = (SPLIST *)malloc(sizeof(SPLIST)+sizeof(RREAL)*2*(nv-3));
273          else
274                  spn = (SPLIST *)malloc(sizeof(SPLIST));
275          if (spn == NULL)
# Line 257 | Line 283 | int    nv;
283   }
284  
285  
286 < int
287 < sourcepoly(sn, sp)                      /* compute image polygon for source */
288 < int     sn;
289 < FLOAT   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}};
296 <        register SRCREC *s = source + sn;
296 >        SRCREC  *s = source + sn;
297          FVECT   ap, ip;
298 <        FLOAT   pt[6][2];
298 >        RREAL   pt[6][2];
299          int     dir;
300 <        register int    i, j;
300 >        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 284 | Line 315 | FLOAT  sp[MAXVERT][2];
315                  for (j = 0; j < 4; j++) {       /* four corners */
316                          for (i = 0; i < 3; i++) {
317                                  ap[i] = s->sloc[i];
318 <                                if (j==1|j==2) ap[i] += s->ss[SU][i];
318 >                                if ((j==1)|(j==2)) ap[i] += s->ss[SU][i];
319                                  else ap[i] -= s->ss[SU][i];
320 <                                if (j==2|j==3) ap[i] += s->ss[SV][i];
320 >                                if ((j==2)|(j==3)) ap[i] += s->ss[SV][i];
321                                  else ap[i] -= s->ss[SV][i];
322                                  if (s->sflags & SDISTANT) {
323                                          ap[i] *= 1. + ourview.vfore;
# Line 327 | Line 358 | FLOAT  sp[MAXVERT][2];
358  
359  
360                          /* initialize by finding sources smaller than rad */
361 < init_drawsources(rad)
362 < int     rad;                            /* source sample size */
361 > void
362 > init_drawsources(
363 >        int     rad                             /* source sample size */
364 > )
365   {
366 <        FLOAT   spoly[MAXVERT][2];
366 >        RREAL   spoly[MAXVERT][2];
367          int     nsv;
368 <        register SPLIST *sp;
369 <        register int    i;
368 >        SPLIST  *sp;
369 >        int     i;
370                                          /* free old source list if one */
371          for (sp = sphead; sp != NULL; sp = sphead) {
372                  sphead = sp->next;
373 <                free((char *)sp);
373 >                free((void *)sp);
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 356 | Line 392 | int    rad;                            /* source sample size */
392          }
393   }
394  
395 <                        /* 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 > 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 <        FLOAT   spoly[MAXVERT][2], ppoly[MAXVERT][2];
405 >        RREAL   spoly[MAXVERT][2], ppoly[MAXVERT][2];
406          int     nsv, npv;
407          int     xmin, xmax, ymin, ymax, x, y;
408 <        FLOAT   cxy[2];
409 <        double  pa;
408 >        RREAL   cxy[2];
409 >        double  w;
410          RAY     sr;
411 <        register SPLIST *sp;
412 <        register int    i;
411 >        SPLIST  *sp;
412 >        int     i;
413                                          /* check each source in our list */
414          for (sp = sphead; sp != NULL; sp = sp->next) {
415                                          /* clip source poly to subimage */
# Line 408 | Line 448 | int    x0, xsiz, y0, ysiz;             /* origin and size of subimag
448                                  if (source[sp->sn].sflags & SSPOT &&
449                                                  spotout(&sr, source[sp->sn].sl.s))
450                                          continue;       /* outside spot */
451 <                                rayorigin(&sr, NULL, SHADOW, 1.0);
451 >                                rayorigin(&sr, SHADOW, NULL, NULL);
452                                  sr.rsrc = sp->sn;
453                                  rayvalue(&sr);          /* compute value */
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 < zbf[y-y0][x-x0])
459 >                                                sr.rt < 0.99*zbf[y-y0][x-x0]) {
460                                          zbf[y-y0][x-x0] = sr.rt;
461 <                                pa = poly_area(ppoly, npv);
462 <                                scalecolor(sr.rcol, pa*hres*vres);
463 <                                scalecolor(pic[y-y0][x-x0], (1.-pa*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);
469                          }
470          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines