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.10 by greg, Tue Jun 19 00:12:08 2012 UTC

# Line 11 | Line 11 | static const char RCSid[] = "$Id$";
11   #include "otypes.h"
12   #include "platform.h"
13  
14 + char    *shm_boundary = NULL;           /* boundary of shared memory */
15 +
16   CUBE    thescene;                       /* our scene */
17   OBJECT  nsceneobjs;                     /* number of objects in our scene */
18  
# Line 23 | 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 */
30 > double  dstrsrc = 0.9;                  /* square source distribution */
31   double  shadthresh = .03;               /* shadow threshold */
32   double  shadcert = .75;                 /* shadow certainty */
33   int     directrelay = 3;                /* number of source relays */
# Line 43 | 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 61 | 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  
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
69   static void mcfree(void *p) { epfree((*(MODCONT *)p).binv); free(p); }
70  
71   LUTAB   modconttab = LU_SINIT(NULL,mcfree);     /* modifier lookup table */
72  
91 static OBJECT           traset[MAXTSET+1]={0};  /* trace include set */
92
73   /************************** INITIALIZATION ROUTINES ***********************/
74  
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
75   char *
76   formstr(                                /* return format identifier */
77          int  f
# Line 186 | Line 137 | addmodifier(char *modn, char *outf, char *binv, int bi
137   }
138  
139  
140 < /* add modifiers from a file list */
140 > /* Add modifiers from a file list */
141   void
142   addmodfile(char *fname, char *outf, char *binv, int bincnt)
143   {
# Line 208 | Line 159 | quit(                  /* quit program */
159   )
160   {
161          if (nchild > 0)         /* close children if any */
162 <                end_children();
162 >                end_children(code != 0);
163          exit(code);
164   }
165  
# Line 222 | Line 173 | rcinit()
173          if (nproc > MAXPROCESS)
174                  sprintf(errmsg, "too many processes requested -- reducing to %d",
175                                  nproc = MAXPROCESS);
176 <                
177 <        if ((nproc > 1) & (accumulate <= 0))
178 <                zero_record(0);         /* prime our queue to accumulate */
179 <
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();
176 >        if (nproc > 1) {
177 >                preload_objs();         /* preload auxiliary data */
178 >                                        /* set shared memory boundary */
179 >                shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY");
180          }
181          if (yres > 0) {                 /* set up flushing & ray counts */
182                  if (xres > 0)
# Line 248 | Line 192 | rcinit()
192          for (i = 0; i < nsources; i++)
193                  source[i].sflags |= SFOLLOW;
194  
195 <        if (nproc == 1 || in_rchild())  /* single process or child */
195 >        if (nproc > 1 && in_rchild())   /* forked child? */
196                  return;                 /* return to main processing loop */
197  
198 <        parental_loop();                /* else run controller */
198 >        if (recover) {                  /* recover previous output? */
199 >                if (accumulate <= 0)
200 >                        reload_output();
201 >                else
202 >                        recover_output();
203 >        }
204 >        if (nproc == 1)                 /* single process? */
205 >                return;
206 >                                        /* else run appropriate controller */
207 >        if (accumulate <= 0)
208 >                feeder_loop();
209 >        else
210 >                parental_loop();
211          quit(0);                        /* parent musn't return! */
212   }
213  
# Line 265 | Line 221 | trace_contrib(RAY *r)
221          int     bn;
222          RREAL   contr[3];
223  
224 <        if (r->ro == NULL || !inset(traset, r->ro->omod))
224 >        if (r->ro == NULL || r->ro->omod == OVOID)
225                  return;
226  
227          mp = (MODCONT *)lu_find(&modconttab,objptr(r->ro->omod)->oname)->data;
228  
229 <        if (mp == NULL)
230 <                error(CONSISTENCY, "unexpected modifier in trace_contrib()");
229 >        if (mp == NULL)                         /* not in our list? */
230 >                return;
231  
232          worldfunc(RCCONTEXT, r);                /* get bin number */
233          bn = (int)(evalue(mp->binv) + .5);
# Line 286 | Line 242 | trace_contrib(RAY *r)
242   }
243  
244  
245 + /* Evaluate irradiance contributions */
246   static void
247 < rayirrad(                       /* compute irradiance rather than radiance */
291 <        RAY *r
292 < )
247 > eval_irrad(FVECT org, FVECT dir)
248   {
249 <        r->rot = 1e-5;                  /* pretend we hit surface */
250 <        VSUM(r->rop, r->rorg, r->rdir, r->rot);
251 <        r->ron[0] = -r->rdir[0];
252 <        r->ron[1] = -r->rdir[1];
253 <        r->ron[2] = -r->rdir[2];
254 <        r->rod = 1.0;
255 <                                        /* compute result */
256 <        r->revf = raytrace;
257 <        (*ofun[Lamb.otype].funp)(&Lamb, r);
258 <        r->revf = rayirrad;
249 >        RAY     thisray;
250 >
251 >        VSUM(thisray.rorg, org, dir, 1.1e-4);
252 >        thisray.rdir[0] = -dir[0];
253 >        thisray.rdir[1] = -dir[1];
254 >        thisray.rdir[2] = -dir[2];
255 >        thisray.rmax = 0.0;
256 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
257 >        thisray.rot = 1e-5;             /* pretend we hit surface */
258 >        thisray.rod = 1.0;
259 >        VSUM(thisray.rop, org, dir, 1e-4);
260 >        samplendx++;                    /* compute result */
261 >        (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
262   }
263  
264  
265 < /* Evaluate ray contributions */
265 > /* Evaluate radiance contributions */
266   static void
267 < eval_ray(FVECT  org, FVECT  dir, double dmax)
267 > eval_rad(FVECT org, FVECT dir, double dmax)
268   {
269          RAY     thisray;
270                                          /* set up ray */
271 +        VCOPY(thisray.rorg, org);
272 +        VCOPY(thisray.rdir, dir);
273 +        thisray.rmax = dmax;
274          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        }
275          samplendx++;                    /* call ray evaluation */
276          rayvalue(&thisray);
277   }
# Line 356 | Line 305 | rcontrib()
305          static int      ignore_warning_given = 0;
306          FVECT           orig, direc;
307          double          d;
308 <                                        /* initialize & fork */
308 >                                        /* initialize (& fork more of us) */
309          rcinit();
310                                          /* load rays from stdin & process */
311   #ifdef getc_unlocked
312 <        flockfile(stdin);               /* avoid lock/unlock overhead */
312 >        flockfile(stdin);               /* avoid mutex overhead */
313   #endif
314          while (getvec(orig) == 0 && getvec(direc) == 0) {
315                  d = normalize(direc);
316 <                if ((d == 0.0) & (accumulate != 1)) {
316 >                if (nchild != -1 && (d == 0.0) & (accumulate != 1)) {
317                          if (!ignore_warning_given++)
318                                  error(WARNING,
319                                  "dummy ray(s) ignored during accumulation\n");
# Line 376 | Line 325 | rcontrib()
325                  if (d == 0.0) {                         /* zero ==> flush */
326                          if ((yres <= 0) | (xres <= 0))
327                                  waitflush = 1;          /* flush right after */
328 <                } else {                                /* else compute */
329 <                        eval_ray(orig, direc, lim_dist ? d : 0.0);
328 >                        account = 1;
329 >                } else if (imm_irrad) {                 /* else compute */
330 >                        eval_irrad(orig, direc);
331 >                } else {
332 >                        eval_rad(orig, direc, lim_dist ? d : 0.0);
333                  }
334                  done_contrib();         /* accumulate/output */
335                  ++lastdone;
336                  if (raysleft && !--raysleft)
337                          break;          /* preemptive EOI */
338          }
339 <        if (accumulate <= 0 || account < accumulate) {
339 >        if ((accumulate <= 0) | (account < accumulate)) {
340                  if (account < accumulate) {
341                          error(WARNING, "partial accumulation in final record");
342                          accumulate -= account;
# Line 392 | Line 344 | rcontrib()
344                  account = 1;            /* output accumulated totals */
345                  done_contrib();
346          }
347 +        lu_done(&ofiletab);             /* close output files */
348          if (raysleft)
349                  error(USER, "unexpected EOF on input");
397        lu_done(&ofiletab);             /* close output files */
350   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines