Field3D
FieldSampler< WrapperVec_T, Dims_T > Struct Template Reference

Interface for sampling a vector of fields of the same type. More...

#include <FieldSampler.h>

Public Types

typedef Field_T::value_type Data_T
 
typedef WrapperVec_T::value_type::field_type Field_T
 
typedef detail::ScalarOrVector< Dims_T >::type Input_T
 
enum  Mode { Min , Max }
 

Static Public Member Functions

static void getMinMax (const WrapperVec_T &f, const Box3d &wsBounds, float *min, float *max)
 
static void getMinMaxMIP (const WrapperVec_T &f, const Box3d &wsBounds, float *min, float *max)
 
static void getMinMaxPrefilt (const WrapperVec_T &f, const Box3d &wsBounds, float *result, const Mode mode)
 
static void sample (const WrapperVec_T &f, const V3d &wsP, float *value, size_t &numHits)
 
static void sampleMIP (const WrapperVec_T &f, const V3d &wsP, const float wsSpotSize, float *value, size_t &numHits)
 
static void sampleMIPMultiple (const WrapperVec_T &f, const size_t neval, const float *wsPs, const float *wsSpotSizes, float *value, size_t *numHits)
 
static void sampleMultiple (const WrapperVec_T &f, const size_t neval, const float *wsPs, float *value, size_t *numHits)
 

Detailed Description

template<typename WrapperVec_T, int Dims_T>
struct FieldSampler< WrapperVec_T, Dims_T >

Interface for sampling a vector of fields of the same type.

Definition at line 81 of file FieldSampler.h.

Member Typedef Documentation

◆ Field_T

template<typename WrapperVec_T , int Dims_T>
typedef WrapperVec_T::value_type::field_type FieldSampler< WrapperVec_T, Dims_T >::Field_T

Definition at line 88 of file FieldSampler.h.

◆ Data_T

template<typename WrapperVec_T , int Dims_T>
typedef Field_T::value_type FieldSampler< WrapperVec_T, Dims_T >::Data_T

Definition at line 89 of file FieldSampler.h.

◆ Input_T

Definition at line 90 of file FieldSampler.h.

Member Enumeration Documentation

◆ Mode

Enumerator
Min 
Max 

Definition at line 83 of file FieldSampler.h.

83 {
84 Min,
85 Max
86 };

Member Function Documentation

◆ sample()

template<typename WrapperVec_T , int Dims_T>
static void FieldSampler< WrapperVec_T, Dims_T >::sample ( const WrapperVec_T & f,
const V3d & wsP,
float * value,
size_t & numHits )
inlinestatic

Definition at line 93 of file FieldSampler.h.

95 {
96 // Reinterpret the pointer according to Dims_T
97 Input_T *data = reinterpret_cast<Input_T*>(value);
98 // Loop over fields in vector
99 for (size_t i = 0, end = f.size(); i < end; ++i) {
100 V3d vsP;
101 // Apply world to object transform
102 if (f[i].doOsToWs) {
103 V3d osP;
104 f[i].wsToOs.multVecMatrix(wsP, osP);
105 f[i].mapping->worldToVoxel(osP, vsP);
106 } else {
107 f[i].mapping->worldToVoxel(wsP, vsP);
108 }
109 // Sample
110 if (f[i].vsBounds.intersects(vsP)) {
111 // Count as within field
112 numHits++;
113 // Sample and remap
114 if (f[i].valueRemapOp) {
115 const Data_T unremapped = f[i].interp.sample(*f[i].field, vsP);
116 *data += f[i].valueRemapOp->remap(unremapped);
117 } else {
118 *data += f[i].interp.sample(*f[i].field, vsP);
119 }
120 }
121 }
122 }
Imath::V3d V3d
Definition SpiMathLib.h:74
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
detail::ScalarOrVector< Dims_T >::type Input_T
Field_T::value_type Data_T

References FIELD3D_MTX_T.

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::Sample::operator()().

◆ sampleMultiple()

template<typename WrapperVec_T , int Dims_T>
static void FieldSampler< WrapperVec_T, Dims_T >::sampleMultiple ( const WrapperVec_T & f,
const size_t neval,
const float * wsPs,
float * value,
size_t * numHits )
inlinestatic

Definition at line 125 of file FieldSampler.h.

127 {
128 // Loop over fields in vector
129 for (size_t i = 0; i < f.size(); ++i) {
130 const typename WrapperVec_T::value_type &field = f[i];
131
132 // Reinterpret the pointer according to Dims_T
133 Input_T *data = reinterpret_cast<Input_T*>(value);
134
135 if (field.doOsToWs || field.valueRemapOp) {
136
137 // Loop over samples
138 for (size_t ieval = 0; ieval < neval; ++ieval) {
139 const V3d wsP(*reinterpret_cast<const V3f*>(wsPs + 3 * ieval));
140 V3d vsP;
141 // Apply world to object transform
142 if (field.doOsToWs) {
143 V3d osP;
144 field.wsToOs.multVecMatrix(wsP, osP);
145 field.mapping->worldToVoxel(osP, vsP);
146 } else {
147 field.mapping->worldToVoxel(wsP, vsP);
148 }
149 // Sample
150 if (field.vsBounds.intersects(vsP)) {
151 // Count as within field
152 numHits[ieval]++;
153 // Sample and remap
154 if (field.valueRemapOp) {
155 const Data_T unremapped = field.interp.sample(*field.field, vsP);
156 data[ieval] += field.valueRemapOp->remap(unremapped);
157 } else {
158 data[ieval] += field.interp.sample(*field.field, vsP);
159 }
160 }
161 }
162
163 } else {
164
165 const Imath::Box3d &vsBounds_d = field.vsBounds;
166
167 // Loop over samples
168 for (size_t ieval = 0; ieval < neval; ++ieval) {
169 const V3d wsP(*reinterpret_cast<const V3f*>(wsPs + 3 * ieval));
170 V3d vsP;
171
172 // Apply world to object transform
173 field.mapping->worldToVoxel(wsP, vsP);
174
175 // Sample
176 if (vsBounds_d.intersects(vsP)) {
177 // Count as within field
178 numHits[ieval]++;
179 // Sample
180 data[ieval] += field.interp.sample(*field.field, vsP);
181 }
182 }
183 }
184 }
185 }
Imath::V3f V3f
Definition SpiMathLib.h:73

References FIELD3D_MTX_T.

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::SampleMultiple::operator()().

◆ sampleMIP()

template<typename WrapperVec_T , int Dims_T>
static void FieldSampler< WrapperVec_T, Dims_T >::sampleMIP ( const WrapperVec_T & f,
const V3d & wsP,
const float wsSpotSize,
float * value,
size_t & numHits )
inlinestatic

Definition at line 188 of file FieldSampler.h.

190 {
191 // Reinterpret the pointer according to Dims_T
192 Input_T *data = reinterpret_cast<Input_T*>(value);
193 // Loop over fields in vector
194 for (size_t i = 0, end = f.size(); i < end; ++i) {
195 V3d vsP;
196 float spotSize = wsSpotSize / f[i].worldScale;
197 // Apply world to object transform
198 if (f[i].doOsToWs) {
199 V3d osP;
200 f[i].wsToOs.multVecMatrix(wsP, osP);
201 f[i].mapping->worldToVoxel(osP, vsP);
202 spotSize = wsSpotSize / f[i].worldScale;
203 } else {
204 f[i].mapping->worldToVoxel(wsP, vsP);
205 }
206 // Sample
207 if (f[i].vsBounds.intersects(vsP)) {
208 // Count as within field
209 numHits++;
210 // Sample and remap
211 if (f[i].valueRemapOp) {
212 const Data_T unremapped = f[i].interp->sample(vsP, spotSize);
213 *data += f[i].valueRemapOp->remap(unremapped);
214 } else {
215 *data += f[i].interp->sample(vsP, spotSize);
216 }
217 }
218 }
219 }

References FIELD3D_MTX_T.

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::SampleMIP::operator()().

◆ sampleMIPMultiple()

template<typename WrapperVec_T , int Dims_T>
static void FieldSampler< WrapperVec_T, Dims_T >::sampleMIPMultiple ( const WrapperVec_T & f,
const size_t neval,
const float * wsPs,
const float * wsSpotSizes,
float * value,
size_t * numHits )
inlinestatic

Definition at line 222 of file FieldSampler.h.

225 {
226 // Loop over fields in vector
227 for (size_t i = 0; i < f.size(); ++i) {
228 const typename WrapperVec_T::value_type &field = f[i];
229
230 // Reinterpret the pointer according to Dims_T
231 Input_T *data = reinterpret_cast<Input_T*>(value);
232
233 if (field.doOsToWs || field.valueRemapOp) {
234
235 if (field.valueRemapOp && field.doWsBoundsOptimization) {
236
237 // Loop over samples
238 for (size_t ieval = 0; ieval < neval; ++ieval) {
239 const V3f &wsP = *reinterpret_cast<const V3f*>(wsPs + 3 * ieval);
240
241 if (field.wsBounds.intersects(wsP)) {
242
243 // Apply world to object transform
244 V3d vsP;
245
246 field.wsToVs.multVecMatrix(V3d(wsP), vsP);
247
248 // Sample
249 if (field.vsBounds.intersects(vsP)) {
250 // Count as within field
251 numHits[ieval]++;
252 const float spotSize = wsSpotSizes[ieval] / field.worldScale;
253 const Data_T unremapped = field.interp->sample(vsP, spotSize);
254 data[ieval] += field.valueRemapOp->remap(unremapped);
255 }
256 }
257 }
258
259 } else {
260 // Loop over samples
261 for (size_t ieval = 0; ieval < neval; ++ieval) {
262 const V3d wsP(*reinterpret_cast<const V3f*>(wsPs + 3 * ieval));
263 const float wsSpotSize = wsSpotSizes[ieval];
264 Input_T *idata = data + ieval;
265
266 V3d vsP;
267 float spotSize = wsSpotSize / field.worldScale;
268 // Apply world to object transform
269 if (field.doOsToWs) {
270 V3d osP;
271
272 field.wsToOs.multVecMatrix(wsP, osP);
273 field.mapping->worldToVoxel(osP, vsP);
274 spotSize = wsSpotSize / field.worldScale;
275 } else {
276 field.mapping->worldToVoxel(wsP, vsP);
277 }
278 // Sample
279 if (field.vsBounds.intersects(vsP)) {
280 // Count as within field
281 numHits[ieval]++;
282 if (field.valueRemapOp) {
283 const Data_T unremapped = field.interp->sample(vsP, spotSize);
284 *idata += field.valueRemapOp->remap(unremapped);
285 } else {
286 *idata += field.interp->sample(vsP, spotSize);
287 }
288 }
289 }
290 }
291 } else {
292
293 const Imath::Box3d &vsBounds_d = field.vsBounds;
294 const double worldScale = field.worldScale;
295
296 // Loop over samples
297 for (size_t ieval = 0; ieval < neval; ++ieval) {
298 const V3d wsP(*reinterpret_cast<const V3f*>(wsPs + 3 * ieval));
299 V3d vsP;
300
301 // Apply world to object transform
302 field.mapping->worldToVoxel(wsP, vsP);
303
304 // Sample
305 if (vsBounds_d.intersects(vsP)) {
306 // Count as within field
307 numHits[ieval]++;
308 const double spotSize = wsSpotSizes[ieval] / worldScale;
309
310 data[ieval] += field.interp->sample(vsP, spotSize);
311 }
312 }
313 }
314 }
315 }

References FIELD3D_MTX_T.

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::SampleMIPMultiple::operator()().

◆ getMinMax()

template<typename WrapperVec_T , int Dims_T>
static void FieldSampler< WrapperVec_T, Dims_T >::getMinMax ( const WrapperVec_T & f,
const Box3d & wsBounds,
float * min,
float * max )
inlinestatic

Definition at line 318 of file FieldSampler.h.

320 {
321 // Reinterpret the pointer according to Dims_T
322 Input_T *minData = reinterpret_cast<Input_T*>(min);
323 Input_T *maxData = reinterpret_cast<Input_T*>(max);
324 // Loop over fields in vector
325 for (size_t field = 0, end = f.size(); field < end; ++field) {
326 // Data window
327 const Box3i dw = f[field].field->dataWindow();
328 // Transform corners to voxel space and compute bounds
330 if (wsBounds.isInfinite()) {
331 dvsBounds = dw;
332 } else {
333 Box3d vsBounds;
334 if (f[field].doOsToWs) {
336 transformBounds(f[field].wsToOs, wsBounds, osBounds);
337 worldToVoxel(f[field].mapping, osBounds, vsBounds);
338 } else {
339 worldToVoxel(f[field].mapping, wsBounds, vsBounds);
340 }
342 // Early termination if no intersection
343 if (!dw.intersects(dvsBounds)) {
344 return;
345 }
346 }
347 for (int k = dvsBounds.min.z; k <= dvsBounds.max.z; ++k) {
348 for (int j = dvsBounds.min.y; j <= dvsBounds.max.y; ++j) {
349 for (int i = dvsBounds.min.x; i <= dvsBounds.max.x; ++i) {
350 const Data_T val = f[field].field->fastValue(i, j, k);
353 }
354 }
355 }
356 }
357 }
void worldToVoxel(const Field3D::FieldMapping *mapping, const Box3d &wsBounds, Box3d &vsBounds)
Computes a voxel space bounds given a bounding box in world space. This is done by transforming each ...
void transformBounds(const M44d &mtx, const Box3d &fromBounds, Box3d &toBounds)
Transforms a bounding box by a 4x4 matrix This is done by transforming each corner vertex from world ...
Box3i discreteBounds(const Box3d &bbox)
Converts a floating point bounding box to an integer bounding box.
Definition Field.h:1128
Box3i clipBounds(const Box3i &bbox, const Box3i &bounds)
Definition Field.h:1145
Imath::Box3d Box3d
Definition SpiMathLib.h:79
Imath::Box3i Box3i
Definition SpiMathLib.h:77
T max(const T a, const T2 b)
Max operation on mixed types.
T min(const T a, const T2 b)
Min operation on mixed types.

References clipBounds(), discreteBounds(), FIELD3D_MTX_T, detail::max(), detail::min(), transformBounds(), and worldToVoxel().

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::GetMinMax::operator()().

◆ getMinMaxMIP()

template<typename WrapperVec_T , int Dims_T>
static void FieldSampler< WrapperVec_T, Dims_T >::getMinMaxMIP ( const WrapperVec_T & f,
const Box3d & wsBounds,
float * min,
float * max )
inlinestatic

Definition at line 360 of file FieldSampler.h.

362 {
363 // Reinterpret the pointer according to Dims_T
364 Input_T *minData = reinterpret_cast<Input_T*>(min);
365 Input_T *maxData = reinterpret_cast<Input_T*>(max);
366 // Loop over fields in vector
367 for (size_t field = 0, end = f.size(); field < end; ++field) {
368 // Data window
369 const Box3i dw = f[field].field->dataWindow();
370 // Transform corners to voxel space and compute bounds
372 if (wsBounds.isInfinite()) {
373 dvsBounds = dw;
374 } else {
375 Box3d vsBounds;
376 if (f[field].doOsToWs) {
378 transformBounds(f[field].wsToOs, wsBounds, osBounds);
379 worldToVoxel(f[field].mapping, osBounds, vsBounds);
380 } else {
381 worldToVoxel(f[field].mapping, wsBounds, vsBounds);
382 }
384 // Early termination if no intersection
385 if (!dw.intersects(dvsBounds)) {
386 return;
387 }
388 }
389 for (int k = dvsBounds.min.z; k <= dvsBounds.max.z; ++k) {
390 for (int j = dvsBounds.min.y; j <= dvsBounds.max.y; ++j) {
391 for (int i = dvsBounds.min.x; i <= dvsBounds.max.x; ++i) {
392 const Data_T val = f[field].field->fastMipValue(0, i, j, k);
395 }
396 }
397 }
398 }
399 }

References clipBounds(), discreteBounds(), FIELD3D_MTX_T, detail::max(), detail::min(), transformBounds(), and worldToVoxel().

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::GetMinMaxMIP::operator()().

◆ getMinMaxPrefilt()

template<typename WrapperVec_T , int Dims_T>
static void FieldSampler< WrapperVec_T, Dims_T >::getMinMaxPrefilt ( const WrapperVec_T & f,
const Box3d & wsBounds,
float * result,
const Mode mode )
inlinestatic

Definition at line 402 of file FieldSampler.h.

406 {
407 // Reinterpret the pointer according to Dims_T
408 Input_T *data = reinterpret_cast<Input_T*>(result);
409 // Loop over fields in vector
410 for (size_t field = 0, end = f.size(); field < end; ++field) {
411 // Choose the MIP level to check
412 const size_t numLevels = f[field].field->numLevels();
413 size_t level = 0;
415 // Infinite bounds?
416 if (wsBounds.isInfinite()) {
417 // Use the coarsest level
418 level = numLevels - 1;
419 dvsBounds = f[field].field->mipLevel(level)->dataWindow();
420 } else {
421 for (size_t i = 0; i < numLevels; ++i) {
422 // Update current level
423 level = i;
424 // Data window of current level
425 const Box3i dw = f[field].field->mipLevel(level)->dataWindow();
426 Box3d vsBounds;
427 if (f[field].doOsToWs) {
429 transformBounds(f[field].wsToOs, wsBounds, osBounds);
430 worldToVoxel(f[field].field->mipLevel(level)->mapping().get(),
431 osBounds, vsBounds);
432 } else {
433 worldToVoxel(f[field].field->mipLevel(level)->mapping().get(),
434 wsBounds, vsBounds);
435 }
437 // If size of dvsBounds is <= 2, stop
438 Imath::V3i size = dvsBounds.size();
439 if (std::max(size.x, std::max(size.y, size.z)) <= 2) {
440 break;
441 }
442 }
443 }
444 // Level chosen. Run loop
445 for (int k = dvsBounds.min.z; k <= dvsBounds.max.z; ++k) {
446 for (int j = dvsBounds.min.y; j <= dvsBounds.max.y; ++j) {
447 for (int i = dvsBounds.min.x; i <= dvsBounds.max.x; ++i) {
448 const Data_T val = f[field].field->fastMipValue(level, i, j, k);
449 if (mode == Min) {
450 *data = detail::min(val, *data);
451 } else {
452 *data = detail::max(val, *data);
453 }
454 }
455 }
456 }
457 }
458 }

References clipBounds(), discreteBounds(), FIELD3D_MTX_T, detail::max(), detail::min(), FieldSampler< WrapperVec_T, Dims_T >::Min, transformBounds(), and worldToVoxel().

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::GetMinMaxPrefilt::operator()().


The documentation for this struct was generated from the following file: