Point Cloud Library (PCL)  1.7.0
/tmp/buildd/pcl-1.7-1.7.0/people/include/pcl/people/height_map_2d.h
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Point Cloud Library (PCL) - www.pointclouds.org
00005  * Copyright (c) 2013-, Open Perception, 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 the copyright holder(s) 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  * height_map_2d.h
00037  * Created on: Nov 30, 2012
00038  * Author: Matteo Munaro
00039  */
00040 
00041 #ifndef PCL_PEOPLE_HEIGHT_MAP_2D_H_
00042 #define PCL_PEOPLE_HEIGHT_MAP_2D_H_
00043 
00044 #include <pcl/people/person_cluster.h>
00045 #include <pcl/point_types.h>
00046 
00047 namespace pcl
00048 {
00049   namespace people
00050   {
00051     /** \brief @b HeightMap2D represents a class for creating a 2D height map from a point cloud and searching for its local maxima
00052       * \author Matteo Munaro
00053       * \ingroup people
00054     */
00055     template <typename PointT> class HeightMap2D;
00056 
00057     template <typename PointT>
00058     class HeightMap2D
00059     {
00060     public:
00061 
00062       typedef pcl::PointCloud<PointT> PointCloud;
00063       typedef boost::shared_ptr<PointCloud> PointCloudPtr;
00064       typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;
00065 
00066       /** \brief Constructor. */
00067       HeightMap2D();
00068 
00069       /** \brief Destructor. */
00070       virtual ~HeightMap2D ();
00071 
00072       /**
00073        * \brief Compute the height map with the projection of cluster points onto the ground plane.
00074        * 
00075        * \param[in] cluster The PersonCluster used to compute the height map.
00076        */
00077       void
00078       compute (pcl::people::PersonCluster<PointT>& cluster);
00079 
00080       /**
00081        * \brief Compute local maxima of the height map.
00082        */
00083       void
00084       searchLocalMaxima ();
00085 
00086       /**
00087        * \brief Filter maxima of the height map by imposing a minimum distance between them.
00088        */
00089       void
00090       filterMaxima ();
00091 
00092       /**
00093        * \brief Set initial cluster indices.
00094        * 
00095        * \param[in] cloud A pointer to the input cloud.
00096        */
00097       void
00098       setInputCloud (PointCloudPtr& cloud);
00099 
00100       /**
00101        * \brief Set the ground coefficients.
00102        * 
00103        * \param[in] ground_coeffs The ground plane coefficients.
00104        */
00105       void
00106       setGround (Eigen::VectorXf& ground_coeffs);
00107 
00108       /**
00109        * \brief Set bin size for the height map. 
00110        * 
00111        * \param[in] bin_size Bin size for the height map (default = 0.06).
00112        */
00113       void
00114       setBinSize (float bin_size);
00115 
00116       /**
00117        * \brief Set minimum distance between maxima. 
00118        * 
00119        * \param[in] minimum_distance_between_maxima Minimum allowed distance between maxima (default = 0.3).
00120        */
00121       void
00122       setMinimumDistanceBetweenMaxima (float minimum_distance_between_maxima);
00123 
00124       /**
00125        * \brief Set sensor orientation to landscape mode (false) or portrait mode (true).
00126        * 
00127        * \param[in] vertical Landscape (false) or portrait (true) mode (default = false).
00128        */
00129       void
00130       setSensorPortraitOrientation (bool vertical);
00131 
00132       /**
00133        * \brief Get the height map as a vector of int.
00134        */
00135       std::vector<int>&
00136       getHeightMap ();
00137 
00138       /**
00139        * \brief Get bin size for the height map. 
00140        */
00141       float
00142       getBinSize ();
00143 
00144       /**
00145        * \brief Get minimum distance between maxima of the height map. 
00146        */
00147       float
00148       getMinimumDistanceBetweenMaxima ();
00149 
00150       /**
00151        * \brief Return the maxima number after the filterMaxima method.
00152        */
00153       int&
00154       getMaximaNumberAfterFiltering ();
00155 
00156       /**
00157        * \brief Return the point cloud indices corresponding to the maxima computed after the filterMaxima method.
00158        */
00159       std::vector<int>&
00160       getMaximaCloudIndicesFiltered ();
00161 
00162     protected:
00163       /** \brief ground plane coefficients */
00164       Eigen::VectorXf ground_coeffs_;            
00165       
00166       /** \brief ground plane normalization factor */
00167       float sqrt_ground_coeffs_;              
00168       
00169       /** \brief pointer to the input cloud */
00170       PointCloudPtr cloud_;                
00171       
00172       /** \brief if true, the sensor is considered to be vertically placed (portrait mode) */
00173       bool vertical_;                    
00174       
00175       /** \brief vector with maximum height values for every bin (height map) */
00176       std::vector<int> buckets_;              
00177       
00178       /** \brief indices of the pointcloud points with maximum height for every bin */
00179       std::vector<int> buckets_cloud_indices_;      
00180       
00181       /** \brief bin dimension */
00182       float bin_size_;                  
00183       
00184       /** \brief number of local maxima in the height map */
00185       int maxima_number_;                  
00186       
00187       /** \brief contains the position of the maxima in the buckets vector */
00188       std::vector<int> maxima_indices_;          
00189       
00190       /** \brief contains the point cloud position of the maxima (indices of the point cloud) */
00191       std::vector<int> maxima_cloud_indices_;        
00192       
00193       /** \brief number of local maxima after filtering */
00194       int maxima_number_after_filtering_;          
00195       
00196       /** \brief contains the position of the maxima in the buckets array after filtering */
00197       std::vector<int> maxima_indices_filtered_;      
00198       
00199       /** \brief contains the point cloud position of the maxima after filtering */
00200       std::vector<int> maxima_cloud_indices_filtered_;  
00201       
00202       /** \brief minimum allowed distance between maxima */
00203       float min_dist_between_maxima_;            
00204     };
00205 
00206   } /* namespace people */
00207 } /* namespace pcl */
00208 #include <pcl/people/impl/height_map_2d.hpp>
00209 #endif /* PCL_PEOPLE_HEIGHT_MAP_2D_H_ */