Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for HalfGrid and ComputeType #1787

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openvdb/openvdb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ set(OPENVDB_LIBRARY_MATH_INCLUDE_FILES
math/DDA.h
math/FiniteDifference.h
math/Half.h
math/HalfDecl.h
math/LegacyFrustum.h
math/Maps.h
math/Mat.h
Expand Down
6 changes: 4 additions & 2 deletions openvdb/openvdb/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ class Grid: public GridBase
using TreePtrType = typename _TreeType::Ptr;
using ConstTreePtrType = typename _TreeType::ConstPtr;
using ValueType = typename _TreeType::ValueType;
using ComputeType = typename _TreeType::ComputeType;
using BuildType = typename _TreeType::BuildType;

using ValueOnIter = typename _TreeType::ValueOnIter;
Expand Down Expand Up @@ -1746,10 +1747,11 @@ template<typename GridType>
typename GridType::Ptr
createLevelSet(Real voxelSize, Real halfWidth)
{
using ValueType = typename GridType::ValueType;
using ValueType = typename GridType::ValueType;
using ComputeType = typename GridType::ComputeType;

// GridType::ValueType is required to be a floating-point scalar.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should match what the code does. But I think in this case, the comment is right. ValueType reflects the payload stored in the leaf nodes and in the background value. The requirement for a level-set is for these two things to be floating point.

static_assert(std::is_floating_point<ValueType>::value,
static_assert(std::is_floating_point<ComputeType>::value,
"level-set grids must be floating-point-valued");

typename GridType::Ptr grid = GridType::create(
Expand Down
1 change: 1 addition & 0 deletions openvdb/openvdb/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ operator<<(std::ostream& ostr, const Metadata& metadata)
using BoolMetadata = TypedMetadata<bool>;
using DoubleMetadata = TypedMetadata<double>;
using FloatMetadata = TypedMetadata<float>;
using HalfMetadata = TypedMetadata<math::half>;
using Int32Metadata = TypedMetadata<int32_t>;
using Int64Metadata = TypedMetadata<int64_t>;
using StringMetadata = TypedMetadata<std::string>;
Expand Down
62 changes: 38 additions & 24 deletions openvdb/openvdb/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,7 @@
#include "Platform.h"
#include "TypeList.h" // backwards compat

#ifdef OPENVDB_USE_IMATH_HALF
#ifdef OPENVDB_IMATH_VERSION
#include <Imath/half.h>
#else
#include <OpenEXR/half.h>
#endif
namespace openvdb {
OPENVDB_USE_VERSION_NAMESPACE
namespace OPENVDB_VERSION_NAME {
namespace math {
using half = half;
}}}
#else
#include <openvdb/math/Half.h>
namespace openvdb {
OPENVDB_USE_VERSION_NAMESPACE
namespace OPENVDB_VERSION_NAME {
namespace math {
using half = internal::half;
}}}
#endif
#include <openvdb/math/HalfDecl.h>

#include <openvdb/math/Math.h>
#include <openvdb/math/BBox.h>
Expand Down Expand Up @@ -58,12 +38,13 @@ using Int64 = int64_t;
using Int = Int32;
using Byte = unsigned char;
using Real = double;
using Half = math::half;

// Two-dimensional vector types
using Vec2R = math::Vec2<Real>;
using Vec2I = math::Vec2<Index32>;
using Vec2f = math::Vec2<float>;
using Vec2H = math::Vec2<math::half>;
using Vec2H = math::Vec2<Half>;
using math::Vec2i;
using math::Vec2s;
using math::Vec2d;
Expand All @@ -72,7 +53,7 @@ using math::Vec2d;
using Vec3R = math::Vec3<Real>;
using Vec3I = math::Vec3<Index32>;
using Vec3f = math::Vec3<float>;
using Vec3H = math::Vec3<math::half>;
using Vec3H = math::Vec3<Half>;
using Vec3U8 = math::Vec3<uint8_t>;
using Vec3U16 = math::Vec3<uint16_t>;
using math::Vec3i;
Expand All @@ -87,7 +68,7 @@ using BBoxd = math::BBox<Vec3d>;
using Vec4R = math::Vec4<Real>;
using Vec4I = math::Vec4<Index32>;
using Vec4f = math::Vec4<float>;
using Vec4H = math::Vec4<math::half>;
using Vec4H = math::Vec4<Half>;
using math::Vec4i;
using math::Vec4s;
using math::Vec4d;
Expand Down Expand Up @@ -446,6 +427,22 @@ template<typename FromType, typename ToType> struct CopyConstness<const FromType
/// @endcond


////////////////////////////////////////

/// @brief Maps one type (e.g. the value types) to other types
template<typename T>
struct ValueToComputeMap
{
using Type = T;
};

template<>
struct ValueToComputeMap<Half>
{
using Type = float;
};


////////////////////////////////////////


Expand Down Expand Up @@ -688,6 +685,23 @@ class Steal {};
/// @brief Tag dispatch class that distinguishes constructors during file input
class PartialCreate {};

// For half compilation
namespace math {
template<>
inline auto cwiseAdd(const Vec3H& v, const float s)
{
Vec3H out;
const Half* ip = v.asPointer();
Half* op = out.asPointer();
for (unsigned i = 0; i < 3; ++i, ++op, ++ip) {
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
*op = *ip + s;
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
}
return out;
}
} // namespace math

} // namespace OPENVDB_VERSION_NAME
} // namespace openvdb

Expand Down
30 changes: 30 additions & 0 deletions openvdb/openvdb/math/HalfDecl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: MPL-2.0

#ifndef OPENVDB_HALFDECL_HAS_BEEN_INCLUDED
#define OPENVDB_HALFDECL_HAS_BEEN_INCLUDED

#ifdef OPENVDB_USE_IMATH_HALF
#ifdef OPENVDB_IMATH_VERSION
#include <Imath/half.h>
#else
#include <OpenEXR/half.h>
#endif
namespace openvdb {
OPENVDB_USE_VERSION_NAMESPACE
namespace OPENVDB_VERSION_NAME {
namespace math {
using half = half;
}}}
#else
#include <openvdb/math/Half.h>
namespace openvdb {
OPENVDB_USE_VERSION_NAMESPACE
namespace OPENVDB_VERSION_NAME {
namespace math {
using half = internal::half;
}}}
#endif


#endif // OPENVDB_HALFDECL_HAS_BEEN_INCLUDED
Loading
Loading