outofcore_depth_first_iterator.hpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2012, Willow Garage, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Willow Garage, Inc. nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id$
00037  */
00038 
00039 #ifndef PCL_OUTOFCORE_DEPTH_FIRST_ITERATOR_IMPL_H_
00040 #define PCL_OUTOFCORE_DEPTH_FIRST_ITERATOR_IMPL_H_
00041 
00042 namespace pcl
00043 {
00044   namespace outofcore
00045   {
00046 
00047     template<typename PointT, typename ContainerT> 
00048     OutofcoreDepthFirstIterator<PointT, ContainerT>::OutofcoreDepthFirstIterator (OutofcoreOctreeBase<ContainerT, PointT>& octree_arg) 
00049     : OutofcoreIteratorBase<PointT, ContainerT> (octree_arg)
00050     , currentChildIdx_ (0)
00051     , stack_ (0)
00052     {
00053       stack_.reserve (this->octree_.getTreeDepth ());
00054       OutofcoreIteratorBase<PointT,ContainerT>::reset ();
00055     }
00056 
00058 
00059     template<typename PointT, typename ContainerT> 
00060     OutofcoreDepthFirstIterator<PointT, ContainerT>::~OutofcoreDepthFirstIterator ()
00061     {
00062     }
00063 
00065 
00066     template<typename PointT, typename ContainerT> 
00067     OutofcoreDepthFirstIterator<PointT, ContainerT>& 
00068     OutofcoreDepthFirstIterator<PointT, ContainerT>::operator++ ()
00069     {
00070       //when currentNode_ is 0, skip incrementing because it is already at the end
00071       if (this->currentNode_)
00072       {
00073         bool bTreeUp = false;
00074         OutofcoreOctreeBaseNode<ContainerT, PointT>* itNode = 0;
00075 
00076         if (this->currentNode_->getNodeType () == pcl::octree::BRANCH_NODE)
00077         {
00078           BranchNode* currentBranch = static_cast<BranchNode*> (this->currentNode_);
00079           
00080           if (currentChildIdx_ < 8)
00081           {
00082             itNode = this->octree_.getBranchChildPtr (*currentBranch, currentChildIdx_);
00083 
00084             //keep looking for a valid child until we've run out of children or a valid one is found
00085             while ((currentChildIdx_ < 7) && !(itNode))
00086             {
00087               //find next existing child node
00088               currentChildIdx_++;
00089               itNode = this->octree_.getBranchChildPtr (*currentBranch, currentChildIdx_);
00090             }
00091             //if no valid one was found, set flag to move back up the tree to the parent node
00092             if (!itNode)
00093             {
00094               bTreeUp = true;
00095             }
00096           }
00097           else
00098           {
00099             bTreeUp = true;
00100           }
00101         }
00102         else
00103         {
00104           bTreeUp = true;
00105         }
00106         
00107         if (bTreeUp)
00108         {
00109           if (stack_.size () > 0)
00110           {
00111             std::pair<OutofcoreOctreeBaseNode<ContainerT, PointT>*, unsigned char>& stackEntry = stack_.back ();
00112             stack_.pop_back ();
00113               
00114             this->currentNode_ = stackEntry.first;
00115             currentChildIdx_ = stackEntry.second;
00116               
00117             //don't do anything with the keys here...
00118             this->currentOctreeDepth_--;
00119           }
00120           else
00121           {
00122             this->currentNode_ = NULL;
00123           }
00124             
00125         }
00126         else
00127         {
00128           std::pair<OutofcoreOctreeBaseNode<ContainerT, PointT>*, unsigned char> newStackEntry;
00129           newStackEntry.first = this->currentNode_;
00130           newStackEntry.second = static_cast<unsigned char> (currentChildIdx_+1);
00131             
00132           stack_.push_back (newStackEntry);
00133             
00134           //don't do anything with the keys here...
00135             
00136           this->currentOctreeDepth_++;
00137           currentChildIdx_= 0;
00138           this->currentNode_ = itNode;
00139         }
00140       }
00141         
00142       return (*this);
00143     }
00144 
00146 
00147   }//namesapce pcl
00148 }//namespace outofcore
00149 
00150 #endif //PCL_OUTOFCORE_DEPTH_FIRST_ITERATOR_IMPL_H_
00151 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:30