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.2 by greg, Sun Jun 10 05:25:42 2012 UTC vs.
Revision 2.25 by greg, Wed May 20 13:16:20 2015 UTC

# Line 6 | Line 6 | static const char RCSid[] = "$Id$";
6   * Initialization and calculation routines
7   */
8  
9 + #include "copyright.h"
10 +
11   #include "rcontrib.h"
10 #include "source.h"
12   #include "otypes.h"
13 < #include "platform.h"
13 > #include "source.h"
14  
15   char    *shm_boundary = NULL;           /* boundary of shared memory */
16  
# Line 25 | Line 26 | void   (*trace)() = trace_contrib;
26  
27   int     do_irrad = 0;                   /* compute irradiance? */
28  
29 < int     rand_samp = 0;                  /* pure Monte Carlo sampling? */
29 > int     rand_samp = 1;                  /* pure Monte Carlo sampling? */
30  
31 < double  dstrsrc = 0.0;                  /* square source distribution */
31 > double  dstrsrc = 0.9;                  /* square source distribution */
32   double  shadthresh = .03;               /* shadow threshold */
33   double  shadcert = .75;                 /* shadow certainty */
34   int     directrelay = 3;                /* number of source relays */
# Line 45 | Line 46 | double specjitter = 1.;                /* specular sampling jitter *
46  
47   int     backvis = 1;                    /* back face visibility */
48  
49 < int     maxdepth = 8;                   /* maximum recursion depth */
50 < double  minweight = 5e-4;               /* minimum ray weight */
49 > int     maxdepth = -10;                 /* maximum recursion depth */
50 > double  minweight = 2e-3;               /* minimum ray weight */
51  
52   char    *ambfile = NULL;                /* ambient file name */
53   COLOR   ambval = BLKCOLOR;              /* ambient value */
# Line 63 | Line 64 | int    account;                        /* current accumulation count */
64   RNUMBER raysleft;                       /* number of rays left to trace */
65   long    waitflush;                      /* how long until next flush */
66  
67 < int     lastray = 0;                    /* last ray number sent */
68 < int     lastdone = 0;                   /* last ray output */
67 > RNUMBER lastray = 0;                    /* last ray number sent */
68 > RNUMBER lastdone = 0;                   /* last ray output */
69  
69 /* Close output stream and free record */
70 static void
71 closestream(void *p)
72 {
73        STREAMOUT       *sop = (STREAMOUT *)p;
74        int             status = 0;
75        if (sop->outpipe)
76                status = pclose(sop->ofp);
77        else if (sop->ofp != stdout)
78                status = fclose(sop->ofp);
79        if (status)
80                error(SYSTEM, "error closing output stream");
81        free(p);
82 }
83
84 LUTAB   ofiletab = LU_SINIT(free,closestream);  /* output file table */
85
86 #define OF_MODIFIER     01
87 #define OF_BIN          02
88
70   static void mcfree(void *p) { epfree((*(MODCONT *)p).binv); free(p); }
71  
72   LUTAB   modconttab = LU_SINIT(NULL,mcfree);     /* modifier lookup table */
73  
93 static OBJECT           traset[MAXTSET+1]={0};  /* trace include set */
94
74   /************************** INITIALIZATION ROUTINES ***********************/
75  
97 void
98 tranotify(                      /* record new modifier */
99        OBJECT  obj
100 )
101 {
102        static int      hitlimit = 0;
103        OBJREC          *o = objptr(obj);
104        int             i;
105
106        if (obj == OVOID) {             /* starting over */
107                traset[0] = 0;
108                hitlimit = 0;
109                return;
110        }
111        if (hitlimit || !ismodifier(o->otype))
112                return;
113        for (i = nmods; i-- > 0; )
114                if (!strcmp(o->oname, modname[i])) {
115                        if (traset[0] >= MAXTSET) {
116                                error(WARNING, "too many same-named modifiers");
117                                hitlimit++;
118                                return;         /* should this be fatal? */
119                        }
120                        insertelem(traset, obj);
121                        break;
122                }
123 }
124
125
76   char *
77   formstr(                                /* return format identifier */
78          int  f
# Line 140 | Line 90 | formstr(                               /* return format identifier */
90  
91   /* Add modifier to our list to track */
92   MODCONT *
93 < addmodifier(char *modn, char *outf, char *binv, int bincnt)
93 > addmodifier(char *modn, char *outf, char *prms, char *binv, int bincnt)
94   {
95          LUENT   *lep = lu_find(&modconttab,modn);
96          MODCONT *mp;
# Line 177 | Line 127 | addmodifier(char *modn, char *outf, char *binv, int bi
127                  error(SYSTEM, "out of memory in addmodifier");
128          mp->outspec = outf;             /* XXX assumes static string */
129          mp->modname = modn;             /* XXX assumes static string */
130 +        mp->params = prms;
131          mp->binv = ebinv;
132          mp->nbins = bincnt;
133          memset(mp->cbin, 0, sizeof(DCOLOR)*bincnt);
# Line 188 | Line 139 | addmodifier(char *modn, char *outf, char *binv, int bi
139   }
140  
141  
142 < /* add modifiers from a file list */
142 > /* Add modifiers from a file list */
143   void
144 < addmodfile(char *fname, char *outf, char *binv, int bincnt)
144 > addmodfile(char *fname, char *outf, char *prms, char *binv, int bincnt)
145   {
146          char    *mname[MAXMODLIST];
147          int     i;
# Line 200 | Line 151 | addmodfile(char *fname, char *outf, char *binv, int bi
151                  error(SYSTEM, errmsg);
152          }
153          for (i = 0; mname[i]; i++)      /* add each one */
154 <                addmodifier(mname[i], outf, binv, bincnt);
154 >                addmodifier(mname[i], outf, prms, binv, bincnt);
155   }
156  
157  
# Line 210 | Line 161 | quit(                  /* quit program */
161   )
162   {
163          if (nchild > 0)         /* close children if any */
164 <                end_children();
164 >                end_children(code != 0);
165          exit(code);
166   }
167  
# Line 229 | Line 180 | rcinit()
180                                          /* set shared memory boundary */
181                  shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY");
182          }
183 <        if ((nproc > 1) & (accumulate <= 0))
184 <                put_zero_record(0);     /* prime our queue to accumulate */
234 <
235 <        if (recover) {                  /* recover previous output? */
236 <                if (accumulate <= 0) {
237 <                        reload_output();
238 <                        if (nproc > 1)
239 <                                queue_modifiers();
240 <                } else
241 <                        recover_output();
242 <        }
183 >        for (i = 0; i < nsources; i++)  /* tracing to sources as well */
184 >                source[i].sflags |= SFOLLOW;
185          if (yres > 0) {                 /* set up flushing & ray counts */
186                  if (xres > 0)
187                          raysleft = (RNUMBER)xres*yres;
# Line 250 | Line 192 | rcinit()
192          if ((account = accumulate) > 1)
193                  raysleft *= accumulate;
194          waitflush = (yres > 0) & (xres > 1) ? 0 : xres;
253                                        /* tracing to sources as well */
254        for (i = 0; i < nsources; i++)
255                source[i].sflags |= SFOLLOW;
195  
196 <        if (nproc == 1 || in_rchild())  /* single process or child */
196 >        if (nproc > 1 && in_rchild())   /* forked child? */
197                  return;                 /* return to main processing loop */
198  
199 <        parental_loop();                /* else run controller */
199 >        if (recover) {                  /* recover previous output? */
200 >                if (accumulate <= 0)
201 >                        reload_output();
202 >                else
203 >                        recover_output();
204 >        }
205 >        if (nproc == 1)                 /* single process? */
206 >                return;
207 >                                        /* else run appropriate controller */
208 >        if (accumulate <= 0)
209 >                feeder_loop();
210 >        else
211 >                parental_loop();
212          quit(0);                        /* parent musn't return! */
213   }
214  
# Line 268 | Line 219 | static void
219   trace_contrib(RAY *r)
220   {
221          MODCONT *mp;
222 +        double  bval;
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 +                                                /* shadow ray not on source? */
229 +        if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
230 +                return;
231  
232          mp = (MODCONT *)lu_find(&modconttab,objptr(r->ro->omod)->oname)->data;
233  
234 <        if (mp == NULL)
235 <                error(CONSISTENCY, "unexpected modifier in trace_contrib()");
234 >        if (mp == NULL)                         /* not in our list? */
235 >                return;
236  
237 <        worldfunc(RCCONTEXT, r);                /* get bin number */
238 <        bn = (int)(evalue(mp->binv) + .5);
239 <        if ((bn < 0) | (bn >= mp->nbins)) {
240 <                error(WARNING, "bad bin number (ignored)");
237 >        worldfunc(RCCONTEXT, r);                /* else set context */
238 >        set_eparams((char *)mp->params);
239 >        if ((bval = evalue(mp->binv)) <= -.5)   /* and get bin number */
240 >                return;                         /* silently ignore negatives */
241 >        if ((bn = (int)(bval + .5)) >= mp->nbins) {
242 >                sprintf(errmsg, "bad bin number (%d ignored)", bn);
243 >                error(WARNING, errmsg);
244                  return;
245          }
246 <        raycontrib(contr, r, PRIMARY);
246 >        raycontrib(contr, r, PRIMARY);          /* compute coefficient */
247          if (contrib)
248 <                multcolor(contr, r->rcol);
248 >                multcolor(contr, r->rcol);      /* -> contribution */
249          addcolor(mp->cbin[bn], contr);
250   }
251  
252  
253 + /* Evaluate irradiance contributions */
254   static void
255 < rayirrad(                       /* compute irradiance rather than radiance */
297 <        RAY *r
298 < )
255 > eval_irrad(FVECT org, FVECT dir)
256   {
257 <        r->rot = 1e-5;                  /* pretend we hit surface */
258 <        VSUM(r->rop, r->rorg, r->rdir, r->rot);
259 <        r->ron[0] = -r->rdir[0];
260 <        r->ron[1] = -r->rdir[1];
261 <        r->ron[2] = -r->rdir[2];
262 <        r->rod = 1.0;
263 <                                        /* compute result */
264 <        r->revf = raytrace;
265 <        (*ofun[Lamb.otype].funp)(&Lamb, r);
266 <        r->revf = rayirrad;
257 >        RAY     thisray;
258 >
259 >        VSUM(thisray.rorg, org, dir, 1.1e-4);
260 >        thisray.rdir[0] = -dir[0];
261 >        thisray.rdir[1] = -dir[1];
262 >        thisray.rdir[2] = -dir[2];
263 >        thisray.rmax = 0.0;
264 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
265 >                                        /* pretend we hit surface */
266 >        thisray.rt = thisray.rot = 1e-5;
267 >        thisray.rod = 1.0;
268 >        VCOPY(thisray.ron, dir);
269 >        VSUM(thisray.rop, org, dir, 1e-4);
270 >        samplendx++;                    /* compute result */
271 >        (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
272   }
273  
274  
275 < /* Evaluate ray contributions */
275 > /* Evaluate radiance contributions */
276   static void
277 < eval_ray(FVECT  org, FVECT  dir, double dmax)
277 > eval_rad(FVECT org, FVECT dir, double dmax)
278   {
279          RAY     thisray;
280                                          /* set up ray */
281 +        VCOPY(thisray.rorg, org);
282 +        VCOPY(thisray.rdir, dir);
283 +        thisray.rmax = dmax;
284          rayorigin(&thisray, PRIMARY, NULL, NULL);
320        if (imm_irrad) {
321                VSUM(thisray.rorg, org, dir, 1.1e-4);
322                thisray.rdir[0] = -dir[0];
323                thisray.rdir[1] = -dir[1];
324                thisray.rdir[2] = -dir[2];
325                thisray.rmax = 0.0;
326                thisray.revf = rayirrad;
327        } else {
328                VCOPY(thisray.rorg, org);
329                VCOPY(thisray.rdir, dir);
330                thisray.rmax = dmax;
331        }
285          samplendx++;                    /* call ray evaluation */
286          rayvalue(&thisray);
287   }
# Line 370 | Line 323 | rcontrib()
323   #endif
324          while (getvec(orig) == 0 && getvec(direc) == 0) {
325                  d = normalize(direc);
326 <                if ((d == 0.0) & (accumulate != 1)) {
326 >                if (nchild != -1 && (d == 0.0) & (accumulate == 0)) {
327                          if (!ignore_warning_given++)
328                                  error(WARNING,
329                                  "dummy ray(s) ignored during accumulation\n");
# Line 380 | Line 333 | rcontrib()
333                          lastray = lastdone = 0;
334                  ++lastray;
335                  if (d == 0.0) {                         /* zero ==> flush */
336 <                        if ((yres <= 0) | (xres <= 0))
337 <                                waitflush = 1;          /* flush right after */
338 <                } else {                                /* else compute */
339 <                        eval_ray(orig, direc, lim_dist ? d : 0.0);
336 >                        if ((yres <= 0) | (xres <= 1))
337 >                                waitflush = 1;          /* flush after */
338 >                        if (nchild == -1)
339 >                                account = 1;
340 >                } else if (imm_irrad) {                 /* else compute */
341 >                        eval_irrad(orig, direc);
342 >                } else {
343 >                        eval_rad(orig, direc, lim_dist ? d : 0.0);
344                  }
345                  done_contrib();         /* accumulate/output */
346                  ++lastdone;
347                  if (raysleft && !--raysleft)
348                          break;          /* preemptive EOI */
349          }
350 <        if (accumulate <= 0 || account < accumulate) {
350 >        if (nchild != -1 && (accumulate <= 0) | (account < accumulate)) {
351                  if (account < accumulate) {
352                          error(WARNING, "partial accumulation in final record");
353                          accumulate -= account;
# Line 398 | Line 355 | rcontrib()
355                  account = 1;            /* output accumulated totals */
356                  done_contrib();
357          }
358 +        lu_done(&ofiletab);             /* close output files */
359          if (raysleft)
360                  error(USER, "unexpected EOF on input");
403        lu_done(&ofiletab);             /* close output files */
361   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines