32 minCoord.fill(intBound);
43 for (
size_t i = 0; i < ND; ++i) {
46 size_t bits = std::ceil(std::log2((bounds(i, 1) - bounds(i, 0)) / steps(i)));
49 maxBits = std::max(maxBits, bits);
63 for (
size_t i = 0; i < ND; ++i) {
64 bounds(i, 0) = std::nexttoward(bounds(i, 0), std::numeric_limits<float>::lowest());
65 bounds(i, 1) = std::nexttoward(bounds(i, 1), std::numeric_limits<float>::max());
73 for (
size_t i = 0; i < coord.rows(); i++) {
74 const float coordValue = coord(i, 0);
75 const Eigen::Matrix<float, 1, 2> coordBounds = bounds.row(i);
77 if (coordValue < coordBounds[0] || coordValue > coordBounds[1]) {
89template <
int ND,
typename IntT>
95 Eigen::Array<IntT, ND, 1> res =
n.template cast<IntT>();
96 for (
unsigned i = 0; i < ND; ++i)
97 if (coord[i] == bounds(i, 1))
98 res[i] = std::numeric_limits<IntT>::max();
99 else if (coord[i] == bounds(i, 0))
108template <
int ND,
typename IntT>
110 const Eigen::Array<IntT, ND, 1> &intCoord) {
111 const auto range = bounds.col(1) - bounds.col(0);
112 const auto coordFactorOfRange = intCoord.template cast<float>() / (float)std::numeric_limits<IntT>::max();
113 return bounds.col(0) + (coordFactorOfRange * range);
121 const float intValue = coordFactorOfRange * std::numeric_limits<IntT>::max();
122 return (IntT)intValue;
129 const float coordFactorOfRange = (float)
value / (
float)std::numeric_limits<IntT>::max();
133template <
size_t nd,
typename IntT,
typename MortonT>
135 return morton_index::ConvertCoordinatesFromIntegerRange<nd, IntT>(space,
139template <
size_t nd,
typename IntT,
typename MortonT,
typename coord_t =
float>
142 morton_index::ConvertCoordinatesToIntegerRange<nd, IntT>(space, coord));
double value
The value of the point.
double lower
lower and upper bounds on the multiplier, if known
bool morton_contains(const MortonT lower, const MortonT upper, const MortonT value)
Checks if a point defined by a Morton number is within the box bounds (as defined by an upper and low...
MortonT coordinatesToIndex(coord_t *coord, const MDSpaceBounds< nd > &space)
MDCoordinate< ND > ConvertCoordinatesFromIntegerRange(const MDSpaceBounds< ND > &bounds, const Eigen::Array< IntT, ND, 1 > &intCoord)
Converts a point expressed as integer coordinates back to floating point, given bounds of the origina...
Eigen::Array< IntT, ND, 1 > ConvertCoordinatesToIntegerRange(const MDSpaceBounds< ND > &bounds, const float *crd)
Converts a point to integer range given a range of floating point coordinates.
void ExpandBounds(MDSpaceBounds< ND > &bounds)
Expands a coordinate space enough that floating point error cannot cause an overflow when mapping a v...
bool CheckCoordinatesInMDSpace(const MDSpaceBounds< ND > &bounds, const MDCoordinate< ND > &coord)
Checks that a coordinate is within the extents of an MD space.
size_t CalculateRequiredCoordinateIntegerWidth(const MDSpaceBounds< ND > &bounds, const MDSpaceSteps< ND > &steps)
Calculates the required width of the interleaved integer to accurately represent coordinates in a giv...
MortonT calculateDefaultBound(IntT intBound)
Eigen::Array< float, static_cast< int >(ND), 1 > MDCoordinate
IntT ConvertCoordinateToIntegerRange(float value, float lower, float upper)
Converts a single floating point coordinate to an integer range.
float ConvertCoordinateFromIntegerRange(IntT value, float lower, float upper)
Converts a single integer coordinate to a floating point.
Eigen::Array< IntT, static_cast< int >(ND), 1 > IntArray
MDCoordinate< nd > indexToCoordinates(const MortonT &idx, const MDSpaceBounds< nd > &space)
Eigen::Array< float, static_cast< int >(ND), 1 > MDSpaceSteps
Eigen::Array< float, static_cast< int >(ND), 2 > MDSpaceBounds
static MortonT interleave(const IntArray< ND, IntT > &coord)