EBGeometry 1.0
Loading...
Searching...
No Matches
EBGeometry_Octree.hpp
Go to the documentation of this file.
1/* EBGeometry
2 * Copyright © 2023 Robert Marskar
3 * Please refer to Copyright.txt and LICENSE in the EBGeometry root directory.
4 */
5
12#ifndef EBGeometry_Octree
13#define EBGeometry_Octree
14
15// Std includes
16#include <array>
17#include <functional>
18#include <memory>
19
20// Our includes
21#include "EBGeometry_Vec.hpp"
23
27namespace Octree {
31 enum OctantIndex : size_t
32 {
33 BottomLeftFront = 0,
34 BottomRightFront = 1,
35 BottomLeftBack = 2,
36 BottomRightBack = 3,
37 TopLeftFront = 4,
38 TopRightFront = 5,
39 TopLeftBack = 6,
40 TopRightBack = 7
41 };
42
46 template <typename T>
47 constexpr std::array<Vec3T<T>, 8> LowCorner = {Vec3T<T>(0.0, 0.0, 0.0),
48 Vec3T<T>(0.5, 0.0, 0.0),
49 Vec3T<T>(0.0, 0.5, 0.0),
50 Vec3T<T>(0.5, 0.5, 0.0),
51 Vec3T<T>(0.0, 0.0, 0.5),
52 Vec3T<T>(0.5, 0.0, 0.5),
53 Vec3T<T>(0.0, 0.5, 0.5),
54 Vec3T<T>(0.5, 0.5, 0.5)};
55
59 template <typename T>
60 constexpr std::array<Vec3T<T>, 8> HighCorner = {LowCorner<T>[0] + 0.5 * Vec3T<T>::one(),
61 LowCorner<T>[1] + 0.5 * Vec3T<T>::one(),
62 LowCorner<T>[2] + 0.5 * Vec3T<T>::one(),
63 LowCorner<T>[3] + 0.5 * Vec3T<T>::one(),
64 LowCorner<T>[4] + 0.5 * Vec3T<T>::one(),
65 LowCorner<T>[5] + 0.5 * Vec3T<T>::one(),
66 LowCorner<T>[6] + 0.5 * Vec3T<T>::one(),
67 LowCorner<T>[7] + 0.5 * Vec3T<T>::one()};
68
74 template <typename Meta, typename Data = void>
75 class Node : public std::enable_shared_from_this<Node<Meta, Data>>
76 {
77 public:
83 using StopFunction = std::function<bool(const Node<Meta, Data>& a_node)>;
84
90 using MetaConstructor = std::function<Meta(const OctantIndex& a_index, const Meta& a_parentMeta)>;
91
98 std::function<std::shared_ptr<Data>(const OctantIndex& a_index, const std::shared_ptr<Data>& a_parentData)>;
99
104 using Updater = std::function<void(const Node<Meta, Data>& a_node)>;
105
111 using Visiter = std::function<bool(const Node<Meta, Data>& a_node)>;
112
117 using Sorter = std::function<void(std::array<std::shared_ptr<const Node<Meta, Data>>, 8>& a_children)>;
118
123
127 virtual ~Node();
128
133 inline const std::array<std::shared_ptr<Node<Meta, Data>>, 8>&
135
140 inline std::array<std::shared_ptr<Node<Meta, Data>>, 8>&
142
147 inline Meta&
149
156
161 inline std::shared_ptr<Data>&
163
170
174 inline bool
176
183 inline void
187
194 inline void
198
205 inline void
209 const Sorter& a_sorter = [](std::array<std::shared_ptr<const Node<Meta, Data>>, 8>& a_children) -> void {
210 return;
211 }) const noexcept;
212
213 protected:
219
223 std::shared_ptr<Data> m_data;
224
228 std::array<std::shared_ptr<Node<Meta, Data>>, 8> m_children;
229 };
230} // namespace Octree
231
233
234#include "EBGeometry_OctreeImplem.hpp"
235
236#endif
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:76
std::function< void(std::array< std::shared_ptr< const Node< Meta, Data > >, 8 > &a_children)> Sorter
Sorter for traverse pattern. This is called on interior nodes for deciding which sub-tree to visit fi...
Definition EBGeometry_Octree.hpp:117
std::function< void(const Node< Meta, Data > &a_node)> Updater
Updater pattern for Node::traverse. This is called when visiting a leaf node.
Definition EBGeometry_Octree.hpp:104
void buildBreadthFirst(const StopFunction &a_stopFunction, const MetaConstructor &a_metaConstructor, const DataConstructor &a_dataConstructor) noexcept
Build the octree in breadth-first order. User decides if the node should be split,...
Node()
Default constructor.
void traverse(const Updater &a_updater, const Visiter &a_visiter, const Sorter &a_sorter=[](std::array< std::shared_ptr< const Node< Meta, Data > >, 8 > &a_children) -> void { return;}) const noexcept
Traverse the tree.
const std::array< std::shared_ptr< Node< Meta, Data > >, 8 > & getChildren() const noexcept
Get children.
std::function< bool(const Node< Meta, Data > &a_node)> StopFunction
Function for deciding whether or not to split a node.
Definition EBGeometry_Octree.hpp:83
bool isLeaf() const noexcept
Check if this is a leaf node.
void buildDepthFirst(const StopFunction &a_stopFunction, const MetaConstructor &a_metaConstructor, const DataConstructor &a_dataConstructor) noexcept
Build the octree in depth-first order. User decides if the node should be split, and how to split it.
std::function< bool(const Node< Meta, Data > &a_node)> Visiter
Visiter pattern for Node::traverse. This is called on interior and leaf nodes. Must return true if we...
Definition EBGeometry_Octree.hpp:111
virtual ~Node()
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:98
std::shared_ptr< Data > m_data
Node contents.
Definition EBGeometry_Octree.hpp:223
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:90
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:218
std::shared_ptr< Data > & getData() noexcept
Get node data.
std::array< std::shared_ptr< Node< Meta, Data > >, 8 > m_children
Node children.
Definition EBGeometry_Octree.hpp:228
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:218
static constexpr Vec3T< T > one() noexcept
Return av vector with x = y = z = 1.
Namespace for octree functionality.
Definition EBGeometry_Octree.hpp:27
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:47
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:60
OctantIndex
Lexicographical x-y-z octant indexing.
Definition EBGeometry_Octree.hpp:32