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.7 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.23 by greg, Thu Nov 8 00:54:07 2018 UTC

# Line 8 | Line 8 | static const char      RCSid[] = "$Id$";
8   *  External symbols declared in source.h
9   */
10  
11 < /* ====================================================================
12 < * The Radiance Software License, Version 1.0
13 < *
14 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
15 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
16 < *
17 < * Redistribution and use in source and binary forms, with or without
18 < * modification, are permitted provided that the following conditions
19 < * are met:
20 < *
21 < * 1. Redistributions of source code must retain the above copyright
22 < *         notice, this list of conditions and the following disclaimer.
23 < *
24 < * 2. Redistributions in binary form must reproduce the above copyright
25 < *       notice, this list of conditions and the following disclaimer in
26 < *       the documentation and/or other materials provided with the
27 < *       distribution.
28 < *
29 < * 3. The end-user documentation included with the redistribution,
30 < *           if any, must include the following acknowledgment:
31 < *             "This product includes Radiance software
32 < *                 (http://radsite.lbl.gov/)
33 < *                 developed by the Lawrence Berkeley National Laboratory
34 < *               (http://www.lbl.gov/)."
35 < *       Alternately, this acknowledgment may appear in the software itself,
36 < *       if and wherever such third-party acknowledgments normally appear.
37 < *
38 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
39 < *       and "The Regents of the University of California" must
40 < *       not be used to endorse or promote products derived from this
41 < *       software without prior written permission. For written
42 < *       permission, please contact [email protected].
43 < *
44 < * 5. Products derived from this software may not be called "Radiance",
45 < *       nor may "Radiance" appear in their name, without prior written
46 < *       permission of Lawrence Berkeley National Laboratory.
47 < *
48 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
49 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
50 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
51 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
52 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
55 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
56 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
57 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
58 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 < * SUCH DAMAGE.
60 < * ====================================================================
61 < *
62 < * This software consists of voluntary contributions made by many
63 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
64 < * information on Lawrence Berkeley National Laboratory, please see
65 < * <http://www.lbl.gov/>.
66 < */
11 > #include "copyright.h"
12  
13   #include  "ray.h"
69
14   #include  "otypes.h"
15 <
15 > #include  "otspecial.h"
16   #include  "source.h"
73
17   #include  "random.h"
18  
19   #define  MINSAMPLES     16              /* minimum number of pretest samples */
20   #define  STESTMAX       32              /* maximum seeks per sample */
21  
22 + #define FEQ(a,b)        ((a)-(b)+FTINY >= 0 && (b)-(a)+FTINY >= 0)
23  
24 +
25   static OBJECT  *vobject;                /* virtual source objects */
26   static int  nvobjects = 0;              /* number of virtual source objects */
27  
28  
29 + static int
30 + isident4(MAT4 m)
31 + {
32 +        int     i, j;
33 +
34 +        for (i = 4; i--; )
35 +                for (j = 4; j--; )
36 +                        if (!FEQ(m[i][j], i==j))
37 +                                return(0);
38 +        return(1);
39 + }
40 +
41 +
42   void
43 < markvirtuals()                  /* find and mark virtual sources */
43 > markvirtuals(void)                      /* find and mark virtual sources */
44   {
45 <        register OBJREC  *o;
46 <        register int  i;
45 >        OBJREC  *o;
46 >        int  i;
47                                          /* check number of direct relays */
48          if (directrelay <= 0)
49                  return;
50                                          /* find virtual source objects */
51 <        for (i = 0; i < nobjects; i++) {
51 >        for (i = 0; i < nsceneobjs; i++) {
52                  o = objptr(i);
53                  if (!issurface(o->otype) || o->omod == OVOID)
54                          continue;
# Line 104 | Line 62 | markvirtuals()                 /* find and mark virtual sources */
62                  if (nvobjects == 0)
63                          vobject = (OBJECT *)malloc(sizeof(OBJECT));
64                  else
65 <                        vobject = (OBJECT *)realloc((char *)vobject,
65 >                        vobject = (OBJECT *)realloc((void *)vobject,
66                                  (unsigned)(nvobjects+1)*sizeof(OBJECT));
67                  if (vobject == NULL)
68                          error(SYSTEM, "out of memory in addvirtuals");
# Line 125 | Line 83 | markvirtuals()                 /* find and mark virtual sources */
83  
84  
85   void
86 < addvirtuals(sn, nr)             /* add virtuals associated with source */
87 < int  sn;
88 < int  nr;
86 > addvirtuals(            /* add virtuals associated with source */
87 >        int  sn,
88 >        int  nr
89 > )
90   {
91 <        register int  i;
91 >        int  i;
92                                  /* check relay limit first */
93          if (nr <= 0)
94                  return;
# Line 143 | Line 102 | int  nr;
102  
103  
104   void
105 < vproject(o, sn, n)              /* create projected source(s) if they exist */
106 < OBJREC  *o;
107 < int  sn;
108 < int  n;
105 > vproject(               /* create projected source(s) if they exist */
106 >        OBJREC  *o,
107 >        int  sn,
108 >        int  n
109 > )
110   {
111 <        register int  i;
112 <        register VSMATERIAL  *vsmat;
111 >        int  i;
112 >        VSMATERIAL  *vsmat;
113          MAT4  proj;
114          int  ns;
115  
# Line 171 | Line 131 | int  n;
131  
132  
133   OBJREC *
134 < vsmaterial(o)                   /* get virtual source material pointer */
135 < OBJREC  *o;
134 > vsmaterial(                     /* get virtual source material pointer */
135 >        OBJREC  *o
136 > )
137   {
138 <        register int  i;
139 <        register OBJREC  *m;
138 >        int  i;
139 >        OBJREC  *m;
140  
141          i = o->omod;
142 <        m = objptr(i);
142 >        m = findmaterial(objptr(i));
143 >        if (m == NULL)
144 >                return(objptr(i));
145          if (m->otype != MAT_ILLUM || m->oargs.nsargs < 1 ||
146                          !strcmp(m->oargs.sarg[0], VOIDID) ||
147                          (i = lastmod(objndx(m), m->oargs.sarg[0])) == OVOID)
# Line 188 | Line 151 | OBJREC  *o;
151  
152  
153   int
154 < makevsrc(op, sn, pm)            /* make virtual source if reasonable */
155 < OBJREC  *op;
156 < register int  sn;
157 < MAT4  pm;
154 > makevsrc(               /* make virtual source if reasonable */
155 >        OBJREC  *op,
156 >        int  sn,
157 >        MAT4  pm
158 > )
159   {
160          FVECT  nsloc, nsnorm, ocent, v;
161          double  maxrad2, d;
162          int  nsflags;
163          SPOT  theirspot, ourspot;
164 <        register int  i;
165 <
164 >        int  i;
165 >                                        /* check for no-op */
166 >        if (isident4(pm))
167 >                return(0);
168          nsflags = source[sn].sflags | (SVIRTUAL|SSPOT|SFOLLOW);
169                                          /* get object center and max. radius */
170          maxrad2 = getdisk(ocent, op, sn);
# Line 249 | Line 215 | MAT4  pm;
215                  else
216                          nsflags &= ~SSPOT;
217                  if (source[sn].sflags & SSPOT) {
218 <                        copystruct(&theirspot, source[sn].sl.s);
218 >                        theirspot = *(source[sn].sl.s);
219                          multv3(theirspot.aim, source[sn].sl.s->aim, pm);
220                          normalize(theirspot.aim);
221                          if (nsflags & SSPOT) {
# Line 259 | Line 225 | MAT4  pm;
225                                          return(-1);     /* no overlap */
226                          } else {
227                                  nsflags |= SSPOT;
228 <                                copystruct(&ourspot, &theirspot);
228 >                                ourspot = theirspot;
229                                  d = 2.*ourspot.siz;
230                          }
231                          if (ourspot.siz < d-FTINY) {    /* it shrunk */
# Line 299 | Line 265 | MAT4  pm;
265          if (nsflags & SSPOT) {
266                  if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
267                          goto memerr;
268 <                copystruct(source[i].sl.s, &ourspot);
268 >                *(source[i].sl.s) = ourspot;
269          }
270          if (nsflags & SPROX)
271                  source[i].sl.prox = source[sn].sl.prox;
# Line 308 | Line 274 | MAT4  pm;
274          return(i);
275   memerr:
276          error(SYSTEM, "out of memory in makevsrc");
277 +        return -1; /* pro forma return */
278   }
279  
280  
281   double
282 < getdisk(oc, op, sn)             /* get visible object disk */
283 < FVECT  oc;
284 < OBJREC  *op;
285 < register int  sn;
282 > getdisk(                /* get visible object disk */
283 >        FVECT  oc,
284 >        OBJREC  *op,
285 >        int  sn
286 > )
287   {
288          double  rad2, roffs, offs, d, rd, rdoto;
289          FVECT  rnrm, nrm;
# Line 344 | Line 312 | register int  sn;
312  
313  
314   int
315 < vstestvis(f, o, oc, or2, sn)            /* pretest source visibility */
316 < int  f;                 /* virtual source flags */
317 < OBJREC  *o;             /* relay object */
318 < FVECT  oc;              /* relay object center */
319 < double  or2;            /* relay object radius squared */
320 < register int  sn;       /* target source number */
315 > vstestvis(              /* pretest source visibility */
316 >        int  f,                 /* virtual source flags */
317 >        OBJREC  *o,             /* relay object */
318 >        FVECT  oc,              /* relay object center */
319 >        double  or2,            /* relay object radius squared */
320 >        int  sn /* target source number */
321 > )
322   {
323          RAY  sr;
324          FVECT  onorm;
325 <        FVECT  offsdir;
325 >        double  offsdir[3];
326          SRCINDEX  si;
327 <        double  or, d;
327 >        double  or, d, d1;
328          int  stestlim, ssn;
329          int  nhit, nok;
330 <        register int  i, n;
330 >        int  i, n;
331                                  /* return if pretesting disabled */
332          if (vspretest <= 0)
333                  return(f);
# Line 369 | Line 338 | register int  sn;      /* target source number */
338                                          /* 32. == heuristic constant */
339                  n = 32.*or2/(thescene.cusize*thescene.cusize)*vspretest + .5;
340          } else {
341 <                for (i = 0; i < 3; i++)
373 <                        offsdir[i] = source[sn].sloc[i] - oc[i];
341 >                VSUB(offsdir, source[sn].sloc, oc);
342                  d = DOT(offsdir,offsdir);
343                  if (d <= FTINY)
344                          n = 2.*PI * vspretest + .5;
# Line 407 | Line 375 | register int  sn;      /* target source number */
375                                  sr.rdir[i] = -onorm[i];
376                          }
377                          sr.rmax = 0.0;
378 <                        rayorigin(&sr, NULL, PRIMARY, 1.0);
378 >                        rayorigin(&sr, PRIMARY, NULL, NULL);
379                  } while (!(*ofun[o->otype].funp)(o, &sr));
380                                          /* check against source */
381                  VCOPY(sr.rorg, sr.rop); /* starting from intersection */
# Line 421 | Line 389 | register int  sn;      /* target source number */
389                  }
390                  sr.revf = srcvalue;
391                  rayvalue(&sr);                  /* check sample validity */
392 <                if (bright(sr.rcol) <= FTINY)
392 >                if ((d = bright(sr.rcol)) <= FTINY)
393                          continue;
394                  nok++;                  /* got sample; check obstructions */
395                  rayclear(&sr);
396                  sr.revf = raytrace;
397                  rayvalue(&sr);
398 <                if (bright(sr.rcol) > FTINY)
398 >                if ((d1 = bright(sr.rcol)) > FTINY) {
399 >                        if (d - d1 > FTINY) {
400 > #ifdef DEBUG
401 >                                fprintf(stderr, "\tpartially shadowed\n");
402 > #endif
403 >                                return(f);      /* intervening transmitter */
404 >                        }
405                          nhit++;
406 +                }
407                  if (nhit > 0 && nhit < nok) {
408   #ifdef DEBUG
409                          fprintf(stderr, "\tpartially occluded\n");
# Line 451 | Line 426 | register int  sn;      /* target source number */
426  
427   #ifdef DEBUG
428   void
429 < virtverb(sn, fp)        /* print verbose description of virtual source */
430 < register int  sn;
431 < FILE  *fp;
429 > virtverb(       /* print verbose description of virtual source */
430 >        int  sn,
431 >        FILE  *fp
432 > )
433   {
458        register int  i;
459
434          fprintf(fp, "%s virtual source %d in %s %s\n",
435                          source[sn].sflags & SDISTANT ? "distant" : "local",
436                          sn, ofun[source[sn].so->otype].funame,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines