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.38 by greg, Fri Nov 5 17:36:56 2004 UTC vs.
Revision 2.49 by schorsch, Mon Sep 19 11:30:10 2005 UTC

# Line 29 | Line 29 | static const char      RCSid[] = "$Id$";
29   #include  "source.h"
30   #include  "otypes.h"
31   #include  "resolu.h"
32 + #include  "random.h"
33  
34   CUBE  thescene;                         /* our scene */
35   OBJECT  nsceneobjs;                     /* number of objects in our scene */
# Line 46 | 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  
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 */
# Line 74 | Line 79 | double  specjitter = 1.;               /* specular sampling jitter
79  
80   int  backvis = 1;                       /* back face visibility */
81  
82 < int  maxdepth = 8;                      /* maximum recursion depth */
82 > int  maxdepth = -10;                    /* maximum recursion depth */
83   double  minweight = 2e-3;               /* minimum ray weight */
84  
85   char  *ambfile = NULL;                  /* ambient file name */
# Line 96 | Line 101 | typedef void putf_t(double v);
101   static putf_t puta, putd, putf;
102  
103   typedef void oputf_t(RAY *r);
104 < static oputf_t  oputo, oputd, oputv, oputl, oputL, oputc,
105 <                oputp, oputn, oputN, oputs, oputw, oputm;
104 > static oputf_t  oputo, oputd, oputv, oputl, oputL, oputc, oputp,
105 >                oputn, oputN, oputs, oputw, oputW, oputm, oputM, oputtilde;
106  
107   static void setoutput(char *vs);
108   static void tranotify(OBJECT obj);
# Line 148 | Line 153 | 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 160 | Line 166 | rtrace(                                /* trace rays from file */
166                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
167                  error(SYSTEM, errmsg);
168          }
163 #ifdef _WIN32
169          if (inform != 'a')
170                  SET_FILE_BINARY(fp);
166 #endif
171                                          /* set up output */
172          setoutput(outvals);
173          switch (outform) {
# Line 189 | Line 193 | rtrace(                                /* trace rays from file */
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   static void
227 + trace_sources(void)                     /* trace rays to light sources, also */
228 + {
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   )
# Line 229 | Line 243 | setoutput(                             /* set up output tables */
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 271 | Line 290 | setoutput(                             /* set up output tables */
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   }
# Line 284 | Line 315 | 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  
# Line 299 | Line 331 | rad(           /* compute and print ray value(s) */
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)) {
337                          if (thisray.ro == &Aftplane) {  /* clipped */
# Line 326 | Line 358 | irrad(                 /* compute immediate irradiance value */
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 439 | Line 472 | ourtrace(                              /* print ray values */
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  
# Line 448 | Line 482 | 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 482 | Line 516 | oputv(                         /* print value */
516          RAY  *r
517   )
518   {
485        COLR  cout;
486        
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 602 | Line 635 | oputw(                         /* print weight */
635  
636  
637   static void
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   )
# Line 614 | Line 661 | oputm(                         /* print modifier */
661          else
662                  putchar('*');
663          putchar('\t');
664 + }
665 +
666 +
667 + static void
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines