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.1 by greg, Sat Jun 9 07:16:47 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 +
14   CUBE    thescene;                       /* our scene */
15   OBJECT  nsceneobjs;                     /* number of objects in our scene */
16  
# Line 23 | Line 23 | void   (*trace)() = trace_contrib;
23  
24   int     do_irrad = 0;                   /* compute irradiance? */
25  
26 < int     rand_samp = 0;                  /* pure Monte Carlo sampling? */
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 43 | Line 43 | double specjitter = 1.;                /* specular sampling jitter *
43  
44   int     backvis = 1;                    /* back face visibility */
45  
46 < int     maxdepth = 8;                   /* maximum recursion depth */
47 < double  minweight = 5e-4;               /* minimum ray weight */
46 > int     maxdepth = -10;                 /* maximum recursion depth */
47 > double  minweight = 2e-3;               /* minimum ray weight */
48  
49   char    *ambfile = NULL;                /* ambient file name */
50   COLOR   ambval = BLKCOLOR;              /* ambient value */
# Line 61 | Line 61 | int    account;                        /* current accumulation count */
61   RNUMBER raysleft;                       /* number of rays left to trace */
62   long    waitflush;                      /* how long until next flush */
63  
64 < int     lastray = 0;                    /* last ray number sent */
65 < int     lastdone = 0;                   /* last ray output */
64 > RNUMBER lastray = 0;                    /* last ray number sent */
65 > RNUMBER lastdone = 0;                   /* last ray output */
66  
67 /* Close output stream and free record */
68 static void
69 closestream(void *p)
70 {
71        STREAMOUT       *sop = (STREAMOUT *)p;
72        int             status = 0;
73        if (sop->outpipe)
74                status = pclose(sop->ofp);
75        else if (sop->ofp != stdout)
76                status = fclose(sop->ofp);
77        if (status)
78                error(SYSTEM, "error closing output stream");
79        free(p);
80 }
81
82 LUTAB   ofiletab = LU_SINIT(free,closestream);  /* output file table */
83
84 #define OF_MODIFIER     01
85 #define OF_BIN          02
86
67   static void mcfree(void *p) { epfree((*(MODCONT *)p).binv); free(p); }
68  
69   LUTAB   modconttab = LU_SINIT(NULL,mcfree);     /* modifier lookup table */
70  
91 static OBJECT           traset[MAXTSET+1]={0};  /* trace include set */
92
71   /************************** INITIALIZATION ROUTINES ***********************/
72  
95 void
96 tranotify(                      /* record new modifier */
97        OBJECT  obj
98 )
99 {
100        static int      hitlimit = 0;
101        OBJREC          *o = objptr(obj);
102        int             i;
103
104        if (obj == OVOID) {             /* starting over */
105                traset[0] = 0;
106                hitlimit = 0;
107                return;
108        }
109        if (hitlimit || !ismodifier(o->otype))
110                return;
111        for (i = nmods; i-- > 0; )
112                if (!strcmp(o->oname, modname[i])) {
113                        if (traset[0] >= MAXTSET) {
114                                error(WARNING, "too many same-named modifiers");
115                                hitlimit++;
116                                return;         /* should this be fatal? */
117                        }
118                        insertelem(traset, obj);
119                        break;
120                }
121 }
122
123
73   char *
74   formstr(                                /* return format identifier */
75          int  f
# Line 186 | 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 208 | 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 222 | Line 171 | rcinit()
171          if (nproc > MAXPROCESS)
172                  sprintf(errmsg, "too many processes requested -- reducing to %d",
173                                  nproc = MAXPROCESS);
174 <                
175 <        if ((nproc > 1) & (accumulate <= 0))
176 <                zero_record(0);         /* prime our queue to accumulate */
177 <
229 <        if (recover) {                  /* recover previous output? */
230 <                if (accumulate <= 0) {
231 <                        reload_output();
232 <                        if ((nproc > 1) & (accumulate <= 0))
233 <                                queue_modifiers();
234 <                } else
235 <                        recover_output();
174 >        if (nproc > 1) {
175 >                preload_objs();         /* preload auxiliary data */
176 >                                        /* set shared memory boundary */
177 >                shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY");
178          }
179          if (yres > 0) {                 /* set up flushing & ray counts */
180                  if (xres > 0)
# Line 244 | Line 186 | rcinit()
186          if ((account = accumulate) > 1)
187                  raysleft *= accumulate;
188          waitflush = (yres > 0) & (xres > 1) ? 0 : xres;
247                                        /* tracing to sources as well */
248        for (i = 0; i < nsources; i++)
249                source[i].sflags |= SFOLLOW;
189  
190 <        if (nproc == 1 || in_rchild())  /* single process or child */
190 >        if (nproc > 1 && in_rchild())   /* forked child? */
191                  return;                 /* return to main processing loop */
192  
193 <        parental_loop();                /* else run controller */
193 >        if (recover) {                  /* recover previous output? */
194 >                if (accumulate <= 0)
195 >                        reload_output();
196 >                else
197 >                        recover_output();
198 >        }
199 >        if (nproc == 1)                 /* single process? */
200 >                return;
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 265 | 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 286 | Line 237 | trace_contrib(RAY *r)
237   }
238  
239  
240 + /* Evaluate irradiance contributions */
241   static void
242 < rayirrad(                       /* compute irradiance rather than radiance */
291 <        RAY *r
292 < )
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);
314        if (imm_irrad) {
315                VSUM(thisray.rorg, org, dir, 1.1e-4);
316                thisray.rdir[0] = -dir[0];
317                thisray.rdir[1] = -dir[1];
318                thisray.rdir[2] = -dir[2];
319                thisray.rmax = 0.0;
320                thisray.revf = rayirrad;
321        } else {
322                VCOPY(thisray.rorg, org);
323                VCOPY(thisray.rdir, dir);
324                thisray.rmax = dmax;
325        }
270          samplendx++;                    /* call ray evaluation */
271          rayvalue(&thisray);
272   }
# Line 356 | Line 300 | rcontrib()
300          static int      ignore_warning_given = 0;
301          FVECT           orig, direc;
302          double          d;
303 <                                        /* initialize & fork */
303 >                                        /* initialize (& fork more of us) */
304          rcinit();
305                                          /* load rays from stdin & process */
306   #ifdef getc_unlocked
307 <        flockfile(stdin);               /* avoid lock/unlock overhead */
307 >        flockfile(stdin);               /* avoid mutex overhead */
308   #endif
309          while (getvec(orig) == 0 && getvec(direc) == 0) {
310                  d = normalize(direc);
311 <                if ((d == 0.0) & (accumulate != 1)) {
311 >                if (nchild != -1 && (d == 0.0) & (accumulate != 1)) {
312                          if (!ignore_warning_given++)
313                                  error(WARNING,
314                                  "dummy ray(s) ignored during accumulation\n");
# Line 376 | Line 320 | rcontrib()
320                  if (d == 0.0) {                         /* zero ==> flush */
321                          if ((yres <= 0) | (xres <= 0))
322                                  waitflush = 1;          /* flush right after */
323 <                } else {                                /* else compute */
324 <                        eval_ray(orig, direc, lim_dist ? d : 0.0);
323 >                        account = 1;
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;
331                  if (raysleft && !--raysleft)
332                          break;          /* preemptive EOI */
333          }
334 <        if (accumulate <= 0 || account < accumulate) {
334 >        if (nchild != -1 && (accumulate <= 0) | (account < accumulate)) {
335                  if (account < accumulate) {
336                          error(WARNING, "partial accumulation in final record");
337                          accumulate -= account;
# Line 392 | 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");
397        lu_done(&ofiletab);             /* close output files */
345   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines