39 #ifndef OCTREE_ITERATOR_HPP_
40 #define OCTREE_ITERATOR_HPP_
52 template<
typename DataT,
typename OctreeT>
54 OctreeT& octree_arg) :
58 stack_.reserve (this->octree_.getTreeDepth ());
65 template<
typename DataT,
typename OctreeT>
71 template<
typename DataT,
typename OctreeT>
81 template<
typename DataT,
typename OctreeT>
84 if (!this->currentNode_)
88 if (stack_.size () > 0)
91 std::pair<OctreeNode*, unsigned char>& stackEntry =
96 this->currentNode_ = stackEntry.first;
97 currentChildIdx_ = stackEntry.second;
100 this->currentOctreeKey_.x = (this->currentOctreeKey_.x >> 1);
101 this->currentOctreeKey_.y = (this->currentOctreeKey_.y >> 1);
102 this->currentOctreeKey_.z = (this->currentOctreeKey_.z >> 1);
105 this->currentOctreeDepth_--;
109 this->currentNode_ = NULL;
113 template<
typename DataT,
typename OctreeT>
117 if (this->currentNode_)
120 bool bTreeUp =
false;
123 if (this->currentNode_->getNodeType () ==
BRANCH_NODE)
127 static_cast<BranchNode*
> (this->currentNode_);
129 if (currentChildIdx_ < 8)
131 itNode = this->octree_.getBranchChildPtr (*currentBranch,
134 while ( (currentChildIdx_ < 7) && ! (itNode))
139 itNode = this->octree_.getBranchChildPtr (*currentBranch,
165 if (stack_.size () > 0)
168 std::pair<OctreeNode*, unsigned char>& stackEntry = stack_.back ();
172 this->currentNode_ = stackEntry.first;
173 currentChildIdx_ = stackEntry.second;
176 this->currentOctreeKey_.x = (this->currentOctreeKey_.x >> 1);
177 this->currentOctreeKey_.y = (this->currentOctreeKey_.y >> 1);
178 this->currentOctreeKey_.z = (this->currentOctreeKey_.z >> 1);
181 this->currentOctreeDepth_--;
186 this->currentNode_ = NULL;
195 std::pair<OctreeNode*, unsigned char> newStackEntry;
198 newStackEntry.first = this->currentNode_;
199 newStackEntry.second =
static_cast<unsigned char> (currentChildIdx_
203 stack_.push_back (newStackEntry);
206 this->currentOctreeKey_.x = (this->currentOctreeKey_.x << 1)
207 | (!! (currentChildIdx_ & (1 << 2)));
208 this->currentOctreeKey_.y = (this->currentOctreeKey_.y << 1)
209 | (!! (currentChildIdx_ & (1 << 1)));
210 this->currentOctreeKey_.z = (this->currentOctreeKey_.z << 1)
211 | (!! (currentChildIdx_ & (1 << 0)));
214 this->currentOctreeDepth_++;
217 currentChildIdx_ = 0;
218 this->currentNode_ = itNode;
226 template<
typename DataT,
typename OctreeT>
228 OctreeT& octree_arg) :
238 template<
typename DataT,
typename OctreeT>
244 template<
typename DataT,
typename OctreeT>
253 for (i = 0; i < 8; i++)
256 BranchNode* currentBranch =
257 static_cast<BranchNode*
> (this->currentNode_);
260 static_cast<OctreeNode*
> (this->octree_.getBranchChildPtr (
269 newKey.
x = (this->currentOctreeKey_.x << 1) | (!! (i & (1 << 2)));
270 newKey.
y = (this->currentOctreeKey_.y << 1) | (!! (i & (1 << 1)));
271 newKey.
z = (this->currentOctreeKey_.z << 1) | (!! (i & (1 << 0)));
273 FIFOElement newListElement;
274 newListElement.node = itNode;
275 newListElement.key = newKey;
276 newListElement.depth = this->currentOctreeDepth_ + 1;
278 FIFO_.push_back (newListElement);
285 template<
typename DataT,
typename OctreeT>
295 template<
typename DataT,
typename OctreeT>
299 if (this->currentNode_)
303 addChildNodesToFIFO (this->currentNode_);
305 if (FIFO_.size () > 0)
307 FIFOElement FIFOElement;
310 FIFOElement = FIFO_.front ();
314 this->currentNode_ = FIFOElement.node;
315 this->currentOctreeKey_ = FIFOElement.key;
316 this->currentOctreeDepth_ = FIFOElement.depth;
321 this->currentNode_ = NULL;