OpenVDB 14.0.0
Loading...
Searching...
No Matches
Coord Class Reference

Signed (i, j, k) 32-bit integer coordinate class, similar to openvdb::math::Coord. More...

#include <nanovdb/math/Math.h>

Public Types

using ValueType = int32_t
using IndexType = uint32_t

Public Member Functions

__hostdev__ constexpr Coord () noexcept
 Initialize all coordinates to zero.
__hostdev__ constexpr Coord (ValueType n) noexcept
 Initializes all coordinates to the given signed integer.
__hostdev__ constexpr Coord (ValueType i, ValueType j, ValueType k) noexcept
 Initializes coordinate to the given signed integers.
__hostdev__ constexpr Coord (ValueType *ptr) noexcept
 Read three signed integers from ptr (no bounds check).
__hostdev__ constexpr int32_t x () const noexcept
 Named component accessors (x = mVec[0], y = mVec[1], z = mVec[2]).
__hostdev__ constexpr int32_t & x () noexcept
__hostdev__ constexpr int32_t y () const noexcept
__hostdev__ constexpr int32_t & y () noexcept
__hostdev__ constexpr int32_t z () const noexcept
__hostdev__ constexpr int32_t & z () noexcept
__hostdev__ constexpr const ValueType & operator[] (IndexType i) const noexcept
 Return a const reference to the given Coord component.
__hostdev__ constexpr ValueType & operator[] (IndexType i) noexcept
 Return a non-const reference to the given Coord component.
template<typename CoordT>
__hostdev__ constexpr Coord & operator= (const CoordT &other) noexcept
 Assignment operator that works with openvdb::Coord.
__hostdev__ constexpr Coord operator& (IndexType n) const noexcept
 Return a new instance with coordinates masked by the given unsigned integer.
__hostdev__ constexpr Coord operator<< (IndexType n) const noexcept
 Return a new instance with coordinates left-shifted by the given unsigned integer.
__hostdev__ constexpr Coord operator>> (IndexType n) const noexcept
 Return a new instance with coordinates right-shifted by the given unsigned integer.
__hostdev__ constexpr bool operator< (const Coord &rhs) const noexcept
 Return true if this Coord is lexicographically less than the given Coord.
__hostdev__ constexpr bool operator<= (const Coord &rhs) const noexcept
 Return true if this Coord is lexicographically less or equal to the given Coord.
__hostdev__ constexpr bool operator> (const Coord &rhs) const noexcept
 Return true if this Coord is lexicographically greater than the given Coord.
__hostdev__ constexpr bool operator>= (const Coord &rhs) const noexcept
 Return true if this Coord is lexicographically greater or equal to the given Coord.
__hostdev__ constexpr bool operator== (const Coord &rhs) const noexcept
 Return true iff every component matches rhs.
__hostdev__ constexpr bool operator!= (const Coord &rhs) const noexcept
 Return true iff any component differs from rhs.
__hostdev__ constexpr Coord & operator&= (int n) noexcept
 In-place component-wise bitwise AND with the given mask.
__hostdev__ constexpr Coord & operator<<= (uint32_t n) noexcept
 In-place left-shift of every component by n bits.
__hostdev__ constexpr Coord & operator>>= (uint32_t n) noexcept
 In-place right-shift of every component by n bits.
__hostdev__ constexpr Coord & operator+= (int n) noexcept
 Add a scalar to every component in place.
__hostdev__ constexpr Coord & operator+= (const Coord &rhs) noexcept
 In-place component-wise addition with another coordinate.
__hostdev__ constexpr Coord operator+ (const Coord &rhs) const noexcept
 Component-wise sum of two coordinates.
__hostdev__ constexpr Coord operator- (const Coord &rhs) const noexcept
 Component-wise difference of two coordinates.
__hostdev__ constexpr Coord operator- () const noexcept
 Component-wise negation.
__hostdev__ constexpr Coord & operator-= (const Coord &rhs) noexcept
 In-place component-wise subtraction with another coordinate.
__hostdev__ constexpr Coord & minComponent (const Coord &other) noexcept
 Perform a component-wise minimum with the other Coord.
__hostdev__ constexpr Coord & maxComponent (const Coord &other) noexcept
 Perform a component-wise maximum with the other Coord.
__hostdev__ constexpr Coord offsetBy (ValueType dx, ValueType dy, ValueType dz) const noexcept
 Return a new Coord offset component-by-component by (dx, dy, dz).
__hostdev__ constexpr Coord offsetBy (ValueType n) const noexcept
 Return a new Coord offset by the same scalar n in every component.
template<int Log2N = 3 + 4 + 5>
__hostdev__ constexpr uint32_t hash () const noexcept
 Return a hash key derived from the existing coordinates.
__hostdev__ constexpr uint8_t octant () const noexcept
 Return the octant of this Coord.
__hostdev__ constexpr Vec3< float > asVec3s () const noexcept
 Return a single precision floating-point vector of this coordinate.
__hostdev__ constexpr Vec3< double > asVec3d () const noexcept
 Return a double precision floating-point vector of this coordinate.
__hostdev__ constexpr Coord round () const noexcept
 Identity (Coord is already integer); provided so generic code can call .round() uniformly on Coord and Vec3<T>.

Static Public Member Functions

static __hostdev__ constexpr Coord max () noexcept
 Largest representable Coord (all components = INT32_MAX).
static __hostdev__ constexpr Coord min () noexcept
 Smallest representable Coord (all components = INT32_MIN).
static __hostdev__ constexpr size_t memUsage () noexcept
 Byte size of a Coord (always 12 on a 32-bit int32_t platform).
static __hostdev__ constexpr bool lessThan (const Coord &a, const Coord &b) noexcept
template<typename Vec3T>
static __hostdev__ Coord Floor (const Vec3T &xyz) noexcept
 Return the largest integer coordinates that are not greater than xyz (node centered conversion).

Detailed Description

Signed (i, j, k) 32-bit integer coordinate class, similar to openvdb::math::Coord.

Member Typedef Documentation

◆ IndexType

using IndexType = uint32_t

◆ ValueType

using ValueType = int32_t

Constructor & Destructor Documentation

◆ Coord() [1/4]

__hostdev__ constexpr Coord ( )
inlineconstexprnoexcept

Initialize all coordinates to zero.

◆ Coord() [2/4]

__hostdev__ constexpr Coord ( ValueType n)
inlineexplicitconstexprnoexcept

Initializes all coordinates to the given signed integer.

◆ Coord() [3/4]

__hostdev__ constexpr Coord ( ValueType i,
ValueType j,
ValueType k )
inlineconstexprnoexcept

Initializes coordinate to the given signed integers.

◆ Coord() [4/4]

__hostdev__ constexpr Coord ( ValueType * ptr)
inlineconstexprnoexcept

Read three signed integers from ptr (no bounds check).

Member Function Documentation

◆ asVec3d()

__hostdev__ constexpr Vec3< double > asVec3d ( ) const
inlinenodiscardconstexprnoexcept

Return a double precision floating-point vector of this coordinate.

◆ asVec3s()

__hostdev__ constexpr Vec3< float > asVec3s ( ) const
inlinenodiscardconstexprnoexcept

Return a single precision floating-point vector of this coordinate.

◆ Floor()

template<typename Vec3T>
__hostdev__ Coord Floor ( const Vec3T & xyz)
inlinestaticnodiscardnoexcept

Return the largest integer coordinates that are not greater than xyz (node centered conversion).

◆ hash()

template<int Log2N = 3 + 4 + 5>
__hostdev__ constexpr uint32_t hash ( ) const
inlinenodiscardconstexprnoexcept

Return a hash key derived from the existing coordinates.

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" (the second number had a typo!)

◆ lessThan()

__hostdev__ constexpr bool lessThan ( const Coord & a,
const Coord & b )
inlinestaticnodiscardconstexprnoexcept

Return true if any of the components of a are smaller than the corresponding components of b.

◆ max()

__hostdev__ constexpr Coord max ( )
inlinestaticnodiscardconstexprnoexcept

Largest representable Coord (all components = INT32_MAX).

◆ maxComponent()

__hostdev__ constexpr Coord & maxComponent ( const Coord & other)
inlineconstexprnoexcept

Perform a component-wise maximum with the other Coord.

◆ memUsage()

__hostdev__ constexpr size_t memUsage ( )
inlinestaticnodiscardconstexprnoexcept

Byte size of a Coord (always 12 on a 32-bit int32_t platform).

◆ min()

__hostdev__ constexpr Coord min ( )
inlinestaticnodiscardconstexprnoexcept

Smallest representable Coord (all components = INT32_MIN).

◆ minComponent()

__hostdev__ constexpr Coord & minComponent ( const Coord & other)
inlineconstexprnoexcept

Perform a component-wise minimum with the other Coord.

◆ octant()

__hostdev__ constexpr uint8_t octant ( ) const
inlinenodiscardconstexprnoexcept

Return the octant of this Coord.

◆ offsetBy() [1/2]

__hostdev__ constexpr Coord offsetBy ( ValueType dx,
ValueType dy,
ValueType dz ) const
inlinenodiscardconstexprnoexcept

Return a new Coord offset component-by-component by (dx, dy, dz).

◆ offsetBy() [2/2]

__hostdev__ constexpr Coord offsetBy ( ValueType n) const
inlinenodiscardconstexprnoexcept

Return a new Coord offset by the same scalar n in every component.

◆ operator!=()

__hostdev__ constexpr bool operator!= ( const Coord & rhs) const
inlinenodiscardconstexprnoexcept

Return true iff any component differs from rhs.

