41 #include <pcl/octree/octree_container.h>
42 #include <pcl/octree/octree_iterator.h>
43 #include <pcl/octree/octree_key.h>
44 #include <pcl/octree/octree_nodes.h>
45 #include <pcl/pcl_macros.h>
53 template <
typename ContainerT>
71 for (
unsigned char b = 0; b < 2; ++b) {
72 for (
unsigned char i = 0; i < 8; ++i) {
97 getChildPtr(
unsigned char buffer_arg,
unsigned char index_arg)
const
99 assert((buffer_arg < 2) && (index_arg < 8));
110 unsigned char index_arg,
113 assert((buffer_arg < 2) && (index_arg < 8));
123 hasChild(
unsigned char buffer_arg,
unsigned char index_arg)
const
125 assert((buffer_arg < 2) && (index_arg < 8));
202 template <
typename T, std::
size_t ROW, std::
size_t COL>
220 template <
typename LeafContainerT =
index_t,
221 typename BranchContainerT = OctreeContainerEmpty>
246 return Iterator(
this, max_depth_arg);
469 bool do_XOR_encoding_arg =
false);
483 std::vector<LeafContainerT*>& leaf_container_vector_arg,
484 bool do_XOR_encoding_arg =
false);
492 serializeLeafs(std::vector<LeafContainerT*>& leaf_container_vector_arg);
511 bool do_XOR_decoding_arg =
false);
524 std::vector<LeafContainerT*>& leaf_container_vector_arg,
525 bool do_XOR_decoding_arg =
false);
544 inline LeafContainerT*
547 LeafContainerT* result =
nullptr;
558 inline LeafContainerT*
579 return (
findLeaf(key_arg) !=
nullptr);
630 unsigned char child_idx_arg,
648 for (
unsigned char i = 0; i < 8; i++) {
650 node_bits |=
static_cast<char>((!!child) << i);
664 unsigned char bufferSelector_arg)
const
670 for (
unsigned char i = 0; i < 8; i++) {
672 node_bits |=
static_cast<char>((!!child) << i);
689 node_bits[0] = node_bits[1] = 0;
691 for (
unsigned char i = 0; i < 8; i++) {
695 node_bits[0] |=
static_cast<char>((!!childA) << i);
696 node_bits[1] |=
static_cast<char>((!!childB) << i);
699 return node_bits[0] ^ node_bits[1];
720 unsigned char buffer_selector_arg,
721 unsigned char child_idx_arg)
723 if (branch_arg.
hasChild(buffer_selector_arg, child_idx_arg)) {
725 branch_arg.
getChildPtr(buffer_selector_arg, child_idx_arg);
733 delete (branchChild);
739 delete (branchChild);
747 branch_arg.
setChildPtr(buffer_selector_arg, child_idx_arg,
nullptr);
768 for (
char i = 0; i < 8; i++) {
796 buffer_selector_, child_idx_arg, static_cast<OctreeNode*>(new_branch_child));
798 return new_branch_child;
809 auto* new_leaf_child =
new LeafNode();
813 return new_leaf_child;
837 bool branch_reset_arg =
false);
851 LeafContainerT*& result_arg)
const;
883 std::vector<char>* binary_tree_out_arg,
884 typename std::vector<LeafContainerT*>* leaf_container_vector_arg,
885 bool do_XOR_encoding_arg =
false,
886 bool new_leafs_filter_arg =
false);
909 typename std::vector<char>::const_iterator& binary_tree_in_it_arg,
910 typename std::vector<char>::const_iterator& binary_tree_in_it_end_arg,
911 typename std::vector<LeafContainerT*>::const_iterator*
912 leaf_container_vector_it_arg,
913 typename std::vector<LeafContainerT*>::const_iterator*
914 leaf_container_vector_it_end_arg,
915 bool branch_reset_arg =
false,
916 bool do_XOR_decoding_arg =
false);
960 unsigned char mask = 1;
963 for (
int i = 0; i < 8; i++) {
965 std::cout << ((data_arg & (mask << i)) ?
"1" :
"0");
967 std::cout << std::endl;
1006 #ifdef PCL_NO_PRECOMPILE
1007 #include <pcl/octree/impl/octree2buf_base.hpp>
LeafContainerT * createLeaf(const OctreeKey &key_arg)
Create a leaf node.
Octree2BufBase()
Empty constructor.
Octree2BufBase & operator=(const Octree2BufBase &source)
Copy constructor.
OctreeNode * getRootNode() const
Retrieve root node.
uindex_t getTreeDepth() const
Get the maximum depth of the octree.
void setTreeDepth(uindex_t depth_arg)
Set the maximum depth of the octree.
void findLeafRecursive(const OctreeKey &key_arg, uindex_t depth_mask_arg, BranchNode *branch_arg, LeafContainerT *&result_arg) const
Recursively search for a given leaf node and return a pointer.
bool octreeCanResize()
Test if octree is able to dynamically change its depth.
bool existLeaf(uindex_t idx_x_arg, uindex_t idx_y_arg, uindex_t idx_z_arg) const
Check for the existence of leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
ContainerT * getContainerPtr()
Get pointer to container.
void treeCleanUpRecursive(BranchNode *branch_arg)
Recursively explore the octree and remove unused branch and leaf nodes.
Octree2BufBase(const Octree2BufBase &source)
Copy constructor.
std::size_t getBranchCount() const
Return the amount of existing branches in the octree.
LeafNodeBreadthIterator leaf_breadth_begin(uindex_t max_depth_arg=0u)
virtual node_type_t getNodeType() const =0
Pure virtual method for retrieving the type of octree node (branch or leaf)
OctreeLeafNode< LeafContainerT > LeafNode
const DepthFirstIterator depth_end()
LeafContainerT * findLeaf(uindex_t idx_x_arg, uindex_t idx_y_arg, uindex_t idx_z_arg)
Find leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
bool hasChild(unsigned char buffer_arg, unsigned char index_arg) const
Check if branch is pointing to a particular child node.
void setBranchChildPtr(BranchNode &branch_arg, unsigned char child_idx_arg, OctreeNode *new_child_arg)
Assign new child node to branch.
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
OctreeNode * getChildPtr(unsigned char buffer_arg, unsigned char index_arg) const
Get child pointer in current branch node.
OctreeNode * getBranchChildPtr(const BranchNode &branch_arg, unsigned char child_idx_arg) const
Retrieve a child node pointer for child node at child_idx.
LeafNode * createLeafChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Fetch and add a new leaf child to a branch class.
const LeafNodeBreadthIterator leaf_breadth_end()
OctreeKey max_key_
key range
bool tree_dirty_flag_
flags indicating if unused branches and leafs might exist in previous buffer
void deleteBranch(BranchNode &branch_arg)
Delete branch and all its subchilds from octree (both buffers)
void serializeTreeRecursive(BranchNode *branch_arg, OctreeKey &key_arg, std::vector< char > *binary_tree_out_arg, typename std::vector< LeafContainerT * > *leaf_container_vector_arg, bool do_XOR_encoding_arg=false, bool new_leafs_filter_arg=false)
Recursively explore the octree and output binary octree description together with a vector of leaf no...
OctreeLeafNodeBreadthFirstIterator< OctreeT > LeafNodeBreadthIterator
std::array< std::array< T, COL >, ROW > OctreeMatrix
void deserializeTree(std::vector< char > &binary_tree_in_arg, bool do_XOR_decoding_arg=false)
Deserialize a binary octree description vector and create a corresponding octree structure.
ContainerT & operator*()
Get reference to container.
void deleteBranchChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Delete child node and all its subchilds from octree in current buffer.
bool hasBranchChanges(const BranchNode &branch_arg) const
Test if branch changed between previous and current buffer.
BufferedBranchNode< BranchContainerT > BranchNode
OctreeBreadthFirstIterator< OctreeT > BreadthFirstIterator
uindex_t createLeafRecursive(const OctreeKey &key_arg, uindex_t depth_mask_arg, BranchNode *branch_arg, LeafNode *&return_leaf_arg, BranchNode *&parent_of_leaf_arg, bool branch_reset_arg=false)
Create a leaf node at octree key.
void deleteTree()
Delete the octree structure and its leaf nodes.
bool existLeaf(const OctreeKey &key_arg) const
Check if leaf doesn't exist in the octree.
void switchBuffers()
Switch buffers and reset current octree structure.
char getBranchBitPattern(const BranchNode &branch_arg) const
Generate bit pattern reflecting the existence of child node pointers for current buffer.
void serializeNewLeafs(std::vector< LeafContainerT * > &leaf_container_vector_arg)
Outputs a vector of all DataT elements from leaf nodes, that do not exist in the previous octree buff...
node_type_t getNodeType() const override
Get the type of octree node.
const ContainerT & operator*() const
Get const reference to container.
void removeLeaf(uindex_t idx_x_arg, uindex_t idx_y_arg, uindex_t idx_z_arg)
Remove leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
BufferedBranchNode * deepCopy() const override
Method to perform a deep copy of the octree.
void serializeTree(std::vector< char > &binary_tree_out_arg, bool do_XOR_encoding_arg=false)
Serialize octree into a binary output vector describing its branch node structure.
OctreeDepthFirstIterator< OctreeT > Iterator
bool branchHasChild(const BranchNode &branch_arg, unsigned char child_idx_arg) const
Check if branch is pointing to a particular child node.
virtual ~Octree2BufBase()
Empty deconstructor.
void deleteBranchChild(BranchNode &branch_arg, unsigned char buffer_selector_arg, unsigned char child_idx_arg)
Delete child node and all its subchilds from octree in specific buffer.
bool dynamic_depth_enabled_
Enable dynamic_depth.
char getBranchBitPattern(const BranchNode &branch_arg, unsigned char bufferSelector_arg) const
Generate bit pattern reflecting the existence of child node pointers in specific buffer.
const ContainerT & getContainer() const
Get const reference to container.
virtual void deserializeTreeCallback(LeafContainerT &, const OctreeKey &)
Callback executed for every leaf node data during deserialization.
BufferedBranchNode()
Empty constructor.
DepthFirstIterator depth_begin(uindex_t maxDepth_arg=0)
const ContainerT * getContainerPtr() const
Get const pointer to container.
void deleteCurrentBuffer()
Delete the octree structure in the current buffer.
Octree container class that does store a vector of point indices.
Octree leaf node iterator class.
BreadthFirstIterator breadth_begin(uindex_t max_depth_arg=0)
ContainerT * operator->()
Get pointer to container.
std::size_t branch_count_
Amount of branch nodes.
void deletePreviousBuffer()
Delete octree structure of previous buffer.
OctreeDepthFirstIterator< OctreeT > DepthFirstIterator
const BreadthFirstIterator breadth_end()
void setMaxVoxelIndex(uindex_t max_voxel_index_arg)
Set the maximum amount of voxels per dimension.
void serializeLeafs(std::vector< LeafContainerT * > &leaf_container_vector_arg)
Outputs a vector of all DataT elements that are stored within the octree leaf nodes.
OctreeMatrix< OctreeNode *, 2, 8 > child_node_array_
~BufferedBranchNode() override=default
Empty constructor.
std::size_t getLeafCount() const
Return the amount of existing leafs in the octree.
LeafContainerT * createLeaf(uindex_t idx_x_arg, uindex_t idx_y_arg, uindex_t idx_z_arg)
Create new leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
uindex_t depth_mask_
Depth mask based on octree depth.
const LeafNodeDepthFirstIterator leaf_depth_end()
OctreeLeafNodeDepthFirstIterator< OctreeT > LeafNodeDepthFirstIterator
Abstract octree leaf class
void deserializeTreeRecursive(BranchNode *branch_arg, uindex_t depth_mask_arg, OctreeKey &key_arg, typename std::vector< char >::const_iterator &binary_tree_in_it_arg, typename std::vector< char >::const_iterator &binary_tree_in_it_end_arg, typename std::vector< LeafContainerT * >::const_iterator *leaf_container_vector_it_arg, typename std::vector< LeafContainerT * >::const_iterator *leaf_container_vector_it_end_arg, bool branch_reset_arg=false, bool do_XOR_decoding_arg=false)
Rebuild an octree based on binary XOR octree description and DataT objects for leaf node initializati...
bool deleteLeafRecursive(const OctreeKey &key_arg, uindex_t depth_mask_arg, BranchNode *branch_arg)
Recursively search and delete leaf node.
uindex_t octree_depth_
Octree depth.
char getBranchXORBitPattern(const BranchNode &branch_arg) const
Generate XOR bit pattern reflecting differences between the two octree buffers.
unsigned char buffer_selector_
Currently active octree buffer.
LeafNodeDepthFirstIterator leaf_depth_begin(uindex_t max_depth_arg=0)
const ContainerT * getContainerPtr() const
Get const pointer to container.
void printBinary(char data_arg)
Prints binary representation of a byte - used for debugging.
virtual void serializeTreeCallback(LeafContainerT &, const OctreeKey &)
Callback executed for every leaf node data during serialization.
Abstract octree iterator class
ContainerT & getContainer()
Get reference to container.
LeafContainerT * findLeaf(const OctreeKey &key_arg) const
Find leaf node.
Octree double buffer class
void removeLeaf(const OctreeKey &key_arg)
Remove leaf node from octree.
BranchNode * createBranchChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Fetch and add a new branch child to a branch class in current buffer.
Iterator begin(uindex_t max_depth_arg=0)
BranchNode * root_node_
Pointer to root branch node of octree.
const ContainerT * operator->() const
Get const pointer to container.
void setChildPtr(unsigned char buffer_arg, unsigned char index_arg, OctreeNode *newNode_arg)
Set child pointer in current branch node.
detail::int_type_t< detail::index_type_size, false > uindex_t
Type used for an unsigned index in PCL.
Octree container class that does not store any information.
Abstract octree node class
std::size_t leaf_count_
Amount of leaf nodes.
BufferedBranchNode(const BufferedBranchNode &source)
Copy constructor.
void reset()
Reset branch node container for every branch buffer.
BufferedBranchNode & operator=(const BufferedBranchNode &source_arg)
Copy operator.
Octree leaf node iterator class.