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

template<typename WrapperVec_T, int Dims_T>

typedef detail::ScalarOrVector<Dims_T>::type FieldSampler< WrapperVec_T, Dims_T >::Input_T

Definition at line 90 of file FieldSampler.h.

## Member Enumeration Documentation

## Mode

template<typename WrapperVec_T, int Dims_T>

enum FieldSampler::Mode

Enumerator
Min |
Max |

Definition at line 83 of file FieldSampler.h.

{
Min,
Max
};
FieldSampler::Max
@ Max
Definition FieldSampler.h:85
FieldSampler::Min
@ Min
Definition FieldSampler.h:84

## Member Function Documentation

## sample()

template<typename WrapperVec_T, int Dims_T>

void FieldSampler< WrapperVec_T, Dims_T >::sample | ( | const WrapperVec_T & | f,
|  | const V3d & | wsP,
|  | float * | value,
|  | size_t & | numHits )

inline static

Definition at line 93 of file FieldSampler.h.

{
// Reinterpret the pointer according to Dims_T
Input_T *data = reinterpret_cast<Input_T*>(value);
// Loop over fields in vector
for (size_t i = 0, end = f.size(); i < end; ++i) {
V3d vsP;
// Apply world to object transform
if (f[i].doOsToWs) {
V3d osP;
f[i].wsToOs.multVecMatrix(wsP, osP);
f[i].mapping->worldToVoxel(osP, vsP);
} else {
f[i].mapping->worldToVoxel(wsP, vsP);
}
// Sample
if (f[i].vsBounds.intersects(vsP)) {
// Count as within field
numHits++;
// Sample and remap
if (f[i].valueRemapOp) {
const Data_T unremapped = f[i].interp.sample(*f[i].field, vsP);
*data += f[i].valueRemapOp->remap(unremapped);
} else {
*data += f[i].interp.sample(*f[i].field, vsP);
}
}
}
}
FieldSampler
Interface for sampling a vector of fields of the same type.
Definition FieldSampler.h:82
FieldSampler::Input_T
detail::ScalarOrVector< Dims_T >::type Input_T
Definition FieldSampler.h:90
FieldSampler::sample
static void sample(const WrapperVec_T &f, const V3d &wsP, float *value, size_t &numHits)
Definition FieldSampler.h:93
FieldSampler::Data_T
Field_T::value_type Data_T
Definition FieldSampler.h:89

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

## sampleMultiple()

template<typename WrapperVec_T, int Dims_T>

void FieldSampler< WrapperVec_T, Dims_T >::sampleMultiple | ( | const WrapperVec_T & | f,
|  | const size_t | neval,
|  | const float * | wsPs,
|  | float * | value,
|  | size_t * | numHits )

inline static

Definition at line 125 of file FieldSampler.h.

{
// Loop over fields in vector
for (size_t i = 0; i < f.size(); ++i) {
const typename WrapperVec_T::value_type &field = f[i];
// Reinterpret the pointer according to Dims_T
Input_T *data = reinterpret_cast<Input_T*>(value);
if (field.doOsToWs || field.valueRemapOp) {
// Loop over samples
for (size_t ieval = 0; ieval < neval; ++ieval) {
const V3d wsP(*reinterpret_cast<const V3f*>(wsPs + 3 * ieval));
V3d vsP;
// Apply world to object transform
if (field.doOsToWs) {
V3d osP;
field.wsToOs.multVecMatrix(wsP, osP);
field.mapping->worldToVoxel(osP, vsP);
} else {
field.mapping->worldToVoxel(wsP, vsP);
}
// Sample
if (field.vsBounds.intersects(vsP)) {
// Count as within field
numHits[ieval]++;
// Sample and remap
if (field.valueRemapOp) {
const Data_T unremapped = field.interp.sample(*field.field, vsP);
data[ieval] += field.valueRemapOp->remap(unremapped);
} else {
data[ieval] += field.interp.sample(*field.field, vsP);
}
}
}
} else {
const Imath::Box3d &vsBounds_d = field.vsBounds;
// Loop over samples
for (size_t ieval = 0; ieval < neval; ++ieval) {
const V3d wsP(*reinterpret_cast<const V3f*>(wsPs + 3 * ieval));
V3d vsP;
// Apply world to object transform
field.mapping->worldToVoxel(wsP, vsP);
// Sample
if (vsBounds_d.intersects(vsP)) {
// Count as within field
numHits[ieval]++;
// Sample
data[ieval] += field.interp.sample(*field.field, vsP);
}
}
}
}
}

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

## sampleMIP()

template<typename WrapperVec_T, int Dims_T>

void FieldSampler< WrapperVec_T, Dims_T >::sampleMIP | ( | const WrapperVec_T & | f,
|  | const V3d & | wsP,
|  | const float | wsSpotSize,
|  | float * | value,
|  | size_t & | numHits )

inline static

Definition at line 188 of file FieldSampler.h.

{
// Reinterpret the pointer according to Dims_T
Input_T *data = reinterpret_cast<Input_T*>(value);
// Loop over fields in vector
for (size_t i = 0, end = f.size(); i < end; ++i) {
V3d vsP;
float spotSize = wsSpotSize / f[i].worldScale;
// Apply world to object transform
if (f[i].doOsToWs) {
V3d osP;
f[i].wsToOs.multVecMatrix(wsP, osP);
f[i].mapping->worldToVoxel(osP, vsP);
spotSize = wsSpotSize / f[i].worldScale;
} else {
f[i].mapping->worldToVoxel(wsP, vsP);
}
// Sample
if (f[i].vsBounds.intersects(vsP)) {
// Count as within field
numHits++;
// Sample and remap
if (f[i].valueRemapOp) {
const Data_T unremapped = f[i].interp->sample(vsP, spotSize);
*data += f[i].valueRemapOp->remap(unremapped);
} else {
*data += f[i].interp->sample(vsP, spotSize);
}
}
}
}

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

## sampleMIPMultiple()

template<typename WrapperVec_T, int Dims_T>

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 )

inline static

Definition at line 222 of file FieldSampler.h.

{
// Loop over fields in vector
for (size_t i = 0; i < f.size(); ++i) {
const typename WrapperVec_T::value_type &field = f[i];
// Reinterpret the pointer according to Dims_T
Input_T *data = reinterpret_cast<Input_T*>(value);
if (field.doOsToWs || field.valueRemapOp) {
if (field.valueRemapOp && field.doWsBoundsOptimization) {
// Loop over samples
for (size_t ieval = 0; ieval < neval; ++ieval) {
const V3f &wsP = *reinterpret_cast<const V3f*>(wsPs + 3 * ieval);
if (field.wsBounds.intersects(wsP)) {
// Apply world to object transform
V3d vsP;
field.wsToVs.multVecMatrix(V3d(wsP), vsP);
// Sample
if (field.vsBounds.intersects(vsP)) {
// Count as within field
numHits[ieval]++;
const float spotSize = wsSpotSizes[ieval] / field.worldScale;
const Data_T unremapped = field.interp->sample(vsP, spotSize);
data[ieval] += field.valueRemapOp->remap(unremapped);
}
}
}
} else {
// Loop over samples
for (size_t ieval = 0; ieval < neval; ++ieval) {
const V3d wsP(*reinterpret_cast<const V3f*>(wsPs + 3 * ieval));
const float wsSpotSize = wsSpotSizes[ieval];
Input_T *idata = data + ieval;
V3d vsP;
float spotSize = wsSpotSize / field.worldScale;
// Apply world to object transform
if (field.doOsToWs) {
V3d osP;
field.wsToOs.multVecMatrix(wsP, osP);
field.mapping->worldToVoxel(osP, vsP);
spotSize = wsSpotSize / field.worldScale;
} else {
field.mapping->worldToVoxel(wsP, vsP);
}
// Sample
if (field.vsBounds.intersects(vsP)) {
// Count as within field
numHits[ieval]++;
if (field.valueRemapOp) {
const Data_T unremapped = field.interp->sample(vsP, spotSize);
*idata += field.valueRemapOp->remap(unremapped);
} else {
*idata += field.interp->sample(vsP, spotSize);
}
}
}
}
} else {
const Imath::Box3d &vsBounds_d = field.vsBounds;
const double worldScale = field.worldScale;
// Loop over samples
for (size_t ieval = 0; ieval < neval; ++ieval) {
const V3d wsP(*reinterpret_cast<const V3f*>(wsPs + 3 * ieval));
V3d vsP;
// Apply world to object transform
field.mapping->worldToVoxel(wsP, vsP);
// Sample
if (vsBounds_d.intersects(vsP)) {
// Count as within field
numHits[ieval]++;
const double spotSize = wsSpotSizes[ieval] / worldScale;
data[ieval] += field.interp->sample(vsP, spotSize);
}
}
}
}
}
V3d
Imath::V3d V3d
Definition SpiMathLib.h:74

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