◆ operator&()

__hostdev__ constexpr Coord operator& ( IndexType n) const
inlinenodiscardconstexprnoexcept

Return a new instance with coordinates masked by the given unsigned integer.

◆ operator&=()

__hostdev__ constexpr Coord & operator&= ( int n)
inlineconstexprnoexcept

In-place component-wise bitwise AND with the given mask.

◆ operator+()

__hostdev__ constexpr Coord operator+ ( const Coord & rhs) const
inlinenodiscardconstexprnoexcept

Component-wise sum of two coordinates.

◆ operator+=() [1/2]

__hostdev__ constexpr Coord & operator+= ( const Coord & rhs)
inlineconstexprnoexcept

In-place component-wise addition with another coordinate.

◆ operator+=() [2/2]

__hostdev__ constexpr Coord & operator+= ( int n)
inlineconstexprnoexcept

Add a scalar to every component in place.

◆ operator-() [1/2]

__hostdev__ constexpr Coord operator- ( ) const
inlinenodiscardconstexprnoexcept

Component-wise negation.

◆ operator-() [2/2]

__hostdev__ constexpr Coord operator- ( const Coord & rhs) const
inlinenodiscardconstexprnoexcept

Component-wise difference of two coordinates.

◆ operator-=()

__hostdev__ constexpr Coord & operator-= ( const Coord & rhs)
inlineconstexprnoexcept

In-place component-wise subtraction with another coordinate.

◆ operator<()

__hostdev__ constexpr bool operator< ( const Coord & rhs) const
inlinenodiscardconstexprnoexcept

Return true if this Coord is lexicographically less than the given Coord.

◆ operator<<()

__hostdev__ constexpr Coord operator<< ( IndexType n) const
inlinenodiscardconstexprnoexcept

Return a new instance with coordinates left-shifted by the given unsigned integer.

◆ operator<<=()

__hostdev__ constexpr Coord & operator<<= ( uint32_t n)
inlineconstexprnoexcept

In-place left-shift of every component by n bits.

◆ operator<=()

__hostdev__ constexpr bool operator<= ( const Coord & rhs) const
inlinenodiscardconstexprnoexcept

Return true if this Coord is lexicographically less or equal to the given Coord.

◆ operator=()

template<typename CoordT>
__hostdev__ constexpr Coord & operator= ( const CoordT & other)
inlineconstexprnoexcept

Assignment operator that works with openvdb::Coord.

◆ operator==()

__hostdev__ constexpr bool operator== ( const Coord & rhs) const
inlinenodiscardconstexprnoexcept

Return true iff every component matches rhs.

◆ operator>()

__hostdev__ constexpr bool operator> ( const Coord & rhs) const
inlinenodiscardconstexprnoexcept

Return true if this Coord is lexicographically greater than the given Coord.

◆ operator>=()

__hostdev__ constexpr bool operator>= ( const Coord & rhs) const
inlinenodiscardconstexprnoexcept

Return true if this Coord is lexicographically greater or equal to the given Coord.

◆ operator>>()

__hostdev__ constexpr Coord operator>> ( IndexType n) const
inlinenodiscardconstexprnoexcept

Return a new instance with coordinates right-shifted by the given unsigned integer.

◆ operator>>=()

__hostdev__ constexpr Coord & operator>>= ( uint32_t n)
inlineconstexprnoexcept

In-place right-shift of every component by n bits.

◆ operator[]() [1/2]

__hostdev__ constexpr const ValueType & operator[] ( IndexType i) const
inlineconstexprnoexcept

Return a const reference to the given Coord component.

Warning
The argument is assumed to be 0, 1, or 2.

◆ operator[]() [2/2]

__hostdev__ constexpr ValueType & operator[] ( IndexType i)
inlineconstexprnoexcept

Return a non-const reference to the given Coord component.

Warning
The argument is assumed to be 0, 1, or 2.

◆ round()

__hostdev__ constexpr Coord round ( ) const
inlinenodiscardconstexprnoexcept

Identity (Coord is already integer); provided so generic code can call .round() uniformly on Coord and Vec3<T>.

◆ x() [1/2]

__hostdev__ constexpr int32_t x ( ) const
inlineconstexprnoexcept

Named component accessors (x = mVec[0], y = mVec[1], z = mVec[2]).

◆ x() [2/2]

__hostdev__ constexpr int32_t & x ( )
inlineconstexprnoexcept

◆ y() [1/2]

__hostdev__ constexpr int32_t y ( ) const
inlineconstexprnoexcept

◆ y() [2/2]

__hostdev__ constexpr int32_t & y ( )
inlineconstexprnoexcept

◆ z() [1/2]

__hostdev__ constexpr int32_t z ( ) const
inlineconstexprnoexcept

◆ z() [2/2]

__hostdev__ constexpr int32_t & z ( )
inlineconstexprnoexcept