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 <cstdint>
16#include <vector>
17
18// Our includes
19#include "EBGeometry_Array.hpp"
20#include "EBGeometry_GPU.hpp"
21#include "EBGeometry_Vec.hpp"
22
23namespace EBGeometry {
24
46namespace SFC {
47
51using Code = uint64_t;
52
57
62static constexpr unsigned int ValidBits = 21;
63
67static constexpr Code ValidSpan = (static_cast<uint64_t>(1) << ValidBits) - 1;
68
72struct Morton
73{
79 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
80 inline static uint64_t
81 encode(const Index& a_point) noexcept;
82
89 [[nodiscard]] inline static Index
90 decode(const uint64_t& a_code) noexcept;
91
92protected:
96 static constexpr uint_fast64_t Mask_64[6]{
97 0x1fffff, 0x1f00000000ffff, 0x1f0000ff0000ff, 0x100f00f00f00f00f, 0x10c30c30c30c30c3, 0x1249249249249249};
98};
99
105struct Nested
106{
112 [[nodiscard]] inline static uint64_t
113 encode(const Index& a_point) noexcept;
114
121 [[nodiscard]] inline static Index
122 decode(const uint64_t& a_code) noexcept;
123};
124
137{
143 [[nodiscard]] inline static uint64_t
144 encode(const Index& a_point) noexcept;
145
152 [[nodiscard]] inline static Index
153 decode(const uint64_t& a_code) noexcept;
154};
155
172template <class T>
173[[nodiscard]] inline std::vector<Index>
174computeBins(const std::vector<Vec3T<T>>& a_points);
175
189template <class Curve = Morton, class T>
190[[nodiscard]] inline std::vector<uint32_t>
191order(const std::vector<Vec3T<T>>& a_points);
192
193} // namespace SFC
194
195} // namespace EBGeometry
196
197#include "EBGeometry_SFCImplem.hpp"
198
199#endif
A fixed-size array that compiles for both host and device.
GPU portability layer: host/device decoration macros and backend detection.
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
std::vector< Index > computeBins(const std::vector< Vec3T< T > > &a_points)
Bin a set of points into the space-filling curve's integer grid, normalizing by their own bounding ra...
uint64_t Code
Alias for SFC code.
Definition EBGeometry_SFC.hpp:51
std::vector< uint32_t > order(const std::vector< Vec3T< T > > &a_points)
Return the index permutation that orders a_points along a space-filling curve.
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Fixed-size array with host- and device-callable members.
Definition EBGeometry_Array.hpp:33
Implementation of the 3D Hilbert space-filling curve.
Definition EBGeometry_SFC.hpp:137
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:73
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:96
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:106
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.