Point Cloud Library (PCL)  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
octree_iterator.h
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-2011, 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: octree_iterator.h 3749 2011-12-31 22:58:01Z rusu $
00037  */
00038 
00039 #ifndef OCTREE_ITERATOR_H
00040 #define OCTREE_ITERATOR_H
00041 
00042 #include <cstddef>
00043 #include <vector>
00044 
00045 #include "octree_nodes.h"
00046 
00047 #include <pcl/point_cloud.h>
00048 #include <pcl/point_types.h>
00049 
00050 #include <iterator>
00051 
00052 namespace pcl
00053 {
00054   namespace octree
00055   {
00057 
00062     template<typename DataT, typename LeafT, typename OctreeT>
00063     class OctreeNodeIterator: public std::iterator<std::forward_iterator_tag, const OctreeNode, void,
00064           const OctreeNode*, const OctreeNode&>
00065     {
00066       // public typedefs
00067       typedef typename OctreeT::OctreeBranch OctreeBranch;
00068       typedef typename OctreeT::OctreeKey OctreeKey;
00069 
00070       public:
00074         explicit
00075         OctreeNodeIterator (const OctreeT& octree_arg);
00076 
00078         virtual
00079         ~OctreeNodeIterator ();
00080 
00083         inline void
00084         reset ();
00085 
00089         inline const OctreeKey&
00090         getCurrentOctreeKey () const
00091         {
00092           return (currentOctreeKey_);
00093         }
00094 
00098         inline unsigned int
00099         getCurrentOctreeDepth () const
00100         {
00101           return (currentOctreeDepth_);
00102         }
00103 
00107         inline const OctreeNode*
00108         getCurrentOctreeNode () const
00109         {
00110           return (currentNode_);
00111         }
00112 
00117         inline void
00118         getVoxelBounds (Eigen::Vector3f &min_pt, Eigen::Vector3f &max_pt) const
00119         {
00120           octree_->genVoxelBoundsFromOctreeKey (currentOctreeKey_, currentOctreeDepth_, min_pt, max_pt);
00121         }
00122 
00126         inline const OctreeNode*
00127         operator* () const
00128         { // return designated object
00129           return (this->getCurrentOctreeNode ());
00130         }
00131 
00135         inline bool
00136         operator== (const OctreeNodeIterator& right_arg) const
00137         { // test for iterator equality
00138           return ((octree_ == right_arg.octree_) && (currentNode_ == right_arg.currentNode_));
00139         }
00140 
00144         inline bool
00145         operator!= (const OctreeNodeIterator& right_arg) const
00146         { // test for iterator inequality
00147           return (!(octree_ != right_arg.octree_) || !(currentNode_ != right_arg.currentNode_));
00148         }
00149 
00152         void
00153         skipChildVoxels ();
00154 
00158         OctreeNodeIterator&
00159         operator++ ();
00160 
00164         inline OctreeNodeIterator
00165         operator++ (int)
00166         {
00167           OctreeNodeIterator _Tmp = *this;
00168           ++*this;
00169           return (_Tmp);
00170         }
00171 
00172       protected:
00174         const OctreeT& octree_;
00175 
00177         const OctreeNode* currentNode_;
00178 
00180         unsigned char currentChildIdx_;
00181 
00183         unsigned int currentOctreeDepth_;
00184 
00186         OctreeKey currentOctreeKey_;
00187 
00189         std::vector<std::pair<OctreeNode const*, unsigned char> > stack_;
00190       };
00191 
00193 
00198 
00199     template<typename DataT, typename LeafT, typename OctreeT>
00200     class OctreeLeafNodeIterator : public OctreeNodeIterator<DataT, LeafT, OctreeT>
00201     {
00202       public:
00206         explicit
00207         OctreeLeafNodeIterator (const OctreeT& octree_arg) :
00208           OctreeNodeIterator<DataT, LeafT, OctreeT> (octree_arg)
00209         {
00210         }
00211 
00213         virtual
00214         ~OctreeLeafNodeIterator ()
00215         {
00216         }
00217 
00221         inline OctreeLeafNodeIterator&
00222         operator++ ()
00223         {
00224           do
00225           {
00226             OctreeNodeIterator<DataT, LeafT, OctreeT>::operator++ ();
00227           } while ((this->currentNode_) && (this->currentNode_->getNodeType () != LEAF_NODE));
00228 
00229           return (*this);
00230         }
00231 
00235         inline OctreeLeafNodeIterator
00236         operator++ (int)
00237         {
00238           OctreeLeafNodeIterator _Tmp = *this;
00239           ++*this;
00240           return (_Tmp);
00241         }
00242 
00246         const LeafT*
00247         operator* () const
00248         {
00249           // return designated object
00250           const LeafT* ret = NULL;
00251 
00252           if (this->currentNode_ && (this->currentNode_->getNodeType () == LEAF_NODE))
00253             ret = (const LeafT*)this->currentNode_;
00254           return (ret);
00255         }
00256 
00260         virtual void
00261         getData (const DataT*& data_arg) const
00262         {
00263           const DataT* result = 0;
00264 
00265           if (this->currentNode_ && (this->currentNode_->getNodeType () == LEAF_NODE))
00266           {
00267             const LeafT* leafNode = (const LeafT*)this->currentNode_;
00268             leafNode->getData (result);
00269           }
00270           data_arg = result;
00271         }
00272 
00276         virtual void
00277         getData (std::vector<DataT>& dataVector_arg) const
00278         {
00279           if (this->currentNode_ && (this->currentNode_->getNodeType () == LEAF_NODE))
00280           {
00281             const LeafT* leafNode = (const LeafT*)this->currentNode_;
00282             leafNode->getData (dataVector_arg);
00283           }
00284         }
00285       };
00286 
00287   }
00288 }
00289 
00290 #endif
00291 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines