ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rcontrib.c
(Generate patch)

Comparing ray/src/rt/rcontrib.c (file contents):
Revision 2.2 by greg, Sun Jun 10 05:25:42 2012 UTC vs.
Revision 2.7 by greg, Fri Jun 15 21:32:11 2012 UTC

# Line 25 | Line 25 | void   (*trace)() = trace_contrib;
25  
26   int     do_irrad = 0;                   /* compute irradiance? */
27  
28 < int     rand_samp = 0;                  /* pure Monte Carlo sampling? */
28 > int     rand_samp = 1;                  /* pure Monte Carlo sampling? */
29  
30   double  dstrsrc = 0.0;                  /* square source distribution */
31   double  shadthresh = .03;               /* shadow threshold */
# Line 45 | Line 45 | double specjitter = 1.;                /* specular sampling jitter *
45  
46   int     backvis = 1;                    /* back face visibility */
47  
48 < int     maxdepth = 8;                   /* maximum recursion depth */
49 < double  minweight = 5e-4;               /* minimum ray weight */
48 > int     maxdepth = -10;                 /* maximum recursion depth */
49 > double  minweight = 2e-3;               /* minimum ray weight */
50  
51   char    *ambfile = NULL;                /* ambient file name */
52   COLOR   ambval = BLKCOLOR;              /* ambient value */
# Line 63 | Line 63 | int    account;                        /* current accumulation count */
63   RNUMBER raysleft;                       /* number of rays left to trace */
64   long    waitflush;                      /* how long until next flush */
65  
66 < int     lastray = 0;                    /* last ray number sent */
67 < int     lastdone = 0;                   /* last ray output */
66 > RNUMBER lastray = 0;                    /* last ray number sent */
67 > RNUMBER lastdone = 0;                   /* last ray output */
68  
69 /* Close output stream and free record */
70 static void
71 closestream(void *p)
72 {
73        STREAMOUT       *sop = (STREAMOUT *)p;
74        int             status = 0;
75        if (sop->outpipe)
76                status = pclose(sop->ofp);
77        else if (sop->ofp != stdout)
78                status = fclose(sop->ofp);
79        if (status)
80                error(SYSTEM, "error closing output stream");
81        free(p);
82 }
83
84 LUTAB   ofiletab = LU_SINIT(free,closestream);  /* output file table */
85
86 #define OF_MODIFIER     01
87 #define OF_BIN          02
88
69   static void mcfree(void *p) { epfree((*(MODCONT *)p).binv); free(p); }
70  
71   LUTAB   modconttab = LU_SINIT(NULL,mcfree);     /* modifier lookup table */
72  
93 static OBJECT           traset[MAXTSET+1]={0};  /* trace include set */
94
73   /************************** INITIALIZATION ROUTINES ***********************/
74  
97 void
98 tranotify(                      /* record new modifier */
99        OBJECT  obj
100 )
101 {
102        static int      hitlimit = 0;
103        OBJREC          *o = objptr(obj);
104        int             i;
105
106        if (obj == OVOID) {             /* starting over */
107                traset[0] = 0;
108                hitlimit = 0;
109                return;
110        }
111        if (hitlimit || !ismodifier(o->otype))
112                return;
113        for (i = nmods; i-- > 0; )
114                if (!strcmp(o->oname, modname[i])) {
115                        if (traset[0] >= MAXTSET) {
116                                error(WARNING, "too many same-named modifiers");
117                                hitlimit++;
118                                return;         /* should this be fatal? */
119                        }
120                        insertelem(traset, obj);
121                        break;
122                }
123 }
124
125
75   char *
76   formstr(                                /* return format identifier */
77          int  f
# Line 232 | Line 181 | rcinit()
181          if ((nproc > 1) & (accumulate <= 0))
182                  put_zero_record(0);     /* prime our queue to accumulate */
183  
235        if (recover) {                  /* recover previous output? */
236                if (accumulate <= 0) {
237                        reload_output();
238                        if (nproc > 1)
239                                queue_modifiers();
240                } else
241                        recover_output();
242        }
184          if (yres > 0) {                 /* set up flushing & ray counts */
185                  if (xres > 0)
186                          raysleft = (RNUMBER)xres*yres;
# Line 254 | Line 195 | rcinit()
195          for (i = 0; i < nsources; i++)
196                  source[i].sflags |= SFOLLOW;
197  
198 <        if (nproc == 1 || in_rchild())  /* single process or child */
198 >        if (nproc > 1 && in_rchild())   /* forked child? */
199                  return;                 /* return to main processing loop */
200  
201 +        if (recover) {                  /* recover previous output? */
202 +                if (accumulate <= 0) {
203 +                        reload_output();
204 +                        if (nproc > 1)
205 +                                queue_modifiers();
206 +                } else
207 +                        recover_output();
208 +        }
209 +        if (nproc == 1)                 /* single process? */
210 +                return;
211 +
212          parental_loop();                /* else run controller */
213          quit(0);                        /* parent musn't return! */
214   }
# Line 271 | Line 223 | trace_contrib(RAY *r)
223          int     bn;
224          RREAL   contr[3];
225  
226 <        if (r->ro == NULL || !inset(traset, r->ro->omod))
226 >        if (r->ro == NULL || r->ro->omod == OVOID)
227                  return;
228  
229          mp = (MODCONT *)lu_find(&modconttab,objptr(r->ro->omod)->oname)->data;
230  
231 <        if (mp == NULL)
232 <                error(CONSISTENCY, "unexpected modifier in trace_contrib()");
231 >        if (mp == NULL)                         /* not in our list? */
232 >                return;
233  
234          worldfunc(RCCONTEXT, r);                /* get bin number */
235          bn = (int)(evalue(mp->binv) + .5);
# Line 292 | Line 244 | trace_contrib(RAY *r)
244   }
245  
246  
247 + /* Evaluate irradiance contributions */
248   static void
249 < rayirrad(                       /* compute irradiance rather than radiance */
297 <        RAY *r
298 < )
249 > eval_irrad(FVECT org, FVECT dir)
250   {
251 <        r->rot = 1e-5;                  /* pretend we hit surface */
252 <        VSUM(r->rop, r->rorg, r->rdir, r->rot);
253 <        r->ron[0] = -r->rdir[0];
254 <        r->ron[1] = -r->rdir[1];
255 <        r->ron[2] = -r->rdir[2];
256 <        r->rod = 1.0;
257 <                                        /* compute result */
258 <        r->revf = raytrace;
259 <        (*ofun[Lamb.otype].funp)(&Lamb, r);
260 <        r->revf = rayirrad;
251 >        RAY     thisray;
252 >
253 >        VSUM(thisray.rorg, org, dir, 1.1e-4);
254 >        thisray.rdir[0] = -dir[0];
255 >        thisray.rdir[1] = -dir[1];
256 >        thisray.rdir[2] = -dir[2];
257 >        thisray.rmax = 0.0;
258 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
259 >        thisray.rot = 1e-5;             /* pretend we hit surface */
260 >        thisray.rod = 1.0;
261 >        VSUM(thisray.rop, org, dir, 1e-4);
262 >        samplendx++;                    /* compute result */
263 >        (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
264   }
265  
266  
267 < /* Evaluate ray contributions */
267 > /* Evaluate radiance contributions */
268   static void
269 < eval_ray(FVECT  org, FVECT  dir, double dmax)
269 > eval_rad(FVECT org, FVECT dir, double dmax)
270   {
271          RAY     thisray;
272                                          /* set up ray */
273 +        VCOPY(thisray.rorg, org);
274 +        VCOPY(thisray.rdir, dir);
275 +        thisray.rmax = dmax;
276          rayorigin(&thisray, PRIMARY, NULL, NULL);
320        if (imm_irrad) {
321                VSUM(thisray.rorg, org, dir, 1.1e-4);
322                thisray.rdir[0] = -dir[0];
323                thisray.rdir[1] = -dir[1];
324                thisray.rdir[2] = -dir[2];
325                thisray.rmax = 0.0;
326                thisray.revf = rayirrad;
327        } else {
328                VCOPY(thisray.rorg, org);
329                VCOPY(thisray.rdir, dir);
330                thisray.rmax = dmax;
331        }
277          samplendx++;                    /* call ray evaluation */
278          rayvalue(&thisray);
279   }
# Line 370 | Line 315 | rcontrib()
315   #endif
316          while (getvec(orig) == 0 && getvec(direc) == 0) {
317                  d = normalize(direc);
318 <                if ((d == 0.0) & (accumulate != 1)) {
318 >                if (nchild != -1 && (d == 0.0) & (accumulate != 1)) {
319                          if (!ignore_warning_given++)
320                                  error(WARNING,
321                                  "dummy ray(s) ignored during accumulation\n");
# Line 382 | Line 327 | rcontrib()
327                  if (d == 0.0) {                         /* zero ==> flush */
328                          if ((yres <= 0) | (xres <= 0))
329                                  waitflush = 1;          /* flush right after */
330 <                } else {                                /* else compute */
331 <                        eval_ray(orig, direc, lim_dist ? d : 0.0);
330 >                        account = 1;
331 >                } else if (imm_irrad) {                 /* else compute */
332 >                        eval_irrad(orig, direc);
333 >                } else {
334 >                        eval_rad(orig, direc, lim_dist ? d : 0.0);
335                  }
336                  done_contrib();         /* accumulate/output */
337                  ++lastdone;
338                  if (raysleft && !--raysleft)
339                          break;          /* preemptive EOI */
340          }
341 <        if (accumulate <= 0 || account < accumulate) {
341 >        if (nchild != -1 && (accumulate <= 0) | (account < accumulate)) {
342                  if (account < accumulate) {
343                          error(WARNING, "partial accumulation in final record");
344                          accumulate -= account;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines