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.34 by greg, Tue Nov 13 19:58:33 2018 UTC vs.
Revision 2.45 by greg, Wed Aug 21 20:42:20 2024 UTC

# Line 12 | Line 12 | static const char RCSid[] = "$Id$";
12   #include "otypes.h"
13   #include "source.h"
14  
15 char    *shm_boundary = NULL;           /* boundary of shared memory */
16
15   CUBE    thescene;                       /* our scene */
16   OBJECT  nsceneobjs;                     /* number of objects in our scene */
17  
# Line 68 | Line 66 | RNUMBER        lastdone = 0;                   /* last ray output */
66  
67   static void     trace_contrib(RAY *r);  /* our trace callback */
68  
69 < static void mcfree(void *p) { epfree((*(MODCONT *)p).binv); free(p); }
69 > static void mcfree(void *p) { epfree((*(MODCONT *)p).binv,1); free(p); }
70  
71   LUTAB   modconttab = LU_SINIT(NULL,mcfree);     /* modifier lookup table */
72  
73   /************************** INITIALIZATION ROUTINES ***********************/
74  
75 < char *
75 > const char *
76   formstr(                                /* return format identifier */
77          int  f
78   )
# Line 83 | Line 81 | formstr(                               /* return format identifier */
81          case 'a': return("ascii");
82          case 'f': return("float");
83          case 'd': return("double");
84 <        case 'c': return(COLRFMT);
84 >        case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT);
85          }
86          return("unknown");
87   }
# Line 102 | Line 100 | addmodifier(char *modn, char *outf, char *prms, char *
100                  sprintf(errmsg, "duplicate modifier '%s'", modn);
101                  error(USER, errmsg);
102          }
105        if (nmods >= MAXMODLIST) {
106                sprintf(errmsg, "too many modifiers (%d limit)", MAXMODLIST);
107                error(INTERNAL, errmsg);
108        }
103          if (!strcmp(modn, VOIDID)) {
104                  sprintf(errmsg, "cannot track '%s' modifier", VOIDID);
105                  error(USER, errmsg);
106          }
107 +        if (nmods >= modasiz) {         /* need bigger modifier array */
108 +                modasiz += modasiz/2 + 64;
109 +                if (modname == NULL)
110 +                        modname = (char **)malloc(modasiz*sizeof(char *));
111 +                else
112 +                        modname = (char **)realloc(modname, modasiz*sizeof(char *));
113 +                if (modname == NULL)
114 +                        error(SYSTEM, "Out of memory in addmodifier()");
115 +        }
116          modname[nmods++] = modn;        /* XXX assumes static string */
117          lep->key = modn;                /* XXX assumes static string */
118          if (binv == NULL)
# Line 129 | Line 132 | addmodifier(char *modn, char *outf, char *prms, char *
132                  error(USER, errmsg);
133          }
134                                          /* initialize results holder */
135 <        mp = (MODCONT *)malloc(sizeof(MODCONT)+sizeof(DCOLOR)*(bincnt-1));
135 >        mp = (MODCONT *)malloc(mcsize(bincnt));
136          if (mp == NULL)
137                  error(SYSTEM, "out of memory in addmodifier");
138          mp->outspec = outf;             /* XXX assumes static string */
# Line 138 | Line 141 | addmodifier(char *modn, char *outf, char *prms, char *
141          mp->binv = ebinv;
142          mp->bin0 = 0;
143          mp->nbins = bincnt;
144 <        memset(mp->cbin, 0, sizeof(DCOLOR)*bincnt);
144 >        memset(mp->cbin, 0, DCOLORSIZ*bincnt);
145                                          /* figure out starting bin */
146          while (!getostream(mp->outspec, mp->modname, mp->bin0, 1))
147                  mp->bin0++;
# Line 154 | Line 157 | addmodifier(char *modn, char *outf, char *prms, char *
157   void
158   addmodfile(char *fname, char *outf, char *prms, char *binv, int bincnt)
159   {
160 <        char    *mname[MAXMODLIST];
161 <        int     i;
162 <                                        /* find the file & store strings */
163 <        i = wordfile(mname, MAXMODLIST, getpath(fname, getrlibpath(), R_OK));
164 <        if (i < 0) {
165 <                sprintf(errmsg, "cannot find modifier file '%s'", fname);
160 >        char    *path = getpath(fname, getrlibpath(), R_OK);
161 >        char    mod[MAXSTR];
162 >        FILE    *fp;
163 >
164 >        if (path == NULL || (fp = fopen(path, "r")) == NULL) {
165 >                if (path == NULL)
166 >                        sprintf(errmsg, "cannot find modifier file '%s'", fname);
167 >                else
168 >                        sprintf(errmsg, "cannot load modifier file '%s'", path);
169                  error(SYSTEM, errmsg);
170          }
171 <        if (i >= MAXMODLIST-1) {
172 <                sprintf(errmsg, "too many modifiers (%d limit) in file '%s'",
173 <                                MAXMODLIST-1, fname);
174 <                error(INTERNAL, errmsg);
171 >        while (fgetword(mod, sizeof(mod), fp) != NULL)
172 >                addmodifier(savqstr(mod), outf, prms, binv, bincnt);
173 >        fclose(fp);
174 > }
175 >
176 >
177 > /* Check if we have any more rays left (and report progress) */
178 > int
179 > morays(void)
180 > {
181 >        static RNUMBER  total_rays;
182 >        static time_t   tstart, last_report;
183 >        time_t          tnow;
184 >
185 >        if (!raysleft)
186 >                return(1);      /* unknown total, so nothing to do or say */
187 >
188 >        if (report_intvl > 0 && (tnow = time(0)) >= last_report+report_intvl) {
189 >                if (!total_rays) {
190 >                        total_rays = raysleft;
191 >                        tstart = tnow;
192 >                } else {
193 >                        sprintf(errmsg, "%.2f%% done after %.3f hours\n",
194 >                                        100.-100.*raysleft/total_rays,
195 >                                        (1./3600.)*(tnow - tstart));
196 >                        eputs(errmsg);
197 >                }
198 >                last_report = tnow;
199          }
200 <        for (i = 0; mname[i]; i++)      /* add each one */
171 <                addmodifier(mname[i], outf, prms, binv, bincnt);
200 >        return(--raysleft);
201   }
202  
203  
204 + /* Quit program */
205   void
206 < quit(                   /* quit program */
206 > quit(
207          int  code
208   )
209   {
210          if (nchild > 0)         /* close children if any */
211                  end_children(code != 0);
212 +        else if (nchild < 0)
213 +                _exit(code);    /* avoid flush() in child */
214          exit(code);
215   }
216  
# Line 192 | Line 224 | rcinit(void)
224          if (nproc > MAXPROCESS)
225                  sprintf(errmsg, "too many processes requested -- reducing to %d",
226                                  nproc = MAXPROCESS);
227 <        if (nproc > 1) {
228 <                preload_objs();         /* preload auxiliary data */
197 <                                        /* set shared memory boundary */
198 <                shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY");
199 <        }
227 >        if (nproc > 1)
228 >                cow_memshare();         /* preload auxiliary data */
229          trace = trace_contrib;          /* set up trace call-back */
230          for (i = 0; i < nsources; i++)  /* tracing to sources as well */
231                  source[i].sflags |= SFOLLOW;
# Line 239 | Line 268 | trace_contrib(RAY *r)
268          MODCONT *mp;
269          double  bval;
270          int     bn;
271 <        RREAL   contr[3];
271 >        SCOLOR  contr;
272 >        DCOLORV *dvp;
273 >        int     i;
274  
275          if (r->ro == NULL || r->ro->omod == OVOID)
276                  return;
# Line 263 | Line 294 | trace_contrib(RAY *r)
294          }
295          raycontrib(contr, r, PRIMARY);          /* compute coefficient */
296          if (contrib)
297 <                multcolor(contr, r->rcol);      /* -> contribution */
298 <        addcolor(mp->cbin[bn], contr);
297 >                smultscolor(contr, r->rcol);    /* -> contribution */
298 >        dvp = mcbin(mp, bn);
299 >        for (i = 0; i < NCSAMP; i++)            /* add it in */
300 >                *dvp++ += contr[i];
301   }
302  
303  
# Line 281 | Line 314 | eval_irrad(FVECT org, FVECT dir)
314          thisray.rmax = 0.0;
315          rayorigin(&thisray, PRIMARY, NULL, NULL);
316                                          /* pretend we hit surface */
317 <        thisray.rxt = thisray.rmt = thisray.rot = 1e-5;
317 >        thisray.rxt = thisray.rot = 1e-5;
318          thisray.rod = 1.0;
319          VCOPY(thisray.ron, dir);
320          VSUM(thisray.rop, org, dir, 1e-4);
# Line 318 | Line 351 | done_contrib(void)
351          for (i = 0; i < nmods; i++) {   /* output records & clear */
352                  mp = (MODCONT *)lu_find(&modconttab,modname[i])->data;
353                  mod_output(mp);
354 <                memset(mp->cbin, 0, sizeof(DCOLOR)*mp->nbins);
354 >                memset(mp->cbin, 0, DCOLORSIZ*mp->nbins);
355          }
356          end_record();                   /* end lines & flush if time */
357  
# Line 362 | Line 395 | rcontrib(void)
395                  }
396                  done_contrib();         /* accumulate/output */
397                  ++lastdone;
398 <                if (raysleft && !--raysleft)
398 >                if (!morays())
399                          break;          /* preemptive EOI */
400          }
401          if (nchild != -1 && (accumulate <= 0) | (account < accumulate)) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines