--- ray/src/rt/RcontribSimulManager.h 2024/11/01 23:05:01 2.4 +++ ray/src/rt/RcontribSimulManager.h 2025/01/02 16:16:49 2.10 @@ -1,4 +1,4 @@ -/* RCSid $Id: RcontribSimulManager.h,v 2.4 2024/11/01 23:05:01 greg Exp $ */ +/* RCSid $Id: RcontribSimulManager.h,v 2.10 2025/01/02 16:16:49 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. @@ -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) { @@ -204,14 +207,18 @@ class RcontribSimulManager : protected RtraceSimulMana modLUT.freek = efree; modLUT.freed = FreeRcMod; kid = NULL; kidRow = NULL; nkids = 0; - rtFlags = RTtraceSources; - SetTraceCall(&RctCall, this); outOp = RCOnew; cdsF = &defDataShare; + xres = yres = 0; accum = 1; + if (octname) { + SetTraceCall(&RctCall, this); + rtFlags |= RTtraceSources; + UpdateMode(); + } } ~RcontribSimulManager() { - Cleanup(); + if (nkids >= 0) ClearModifiers(); } /// Check modifiable ray-tracing computation flag(s) bool HasFlag(int fl) const { @@ -226,7 +233,12 @@ class RcontribSimulManager : protected RtraceSimulMana } /// Load octree and prepare renderer bool LoadOctree(const char *octn) { - return RtraceSimulManager::LoadOctree(octn); + if (octname) Cleanup(false); + if (!RtraceSimulManager::LoadOctree(octn)) + return false; + SetTraceCall(&RctCall, this); + rtFlags |= RTtraceSources; + return UpdateMode(); } /// Prepare header from previous input (or clear) bool NewHeader(const char *inspec=NULL) { @@ -304,8 +316,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,18 +325,35 @@ 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(); rowsDone.NewBitMap(0); + rInPos = 0; } lu_done(&modLUT); delete outList; outList = NULL; nChan = 0; + } + /// Close octree, free data, return status + int Cleanup(bool everything = false) { + ClearModifiers(); + cow_doneshare(); + if (everything) { + dtyp = 'f'; + outOp = RCOnew; + cdsF = &defDataShare; + xres = yres = 0; + accum = 1; + rtFlags &= ~RCmask; + } return RtraceSimulManager::Cleanup(everything); } }; + +extern const char * formstr(int f); // string from format #endif /* RcontribSimulManager_h */