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.12 by greg, Thu Jun 21 17:14:32 2012 UTC

# Line 9 | Line 9 | static const char RCSid[] = "$Id$";
9   #include "rcontrib.h"
10   #include "source.h"
11   #include "otypes.h"
12 #include "platform.h"
12  
13 + char    *shm_boundary = NULL;           /* boundary of shared memory */
14 +
15   CUBE    thescene;                       /* our scene */
16   OBJECT  nsceneobjs;                     /* number of objects in our scene */
17  
# Line 23 | Line 24 | void   (*trace)() = trace_contrib;
24  
25   int     do_irrad = 0;                   /* compute irradiance? */
26  
27 < int     rand_samp = 0;                  /* pure Monte Carlo sampling? */
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 43 | Line 44 | double specjitter = 1.;                /* specular sampling jitter *
44  
45   int     backvis = 1;                    /* back face visibility */
46  
47 < int     maxdepth = 8;                   /* maximum recursion depth */
48 < double  minweight = 5e-4;               /* minimum ray weight */
47 > int     maxdepth = -10;                 /* maximum recursion depth */
48 > double  minweight = 2e-3;               /* minimum ray weight */
49  
50   char    *ambfile = NULL;                /* ambient file name */
51   COLOR   ambval = BLKCOLOR;              /* ambient value */
# Line 61 | 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  
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
68   static void mcfree(void *p) { epfree((*(MODCONT *)p).binv); free(p); }
69  
70   LUTAB   modconttab = LU_SINIT(NULL,mcfree);     /* modifier lookup table */
71  
91 static OBJECT           traset[MAXTSET+1]={0};  /* trace include set */
92
72   /************************** INITIALIZATION ROUTINES ***********************/
73  
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
74   char *
75   formstr(                                /* return format identifier */
76          int  f
# Line 186 | 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 208 | 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 222 | Line 172 | rcinit()
172          if (nproc > MAXPROCESS)
173                  sprintf(errmsg, "too many processes requested -- reducing to %d",
174                                  nproc = MAXPROCESS);
175 <                
176 <        if ((nproc > 1) & (accumulate <= 0))
177 <                zero_record(0);         /* prime our queue to accumulate */
178 <
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();
175 >        if (nproc > 1) {
176 >                preload_objs();         /* preload auxiliary data */
177 >                                        /* set shared memory boundary */
178 >                shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY");
179          }
180          if (yres > 0) {                 /* set up flushing & ray counts */
181                  if (xres > 0)
# Line 248 | Line 191 | rcinit()
191          for (i = 0; i < nsources; i++)
192                  source[i].sflags |= SFOLLOW;
193  
194 <        if (nproc == 1 || in_rchild())  /* single process or child */
194 >        if (nproc > 1 && in_rchild())   /* forked child? */
195                  return;                 /* return to main processing loop */
196  
197 <        parental_loop();                /* else run controller */
197 >        if (recover) {                  /* recover previous output? */
198 >                if (accumulate <= 0)
199 >                        reload_output();
200 >                else
201 >                        recover_output();
202 >        }
203 >        if (nproc == 1)                 /* single process? */
204 >                return;
205 >                                        /* else run appropriate controller */
206 >        if (accumulate <= 0)
207 >                feeder_loop();
208 >        else
209 >                parental_loop();
210          quit(0);                        /* parent musn't return! */
211   }
212  
# Line 265 | Line 220 | trace_contrib(RAY *r)
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  
231          worldfunc(RCCONTEXT, r);                /* get bin number */
232          bn = (int)(evalue(mp->binv) + .5);
# Line 286 | Line 241 | trace_contrib(RAY *r)
241   }
242  
243  
244 + /* Evaluate irradiance contributions */
245   static void
246 < rayirrad(                       /* compute irradiance rather than radiance */
291 <        RAY *r
292 < )
246 > eval_irrad(FVECT org, FVECT dir)
247   {
248 <        r->rot = 1e-5;                  /* pretend we hit surface */
249 <        VSUM(r->rop, r->rorg, r->rdir, r->rot);
250 <        r->ron[0] = -r->rdir[0];
251 <        r->ron[1] = -r->rdir[1];
252 <        r->ron[2] = -r->rdir[2];
253 <        r->rod = 1.0;
254 <                                        /* compute result */
255 <        r->revf = raytrace;
256 <        (*ofun[Lamb.otype].funp)(&Lamb, r);
257 <        r->revf = rayirrad;
248 >        RAY     thisray;
249 >
250 >        VSUM(thisray.rorg, org, dir, 1.1e-4);
251 >        thisray.rdir[0] = -dir[0];
252 >        thisray.rdir[1] = -dir[1];
253 >        thisray.rdir[2] = -dir[2];
254 >        thisray.rmax = 0.0;
255 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
256 >        thisray.rot = 1e-5;             /* pretend we hit surface */
257 >        thisray.rod = 1.0;
258 >        VSUM(thisray.rop, org, dir, 1e-4);
259 >        samplendx++;                    /* compute result */
260 >        (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
261   }
262  
263  
264 < /* Evaluate ray contributions */
264 > /* Evaluate radiance contributions */
265   static void
266 < eval_ray(FVECT  org, FVECT  dir, double dmax)
266 > eval_rad(FVECT org, FVECT dir, double dmax)
267   {
268          RAY     thisray;
269                                          /* set up ray */
270 +        VCOPY(thisray.rorg, org);
271 +        VCOPY(thisray.rdir, dir);
272 +        thisray.rmax = dmax;
273          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        }
274          samplendx++;                    /* call ray evaluation */
275          rayvalue(&thisray);
276   }
# Line 356 | Line 304 | rcontrib()
304          static int      ignore_warning_given = 0;
305          FVECT           orig, direc;
306          double          d;
307 <                                        /* initialize & fork */
307 >                                        /* initialize (& fork more of us) */
308          rcinit();
309                                          /* load rays from stdin & process */
310   #ifdef getc_unlocked
311 <        flockfile(stdin);               /* avoid lock/unlock overhead */
311 >        flockfile(stdin);               /* avoid mutex overhead */
312   #endif
313          while (getvec(orig) == 0 && getvec(direc) == 0) {
314                  d = normalize(direc);
315 <                if ((d == 0.0) & (accumulate != 1)) {
315 >                if (nchild != -1 && (d == 0.0) & (accumulate != 1)) {
316                          if (!ignore_warning_given++)
317                                  error(WARNING,
318                                  "dummy ray(s) ignored during accumulation\n");
# Line 376 | Line 324 | rcontrib()
324                  if (d == 0.0) {                         /* zero ==> flush */
325                          if ((yres <= 0) | (xres <= 0))
326                                  waitflush = 1;          /* flush right after */
327 <                } else {                                /* else compute */
328 <                        eval_ray(orig, direc, lim_dist ? d : 0.0);
327 >                        account = 1;
328 >                } else if (imm_irrad) {                 /* else compute */
329 >                        eval_irrad(orig, direc);
330 >                } else {
331 >                        eval_rad(orig, direc, lim_dist ? d : 0.0);
332                  }
333                  done_contrib();         /* accumulate/output */
334                  ++lastdone;
335                  if (raysleft && !--raysleft)
336                          break;          /* preemptive EOI */
337          }
338 <        if (accumulate <= 0 || account < accumulate) {
338 >        if (nchild != -1 && (accumulate <= 0) | (account < accumulate)) {
339                  if (account < accumulate) {
340                          error(WARNING, "partial accumulation in final record");
341                          accumulate -= account;
# Line 392 | Line 343 | rcontrib()
343                  account = 1;            /* output accumulated totals */
344                  done_contrib();
345          }
346 +        lu_done(&ofiletab);             /* close output files */
347          if (raysleft)
348                  error(USER, "unexpected EOF on input");
397        lu_done(&ofiletab);             /* close output files */
349   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines