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.39 by greg, Thu Apr 14 18:04:12 2005 UTC vs.
Revision 2.48 by greg, Tue Jun 21 15:06:50 2005 UTC

# Line 46 | Line 46 | char  *outvals = "v";                  /* output specification */
46  
47   int  do_irrad = 0;                      /* compute irradiance? */
48  
49 + int  rand_samp = 0;                     /* pure Monte Carlo sampling? */
50 +
51   void  (*trace)() = NULL;                /* trace call */
52  
53   char  *tralist[128];                    /* list of modifers to trace (or no) */
54   int  traincl = -1;                      /* include == 1, exclude == 0 */
55 < #define  MAXTSET        511             /* maximum number in trace set */
55 > #ifndef  MAXTSET
56 > #define  MAXTSET        1024            /* maximum number in trace set */
57 > #endif
58   OBJECT  traset[MAXTSET+1]={0};          /* trace include/exclude set */
59  
60   int  hresolu = 0;                       /* horizontal (scan) size */
# Line 74 | Line 78 | double  specjitter = 1.;               /* specular sampling jitter
78  
79   int  backvis = 1;                       /* back face visibility */
80  
81 < int  maxdepth = 8;                      /* maximum recursion depth */
81 > int  maxdepth = -10;                    /* maximum recursion depth */
82   double  minweight = 2e-3;               /* minimum ray weight */
83  
84   char  *ambfile = NULL;                  /* ambient file name */
# Line 96 | Line 100 | typedef void putf_t(double v);
100   static putf_t puta, putd, putf;
101  
102   typedef void oputf_t(RAY *r);
103 < static oputf_t  oputo, oputd, oputv, oputl, oputL, oputc,
104 <                oputp, oputn, oputN, oputs, oputw, oputm, oputM;
103 > static oputf_t  oputo, oputd, oputv, oputl, oputL, oputc, oputp,
104 >                oputn, oputN, oputs, oputw, oputW, oputm, oputM, oputtilde;
105  
106   static void setoutput(char *vs);
107   static void tranotify(OBJECT obj);
# Line 148 | Line 152 | rtrace(                                /* trace rays from file */
152          char  *fname
153   )
154   {
155 <        long  vcount = hresolu>1 ? hresolu*vresolu : vresolu;
155 >        unsigned long  vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu
156 >                                              : vresolu;
157          long  nextflush = hresolu;
158          FILE  *fp;
159          double  d;
# Line 160 | Line 165 | rtrace(                                /* trace rays from file */
165                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
166                  error(SYSTEM, errmsg);
167          }
163 #ifdef _WIN32
168          if (inform != 'a')
169                  SET_FILE_BINARY(fp);
166 #endif
170                                          /* set up output */
171          setoutput(outvals);
172          switch (outform) {
# Line 189 | Line 192 | rtrace(                                /* trace rays from file */
192                  d = normalize(direc);
193                  if (d == 0.0) {                         /* zero ==> flush */
194                          bogusray();
195 <                        if (--nextflush <= 0 || vcount <= 0) {
195 >                        if (--nextflush <= 0 || !vcount) {
196                                  fflush(stdout);
197                                  nextflush = hresolu;
198                          }
199                  } else {
200 <                        samplendx++;
200 >                        samplendx = rand_samp ? random() : samplendx+1;
201                                                          /* compute and print */
202                          if (imm_irrad)
203                                  irrad(orig, direc);
204                          else
205                                  rad(orig, direc, lim_dist ? d : 0.0);
206                                                          /* flush if time */
207 <                        if (--nextflush == 0) {
207 >                        if (!--nextflush) {
208                                  fflush(stdout);
209                                  nextflush = hresolu;
210                          }
211                  }
212                  if (ferror(stdout))
213                          error(SYSTEM, "write error");
214 <                if (--vcount == 0)                      /* check for end */
214 >                if (vcount && !--vcount)                /* check for end */
215                          break;
216          }
217          fflush(stdout);
218 <        if (vcount > 0)
219 <                error(USER, "read error");
218 >        if (vcount)
219 >                error(USER, "unexpected EOF on input");
220          if (fname != NULL)
221                  fclose(fp);
222   }
223  
224  
225   static void
226 + trace_sources(void)                     /* trace rays to light sources, also */
227 + {
228 +        int     sn;
229 +        
230 +        for (sn = 0; sn < nsources; sn++)
231 +                source[sn].sflags |= SFOLLOW;
232 + }
233 +
234 +
235 + static void
236   setoutput(                              /* set up output tables */
237          register char  *vs
238   )
# Line 229 | Line 242 | setoutput(                             /* set up output tables */
242          castonly = 1;
243          while (*vs)
244                  switch (*vs++) {
245 +                case 'T':                               /* trace sources */
246 +                        if (!*vs) break;
247 +                        trace_sources();
248 +                        /* fall through */
249                  case 't':                               /* trace */
250 +                        if (!*vs) break;
251                          *table = NULL;
252                          table = every_out;
253                          trace = ourtrace;
# Line 271 | Line 289 | setoutput(                             /* set up output tables */
289                  case 'w':                               /* weight */
290                          *table++ = oputw;
291                          break;
292 +                case 'W':                               /* coefficient */
293 +                        *table++ = oputW;
294 +                        if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
295 +                                error(WARNING,
296 +                                        "-otW accuracy depends on -aa 0 -as 0");
297 +                        break;
298                  case 'm':                               /* modifier */
299                          *table++ = oputm;
300                          break;
301                  case 'M':                               /* material */
302                          *table++ = oputM;
303                          break;
304 +                case '~':                               /* tilde */
305 +                        *table++ = oputtilde;
306 +                        break;
307                  }
308          *table = NULL;
309   }
# Line 287 | Line 314 | bogusray(void)                 /* print out empty record */
314   {
315          thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
316          thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
317 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
317 >        thisray.rmax = 0.0;
318 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
319          printvals(&thisray);
320   }
321  
# Line 302 | Line 330 | rad(           /* compute and print ray value(s) */
330          VCOPY(thisray.rorg, org);
331          VCOPY(thisray.rdir, dir);
332          thisray.rmax = dmax;
333 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
333 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
334          if (castonly) {
335                  if (!localhit(&thisray, &thescene)) {
336                          if (thisray.ro == &Aftplane) {  /* clipped */
# Line 329 | Line 357 | irrad(                 /* compute immediate irradiance value */
357                  thisray.rorg[i] = org[i] + dir[i];
358                  thisray.rdir[i] = -dir[i];
359          }
360 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
360 >        thisray.rmax = 0.0;
361 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
362                                          /* pretend we hit surface */
363          thisray.rot = 1.0-1e-4;
364          thisray.rod = 1.0;
# Line 442 | Line 471 | ourtrace(                              /* print ray values */
471          tabin(r);
472          for (tp = every_out; *tp != NULL; tp++)
473                  (**tp)(r);
474 <        putchar('\n');
474 >        if (outform == 'a')
475 >                putchar('\n');
476   }
477  
478  
# Line 451 | Line 481 | tabin(                         /* tab in appropriate amount */
481          RAY  *r
482   )
483   {
484 <        register RAY  *rp;
484 >        const RAY  *rp;
485  
486          for (rp = r->parent; rp != NULL; rp = rp->parent)
487                  putchar('\t');
# Line 485 | Line 515 | oputv(                         /* print value */
515          RAY  *r
516   )
517   {
488        COLR  cout;
489        
518          if (outform == 'c') {
519 +                COLR  cout;
520                  setcolr(cout,   colval(r->rcol,RED),
521                                  colval(r->rcol,GRN),
522                                  colval(r->rcol,BLU));
# Line 605 | Line 634 | oputw(                         /* print weight */
634  
635  
636   static void
637 + oputW(                          /* print contribution */
638 +        RAY  *r
639 + )
640 + {
641 +        double  contr[3];
642 +
643 +        raycontrib(contr, r, PRIMARY);
644 +        (*putreal)(contr[RED]);
645 +        (*putreal)(contr[GRN]);
646 +        (*putreal)(contr[BLU]);
647 + }
648 +
649 +
650 + static void
651   oputm(                          /* print modifier */
652          RAY  *r
653   )
# Line 635 | Line 678 | oputM(                         /* print material */
678          } else
679                  putchar('*');
680          putchar('\t');
681 + }
682 +
683 +
684 + static void
685 + oputtilde(                      /* output tilde (spacer) */
686 +        RAY  *r
687 + )
688 + {
689 +        fputs("~\t", stdout);
690   }
691  
692  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines