39 #ifndef PCL_OCTREE_TREE_BASE_H 40 #define PCL_OCTREE_TREE_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> 60 template<
typename LeafContainerT = int,
61 typename BranchContainerT = OctreeContainerEmpty >
167 createLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
177 findLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
186 existLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg)
const ;
194 removeLeaf (
unsigned int idx_x_arg,
unsigned int idx_y_arg,
unsigned int idx_z_arg);
230 serializeTree (std::vector<char>& binary_tree_out_arg, std::vector<LeafContainerT*>& leaf_container_vector_arg);
236 serializeLeafs (std::vector<LeafContainerT*>& leaf_container_vector_arg);
249 deserializeTree (std::vector<char>& binary_tree_input_arg, std::vector<LeafContainerT*>& leaf_container_vector_arg);
282 LeafContainerT* result = 0;
325 unsigned char child_idx_arg)
const 328 return (branch_arg.
getChildPtr(child_idx_arg) != 0);
338 unsigned char child_idx_arg)
const 349 unsigned char child_idx_arg,
352 branch_arg[child_idx_arg] = new_child_arg;
367 for (i = 0; i < 8; i++) {
369 node_bits |= static_cast<char> ((!!child) << i);
382 if (branch_arg.
hasChild(child_idx_arg))
384 OctreeNode* branch_child = branch_arg[child_idx_arg];
391 deleteBranch (*static_cast<BranchNode*> (branch_child));
408 branch_arg[child_idx_arg] = 0;
421 for (i = 0; i < 8; i++)
431 unsigned char child_idx_arg)
434 branch_arg[child_idx_arg] = static_cast<OctreeNode*> (new_branch_child);
436 return new_branch_child;
448 branch_arg[child_idx_arg] = static_cast<OctreeNode*> (new_leaf_child);
450 return new_leaf_child;
467 unsigned int depth_mask_arg,
481 unsigned int depth_mask_arg,
483 LeafContainerT*& result_arg)
const;
493 unsigned int depth_mask_arg,
505 std::vector<char>* binary_tree_out_arg,
506 typename std::vector<LeafContainerT*>* leaf_container_vector_arg)
const;
519 typename std::vector<char>::const_iterator& binary_tree_input_it_arg,
520 typename std::vector<char>::const_iterator& binary_tree_input_it_end_arg,
521 typename std::vector<LeafContainerT*>::const_iterator* leaf_container_vector_it_arg,
522 typename std::vector<LeafContainerT*>::const_iterator* leaf_container_vector_it_end_arg);
556 return log( n_arg ) / log( 2.0 );
596 #ifdef PCL_NO_PRECOMPILE 597 #include <pcl/octree/impl/octree_base.hpp> bool hasChild(unsigned char child_idx_arg) const
Check if branch is pointing to a particular child node.
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).
const DepthFirstIterator depth_end()
OctreeBreadthFirstIterator< OctreeT > BreadthFirstIterator
void deleteTree()
Delete the octree structure and its leaf nodes.
const OctreeLeafNodeIterator< OctreeT > ConstLeafNodeIterator
void setMaxVoxelIndex(unsigned int max_voxel_index_arg)
Set the maximum amount of voxels per dimension.
void deserializeTree(std::vector< char > &binary_tree_input_arg)
Deserialize a binary octree description vector and create a corresponding octree structure.
bool branchHasChild(const BranchNode &branch_arg, unsigned char child_idx_arg) const
Check if branch is pointing to a particular child node.
BreadthFirstIterator breadth_begin(unsigned int max_depth_arg=0)
bool deleteLeafRecursive(const OctreeKey &key_arg, unsigned int depth_mask_arg, BranchNode *branch_arg)
Recursively search and delete leaf node.
virtual node_type_t getNodeType() const =0
Pure virtual method for receiving the type of octree node (branch or leaf)
virtual ~OctreeBase()
Empty deconstructor.
Iterator begin(unsigned int max_depth_arg=0)
void deleteBranch(BranchNode &branch_arg)
Delete branch and all its subchilds from octree.
BranchContainerT BranchContainer
OctreeBase & operator=(const OctreeBase &source)
Copy operator.
void setTreeDepth(unsigned int max_depth_arg)
Set the maximum depth of the octree.
OctreeNode * getChildPtr(unsigned char child_idx_arg) const
Get pointer to child.
OctreeBase()
Empty constructor.
OctreeBase(const OctreeBase &source)
Copy constructor.
LeafNode * createLeafChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Create and add a new leaf child to a branch class.
bool existLeaf(unsigned int idx_x_arg, unsigned int idx_y_arg, unsigned int idx_z_arg) const
idx_x_arg for the existence of leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
unsigned int octree_depth_
Octree depth.
Octree leaf node iterator class.
LeafContainerT * findLeaf(const OctreeKey &key_arg) const
Find leaf node.
const OctreeBreadthFirstIterator< OctreeT > ConstBreadthFirstIterator
unsigned int createLeafRecursive(const OctreeKey &key_arg, unsigned int depth_mask_arg, BranchNode *branch_arg, LeafNode *&return_leaf_arg, BranchNode *&parent_of_leaf_arg)
Create a leaf node at octree key.
void serializeTree(std::vector< char > &binary_tree_out_arg)
Serialize octree into a binary output vector describing its branch node structure.
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).
LeafNodeIterator leaf_begin(unsigned int max_depth_arg=0)
OctreeLeafNodeIterator< OctreeT > LeafNodeIterator
OctreeBase< LeafContainerT, BranchContainerT > OctreeT
BranchNode * createBranchChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Create and add a new branch child to a branch class.
OctreeKey max_key_
key range
bool octreeCanResize()
Test if octree is able to dynamically change its depth.
OctreeBranchNode< BranchContainerT > BranchNode
virtual void serializeTreeCallback(LeafContainerT &, const OctreeKey &) const
Callback executed for every leaf node during serialization.
BranchNode * root_node_
Pointer to root branch node of octree.
void serializeLeafs(std::vector< LeafContainerT * > &leaf_container_vector_arg)
Outputs a vector of all LeafContainerT elements that are stored within the octree leaf nodes.
OctreeNode * getRootNode() const
Retrieve root node.
OctreeDepthFirstIterator< OctreeT > DepthFirstIterator
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).
std::size_t getLeafCount() const
Return the amount of existing leafs in the octree.
void removeLeaf(const OctreeKey &key_arg)
Remove leaf node from octree.
virtual void deserializeTreeCallback(LeafContainerT &, const OctreeKey &)
Callback executed for every leaf node during deserialization.
bool dynamic_depth_enabled_
Enable dynamic_depth.
LeafContainerT LeafContainer
LeafContainerT * createLeaf(const OctreeKey &key_arg)
Create a leaf node.
unsigned int getTreeDepth() const
Get the maximum depth of the octree.
Abstract octree leaf class
void deserializeTreeRecursive(BranchNode *branch_arg, unsigned int depth_mask_arg, OctreeKey &key_arg, typename std::vector< char >::const_iterator &binary_tree_input_it_arg, typename std::vector< char >::const_iterator &binary_tree_input_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)
Recursive method for deserializing octree structure.
OctreeLeafNode< LeafContainerT > LeafNode
char getBranchBitPattern(const BranchNode &branch_arg) const
Generate bit pattern reflecting the existence of child node pointers.
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 LeafNodeIterator leaf_end()
void setBranchChildPtr(BranchNode &branch_arg, unsigned char child_idx_arg, OctreeNode *new_child_arg)
Assign new child node to branch.
const ContainerT * getContainerPtr() const
Get const pointer to container.
Abstract octree iterator class
bool existLeaf(const OctreeKey &key_arg) const
Check for existance of a leaf node in the octree.
const OctreeDepthFirstIterator< OctreeT > ConstIterator
const OctreeDepthFirstIterator< OctreeT > ConstDepthFirstIterator
Abstract octree branch class
std::size_t leaf_count_
Amount of leaf nodes.
const BreadthFirstIterator breadth_end()
Abstract octree node class
void serializeTreeRecursive(const BranchNode *branch_arg, OctreeKey &key_arg, std::vector< char > *binary_tree_out_arg, typename std::vector< LeafContainerT * > *leaf_container_vector_arg) const
Recursively explore the octree and output binary octree description together with a vector of leaf no...
DepthFirstIterator depth_begin(unsigned int max_depth_arg=0)
std::size_t getBranchCount() const
Return the amount of existing branch nodes in the octree.
unsigned int depth_mask_
Depth mask based on octree depth.
double Log2(double n_arg)
Helper function to calculate the binary logarithm.
OctreeDepthFirstIterator< OctreeT > Iterator
std::size_t branch_count_
Amount of branch nodes.
OctreeNode * getBranchChildPtr(const BranchNode &branch_arg, unsigned char child_idx_arg) const
Retrieve a child node pointer for child node at child_idx.
void deleteBranchChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Delete child node and all its subchilds from octree.