39 #ifndef PCL_OCTREE_BASE_HPP 40 #define PCL_OCTREE_BASE_HPP 44 #include <pcl/impl/instantiate.hpp> 51 template<
typename LeafContainerT,
typename BranchContainerT>
58 dynamic_depth_enabled_ (false),
64 template<
typename LeafContainerT,
typename BranchContainerT>
73 template<
typename LeafContainerT,
typename BranchContainerT>
77 unsigned int tree_depth;
79 assert(max_voxel_index_arg>0);
82 tree_depth = std::max ( (std::min (static_cast<unsigned int> (
OctreeKey::maxDepth), static_cast<unsigned int> (std::ceil (
Log2 (max_voxel_index_arg))))), 0u);
89 template<
typename LeafContainerT,
typename BranchContainerT>
106 template<
typename LeafContainerT,
typename BranchContainerT>
109 unsigned int idx_y_arg,
110 unsigned int idx_z_arg)
113 OctreeKey key (idx_x_arg, idx_y_arg, idx_z_arg);
120 template<
typename LeafContainerT,
typename BranchContainerT>
123 unsigned int idx_y_arg,
124 unsigned int idx_z_arg)
127 OctreeKey key (idx_x_arg, idx_y_arg, idx_z_arg);
134 template<
typename LeafContainerT,
typename BranchContainerT>
137 unsigned int idx_y_arg,
138 unsigned int idx_z_arg)
const 141 OctreeKey key (idx_x_arg, idx_y_arg, idx_z_arg);
148 template<
typename LeafContainerT,
typename BranchContainerT>
151 unsigned int idx_y_arg,
152 unsigned int idx_z_arg)
155 OctreeKey key (idx_x_arg, idx_y_arg, idx_z_arg);
162 template<
typename LeafContainerT,
typename BranchContainerT>
178 template<
typename LeafContainerT,
typename BranchContainerT>
186 binary_tree_out_arg.clear ();
193 template<
typename LeafContainerT,
typename BranchContainerT>
196 std::vector<LeafContainerT*>& leaf_container_vector_arg)
202 binary_tree_out_arg.clear ();
203 leaf_container_vector_arg.clear ();
206 leaf_container_vector_arg.reserve (this->
leaf_count_);
212 template<
typename LeafContainerT,
typename BranchContainerT>
219 leaf_container_vector_arg.clear ();
221 leaf_container_vector_arg.reserve (this->
leaf_count_);
227 template<
typename LeafContainerT,
typename BranchContainerT>
237 std::vector<char>::const_iterator binary_tree_out_it = binary_tree_out_arg.begin ();
238 std::vector<char>::const_iterator binary_tree_out_it_end = binary_tree_out_arg.end ();
244 binary_tree_out_it_end,
251 template<
typename LeafContainerT,
typename BranchContainerT>
254 std::vector<LeafContainerT*>& leaf_container_vector_arg)
259 typename std::vector<LeafContainerT*>::const_iterator leaf_vector_it = leaf_container_vector_arg.begin ();
262 typename std::vector<LeafContainerT*>::const_iterator leaf_vector_it_end = leaf_container_vector_arg.end ();
268 std::vector<char>::const_iterator binary_tree_input_it = binary_tree_in_arg.begin ();
269 std::vector<char>::const_iterator binary_tree_input_it_end = binary_tree_in_arg.end ();
274 binary_tree_input_it,
275 binary_tree_input_it_end,
277 &leaf_vector_it_end);
282 template<
typename LeafContainerT,
typename BranchContainerT>
285 unsigned int depth_mask_arg,
291 unsigned char child_idx;
296 OctreeNode* child_node = (*branch_arg)[child_idx];
308 return createLeafRecursive (key_arg, depth_mask_arg / 2, childBranch, return_leaf_arg, parent_of_leaf_arg);
315 return_leaf_arg = leaf_node;
316 parent_of_leaf_arg = branch_arg;
327 return createLeafRecursive (key_arg, depth_mask_arg / 2, static_cast<BranchNode*> (child_node),
328 return_leaf_arg, parent_of_leaf_arg);
332 return_leaf_arg =
static_cast<LeafNode*
> (child_node);;
333 parent_of_leaf_arg = branch_arg;
339 return (depth_mask_arg >> 1);
343 template<
typename LeafContainerT,
typename BranchContainerT>
346 unsigned int depth_mask_arg,
348 LeafContainerT*& result_arg)
const 351 unsigned char child_idx;
356 OctreeNode* child_node = (*branch_arg)[child_idx];
365 child_branch =
static_cast<BranchNode*
> (child_node);
373 child_leaf =
static_cast<LeafNode*
> (child_node);
382 template<
typename LeafContainerT,
typename BranchContainerT>
385 unsigned int depth_mask_arg,
389 unsigned char child_idx;
396 OctreeNode* child_node = (*branch_arg)[child_idx];
405 child_branch =
static_cast<BranchNode*
> (child_node);
429 b_no_children =
false;
430 for (child_idx = 0; (!b_no_children) && (child_idx < 8); child_idx++)
432 b_no_children = branch_arg->
hasChild (child_idx);
435 return (b_no_children);
439 template<
typename LeafContainerT,
typename BranchContainerT>
443 std::vector<char>* binary_tree_out_arg,
444 typename std::vector<LeafContainerT*>* leaf_container_vector_arg)
const 448 unsigned char child_idx;
449 char node_bit_pattern;
455 if (binary_tree_out_arg)
456 binary_tree_out_arg->push_back (node_bit_pattern);
459 for (child_idx = 0; child_idx < 8; child_idx++)
463 if (branch_arg->
hasChild (child_idx))
476 leaf_container_vector_arg);
483 if (leaf_container_vector_arg)
501 template<
typename LeafContainerT,
typename BranchContainerT>
504 typename std::vector<char>::const_iterator& binary_tree_input_it_arg,
505 typename std::vector<char>::const_iterator& binary_tree_input_it_end_arg,
506 typename std::vector<LeafContainerT*>::const_iterator* leaf_container_vector_it_arg,
507 typename std::vector<LeafContainerT*>::const_iterator* leaf_container_vector_it_end_arg)
510 unsigned char child_idx;
513 if (binary_tree_input_it_arg != binary_tree_input_it_end_arg)
516 node_bits = (*binary_tree_input_it_arg);
517 binary_tree_input_it_arg++;
520 for (child_idx = 0; child_idx < 8; child_idx++)
523 if (node_bits & (1 << child_idx))
528 if (depth_mask_arg > 1)
537 binary_tree_input_it_arg, binary_tree_input_it_end_arg,
538 leaf_container_vector_it_arg, leaf_container_vector_it_end_arg);
546 if (leaf_container_vector_it_arg && (*leaf_container_vector_it_arg != *leaf_container_vector_it_end_arg))
548 LeafContainerT& container = **child_leaf;
549 container = ***leaf_container_vector_it_arg;
550 ++*leaf_container_vector_it_arg;
569 #define PCL_INSTANTIATE_OctreeBase(T) template class PCL_EXPORTS pcl::octree::OctreeBase<T>; 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).
void deleteTree()
Delete the octree structure and its leaf nodes.
void setMaxVoxelIndex(unsigned int max_voxel_index_arg)
Set the maximum amount of voxels per dimension.
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...
void deserializeTree(std::vector< char > &binary_tree_input_arg)
Deserialize a binary octree description vector and create a corresponding octree structure.
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.
static const unsigned char maxDepth
void serializeLeafs(std::vector< LeafContainerT *> &leaf_container_vector_arg)
Outputs a vector of all LeafContainerT elements that are stored within the octree leaf nodes...
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.
void deleteBranch(BranchNode &branch_arg)
Delete branch and all its subchilds from octree.
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.
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.
void popBranch()
pop child node from octree key
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).
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
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.
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).
unsigned char getChildIdxWithDepthMask(unsigned int depthMask) const
get child node index using depthMask
virtual void deserializeTreeCallback(LeafContainerT &, const OctreeKey &)
Callback executed for every leaf node during deserialization.
bool dynamic_depth_enabled_
Enable dynamic_depth.
Abstract octree leaf class
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 ContainerT * getContainerPtr() const
Get const pointer to container.
Abstract octree branch class
void pushBranch(unsigned char childIndex)
push a child node to the octree key
std::size_t leaf_count_
Amount of leaf nodes.
Abstract octree node class
unsigned int depth_mask_
Depth mask based on octree depth.
double Log2(double n_arg)
Helper function to calculate the binary logarithm.
std::size_t branch_count_
Amount of branch nodes.
void deleteBranchChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Delete child node and all its subchilds from octree.