/usr/include/Field3D/FieldSampler.h is in libfield3d-dev 1.6.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | //----------------------------------------------------------------------------//
#ifndef __F3DUTIL_FIELDSAMPLER_H__
#define __F3DUTIL_FIELDSAMPLER_H__
//------------------------------------------------------------------------------
// Project includes
#include "Types.h"
//----------------------------------------------------------------------------//
#include "ns.h"
FIELD3D_NAMESPACE_OPEN
//------------------------------------------------------------------------------
// FieldSampler
//------------------------------------------------------------------------------
//! Interface for sampling a vector of fields of the same type
template <typename WrapperVec_T, int Dims_T>
struct FieldSampler
{
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 getMinMaxMIP(const WrapperVec_T &f,
const Box3d &wsBounds, float *min, float *max);
};
//------------------------------------------------------------------------------
//! Scalar specialization
template <typename WrapperVec_T>
struct FieldSampler<WrapperVec_T, 1>
{
// Ordinary fields
static void sample(const WrapperVec_T &f, const V3d &p, float *value,
bool isVs)
{
if (isVs) {
for (size_t i = 0, end = f.size(); i < end; ++i) {
if (f[i].vsBounds.intersects(p)) {
*value += f[i].interp.sample(*f[i].field, p);
}
}
} else {
V3d vsP;
for (size_t i = 0, end = f.size(); i < end; ++i) {
f[i].mapping->worldToVoxel(p, vsP);
if (f[i].vsBounds.intersects(vsP)) {
*value += f[i].interp.sample(*f[i].field, vsP);
}
}
}
}
// MIP fields
static void sampleMIP(const WrapperVec_T &f, const V3d &p,
const float wsSpotSize, float *value, bool isVs)
{
if (isVs) {
for (size_t i = 0, end = f.size(); i < end; ++i) {
if (f[i].vsBounds.intersects(p)) {
*value += f[i].interp->sample(p, wsSpotSize);
}
}
} else {
V3d vsP;
for (size_t i = 0, end = f.size(); i < end; ++i) {
f[i].mapping->worldToVoxel(p, vsP);
if (f[i].vsBounds.intersects(vsP)) {
*value += f[i].interp->sample(vsP, wsSpotSize);
}
}
}
}
// Get min/max
static void getMinMax(const WrapperVec_T &f,
const Box3d &wsBounds, float *min, float *max)
{
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
Box3d vsBounds;
worldToVoxel(f[field].mapping, wsBounds, vsBounds);
Box3i 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) {
float val = f[field].field->fastValue(i, j, k);
min[0] = std::min(val, min[0]);
max[0] = std::max(val, max[0]);
}
}
}
}
}
// Get min/max
static void getMinMaxMIP(const WrapperVec_T &f,
const Box3d &wsBounds, float *min, float *max)
{
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
Box3d vsBounds;
worldToVoxel(f[field].mapping, wsBounds, vsBounds);
Box3i 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) {
float val = f[field].field->fastMipValue(0, i, j, k);
min[0] = std::min(val, min[0]);
max[0] = std::max(val, max[0]);
}
}
}
}
}
};
//------------------------------------------------------------------------------
//! Vector specialization
template <typename WrapperVec_T>
struct FieldSampler<WrapperVec_T, 3>
{
// Ordinary fields
static void sample(const WrapperVec_T &f, const V3d &p, float *value,
bool isVs)
{
V3f v(value[0], value[1], value[2]);
if (isVs) {
for (size_t i = 0, end = f.size(); i < end; ++i) {
if (f[i].vsBounds.intersects(p)) {
v += f[i].interp.sample(*f[i].field, p);
}
}
} else {
V3d vsP;
for (size_t i = 0, end = f.size(); i < end; ++i) {
f[i].mapping->worldToVoxel(p, vsP);
if (f[i].vsBounds.intersects(vsP)) {
v += f[i].interp.sample(*f[i].field, vsP);
}
}
}
memcpy(value, &v[0], sizeof(V3f));
}
// MIP fields
static void sampleMIP(const WrapperVec_T &f, const V3d &p,
const float wsSpotSize, float *value, bool isVs)
{
V3f v(value[0], value[1], value[2]);
if (isVs) {
for (size_t i = 0, end = f.size(); i < end; ++i) {
if (f[i].vsBounds.intersects(p)) {
v += f[i].interp->sample(p, wsSpotSize);
}
}
} else {
V3d vsP;
for (size_t i = 0, end = f.size(); i < end; ++i) {
f[i].mapping->worldToVoxel(p, vsP);
if (f[i].vsBounds.intersects(vsP)) {
v += f[i].interp->sample(vsP, wsSpotSize);
}
}
}
memcpy(value, &v[0], sizeof(V3f));
}
static void getMinMax(const WrapperVec_T &f,
const Box3d &wsBounds, float *min, float *max)
{
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
Box3d vsBounds;
worldToVoxel(f[field].mapping, wsBounds, vsBounds);
Box3i 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) {
V3f val = f[field].field->fastValue(i, j, k);
min[0] = std::min(val.x, min[0]);
min[1] = std::min(val.y, min[1]);
min[2] = std::min(val.z, min[2]);
max[0] = std::max(val.x, max[0]);
max[1] = std::max(val.y, max[1]);
max[2] = std::max(val.z, max[2]);
}
}
}
}
}
static void getMinMaxMIP(const WrapperVec_T &f,
const Box3d &wsBounds, float *min, float *max)
{
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
Box3d vsBounds;
worldToVoxel(f[field].mapping, wsBounds, vsBounds);
Box3i 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) {
V3f val = f[field].field->fastMipValue(0, i, j, k);
min[0] = std::min(val.x, min[0]);
min[1] = std::min(val.y, min[1]);
min[2] = std::min(val.z, min[2]);
max[0] = std::max(val.x, max[0]);
max[1] = std::max(val.y, max[1]);
max[2] = std::max(val.z, max[2]);
}
}
}
}
}
};
//----------------------------------------------------------------------------//
FIELD3D_NAMESPACE_HEADER_CLOSE
//------------------------------------------------------------------------------
#endif // include guard
//------------------------------------------------------------------------------
|