39 #ifndef PCL_OCTREE_TREE_2BUF_BASE_H 40 #define PCL_OCTREE_TREE_2BUF_BASE_H 44 #include <pcl/octree/octree_nodes.h> 45 #include <pcl/octree/octree_container.h> 46 #include <pcl/octree/octree_key.h> 47 #include <pcl/octree/octree_iterator.h> 55 template<
typename ContainerT>
81 for (b = 0; b < 2; ++b)
82 for (i = 0; i < 8; ++i)
108 getChildPtr (
unsigned char buffer_arg,
unsigned char index_arg)
const 110 assert( (buffer_arg<2) && (index_arg<8));
119 inline void setChildPtr (
unsigned char buffer_arg,
unsigned char index_arg,
122 assert( (buffer_arg<2) && (index_arg<8));
131 inline bool hasChild (
unsigned char buffer_arg,
unsigned char index_arg)
const 133 assert( (buffer_arg<2) && (index_arg<8));
223 template<
typename LeafContainerT = int,
248 Iterator
begin(
unsigned int max_depth_arg = 0) {
return Iterator(
this, max_depth_arg);};
249 const Iterator end() {
return Iterator();};
258 PCL_DEPRECATED (
"Please use leaf_depth_begin () instead.")
259 LeafNodeIterator leaf_begin (
unsigned int max_depth_arg = 0)
261 return LeafNodeIterator (
this, max_depth_arg);
264 PCL_DEPRECATED (
"Please use leaf_depth_end () instead.")
265 const LeafNodeIterator leaf_end ()
267 return LeafNodeIterator ();
275 return LeafNodeDepthFirstIterator (
this, max_depth_arg);
280 return LeafNodeDepthFirstIterator();
286 DepthFirstIterator
depth_begin(
unsigned int maxDepth_arg = 0) {
return DepthFirstIterator(
this, maxDepth_arg);};
287 const DepthFirstIterator
depth_end() {
return DepthFirstIterator();};
292 BreadthFirstIterator
breadth_begin(
unsigned int max_depth_arg = 0) {
return BreadthFirstIterator(
this, max_depth_arg);};
293 const BreadthFirstIterator breadth_end() {
return BreadthFirstIterator();};
301 return LeafNodeBreadthIterator (
this, max_depth_arg? max_depth_arg : this->octree_depth_);
306 return LeafNodeBreadthIterator (
this, 0, NULL);
318 leaf_count_ (source.leaf_count_),
319 branch_count_ (source.branch_count_),
320 root_node_ (new (
BranchNode) (*(source.root_node_))),
321 depth_mask_ (source.depth_mask_),
322 max_key_ (source.max_key_),
323 buffer_selector_ (source.buffer_selector_),
324 tree_dirty_flag_ (source.tree_dirty_flag_),
325 octree_depth_ (source.octree_depth_),
326 dynamic_depth_enabled_(source.dynamic_depth_enabled_)
350 setMaxVoxelIndex (
unsigned int max_voxel_index_arg);
356 setTreeDepth (
unsigned int depth_arg);
363 return this->octree_depth_;
374 createLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
384 findLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
393 existLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg)
const;
401 removeLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
408 return (leaf_count_);
416 return (branch_count_);
427 treeCleanUpRecursive (root_node_);
433 buffer_selector_ = !buffer_selector_;
434 treeCleanUpRecursive (root_node_);
447 serializeTree (std::vector<char>& binary_tree_out_arg,
448 bool do_XOR_encoding_arg =
false);
456 serializeTree (std::vector<char>& binary_tree_out_arg,
457 std::vector<LeafContainerT*>& leaf_container_vector_arg,
458 bool do_XOR_encoding_arg =
false);
464 serializeLeafs (std::vector<LeafContainerT*>& leaf_container_vector_arg);
470 serializeNewLeafs (std::vector<LeafContainerT*>& leaf_container_vector_arg);
477 deserializeTree (std::vector<char>& binary_tree_in_arg,
478 bool do_XOR_decoding_arg =
false);
486 deserializeTree (std::vector<char>& binary_tree_in_arg,
487 std::vector<LeafContainerT*>& leaf_container_vector_arg,
488 bool do_XOR_decoding_arg =
false);
500 return (this->root_node_);
507 inline LeafContainerT*
510 LeafContainerT* result = 0;
511 findLeafRecursive (key_arg, depth_mask_, root_node_, result);
520 inline LeafContainerT*
526 createLeafRecursive (key_arg, depth_mask_ ,root_node_, leaf_node, leaf_node_parent,
false);
539 return (findLeaf(key_arg) != 0);
547 if (key_arg <= max_key_)
549 deleteLeafRecursive (key_arg, depth_mask_, root_node_);
552 tree_dirty_flag_ =
true;
569 return (branch_arg.
getChildPtr(buffer_selector_, child_idx_arg) != 0);
579 unsigned char child_idx_arg)
const 581 return branch_arg.
getChildPtr(buffer_selector_, child_idx_arg);
592 branch_arg.
setChildPtr (buffer_selector_, child_idx_arg, new_child_arg);
606 for (i = 0; i < 8; i++)
609 node_bits |=
static_cast<char> ( (!!child) << i);
621 unsigned char bufferSelector_arg)
const 628 for (i = 0; i < 8; i++)
631 node_bits |=
static_cast<char> ( (!!child) << i);
648 node_bits[0] = node_bits[1] = 0;
650 for (i = 0; i < 8; i++)
655 node_bits[0] |=
static_cast<char> ( (!!childA) << i);
656 node_bits[1] |=
static_cast<char> ( (!!childB) << i);
659 return node_bits[0] ^ node_bits[1];
668 return (getBranchXORBitPattern (branch_arg) > 0);
677 unsigned char buffer_selector_arg,
678 unsigned char child_idx_arg)
680 if (branch_arg.
hasChild(buffer_selector_arg, child_idx_arg))
689 deleteBranch (*static_cast<BranchNode*> (branchChild));
692 delete (branchChild);
699 delete (branchChild);
707 branch_arg.
setChildPtr(buffer_selector_arg, child_idx_arg, 0);
717 deleteBranchChild(branch_arg, buffer_selector_, child_idx_arg);
728 for (i = 0; i < 8; i++)
734 deleteBranchChild (branch_arg, 0, i);
742 deleteBranchChild (branch_arg, 0, i);
743 deleteBranchChild (branch_arg, 1, i);
754 unsigned char child_idx_arg)
758 branch_arg.
setChildPtr (buffer_selector_, child_idx_arg,
759 static_cast<OctreeNode*> (new_branch_child));
761 return new_branch_child;
774 branch_arg.
setChildPtr(buffer_selector_, child_idx_arg, new_leaf_child);
776 return new_leaf_child;
793 createLeafRecursive (
const OctreeKey& key_arg,
794 unsigned int depth_mask_arg,
798 bool branch_reset_arg =
false);
809 findLeafRecursive (
const OctreeKey& key_arg,
810 unsigned int depth_mask_arg,
812 LeafContainerT*& result_arg)
const;
822 deleteLeafRecursive (
const OctreeKey& key_arg,
823 unsigned int depth_mask_arg,
835 serializeTreeRecursive (
BranchNode* branch_arg,
837 std::vector<char>* binary_tree_out_arg,
838 typename std::vector<LeafContainerT*>* leaf_container_vector_arg,
839 bool do_XOR_encoding_arg =
false,
840 bool new_leafs_filter_arg =
false);
854 deserializeTreeRecursive (
BranchNode* branch_arg,
855 unsigned int depth_mask_arg,
857 typename std::vector<char>::const_iterator& binary_tree_in_it_arg,
858 typename std::vector<char>::const_iterator& binary_tree_in_it_end_arg,
859 typename std::vector<LeafContainerT*>::const_iterator* leaf_container_vector_it_arg,
860 typename std::vector<LeafContainerT*>::const_iterator* leaf_container_vector_it_end_arg,
861 bool branch_reset_arg =
false,
862 bool do_XOR_decoding_arg =
false);
891 treeCleanUpRecursive (
BranchNode* branch_arg);
897 inline double Log2 (
double n_arg)
899 return log (n_arg) / log (2.0);
915 unsigned char mask = 1;
918 for (
int i = 0; i < 8; i++)
921 std::cout << ((data_arg & (mask << i)) ?
"1" :
"0");
923 std::cout << std::endl;
962 #ifdef PCL_NO_PRECOMPILE 963 #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.
OctreeNode * getChildPtr(unsigned char buffer_arg, unsigned char index_arg) const
Get child pointer in current branch node.
const OctreeLeafNodeDepthFirstIterator< OctreeT > ConstLeafNodeDepthFirstIterator
virtual node_type_t getNodeType() const
Get the type of octree node.
bool octreeCanResize()
Test if octree is able to dynamically change its depth.
ContainerT * getContainerPtr()
Get pointer to container.
virtual ~BufferedBranchNode()
Empty constructor.
unsigned int octree_depth_
Octree depth.
Octree2BufBase(const Octree2BufBase &source)
Copy constructor.
const OctreeBreadthFirstIterator< OctreeT > ConstBreadthFirstIterator
char getBranchBitPattern(const BranchNode &branch_arg) const
Generate bit pattern reflecting the existence of child node pointers for current buffer.
This file defines compatibility wrappers for low level I/O functions.
virtual BufferedBranchNode * deepCopy() const
Method to perform a deep copy of the octree.
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.
const OctreeLeafNodeDepthFirstIterator< OctreeT > ConstLeafNodeIterator
const LeafNodeBreadthIterator leaf_breadth_end()
OctreeKey max_key_
key range
const OctreeDepthFirstIterator< OctreeT > ConstDepthFirstIterator
void deleteBranch(BranchNode &branch_arg)
Delete branch and all its subchilds from octree (both buffers)
LeafContainerT LeafContainer
void deleteBranchChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Delete child node and all its subchilds from octree in current buffer.
OctreeLeafNodeBreadthFirstIterator< OctreeT > LeafNodeBreadthIterator
const OctreeDepthFirstIterator< OctreeT > ConstIterator
OctreeDepthFirstIterator< OctreeT > DepthFirstIterator
BranchContainerT BranchContainer
BreadthFirstIterator breadth_begin(unsigned int max_depth_arg=0)
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.
std::size_t getLeafCount() const
Return the amount of existing leafs in the octree.
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.
OctreeLeafNode< LeafContainerT > LeafNode
void deleteCurrentBuffer()
Delete the octree structure in the current buffer.
Octree leaf node iterator class.
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 > Iterator
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()
Abstract octree leaf class
const ContainerT * operator->() const
Get const pointer to container.
LeafNodeDepthFirstIterator leaf_depth_begin(unsigned int max_depth_arg=0)
unsigned char buffer_selector_
Currently active octree buffer.
BufferedBranchNode< BranchContainerT > BranchNode
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.
OctreeLeafNodeDepthFirstIterator< OctreeT > LeafNodeDepthFirstIterator
Abstract octree iterator class
ContainerT & getContainer()
Get reference to container.
OctreeLeafNodeDepthFirstIterator< OctreeT > LeafNodeIterator
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.
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]
Abstract octree node class
Octree2BufBase< LeafContainerT, BranchContainerT > OctreeT
std::size_t leaf_count_
Amount of leaf nodes.
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 hasChild(unsigned char buffer_arg, unsigned char index_arg) const
Check if branch is pointing to a particular child node.
const OctreeLeafNodeBreadthFirstIterator< OctreeT > ConstLeafNodeBreadthIterator