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.50 by greg, Fri Oct 7 03:45:14 2005 UTC vs.
Revision 2.58 by greg, Sat Dec 12 23:08:13 2009 UTC

# Line 31 | Line 31 | static const char      RCSid[] = "$Id$";
31   #include  "resolu.h"
32   #include  "random.h"
33  
34 < CUBE  thescene;                         /* our scene */
35 < OBJECT  nsceneobjs;                     /* number of objects in our scene */
34 > extern int  inform;                     /* input format */
35 > extern int  outform;                    /* output format */
36 > extern char  *outvals;                  /* output values */
37  
38 < int  dimlist[MAXDIM];                   /* sampling dimensions */
39 < int  ndims = 0;                         /* number of sampling dimensions */
39 < int  samplendx = 0;                     /* index for this sample */
38 > extern int  imm_irrad;                  /* compute immediate irradiance? */
39 > extern int  lim_dist;                   /* limit distance? */
40  
41 < int  imm_irrad = 0;                     /* compute immediate irradiance? */
42 < int  lim_dist = 0;                      /* limit distance? */
41 > extern char  *tralist[];                /* list of modifers to trace (or no) */
42 > extern int  traincl;                    /* include == 1, exclude == 0 */
43  
44 < int  inform = 'a';                      /* input format */
45 < int  outform = 'a';                     /* output format */
46 < char  *outvals = "v";                   /* output specification */
44 > extern int  hresolu;                    /* horizontal resolution */
45 > extern int  vresolu;                    /* vertical resolution */
46  
47 < int  do_irrad = 0;                      /* compute irradiance? */
47 > static int  castonly = 0;
48  
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 */
49   #ifndef  MAXTSET
50 < #define  MAXTSET        1024            /* maximum number in trace set */
50 > #define  MAXTSET        8191            /* maximum number in trace set */
51   #endif
52   OBJECT  traset[MAXTSET+1]={0};          /* trace include/exclude set */
53  
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 = .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? */
70 double  srcsizerat = .2;                /* maximum ratio source size/dist. */
71
72 COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
73 COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
74 double  seccg = 0.;                     /* global scattering eccentricity */
75 double  ssampdist = 0.;                 /* scatter sampling distance */
76
77 double  specthresh = .15;               /* specular sampling threshold */
78 double  specjitter = 1.;                /* specular sampling jitter */
79
80 int  backvis = 1;                       /* back face visibility */
81
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.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[AMBLLEN];                /* ambient include/exclude list */
94 int  ambincl = -1;                      /* include == 1, exclude == 0 */
95
96 static int  castonly = 0;
97
54   static RAY  thisray;                    /* for our convenience */
55  
56   typedef void putf_t(double v);
57   static putf_t puta, putd, putf;
58  
59   typedef void oputf_t(RAY *r);
60 < static oputf_t  oputo, oputd, oputv, oputl, oputL, oputc, oputp,
60 > static oputf_t  oputo, oputd, oputv, oputV, oputl, oputL, oputc, oputp,
61                  oputn, oputN, oputs, oputw, oputW, oputm, oputM, oputtilde;
62  
63   static void setoutput(char *vs);
64 < static void tranotify(OBJECT obj);
64 > extern void tranotify(OBJECT obj);
65   static void bogusray(void);
66 < static void rad(FVECT  org, FVECT  dir, double  dmax);
67 < static void irrad(FVECT  org, FVECT  dir);
68 < static void printvals(RAY  *r);
69 < static int getvec(FVECT  vec, int  fmt, FILE  *fp);
70 < static void tabin(RAY  *r);
71 < static void ourtrace(RAY  *r);
66 > static void rad(FVECT org, FVECT dir, double dmax);
67 > static void irrad(FVECT org, FVECT dir);
68 > static int printvals(RAY *r);
69 > static int getvec(FVECT vec, int fmt, FILE *fp);
70 > static void tabin(RAY *r);
71 > static void ourtrace(RAY *r);
72  
73   static oputf_t *ray_out[16], *every_out[16];
74   static putf_t *putreal;
75  
120 void  (*addobjnotify[])() = {ambnotify, tranotify, NULL};
76  
122
77   void
78   quit(                   /* quit program */
79          int  code
80   )
81   {
82 < #ifndef  NON_POSIX /* XXX we don't clean up elsewhere? */
83 <        headclean();            /* delete header file */
84 <        pfclean();              /* clean up persist files */
82 >        if (ray_pnprocs > 0)    /* close children if any */
83 >                ray_pclose(0);          
84 > #ifndef  NON_POSIX
85 >        else if (!ray_pnprocs) {
86 >                headclean();    /* delete header file */
87 >                pfclean();      /* clean up persist files */
88 >        }
89   #endif
90          exit(code);
91   }
92  
93  
94 < extern char *
94 > char *
95   formstr(                                /* return format identifier */
96          int  f
97   )
# Line 181 | Line 139 | rtrace(                                /* trace rays from file */
139          default:
140                  error(CONSISTENCY, "botched output format");
141          }
142 +        if (ray_pnprocs > 1)
143 +                ray_fifo_out = printvals;
144          if (hresolu > 0) {
145                  if (vresolu > 0)
146                          fprtresolu(hresolu, vresolu, stdout);
# Line 192 | Line 152 | rtrace(                                /* trace rays from file */
152  
153                  d = normalize(direc);
154                  if (d == 0.0) {                         /* zero ==> flush */
155 +                        if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
156 +                                error(USER, "lost children");
157                          bogusray();
158                          if (--nextflush <= 0 || !vcount) {
159                                  fflush(stdout);
160                                  nextflush = hresolu;
161                          }
162 <                } else {
201 <                        samplendx = rand_samp ? random() : samplendx+1;
202 <                                                        /* compute and print */
162 >                } else {                                /* compute and print */
163                          if (imm_irrad)
164                                  irrad(orig, direc);
165                          else
166                                  rad(orig, direc, lim_dist ? d : 0.0);
167                                                          /* flush if time */
168                          if (!--nextflush) {
169 +                                if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
170 +                                        error(USER, "lost children");
171                                  fflush(stdout);
172                                  nextflush = hresolu;
173                          }
# Line 215 | Line 177 | rtrace(                                /* trace rays from file */
177                  if (vcount && !--vcount)                /* check for end */
178                          break;
179          }
180 +        if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
181 +                error(USER, "unable to complete processing");
182          if (fflush(stdout) < 0)
183                  error(SYSTEM, "write error");
184          if (vcount)
# Line 236 | Line 200 | trace_sources(void)                    /* trace rays to light sources,
200  
201   static void
202   setoutput(                              /* set up output tables */
203 <        register char  *vs
203 >        char  *vs
204   )
205   {
206 <        register oputf_t **table = ray_out;
206 >        oputf_t **table = ray_out;
207  
208          castonly = 1;
209          while (*vs)
# Line 265 | Line 229 | setoutput(                             /* set up output tables */
229                          *table++ = oputv;
230                          castonly = 0;
231                          break;
232 +                case 'V':                               /* contribution */
233 +                        *table++ = oputV;
234 +                        if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
235 +                                error(WARNING,
236 +                                        "-otV accuracy depends on -aa 0 -as 0");
237 +                        break;
238                  case 'l':                               /* effective distance */
239                          *table++ = oputl;
240                          castonly = 0;
# Line 332 | Line 302 | rad(           /* compute and print ray value(s) */
302          VCOPY(thisray.rorg, org);
303          VCOPY(thisray.rdir, dir);
304          thisray.rmax = dmax;
305 +        if (!castonly && ray_pnprocs > 1) {
306 +                if (ray_fifo_in(&thisray) < 0)
307 +                        error(USER, "lost children");
308 +                return;
309 +        }
310          rayorigin(&thisray, PRIMARY, NULL, NULL);
311          if (castonly) {
312                  if (!localhit(&thisray, &thescene)) {
# Line 342 | Line 317 | rad(           /* compute and print ray value(s) */
317                                  sourcehit(&thisray);
318                  }
319          } else
320 <                rayvalue(&thisray);
320 >                ray_trace(&thisray);
321          printvals(&thisray);
322   }
323  
# Line 353 | Line 328 | irrad(                 /* compute immediate irradiance value */
328          FVECT  dir
329   )
330   {
331 <        register int  i;
332 <
333 <        for (i = 0; i < 3; i++) {
334 <                thisray.rorg[i] = org[i] + dir[i];
360 <                thisray.rdir[i] = -dir[i];
361 <        }
331 >        VSUM(thisray.rorg, org, dir, 1.1e-4);
332 >        thisray.rdir[0] = -dir[0];
333 >        thisray.rdir[1] = -dir[1];
334 >        thisray.rdir[2] = -dir[2];
335          thisray.rmax = 0.0;
336          rayorigin(&thisray, PRIMARY, NULL, NULL);
337                                          /* pretend we hit surface */
338 <        thisray.rot = 1.0-1e-4;
338 >        thisray.rot = 1e-5;
339          thisray.rod = 1.0;
340          VCOPY(thisray.ron, dir);
341 <        for (i = 0; i < 3; i++)         /* fudge factor */
369 <                thisray.rop[i] = org[i] + 1e-4*dir[i];
341 >        VSUM(thisray.rop, org, dir, 1e-4);
342                                          /* compute and print */
343          (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
344          printvals(&thisray);
345   }
346  
347  
348 < static void
348 > static int
349   printvals(                      /* print requested ray values */
350          RAY  *r
351   )
352   {
353 <        register oputf_t **tp;
353 >        oputf_t **tp;
354  
355          if (ray_out[0] == NULL)
356 <                return;
356 >                return(0);
357          for (tp = ray_out; *tp != NULL; tp++)
358                  (**tp)(r);
359          if (outform == 'a')
360                  putchar('\n');
361 +        return(1);
362   }
363  
364  
365   static int
366   getvec(         /* get a vector from fp */
367 <        register FVECT  vec,
367 >        FVECT  vec,
368          int  fmt,
369          FILE  *fp
370   )
# Line 399 | Line 372 | getvec(                /* get a vector from fp */
372          static float  vf[3];
373          static double  vd[3];
374          char  buf[32];
375 <        register int  i;
375 >        int  i;
376  
377          switch (fmt) {
378          case 'a':                                       /* ascii */
# Line 413 | Line 386 | getvec(                /* get a vector from fp */
386          case 'f':                                       /* binary float */
387                  if (fread((char *)vf, sizeof(float), 3, fp) != 3)
388                          return(-1);
389 <                vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2];
389 >                VCOPY(vec, vf);
390                  break;
391          case 'd':                                       /* binary double */
392                  if (fread((char *)vd, sizeof(double), 3, fp) != 3)
393                          return(-1);
394 <                vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2];
394 >                VCOPY(vec, vd);
395                  break;
396          default:
397                  error(CONSISTENCY, "botched input format");
# Line 427 | Line 400 | getvec(                /* get a vector from fp */
400   }
401  
402  
403 < static void
403 > void
404   tranotify(                      /* record new modifier */
405          OBJECT  obj
406   )
407   {
408          static int  hitlimit = 0;
409 <        register OBJREC  *o = objptr(obj);
410 <        register char  **tralp;
409 >        OBJREC   *o = objptr(obj);
410 >        char  **tralp;
411  
412          if (obj == OVOID) {             /* starting over */
413                  traset[0] = 0;
# Line 461 | Line 434 | ourtrace(                              /* print ray values */
434          RAY  *r
435   )
436   {
437 <        register oputf_t **tp;
437 >        oputf_t **tp;
438  
439          if (every_out[0] == NULL)
440                  return;
# Line 532 | Line 505 | oputv(                         /* print value */
505  
506  
507   static void
508 + oputV(                          /* print value contribution */
509 +        RAY *r
510 + )
511 + {
512 +        double  contr[3];
513 +
514 +        raycontrib(contr, r, PRIMARY);
515 +        multcolor(contr, r->rcol);
516 +        (*putreal)(contr[RED]);
517 +        (*putreal)(contr[GRN]);
518 +        (*putreal)(contr[BLU]);
519 + }
520 +
521 +
522 + static void
523   oputl(                          /* print effective distance */
524          RAY  *r
525   )
# Line 636 | Line 624 | oputw(                         /* print weight */
624  
625  
626   static void
627 < oputW(                          /* print contribution */
627 > oputW(                          /* print coefficient */
628          RAY  *r
629   )
630   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines