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.2 by greg, Sat May 23 08:03:19 1992 UTC vs.
Revision 2.13 by greg, Tue Mar 2 01:13:45 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 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 "copyright.h"
12 +
13   #include  "ray.h"
14  
14 #include  "octree.h"
15
15   #include  "otypes.h"
16  
17   #include  "source.h"
# Line 23 | Line 22 | static char SCCSid[] = "$SunId$ LBL";
22   #define  STESTMAX       32              /* maximum seeks per sample */
23  
24  
26 double  getdisk();
27
25   static OBJECT  *vobject;                /* virtual source objects */
26   static int  nvobjects = 0;              /* number of virtual source objects */
27  
28  
29 + void
30   markvirtuals()                  /* find and mark virtual sources */
31   {
32          register OBJREC  *o;
# Line 37 | Line 35 | markvirtuals()                 /* find and mark virtual sources */
35          if (directrelay <= 0)
36                  return;
37                                          /* find virtual source objects */
38 <        for (i = 0; i < nobjects; i++) {
38 >        for (i = 0; i < nsceneobjs; i++) {
39                  o = objptr(i);
40                  if (!issurface(o->otype) || o->omod == OVOID)
41                          continue;
# Line 51 | Line 49 | markvirtuals()                 /* find and mark virtual sources */
49                  if (nvobjects == 0)
50                          vobject = (OBJECT *)malloc(sizeof(OBJECT));
51                  else
52 <                        vobject = (OBJECT *)realloc((char *)vobject,
52 >                        vobject = (OBJECT *)realloc((void *)vobject,
53                                  (unsigned)(nvobjects+1)*sizeof(OBJECT));
54                  if (vobject == NULL)
55                          error(SYSTEM, "out of memory in addvirtuals");
# Line 66 | Line 64 | markvirtuals()                 /* find and mark virtual sources */
64          for (i = nsources; i-- > 0; )
65                  addvirtuals(i, directrelay);
66                                          /* done with our object list */
67 <        free((char *)vobject);
67 >        free((void *)vobject);
68          nvobjects = 0;
69   }
70  
71  
72 + void
73   addvirtuals(sn, nr)             /* add virtuals associated with source */
74   int  sn;
75   int  nr;
# Line 88 | Line 87 | int  nr;
87   }
88  
89  
90 + void
91   vproject(o, sn, n)              /* create projected source(s) if they exist */
92   OBJREC  *o;
93   int  sn;
# Line 123 | Line 123 | OBJREC  *o;
123          register OBJREC  *m;
124  
125          i = o->omod;
126 <        m = objptr(i);
126 >        m = findmaterial(objptr(i));
127 >        if (m == NULL)
128 >                return(objptr(i));
129          if (m->otype != MAT_ILLUM || m->oargs.nsargs < 1 ||
130                          !strcmp(m->oargs.sarg[0], VOIDID) ||
131 <                        (i = modifier(m->oargs.sarg[0])) == OVOID)
131 >                        (i = lastmod(objndx(m), m->oargs.sarg[0])) == OVOID)
132                  return(m);              /* direct modifier */
133          return(objptr(i));              /* illum alternate */
134   }
# Line 157 | Line 159 | MAT4  pm;
159                  normalize(nsloc);
160                  VCOPY(ourspot.aim, ocent);
161                  ourspot.siz = PI*maxrad2;
162 <                ourspot.flen = 0.;
162 >                ourspot.flen = -1.;
163                  if (source[sn].sflags & SSPOT) {
164                          multp3(theirspot.aim, source[sn].sl.s->aim, pm);
165                                                  /* adjust for source size */
# Line 194 | Line 196 | MAT4  pm;
196                  else
197                          nsflags &= ~SSPOT;
198                  if (source[sn].sflags & SSPOT) {
199 <                        copystruct(&theirspot, source[sn].sl.s);
199 >                        theirspot = *(source[sn].sl.s);
200                          multv3(theirspot.aim, source[sn].sl.s->aim, pm);
201                          normalize(theirspot.aim);
202                          if (nsflags & SSPOT) {
# Line 204 | Line 206 | MAT4  pm;
206                                          return(-1);     /* no overlap */
207                          } else {
208                                  nsflags |= SSPOT;
209 <                                copystruct(&ourspot, &theirspot);
209 >                                ourspot = theirspot;
210                                  d = 2.*ourspot.siz;
211                          }
212                          if (ourspot.siz < d-FTINY) {    /* it shrunk */
# Line 244 | Line 246 | MAT4  pm;
246          if (nsflags & SSPOT) {
247                  if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
248                          goto memerr;
249 <                copystruct(source[i].sl.s, &ourspot);
249 >                *(source[i].sl.s) = ourspot;
250          }
251          if (nsflags & SPROX)
252                  source[i].sl.prox = source[sn].sl.prox;
# Line 301 | Line 303 | register int  sn;      /* target source number */
303          FVECT  offsdir;
304          SRCINDEX  si;
305          double  or, d;
304        int  infront;
306          int  stestlim, ssn;
307          int  nhit, nok;
308          register int  i, n;
# Line 314 | Line 315 | register int  sn;      /* target source number */
315          if (source[sn].sflags & SDISTANT) {
316                                          /* 32. == heuristic constant */
317                  n = 32.*or2/(thescene.cusize*thescene.cusize)*vspretest + .5;
317                infront = DOT(onorm, source[sn].sloc) > 0.;
318          } else {
319                  for (i = 0; i < 3; i++)
320                          offsdir[i] = source[sn].sloc[i] - oc[i];
# Line 323 | Line 323 | register int  sn;      /* target source number */
323                          n = 2.*PI * vspretest + .5;
324                  else
325                          n = 2.*PI * (1.-sqrt(1./(1.+or2/d)))*vspretest + .5;
326                infront = DOT(onorm, offsdir) > 0.;
326          }
327          if (n < MINSAMPLES) n = MINSAMPLES;
328   #ifdef DEBUG
# Line 335 | Line 334 | register int  sn;      /* target source number */
334          stestlim = n*STESTMAX;
335          ssn = 0;
336          nhit = nok = 0;
337 +        initsrcindex(&si);
338          while (n-- > 0) {
339                                          /* get sample point */
340                  do {
# Line 348 | Line 348 | register int  sn;      /* target source number */
348                          for (i = 0; i < 3; i++)
349                                  offsdir[i] = or*(1. - 2.*offsdir[i]);
350                          ssn++;
351 <                        for (i = 0; i < 3; i++)
352 <                                sr.rorg[i] = oc[i] + offsdir[i];
353 <                        d = DOT(offsdir,onorm);
354 <                        if (infront)
355 <                                for (i = 0; i < 3; i++) {
356 <                                        sr.rorg[i] -= (d-.0001)*onorm[i];
357 <                                        sr.rdir[i] = -onorm[i];
358 <                                }
359 <                        else
360 <                                for (i = 0; i < 3; i++) {
361 <                                        sr.rorg[i] -= (d+.0001)*onorm[i];
362 <                                        sr.rdir[i] = onorm[i];
363 <                                }
351 >                        d = 1. - DOT(offsdir, onorm);
352 >                        for (i = 0; i < 3; i++) {
353 >                                sr.rorg[i] = oc[i] + offsdir[i] + d*onorm[i];
354 >                                sr.rdir[i] = -onorm[i];
355 >                        }
356 >                        sr.rmax = 0.0;
357                          rayorigin(&sr, NULL, PRIMARY, 1.0);
358                  } while (!(*ofun[o->otype].funp)(o, &sr));
359                                          /* check against source */
360 <                initsrcindex(&si);
368 <                si.sn = sn;
369 <                nopart(&si, &sr);
360 >                VCOPY(sr.rorg, sr.rop); /* starting from intersection */
361                  samplendx++;
362 <                if (!srcray(&sr, NULL, &si) || sr.rsrc != sn)
363 <                        continue;
362 >                if (si.sp >= si.np-1 ||
363 >                                !srcray(&sr, NULL, &si) || sr.rsrc != sn) {
364 >                        si.sn = sn-1;           /* reset index to our source */
365 >                        si.np = 0;
366 >                        if (!srcray(&sr, NULL, &si) || sr.rsrc != sn)
367 >                                continue;       /* can't get there from here */
368 >                }
369                  sr.revf = srcvalue;
370 <                rayvalue(&sr);
370 >                rayvalue(&sr);                  /* check sample validity */
371                  if (bright(sr.rcol) <= FTINY)
372                          continue;
373 <                nok++;
378 <                                        /* check against obstructions */
373 >                nok++;                  /* got sample; check obstructions */
374                  rayclear(&sr);
375                  sr.revf = raytrace;
376                  rayvalue(&sr);
# Line 402 | Line 397 | register int  sn;      /* target source number */
397          
398  
399   #ifdef DEBUG
400 + void
401   virtverb(sn, fp)        /* print verbose description of virtual source */
402   register int  sn;
403   FILE  *fp;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines