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

Comparing ray/src/rt/rtrace.c (file contents):
Revision 2.16 by greg, Wed Jul 14 10:38:49 1993 UTC vs.
Revision 2.27 by greg, Sat Feb 22 02:07:29 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 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   *  rtrace.c - program and variables for individual ray tracing.
6 + */
7 +
8 + /* ====================================================================
9 + * The Radiance Software License, Version 1.0
10   *
11 < *     6/11/86
11 > * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 > * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 > *
14 > * Redistribution and use in source and binary forms, with or without
15 > * modification, are permitted provided that the following conditions
16 > * are met:
17 > *
18 > * 1. Redistributions of source code must retain the above copyright
19 > *         notice, this list of conditions and the following disclaimer.
20 > *
21 > * 2. Redistributions in binary form must reproduce the above copyright
22 > *       notice, this list of conditions and the following disclaimer in
23 > *       the documentation and/or other materials provided with the
24 > *       distribution.
25 > *
26 > * 3. The end-user documentation included with the redistribution,
27 > *           if any, must include the following acknowledgment:
28 > *             "This product includes Radiance software
29 > *                 (http://radsite.lbl.gov/)
30 > *                 developed by the Lawrence Berkeley National Laboratory
31 > *               (http://www.lbl.gov/)."
32 > *       Alternately, this acknowledgment may appear in the software itself,
33 > *       if and wherever such third-party acknowledgments normally appear.
34 > *
35 > * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 > *       and "The Regents of the University of California" must
37 > *       not be used to endorse or promote products derived from this
38 > *       software without prior written permission. For written
39 > *       permission, please contact [email protected].
40 > *
41 > * 5. Products derived from this software may not be called "Radiance",
42 > *       nor may "Radiance" appear in their name, without prior written
43 > *       permission of Lawrence Berkeley National Laboratory.
44 > *
45 > * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 > * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 > * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 > * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 > * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 > * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 > * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 > * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 > * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 > * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 > * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 > * SUCH DAMAGE.
57 > * ====================================================================
58 > *
59 > * This software consists of voluntary contributions made by many
60 > * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 > * information on Lawrence Berkeley National Laboratory, please see
62 > * <http://www.lbl.gov/>.
63   */
64  
65   /*
# Line 26 | Line 78 | static char SCCSid[] = "$SunId$ LBL";
78  
79   #include  "ray.h"
80  
29 #include  "octree.h"
30
81   #include  "otypes.h"
82  
83   #include  "resolu.h"
84  
85 + CUBE  thescene;                         /* our scene */
86 + OBJECT  nsceneobjs;                     /* number of objects in our scene */
87 +
88   int  dimlist[MAXDIM];                   /* sampling dimensions */
89   int  ndims = 0;                         /* number of sampling dimensions */
90   int  samplendx = 0;                     /* index for this sample */
91  
92   int  imm_irrad = 0;                     /* compute immediate irradiance? */
93 + int  lim_dist = 0;                      /* limit distance? */
94  
95   int  inform = 'a';                      /* input format */
96   int  outform = 'a';                     /* output format */
97   char  *outvals = "v";                   /* output specification */
98  
99 + int  do_irrad = 0;                      /* compute irradiance? */
100 +
101 + void  (*trace)() = NULL;                /* trace call */
102 +
103 + extern void  ambnotify(), tranotify();
104 + void  (*addobjnotify[])() = {ambnotify, tranotify, NULL};
105   char  *tralist[128];                    /* list of modifers to trace (or no) */
106   int  traincl = -1;                      /* include == 1, exclude == 0 */
107   #define  MAXTSET        511             /* maximum number in trace set */
# Line 53 | Line 113 | int  vresolu = 0;                      /* vertical resolution */
113   double  dstrsrc = 0.0;                  /* square source distribution */
114   double  shadthresh = .05;               /* shadow threshold */
115   double  shadcert = .5;                  /* shadow certainty */
116 < int  directrelay = 1;                   /* number of source relays */
116 > int  directrelay = 2;                   /* number of source relays */
117   int  vspretest = 512;                   /* virtual source pretest density */
118   int  directvis = 1;                     /* sources visible? */
119 < double  srcsizerat = .25;               /* maximum ratio source size/dist. */
119 > double  srcsizerat = .2;                /* maximum ratio source size/dist. */
120  
121 + COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
122 + COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
123 + double  seccg = 0.;                     /* global scattering eccentricity */
124 + double  ssampdist = 0.;                 /* scatter sampling distance */
125 +
126   double  specthresh = .15;               /* specular sampling threshold */
127   double  specjitter = 1.;                /* specular sampling jitter */
128  
129 + int  backvis = 1;                       /* back face visibility */
130 +
131   int  maxdepth = 6;                      /* maximum recursion depth */
132   double  minweight = 4e-3;               /* minimum ray weight */
133  
134 + char  *ambfile = NULL;                  /* ambient file name */
135   COLOR  ambval = BLKCOLOR;               /* ambient value */
136 + int  ambvwt = 0;                        /* initial weight for ambient value */
137   double  ambacc = 0.2;                   /* ambient accuracy */
138 < int  ambres = 32;                       /* ambient resolution */
139 < int  ambdiv = 128;                      /* ambient divisions */
138 > int  ambres = 128;                      /* ambient resolution */
139 > int  ambdiv = 512;                      /* ambient divisions */
140   int  ambssamp = 0;                      /* ambient super-samples */
141   int  ambounce = 0;                      /* ambient bounces */
142   char  *amblist[128];                    /* ambient include/exclude list */
143   int  ambincl = -1;                      /* include == 1, exclude == 0 */
144  
76 extern OBJREC  Lamb;                    /* a Lambertian surface */
145  
146   static RAY  thisray;                    /* for our convenience */
147  
148 < static int  oputo(), oputd(), oputv(), oputl(), oputL(),
148 > static void  oputo(), oputd(), oputv(), oputl(), oputL(),
149                  oputp(), oputn(), oputN(), oputs(), oputw(), oputm();
150  
151 < static int  ourtrace(), tabin();
152 < static int  (*ray_out[16])(), (*every_out[16])();
151 > static void  ourtrace(), tabin();
152 > static void  (*ray_out[16])(), (*every_out[16])();
153   static int  castonly = 0;
154  
155 < static int  puta(), putf(), putd();
155 > static void  puta(), putf(), putd();
156  
157 < static int  (*putreal)();
157 > static void  (*putreal)();
158  
159 + void    bogusray(), rad(), irrad(), printvals();
160  
161 +
162 + void
163   quit(code)                      /* quit program */
164   int  code;
165   {
# Line 114 | Line 185 | int  f;
185   }
186  
187  
188 + void
189   rtrace(fname)                           /* trace rays from file */
190   char  *fname;
191   {
192          long  vcount = hresolu>1 ? hresolu*vresolu : vresolu;
193          long  nextflush = hresolu;
194          FILE  *fp;
195 +        double  d;
196          FVECT  orig, direc;
197                                          /* set up input */
198          if (fname == NULL)
# Line 154 | Line 227 | char  *fname;
227          while (getvec(orig, inform, fp) == 0 &&
228                          getvec(direc, inform, fp) == 0) {
229  
230 <                if (normalize(direc) == 0.0) {          /* zero ==> flush */
231 <                        fflush(stdout);
232 <                        continue;
233 <                }
234 <                samplendx++;
230 >                d = normalize(direc);
231 >                if (d == 0.0) {                         /* zero ==> flush */
232 >                        bogusray();
233 >                        if (--nextflush <= 0 || vcount <= 0) {
234 >                                fflush(stdout);
235 >                                nextflush = hresolu;
236 >                        }
237 >                } else {
238 >                        samplendx++;
239                                                          /* compute and print */
240 <                if (imm_irrad)
241 <                        irrad(orig, direc);
242 <                else
243 <                        rad(orig, direc);
240 >                        if (imm_irrad)
241 >                                irrad(orig, direc);
242 >                        else
243 >                                rad(orig, direc, lim_dist ? d : 0.0);
244                                                          /* flush if time */
245 <                if (--nextflush == 0) {
246 <                        fflush(stdout);
247 <                        nextflush = hresolu;
245 >                        if (--nextflush == 0) {
246 >                                fflush(stdout);
247 >                                nextflush = hresolu;
248 >                        }
249                  }
250                  if (ferror(stdout))
251                          error(SYSTEM, "write error");
# Line 185 | Line 263 | char  *fname;
263   setoutput(vs)                           /* set up output tables */
264   register char  *vs;
265   {
266 <        extern int  (*trace)();
267 <        register int (**table)() = ray_out;
266 >        extern void  (*trace)();
267 >        register void (**table)() = ray_out;
268  
269          castonly = 1;
270          while (*vs)
# Line 238 | Line 316 | register char  *vs;
316   }
317  
318  
319 < rad(org, dir)                   /* compute and print ray value(s) */
319 > void
320 > bogusray()                      /* print out empty record */
321 > {
322 >        thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
323 >        thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
324 >        rayorigin(&thisray, NULL, PRIMARY, 1.0);
325 >        printvals(&thisray);
326 > }
327 >
328 >
329 > void
330 > rad(org, dir, dmax)             /* compute and print ray value(s) */
331   FVECT  org, dir;
332 + double  dmax;
333   {
334          VCOPY(thisray.rorg, org);
335          VCOPY(thisray.rdir, dir);
336 +        thisray.rmax = dmax;
337          rayorigin(&thisray, NULL, PRIMARY, 1.0);
338 <        if (castonly)
339 <                localhit(&thisray, &thescene) || sourcehit(&thisray);
340 <        else
338 >        if (castonly) {
339 >                if (!localhit(&thisray, &thescene))
340 >                        if (thisray.ro == &Aftplane) {  /* clipped */
341 >                                thisray.ro = NULL;
342 >                                thisray.rot = FHUGE;
343 >                        } else
344 >                                sourcehit(&thisray);
345 >        } else
346                  rayvalue(&thisray);
347          printvals(&thisray);
348   }
349  
350  
351 + void
352   irrad(org, dir)                 /* compute immediate irradiance value */
353   FVECT  org, dir;
354   {
# Line 274 | Line 371 | FVECT  org, dir;
371   }
372  
373  
374 + void
375   printvals(r)                    /* print requested ray values */
376   RAY  *r;
377   {
378 <        register int  (**tp)();
378 >        register void  (**tp)();
379  
380          if (ray_out[0] == NULL)
381                  return;
# Line 288 | Line 386 | RAY  *r;
386   }
387  
388  
389 + int
390   getvec(vec, fmt, fp)            /* get a vector from fp */
391   register FVECT  vec;
392   int  fmt;
393   FILE  *fp;
394   {
296        extern char  *fgetword();
395          static float  vf[3];
396          static double  vd[3];
397          char  buf[32];
# Line 325 | Line 423 | FILE  *fp;
423   }
424  
425  
426 + void
427   tranotify(obj)                  /* record new modifier */
428   OBJECT  obj;
429   {
# Line 332 | Line 431 | OBJECT obj;
431          register OBJREC  *o = objptr(obj);
432          register char  **tralp;
433  
434 +        if (obj == OVOID) {             /* starting over */
435 +                traset[0] = 0;
436 +                hitlimit = 0;
437 +                return;
438 +        }
439          if (hitlimit || !ismodifier(o->otype))
440                  return;
441          for (tralp = tralist; *tralp != NULL; tralp++)
# Line 347 | Line 451 | OBJECT obj;
451   }
452  
453  
454 < static
454 > static void
455   ourtrace(r)                             /* print ray values */
456   RAY  *r;
457   {
458 <        register int  (**tp)();
458 >        register void  (**tp)();
459  
460          if (every_out[0] == NULL)
461                  return;
# Line 367 | Line 471 | RAY  *r;
471   }
472  
473  
474 < static
474 > static void
475   tabin(r)                                /* tab in appropriate amount */
476   RAY  *r;
477   {
# Line 378 | Line 482 | RAY  *r;
482   }
483  
484  
485 < static
485 > static void
486   oputo(r)                                /* print origin */
487   register RAY  *r;
488   {
# Line 388 | Line 492 | register RAY  *r;
492   }
493  
494  
495 < static
495 > static void
496   oputd(r)                                /* print direction */
497   register RAY  *r;
498   {
# Line 398 | Line 502 | register RAY  *r;
502   }
503  
504  
505 < static
505 > static void
506   oputv(r)                                /* print value */
507   register RAY  *r;
508   {
# Line 417 | Line 521 | register RAY  *r;
521   }
522  
523  
524 < static
524 > static void
525   oputl(r)                                /* print effective distance */
526   register RAY  *r;
527   {
# Line 425 | Line 529 | register RAY  *r;
529   }
530  
531  
532 < static
532 > static void
533   oputL(r)                                /* print single ray length */
534   register RAY  *r;
535   {
# Line 433 | Line 537 | register RAY  *r;
537   }
538  
539  
540 < static
540 > static void
541   oputp(r)                                /* print point */
542   register RAY  *r;
543   {
# Line 449 | Line 553 | register RAY  *r;
553   }
554  
555  
556 < static
556 > static void
557   oputN(r)                                /* print unperturbed normal */
558   register RAY  *r;
559   {
# Line 465 | Line 569 | register RAY  *r;
569   }
570  
571  
572 < static
572 > static void
573   oputn(r)                                /* print perturbed normal */
574   RAY  *r;
575   {
# Line 484 | Line 588 | RAY  *r;
588   }
589  
590  
591 < static
591 > static void
592   oputs(r)                                /* print name */
593   register RAY  *r;
594   {
# Line 496 | Line 600 | register RAY  *r;
600   }
601  
602  
603 < static
603 > static void
604   oputw(r)                                /* print weight */
605   register RAY  *r;
606   {
# Line 504 | Line 608 | register RAY  *r;
608   }
609  
610  
611 < static
611 > static void
612   oputm(r)                                /* print modifier */
613   register RAY  *r;
614   {
615          if (r->ro != NULL)
616 <                fputs(objptr(r->ro->omod)->oname, stdout);
616 >                if (r->ro->omod != OVOID)
617 >                        fputs(objptr(r->ro->omod)->oname, stdout);
618 >                else
619 >                        fputs(VOIDID, stdout);
620          else
621                  putchar('*');
622          putchar('\t');
623   }
624  
625  
626 < static
626 > static void
627   puta(v)                         /* print ascii value */
628   double  v;
629   {
# Line 524 | Line 631 | double  v;
631   }
632  
633  
634 < static
634 > static void
635   putd(v)                         /* print binary double */
636   double  v;
637   {
# Line 532 | Line 639 | double  v;
639   }
640  
641  
642 < static
642 > static void
643   putf(v)                         /* print binary float */
644   double  v;
645   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines