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.5 by greg, Wed Jun 13 00:16:42 2012 UTC vs.
Revision 2.13 by greg, Fri Jun 22 22:03:02 2012 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7   */
8  
9   #include "rcontrib.h"
10 #include "source.h"
10   #include "otypes.h"
12 #include "platform.h"
11  
12   char    *shm_boundary = NULL;           /* boundary of shared memory */
13  
# Line 27 | Line 25 | int    do_irrad = 0;                   /* compute irradiance? */
25  
26   int     rand_samp = 1;                  /* pure Monte Carlo sampling? */
27  
28 < double  dstrsrc = 0.0;                  /* square source distribution */
28 > double  dstrsrc = 0.9;                  /* square source distribution */
29   double  shadthresh = .03;               /* shadow threshold */
30   double  shadcert = .75;                 /* shadow certainty */
31   int     directrelay = 3;                /* number of source relays */
# Line 70 | Line 68 | static void mcfree(void *p) { epfree((*(MODCONT *)p).b
68  
69   LUTAB   modconttab = LU_SINIT(NULL,mcfree);     /* modifier lookup table */
70  
73 static OBJECT           traset[MAXTSET+1]={0};  /* trace include set */
74
71   /************************** INITIALIZATION ROUTINES ***********************/
72  
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
73   char *
74   formstr(                                /* return format identifier */
75          int  f
# Line 168 | Line 135 | addmodifier(char *modn, char *outf, char *binv, int bi
135   }
136  
137  
138 < /* add modifiers from a file list */
138 > /* Add modifiers from a file list */
139   void
140   addmodfile(char *fname, char *outf, char *binv, int bincnt)
141   {
# Line 190 | Line 157 | quit(                  /* quit program */
157   )
158   {
159          if (nchild > 0)         /* close children if any */
160 <                end_children();
160 >                end_children(code != 0);
161          exit(code);
162   }
163  
# Line 209 | Line 176 | rcinit()
176                                          /* set shared memory boundary */
177                  shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY");
178          }
212        if ((nproc > 1) & (accumulate <= 0))
213                put_zero_record(0);     /* prime our queue to accumulate */
214
179          if (yres > 0) {                 /* set up flushing & ray counts */
180                  if (xres > 0)
181                          raysleft = (RNUMBER)xres*yres;
# Line 222 | Line 186 | rcinit()
186          if ((account = accumulate) > 1)
187                  raysleft *= accumulate;
188          waitflush = (yres > 0) & (xres > 1) ? 0 : xres;
225                                        /* tracing to sources as well */
226        for (i = 0; i < nsources; i++)
227                source[i].sflags |= SFOLLOW;
189  
190          if (nproc > 1 && in_rchild())   /* forked child? */
191                  return;                 /* return to main processing loop */
192  
193          if (recover) {                  /* recover previous output? */
194 <                if (accumulate <= 0) {
194 >                if (accumulate <= 0)
195                          reload_output();
196 <                        if (nproc > 1)
236 <                                queue_modifiers();
237 <                } else
196 >                else
197                          recover_output();
198          }
199          if (nproc == 1)                 /* single process? */
200                  return;
201 <
202 <        parental_loop();                /* else run controller */
201 >                                        /* else run appropriate controller */
202 >        if (accumulate <= 0)
203 >                feeder_loop();
204 >        else
205 >                parental_loop();
206          quit(0);                        /* parent musn't return! */
207   }
208  
# Line 254 | Line 216 | trace_contrib(RAY *r)
216          int     bn;
217          RREAL   contr[3];
218  
219 <        if (r->ro == NULL || !inset(traset, r->ro->omod))
219 >        if (r->ro == NULL || r->ro->omod == OVOID)
220                  return;
221  
222          mp = (MODCONT *)lu_find(&modconttab,objptr(r->ro->omod)->oname)->data;
223  
224 <        if (mp == NULL)
225 <                error(CONSISTENCY, "unexpected modifier in trace_contrib()");
224 >        if (mp == NULL)                         /* not in our list? */
225 >                return;
226  
227          worldfunc(RCCONTEXT, r);                /* get bin number */
228          bn = (int)(evalue(mp->binv) + .5);
# Line 275 | Line 237 | trace_contrib(RAY *r)
237   }
238  
239  
240 + /* Evaluate irradiance contributions */
241   static void
242 < rayirrad(                       /* compute irradiance rather than radiance */
280 <        RAY *r
281 < )
242 > eval_irrad(FVECT org, FVECT dir)
243   {
244 <        r->rot = 1e-5;                  /* pretend we hit surface */
245 <        VSUM(r->rop, r->rorg, r->rdir, r->rot);
246 <        r->ron[0] = -r->rdir[0];
247 <        r->ron[1] = -r->rdir[1];
248 <        r->ron[2] = -r->rdir[2];
249 <        r->rod = 1.0;
250 <                                        /* compute result */
251 <        r->revf = raytrace;
252 <        (*ofun[Lamb.otype].funp)(&Lamb, r);
253 <        r->revf = rayirrad;
244 >        RAY     thisray;
245 >
246 >        VSUM(thisray.rorg, org, dir, 1.1e-4);
247 >        thisray.rdir[0] = -dir[0];
248 >        thisray.rdir[1] = -dir[1];
249 >        thisray.rdir[2] = -dir[2];
250 >        thisray.rmax = 0.0;
251 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
252 >        thisray.rot = 1e-5;             /* pretend we hit surface */
253 >        thisray.rod = 1.0;
254 >        VSUM(thisray.rop, org, dir, 1e-4);
255 >        samplendx++;                    /* compute result */
256 >        (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
257   }
258  
259  
260 < /* Evaluate ray contributions */
260 > /* Evaluate radiance contributions */
261   static void
262 < eval_ray(FVECT  org, FVECT  dir, double dmax)
262 > eval_rad(FVECT org, FVECT dir, double dmax)
263   {
264          RAY     thisray;
265                                          /* set up ray */
266 +        VCOPY(thisray.rorg, org);
267 +        VCOPY(thisray.rdir, dir);
268 +        thisray.rmax = dmax;
269          rayorigin(&thisray, PRIMARY, NULL, NULL);
303        if (imm_irrad) {
304                VSUM(thisray.rorg, org, dir, 1.1e-4);
305                thisray.rdir[0] = -dir[0];
306                thisray.rdir[1] = -dir[1];
307                thisray.rdir[2] = -dir[2];
308                thisray.rmax = 0.0;
309                thisray.revf = rayirrad;
310        } else {
311                VCOPY(thisray.rorg, org);
312                VCOPY(thisray.rdir, dir);
313                thisray.rmax = dmax;
314        }
270          samplendx++;                    /* call ray evaluation */
271          rayvalue(&thisray);
272   }
# Line 366 | Line 321 | rcontrib()
321                          if ((yres <= 0) | (xres <= 0))
322                                  waitflush = 1;          /* flush right after */
323                          account = 1;
324 <                } else {                                /* else compute */
325 <                        eval_ray(orig, direc, lim_dist ? d : 0.0);
324 >                } else if (imm_irrad) {                 /* else compute */
325 >                        eval_irrad(orig, direc);
326 >                } else {
327 >                        eval_rad(orig, direc, lim_dist ? d : 0.0);
328                  }
329                  done_contrib();         /* accumulate/output */
330                  ++lastdone;
# Line 382 | Line 339 | rcontrib()
339                  account = 1;            /* output accumulated totals */
340                  done_contrib();
341          }
342 +        lu_done(&ofiletab);             /* close output files */
343          if (raysleft)
344                  error(USER, "unexpected EOF on input");
387        lu_done(&ofiletab);             /* close output files */
345   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines