Point Cloud Library (PCL)  1.7.0
/tmp/buildd/pcl-1.7-1.7.0/keypoints/include/pcl/keypoints/harris_3d.h
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  */
00037 
00038 #ifndef PCL_HARRIS_KEYPOINT_3D_H_
00039 #define PCL_HARRIS_KEYPOINT_3D_H_
00040 
00041 #include <pcl/keypoints/keypoint.h>
00042 
00043 namespace pcl
00044 {
00045   /** \brief HarrisKeypoint3D uses the idea of 2D Harris keypoints, but instead of using image gradients, it uses
00046     * surface normals.
00047     *
00048     * \author Suat Gedikli
00049     * \ingroup keypoints
00050     */
00051   template <typename PointInT, typename PointOutT, typename NormalT = pcl::Normal>
00052   class HarrisKeypoint3D : public Keypoint<PointInT, PointOutT>
00053   {
00054     public:
00055       typedef boost::shared_ptr<HarrisKeypoint3D<PointInT, PointOutT, NormalT> > Ptr;
00056       typedef boost::shared_ptr<const HarrisKeypoint3D<PointInT, PointOutT, NormalT> > ConstPtr;
00057 
00058       typedef typename Keypoint<PointInT, PointOutT>::PointCloudIn PointCloudIn;
00059       typedef typename Keypoint<PointInT, PointOutT>::PointCloudOut PointCloudOut;
00060       typedef typename Keypoint<PointInT, PointOutT>::KdTree KdTree;
00061       typedef typename PointCloudIn::ConstPtr PointCloudInConstPtr;
00062 
00063       typedef typename pcl::PointCloud<NormalT> PointCloudN;
00064       typedef typename PointCloudN::Ptr PointCloudNPtr;
00065       typedef typename PointCloudN::ConstPtr PointCloudNConstPtr;
00066 
00067       using Keypoint<PointInT, PointOutT>::name_;
00068       using Keypoint<PointInT, PointOutT>::input_;
00069       using Keypoint<PointInT, PointOutT>::indices_;
00070       using Keypoint<PointInT, PointOutT>::surface_;
00071       using Keypoint<PointInT, PointOutT>::tree_;
00072       using Keypoint<PointInT, PointOutT>::k_;
00073       using Keypoint<PointInT, PointOutT>::search_radius_;
00074       using Keypoint<PointInT, PointOutT>::search_parameter_;
00075       using Keypoint<PointInT, PointOutT>::initCompute;
00076 
00077       typedef enum {HARRIS = 1, NOBLE, LOWE, TOMASI, CURVATURE} ResponseMethod;
00078 
00079       /** \brief Constructor
00080         * \param[in] method the method to be used to determine the corner responses
00081         * \param[in] radius the radius for normal estimation as well as for non maxima suppression
00082         * \param[in] threshold the threshold to filter out weak corners
00083         */
00084       HarrisKeypoint3D (ResponseMethod method = HARRIS, float radius = 0.01f, float threshold = 0.0f)
00085       : threshold_ (threshold)
00086       , refine_ (true)
00087       , nonmax_ (true)
00088       , method_ (method)
00089       , threads_ (0)
00090       {
00091         name_ = "HarrisKeypoint3D";
00092         search_radius_ = radius;
00093       }
00094       
00095       /** \brief Empty destructor */
00096       virtual ~HarrisKeypoint3D () {}
00097 
00098       /** \brief Set the method of the response to be calculated.
00099         * \param[in] type
00100         */
00101       void 
00102       setMethod (ResponseMethod type);
00103 
00104       /** \brief Set the radius for normal estimation and non maxima supression.
00105         * \param[in] radius
00106         */
00107       void 
00108       setRadius (float radius);
00109 
00110       /** \brief Set the threshold value for detecting corners. This is only evaluated if non maxima suppression is turned on.
00111         * \brief note non maxima suppression needs to be activated in order to use this feature.
00112         * \param[in] threshold
00113         */
00114       void 
00115       setThreshold (float threshold);
00116 
00117       /** \brief Whether non maxima suppression should be applied or the response for each point should be returned
00118         * \note this value needs to be turned on in order to apply thresholding and refinement
00119         * \param[in] nonmax default is false
00120         */
00121       void 
00122       setNonMaxSupression (bool = false);
00123 
00124       /** \brief Whether the detected key points should be refined or not. If turned of, the key points are a subset of the original point cloud. Otherwise the key points may be arbitrary.
00125         * \brief note non maxima supression needs to be on in order to use this feature.
00126         * \param[in] do_refine
00127         */
00128       void 
00129       setRefine (bool do_refine);
00130 
00131       /** \brief Set normals if precalculated normals are available.
00132         * \param normals
00133         */
00134       void 
00135       setNormals (const PointCloudNConstPtr &normals);
00136 
00137       /** \brief Provide a pointer to a dataset to add additional information
00138         * to estimate the features for every point in the input dataset.  This
00139         * is optional, if this is not set, it will only use the data in the
00140         * input cloud to estimate the features.  This is useful when you only
00141         * need to compute the features for a downsampled cloud.
00142         * \param[in] cloud a pointer to a PointCloud message
00143         */
00144       virtual void
00145       setSearchSurface (const PointCloudInConstPtr &cloud) { surface_ = cloud; normals_.reset(); }
00146 
00147       /** \brief Initialize the scheduler and set the number of threads to use.
00148         * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
00149         */
00150       inline void
00151       setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
00152     protected:
00153       bool
00154       initCompute ();
00155       void detectKeypoints (PointCloudOut &output);
00156       /** \brief gets the corner response for valid input points*/
00157       void responseHarris (PointCloudOut &output) const;
00158       void responseNoble (PointCloudOut &output) const;
00159       void responseLowe (PointCloudOut &output) const;
00160       void responseTomasi (PointCloudOut &output) const;
00161       void responseCurvature (PointCloudOut &output) const;
00162       void refineCorners (PointCloudOut &corners) const;
00163       /** \brief calculates the upper triangular part of unnormalized covariance matrix over the normals given by the indices.*/
00164       void calculateNormalCovar (const std::vector<int>& neighbors, float* coefficients) const;
00165     private:
00166       float threshold_;
00167       bool refine_;
00168       bool nonmax_;
00169       ResponseMethod method_;
00170       PointCloudNConstPtr normals_;
00171       unsigned int threads_;
00172   };
00173 }
00174 
00175 #include <pcl/keypoints/impl/harris_3d.hpp>
00176 
00177 #endif // #ifndef PCL_HARRIS_KEYPOINT_3D_H_
00178