ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/rt/RcontribSimulManager.cpp
(Generate patch)

Comparing ray/src/rt/RcontribSimulManager.cpp (file contents):
Revision 2.15 by greg, Fri Oct 17 17:43:53 2025 UTC vs.
Revision 2.23 by greg, Tue Nov 11 02:08:52 2025 UTC

# Line 58 | Line 58 | static const char      ROW_DONE[] = "ROW FINISHED\n";
58   static RcontribMod *
59   NewRcMod(const char *prms, const char *binexpr, int ncbins)
60   {
61 +        if (binexpr && !*binexpr) binexpr = NULL;
62          if (!prms) prms = "";
63          if ((ncbins > 1) & !binexpr) {
64                  error(USER, "missing bin expression");
# Line 115 | Line 116 | formstr(int f)
116          return("unknown");
117   }
118  
119 < // Our default data share function
119 > // Standard file data share function
120   RdataShare *
121 < defDataShare(const char *name, RCOutputOp op, size_t siz)
121 > fileDataShare(const char *name, RCOutputOp op, size_t siz)
122   {
123 <        return new RdataShareMap(name, RSDOflags[op], siz);
123 >        if (op == RCOrecover && access(name, R_OK|W_OK) < 0) {
124 >                sprintf(errmsg, "cannot recover from '%s'", name);
125 >                error(SYSTEM, errmsg);
126 >                return NULL;
127 >        }
128 >        RdataShare *    rds = new RdataShareFile(name, RSDOflags[op],
129 >                                                 siz*(op != RCOforce));
130 >                                                
131 >        if (!rds || (op == RCOforce && rds->Resize(siz) < siz)) {
132 >                delete rds;
133 >                sprintf(errmsg, "cannot create %lu byte output file '%s'",
134 >                                        (unsigned long)siz, name);
135 >                error(SYSTEM, errmsg);
136 >                return NULL;
137 >        }
138 >        return rds;
139   }
140  
141 + // Memory-mapped data share function
142 + RdataShare *
143 + mapDataShare(const char *name, RCOutputOp op, size_t siz)
144 + {
145 +        if (op == RCOrecover && access(name, R_OK|W_OK) < 0) {
146 +                sprintf(errmsg, "cannot recover from '%s'", name);
147 +                error(SYSTEM, errmsg);
148 +                return NULL;
149 +        }
150 +        RdataShare *    rds = new RdataShareMap(name, RSDOflags[op],
151 +                                                 siz*(op != RCOforce));
152 +
153 +        if (!rds || (op == RCOforce && rds->Resize(siz) < siz)) {
154 +                delete rds;
155 +                sprintf(errmsg, "cannot create %lu byte output map '%s'",
156 +                                        (unsigned long)siz, name);
157 +                error(SYSTEM, errmsg);
158 +                return NULL;
159 +        }
160 +        return rds;
161 + }
162 +
163   // Set output format ('f', 'd', or 'c')
164   bool
165   RcontribSimulManager::SetDataFormat(int ty)
# Line 165 | Line 203 | RcontribSimulManager::RctCall(RAY *r, void *cd)
203          if (!mp)
204                  return 0;               // not in our modifier list
205  
206 <        int                     bi = 0; // get bin index
206 >        int     i;                      // pre-emptive check for zero
207 >        if (rcp->HasFlag(RCcontrib)) {
208 >                for (i = NCSAMP; i--; )
209 >                        if (r->rcoef[i]*r->rcol[i] > FTINY)
210 >                                break;
211 >                if (i < 0)
212 >                        return 0;       // zero contribution
213 >        } else if (sintens(r->rcoef) <= FTINY)
214 >                return 0;               // zero coefficient
215 >
216 >        int     bi = 0;                 // get bin index
217          if (mp->binv) {
218                  worldfunc(RCCONTEXT, r);
219                  set_eparams(mp->params);
# Line 185 | Line 233 | RcontribSimulManager::RctCall(RAY *r, void *cd)
233          if (rcp->HasFlag(RCcontrib))
234                  smultscolor(contr, r->rcol);    // -> value contribution
235  
236 <        for (int i = 0; i < NCSAMP; i++)
236 >        for (i = 0; i < NCSAMP; i++)
237                  *dvp++ += contr[i];             // accumulate color/spectrum
238          return 1;
239   }
# Line 379 | Line 427 | RcontribSimulManager::PrepOutput()
427                          if (rd < 0)
428                                  return -1;
429                          if (rd >= op->nRows) {
430 <                                if (remWarnings >= 0) {
430 >                                if (remWarnings > 0) {
431                                          sprintf(errmsg, "recovered output '%s' is complete",
432                                                          op->GetName());
433                                          error(WARNING, --remWarnings ? errmsg : "etc...");
# Line 396 | Line 444 | RcontribSimulManager::PrepOutput()
444          }
445          rowsDone.NewBitMap(outList->nRows);     // create row completion map
446          rowsDone.ClearBits(0, rInPos, true);
447 <        return rInPos;
447 >        return nrDone = rInPos;
448   }
449  
450   // Create header in open write-only channel
# Line 431 | Line 479 | RcontribOutput::NewHeader(const RcontribSimulManager *
479          sprintf(hdr+begData, "%s%d\n", NCOMPSTR, NCSAMP);
480          begData += strlen(hdr+begData);
481          if (NCSAMP > 3) {
482 <                sprintf(hdr+begData, "%s %f %f %f %f\n", WLSPLTSTR,
482 >                sprintf(hdr+begData, "%s %g %g %g %g\n", WLSPLTSTR,
483                                  WLPART[0], WLPART[1], WLPART[2], WLPART[3]);
484                  begData += strlen(hdr+begData);
485          }
# Line 516 | Line 564 | RcontribOutput::CheckHeader(const RcontribSimulManager
564                  return -1;
565          }
566                                                  // check #columns
567 <        if (((cp = findArgs(hdr, "NCOLS=", begData)) && atoi(cp)*esiz != rowBytes) ||
568 <                        !rcp->xres | (rowBytes > esiz)) {
569 <                sprintf(errmsg, "expected NCOLS=%d in '%s'",
522 <                                int(rowBytes/esiz), GetName());
567 >        if ((cp = findArgs(hdr, "NCOLS=", begData)) ? (atoi(cp)*esiz != rowBytes)
568 >                                                    : (!rcp->xres | (rowBytes > esiz))) {
569 >                sprintf(errmsg, "expected NCOLS=%d in '%s'", int(rowBytes/esiz), GetName());
570                  error(USER, errmsg);
571                  return -1;
572          }
# Line 561 | Line 608 | RcontribSimulManager::ResetRow(int r)
608                          return false;
609  
610          rowsDone.ClearBits(r, rInPos-r, false);
611 <        rInPos = r;
611 >        nrDone = rInPos = r;
612          return true;
613   }
614  
# Line 720 | Line 767 | RcontribSimulManager::UpdateRowsDone(int r)
767                  error(WARNING, "redundant call to UpdateRowsDone()");
768                  return false;
769          }
770 <        int     nDone = GetRowFinished();
771 <        if (nDone <= r)
770 >        GetRowFinished();
771 >        if (nrDone <= r)
772                  return true;                    // nothing to update, yet
773          for (RcontribOutput *op = outList; op; op = op->next)
774 <                if (!op->SetRowsDone(nDone))
774 >                if (!op->SetRowsDone(nrDone))
775                          return false;
776          return true;                            // up-to-date
777   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)