25 |
|
|
26 |
|
extern char RCCONTEXT[]; // global rcontrib context |
27 |
|
|
28 |
< |
extern int xres, yres; // global resolution settings |
28 |
> |
class RcontribSimulManager; // need forward decl |
29 |
|
|
30 |
– |
class RcontribSimulManager; // need forward decl |
31 |
– |
|
30 |
|
/// Shared data object for record output (includes header; may be write-only) |
31 |
|
class RcontribOutput { |
34 |
– |
protected: |
32 |
|
RcontribOutput * next; // next in sorted list |
33 |
|
char * ofname; // output file name |
34 |
|
uint32 rowCountPos; // row count position in header |
121 |
|
* |
122 |
|
* 1) Call LoadOctree(), then alter the header as desired |
123 |
|
* 2) Set number of spectral samples (NCSAMP) and call SetDataFormat() |
124 |
< |
* 3) Call AddModifier() and AddModFile() to indicate tracked modifiers |
125 |
< |
* 4) Set outOp and cdsF according to desired output/recovery |
126 |
< |
* 5) Call PrepOutput() to open output channels |
127 |
< |
* 6) Call SetThreadCount() to fork children if desired |
128 |
< |
* 7) Set accum to the number of ray samples per record |
129 |
< |
* 8) Call ComputeRecord() with accum ray samples |
130 |
< |
* 9) Continue until GetRowMax() records have been sent |
131 |
< |
* 10) Call Cleanup() |
124 |
> |
* 3) Set xres and yres to desired dimensions (xres>0 for picture output) |
125 |
> |
* 4) Call AddModifier() and AddModFile() to indicate tracked modifiers |
126 |
> |
* 5) Set outOp and cdsF according to desired output/recovery |
127 |
> |
* 6) Set desired computation flags via SetFlag() |
128 |
> |
* 7) Call PrepOutput() to open output channels |
129 |
> |
* 8) Call SetThreadCount() to fork children if desired |
130 |
> |
* 9) Set accum to the number of ray samples per record |
131 |
> |
* 10) Call ComputeRecord() with accum ray samples |
132 |
> |
* 11) Continue until GetRowMax() records have been sent |
133 |
> |
* 12) Call Cleanup() |
134 |
|
* |
135 |
|
* The order of some of these calls may be changed. Technically, the octree |
136 |
|
* may be loaded anytime before PrepOutput() is called. Also, SetThreadCount() |
137 |
< |
* may be called anytime after PrepOutput() and interleaved with |
137 |
> |
* may be called anytime *after* PrepOutput(), and may be interleaved with |
138 |
|
* calls to ComputeRecord(). The accum setting may be changed at any time. |
139 |
|
* Finally, it is possible to restart the output using ResetRow(), and |
140 |
|
* a zero argument will rewind to the beginning, whence all records |
141 |
|
* may be recalculated. The previous output rows are not zeroed or deleted, |
142 |
|
* but are overwritten as the calculation proceeds from the new starting point. |
143 |
|
* However, the output file(s) will indicate in the NROWS= line in the header |
144 |
< |
* that only the newly calculated rows are present. |
144 |
> |
* that only the newly calculated rows are present. If you wish to start over |
145 |
> |
* with a different set of modifiers or outputs, call ClearModifiers() instead, |
146 |
> |
* which keeps the current octree in memory. This call also returns to single |
147 |
> |
* process mode if any children were running. |
148 |
|
* |
149 |
|
* It is not possible to write to standard output, but the output |
150 |
|
* model is quite flexible thanks to the RdataShare polymorphic class. |
155 |
|
*/ |
156 |
|
|
157 |
|
/// Output channel opening options: new/exclusive, overwrite if exists, or recover data |
158 |
< |
enum RCOutputOp {RCOnew, RCOforce, RCOrecover}; |
158 |
> |
enum RCOutputOp {RCOnew=0, RCOforce, RCOrecover}; |
159 |
|
|
160 |
|
/// Converts above to RdataShare open flags (may be adjusted by calling program) |
161 |
|
extern int RSDOflags[]; |
166 |
|
/// Our default data share function |
167 |
|
extern RcreateDataShareF defDataShare; |
168 |
|
|
169 |
< |
/// Call-back used by GetOutputs() method (cd is client data) |
170 |
< |
typedef int RoutputShareF(const RcontribOutput *op, void *cd); |
169 |
> |
/// Modifiable ray-tracing flags for rcontrib |
170 |
> |
#define RCcontrib (RTmask+1) // compute contributions? (r.t. coefficients) |
171 |
> |
#define RCmask (RTlimDist|RTimmIrrad|RCcontrib) |
172 |
|
|
173 |
|
/// rcontrib-like simulation manager (at most one such object) |
174 |
|
class RcontribSimulManager : protected RtraceSimulManager { |
192 |
|
public: |
193 |
|
RCOutputOp outOp; // output operation |
194 |
|
RcreateDataShareF * cdsF; // data share creator |
195 |
+ |
int xres, yres; // output (picture) size |
196 |
|
uint32 accum; // # rays to accumulate per record |
197 |
|
RcontribSimulManager(const char *octn = NULL) |
198 |
|
: RtraceSimulManager(NULL, NULL, octn) { |
211 |
|
SetTraceCall(&RctCall, this); |
212 |
|
outOp = RCOnew; |
213 |
|
cdsF = &defDataShare; |
214 |
+ |
xres = yres = 0; |
215 |
|
accum = 1; |
216 |
|
} |
217 |
|
~RcontribSimulManager() { |
218 |
< |
Cleanup(); |
218 |
> |
if (nkids >= 0) ClearModifiers(); |
219 |
|
} |
220 |
+ |
/// Check modifiable ray-tracing computation flag(s) |
221 |
+ |
bool HasFlag(int fl) const { |
222 |
+ |
return ((rtFlags & RCmask & fl) != 0); |
223 |
+ |
} |
224 |
+ |
/// Set/reset modifiable ray-tracing computation flag(s) |
225 |
+ |
bool SetFlag(int fl, bool val = true) { |
226 |
+ |
if (!(fl &= RCmask)) return false; |
227 |
+ |
if (val) rtFlags |= fl; |
228 |
+ |
else rtFlags &= ~fl; |
229 |
+ |
return true; |
230 |
+ |
} |
231 |
|
/// Load octree and prepare renderer |
232 |
|
bool LoadOctree(const char *octn) { |
233 |
|
return RtraceSimulManager::LoadOctree(octn); |
271 |
|
bool AddModFile(const char *modfn, const char *outspec, |
272 |
|
const char *prms = NULL, |
273 |
|
const char *binval = NULL, int bincnt = 1); |
274 |
< |
/// Run through current list of output struct's |
275 |
< |
int GetOutputs(RoutputShareF *osF, void *cd = NULL) const; |
274 |
> |
/// Get named rcontrib output (or list) |
275 |
> |
const RcontribOutput * GetOutput(const char *nm = NULL) const { |
276 |
> |
if (!nm) return outList; |
277 |
> |
const RcontribOutput * op = outList; |
278 |
> |
while (op && strcmp(op->GetName(), nm)) |
279 |
> |
op = op->next; |
280 |
> |
return op; |
281 |
> |
} |
282 |
|
/// Open output channels and return # completed rows |
283 |
|
int PrepOutput(); |
284 |
|
/// Are we ready to compute some records? |
285 |
|
bool Ready() const { |
286 |
< |
return rowsDone.Length(); |
286 |
> |
return (rowsDone.Length() > 0) & (accum > 0); |
287 |
|
} |
288 |
|
/// Set number of computation threads (0 => #cores) |
289 |
|
int SetThreadCount(int nt = 0); |
308 |
|
return rowsDone.Length(); |
309 |
|
return nDone; |
310 |
|
} |
289 |
– |
/// Rewind calculation (previous results unchanged) |
290 |
– |
bool ResetRow(int r); |
311 |
|
/// Add a ray/bundle to compute next record (n=accum) |
312 |
|
int ComputeRecord(const FVECT orig_direc[]); |
313 |
|
/// Finish pending rays if multi-processing |
317 |
|
; |
318 |
|
return true; |
319 |
|
} |
320 |
< |
/// Close octree, free data, return status |
321 |
< |
int Cleanup(bool everything = false) { |
320 |
> |
/// Rewind calculation (previous results unchanged) |
321 |
> |
bool ResetRow(int r); |
322 |
> |
/// Clear the modifiers and close all outputs |
323 |
> |
void ClearModifiers() { |
324 |
|
if (rowsDone.Length()) { |
325 |
|
SetThreadCount(1); |
326 |
|
cow_doneshare(); |
329 |
|
lu_done(&modLUT); |
330 |
|
delete outList; outList = NULL; |
331 |
|
nChan = 0; |
332 |
+ |
} |
333 |
+ |
/// Close octree, free data, return status |
334 |
+ |
int Cleanup(bool everything = false) { |
335 |
+ |
ClearModifiers(); |
336 |
|
return RtraceSimulManager::Cleanup(everything); |
337 |
|
} |
338 |
|
}; |