## getMinMax()

template<typename WrapperVec_T, int Dims_T>

void FieldSampler< WrapperVec_T, Dims_T >::getMinMax | ( | const WrapperVec_T & | f,
|  | const Box3d & | wsBounds,
|  | float * | min,
|  | float * | max )

inline static

Definition at line 318 of file FieldSampler.h.

{
// Reinterpret the pointer according to Dims_T
Input_T *minData = reinterpret_cast<Input_T*>(min);
Input_T *maxData = reinterpret_cast<Input_T*>(max);
// Loop over fields in vector
for (size_t field = 0, end = f.size(); field < end; ++field) {
// Data window
const Box3i dw = f[field].field->dataWindow();
// Transform corners to voxel space and compute bounds
Box3i dvsBounds;
if (wsBounds.isInfinite()) {
dvsBounds = dw;
} else {
Box3d vsBounds;
if (f[field].doOsToWs) {
Box3d osBounds;
transformBounds(f[field].wsToOs, wsBounds, osBounds);
worldToVoxel(f[field].mapping, osBounds, vsBounds);
} else {
worldToVoxel(f[field].mapping, wsBounds, vsBounds);
}
dvsBounds = clipBounds(discreteBounds(vsBounds), dw);
// Early termination if no intersection
if (!dw.intersects(dvsBounds)) {
return;
}
}
for (int k = dvsBounds.min.z; k <= dvsBounds.max.z; ++k) {
for (int j = dvsBounds.min.y; j <= dvsBounds.max.y; ++j) {
for (int i = dvsBounds.min.x; i <= dvsBounds.max.x; ++i) {
const Data_T val = f[field].field->fastValue(i, j, k);
*minData = detail::min(val, *minData);
*maxData = detail::max(val, *maxData);
}
}
}
}
}
worldToVoxel
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 ...
Definition FieldMapping.cpp:173
transformBounds
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 ...
Definition FieldMapping.cpp:200
discreteBounds
Box3i discreteBounds(const Box3d &bbox)
Converts a floating point bounding box to an integer bounding box.
Definition Field.h:1128
clipBounds
Box3i clipBounds(const Box3i &bbox, const Box3i &bounds)
Definition Field.h:1145
detail::max
T max(const T a, const T2 b)
Max operation on mixed types.
Definition FieldSampler.h:32
detail::min
T min(const T a, const T2 b)
Min operation on mixed types.
Definition FieldSampler.h:25

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

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

## getMinMaxMIP()

template<typename WrapperVec_T, int Dims_T>

void FieldSampler< WrapperVec_T, Dims_T >::getMinMaxMIP | ( | const WrapperVec_T & | f,
|  | const Box3d & | wsBounds,
|  | float * | min,
|  | float * | max )

inline static

Definition at line 360 of file FieldSampler.h.

{
// Reinterpret the pointer according to Dims_T
Input_T *minData = reinterpret_cast<Input_T*>(min);
Input_T *maxData = reinterpret_cast<Input_T*>(max);
// Loop over fields in vector
for (size_t field = 0, end = f.size(); field < end; ++field) {
// Data window
const Box3i dw = f[field].field->dataWindow();
// Transform corners to voxel space and compute bounds
Box3i dvsBounds;
if (wsBounds.isInfinite()) {
dvsBounds = dw;
} else {
Box3d vsBounds;
if (f[field].doOsToWs) {
Box3d osBounds;
transformBounds(f[field].wsToOs, wsBounds, osBounds);
worldToVoxel(f[field].mapping, osBounds, vsBounds);
} else {
worldToVoxel(f[field].mapping, wsBounds, vsBounds);
}
dvsBounds = clipBounds(discreteBounds(vsBounds), dw);
// Early termination if no intersection
if (!dw.intersects(dvsBounds)) {
return;
}
}
for (int k = dvsBounds.min.z; k <= dvsBounds.max.z; ++k) {
for (int j = dvsBounds.min.y; j <= dvsBounds.max.y; ++j) {
for (int i = dvsBounds.min.x; i <= dvsBounds.max.x; ++i) {
const Data_T val = f[field].field->fastMipValue(0, i, j, k);
*minData = detail::min(val, *minData);
*maxData = detail::max(val, *maxData);
}
}
}
}
}

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

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

## getMinMaxPrefilt()

template<typename WrapperVec_T, int Dims_T>

void FieldSampler< WrapperVec_T, Dims_T >::getMinMaxPrefilt | ( | const WrapperVec_T & | f,
|  | const Box3d & | wsBounds,
|  | float * | result,
|  | const Mode | mode )

inline static

Definition at line 402 of file FieldSampler.h.

{
// Reinterpret the pointer according to Dims_T
Input_T *data = reinterpret_cast<Input_T*>(result);
// Loop over fields in vector
for (size_t field = 0, end = f.size(); field < end; ++field) {
// Choose the MIP level to check
const size_t numLevels = f[field].field->numLevels();
size_t level = 0;
Box3i dvsBounds;
// Infinite bounds?
if (wsBounds.isInfinite()) {
// Use the coarsest level
level = numLevels - 1;
dvsBounds = f[field].field->mipLevel(level)->dataWindow();
} else {
for (size_t i = 0; i < numLevels; ++i) {
// Update current level
level = i;
// Data window of current level
const Box3i dw = f[field].field->mipLevel(level)->dataWindow();
Box3d vsBounds;
if (f[field].doOsToWs) {
Box3d osBounds;
transformBounds(f[field].wsToOs, wsBounds, osBounds);
worldToVoxel(f[field].field->mipLevel(level)->mapping().get(),
osBounds, vsBounds);
} else {
worldToVoxel(f[field].field->mipLevel(level)->mapping().get(),
wsBounds, vsBounds);
}
dvsBounds = clipBounds(discreteBounds(vsBounds), dw);
// If size of dvsBounds is <= 2, stop
Imath::V3i size = dvsBounds.size();
if (std::max(size.x, std::max(size.y, size.z)) <= 2) {
break;
}
}
}
// Level chosen. Run loop
for (int k = dvsBounds.min.z; k <= dvsBounds.max.z; ++k) {
for (int j = dvsBounds.min.y; j <= dvsBounds.max.y; ++j) {
for (int i = dvsBounds.min.x; i <= dvsBounds.max.x; ++i) {
const Data_T val = f[field].field->fastMipValue(level, i, j, k);
if (mode == Min) {
*data = detail::min(val, *data);
} else {
*data = detail::max(val, *data);
}
}
}
}
}
}

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

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

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

- export/FieldSampler.h