Skip to content

Commit

Permalink
ValueType -> ComputeType
Browse files Browse the repository at this point in the history
ValueType -> ComputeType computations in various tools
  • Loading branch information
ghurstunither committed Feb 22, 2024
1 parent c0cecf7 commit 9371e1f
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 178 deletions.
7 changes: 4 additions & 3 deletions openvdb/openvdb/math/Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ template<> struct Tolerance<double> { static double value() { return 1e-15;

//@{
/// Delta for small floating-point offsets
template<typename T> struct Delta { static T value() { return zeroVal<T>(); } };
template<> struct Delta<float> { static float value() { return 1e-5f; } };
template<> struct Delta<double> { static double value() { return 1e-9; } };
template<typename T> struct Delta { static T value() { return zeroVal<T>(); } };
template<> struct Delta<math::half> { static math::half value() { return 0.00390625; } };
template<> struct Delta<float> { static float value() { return 1e-5f; } };
template<> struct Delta<double> { static double value() { return 1e-9; } };
//@}


Expand Down
24 changes: 12 additions & 12 deletions openvdb/openvdb/math/Stencils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BaseStencil
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridT::ValueType ValueType;
typedef typename GridT::ComputeType ValueType;
typedef tree::ValueAccessor<const TreeType, IsSafe> AccessorType;
typedef std::vector<ValueType> BufferType;

Expand Down Expand Up @@ -250,7 +250,7 @@ class SevenPointStencil: public BaseStencil<SevenPointStencil<GridT, IsSafe>, Gr
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridT::ValueType ValueType;
typedef typename GridT::ComputeType ValueType;

static const int SIZE = 7;

Expand Down Expand Up @@ -304,7 +304,7 @@ class BoxStencil: public BaseStencil<BoxStencil<GridT, IsSafe>, GridT, IsSafe>
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridT::ValueType ValueType;
typedef typename GridT::ComputeType ValueType;

static const int SIZE = 8;

Expand Down Expand Up @@ -475,7 +475,7 @@ class SecondOrderDenseStencil
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridType::ValueType ValueType;
typedef typename GridType::ComputeType ValueType;

static const int SIZE = 19;

Expand Down Expand Up @@ -555,7 +555,7 @@ class ThirteenPointStencil
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridType::ValueType ValueType;
typedef typename GridType::ComputeType ValueType;

static const int SIZE = 13;

Expand Down Expand Up @@ -686,7 +686,7 @@ class FourthOrderDenseStencil
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridType::ValueType ValueType;
typedef typename GridType::ComputeType ValueType;

static const int SIZE = 61;

Expand Down Expand Up @@ -825,7 +825,7 @@ class NineteenPointStencil
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridType::ValueType ValueType;
typedef typename GridType::ComputeType ValueType;

static const int SIZE = 19;

Expand Down Expand Up @@ -1041,7 +1041,7 @@ class SixthOrderDenseStencil
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridType::ValueType ValueType;
typedef typename GridType::ComputeType ValueType;

static const int SIZE = 127;

Expand Down Expand Up @@ -1235,7 +1235,7 @@ class GradStencil : public BaseStencil<GradStencil<GridT, IsSafe>, GridT, IsSafe
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridType::ValueType ValueType;
typedef typename GridType::ComputeType ValueType;

static const int SIZE = 7;

Expand Down Expand Up @@ -1369,7 +1369,7 @@ class WenoStencil: public BaseStencil<WenoStencil<GridT, IsSafe>, GridT, IsSafe>
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridType::ValueType ValueType;
typedef typename GridType::ComputeType ValueType;

static const int SIZE = 19;

Expand Down Expand Up @@ -1519,7 +1519,7 @@ class CurvatureStencil: public BaseStencil<CurvatureStencil<GridT, IsSafe>, Grid
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridT::ValueType ValueType;
typedef typename GridT::ComputeType ValueType;

static const int SIZE = 19;

Expand Down Expand Up @@ -1768,7 +1768,7 @@ class DenseStencil: public BaseStencil<DenseStencil<GridT, IsSafe>, GridT, IsSaf
public:
typedef GridT GridType;
typedef typename GridT::TreeType TreeType;
typedef typename GridType::ValueType ValueType;
typedef typename GridType::ComputeType ValueType;

DenseStencil(const GridType& grid, int halfWidth)
: BaseType(grid, /*size=*/math::Pow3(2 * halfWidth + 1))
Expand Down
42 changes: 31 additions & 11 deletions openvdb/openvdb/tools/Interpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define OPENVDB_TOOLS_INTERPOLATION_HAS_BEEN_INCLUDED

#include <openvdb/version.h> // for OPENVDB_VERSION_NAME
#include <openvdb/Types.h> // for ValueToComputeMap
#include <openvdb/Platform.h> // for round()
#include <openvdb/math/Math.h>// for SmoothUnitStep
#include <openvdb/math/Transform.h> // for Transform
Expand Down Expand Up @@ -314,7 +315,7 @@ class GridSampler
/// @brief Sample value in integer index space
/// @param i Integer x-coordinate in index space
/// @param j Integer y-coordinate in index space
/// @param k Integer x-coordinate in index space
/// @param k Integer z-coordinate in index space
ValueType sampleVoxel(typename Coord::ValueType i,
typename Coord::ValueType j,
typename Coord::ValueType k) const
Expand Down Expand Up @@ -393,7 +394,7 @@ class GridSampler<tree::ValueAccessor<TreeT>, SamplerType>
/// @brief Sample value in integer index space
/// @param i Integer x-coordinate in index space
/// @param j Integer y-coordinate in index space
/// @param k Integer x-coordinate in index space
/// @param k Integer z-coordinate in index space
ValueType sampleVoxel(typename Coord::ValueType i,
typename Coord::ValueType j,
typename Coord::ValueType k) const
Expand Down Expand Up @@ -745,17 +746,31 @@ BoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
typename TreeT::ValueType& result)
{
using ValueT = typename TreeT::ValueType;
using ComputeT = typename TreeT::ComputeType;

const Vec3i inIdx = local_util::floorVec3(inCoord);
const Vec3R uvw = inCoord - inIdx;

// Retrieve the values of the eight voxels surrounding the
// fractional source coordinates.
ValueT data[2][2][2];

const bool hasActiveValues = BoxSampler::probeValues(data, inTree, Coord(inIdx));
ValueT probeData[2][2][2];
ComputeT computeData[2][2][2];
bool hasActiveValues;

if constexpr(std::is_same_v<ValueT, ComputeT>) {
hasActiveValues = BoxSampler::probeValues(computeData, inTree, Coord(inIdx));
} else {
hasActiveValues = BoxSampler::probeValues(probeData, inTree, Coord(inIdx));
for (int dx = 0; dx < 2; ++dx) {
for (int dy = 0; dy < 2; ++dy) {
for (int dz = 0; dz < 2; ++dz) {
computeData[dx][dy][dz] = probeData[dx][dy][dz];
}
}
}
}

result = BoxSampler::trilinearInterpolation(data, uvw);
result = BoxSampler::trilinearInterpolation(computeData, uvw);

return hasActiveValues;
}
Expand All @@ -766,17 +781,18 @@ inline typename TreeT::ValueType
BoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
{
using ValueT = typename TreeT::ValueType;
using ComputeT = typename TreeT::ComputeType;

const Vec3i inIdx = local_util::floorVec3(inCoord);
const Vec3R uvw = inCoord - inIdx;

// Retrieve the values of the eight voxels surrounding the
// fractional source coordinates.
ValueT data[2][2][2];
ComputeT data[2][2][2];

BoxSampler::getValues(data, inTree, Coord(inIdx));

return BoxSampler::trilinearInterpolation(data, uvw);
return ValueT(BoxSampler::trilinearInterpolation(data, uvw));
}


Expand Down Expand Up @@ -832,6 +848,7 @@ QuadraticSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
typename TreeT::ValueType& result)
{
using ValueT = typename TreeT::ValueType;
using ComputeT = typename TreeT::ComputeType;

const Vec3i inIdx = local_util::floorVec3(inCoord), inLoIdx = inIdx - Vec3i(1, 1, 1);
const Vec3R uvw = inCoord - inIdx;
Expand All @@ -840,15 +857,17 @@ QuadraticSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
// fractional source coordinates.
bool active = false;
ValueT data[3][3][3];
ComputeT computeData[3][3][3];
for (int dx = 0, ix = inLoIdx.x(); dx < 3; ++dx, ++ix) {
for (int dy = 0, iy = inLoIdx.y(); dy < 3; ++dy, ++iy) {
for (int dz = 0, iz = inLoIdx.z(); dz < 3; ++dz, ++iz) {
if (inTree.probeValue(Coord(ix, iy, iz), data[dx][dy][dz])) active = true;
computeData[dx][dy][dz] = data[dx][dy][dz];
}
}
}

result = QuadraticSampler::triquadraticInterpolation(data, uvw);
result = QuadraticSampler::triquadraticInterpolation(computeData, uvw);

return active;
}
Expand All @@ -858,13 +877,14 @@ inline typename TreeT::ValueType
QuadraticSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
{
using ValueT = typename TreeT::ValueType;
using ComputeT = typename TreeT::ComputeType;

const Vec3i inIdx = local_util::floorVec3(inCoord), inLoIdx = inIdx - Vec3i(1, 1, 1);
const Vec3R uvw = inCoord - inIdx;

// Retrieve the values of the 27 voxels surrounding the
// fractional source coordinates.
ValueT data[3][3][3];
ComputeT data[3][3][3];
for (int dx = 0, ix = inLoIdx.x(); dx < 3; ++dx, ++ix) {
for (int dy = 0, iy = inLoIdx.y(); dy < 3; ++dy, ++iy) {
for (int dz = 0, iz = inLoIdx.z(); dz < 3; ++dz, ++iz) {
Expand All @@ -873,7 +893,7 @@ QuadraticSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
}
}

return QuadraticSampler::triquadraticInterpolation(data, uvw);
return ValueT(QuadraticSampler::triquadraticInterpolation(data, uvw));
}


Expand Down
Loading

0 comments on commit 9371e1f

Please sign in to comment.