EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
EBGeometry::Octree::Node< Meta, Data > Class Template Reference

Octree class without anything special (this uses full tree representation rather than linear/pointerless). More...

#include <EBGeometry_Octree.hpp>

Inheritance diagram for EBGeometry::Octree::Node< Meta, Data >:
Inheritance graph
[legend]
Collaboration diagram for EBGeometry::Octree::Node< Meta, Data >:
Collaboration graph
[legend]

Public Types

using SplitFunction = std::function< bool(const Node< Meta, Data > &a_node)>
 Predicate for deciding whether a leaf node should be subdivided further.
 
using MetaConstructor = std::function< Meta(const OctantIndex &a_index, const Meta &a_parentMeta)>
 For assigning meta-data to the child octs during the build process.
 
using DataConstructor = std::function< std::shared_ptr< Data >(const OctantIndex &a_index, const std::shared_ptr< Data > &a_parentData)>
 For assigning data to child octs during the build process.
 
using LeafEvaluator = std::function< void(const Node< Meta, Data > &a_node)>
 LeafEvaluator pattern for Node::traverse. This is called when visiting a leaf node.
 
using PrunePredicate = std::function< bool(const Node< Meta, Data > &a_node)>
 PrunePredicate pattern for Node::traverse. This is called on interior and leaf nodes. Must return true if we should query the node and false otherwise.
 
using ChildOrderer = std::function< void(std::array< std::shared_ptr< const Node< Meta, Data > >, 8 > &a_children)>
 ChildOrderer for traverse pattern. This is called on interior nodes for deciding which sub-tree to visit first.
 

Public Member Functions

 Node ()=default
 Default constructor. All children default-null (leaf node); m_meta and m_data are default-constructed.
 
 Node (const Node &a_other)=default
 Copy constructor.
 
 Node (Node &&a_other)=default
 Move constructor.
 
 ~Node ()=default
 Destructor.
 
Nodeoperator= (const Node &a_other)=default
 Copy assignment.
 
Nodeoperator= (Node &&a_other)=default
 Move assignment.
 
const std::array< std::shared_ptr< Node< Meta, Data > >, 8 > & getChildren () const noexcept
 Get children.
 
std::array< std::shared_ptr< Node< Meta, Data > >, 8 > & getChildren () noexcept
 Get children.
 
MetagetMetaData () noexcept
 Get node meta-data.
 
const MetagetMetaData () const noexcept
 Get node meta-data.
 
std::shared_ptr< Data > & getData () noexcept
 Get node data.
 
const std::shared_ptr< Data > & getData () const noexcept
 Get node data.
 
bool isLeaf () const noexcept
 Check if this is a leaf node.
 
void buildDepthFirst (const SplitFunction &a_splitFunction, const MetaConstructor &a_metaConstructor, const DataConstructor &a_dataConstructor) noexcept
 Build the octree in depth-first order.
 
void buildBreadthFirst (const SplitFunction &a_splitFunction, const MetaConstructor &a_metaConstructor, const DataConstructor &a_dataConstructor) noexcept
 Build the octree in breadth-first order.
 
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.
 

Protected Attributes

Meta m_meta
 Meta-data for the node. This is typically the lower-left and upper-right corners of the node, but it's the users' responsibility to fill this with the meta-information they need for the tree.
 
std::shared_ptr< Datam_data
 Node contents.
 
std::array< std::shared_ptr< Node< Meta, Data > >, 8 > m_children
 Node children.
 

Detailed Description

template<typename Meta, typename Data = void>
class EBGeometry::Octree::Node< Meta, Data >

Octree class without anything special (this uses full tree representation rather than linear/pointerless).

Meta is the meta-data for the node (user can put in e.g. level, volume, etc) and Data is the leaf node contents.

Note
This class should only be used with smart pointers. I.e. std::shared_ptr<Node> rather than Node.
Template Parameters
MetaMeta-data type stored in every node (e.g. an AABB or level index).
DataPayload type stored at leaf nodes.

Member Typedef Documentation

◆ ChildOrderer

template<typename Meta , typename Data = void>
using EBGeometry::Octree::Node< Meta, Data >::ChildOrderer = std::function<void(std::array<std::shared_ptr<const Node<Meta, Data> >, 8>& a_children)>

ChildOrderer for traverse pattern. This is called on interior nodes for deciding which sub-tree to visit first.

Parameters
[in,out]a_childrenSortable children nodes, first node is visited first, then the second, etc.

◆ DataConstructor

template<typename Meta , typename Data = void>
using EBGeometry::Octree::Node< Meta, Data >::DataConstructor = std::function<std::shared_ptr<Data>(const OctantIndex& a_index, const std::shared_ptr<Data>& a_parentData)>

For assigning data to child octs during the build process.

Parameters
[in]a_indexOctant index
[in]a_parentDataParent data.

◆ LeafEvaluator

template<typename Meta , typename Data = void>
using EBGeometry::Octree::Node< Meta, Data >::LeafEvaluator = std::function<void(const Node<Meta, Data>& a_node)>

LeafEvaluator pattern for Node::traverse. This is called when visiting a leaf node.

Parameters
[in]a_nodeLeaf node that is visited.

◆ MetaConstructor

template<typename Meta , typename Data = void>
using EBGeometry::Octree::Node< Meta, Data >::MetaConstructor = std::function<Meta(const OctantIndex& a_index, const Meta& a_parentMeta)>

For assigning meta-data to the child octs during the build process.

Parameters
[in]a_indexOctant index
[in]a_parentMetaParent meta data

◆ PrunePredicate

template<typename Meta , typename Data = void>
using EBGeometry::Octree::Node< Meta, Data >::PrunePredicate = std::function<bool(const Node<Meta, Data>& a_node)>

PrunePredicate pattern for Node::traverse. This is called on interior and leaf nodes. Must return true if we should query the node and false otherwise.

Parameters
[in]a_nodeNode to visit or not.

◆ SplitFunction

template<typename Meta , typename Data = void>
using EBGeometry::Octree::Node< Meta, Data >::SplitFunction = std::function<bool(const Node<Meta, Data>& a_node)>

Predicate for deciding whether a leaf node should be subdivided further.

Called on each leaf node during tree construction. Returns true if the node should be split into eight children, false if it should remain a leaf.

Parameters
[in]a_nodeLeaf node under consideration.

Constructor & Destructor Documentation

◆ Node() [1/2]

template<typename Meta , typename Data = void>
EBGeometry::Octree::Node< Meta, Data >::Node ( const Node< Meta, Data > &  a_other)
default

Copy constructor.

Shallow copy: the copy shares ownership of a_other's children and data (standard std::shared_ptr semantics) rather than deep-cloning the subtree.

Parameters
[in]a_otherOther node.

◆ Node() [2/2]

template<typename Meta , typename Data = void>
EBGeometry::Octree::Node< Meta, Data >::Node ( Node< Meta, Data > &&  a_other)
default

Move constructor.

Parameters
[in,out]a_otherOther node.

Member Function Documentation

◆ buildBreadthFirst()

template<typename Meta , typename Data = void>
void EBGeometry::Octree::Node< Meta, Data >::buildBreadthFirst ( const SplitFunction a_splitFunction,
const MetaConstructor a_metaConstructor,
const DataConstructor a_dataConstructor 
)
inlinenoexcept

Build the octree in breadth-first order.

Must be called on a leaf node; calling it on an interior node is a no-op (with a diagnostic printed to stderr). All three callables must be non-empty (callable). Since this uses shared_from_this() internally, the node must already be owned by a std::shared_ptr (see the class-level

Note
).
Parameters
[in]a_splitFunctionPredicate returning true if a leaf node should be split further.
[in]a_metaConstructorConstructor for node meta-data.
[in]a_dataConstructorConstructor for node data.

◆ buildDepthFirst()

template<typename Meta , typename Data = void>
void EBGeometry::Octree::Node< Meta, Data >::buildDepthFirst ( const SplitFunction a_splitFunction,
const MetaConstructor a_metaConstructor,
const DataConstructor a_dataConstructor 
)
inlinenoexcept

Build the octree in depth-first order.

Must be called on a leaf node; calling it on an interior node is a no-op (with a diagnostic printed to stderr). All three callables must be non-empty (callable).

Parameters
[in]a_splitFunctionPredicate returning true if a leaf node should be split further.
[in]a_metaConstructorConstructor for node meta-data.
[in]a_dataConstructorConstructor for node data.

◆ getChildren() [1/2]

template<typename Meta , typename Data = void>
const std::array< std::shared_ptr< Node< Meta, Data > >, 8 > & EBGeometry::Octree::Node< Meta, Data >::getChildren ( ) const
inlinenoexcept

Get children.

Returns
m_children

◆ getChildren() [2/2]

template<typename Meta , typename Data = void>
std::array< std::shared_ptr< Node< Meta, Data > >, 8 > & EBGeometry::Octree::Node< Meta, Data >::getChildren ( )
inlinenoexcept

Get children.

Returns
m_children

◆ getData() [1/2]

template<typename Meta , typename Data = void>
const std::shared_ptr< Data > & EBGeometry::Octree::Node< Meta, Data >::getData ( ) const
inlinenoexcept

Get node data.

Returns
m_data

◆ getData() [2/2]

template<typename Meta , typename Data = void>
std::shared_ptr< Data > & EBGeometry::Octree::Node< Meta, Data >::getData ( )
inlinenoexcept

Get node data.

Returns
m_data

◆ getMetaData() [1/2]

template<typename Meta , typename Data = void>
const Meta & EBGeometry::Octree::Node< Meta, Data >::getMetaData ( ) const
inlinenoexcept

Get node meta-data.

Returns
m_meta

◆ getMetaData() [2/2]

template<typename Meta , typename Data = void>
Meta & EBGeometry::Octree::Node< Meta, Data >::getMetaData ( )
inlinenoexcept

Get node meta-data.

Returns
m_meta

◆ isLeaf()

template<typename Meta , typename Data = void>
bool EBGeometry::Octree::Node< Meta, Data >::isLeaf ( ) const
inlinenoexcept

Check if this is a leaf node.

Returns
True if this node has no children (i.e., it is a leaf).

◆ operator=() [1/2]

template<typename Meta , typename Data = void>
Node & EBGeometry::Octree::Node< Meta, Data >::operator= ( const Node< Meta, Data > &  a_other)
default

Copy assignment.

See the copy constructor for the shallow-copy semantics.

Parameters
[in]a_otherOther node.
Returns
Reference to (*this).

◆ operator=() [2/2]

template<typename Meta , typename Data = void>
Node & EBGeometry::Octree::Node< Meta, Data >::operator= ( Node< Meta, Data > &&  a_other)
default

Move assignment.

Parameters
[in,out]a_otherOther node.
Returns
Reference to (*this).

◆ traverse()

template<typename Meta , typename Data = void>
void EBGeometry::Octree::Node< Meta, Data >::traverse ( const LeafEvaluator a_leafEvaluator,
const PrunePredicate a_prunePredicate,
const ChildOrderer a_childOrderer = [](std::array< std::shared_ptr< const NodeMetaData > >, 8 > &) -> void { return;} 
) const
inlinenoexcept

Traverse the tree.

Since this uses shared_from_this() internally, the node must already be owned by a std::shared_ptr (see the class-level

Note
). a_leafEvaluator and a_prunePredicate must be non-empty (callable); a_childOrderer, if explicitly supplied, must be non-empty too.
Parameters
[in]a_leafEvaluatorLeafEvaluator when visiting leaf nodes.
[in]a_prunePredicatePrunePredicate for deciding to visit a node.
[in]a_childOrdererChildOrderer method for deciding which subtree to investigate first.

The documentation for this class was generated from the following file: