3 #ifndef __F3DUTIL_FIELDSAMPLER_H__ 4 #define __F3DUTIL_FIELDSAMPLER_H__ 22 template <
typename WrapperVec_T,
int Dims_T>
25 static void sample(
const WrapperVec_T &f,
const V3d &p,
float *value,
27 static void sampleMIP(
const WrapperVec_T &f,
const V3d &p,
28 const float wsSpotSize,
float *value,
bool isVs);
29 static void getMinMax(
const WrapperVec_T &f,
30 const Box3d &wsBounds,
float *min,
float *max);
32 const Box3d &wsBounds,
float *min,
float *max);
38 template <
typename WrapperVec_T>
42 static void sample(
const WrapperVec_T &f,
const V3d &p,
float *value,
46 for (
size_t i = 0, end = f.size(); i < end; ++i) {
47 if (f[i].vsBounds.intersects(p)) {
48 *value += f[i].interp.sample(*f[i].field, p);
53 for (
size_t i = 0, end = f.size(); i < end; ++i) {
54 f[i].mapping->worldToVoxel(p, vsP);
55 if (f[i].vsBounds.intersects(vsP)) {
56 *value += f[i].interp.sample(*f[i].field, vsP);
63 const float wsSpotSize,
float *value,
bool isVs)
66 for (
size_t i = 0, end = f.size(); i < end; ++i) {
67 if (f[i].vsBounds.intersects(p)) {
68 *value += f[i].interp->sample(p, wsSpotSize);
73 for (
size_t i = 0, end = f.size(); i < end; ++i) {
74 f[i].mapping->worldToVoxel(p, vsP);
75 if (f[i].vsBounds.intersects(vsP)) {
76 *value += f[i].interp->sample(vsP, wsSpotSize);
83 const Box3d &wsBounds,
float *min,
float *max)
85 for (
size_t field = 0, end = f.size(); field < end; ++field) {
87 const Box3i dw = f[field].field->dataWindow();
93 if (!dw.intersects(dvsBounds)) {
96 for (
int k = dvsBounds.min.z; k <= dvsBounds.max.z; ++k) {
97 for (
int j = dvsBounds.min.y; j <= dvsBounds.max.y; ++j) {
98 for (
int i = dvsBounds.min.x; i <= dvsBounds.max.x; ++i) {
99 float val = f[field].field->fastValue(i, j, k);
100 min[0] = std::min(val, min[0]);
101 max[0] = std::max(val, max[0]);
109 const Box3d &wsBounds,
float *min,
float *max)
111 for (
size_t field = 0, end = f.size(); field < end; ++field) {
113 const Box3i dw = f[field].field->dataWindow();
119 if (!dw.intersects(dvsBounds)) {
122 for (
int k = dvsBounds.min.z; k <= dvsBounds.max.z; ++k) {
123 for (
int j = dvsBounds.min.y; j <= dvsBounds.max.y; ++j) {
124 for (
int i = dvsBounds.min.x; i <= dvsBounds.max.x; ++i) {
125 float val = f[field].field->fastMipValue(0, i, j, k);
126 min[0] = std::min(val, min[0]);
127 max[0] = std::max(val, max[0]);
138 template <
typename WrapperVec_T>
142 static void sample(
const WrapperVec_T &f,
const V3d &p,
float *value,
145 V3f v(value[0], value[1], value[2]);
147 for (
size_t i = 0, end = f.size(); i < end; ++i) {
148 if (f[i].vsBounds.intersects(p)) {
149 v += f[i].interp.sample(*f[i].field, p);
154 for (
size_t i = 0, end = f.size(); i < end; ++i) {
155 f[i].mapping->worldToVoxel(p, vsP);
156 if (f[i].vsBounds.intersects(vsP)) {
157 v += f[i].interp.sample(*f[i].field, vsP);
161 memcpy(value, &v[0],
sizeof(
V3f));
166 const float wsSpotSize,
float *value,
bool isVs)
168 V3f v(value[0], value[1], value[2]);
170 for (
size_t i = 0, end = f.size(); i < end; ++i) {
171 if (f[i].vsBounds.intersects(p)) {
172 v += f[i].interp->sample(p, wsSpotSize);
177 for (
size_t i = 0, end = f.size(); i < end; ++i) {
178 f[i].mapping->worldToVoxel(p, vsP);
179 if (f[i].vsBounds.intersects(vsP)) {
180 v += f[i].interp->sample(vsP, wsSpotSize);
184 memcpy(value, &v[0],
sizeof(
V3f));
188 const Box3d &wsBounds,
float *min,
float *max)
190 for (
size_t field = 0, end = f.size(); field < end; ++field) {
192 const Box3i dw = f[field].field->dataWindow();
198 if (!dw.intersects(dvsBounds)) {
201 for (
int k = dvsBounds.min.z; k <= dvsBounds.max.z; ++k) {
202 for (
int j = dvsBounds.min.y; j <= dvsBounds.max.y; ++j) {
203 for (
int i = dvsBounds.min.x; i <= dvsBounds.max.x; ++i) {
204 V3f val = f[field].field->fastValue(i, j, k);
205 min[0] = std::min(val.x, min[0]);
206 min[1] = std::min(val.y, min[1]);
207 min[2] = std::min(val.z, min[2]);
208 max[0] = std::max(val.x, max[0]);
209 max[1] = std::max(val.y, max[1]);
210 max[2] = std::max(val.z, max[2]);
218 const Box3d &wsBounds,
float *min,
float *max)
220 for (
size_t field = 0, end = f.size(); field < end; ++field) {
222 const Box3i dw = f[field].field->dataWindow();
228 if (!dw.intersects(dvsBounds)) {
231 for (
int k = dvsBounds.min.z; k <= dvsBounds.max.z; ++k) {
232 for (
int j = dvsBounds.min.y; j <= dvsBounds.max.y; ++j) {
233 for (
int i = dvsBounds.min.x; i <= dvsBounds.max.x; ++i) {
234 V3f val = f[field].field->fastMipValue(0, i, j, k);
235 min[0] = std::min(val.x, min[0]);
236 min[1] = std::min(val.y, min[1]);
237 min[2] = std::min(val.z, min[2]);
238 max[0] = std::max(val.x, max[0]);
239 max[1] = std::max(val.y, max[1]);
240 max[2] = std::max(val.z, max[2]);
254 #endif // include guard #define FIELD3D_NAMESPACE_HEADER_CLOSE
Box3i clipBounds(const Box3i &bbox, const Box3i &bounds)
Contains typedefs for the commonly used types in Field3D.
static void sample(const WrapperVec_T &f, const V3d &p, float *value, bool isVs)
Interface for sampling a vector of fields of the same type.
static void sampleMIP(const WrapperVec_T &f, const V3d &p, const float wsSpotSize, float *value, bool isVs)
static void sample(const WrapperVec_T &f, const V3d &p, float *value, bool isVs)
static void getMinMax(const WrapperVec_T &f, const Box3d &wsBounds, float *min, float *max)
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 ...
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 getMinMaxMIP(const WrapperVec_T &f, const Box3d &wsBounds, float *min, float *max)
Box3i discreteBounds(const Box3d &bbox)
static void getMinMaxMIP(const WrapperVec_T &f, const Box3d &wsBounds, float *min, float *max)
static void sample(const WrapperVec_T &f, const V3d &p, float *value, bool isVs)
static void sampleMIP(const WrapperVec_T &f, const V3d &p, const float wsSpotSize, float *value, bool isVs)
static void getMinMax(const WrapperVec_T &f, const Box3d &wsBounds, float *min, float *max)
static void sampleMIP(const WrapperVec_T &f, const V3d &p, const float wsSpotSize, float *value, bool isVs)