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

Fix prime number in voxel hashing #1626

Merged
merged 1 commit into from
Jul 4, 2023
Merged
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
4 changes: 3 additions & 1 deletion nanovdb/nanovdb/NanoVDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -1134,8 +1134,10 @@ class Coord

/// @brief Return a hash key derived from the existing coordinates.
/// @details For details on this hash function please see the VDB paper.
/// The prime numbers are modified based on the ACM Transactions on Graphics paper:
/// "Real-time 3D reconstruction at scale using voxel hashing"
template<int Log2N = 3 + 4 + 5>
__hostdev__ uint32_t hash() const { return ((1 << Log2N) - 1) & (mVec[0] * 73856093 ^ mVec[1] * 19349663 ^ mVec[2] * 83492791); }
__hostdev__ uint32_t hash() const { return ((1 << Log2N) - 1) & (mVec[0] * 73856093 ^ mVec[1] * 19349669 ^ mVec[2] * 83492791); }

/// @brief Return the octant of this Coord
//__hostdev__ size_t octant() const { return (uint32_t(mVec[0])>>31) | ((uint32_t(mVec[1])>>31)<<1) | ((uint32_t(mVec[2])>>31)<<2); }
Expand Down
6 changes: 4 additions & 2 deletions openvdb/openvdb/math/Coord.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,15 @@ class Coord

/// @brief Return a hash value for this coordinate
/// @note Log2N is the binary logarithm of the hash table size.
/// @details The hash function is taken from the SIGGRAPH paper:
/// @details The hash function is originally taken from the SIGGRAPH paper:
/// "VDB: High-resolution sparse volumes with dynamic topology"
/// and the prime numbers are modified based on the ACM Transactions on Graphics paper:
/// "Real-time 3D reconstruction at scale using voxel hashing"
template<int Log2N = 20>
size_t hash() const
{
const uint32_t* vec = reinterpret_cast<const uint32_t*>(mVec.data());
return ((1<<Log2N)-1) & (vec[0]*73856093 ^ vec[1]*19349663 ^ vec[2]*83492791);
return ((1<<Log2N)-1) & (vec[0]*73856093 ^ vec[1]*19349669 ^ vec[2]*83492791);
}

private:
Expand Down