39 #ifndef PCL_OCTREE_TREE_2BUF_BASE_H
40 #define PCL_OCTREE_TREE_2BUF_BASE_H
44 #include "octree_nodes.h"
45 #include "octree_container.h"
46 #include "octree_key.h"
47 #include "octree_iterator.h"
57 template<
typename ContainerT>
83 for (b = 0; b < 2; ++b)
84 for (i = 0; i < 8; ++i)
110 getChildPtr (
unsigned char buffer_arg,
unsigned char index_arg)
const
112 assert( (buffer_arg<2) && (index_arg<8));
121 inline void setChildPtr (
unsigned char buffer_arg,
unsigned char index_arg,
124 assert( (buffer_arg<2) && (index_arg<8));
133 inline bool hasChild (
unsigned char buffer_arg,
unsigned char index_arg)
const
135 assert( (buffer_arg<2) && (index_arg<8));
225 template<
typename LeafContainerT = int,
335 createLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
345 findLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
354 existLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg)
const;
362 removeLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
409 bool do_XOR_encoding_arg =
false);
418 std::vector<LeafContainerT*>& leaf_container_vector_arg,
419 bool do_XOR_encoding_arg =
false);
425 serializeLeafs (std::vector<LeafContainerT*>& leaf_container_vector_arg);
439 bool do_XOR_decoding_arg =
false);
448 std::vector<LeafContainerT*>& leaf_container_vector_arg,
449 bool do_XOR_decoding_arg =
false);
468 inline LeafContainerT*
471 LeafContainerT* result = 0;
481 inline LeafContainerT*
540 unsigned char child_idx_arg)
const
567 for (i = 0; i < 8; i++)
570 node_bits |=
static_cast<char> ( (!!child) << i);
582 unsigned char bufferSelector_arg)
const
589 for (i = 0; i < 8; i++)
592 node_bits |=
static_cast<char> ( (!!child) << i);
609 node_bits[0] = node_bits[1] = 0;
611 for (i = 0; i < 8; i++)
616 node_bits[0] |=
static_cast<char> ( (!!childA) << i);
617 node_bits[1] |=
static_cast<char> ( (!!childB) << i);
620 return node_bits[0] ^ node_bits[1];
638 unsigned char buffer_selector_arg,
639 unsigned char child_idx_arg)
641 if (branch_arg.
hasChild(buffer_selector_arg, child_idx_arg))
653 delete (branchChild);
660 delete (branchChild);
668 branch_arg.
setChildPtr(buffer_selector_arg, child_idx_arg, 0);
689 for (i = 0; i < 8; i++)
715 unsigned char child_idx_arg)
720 static_cast<OctreeNode*> (new_branch_child));
722 return new_branch_child;
737 return new_leaf_child;
755 unsigned int depth_mask_arg,
759 bool branch_reset_arg =
false);
771 unsigned int depth_mask_arg,
773 LeafContainerT*& result_arg)
const;
784 unsigned int depth_mask_arg,
798 std::vector<char>* binary_tree_out_arg,
799 typename std::vector<LeafContainerT*>* leaf_container_vector_arg,
800 bool do_XOR_encoding_arg =
false,
801 bool new_leafs_filter_arg =
false);
816 unsigned int depth_mask_arg,
818 typename std::vector<char>::const_iterator& binary_tree_in_it_arg,
819 typename std::vector<char>::const_iterator& binary_tree_in_it_end_arg,
820 typename std::vector<LeafContainerT*>::const_iterator* leaf_container_vector_it_arg,
821 typename std::vector<LeafContainerT*>::const_iterator* leaf_container_vector_it_end_arg,
822 bool branch_reset_arg =
false,
823 bool do_XOR_decoding_arg =
false);
858 inline double Log2 (
double n_arg)
860 return log (n_arg) / log (2.0);
876 unsigned char mask = 1;
879 for (
int i = 0; i < 8; i++)
882 std::cout << ((data_arg & (mask << i)) ?
"1" :
"0");
884 std::cout << std::endl;
BranchNode * root_node_
Pointer to root branch node of octree.
OctreeLeafNodeIterator< OctreeT > LeafNodeIterator
const ContainerT & operator*() const
Get const reference to container.
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.
Octree2BufBase(const Octree2BufBase &source)
Copy constructor.
std::size_t branch_count_
Amount of branch nodes.
const ContainerT & getContainer() const
Get const reference to container.
Iterator begin(unsigned int max_depth_arg=0)
BranchContainerT BranchContainer
std::size_t getBranchCount() const
Return the amount of existing branches in the octree.
virtual OctreeNode * deepCopy() const =0
Pure virtual method to perform a deep copy of the octree.
const OctreeBreadthFirstIterator< OctreeT > ConstBreadthFirstIterator
OctreeDepthFirstIterator< OctreeT > Iterator
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.
BranchNode * createBranchChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Fetch and add a new branch child to a branch class in current buffer.
bool deleteLeafRecursive(const OctreeKey &key_arg, unsigned int depth_mask_arg, BranchNode *branch_arg)
Recursively search and delete leaf node.
const ContainerT * getContainerPtr() const
Get const pointer to container.
const ContainerT * getContainerPtr() const
Get const pointer to container.
BufferedBranchNode & operator=(const BufferedBranchNode &source_arg)
Copy operator.
const LeafNodeIterator leaf_end()
Abstract octree leaf class
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).
BufferedBranchNode()
Empty constructor.
char getBranchXORBitPattern(const BranchNode &branch_arg) const
Generate XOR bit pattern reflecting differences between the two octree buffers.
double Log2(double n_arg)
Helper function to calculate the binary logarithm.
void setChildPtr(unsigned char buffer_arg, unsigned char index_arg, OctreeNode *newNode_arg)
Set child pointer in current branch node.
const OctreeDepthFirstIterator< OctreeT > ConstDepthFirstIterator
LeafNodeIterator leaf_begin(unsigned int max_depth_arg=0)
void setBranchChildPtr(BranchNode &branch_arg, unsigned char child_idx_arg, OctreeNode *new_child_arg)
Assign new child node to branch.
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).
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.
void serializeLeafs(std::vector< LeafContainerT * > &leaf_container_vector_arg)
Outputs a vector of all DataT elements that are stored within the octree leaf nodes.
LeafContainerT LeafContainer
bool hasChild(unsigned char buffer_arg, unsigned char index_arg) const
Check if branch is pointing to a particular child node.
virtual void serializeTreeCallback(LeafContainerT &, const OctreeKey &)
Callback executed for every leaf node data during serialization.
char getBranchBitPattern(const BranchNode &branch_arg, unsigned char bufferSelector_arg) const
Generate bit pattern reflecting the existence of child node pointers in specific buffer.
unsigned int octree_depth_
Octree depth.
DepthFirstIterator depth_begin(unsigned int maxDepth_arg=0)
bool existLeaf(const OctreeKey &key_arg) const
Check for leaf not existance in the octree.
virtual node_type_t getNodeType() const =0
Pure virtual method for receiving the type of octree node (branch or leaf)
Abstract octree node class
OctreeNode * getChildPtr(unsigned char buffer_arg, unsigned char index_arg) const
Get child pointer in current branch node.
void setTreeDepth(unsigned int depth_arg)
Set the maximum depth of the octree.
void printBinary(char data_arg)
Prints binary representation of a byte - used for debugging.
unsigned int getTreeDepth() const
Get the maximum depth of the octree.
OctreeNode * getRootNode() const
Retrieve root node.
const DepthFirstIterator depth_end()
LeafContainerT * createLeaf(const OctreeKey &key_arg)
Create a leaf node.
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.
const OctreeLeafNodeIterator< OctreeT > ConstLeafNodeIterator
OctreeKey max_key_
key range
bool octreeCanResize()
Test if octree is able to dynamically change its depth.
void treeCleanUpRecursive(BranchNode *branch_arg)
Recursively explore the octree and remove unused branch and leaf nodes.
std::size_t leaf_count_
Amount of leaf nodes.
void setMaxVoxelIndex(unsigned int max_voxel_index_arg)
Set the maximum amount of voxels per dimension.
virtual BufferedBranchNode * deepCopy() const
Method to perform a deep copy of the octree.
virtual ~Octree2BufBase()
Empty deconstructor.
Octree2BufBase()
Empty constructor.
OctreeLeafNode< LeafContainerT > LeafNode
LeafNode * createLeafChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Fetch and add a new leaf child to a branch class.
const ContainerT * operator->() const
Get const pointer to container.
OctreeDepthFirstIterator< OctreeT > DepthFirstIterator
std::size_t getLeafCount() const
Return the amount of existing leafs in the octree.
bool branchHasChild(const BranchNode &branch_arg, unsigned char child_idx_arg) const
Check if branch is pointing to a particular child node.
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 reset()
Reset branch node container for every branch 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...
Abstract octree iterator class
void deleteBranchChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Delete child node and all its subchilds from octree in current buffer.
Octree2BufBase< LeafContainerT, BranchContainerT > OctreeT
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).
ContainerT * getContainerPtr()
Get pointer to container.
ContainerT & getContainer()
Get reference to container.
virtual ~BufferedBranchNode()
Empty constructor.
BufferedBranchNode(const BufferedBranchNode &source)
Copy constructor.
OctreeNode * getBranchChildPtr(const BranchNode &branch_arg, unsigned char child_idx_arg) const
Retrieve a child node pointer for child node at child_idx.
unsigned int depth_mask_
Depth mask based on octree depth.
void deleteCurrentBuffer()
Delete the octree structure in the current buffer.
Octree leaf node iterator class.
unsigned char buffer_selector_
Currently active octree buffer.
BreadthFirstIterator breadth_begin(unsigned int max_depth_arg=0)
const BreadthFirstIterator breadth_end()
BufferedBranchNode< BranchContainerT > BranchNode
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 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 deleteTree()
Delete the octree structure and its leaf nodes.
void deletePreviousBuffer()
Delete octree structure of previous buffer.
OctreeNode * child_node_array_[2][8]
virtual void deserializeTreeCallback(LeafContainerT &, const OctreeKey &)
Callback executed for every leaf node data during deserialization.
void deleteBranch(BranchNode &branch_arg)
Delete branch and all its subchilds from octree (both buffers)
Octree container class that does not store any information.
bool hasBranchChanges(const BranchNode &branch_arg) const
Test if branch changed between previous and current buffer.
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.
const OctreeDepthFirstIterator< OctreeT > ConstIterator
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).
Octree2BufBase & operator=(const Octree2BufBase &source)
Copy constructor.
OctreeBreadthFirstIterator< OctreeT > BreadthFirstIterator
bool dynamic_depth_enabled_
Enable dynamic_depth.
virtual node_type_t getNodeType() const
Get the type of octree node.
void removeLeaf(const OctreeKey &key_arg)
Remove leaf node from octree.
LeafContainerT * findLeaf(const OctreeKey &key_arg) const
Find leaf node.
Octree double buffer class