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.6 by greg, Fri Jun 15 00:57:40 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 */
31   double  shadthresh = .03;               /* shadow threshold */
# 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 222 | Line 173 | rcinit()
173          if (nproc > MAXPROCESS)
174                  sprintf(errmsg, "too many processes requested -- reducing to %d",
175                                  nproc = MAXPROCESS);
176 <                
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 ((nproc > 1) & (accumulate <= 0))
182 <                zero_record(0);         /* prime our queue to accumulate */
182 >                put_zero_record(0);     /* prime our queue to accumulate */
183  
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();
236        }
184          if (yres > 0) {                 /* set up flushing & ray counts */
185                  if (xres > 0)
186                          raysleft = (RNUMBER)xres*yres;
# Line 248 | Line 195 | rcinit()
195          for (i = 0; i < nsources; i++)
196                  source[i].sflags |= SFOLLOW;
197  
198 <        if (nproc == 1 || in_rchild())  /* single process or child */
198 >        if (nproc > 1 && in_rchild())   /* forked child? */
199                  return;                 /* return to main processing loop */
200  
201 +        if (recover) {                  /* recover previous output? */
202 +                if (accumulate <= 0) {
203 +                        reload_output();
204 +                        if (nproc > 1)
205 +                                queue_modifiers();
206 +                } else
207 +                        recover_output();
208 +        }
209 +        if (nproc == 1)                 /* single process? */
210 +                return;
211 +
212          parental_loop();                /* else run controller */
213          quit(0);                        /* parent musn't return! */
214   }
# Line 265 | Line 223 | trace_contrib(RAY *r)
223          int     bn;
224          RREAL   contr[3];
225  
226 <        if (r->ro == NULL || !inset(traset, r->ro->omod))
226 >        if (r->ro == NULL || r->ro->omod == OVOID)
227                  return;
228  
229          mp = (MODCONT *)lu_find(&modconttab,objptr(r->ro->omod)->oname)->data;
230  
231 <        if (mp == NULL)
232 <                error(CONSISTENCY, "unexpected modifier in trace_contrib()");
231 >        if (mp == NULL)                         /* not in our list? */
232 >                return;
233  
234          worldfunc(RCCONTEXT, r);                /* get bin number */
235          bn = (int)(evalue(mp->binv) + .5);
# Line 356 | Line 314 | rcontrib()
314          static int      ignore_warning_given = 0;
315          FVECT           orig, direc;
316          double          d;
317 <                                        /* initialize & fork */
317 >                                        /* initialize (& fork more of us) */
318          rcinit();
319                                          /* load rays from stdin & process */
320   #ifdef getc_unlocked
321 <        flockfile(stdin);               /* avoid lock/unlock overhead */
321 >        flockfile(stdin);               /* avoid mutex overhead */
322   #endif
323          while (getvec(orig) == 0 && getvec(direc) == 0) {
324                  d = normalize(direc);
325 <                if ((d == 0.0) & (accumulate != 1)) {
325 >                if (nchild != -1 && (d == 0.0) & (accumulate != 1)) {
326                          if (!ignore_warning_given++)
327                                  error(WARNING,
328                                  "dummy ray(s) ignored during accumulation\n");
# Line 376 | Line 334 | rcontrib()
334                  if (d == 0.0) {                         /* zero ==> flush */
335                          if ((yres <= 0) | (xres <= 0))
336                                  waitflush = 1;          /* flush right after */
337 +                        account = 1;
338                  } else {                                /* else compute */
339                          eval_ray(orig, direc, lim_dist ? d : 0.0);
340                  }
# Line 384 | Line 343 | rcontrib()
343                  if (raysleft && !--raysleft)
344                          break;          /* preemptive EOI */
345          }
346 <        if (accumulate <= 0 || account < accumulate) {
346 >        if (nchild != -1 && (accumulate <= 0) | (account < accumulate)) {
347                  if (account < accumulate) {
348                          error(WARNING, "partial accumulation in final record");
349                          accumulate -= account;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines