39#ifndef PCL_OCTREE_ITERATOR_HPP_
40#define PCL_OCTREE_ITERATOR_HPP_
42#include <pcl/console/print.h>
47template <
typename OctreeT>
56template <
typename OctreeT>
66template <
typename OctreeT>
74 stack_.reserve(this->max_octree_depth_);
81 stack_entry.
node_ = this->octree_->getRootNode();
85 stack_.push_back(stack_entry);
87 this->current_state_ = &stack_.back();
92template <
typename OctreeT>
99 unsigned char current_depth = stack_.back().depth_;
102 while (stack_.size() && (stack_.back().depth_ >= current_depth))
106 this->current_state_ = &stack_.back();
109 this->current_state_ = 0;
115template <
typename OctreeT>
127 if ((this->max_octree_depth_ >= stack_entry.
depth_) &&
135 for (std::int8_t i = 7; i >= 0; --i) {
136 const unsigned char child_idx = (
unsigned char)i;
139 if (this->octree_->branchHasChild(*current_branch, child_idx)) {
144 this->octree_->getBranchChildPtr(*current_branch, child_idx);
146 stack_.push_back(stack_entry);
154 this->current_state_ = &stack_.back();
157 this->current_state_ = 0;
165template <
typename OctreeT>
176template <
typename OctreeT>
188template <
typename OctreeT>
200 FIFO_entry.
node_ = this->octree_->getRootNode();
204 FIFO_.push_back(FIFO_entry);
206 this->current_state_ = &FIFO_.front();
211template <
typename OctreeT>
223 if ((this->max_octree_depth_ >= FIFO_entry.
depth_) &&
229 for (
unsigned char child_idx = 0; child_idx < 8; ++child_idx) {
232 if (this->octree_->branchHasChild(*current_branch, child_idx)) {
235 current_key.
pushBranch(
static_cast<unsigned char>(child_idx));
238 this->octree_->getBranchChildPtr(*current_branch, child_idx);
240 FIFO_.push_back(FIFO_entry);
248 this->current_state_ = &FIFO_.front();
251 this->current_state_ = 0;
259template <
typename OctreeT>
265template <
typename OctreeT>
269, fixed_depth_(fixed_depth_arg)
271 this->
reset(fixed_depth_arg);
275template <
typename OctreeT>
280 fixed_depth_ = fixed_depth_arg;
282 if (!this->octree_) {
288 if ((!this->current_state_) || (fixed_depth_ <= this->getCurrentOctreeDepth()))
291 if (this->octree_->getTreeDepth() < fixed_depth_) {
292 PCL_WARN(
"[pcl::octree::FixedDepthIterator] The requested fixed depth was bigger "
293 "than the octree's depth.\n");
294 PCL_WARN(
"[pcl::octree::FixedDepthIterator] fixed_depth = %d (instead of %d)\n",
295 this->octree_->getTreeDepth(),
303 this->max_octree_depth_ = std::min(fixed_depth_, this->octree_->getTreeDepth());
307 this->current_state_ = &FIFO_.front();
310 while (this->current_state_ && (this->getCurrentOctreeDepth() != fixed_depth_))
315template <
typename OctreeT>
324template <
typename OctreeT>
326 OctreeT* octree_arg,
uindex_t max_depth_arg)
333template <
typename OctreeT>
338 const std::deque<IteratorState>& fifo)
343template <
typename OctreeT>
352template <
typename OctreeT>
358 }
while ((this->current_state_) &&
359 (this->current_state_->node_->getNodeType() !=
LEAF_NODE));
365template <
typename OctreeT>
OctreeBreadthFirstIterator & operator++()
Preincrement operator.
void reset()
Reset the iterator to the root node of the octree.
OctreeBreadthFirstIterator(uindex_t max_depth_arg=0)
Empty constructor.
typename OctreeIteratorBase< OctreeT >::BranchNode BranchNode
typename OctreeIteratorBase< OctreeT >::BranchNode BranchNode
void skipChildVoxels()
Skip all child voxels of current node and return to parent node.
OctreeDepthFirstIterator & operator++()
Preincrement operator.
virtual void reset()
Reset the iterator to the root node of the octree.
OctreeDepthFirstIterator(uindex_t max_depth_arg=0)
Empty constructor.
void reset()
Reset the iterator to the first node at the current depth.
OctreeFixedDepthIterator()
Empty constructor.
Abstract octree iterator class
void reset()
Reset iterator.
void popBranch()
pop child node from octree key
void pushBranch(unsigned char childIndex)
push a child node to the octree key
Octree leaf node iterator class.
OctreeLeafNodeBreadthFirstIterator(uindex_t max_depth_arg=0)
Empty constructor.
void reset()
Reset the iterator to the first leaf in the breadth first way.
OctreeLeafNodeBreadthFirstIterator & operator++()
Preincrement operator.
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.