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.3 by greg, Mon Jun 11 05:07:55 2012 UTC vs.
Revision 2.19 by greg, Sat Jul 19 00:07:03 2014 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7   */
8  
9   #include "rcontrib.h"
10 #include "source.h"
10   #include "otypes.h"
11 < #include "platform.h"
11 > #include "source.h"
12  
13   char    *shm_boundary = NULL;           /* boundary of shared memory */
14  
# Line 27 | Line 26 | int    do_irrad = 0;                   /* compute irradiance? */
26  
27   int     rand_samp = 1;                  /* pure Monte Carlo sampling? */
28  
29 < double  dstrsrc = 0.0;                  /* square source distribution */
29 > double  dstrsrc = 0.9;                  /* square source distribution */
30   double  shadthresh = .03;               /* shadow threshold */
31   double  shadcert = .75;                 /* shadow certainty */
32   int     directrelay = 3;                /* number of source relays */
# Line 63 | Line 62 | int    account;                        /* current accumulation count */
62   RNUMBER raysleft;                       /* number of rays left to trace */
63   long    waitflush;                      /* how long until next flush */
64  
65 < int     lastray = 0;                    /* last ray number sent */
66 < int     lastdone = 0;                   /* last ray output */
65 > RNUMBER lastray = 0;                    /* last ray number sent */
66 > RNUMBER lastdone = 0;                   /* last ray output */
67  
68   static void mcfree(void *p) { epfree((*(MODCONT *)p).binv); free(p); }
69  
70   LUTAB   modconttab = LU_SINIT(NULL,mcfree);     /* modifier lookup table */
71  
73 static OBJECT           traset[MAXTSET+1]={0};  /* trace include set */
74
72   /************************** INITIALIZATION ROUTINES ***********************/
73  
77 void
78 tranotify(                      /* record new modifier */
79        OBJECT  obj
80 )
81 {
82        static int      hitlimit = 0;
83        OBJREC          *o = objptr(obj);
84        int             i;
85
86        if (obj == OVOID) {             /* starting over */
87                traset[0] = 0;
88                hitlimit = 0;
89                return;
90        }
91        if (hitlimit || !ismodifier(o->otype))
92                return;
93        for (i = nmods; i-- > 0; )
94                if (!strcmp(o->oname, modname[i])) {
95                        if (traset[0] >= MAXTSET) {
96                                error(WARNING, "too many same-named modifiers");
97                                hitlimit++;
98                                return;         /* should this be fatal? */
99                        }
100                        insertelem(traset, obj);
101                        break;
102                }
103 }
104
105
74   char *
75   formstr(                                /* return format identifier */
76          int  f
# Line 168 | Line 136 | addmodifier(char *modn, char *outf, char *binv, int bi
136   }
137  
138  
139 < /* add modifiers from a file list */
139 > /* Add modifiers from a file list */
140   void
141   addmodfile(char *fname, char *outf, char *binv, int bincnt)
142   {
# Line 190 | Line 158 | quit(                  /* quit program */
158   )
159   {
160          if (nchild > 0)         /* close children if any */
161 <                end_children();
161 >                end_children(code != 0);
162          exit(code);
163   }
164  
# Line 209 | Line 177 | rcinit()
177                                          /* set shared memory boundary */
178                  shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY");
179          }
180 <        if ((nproc > 1) & (accumulate <= 0))
181 <                put_zero_record(0);     /* prime our queue to accumulate */
214 <
215 <        if (recover) {                  /* recover previous output? */
216 <                if (accumulate <= 0) {
217 <                        reload_output();
218 <                        if (nproc > 1)
219 <                                queue_modifiers();
220 <                } else
221 <                        recover_output();
222 <        }
180 >        for (i = 0; i < nsources; i++)  /* tracing to sources as well */
181 >                source[i].sflags |= SFOLLOW;
182          if (yres > 0) {                 /* set up flushing & ray counts */
183                  if (xres > 0)
184                          raysleft = (RNUMBER)xres*yres;
# Line 230 | Line 189 | rcinit()
189          if ((account = accumulate) > 1)
190                  raysleft *= accumulate;
191          waitflush = (yres > 0) & (xres > 1) ? 0 : xres;
233                                        /* tracing to sources as well */
234        for (i = 0; i < nsources; i++)
235                source[i].sflags |= SFOLLOW;
192  
193 <        if (nproc == 1 || in_rchild())  /* single process or child */
193 >        if (nproc > 1 && in_rchild())   /* forked child? */
194                  return;                 /* return to main processing loop */
195  
196 <        parental_loop();                /* else run controller */
196 >        if (recover) {                  /* recover previous output? */
197 >                if (accumulate <= 0)
198 >                        reload_output();
199 >                else
200 >                        recover_output();
201 >        }
202 >        if (nproc == 1)                 /* single process? */
203 >                return;
204 >                                        /* else run appropriate controller */
205 >        if (accumulate <= 0)
206 >                feeder_loop();
207 >        else
208 >                parental_loop();
209          quit(0);                        /* parent musn't return! */
210   }
211  
# Line 248 | Line 216 | static void
216   trace_contrib(RAY *r)
217   {
218          MODCONT *mp;
219 +        double  bval;
220          int     bn;
221          RREAL   contr[3];
222  
223 <        if (r->ro == NULL || !inset(traset, r->ro->omod))
223 >        if (r->ro == NULL || r->ro->omod == OVOID)
224                  return;
225  
226          mp = (MODCONT *)lu_find(&modconttab,objptr(r->ro->omod)->oname)->data;
227  
228 <        if (mp == NULL)
229 <                error(CONSISTENCY, "unexpected modifier in trace_contrib()");
228 >        if (mp == NULL)                         /* not in our list? */
229 >                return;
230 >                                                /* shadow ray not on source? */
231 >        if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
232 >                return;
233  
234 <        worldfunc(RCCONTEXT, r);                /* get bin number */
235 <        bn = (int)(evalue(mp->binv) + .5);
236 <        if ((bn < 0) | (bn >= mp->nbins)) {
234 >        worldfunc(RCCONTEXT, r);                /* else get bin number */
235 >        if ((bval = evalue(mp->binv)) <= -.5)
236 >                return;                         /* silently ignore */
237 >        if ((bn = (int)(bval + .5)) >= mp->nbins) {
238                  error(WARNING, "bad bin number (ignored)");
239                  return;
240          }
241 <        raycontrib(contr, r, PRIMARY);
241 >        raycontrib(contr, r, PRIMARY);          /* compute coefficient */
242          if (contrib)
243 <                multcolor(contr, r->rcol);
243 >                multcolor(contr, r->rcol);      /* -> contribution */
244          addcolor(mp->cbin[bn], contr);
245   }
246  
247  
248 + /* Evaluate irradiance contributions */
249   static void
250 < rayirrad(                       /* compute irradiance rather than radiance */
277 <        RAY *r
278 < )
250 > eval_irrad(FVECT org, FVECT dir)
251   {
252 <        r->rot = 1e-5;                  /* pretend we hit surface */
253 <        VSUM(r->rop, r->rorg, r->rdir, r->rot);
254 <        r->ron[0] = -r->rdir[0];
255 <        r->ron[1] = -r->rdir[1];
256 <        r->ron[2] = -r->rdir[2];
257 <        r->rod = 1.0;
258 <                                        /* compute result */
259 <        r->revf = raytrace;
260 <        (*ofun[Lamb.otype].funp)(&Lamb, r);
261 <        r->revf = rayirrad;
252 >        RAY     thisray;
253 >
254 >        VSUM(thisray.rorg, org, dir, 1.1e-4);
255 >        thisray.rdir[0] = -dir[0];
256 >        thisray.rdir[1] = -dir[1];
257 >        thisray.rdir[2] = -dir[2];
258 >        thisray.rmax = 0.0;
259 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
260 >                                        /* pretend we hit surface */
261 >        thisray.rt = thisray.rot = 1e-5;
262 >        thisray.rod = 1.0;
263 >        VCOPY(thisray.ron, dir);
264 >        VSUM(thisray.rop, org, dir, 1e-4);
265 >        samplendx++;                    /* compute result */
266 >        (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
267   }
268  
269  
270 < /* Evaluate ray contributions */
270 > /* Evaluate radiance contributions */
271   static void
272 < eval_ray(FVECT  org, FVECT  dir, double dmax)
272 > eval_rad(FVECT org, FVECT dir, double dmax)
273   {
274          RAY     thisray;
275                                          /* set up ray */
276 +        VCOPY(thisray.rorg, org);
277 +        VCOPY(thisray.rdir, dir);
278 +        thisray.rmax = dmax;
279          rayorigin(&thisray, PRIMARY, NULL, NULL);
300        if (imm_irrad) {
301                VSUM(thisray.rorg, org, dir, 1.1e-4);
302                thisray.rdir[0] = -dir[0];
303                thisray.rdir[1] = -dir[1];
304                thisray.rdir[2] = -dir[2];
305                thisray.rmax = 0.0;
306                thisray.revf = rayirrad;
307        } else {
308                VCOPY(thisray.rorg, org);
309                VCOPY(thisray.rdir, dir);
310                thisray.rmax = dmax;
311        }
280          samplendx++;                    /* call ray evaluation */
281          rayvalue(&thisray);
282   }
# Line 350 | Line 318 | rcontrib()
318   #endif
319          while (getvec(orig) == 0 && getvec(direc) == 0) {
320                  d = normalize(direc);
321 <                if ((d == 0.0) & (accumulate != 1)) {
321 >                if (nchild != -1 && (d == 0.0) & (accumulate == 0)) {
322                          if (!ignore_warning_given++)
323                                  error(WARNING,
324                                  "dummy ray(s) ignored during accumulation\n");
# Line 360 | Line 328 | rcontrib()
328                          lastray = lastdone = 0;
329                  ++lastray;
330                  if (d == 0.0) {                         /* zero ==> flush */
331 <                        if ((yres <= 0) | (xres <= 0))
332 <                                waitflush = 1;          /* flush right after */
333 <                } else {                                /* else compute */
334 <                        eval_ray(orig, direc, lim_dist ? d : 0.0);
331 >                        if ((yres <= 0) | (xres <= 1))
332 >                                waitflush = 1;          /* flush after */
333 >                        if (nchild == -1)
334 >                                account = 1;
335 >                } else if (imm_irrad) {                 /* else compute */
336 >                        eval_irrad(orig, direc);
337 >                } else {
338 >                        eval_rad(orig, direc, lim_dist ? d : 0.0);
339                  }
340                  done_contrib();         /* accumulate/output */
341                  ++lastdone;
342                  if (raysleft && !--raysleft)
343                          break;          /* preemptive EOI */
344          }
345 <        if (accumulate <= 0 || account < accumulate) {
345 >        if (nchild != -1 && (accumulate <= 0) | (account < accumulate)) {
346                  if (account < accumulate) {
347                          error(WARNING, "partial accumulation in final record");
348                          accumulate -= account;
# Line 378 | Line 350 | rcontrib()
350                  account = 1;            /* output accumulated totals */
351                  done_contrib();
352          }
353 +        lu_done(&ofiletab);             /* close output files */
354          if (raysleft)
355                  error(USER, "unexpected EOF on input");
383        lu_done(&ofiletab);             /* close output files */
356   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines