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

Comparing ray/src/rt/virtuals.c (file contents):
Revision 2.4 by greg, Sat Aug 26 14:07:46 1995 UTC vs.
Revision 2.25 by greg, Fri Feb 12 00:41:19 2021 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 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   * Routines for simulating virtual light sources
6   *      Thus far, we only support planar mirrors.
7 + *
8 + *  External symbols declared in source.h
9   */
10  
11 < #include  "ray.h"
11 > #include "copyright.h"
12  
13 < #include  "octree.h"
15 <
13 > #include  "ray.h"
14   #include  "otypes.h"
15 <
15 > #include  "otspecial.h"
16   #include  "source.h"
19
17   #include  "random.h"
18  
19   #define  MINSAMPLES     16              /* minimum number of pretest samples */
20   #define  STESTMAX       32              /* maximum seeks per sample */
21  
22  
26 double  getdisk();
27
23   static OBJECT  *vobject;                /* virtual source objects */
24   static int  nvobjects = 0;              /* number of virtual source objects */
25  
26  
27 < markvirtuals()                  /* find and mark virtual sources */
27 > static int
28 > isident4(MAT4 m)
29   {
30 <        register OBJREC  *o;
31 <        register int  i;
30 >        int     i, j;
31 >
32 >        for (i = 4; i--; )
33 >                for (j = 4; j--; )
34 >                        if (!FABSEQ(m[i][j], i==j))
35 >                                return(0);
36 >        return(1);
37 > }
38 >
39 >
40 > void
41 > markvirtuals(void)                      /* find and mark virtual sources */
42 > {
43 >        OBJREC  *o;
44 >        int  i;
45                                          /* check number of direct relays */
46          if (directrelay <= 0)
47                  return;
48                                          /* find virtual source objects */
49 <        for (i = 0; i < nobjects; i++) {
49 >        for (i = 0; i < nsceneobjs; i++) {
50                  o = objptr(i);
51                  if (!issurface(o->otype) || o->omod == OVOID)
52                          continue;
# Line 51 | Line 60 | markvirtuals()                 /* find and mark virtual sources */
60                  if (nvobjects == 0)
61                          vobject = (OBJECT *)malloc(sizeof(OBJECT));
62                  else
63 <                        vobject = (OBJECT *)realloc((char *)vobject,
63 >                        vobject = (OBJECT *)realloc((void *)vobject,
64                                  (unsigned)(nvobjects+1)*sizeof(OBJECT));
65                  if (vobject == NULL)
66                          error(SYSTEM, "out of memory in addvirtuals");
# Line 66 | Line 75 | markvirtuals()                 /* find and mark virtual sources */
75          for (i = nsources; i-- > 0; )
76                  addvirtuals(i, directrelay);
77                                          /* done with our object list */
78 <        free((char *)vobject);
78 >        free((void *)vobject);
79          nvobjects = 0;
80   }
81  
82  
83 < addvirtuals(sn, nr)             /* add virtuals associated with source */
84 < int  sn;
85 < int  nr;
83 > void
84 > addvirtuals(            /* add virtuals associated with source */
85 >        int  sn,
86 >        int  nr
87 > )
88   {
89 <        register int  i;
89 >        int  i;
90                                  /* check relay limit first */
91          if (nr <= 0)
92                  return;
# Line 88 | Line 99 | int  nr;
99   }
100  
101  
102 < vproject(o, sn, n)              /* create projected source(s) if they exist */
103 < OBJREC  *o;
104 < int  sn;
105 < int  n;
102 > void
103 > vproject(               /* create projected source(s) if they exist */
104 >        OBJREC  *o,
105 >        int  sn,
106 >        int  n
107 > )
108   {
109 <        register int  i;
110 <        register VSMATERIAL  *vsmat;
109 >        int  i;
110 >        VSMATERIAL  *vsmat;
111          MAT4  proj;
112          int  ns;
113  
# Line 116 | Line 129 | int  n;
129  
130  
131   OBJREC *
132 < vsmaterial(o)                   /* get virtual source material pointer */
133 < OBJREC  *o;
132 > vsmaterial(                     /* get virtual source material pointer */
133 >        OBJREC  *o
134 > )
135   {
136 <        register int  i;
137 <        register OBJREC  *m;
136 >        int  i;
137 >        OBJREC  *m;
138  
139          i = o->omod;
140 <        m = objptr(i);
140 >        m = findmaterial(o);
141 >        if (m == NULL)
142 >                return(objptr(i));
143          if (m->otype != MAT_ILLUM || m->oargs.nsargs < 1 ||
144                          !strcmp(m->oargs.sarg[0], VOIDID) ||
145 <                        (i = modifier(m->oargs.sarg[0])) == OVOID)
145 >                        (i = lastmod(objndx(m), m->oargs.sarg[0])) == OVOID)
146                  return(m);              /* direct modifier */
147          return(objptr(i));              /* illum alternate */
148   }
149  
150  
151   int
152 < makevsrc(op, sn, pm)            /* make virtual source if reasonable */
153 < OBJREC  *op;
154 < register int  sn;
155 < MAT4  pm;
152 > makevsrc(               /* make virtual source if reasonable */
153 >        OBJREC  *op,
154 >        int  sn,
155 >        MAT4  pm
156 > )
157   {
158          FVECT  nsloc, nsnorm, ocent, v;
159          double  maxrad2, d;
160          int  nsflags;
161          SPOT  theirspot, ourspot;
162 <        register int  i;
163 <
162 >        int  i;
163 >                                        /* check for no-op */
164 >        if (isident4(pm))
165 >                return(0);
166          nsflags = source[sn].sflags | (SVIRTUAL|SSPOT|SFOLLOW);
167                                          /* get object center and max. radius */
168          maxrad2 = getdisk(ocent, op, sn);
# Line 157 | Line 176 | MAT4  pm;
176                  normalize(nsloc);
177                  VCOPY(ourspot.aim, ocent);
178                  ourspot.siz = PI*maxrad2;
179 <                ourspot.flen = 0.;
179 >                ourspot.flen = -1.;
180                  if (source[sn].sflags & SSPOT) {
181                          multp3(theirspot.aim, source[sn].sl.s->aim, pm);
182                                                  /* adjust for source size */
# Line 194 | Line 213 | MAT4  pm;
213                  else
214                          nsflags &= ~SSPOT;
215                  if (source[sn].sflags & SSPOT) {
216 <                        copystruct(&theirspot, source[sn].sl.s);
216 >                        theirspot = *(source[sn].sl.s);
217                          multv3(theirspot.aim, source[sn].sl.s->aim, pm);
218                          normalize(theirspot.aim);
219                          if (nsflags & SSPOT) {
# Line 204 | Line 223 | MAT4  pm;
223                                          return(-1);     /* no overlap */
224                          } else {
225                                  nsflags |= SSPOT;
226 <                                copystruct(&ourspot, &theirspot);
226 >                                ourspot = theirspot;
227                                  d = 2.*ourspot.siz;
228                          }
229                          if (ourspot.siz < d-FTINY) {    /* it shrunk */
# Line 244 | Line 263 | MAT4  pm;
263          if (nsflags & SSPOT) {
264                  if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
265                          goto memerr;
266 <                copystruct(source[i].sl.s, &ourspot);
266 >                *(source[i].sl.s) = ourspot;
267          }
268          if (nsflags & SPROX)
269                  source[i].sl.prox = source[sn].sl.prox;
# Line 253 | Line 272 | MAT4  pm;
272          return(i);
273   memerr:
274          error(SYSTEM, "out of memory in makevsrc");
275 +        return -1; /* pro forma return */
276   }
277  
278  
279   double
280 < getdisk(oc, op, sn)             /* get visible object disk */
281 < FVECT  oc;
282 < OBJREC  *op;
283 < register int  sn;
280 > getdisk(                /* get visible object disk */
281 >        FVECT  oc,
282 >        OBJREC  *op,
283 >        int  sn
284 > )
285   {
286          double  rad2, roffs, offs, d, rd, rdoto;
287          FVECT  rnrm, nrm;
# Line 289 | Line 310 | register int  sn;
310  
311  
312   int
313 < vstestvis(f, o, oc, or2, sn)            /* pretest source visibility */
314 < int  f;                 /* virtual source flags */
315 < OBJREC  *o;             /* relay object */
316 < FVECT  oc;              /* relay object center */
317 < double  or2;            /* relay object radius squared */
318 < register int  sn;       /* target source number */
313 > vstestvis(              /* pretest source visibility */
314 >        int  f,                 /* virtual source flags */
315 >        OBJREC  *o,             /* relay object */
316 >        FVECT  oc,              /* relay object center */
317 >        double  or2,            /* relay object radius squared */
318 >        int  sn /* target source number */
319 > )
320   {
321          RAY  sr;
322          FVECT  onorm;
323 <        FVECT  offsdir;
323 >        double  offsdir[3];
324          SRCINDEX  si;
325 <        double  or, d;
325 >        double  or, d, d1;
326          int  stestlim, ssn;
327          int  nhit, nok;
328 <        register int  i, n;
328 >        int  i, n;
329                                  /* return if pretesting disabled */
330          if (vspretest <= 0)
331                  return(f);
# Line 314 | Line 336 | register int  sn;      /* target source number */
336                                          /* 32. == heuristic constant */
337                  n = 32.*or2/(thescene.cusize*thescene.cusize)*vspretest + .5;
338          } else {
339 <                for (i = 0; i < 3; i++)
318 <                        offsdir[i] = source[sn].sloc[i] - oc[i];
339 >                VSUB(offsdir, source[sn].sloc, oc);
340                  d = DOT(offsdir,offsdir);
341                  if (d <= FTINY)
342                          n = 2.*PI * vspretest + .5;
# Line 352 | Line 373 | register int  sn;      /* target source number */
373                                  sr.rdir[i] = -onorm[i];
374                          }
375                          sr.rmax = 0.0;
376 <                        rayorigin(&sr, NULL, PRIMARY, 1.0);
376 >                        rayorigin(&sr, PRIMARY, NULL, NULL);
377                  } while (!(*ofun[o->otype].funp)(o, &sr));
378                                          /* check against source */
379                  VCOPY(sr.rorg, sr.rop); /* starting from intersection */
# Line 366 | Line 387 | register int  sn;      /* target source number */
387                  }
388                  sr.revf = srcvalue;
389                  rayvalue(&sr);                  /* check sample validity */
390 <                if (bright(sr.rcol) <= FTINY)
390 >                if ((d = bright(sr.rcol)) <= FTINY)
391                          continue;
392                  nok++;                  /* got sample; check obstructions */
393                  rayclear(&sr);
394                  sr.revf = raytrace;
395                  rayvalue(&sr);
396 <                if (bright(sr.rcol) > FTINY)
396 >                if ((d1 = bright(sr.rcol)) > FTINY) {
397 >                        if (d - d1 > FTINY) {
398 > #ifdef DEBUG
399 >                                fprintf(stderr, "\tpartially shadowed\n");
400 > #endif
401 >                                return(f);      /* intervening transmitter */
402 >                        }
403                          nhit++;
404 +                }
405                  if (nhit > 0 && nhit < nok) {
406   #ifdef DEBUG
407                          fprintf(stderr, "\tpartially occluded\n");
# Line 395 | Line 423 | register int  sn;      /* target source number */
423          
424  
425   #ifdef DEBUG
426 < virtverb(sn, fp)        /* print verbose description of virtual source */
427 < register int  sn;
428 < FILE  *fp;
426 > void
427 > virtverb(       /* print verbose description of virtual source */
428 >        int  sn,
429 >        FILE  *fp
430 > )
431   {
402        register int  i;
403
432          fprintf(fp, "%s virtual source %d in %s %s\n",
433                          source[sn].sflags & SDISTANT ? "distant" : "local",
434                          sn, ofun[source[sn].so->otype].funame,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines