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> 52 template <
typename ContainerT>
71 for (
unsigned char b = 0; b < 2; ++b)
72 for (
unsigned char i = 0; i < 8; ++i)
95 getChildPtr(
unsigned char buffer_arg,
unsigned char index_arg)
const 97 assert((buffer_arg < 2) && (index_arg < 8));
108 unsigned char index_arg,
111 assert((buffer_arg < 2) && (index_arg < 8));
121 hasChild(
unsigned char buffer_arg,
unsigned char index_arg)
const 123 assert((buffer_arg < 2) && (index_arg < 8));
215 template <
typename LeafContainerT = int,
239 begin(
unsigned int max_depth_arg = 0)
241 return Iterator(
this, max_depth_arg);
396 createLeaf(
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
406 findLeaf(
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
416 unsigned int idx_y_arg,
417 unsigned int idx_z_arg)
const;
425 removeLeaf(
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
480 bool do_XOR_encoding_arg =
false);
494 std::vector<LeafContainerT*>& leaf_container_vector_arg,
495 bool do_XOR_encoding_arg =
false);
503 serializeLeafs(std::vector<LeafContainerT*>& leaf_container_vector_arg);
522 bool do_XOR_decoding_arg =
false);
535 std::vector<LeafContainerT*>& leaf_container_vector_arg,
536 bool do_XOR_decoding_arg =
false);
555 inline LeafContainerT*
558 LeafContainerT* result =
nullptr;
569 inline LeafContainerT*
590 return (
findLeaf(key_arg) !=
nullptr);
641 unsigned char child_idx_arg,
659 for (
unsigned char i = 0; i < 8; i++) {
661 node_bits |=
static_cast<char>((!!child) << i);
675 unsigned char bufferSelector_arg)
const 681 for (
unsigned char i = 0; i < 8; i++) {
683 node_bits |=
static_cast<char>((!!child) << i);
700 node_bits[0] = node_bits[1] = 0;
702 for (
unsigned char i = 0; i < 8; i++) {
706 node_bits[0] |=
static_cast<char>((!!childA) << i);
707 node_bits[1] |=
static_cast<char>((!!childB) << i);
710 return node_bits[0] ^ node_bits[1];
731 unsigned char buffer_selector_arg,
732 unsigned char child_idx_arg)
734 if (branch_arg.
hasChild(buffer_selector_arg, child_idx_arg)) {
736 branch_arg.
getChildPtr(buffer_selector_arg, child_idx_arg);
744 delete (branchChild);
750 delete (branchChild);
758 branch_arg.
setChildPtr(buffer_selector_arg, child_idx_arg,
nullptr);
779 for (
char i = 0; i < 8; i++) {
807 buffer_selector_, child_idx_arg, static_cast<OctreeNode*>(new_branch_child));
809 return new_branch_child;
824 return new_leaf_child;
844 unsigned int depth_mask_arg,
848 bool branch_reset_arg =
false);
860 unsigned int depth_mask_arg,
862 LeafContainerT*& result_arg)
const;
874 unsigned int depth_mask_arg,
894 std::vector<char>* binary_tree_out_arg,
895 typename std::vector<LeafContainerT*>* leaf_container_vector_arg,
896 bool do_XOR_encoding_arg =
false,
897 bool new_leafs_filter_arg =
false);
918 unsigned int depth_mask_arg,
920 typename std::vector<char>::const_iterator& binary_tree_in_it_arg,
921 typename std::vector<char>::const_iterator& binary_tree_in_it_end_arg,
922 typename std::vector<LeafContainerT*>::const_iterator*
923 leaf_container_vector_it_arg,
924 typename std::vector<LeafContainerT*>::const_iterator*
925 leaf_container_vector_it_end_arg,
926 bool branch_reset_arg =
false,
927 bool do_XOR_decoding_arg =
false);
961 return std::log2(n_arg);
980 unsigned char mask = 1;
983 for (
int i = 0; i < 8; i++) {
985 std::cout << ((data_arg & (mask << i)) ?
"1" :
"0");
987 std::cout << std::endl;
1025 #ifdef PCL_NO_PRECOMPILE 1026 #include <pcl/octree/impl/octree2buf_base.hpp> LeafContainerT * createLeaf(const OctreeKey &key_arg)
Create a leaf node.
double Log2(double n_arg)
Helper function to calculate the binary logarithm.
Octree2BufBase()
Empty constructor.
OctreeNode * getChildPtr(unsigned char buffer_arg, unsigned char index_arg) const
Get child pointer in current branch node.
void serializeLeafs(std::vector< LeafContainerT *> &leaf_container_vector_arg)
Outputs a vector of all DataT elements that are stored within the octree leaf nodes.
LeafNodeIterator leaf_begin(unsigned int max_depth_arg=0)
Octree2BufBase & operator=(const Octree2BufBase &source)
Copy constructor.
unsigned int createLeafRecursive(const OctreeKey &key_arg, unsigned int 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.
bool octreeCanResize()
Test if octree is able to dynamically change its depth.
void setTreeDepth(unsigned int depth_arg)
Set the maximum depth of the octree.
node_type_t getNodeType() const override
Get the type of octree node.
ContainerT * getContainerPtr()
Get pointer to container.
void treeCleanUpRecursive(BranchNode *branch_arg)
Recursively explore the octree and remove unused branch and leaf nodes.
unsigned int octree_depth_
Octree depth.
Octree2BufBase(const Octree2BufBase &source)
Copy constructor.
char getBranchBitPattern(const BranchNode &branch_arg) const
Generate bit pattern reflecting the existence of child node pointers for current buffer.
OctreeLeafNode< LeafContainerT > LeafNode
virtual node_type_t getNodeType() const =0
Pure virtual method for receiving the type of octree node (branch or leaf)
const DepthFirstIterator depth_end()
const ContainerT & operator*() const
Get const reference to container.
void setBranchChildPtr(BranchNode &branch_arg, unsigned char child_idx_arg, OctreeNode *new_child_arg)
Assign new child node to branch.
bool branchHasChild(const BranchNode &branch_arg, unsigned char child_idx_arg) const
Check if branch is pointing to a particular child node.
LeafNode * createLeafChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Fetch and add a new leaf child to a branch class.
OctreeNode * getRootNode() const
Retrieve root node.
~BufferedBranchNode()
Empty constructor.
const LeafNodeBreadthIterator leaf_breadth_end()
OctreeKey max_key_
key range
void deleteBranch(BranchNode &branch_arg)
Delete branch and all its subchilds from octree (both buffers)
OctreeLeafNodeBreadthFirstIterator< OctreeT > LeafNodeBreadthIterator
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...
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.
void deserializeTreeRecursive(BranchNode *branch_arg, unsigned int 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...
BufferedBranchNode< BranchContainerT > BranchNode
OctreeBreadthFirstIterator< OctreeT > BreadthFirstIterator
void deleteTree()
Delete the octree structure and its leaf nodes.
void findLeafRecursive(const OctreeKey &key_arg, unsigned int depth_mask_arg, BranchNode *branch_arg, LeafContainerT *&result_arg) const
Recursively search for a given leaf node and return a pointer.
OctreeLeafNodeDepthFirstIterator< OctreeT > LeafNodeIterator
void switchBuffers()
Switch buffers and reset current octree structure.
BreadthFirstIterator breadth_begin(unsigned int max_depth_arg=0)
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
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.
void setMaxVoxelIndex(unsigned int max_voxel_index_arg)
Set the maximum amount of voxels per dimension.
bool dynamic_depth_enabled_
Enable dynamic_depth.
std::size_t getLeafCount() const
Return the amount of existing leafs in the octree.
LeafContainerT * createLeaf(unsigned int idx_x_arg, unsigned int idx_y_arg, unsigned int idx_z_arg)
Create new leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
virtual void deserializeTreeCallback(LeafContainerT &, const OctreeKey &)
Callback executed for every leaf node data during deserialization.
BufferedBranchNode()
Empty constructor.
const ContainerT & getContainer() const
Get const reference to container.
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...
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.
ContainerT * operator->()
Get pointer to container.
LeafNodeBreadthIterator leaf_breadth_begin(unsigned int max_depth_arg=0u)
std::size_t branch_count_
Amount of branch nodes.
void deletePreviousBuffer()
Delete octree structure of previous buffer.
OctreeDepthFirstIterator< OctreeT > DepthFirstIterator
const BreadthFirstIterator breadth_end()
bool existLeaf(unsigned int idx_x_arg, unsigned int idx_y_arg, unsigned int idx_z_arg) const
Check for the existence of leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
OctreeNode * getBranchChildPtr(const BranchNode &branch_arg, unsigned char child_idx_arg) const
Retrieve a child node pointer for child node at child_idx.
char getBranchXORBitPattern(const BranchNode &branch_arg) const
Generate XOR bit pattern reflecting differences between the two octree buffers.
virtual OctreeNode * deepCopy() const =0
Pure virtual method to perform a deep copy of the octree.
const LeafNodeDepthFirstIterator leaf_depth_end()
OctreeLeafNodeDepthFirstIterator< OctreeT > LeafNodeDepthFirstIterator
BufferedBranchNode * deepCopy() const override
Method to perform a deep copy of the octree.
Abstract octree leaf class
const ContainerT * operator->() const
Get const pointer to container.
LeafNodeDepthFirstIterator leaf_depth_begin(unsigned int max_depth_arg=0)
const LeafNodeIterator leaf_end()
unsigned char buffer_selector_
Currently active octree buffer.
Iterator begin(unsigned int max_depth_arg=0)
void printBinary(char data_arg)
Prints binary representation of a byte - used for debugging.
const ContainerT * getContainerPtr() const
Get const pointer to container.
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.
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.
std::size_t getBranchCount() const
Return the amount of existing branches in the octree.
#define PCL_DEPRECATED(Major, Minor, Message)
macro for compatibility across compilers and help remove old deprecated items for the Major...
BranchNode * root_node_
Pointer to root branch node of octree.
unsigned int depth_mask_
Depth mask based on octree 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.
void setChildPtr(unsigned char buffer_arg, unsigned char index_arg, OctreeNode *newNode_arg)
Set child pointer in current branch node.
bool hasBranchChanges(const BranchNode &branch_arg) const
Test if branch changed between previous and current buffer.
DepthFirstIterator depth_begin(unsigned int maxDepth_arg=0)
LeafContainerT * findLeaf(const OctreeKey &key_arg) const
Find leaf node.
Octree container class that does not store any information.
bool existLeaf(const OctreeKey &key_arg) const
Check if leaf doesn't exist in the octree.
const ContainerT * getContainerPtr() const
Get const pointer to container.
OctreeNode * child_node_array_[2][8]
LeafContainerT * findLeaf(unsigned int idx_x_arg, unsigned int idx_y_arg, unsigned int idx_z_arg)
Find leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
Abstract octree node class
std::size_t leaf_count_
Amount of leaf nodes.
Defines all the PCL and non-PCL macros used.
void removeLeaf(unsigned int idx_x_arg, unsigned int idx_y_arg, unsigned int idx_z_arg)
Remove leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
unsigned int getTreeDepth() const
Get the maximum depth of the octree.
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.
bool deleteLeafRecursive(const OctreeKey &key_arg, unsigned int depth_mask_arg, BranchNode *branch_arg)
Recursively search and delete leaf node.
bool hasChild(unsigned char buffer_arg, unsigned char index_arg) const
Check if branch is pointing to a particular child node.