39#ifndef PCL_OCTREE_2BUF_BASE_HPP
40#define PCL_OCTREE_2BUF_BASE_HPP
45template <
typename LeafContainerT,
typename BranchContainerT>
58template <
typename LeafContainerT,
typename BranchContainerT>
67template <
typename LeafContainerT,
typename BranchContainerT>
74 assert(max_voxel_index_arg > 0);
79 std::ceil(std::log2(max_voxel_index_arg))),
87template <
typename LeafContainerT,
typename BranchContainerT>
91 assert(depth_arg > 0);
104template <
typename LeafContainerT,
typename BranchContainerT>
111 OctreeKey key(idx_x_arg, idx_y_arg, idx_z_arg);
118template <
typename LeafContainerT,
typename BranchContainerT>
125 OctreeKey key(idx_x_arg, idx_y_arg, idx_z_arg);
132template <
typename LeafContainerT,
typename BranchContainerT>
139 OctreeKey key(idx_x_arg, idx_y_arg, idx_z_arg);
146template <
typename LeafContainerT,
typename BranchContainerT>
153 OctreeKey key(idx_x_arg, idx_y_arg, idx_z_arg);
160template <
typename LeafContainerT,
typename BranchContainerT>
177template <
typename LeafContainerT,
typename BranchContainerT>
195 for (
unsigned char child_idx = 0; child_idx < 8; child_idx++) {
201template <
typename LeafContainerT,
typename BranchContainerT>
204 std::vector<char>& binary_tree_out_arg,
bool do_XOR_encoding_arg)
209 binary_tree_out_arg.clear();
213 root_node_, new_key, &binary_tree_out_arg,
nullptr, do_XOR_encoding_arg,
false);
220template <
typename LeafContainerT,
typename BranchContainerT>
223 std::vector<char>& binary_tree_out_arg,
224 std::vector<LeafContainerT*>& leaf_container_vector_arg,
225 bool do_XOR_encoding_arg)
230 binary_tree_out_arg.clear();
231 leaf_container_vector_arg.clear();
238 &binary_tree_out_arg,
239 &leaf_container_vector_arg,
248template <
typename LeafContainerT,
typename BranchContainerT>
251 std::vector<LeafContainerT*>& leaf_container_vector_arg)
256 leaf_container_vector_arg.clear();
261 root_node_, new_key,
nullptr, &leaf_container_vector_arg,
false,
false);
268template <
typename LeafContainerT,
typename BranchContainerT>
271 std::vector<char>& binary_tree_in_arg,
bool do_XOR_decoding_arg)
279 std::vector<char>::const_iterator binary_tree_in_it = binary_tree_in_arg.begin();
280 std::vector<char>::const_iterator binary_tree_in_it_end = binary_tree_in_arg.end();
286 binary_tree_in_it_end,
290 do_XOR_decoding_arg);
297template <
typename LeafContainerT,
typename BranchContainerT>
300 std::vector<char>& binary_tree_in_arg,
301 std::vector<LeafContainerT*>& leaf_container_vector_arg,
302 bool do_XOR_decoding_arg)
307 typename std::vector<LeafContainerT*>::const_iterator leaf_container_vector_it =
308 leaf_container_vector_arg.begin();
311 typename std::vector<LeafContainerT*>::const_iterator leaf_container_vector_it_end =
312 leaf_container_vector_arg.end();
318 std::vector<char>::const_iterator binary_tree_in_it = binary_tree_in_arg.begin();
319 std::vector<char>::const_iterator binary_tree_in_it_end = binary_tree_in_arg.end();
325 binary_tree_in_it_end,
326 &leaf_container_vector_it,
327 &leaf_container_vector_it_end,
329 do_XOR_decoding_arg);
336template <
typename LeafContainerT,
typename BranchContainerT>
339 std::vector<LeafContainerT*>& leaf_container_vector_arg)
344 leaf_container_vector_arg.clear();
348 root_node_, new_key,
nullptr, &leaf_container_vector_arg,
false,
true);
355template <
typename LeafContainerT,
typename BranchContainerT>
363 bool branch_reset_arg)
366 if (branch_reset_arg) {
368 for (
unsigned char child_idx = 0; child_idx < 8; child_idx++) {
376 if (depth_mask_arg > 1) {
391 child_branch =
static_cast<BranchNode*
>(child_node);
396 deleteBranchChild(*branch_arg, !buffer_selector_, child_idx);
397 child_branch = createBranchChild(*branch_arg, child_idx);
405 child_branch = createBranchChild(*branch_arg, child_idx);
412 child_branch =
static_cast<BranchNode*
>(
413 branch_arg->
getChildPtr(buffer_selector_, child_idx));
416 return createLeafRecursive(key_arg,
425 LeafNode* child_leaf;
426 if (!branch_arg->
hasChild(buffer_selector_, child_idx)) {
430 if (branch_arg->
hasChild(!buffer_selector_, child_idx)) {
434 child_leaf =
static_cast<LeafNode*
>(child_node);
440 deleteBranchChild(*branch_arg, !buffer_selector_, child_idx);
441 child_leaf = createLeafChild(*branch_arg, child_idx);
447 child_leaf = createLeafChild(*branch_arg, child_idx);
452 return_leaf_arg = child_leaf;
453 parent_of_leaf_arg = branch_arg;
458 static_cast<LeafNode*
>(branch_arg->
getChildPtr(buffer_selector_, child_idx));
459 parent_of_leaf_arg = branch_arg;
462 return depth_mask_arg;
466template <
typename LeafContainerT,
typename BranchContainerT>
472 LeafContainerT*& result_arg)
const
475 unsigned char child_idx;
480 if (depth_mask_arg > 1) {
492 if (branch_arg->
hasChild(buffer_selector_, child_idx)) {
494 LeafNode* leaf_node =
496 result_arg = leaf_node->getContainerPtr();
502template <
typename LeafContainerT,
typename BranchContainerT>
508 unsigned char child_idx;
515 if (depth_mask_arg > 1) {
525 bool bBranchOccupied =
528 if (!bBranchOccupied) {
543 for (child_idx = 0; child_idx < 8; child_idx++) {
554template <
typename LeafContainerT,
typename BranchContainerT>
559 std::vector<char>* binary_tree_out_arg,
560 typename std::vector<LeafContainerT*>* leaf_container_vector_arg,
561 bool do_XOR_encoding_arg,
562 bool new_leafs_filter_arg)
564 if (binary_tree_out_arg) {
566 const char branch_bit_pattern_curr_buffer =
568 if (do_XOR_encoding_arg) {
570 const char branch_bit_pattern_prev_buffer =
573 const char node_XOR_bit_pattern =
574 branch_bit_pattern_curr_buffer ^ branch_bit_pattern_prev_buffer;
576 binary_tree_out_arg->push_back(node_XOR_bit_pattern);
580 binary_tree_out_arg->push_back(branch_bit_pattern_curr_buffer);
585 for (
unsigned char child_idx = 0; child_idx < 8; child_idx++) {
598 leaf_container_vector_arg,
600 new_leafs_filter_arg);
606 if (new_leafs_filter_arg) {
608 if (leaf_container_vector_arg)
616 if (leaf_container_vector_arg)
639template <
typename LeafContainerT,
typename BranchContainerT>
645 typename std::vector<char>::const_iterator& binaryTreeIT_arg,
646 typename std::vector<char>::const_iterator& binaryTreeIT_End_arg,
647 typename std::vector<LeafContainerT*>::const_iterator* dataVectorIterator_arg,
648 typename std::vector<LeafContainerT*>::const_iterator* dataVectorEndIterator_arg,
649 bool branch_reset_arg,
650 bool do_XOR_decoding_arg)
654 if (branch_reset_arg) {
656 for (
unsigned char child_idx = 0; child_idx < 8; child_idx++) {
661 if (binaryTreeIT_arg != binaryTreeIT_End_arg) {
663 char nodeBits = *binaryTreeIT_arg++;
666 char recoveredNodeBits;
667 if (do_XOR_decoding_arg) {
672 recoveredNodeBits = nodeBits;
676 for (
unsigned char child_idx = 0; child_idx < 8; child_idx++) {
678 if (recoveredNodeBits & (1 << child_idx)) {
682 if (depth_mask_arg > 1) {
685 bool doNodeReset =
false;
697 child_branch =
static_cast<BranchNode*
>(child_node);
727 binaryTreeIT_End_arg,
728 dataVectorIterator_arg,
729 dataVectorEndIterator_arg,
731 do_XOR_decoding_arg);
743 child_leaf =
static_cast<LeafNode*
>(child_node);
759 if (dataVectorIterator_arg &&
760 (*dataVectorIterator_arg != *dataVectorEndIterator_arg)) {
761 LeafContainerT& container = **child_leaf;
762 container = ***dataVectorIterator_arg;
763 ++*dataVectorIterator_arg;
787template <
typename LeafContainerT,
typename BranchContainerT>
793 char occupied_children_bit_pattern_prev_buffer =
800 char unused_branches_bit_pattern =
801 node_XOR_bit_pattern & occupied_children_bit_pattern_prev_buffer;
804 for (
unsigned char child_idx = 0; child_idx < 8; child_idx++) {
823 if (unused_branches_bit_pattern & (1 << child_idx)) {
832#define PCL_INSTANTIATE_Octree2BufBase(T) \
833 template class PCL_EXPORTS pcl::octree::Octree2BufBase<T>;
OctreeNode * getChildPtr(unsigned char buffer_arg, unsigned char index_arg) const
Get child pointer in current branch node.
void setChildPtr(unsigned char buffer_arg, unsigned char index_arg, OctreeNode *newNode_arg)
Set child pointer in current branch node.
bool hasChild(unsigned char buffer_arg, unsigned char index_arg) const
Check if branch is pointing to a particular child node.
void deleteBranch(BranchNode &branch_arg)
Delete branch and all its subchilds from octree (both buffers).
void serializeLeafs(std::vector< LeafContainerT * > &leaf_container_vector_arg)
Outputs a vector of all DataT elements that are stored within the octree leaf nodes.
BranchNode * createBranchChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Fetch and add a new branch child to a branch class in current buffer.
char getBranchBitPattern(const BranchNode &branch_arg) const
Generate bit pattern reflecting the existence of child node pointers for current buffer.
OctreeKey max_key_
key range
void switchBuffers()
Switch buffers and reset current octree structure.
OctreeLeafNode< LeafContainerT > LeafNode
uindex_t createLeafRecursive(const OctreeKey &key_arg, uindex_t 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.
std::size_t leaf_count_
Amount of leaf nodes.
uindex_t octree_depth_
Octree depth.
LeafNode * createLeafChild(BranchNode &branch_arg, unsigned char child_idx_arg)
Fetch and add a new leaf child to a branch class.
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 treeCleanUpRecursive(BranchNode *branch_arg)
Recursively explore the octree and remove unused branch and leaf nodes.
void deleteTree()
Delete the octree structure and its leaf nodes.
unsigned char buffer_selector_
Currently active octree buffer.
char getBranchXORBitPattern(const BranchNode &branch_arg) const
Generate XOR bit pattern reflecting differences between the two octree buffers.
virtual void deserializeTreeCallback(LeafContainerT &, const OctreeKey &)
Callback executed for every leaf node data during deserialization.
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...
bool existLeaf(uindex_t idx_x_arg, uindex_t idx_y_arg, uindex_t idx_z_arg) const
Check for the existence of leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
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.
LeafContainerT * createLeaf(uindex_t idx_x_arg, uindex_t idx_y_arg, uindex_t idx_z_arg)
Create new leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
void deleteBranchChild(BranchNode &branch_arg, unsigned char buffer_selector_arg, unsigned char child_idx_arg)
BranchNode * root_node_
Pointer to root branch node of octree.
void setTreeDepth(uindex_t depth_arg)
Set the maximum depth of the octree.
bool tree_dirty_flag_
flags indicating if unused branches and leafs might exist in previous buffer
std::size_t branch_count_
Amount of branch nodes.
void setMaxVoxelIndex(uindex_t max_voxel_index_arg)
Set the maximum amount of voxels per dimension.
bool dynamic_depth_enabled_
Enable dynamic_depth.
void removeLeaf(uindex_t idx_x_arg, uindex_t idx_y_arg, uindex_t idx_z_arg)
Remove leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
bool deleteLeafRecursive(const OctreeKey &key_arg, uindex_t depth_mask_arg, BranchNode *branch_arg)
Recursively search and delete leaf node.
LeafContainerT * findLeaf(uindex_t idx_x_arg, uindex_t idx_y_arg, uindex_t idx_z_arg)
Find leaf node at (idx_x_arg, idx_y_arg, idx_z_arg).
uindex_t depth_mask_
Depth mask based on octree depth.
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...
virtual void serializeTreeCallback(LeafContainerT &, const OctreeKey &)
Callback executed for every leaf node data during serialization.
BufferedBranchNode< BranchContainerT > BranchNode
OctreeContainerPointIndices LeafContainer
Octree2BufBase()
Empty constructor.
void findLeafRecursive(const OctreeKey &key_arg, uindex_t depth_mask_arg, BranchNode *branch_arg, LeafContainerT *&result_arg) const
Recursively search for a given leaf node and return a pointer.
virtual ~Octree2BufBase()
Empty deconstructor.
void deserializeTreeRecursive(BranchNode *branch_arg, uindex_t 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...
void popBranch()
pop child node from octree key
static const unsigned char maxDepth
void pushBranch(unsigned char childIndex)
push a child node to the octree key
unsigned char getChildIdxWithDepthMask(uindex_t depthMask) const
get child node index using depthMask
const ContainerT * getContainerPtr() const
Get const pointer to container.
Abstract octree node class
virtual node_type_t getNodeType() const =0
Pure virtual method for receiving the type of octree node (branch or leaf).
detail::int_type_t< detail::index_type_size, false > uindex_t
Type used for an unsigned index in PCL.