EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_SFC.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
11#ifndef EBGEOMETRY_SFC_HPP
12#define EBGEOMETRY_SFC_HPP
13
14// Std includes
15#include <array>
16#include <cstdint>
17#include <vector>
18
19// Our includes
20#include "EBGeometry_Vec.hpp"
21
22namespace EBGeometry {
23
45namespace SFC {
46
50using Code = uint64_t;
51
55using Index = std::array<unsigned int, 3>;
56
61static constexpr unsigned int ValidBits = 21;
62
66static constexpr Code ValidSpan = (static_cast<uint64_t>(1) << ValidBits) - 1;
67
71struct Morton
72{
78 [[nodiscard]] inline static uint64_t
79 encode(const Index& a_point) noexcept;
80
87 [[nodiscard]] inline static Index
88 decode(const uint64_t& a_code) noexcept;
89
90protected:
94 static constexpr uint_fast64_t Mask_64[6]{
95 0x1fffff, 0x1f00000000ffff, 0x1f0000ff0000ff, 0x100f00f00f00f00f, 0x10c30c30c30c30c3, 0x1249249249249249};
96};
97
102struct Nested
103{
109 [[nodiscard]] inline static uint64_t
110 encode(const Index& a_point) noexcept;
111
118 [[nodiscard]] inline static Index
119 decode(const uint64_t& a_code) noexcept;
120};
121
134{
140 [[nodiscard]] inline static uint64_t
141 encode(const Index& a_point) noexcept;
142
149 [[nodiscard]] inline static Index
150 decode(const uint64_t& a_code) noexcept;
151};
152
167template <class T>
168[[nodiscard]] inline std::vector<Index>
169computeBins(const std::vector<Vec3T<T>>& a_points) noexcept;
170
184template <class Curve = Morton, class T>
185[[nodiscard]] inline std::vector<uint32_t>
186order(const std::vector<Vec3T<T>>& a_points) noexcept;
187
188} // namespace SFC
189
190} // namespace EBGeometry
191
192#include "EBGeometry_SFCImplem.hpp"
193
194#endif
Declaration of 2D and 3D point/vector classes with templated precision. Used with DCEL tools.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:225
std::vector< uint32_t > order(const std::vector< Vec3T< T > > &a_points) noexcept
Return the index permutation that orders a_points along a space-filling curve.
std::array< unsigned int, 3 > Index
Alias for 3D cell index.
Definition EBGeometry_SFC.hpp:55
std::vector< Index > computeBins(const std::vector< Vec3T< T > > &a_points) noexcept
Bin a set of points into the space-filling curve's integer grid, normalizing by their own bounding ra...
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:31
Implementation of the 3D Hilbert space-filling curve.
Definition EBGeometry_SFC.hpp:134
static Index decode(const uint64_t &a_code) noexcept
Decode the linear Hilbert distance back into an Index.
static uint64_t encode(const Index &a_point) noexcept
Encode the input point into the linear Hilbert distance.
Implementation of the Morton SFC.
Definition EBGeometry_SFC.hpp:72
static Index decode(const uint64_t &a_code) noexcept
Decode the 64-bit Morton code into an Index.
static constexpr uint_fast64_t Mask_64[6]
Mask for magic-bits encoding of 3D Morton code.
Definition EBGeometry_SFC.hpp:94
static uint64_t encode(const Index &a_point) noexcept
Encode an input point into a Morton index with a 64-bit representation.
Implementation of a nested index SFC.
Definition EBGeometry_SFC.hpp:103
static Index decode(const uint64_t &a_code) noexcept
Decode the 64-bit SFC code into an Index.
static uint64_t encode(const Index &a_point) noexcept
Encode the input point into the SFC code.