Point Cloud Library (PCL)  1.5.1
 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) 2009-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 4702 2012-02-23 09:39:33Z gedikli $
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 <boost/random.hpp>
00048 #include "pcl/search/pcl_search.h"
00049 
00050 
00051 
00052 #include <Eigen/SVD>
00053 
00054 namespace pcl
00055 {
00061   template <typename PointInT, typename NormalOutT>
00062   class MovingLeastSquares: public PCLBase<PointInT>
00063   {
00064     public:
00065       using PCLBase<PointInT>::input_;
00066       using PCLBase<PointInT>::indices_;
00067       using PCLBase<PointInT>::fake_indices_;
00068       using PCLBase<PointInT>::initCompute;
00069       using PCLBase<PointInT>::deinitCompute;
00070 
00071       typedef typename pcl::search::Search<PointInT> KdTree;
00072       typedef typename pcl::search::Search<PointInT>::Ptr KdTreePtr;
00073 
00074       typedef pcl::PointCloud<NormalOutT> NormalCloudOut;
00075       typedef typename NormalCloudOut::Ptr NormalCloudOutPtr;
00076       typedef typename NormalCloudOut::ConstPtr NormalCloudOutConstPtr;
00077 
00078       typedef pcl::PointCloud<PointInT> PointCloudIn;
00079       typedef typename PointCloudIn::Ptr PointCloudInPtr;
00080       typedef typename PointCloudIn::ConstPtr PointCloudInConstPtr;
00081 
00082       typedef boost::function<int (int, double, std::vector<int> &, std::vector<float> &)> SearchMethod;
00083 
00085       MovingLeastSquares () : PCLBase<PointInT> (), tree_ (), order_ (2), polynomial_fit_ (true), search_radius_ (0), sqr_gauss_param_ (0) {};
00086 
00091       inline void 
00092       setOutputNormals (NormalCloudOutPtr cloud) { normals_ = cloud; }
00093 
00095       inline NormalCloudOutPtr 
00096       getOutputNormals () { return normals_; }
00097 
00101       inline void
00102       setSearchMethod (const KdTreePtr &tree)
00103       {
00104         tree_ = tree;
00105         // Declare the search locator definition
00106         int (KdTree::*radiusSearch)(int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_sqr_distances, unsigned int max_nn) const = &KdTree::radiusSearch;
00107         search_method_ = boost::bind (radiusSearch, boost::ref (tree_), _1, _2, _3, _4, 0);
00108       }
00109 
00111       inline KdTreePtr 
00112       getSearchMethod () { return (tree_); }
00113 
00117       inline void 
00118       setPolynomialOrder (int order) { order_ = order; }
00119 
00121       inline int 
00122       getPolynomialOrder () { return (order_); }
00123 
00127       inline void 
00128       setPolynomialFit (bool polynomial_fit) { polynomial_fit_ = polynomial_fit; }
00129 
00131       inline bool 
00132       getPolynomialFit () { return (polynomial_fit_); }
00133 
00138       inline void 
00139       setSearchRadius (double radius) { search_radius_ = radius; sqr_gauss_param_ = search_radius_ * search_radius_; }
00140 
00142       inline double 
00143       getSearchRadius () { return (search_radius_); }
00144 
00149       inline void 
00150       setSqrGaussParam (double sqr_gauss_param) { sqr_gauss_param_ = sqr_gauss_param; }
00151 
00153       inline double 
00154       getSqrGaussParam () { return (sqr_gauss_param_); }
00155 
00159       void 
00160       reconstruct (PointCloudIn &output);
00161 
00162     protected:
00164       NormalCloudOutPtr normals_;
00165 
00167       SearchMethod search_method_;
00168 
00170       KdTreePtr tree_;
00171 
00173       int order_;
00174 
00176       bool polynomial_fit_;
00177 
00179       double search_radius_;
00180 
00182       double sqr_gauss_param_;
00183 
00185       int nr_coeff_;
00186 
00192       inline int
00193       searchForNeighbors (int index, std::vector<int> &indices, std::vector<float> &sqr_distances)
00194       {
00195         return (search_method_ (index, search_radius_, indices, sqr_distances));
00196       }
00197 
00205       void
00206       computeMLSPointNormal (PointInT &pt, const PointCloudIn &input, 
00207                              const std::vector<int> &nn_indices, std::vector<float> &nn_sqr_dists,
00208                              Eigen::Vector4f &normal);
00209 
00210     private:
00214       virtual void performReconstruction (PointCloudIn &output);
00215 
00217       std::string getClassName () const { return ("MovingLeastSquares"); }
00218   };
00219 }
00220 
00221 #endif  //#ifndef PCL_MLS_H_