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.47 by greg, Mon Jun 13 20:07:56 2005 UTC vs.
Revision 2.57 by greg, Sat Dec 12 19:01:00 2009 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 */
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 */
38 < 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 */
45 < 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  
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 */
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  
60 int  hresolu = 0;                       /* horizontal (scan) size */
61 int  vresolu = 0;                       /* vertical resolution */
62
63 double  dstrsrc = 0.0;                  /* square source distribution */
64 double  shadthresh = .03;               /* shadow threshold */
65 double  shadcert = .75;                 /* shadow certainty */
66 int  directrelay = 2;                   /* number of source relays */
67 int  vspretest = 512;                   /* virtual source pretest density */
68 int  directvis = 1;                     /* sources visible? */
69 double  srcsizerat = .2;                /* maximum ratio source size/dist. */
70
71 COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
72 COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
73 double  seccg = 0.;                     /* global scattering eccentricity */
74 double  ssampdist = 0.;                 /* scatter sampling distance */
75
76 double  specthresh = .15;               /* specular sampling threshold */
77 double  specjitter = 1.;                /* specular sampling jitter */
78
79 int  backvis = 1;                       /* back face visibility */
80
81 int  maxdepth = -10;                    /* maximum recursion depth */
82 double  minweight = 2e-3;               /* minimum ray weight */
83
84 char  *ambfile = NULL;                  /* ambient file name */
85 COLOR  ambval = BLKCOLOR;               /* ambient value */
86 int  ambvwt = 0;                        /* initial weight for ambient value */
87 double  ambacc = 0.15;                  /* ambient accuracy */
88 int  ambres = 256;                      /* ambient resolution */
89 int  ambdiv = 1024;                     /* ambient divisions */
90 int  ambssamp = 512;                    /* ambient super-samples */
91 int  ambounce = 0;                      /* ambient bounces */
92 char  *amblist[AMBLLEN];                /* ambient include/exclude list */
93 int  ambincl = -1;                      /* include == 1, exclude == 0 */
94
95 static int  castonly = 0;
96
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  
119 void  (*addobjnotify[])() = {ambnotify, tranotify, NULL};
76  
121
77   void
78   quit(                   /* quit program */
79          int  code
80   )
81   {
82 < #ifndef  NON_POSIX /* XXX we don't clean up elsewhere? */
82 >        if (ray_pnprocs > 0)    /* close children if any */
83 >                ray_pclose(0);          
84 > #ifndef  NON_POSIX
85          headclean();            /* delete header file */
86          pfclean();              /* clean up persist files */
87   #endif
# Line 132 | Line 89 | quit(                  /* quit program */
89   }
90  
91  
92 < extern char *
92 > char *
93   formstr(                                /* return format identifier */
94          int  f
95   )
# Line 180 | Line 137 | rtrace(                                /* trace rays from file */
137          default:
138                  error(CONSISTENCY, "botched output format");
139          }
140 +        ray_fifo_out = printvals;
141          if (hresolu > 0) {
142                  if (vresolu > 0)
143                          fprtresolu(hresolu, vresolu, stdout);
# Line 191 | Line 149 | rtrace(                                /* trace rays from file */
149  
150                  d = normalize(direc);
151                  if (d == 0.0) {                         /* zero ==> flush */
152 +                        if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
153 +                                error(USER, "lost children");
154                          bogusray();
155                          if (--nextflush <= 0 || !vcount) {
156                                  fflush(stdout);
157                                  nextflush = hresolu;
158                          }
159 <                } else {
200 <                        samplendx = rand_samp ? random() : samplendx+1;
201 <                                                        /* compute and print */
159 >                } else {                                /* compute and print */
160                          if (imm_irrad)
161                                  irrad(orig, direc);
162                          else
163                                  rad(orig, direc, lim_dist ? d : 0.0);
164                                                          /* flush if time */
165                          if (!--nextflush) {
166 +                                if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
167 +                                        error(USER, "lost children");
168                                  fflush(stdout);
169                                  nextflush = hresolu;
170                          }
# Line 214 | Line 174 | rtrace(                                /* trace rays from file */
174                  if (vcount && !--vcount)                /* check for end */
175                          break;
176          }
177 <        fflush(stdout);
177 >        if (ray_pnprocs > 1 && ray_fifo_flush() < 0)
178 >                error(USER, "unable to complete processing");
179 >        if (fflush(stdout) < 0)
180 >                error(SYSTEM, "write error");
181          if (vcount)
182                  error(USER, "unexpected EOF on input");
183          if (fname != NULL)
# Line 234 | Line 197 | trace_sources(void)                    /* trace rays to light sources,
197  
198   static void
199   setoutput(                              /* set up output tables */
200 <        register char  *vs
200 >        char  *vs
201   )
202   {
203 <        register oputf_t **table = ray_out;
203 >        oputf_t **table = ray_out;
204  
205          castonly = 1;
206          while (*vs)
# Line 263 | Line 226 | setoutput(                             /* set up output tables */
226                          *table++ = oputv;
227                          castonly = 0;
228                          break;
229 +                case 'V':                               /* contribution */
230 +                        *table++ = oputV;
231 +                        if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
232 +                                error(WARNING,
233 +                                        "-otV accuracy depends on -aa 0 -as 0");
234 +                        break;
235                  case 'l':                               /* effective distance */
236                          *table++ = oputl;
237                          castonly = 0;
# Line 330 | Line 299 | rad(           /* compute and print ray value(s) */
299          VCOPY(thisray.rorg, org);
300          VCOPY(thisray.rdir, dir);
301          thisray.rmax = dmax;
302 +        if (ray_pnprocs > 1) {
303 +                if (ray_fifo_in(&thisray) < 0)
304 +                        error(USER, "lost children");
305 +                return;
306 +        }
307          rayorigin(&thisray, PRIMARY, NULL, NULL);
308          if (castonly) {
309                  if (!localhit(&thisray, &thescene)) {
# Line 340 | Line 314 | rad(           /* compute and print ray value(s) */
314                                  sourcehit(&thisray);
315                  }
316          } else
317 <                rayvalue(&thisray);
317 >                ray_trace(&thisray);
318          printvals(&thisray);
319   }
320  
# Line 351 | Line 325 | irrad(                 /* compute immediate irradiance value */
325          FVECT  dir
326   )
327   {
328 <        register int  i;
329 <
330 <        for (i = 0; i < 3; i++) {
331 <                thisray.rorg[i] = org[i] + dir[i];
358 <                thisray.rdir[i] = -dir[i];
359 <        }
328 >        VSUM(thisray.rorg, org, dir, 1.1e-4);
329 >        thisray.rdir[0] = -dir[0];
330 >        thisray.rdir[1] = -dir[1];
331 >        thisray.rdir[2] = -dir[2];
332          thisray.rmax = 0.0;
333          rayorigin(&thisray, PRIMARY, NULL, NULL);
334                                          /* pretend we hit surface */
335 <        thisray.rot = 1.0-1e-4;
335 >        thisray.rot = 1e-5;
336          thisray.rod = 1.0;
337          VCOPY(thisray.ron, dir);
338 <        for (i = 0; i < 3; i++)         /* fudge factor */
367 <                thisray.rop[i] = org[i] + 1e-4*dir[i];
338 >        VSUM(thisray.rop, org, dir, 1e-4);
339                                          /* compute and print */
340          (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
341          printvals(&thisray);
342   }
343  
344  
345 < static void
345 > static int
346   printvals(                      /* print requested ray values */
347          RAY  *r
348   )
349   {
350 <        register oputf_t **tp;
350 >        oputf_t **tp;
351  
352          if (ray_out[0] == NULL)
353 <                return;
353 >                return(0);
354          for (tp = ray_out; *tp != NULL; tp++)
355                  (**tp)(r);
356          if (outform == 'a')
357                  putchar('\n');
358 +        return(1);
359   }
360  
361  
362   static int
363   getvec(         /* get a vector from fp */
364 <        register FVECT  vec,
364 >        FVECT  vec,
365          int  fmt,
366          FILE  *fp
367   )
# Line 397 | Line 369 | getvec(                /* get a vector from fp */
369          static float  vf[3];
370          static double  vd[3];
371          char  buf[32];
372 <        register int  i;
372 >        int  i;
373  
374          switch (fmt) {
375          case 'a':                                       /* ascii */
# Line 425 | Line 397 | getvec(                /* get a vector from fp */
397   }
398  
399  
400 < static void
400 > void
401   tranotify(                      /* record new modifier */
402          OBJECT  obj
403   )
404   {
405          static int  hitlimit = 0;
406 <        register OBJREC  *o = objptr(obj);
407 <        register char  **tralp;
406 >        OBJREC   *o = objptr(obj);
407 >        char  **tralp;
408  
409          if (obj == OVOID) {             /* starting over */
410                  traset[0] = 0;
# Line 459 | Line 431 | ourtrace(                              /* print ray values */
431          RAY  *r
432   )
433   {
434 <        register oputf_t **tp;
434 >        oputf_t **tp;
435  
436          if (every_out[0] == NULL)
437                  return;
# Line 530 | Line 502 | oputv(                         /* print value */
502  
503  
504   static void
505 + oputV(                          /* print value contribution */
506 +        RAY *r
507 + )
508 + {
509 +        double  contr[3];
510 +
511 +        raycontrib(contr, r, PRIMARY);
512 +        multcolor(contr, r->rcol);
513 +        (*putreal)(contr[RED]);
514 +        (*putreal)(contr[GRN]);
515 +        (*putreal)(contr[BLU]);
516 + }
517 +
518 +
519 + static void
520   oputl(                          /* print effective distance */
521          RAY  *r
522   )
# Line 634 | Line 621 | oputw(                         /* print weight */
621  
622  
623   static void
624 < oputW(                          /* print contribution */
624 > oputW(                          /* print coefficient */
625          RAY  *r
626   )
627   {
628 <        COLOR   contr;
628 >        double  contr[3];
629  
630          raycontrib(contr, r, PRIMARY);
631 <        (*putreal)(colval(contr,RED));
632 <        (*putreal)(colval(contr,GRN));
633 <        (*putreal)(colval(contr,BLU));
631 >        (*putreal)(contr[RED]);
632 >        (*putreal)(contr[GRN]);
633 >        (*putreal)(contr[BLU]);
634   }
635  
636  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines