Point Cloud Library (PCL)  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
mls.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: mls.h 3753 2011-12-31 23:30:57Z rusu $
00037  *
00038  */
00039 
00040 #ifndef PCL_MLS_H_
00041 #define PCL_MLS_H_
00042 
00043 // PCL includes
00044 #include <pcl/pcl_base.h>
00045 #include <boost/bind.hpp>
00046 #include <boost/function.hpp>
00047 #include "pcl/search/pcl_search.h"
00048 
00049 #include <Eigen/SVD>
00050 
00051 namespace pcl
00052 {
00058   template <typename PointInT, typename NormalOutT>
00059   class MovingLeastSquares: public PCLBase<PointInT>
00060   {
00061     public:
00062       using PCLBase<PointInT>::input_;
00063       using PCLBase<PointInT>::indices_;
00064       using PCLBase<PointInT>::fake_indices_;
00065       using PCLBase<PointInT>::initCompute;
00066       using PCLBase<PointInT>::deinitCompute;
00067 
00068       typedef typename pcl::search::Search<PointInT> KdTree;
00069       typedef typename pcl::search::Search<PointInT>::Ptr KdTreePtr;
00070 
00071       typedef pcl::PointCloud<NormalOutT> NormalCloudOut;
00072       typedef typename NormalCloudOut::Ptr NormalCloudOutPtr;
00073       typedef typename NormalCloudOut::ConstPtr NormalCloudOutConstPtr;
00074 
00075       typedef pcl::PointCloud<PointInT> PointCloudIn;
00076       typedef typename PointCloudIn::Ptr PointCloudInPtr;
00077       typedef typename PointCloudIn::ConstPtr PointCloudInConstPtr;
00078 
00079       typedef boost::function<int (int, double, std::vector<int> &, std::vector<float> &)> SearchMethod;
00080 
00082       MovingLeastSquares () : PCLBase<PointInT> (), tree_ (), order_ (2), polynomial_fit_ (true), search_radius_ (0), sqr_gauss_param_ (0) {};
00083 
00088       inline void 
00089       setOutputNormals (NormalCloudOutPtr cloud) { normals_ = cloud; }
00090 
00092       inline NormalCloudOutPtr 
00093       getOutputNormals () { return normals_; }
00094 
00098       inline void
00099       setSearchMethod (const KdTreePtr &tree)
00100       {
00101         tree_ = tree;
00102         // Declare the search locator definition
00103         int (KdTree::*radiusSearch)(int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_sqr_distances, int max_nn) const = &KdTree::radiusSearch;
00104         search_method_ = boost::bind (radiusSearch, boost::ref (tree_), _1, _2, _3, _4, INT_MAX);
00105       }
00106 
00108       inline KdTreePtr 
00109       getSearchMethod () { return (tree_); }
00110 
00114       inline void 
00115       setPolynomialOrder (int order) { order_ = order; }
00116 
00118       inline int 
00119       getPolynomialOrder () { return (order_); }
00120 
00124       inline void 
00125       setPolynomialFit (bool polynomial_fit) { polynomial_fit_ = polynomial_fit; }
00126 
00128       inline bool 
00129       getPolynomialFit () { return (polynomial_fit_); }
00130 
00135       inline void 
00136       setSearchRadius (double radius) { search_radius_ = radius; sqr_gauss_param_ = search_radius_ * search_radius_; }
00137 
00139       inline double 
00140       getSearchRadius () { return (search_radius_); }
00141 
00146       inline void 
00147       setSqrGaussParam (double sqr_gauss_param) { sqr_gauss_param_ = sqr_gauss_param; }
00148 
00150       inline double 
00151       getSqrGaussParam () { return (sqr_gauss_param_); }
00152 
00156       void 
00157       reconstruct (PointCloudIn &output);
00158 
00159     protected:
00161       NormalCloudOutPtr normals_;
00162 
00164       SearchMethod search_method_;
00165 
00167       KdTreePtr tree_;
00168 
00170       int order_;
00171 
00173       bool polynomial_fit_;
00174 
00176       double search_radius_;
00177 
00179       double sqr_gauss_param_;
00180 
00182       int nr_coeff_;
00183 
00189       inline int
00190       searchForNeighbors (int index, std::vector<int> &indices, std::vector<float> &sqr_distances)
00191       {
00192         return (search_method_ (index, search_radius_, indices, sqr_distances));
00193       }
00194 
00202       void
00203       computeMLSPointNormal (PointInT &pt, const PointCloudIn &input, 
00204                              const std::vector<int> &nn_indices, std::vector<float> &nn_sqr_dists,
00205                              Eigen::Vector4f &normal);
00206 
00207     private:
00211       virtual void performReconstruction (PointCloudIn &output);
00212 
00214       std::string getClassName () const { return ("MovingLeastSquares"); }
00215   };
00216 }
00217 
00218 #endif  //#ifndef PCL_MLS_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines