Point Cloud Library (PCL)
1.3.1
|
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 3031 2011-11-01 04:25:15Z 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 { 00054 00059 template <typename PointInT, typename NormalOutT> 00060 class MovingLeastSquares : public PCLBase<PointInT> 00061 { 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 public: 00069 typedef typename pcl::search::Search<PointInT> KdTree; 00070 typedef typename pcl::search::Search<PointInT>::Ptr KdTreePtr; 00071 00072 typedef pcl::PointCloud<NormalOutT> NormalCloudOut; 00073 typedef typename NormalCloudOut::Ptr NormalCloudOutPtr; 00074 typedef typename NormalCloudOut::ConstPtr NormalCloudOutConstPtr; 00075 00076 typedef pcl::PointCloud<PointInT> PointCloudIn; 00077 typedef typename PointCloudIn::Ptr PointCloudInPtr; 00078 typedef typename PointCloudIn::ConstPtr PointCloudInConstPtr; 00079 00080 typedef boost::function<int (int, double, std::vector<int> &, std::vector<float> &)> SearchMethod; 00081 00083 MovingLeastSquares () : PCLBase<PointInT> (), tree_ (), order_ (2), polynomial_fit_ (true), search_radius_ (0), sqr_gauss_param_ (0) {}; 00084 00089 inline void 00090 setOutputNormals (NormalCloudOutPtr cloud) { normals_ = cloud; } 00091 00093 inline NormalCloudOutPtr 00094 getOutputNormals () { return normals_; } 00095 00099 inline void 00100 setSearchMethod (const KdTreePtr &tree) 00101 { 00102 tree_ = tree; 00103 // Declare the search locator definition 00104 int (KdTree::*radiusSearch)(int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_sqr_distances, int max_nn) const = &KdTree::radiusSearch; 00105 search_method_ = boost::bind (radiusSearch, boost::ref (tree_), _1, _2, _3, _4, INT_MAX); 00106 } 00107 00109 inline KdTreePtr 00110 getSearchMethod () { return (tree_); } 00111 00115 inline void 00116 setPolynomialOrder (int order) { order_ = order; } 00117 00119 inline int 00120 getPolynomialOrder () { return (order_); } 00121 00125 inline void 00126 setPolynomialFit (bool polynomial_fit) { polynomial_fit_ = polynomial_fit; } 00127 00129 inline bool 00130 getPolynomialFit () { return (polynomial_fit_); } 00131 00136 inline void 00137 setSearchRadius (double radius) { search_radius_ = radius; sqr_gauss_param_ = search_radius_ * search_radius_; } 00138 00140 inline double 00141 getSearchRadius () { return (search_radius_); } 00142 00147 inline void 00148 setSqrGaussParam (double sqr_gauss_param) { sqr_gauss_param_ = sqr_gauss_param; } 00149 00151 inline double 00152 getSqrGaussParam () { return (sqr_gauss_param_); } 00153 00157 void 00158 reconstruct (PointCloudIn &output); 00159 00160 protected: 00162 NormalCloudOutPtr normals_; 00163 00165 SearchMethod search_method_; 00166 00168 KdTreePtr tree_; 00169 00171 int order_; 00172 00174 bool polynomial_fit_; 00175 00177 double search_radius_; 00178 00180 double sqr_gauss_param_; 00181 00187 inline int 00188 searchForNeighbors (int index, std::vector<int> &indices, std::vector<float> &sqr_distances) 00189 { 00190 return (search_method_ (index, search_radius_, indices, sqr_distances)); 00191 } 00192 00193 private: 00195 int nr_coeff_; 00196 00198 void performReconstruction (PointCloudIn &output); 00199 00201 std::string getClassName () const { return ("MovingLeastSquares"); } 00202 }; 00203 } 00204 00205 #endif //#ifndef PCL_MLS_H_