EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_Octree.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
11#ifndef EBGEOMETRY_OCTREE_HPP
12#define EBGEOMETRY_OCTREE_HPP
13
14// Std includes
15#include <array>
16#include <cstddef>
17#include <functional>
18#include <memory>
19
20// Our includes
21#include "EBGeometry_Macros.hpp"
22#include "EBGeometry_Vec.hpp"
23
24namespace EBGeometry {
25
29namespace Octree {
30
34enum OctantIndex : size_t
35{
36 BottomLeftFront = 0,
37 BottomRightFront = 1,
38 BottomLeftBack = 2,
39 BottomRightBack = 3,
40 TopLeftFront = 4,
41 TopRightFront = 5,
42 TopLeftBack = 6,
43 TopRightBack = 7
44};
45
49template <typename T>
50constexpr std::array<Vec3T<T>, 8> LowCorner = {Vec3T<T>(0.0, 0.0, 0.0),
51 Vec3T<T>(0.5, 0.0, 0.0),
52 Vec3T<T>(0.0, 0.5, 0.0),
53 Vec3T<T>(0.5, 0.5, 0.0),
54 Vec3T<T>(0.0, 0.0, 0.5),
55 Vec3T<T>(0.5, 0.0, 0.5),
56 Vec3T<T>(0.0, 0.5, 0.5),
57 Vec3T<T>(0.5, 0.5, 0.5)};
58
62template <typename T>
63constexpr std::array<Vec3T<T>, 8> HighCorner = {LowCorner<T>[0] + 0.5 * Vec3T<T>::ones(),
64 LowCorner<T>[1] + 0.5 * Vec3T<T>::ones(),
65 LowCorner<T>[2] + 0.5 * Vec3T<T>::ones(),
66 LowCorner<T>[3] + 0.5 * Vec3T<T>::ones(),
67 LowCorner<T>[4] + 0.5 * Vec3T<T>::ones(),
68 LowCorner<T>[5] + 0.5 * Vec3T<T>::ones(),
69 LowCorner<T>[6] + 0.5 * Vec3T<T>::ones(),
70 LowCorner<T>[7] + 0.5 * Vec3T<T>::ones()};
71
79template <typename Meta, typename Data = void>
80class Node : public std::enable_shared_from_this<Node<Meta, Data>>
81{
82public:
89 using SplitFunction = std::function<bool(const Node<Meta, Data>& a_node)>;
90
96 using MetaConstructor = std::function<Meta(const OctantIndex& a_index, const Meta& a_parentMeta)>;
97
104 std::function<std::shared_ptr<Data>(const OctantIndex& a_index, const std::shared_ptr<Data>& a_parentData)>;
105
110 using LeafEvaluator = std::function<void(const Node<Meta, Data>& a_node)>;
111
117 using PrunePredicate = std::function<bool(const Node<Meta, Data>& a_node)>;
118
123 using ChildOrderer = std::function<void(std::array<std::shared_ptr<const Node<Meta, Data>>, 8>& a_children)>;
124
129 Node() = default;
130
137 Node(const Node& a_other) = default;
138
143 Node(Node&& a_other) = default;
144
148 ~Node() = default;
149
156 Node&
157 operator=(const Node& a_other) = default;
158
164 Node&
165 operator=(Node&& a_other) = default;
166
171 [[nodiscard]] inline const std::array<std::shared_ptr<Node<Meta, Data>>, 8>&
173
178 [[nodiscard]] inline std::array<std::shared_ptr<Node<Meta, Data>>, 8>&
180
187
194
199 [[nodiscard]] inline std::shared_ptr<Data>&
201
206 [[nodiscard]] inline const std::shared_ptr<Data>&
208
213 [[nodiscard]] inline bool
215
224 inline void
228
239 inline void
243
253 inline void
257 const ChildOrderer& a_childOrderer = [](std::array<std::shared_ptr<const Node<Meta, Data>>, 8>&) -> void {
258 return;
259 }) const noexcept;
260
261protected:
267
271 std::shared_ptr<Data> m_data;
272
276 std::array<std::shared_ptr<Node<Meta, Data>>, 8> m_children;
277};
278} // namespace Octree
279
280} // namespace EBGeometry
281
282#include "EBGeometry_OctreeImplem.hpp"
283
284#endif
Utility macros for EBGeometry.
Declaration of 2D and 3D point/vector classes with templated precision. Used with DCEL tools.
Octree class without anything special (this uses full tree representation rather than linear/pointerl...
Definition EBGeometry_Octree.hpp:81
std::function< void(std::array< std::shared_ptr< const Node< Meta, Data > >, 8 > &a_children)> ChildOrderer
ChildOrderer for traverse pattern. This is called on interior nodes for deciding which sub-tree to vi...
Definition EBGeometry_Octree.hpp:123
std::function< void(const Node< Meta, Data > &a_node)> LeafEvaluator
LeafEvaluator pattern for Node::traverse. This is called when visiting a leaf node.
Definition EBGeometry_Octree.hpp:110
void buildDepthFirst(const SplitFunction &a_splitFunction, const MetaConstructor &a_metaConstructor, const DataConstructor &a_dataConstructor) noexcept
Build the octree in depth-first order.
std::array< std::shared_ptr< Node< Meta, Data > >, 8 > m_children
Node children.
Definition EBGeometry_Octree.hpp:276
Node(const Node &a_other)=default
Copy constructor.
void traverse(const LeafEvaluator &a_leafEvaluator, const PrunePredicate &a_prunePredicate, const ChildOrderer &a_childOrderer=[](std::array< std::shared_ptr< const Node< Meta, Data > >, 8 > &) -> void { return;}) const noexcept
Traverse the tree.
std::function< bool(const Node< Meta, Data > &a_node)> SplitFunction
Predicate for deciding whether a leaf node should be subdivided further.
Definition EBGeometry_Octree.hpp:89
std::shared_ptr< Data > & getData() noexcept
Get node data.
void buildBreadthFirst(const SplitFunction &a_splitFunction, const MetaConstructor &a_metaConstructor, const DataConstructor &a_dataConstructor) noexcept
Build the octree in breadth-first order.
Node & operator=(Node &&a_other)=default
Move assignment.
Meta & getMetaData() noexcept
Get node meta-data.
std::function< Meta(const OctantIndex &a_index, const Meta &a_parentMeta)> MetaConstructor
For assigning meta-data to the child octs during the build process.
Definition EBGeometry_Octree.hpp:96
Meta m_meta
Meta-data for the node. This is typically the lower-left and upper-right corners of the node,...
Definition EBGeometry_Octree.hpp:266
std::function< bool(const Node< Meta, Data > &a_node)> PrunePredicate
PrunePredicate pattern for Node::traverse. This is called on interior and leaf nodes....
Definition EBGeometry_Octree.hpp:117
Node & operator=(const Node &a_other)=default
Copy assignment.
std::shared_ptr< Data > m_data
Node contents.
Definition EBGeometry_Octree.hpp:271
const std::array< std::shared_ptr< Node< Meta, Data > >, 8 > & getChildren() const noexcept
Get children.
bool isLeaf() const noexcept
Check if this is a leaf node.
Node(Node &&a_other)=default
Move constructor.
Node()=default
Default constructor. All children default-null (leaf node); m_meta and m_data are default-constructed...
~Node()=default
Destructor.
std::function< std::shared_ptr< Data >(const OctantIndex &a_index, const std::shared_ptr< Data > &a_parentData)> DataConstructor
For assigning data to child octs during the build process.
Definition EBGeometry_Octree.hpp:104
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:225
static constexpr Vec3T< T > ones() noexcept
Return a vector with x = y = z = 1.
constexpr std::array< Vec3T< T >, 8 > HighCorner
Upper-right corners of the octants on the unit cube, indexed lexicographically in x-y-z.
Definition EBGeometry_Octree.hpp:63
OctantIndex
Lexicographical x-y-z octant indexing.
Definition EBGeometry_Octree.hpp:35
constexpr std::array< Vec3T< T >, 8 > LowCorner
Lower-left corners of the octants on the unit cube, indexed lexicographically in x-y-z.
Definition EBGeometry_Octree.hpp:50
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:31