Point Cloud Library (PCL)  1.7.0
/tmp/buildd/pcl-1.7-1.7.0/octree/include/pcl/octree/octree_pointcloud_adjacency_container.h
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2012, Jeremie Papon
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  *  Author : jpapon@gmail.com
00037  *  Email  : jpapon@gmail.com
00038  */
00039 
00040 #ifndef PCL_OCTREE_POINTCLOUD_ADJACENCY_CONTAINER_H_
00041 #define PCL_OCTREE_POINTCLOUD_ADJACENCY_CONTAINER_H_
00042 
00043 namespace pcl
00044 { 
00045   
00046   namespace octree
00047   {
00048     /** \brief @b Octree adjacency leaf container class- stores set of pointers to neighbors, number of points added, and a DataT value
00049     *    \note This class implements a leaf node that stores pointers to neighboring leaves
00050     *   \note This class also has a virtual computeData function, which is called by octreePointCloudAdjacency::addPointsFromInputCloud.
00051     *   \note You should make explicit instantiations of it for your pointtype/datatype combo (if needed) see supervoxel_clustering.hpp for an example of this
00052     */
00053     template<typename PointInT, typename DataT = PointInT>
00054     class OctreePointCloudAdjacencyContainer : public OctreeContainerBase
00055     {
00056     public:
00057       typedef std::set<OctreePointCloudAdjacencyContainer*> NeighborSetT;
00058       //iterators to neighbors
00059       typedef typename NeighborSetT::iterator iterator;
00060       typedef typename NeighborSetT::const_iterator const_iterator;
00061       inline iterator begin () { return (neighbors_.begin ()); }
00062       inline iterator end ()   { return (neighbors_.end ()); }
00063       inline const_iterator begin () const { return (neighbors_.begin ()); }
00064       inline const_iterator end () const  { return (neighbors_.end ()); }
00065       //size of neighbors
00066       inline size_t size () const { return neighbors_.size (); }
00067       //insert for neighbors
00068       inline std::pair<iterator, bool> insert (OctreePointCloudAdjacencyContainer* neighbor) { return neighbors_.insert (neighbor); }
00069       
00070       /** \brief Class initialization. */
00071       OctreePointCloudAdjacencyContainer () :
00072       OctreeContainerBase ()
00073       {
00074         this->reset();       
00075       }
00076       
00077       /** \brief Empty class deconstructor. */
00078       virtual ~OctreePointCloudAdjacencyContainer ()
00079       {
00080       }
00081       
00082       /** \brief deep copy function */
00083       virtual OctreePointCloudAdjacencyContainer *
00084       deepCopy () const
00085       {
00086         OctreePointCloudAdjacencyContainer *new_container = new OctreePointCloudAdjacencyContainer;
00087         new_container->setNeighbors (this->neighbors_);
00088         new_container->setPointCounter (this->num_points_);
00089         return new_container;
00090       }
00091       
00092       /** \brief Add new point to container- this just counts points
00093        * \note To actually store data in the leaves, need to specialize this
00094        * for your point and data type as in supervoxel_clustering.hpp
00095        * \param[in] new_point the new point to add  
00096        */
00097       void 
00098       addPoint (const PointInT& new_point)
00099       {
00100         using namespace pcl::common;
00101         ++num_points_;
00102       }
00103       
00104       /** \brief Function for working on data added. Base implementation does nothing 
00105        * */
00106       void
00107       computeData ()
00108       {
00109       }
00110       
00111       /** \brief Gets the number of points contributing to this leaf */
00112       int
00113       getPointCounter () const { return num_points_; }
00114       
00115       /** \brief Sets the number of points contributing to this leaf */
00116       void
00117       setPointCounter (int points_arg) { num_points_ = points_arg; }
00118       
00119       /** \brief Clear the voxel centroid */
00120       virtual void 
00121       reset ()
00122       {
00123         neighbors_.clear ();
00124         num_points_ = 0;
00125         data_ = DataT ();
00126       }
00127       
00128       /** \brief Add new neighbor to voxel.
00129        * \param[in] neighbor the new neighbor to add  
00130        */
00131       void 
00132       addNeighbor (OctreePointCloudAdjacencyContainer *neighbor)
00133       {
00134         neighbors_.insert (neighbor);
00135       }
00136       
00137       /** \brief Remove neighbor from neighbor set.
00138        * \param[in] neighbor the neighbor to remove
00139        */
00140       void 
00141       removeNeighbor (OctreePointCloudAdjacencyContainer *neighbor)
00142       {
00143         neighbors_.erase (neighbor);
00144         
00145       }
00146       
00147       /** \brief Returns the number of neighbors this leaf has
00148        *  \returns number of neighbors
00149        */
00150       size_t 
00151       getNumNeighbors () const
00152       {
00153         return neighbors_.size ();
00154       }
00155       
00156       /** \brief Sets the whole neighbor set
00157        * \param[in] neighbor_arg the new set
00158        */
00159       void
00160       setNeighbors (const NeighborSetT &neighbor_arg)
00161       {
00162         neighbors_ = neighbor_arg;
00163       }
00164       
00165       /** \brief Returns a reference to the data member to access it without copying */
00166       DataT&
00167       getData () { return data_; }
00168       
00169       /** \brief Sets the data member
00170        *  \param[in] data_arg New value for data
00171        */
00172       void
00173       setData (const DataT& data_arg) { data_ = data_arg;}
00174       
00175       /** \brief  virtual method to get size of container 
00176        * \return number of points added to leaf node container.
00177        */
00178       virtual size_t
00179       getSize ()
00180       {
00181         return num_points_;
00182       }
00183       
00184       
00185     private:
00186       int num_points_;
00187       NeighborSetT neighbors_;
00188       DataT data_;
00189     };
00190   }
00191 }
00192 
00193 #endif