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.27 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.49 by schorsch, Mon Sep 19 11:30:10 2005 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  rtrace.c - program and variables for individual ray tracing.
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
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 < */
8 > #include "copyright.h"
9  
10   /*
11   *  Input is in the form:
# Line 76 | Line 21 | static const char      RCSid[] = "$Id$";
21   *  irradiance values are desired.
22   */
23  
24 < #include  "ray.h"
24 > #include  <time.h>
25  
26 + #include  "platform.h"
27 + #include  "ray.h"
28 + #include  "ambient.h"
29 + #include  "source.h"
30   #include  "otypes.h"
82
31   #include  "resolu.h"
32 + #include  "random.h"
33  
34   CUBE  thescene;                         /* our scene */
35   OBJECT  nsceneobjs;                     /* number of objects in our scene */
# Line 98 | Line 47 | char  *outvals = "v";                  /* output specification */
47  
48   int  do_irrad = 0;                      /* compute irradiance? */
49  
50 + int  rand_samp = 0;                     /* pure Monte Carlo sampling? */
51 +
52   void  (*trace)() = NULL;                /* trace call */
53  
103 extern void  ambnotify(), tranotify();
104 void  (*addobjnotify[])() = {ambnotify, tranotify, NULL};
54   char  *tralist[128];                    /* list of modifers to trace (or no) */
55   int  traincl = -1;                      /* include == 1, exclude == 0 */
56 < #define  MAXTSET        511             /* maximum number in trace set */
56 > #ifndef  MAXTSET
57 > #define  MAXTSET        1024            /* maximum number in trace set */
58 > #endif
59   OBJECT  traset[MAXTSET+1]={0};          /* trace include/exclude set */
60  
61   int  hresolu = 0;                       /* horizontal (scan) size */
62   int  vresolu = 0;                       /* vertical resolution */
63  
64   double  dstrsrc = 0.0;                  /* square source distribution */
65 < double  shadthresh = .05;               /* shadow threshold */
66 < double  shadcert = .5;                  /* shadow certainty */
65 > double  shadthresh = .03;               /* shadow threshold */
66 > double  shadcert = .75;                 /* shadow certainty */
67   int  directrelay = 2;                   /* number of source relays */
68   int  vspretest = 512;                   /* virtual source pretest density */
69   int  directvis = 1;                     /* sources visible? */
# Line 128 | Line 79 | double  specjitter = 1.;               /* specular sampling jitter
79  
80   int  backvis = 1;                       /* back face visibility */
81  
82 < int  maxdepth = 6;                      /* maximum recursion depth */
83 < double  minweight = 4e-3;               /* minimum ray weight */
82 > int  maxdepth = -10;                    /* maximum recursion depth */
83 > double  minweight = 2e-3;               /* minimum ray weight */
84  
85   char  *ambfile = NULL;                  /* ambient file name */
86   COLOR  ambval = BLKCOLOR;               /* ambient value */
87   int  ambvwt = 0;                        /* initial weight for ambient value */
88 < double  ambacc = 0.2;                   /* ambient accuracy */
89 < int  ambres = 128;                      /* ambient resolution */
90 < int  ambdiv = 512;                      /* ambient divisions */
91 < int  ambssamp = 0;                      /* ambient super-samples */
88 > double  ambacc = 0.15;                  /* ambient accuracy */
89 > int  ambres = 256;                      /* ambient resolution */
90 > int  ambdiv = 1024;                     /* ambient divisions */
91 > int  ambssamp = 512;                    /* ambient super-samples */
92   int  ambounce = 0;                      /* ambient bounces */
93 < char  *amblist[128];                    /* ambient include/exclude list */
93 > char  *amblist[AMBLLEN];                /* ambient include/exclude list */
94   int  ambincl = -1;                      /* include == 1, exclude == 0 */
95  
96 + static int  castonly = 0;
97  
98   static RAY  thisray;                    /* for our convenience */
99  
100 < static void  oputo(), oputd(), oputv(), oputl(), oputL(),
101 <                oputp(), oputn(), oputN(), oputs(), oputw(), oputm();
100 > typedef void putf_t(double v);
101 > static putf_t puta, putd, putf;
102  
103 < static void  ourtrace(), tabin();
104 < static void  (*ray_out[16])(), (*every_out[16])();
105 < static int  castonly = 0;
103 > typedef void oputf_t(RAY *r);
104 > static oputf_t  oputo, oputd, oputv, oputl, oputL, oputc, oputp,
105 >                oputn, oputN, oputs, oputw, oputW, oputm, oputM, oputtilde;
106  
107 < static void  puta(), putf(), putd();
107 > static void setoutput(char *vs);
108 > static void tranotify(OBJECT obj);
109 > static void bogusray(void);
110 > static void rad(FVECT  org, FVECT  dir, double  dmax);
111 > static void irrad(FVECT  org, FVECT  dir);
112 > static void printvals(RAY  *r);
113 > static int getvec(FVECT  vec, int  fmt, FILE  *fp);
114 > static void tabin(RAY  *r);
115 > static void ourtrace(RAY  *r);
116  
117 < static void  (*putreal)();
117 > static oputf_t *ray_out[16], *every_out[16];
118 > static putf_t *putreal;
119  
120 < void    bogusray(), rad(), irrad(), printvals();
120 > void  (*addobjnotify[])() = {ambnotify, tranotify, NULL};
121  
122  
123   void
124 < quit(code)                      /* quit program */
125 < int  code;
124 > quit(                   /* quit program */
125 >        int  code
126 > )
127   {
128 < #ifndef  NIX
128 > #ifndef  NON_POSIX /* XXX we don't clean up elsewhere? */
129          headclean();            /* delete header file */
130          pfclean();              /* clean up persist files */
131   #endif
# Line 171 | Line 133 | int  code;
133   }
134  
135  
136 < char *
137 < formstr(f)                              /* return format identifier */
138 < int  f;
136 > extern char *
137 > formstr(                                /* return format identifier */
138 >        int  f
139 > )
140   {
141          switch (f) {
142          case 'a': return("ascii");
# Line 185 | Line 148 | int  f;
148   }
149  
150  
151 < void
152 < rtrace(fname)                           /* trace rays from file */
153 < char  *fname;
151 > extern void
152 > rtrace(                         /* trace rays from file */
153 >        char  *fname
154 > )
155   {
156 <        long  vcount = hresolu>1 ? hresolu*vresolu : vresolu;
156 >        unsigned long  vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu
157 >                                              : vresolu;
158          long  nextflush = hresolu;
159          FILE  *fp;
160          double  d;
# Line 201 | Line 166 | char  *fname;
166                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
167                  error(SYSTEM, errmsg);
168          }
204 #ifdef MSDOS
169          if (inform != 'a')
170 <                setmode(fileno(fp), O_BINARY);
207 < #endif
170 >                SET_FILE_BINARY(fp);
171                                          /* set up output */
172          setoutput(outvals);
173          switch (outform) {
# Line 230 | Line 193 | char  *fname;
193                  d = normalize(direc);
194                  if (d == 0.0) {                         /* zero ==> flush */
195                          bogusray();
196 <                        if (--nextflush <= 0 || vcount <= 0) {
196 >                        if (--nextflush <= 0 || !vcount) {
197                                  fflush(stdout);
198                                  nextflush = hresolu;
199                          }
200                  } else {
201 <                        samplendx++;
201 >                        samplendx = rand_samp ? random() : samplendx+1;
202                                                          /* compute and print */
203                          if (imm_irrad)
204                                  irrad(orig, direc);
205                          else
206                                  rad(orig, direc, lim_dist ? d : 0.0);
207                                                          /* flush if time */
208 <                        if (--nextflush == 0) {
208 >                        if (!--nextflush) {
209                                  fflush(stdout);
210                                  nextflush = hresolu;
211                          }
212                  }
213                  if (ferror(stdout))
214                          error(SYSTEM, "write error");
215 <                if (--vcount == 0)                      /* check for end */
215 >                if (vcount && !--vcount)                /* check for end */
216                          break;
217          }
218          fflush(stdout);
219 <        if (vcount > 0)
220 <                error(USER, "read error");
219 >        if (vcount)
220 >                error(USER, "unexpected EOF on input");
221          if (fname != NULL)
222                  fclose(fp);
223   }
224  
225  
226 < setoutput(vs)                           /* set up output tables */
227 < register char  *vs;
226 > static void
227 > trace_sources(void)                     /* trace rays to light sources, also */
228   {
229 <        extern void  (*trace)();
230 <        register void (**table)() = ray_out;
229 >        int     sn;
230 >        
231 >        for (sn = 0; sn < nsources; sn++)
232 >                source[sn].sflags |= SFOLLOW;
233 > }
234  
235 +
236 + static void
237 + setoutput(                              /* set up output tables */
238 +        register char  *vs
239 + )
240 + {
241 +        register oputf_t **table = ray_out;
242 +
243          castonly = 1;
244          while (*vs)
245                  switch (*vs++) {
246 +                case 'T':                               /* trace sources */
247 +                        if (!*vs) break;
248 +                        trace_sources();
249 +                        /* fall through */
250                  case 't':                               /* trace */
251 +                        if (!*vs) break;
252                          *table = NULL;
253                          table = every_out;
254                          trace = ourtrace;
# Line 289 | Line 268 | register char  *vs;
268                          *table++ = oputl;
269                          castonly = 0;
270                          break;
271 +                case 'c':                               /* local coordinates */
272 +                        *table++ = oputc;
273 +                        break;
274                  case 'L':                               /* single ray length */
275                          *table++ = oputL;
276                          break;
# Line 308 | Line 290 | register char  *vs;
290                  case 'w':                               /* weight */
291                          *table++ = oputw;
292                          break;
293 +                case 'W':                               /* coefficient */
294 +                        *table++ = oputW;
295 +                        if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
296 +                                error(WARNING,
297 +                                        "-otW accuracy depends on -aa 0 -as 0");
298 +                        break;
299                  case 'm':                               /* modifier */
300                          *table++ = oputm;
301                          break;
302 +                case 'M':                               /* material */
303 +                        *table++ = oputM;
304 +                        break;
305 +                case '~':                               /* tilde */
306 +                        *table++ = oputtilde;
307 +                        break;
308                  }
309          *table = NULL;
310   }
311  
312  
313 < void
314 < bogusray()                      /* print out empty record */
313 > static void
314 > bogusray(void)                  /* print out empty record */
315   {
316          thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
317          thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
318 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
318 >        thisray.rmax = 0.0;
319 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
320          printvals(&thisray);
321   }
322  
323  
324 < void
325 < rad(org, dir, dmax)             /* compute and print ray value(s) */
326 < FVECT  org, dir;
327 < double  dmax;
324 > static void
325 > rad(            /* compute and print ray value(s) */
326 >        FVECT  org,
327 >        FVECT  dir,
328 >        double  dmax
329 > )
330   {
331          VCOPY(thisray.rorg, org);
332          VCOPY(thisray.rdir, dir);
333          thisray.rmax = dmax;
334 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
334 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
335          if (castonly) {
336 <                if (!localhit(&thisray, &thescene))
336 >                if (!localhit(&thisray, &thescene)) {
337                          if (thisray.ro == &Aftplane) {  /* clipped */
338                                  thisray.ro = NULL;
339                                  thisray.rot = FHUGE;
340                          } else
341                                  sourcehit(&thisray);
342 +                }
343          } else
344                  rayvalue(&thisray);
345          printvals(&thisray);
346   }
347  
348  
349 < void
350 < irrad(org, dir)                 /* compute immediate irradiance value */
351 < FVECT  org, dir;
349 > static void
350 > irrad(                  /* compute immediate irradiance value */
351 >        FVECT  org,
352 >        FVECT  dir
353 > )
354   {
355          register int  i;
356  
# Line 358 | Line 358 | FVECT  org, dir;
358                  thisray.rorg[i] = org[i] + dir[i];
359                  thisray.rdir[i] = -dir[i];
360          }
361 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
361 >        thisray.rmax = 0.0;
362 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
363                                          /* pretend we hit surface */
364          thisray.rot = 1.0-1e-4;
365          thisray.rod = 1.0;
# Line 371 | Line 372 | FVECT  org, dir;
372   }
373  
374  
375 < void
376 < printvals(r)                    /* print requested ray values */
377 < RAY  *r;
375 > static void
376 > printvals(                      /* print requested ray values */
377 >        RAY  *r
378 > )
379   {
380 <        register void  (**tp)();
380 >        register oputf_t **tp;
381  
382          if (ray_out[0] == NULL)
383                  return;
# Line 386 | Line 388 | RAY  *r;
388   }
389  
390  
391 < int
392 < getvec(vec, fmt, fp)            /* get a vector from fp */
393 < register FVECT  vec;
394 < int  fmt;
395 < FILE  *fp;
391 > static int
392 > getvec(         /* get a vector from fp */
393 >        register FVECT  vec,
394 >        int  fmt,
395 >        FILE  *fp
396 > )
397   {
398          static float  vf[3];
399          static double  vd[3];
# Line 423 | Line 426 | FILE  *fp;
426   }
427  
428  
429 < void
430 < tranotify(obj)                  /* record new modifier */
431 < OBJECT  obj;
429 > static void
430 > tranotify(                      /* record new modifier */
431 >        OBJECT  obj
432 > )
433   {
434          static int  hitlimit = 0;
435          register OBJREC  *o = objptr(obj);
# Line 452 | Line 456 | OBJECT obj;
456  
457  
458   static void
459 < ourtrace(r)                             /* print ray values */
460 < RAY  *r;
459 > ourtrace(                               /* print ray values */
460 >        RAY  *r
461 > )
462   {
463 <        register void  (**tp)();
463 >        register oputf_t **tp;
464  
465          if (every_out[0] == NULL)
466                  return;
# Line 467 | Line 472 | RAY  *r;
472          tabin(r);
473          for (tp = every_out; *tp != NULL; tp++)
474                  (**tp)(r);
475 <        putchar('\n');
475 >        if (outform == 'a')
476 >                putchar('\n');
477   }
478  
479  
480   static void
481 < tabin(r)                                /* tab in appropriate amount */
482 < RAY  *r;
481 > tabin(                          /* tab in appropriate amount */
482 >        RAY  *r
483 > )
484   {
485 <        register RAY  *rp;
485 >        const RAY  *rp;
486  
487          for (rp = r->parent; rp != NULL; rp = rp->parent)
488                  putchar('\t');
# Line 483 | Line 490 | RAY  *r;
490  
491  
492   static void
493 < oputo(r)                                /* print origin */
494 < register RAY  *r;
493 > oputo(                          /* print origin */
494 >        RAY  *r
495 > )
496   {
497          (*putreal)(r->rorg[0]);
498          (*putreal)(r->rorg[1]);
# Line 493 | Line 501 | register RAY  *r;
501  
502  
503   static void
504 < oputd(r)                                /* print direction */
505 < register RAY  *r;
504 > oputd(                          /* print direction */
505 >        RAY  *r
506 > )
507   {
508          (*putreal)(r->rdir[0]);
509          (*putreal)(r->rdir[1]);
# Line 503 | Line 512 | register RAY  *r;
512  
513  
514   static void
515 < oputv(r)                                /* print value */
516 < register RAY  *r;
515 > oputv(                          /* print value */
516 >        RAY  *r
517 > )
518   {
509        COLR  cout;
510        
519          if (outform == 'c') {
520 +                COLR  cout;
521                  setcolr(cout,   colval(r->rcol,RED),
522                                  colval(r->rcol,GRN),
523                                  colval(r->rcol,BLU));
# Line 522 | Line 531 | register RAY  *r;
531  
532  
533   static void
534 < oputl(r)                                /* print effective distance */
535 < register RAY  *r;
534 > oputl(                          /* print effective distance */
535 >        RAY  *r
536 > )
537   {
538          (*putreal)(r->rt);
539   }
540  
541  
542   static void
543 < oputL(r)                                /* print single ray length */
544 < register RAY  *r;
543 > oputL(                          /* print single ray length */
544 >        RAY  *r
545 > )
546   {
547          (*putreal)(r->rot);
548   }
549  
550  
551   static void
552 < oputp(r)                                /* print point */
553 < register RAY  *r;
552 > oputc(                          /* print local coordinates */
553 >        RAY  *r
554 > )
555   {
556 +        (*putreal)(r->uv[0]);
557 +        (*putreal)(r->uv[1]);
558 + }
559 +
560 +
561 + static void
562 + oputp(                          /* print point */
563 +        RAY  *r
564 + )
565 + {
566          if (r->rot < FHUGE) {
567                  (*putreal)(r->rop[0]);
568                  (*putreal)(r->rop[1]);
# Line 554 | Line 576 | register RAY  *r;
576  
577  
578   static void
579 < oputN(r)                                /* print unperturbed normal */
580 < register RAY  *r;
579 > oputN(                          /* print unperturbed normal */
580 >        RAY  *r
581 > )
582   {
583          if (r->rot < FHUGE) {
584                  (*putreal)(r->ron[0]);
# Line 570 | Line 593 | register RAY  *r;
593  
594  
595   static void
596 < oputn(r)                                /* print perturbed normal */
597 < RAY  *r;
596 > oputn(                          /* print perturbed normal */
597 >        RAY  *r
598 > )
599   {
600          FVECT  pnorm;
601  
# Line 589 | Line 613 | RAY  *r;
613  
614  
615   static void
616 < oputs(r)                                /* print name */
617 < register RAY  *r;
616 > oputs(                          /* print name */
617 >        RAY  *r
618 > )
619   {
620          if (r->ro != NULL)
621                  fputs(r->ro->oname, stdout);
# Line 601 | Line 626 | register RAY  *r;
626  
627  
628   static void
629 < oputw(r)                                /* print weight */
630 < register RAY  *r;
629 > oputw(                          /* print weight */
630 >        RAY  *r
631 > )
632   {
633          (*putreal)(r->rweight);
634   }
635  
636  
637   static void
638 < oputm(r)                                /* print modifier */
639 < register RAY  *r;
638 > oputW(                          /* print contribution */
639 >        RAY  *r
640 > )
641   {
642 +        double  contr[3];
643 +
644 +        raycontrib(contr, r, PRIMARY);
645 +        (*putreal)(contr[RED]);
646 +        (*putreal)(contr[GRN]);
647 +        (*putreal)(contr[BLU]);
648 + }
649 +
650 +
651 + static void
652 + oputm(                          /* print modifier */
653 +        RAY  *r
654 + )
655 + {
656          if (r->ro != NULL)
657                  if (r->ro->omod != OVOID)
658                          fputs(objptr(r->ro->omod)->oname, stdout);
# Line 624 | Line 665 | register RAY  *r;
665  
666  
667   static void
668 < puta(v)                         /* print ascii value */
669 < double  v;
668 > oputM(                          /* print material */
669 >        RAY  *r
670 > )
671 > {
672 >        OBJREC  *mat;
673 >
674 >        if (r->ro != NULL) {
675 >                if ((mat = findmaterial(r->ro)) != NULL)
676 >                        fputs(mat->oname, stdout);
677 >                else
678 >                        fputs(VOIDID, stdout);
679 >        } else
680 >                putchar('*');
681 >        putchar('\t');
682 > }
683 >
684 >
685 > static void
686 > oputtilde(                      /* output tilde (spacer) */
687 >        RAY  *r
688 > )
689 > {
690 >        fputs("~\t", stdout);
691 > }
692 >
693 >
694 > static void
695 > puta(                           /* print ascii value */
696 >        double  v
697 > )
698   {
699          printf("%e\t", v);
700   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines