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

Conversation

ghurstunither
Copy link
Contributor

Initial support for HalfGrid and ComputeType in OpenVDB, where the latter enables intermediate float computations for HalfGrid to increase accuracy and speed.

  • Uses ValueToComputeMap in Types.h to set ComputeType at the leaf level and then to propagate all the way up to the grid level.
    • For math::half, ComputeType is float and for any other type T, ComputeType is T.
  • Defines and registers HalfGrid (half vectors not in this PR).
  • Moved the inclusion/declaration of math::half from Types.h to its own HalfDecl.h
    • Added some arithmetic support for math::half in Math.h (to avoid casting in some places) so there were now circular dependancies.
  • Refactors many tools and utilities to perform intermediate computations with ComputeType instead of ValueType.

Note, I decided not to define openvdb::is_floating_point and friends. Instead I opted to use std::is_floating_point<ComputeType>()::value instead.


Still to come in this PR

*Uunit tests for half and to verify no unit tests have broken.

  • Quantification of the level of support in tools.
    • e.g. some tools didn't need refactoring, and so this PR doesn't reflect that they fully support half grids
  • More examples within this description.

Initial support for HalfGrid and ComputeType, where the latter enables float computations for HalfGrid which increases accuracy and speed.

Signed-off-by: ghurstunither <[email protected]>
Remove HalfGrid from RealGridTypes until a consensus is reached.

Signed-off-by: ghurstunither <[email protected]>
Fixes trailingspaces errors

Signed-off-by: ghurstunither <[email protected]>
@@ -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.

template<> struct Tolerance<float> { static float value() { return 1e-8f; } };
template<> struct Tolerance<double> { static double value() { return 1e-15; } };
template<typename T> struct Tolerance { static T value() { return zeroVal<T>(); } };
template<> struct Tolerance<math::half> { static math::half value() { return 0.00097656; } };
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment on the reference of where this value comes from.


// isNegative and operator-() are bitwise ops
// all half types in HalfDecl.h _could_ define abs() as half(FromBits, bits() & 0x7fff)
inline math::half Abs(math::half x) { return x.isNegative() ? -x : x; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Happy to see the comment :)

@@ -362,6 +370,10 @@ isApproxZero(const Type& x, const Type& tolerance)
}


/// Return @c true if @a x is less than zero.
inline bool
isNegative(math::half& x) { return x.isNegative(); }
Copy link
Contributor

@apradhana apradhana Sep 10, 2024

Choose a reason for hiding this comment

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

We probably want to add a const keyword in the argument.

@apradhana
Copy link
Contributor

@ghurstunither. I'm wondering if you have ever compiled this PR with EXPLICIT_TEMPLATE_INSTANTIATION = ON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants