--- ray/src/rt/RcontribSimulManager.h 2024/10/29 19:47:19 2.2 +++ ray/src/rt/RcontribSimulManager.h 2024/12/03 17:39:42 2.8 @@ -1,4 +1,4 @@ -/* RCSid $Id: RcontribSimulManager.h,v 2.2 2024/10/29 19:47:19 greg Exp $ */ +/* RCSid $Id: RcontribSimulManager.h,v 2.8 2024/12/03 17:39:42 greg Exp $ */ /* * RcontribSimulManager.h * @@ -25,10 +25,6 @@ extern char RCCONTEXT[]; // global rcontrib context -extern int contrib; // computing contributions? - -extern int xres, yres; // global resolution settings - class RcontribSimulManager; // need forward decl /// Shared data object for record output (includes header; may be write-only) @@ -125,25 +121,30 @@ extern lut_free_t FreeRcMod; * * 1) Call LoadOctree(), then alter the header as desired * 2) Set number of spectral samples (NCSAMP) and call SetDataFormat() - * 3) Call AddModifier() and AddModFile() to indicate tracked modifiers - * 4) Set outOp and cdsF according to desired output/recovery - * 5) Call PrepOutput() to open output channels - * 6) Call SetThreadCount() to fork children if desired - * 7) Set accum to the number of ray samples per record - * 8) Call ComputeRecord() with accum ray samples - * 9) Continue until GetRowMax() records have been sent - * 10) Call Cleanup() + * 3) Set xres and yres to desired dimensions (xres>0 for picture output) + * 4) Call AddModifier() and AddModFile() to indicate tracked modifiers + * 5) Set outOp and cdsF according to desired output/recovery + * 6) Set desired computation flags via SetFlag() + * 7) Call PrepOutput() to open output channels + * 8) Call SetThreadCount() to fork children if desired + * 9) Set accum to the number of ray samples per record + * 10) Call ComputeRecord() with accum ray samples + * 11) Continue until GetRowMax() records have been sent + * 12) Call Cleanup() * * The order of some of these calls may be changed. Technically, the octree * may be loaded anytime before PrepOutput() is called. Also, SetThreadCount() - * may be called anytime after PrepOutput() and interleaved with + * may be called anytime *after* PrepOutput(), and may be interleaved with * calls to ComputeRecord(). The accum setting may be changed at any time. * Finally, it is possible to restart the output using ResetRow(), and * a zero argument will rewind to the beginning, whence all records * may be recalculated. The previous output rows are not zeroed or deleted, * but are overwritten as the calculation proceeds from the new starting point. * However, the output file(s) will indicate in the NROWS= line in the header - * that only the newly calculated rows are present. + * that only the newly calculated rows are present. If you wish to start over + * with a different set of modifiers or outputs, call ClearModifiers() instead, + * which keeps the current octree in memory. This call also returns to single + * process mode if any children were running. * * It is not possible to write to standard output, but the output * model is quite flexible thanks to the RdataShare polymorphic class. @@ -154,7 +155,7 @@ extern lut_free_t FreeRcMod; */ /// Output channel opening options: new/exclusive, overwrite if exists, or recover data -enum RCOutputOp {RCOnew, RCOforce, RCOrecover}; +enum RCOutputOp {RCOnew=0, RCOforce, RCOrecover}; /// Converts above to RdataShare open flags (may be adjusted by calling program) extern int RSDOflags[]; @@ -166,7 +167,8 @@ typedef RdataShare * RcreateDataShareF(const char *nam extern RcreateDataShareF defDataShare; /// Modifiable ray-tracing flags for rcontrib -#define RCmask (RTlimDist|RTimmIrrad) +#define RCcontrib (RTmask+1) // compute contributions? (r.t. coefficients) +#define RCmask (RTlimDist|RTimmIrrad|RCcontrib) /// rcontrib-like simulation manager (at most one such object) class RcontribSimulManager : protected RtraceSimulManager { @@ -190,6 +192,7 @@ class RcontribSimulManager : protected RtraceSimulMana public: RCOutputOp outOp; // output operation RcreateDataShareF * cdsF; // data share creator + int xres, yres; // output (picture) size uint32 accum; // # rays to accumulate per record RcontribSimulManager(const char *octn = NULL) : RtraceSimulManager(NULL, NULL, octn) { @@ -208,10 +211,11 @@ class RcontribSimulManager : protected RtraceSimulMana SetTraceCall(&RctCall, this); outOp = RCOnew; cdsF = &defDataShare; + xres = yres = 0; accum = 1; } ~RcontribSimulManager() { - Cleanup(); + if (nkids >= 0) ClearModifiers(); } /// Check modifiable ray-tracing computation flag(s) bool HasFlag(int fl) const { @@ -279,7 +283,7 @@ class RcontribSimulManager : protected RtraceSimulMana int PrepOutput(); /// Are we ready to compute some records? bool Ready() const { - return rowsDone.Length(); + return (rowsDone.Length() > 0) & (accum > 0); } /// Set number of computation threads (0 => #cores) int SetThreadCount(int nt = 0); @@ -304,8 +308,6 @@ class RcontribSimulManager : protected RtraceSimulMana return rowsDone.Length(); return nDone; } - /// Rewind calculation (previous results unchanged) - bool ResetRow(int r); /// Add a ray/bundle to compute next record (n=accum) int ComputeRecord(const FVECT orig_direc[]); /// Finish pending rays if multi-processing @@ -315,8 +317,10 @@ class RcontribSimulManager : protected RtraceSimulMana ; return true; } - /// Close octree, free data, return status - int Cleanup(bool everything = false) { + /// Rewind calculation (previous results unchanged) + bool ResetRow(int r); + /// Clear the modifiers and close all outputs + void ClearModifiers() { if (rowsDone.Length()) { SetThreadCount(1); cow_doneshare(); @@ -325,8 +329,14 @@ class RcontribSimulManager : protected RtraceSimulMana lu_done(&modLUT); delete outList; outList = NULL; nChan = 0; + } + /// Close octree, free data, return status + int Cleanup(bool everything = false) { + ClearModifiers(); return RtraceSimulManager::Cleanup(everything); } }; + +extern const char * formstr(int f); // string from format #endif /* RcontribSimulManager_h */