sampling_surface_normal.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 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  */
00037 
00038 #ifndef PCL_FILTERS_SAMPLING_SURFACE_NORMAL_H_
00039 #define PCL_FILTERS_SAMPLING_SURFACE_NORMAL_H_
00040 
00041 #include <pcl/filters/filter.h>
00042 #include <time.h>
00043 #include <limits.h>
00044 
00045 namespace pcl
00046 {
00054   template<typename PointT>
00055   class SamplingSurfaceNormal: public Filter<PointT>
00056   {
00057     using Filter<PointT>::filter_name_;
00058     using Filter<PointT>::getClassName;
00059     using Filter<PointT>::indices_;
00060     using Filter<PointT>::input_;
00061 
00062     typedef typename Filter<PointT>::PointCloud PointCloud;
00063     typedef typename PointCloud::Ptr PointCloudPtr;
00064     typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00065 
00066     typedef typename Eigen::Matrix<float, Eigen::Dynamic, 1> Vector;
00067 
00068     public:
00069 
00070       typedef boost::shared_ptr< SamplingSurfaceNormal<PointT> > Ptr;
00071       typedef boost::shared_ptr< const SamplingSurfaceNormal<PointT> > ConstPtr;
00072 
00074       SamplingSurfaceNormal () : 
00075         sample_ (10), seed_ (static_cast<unsigned int> (time (NULL))), ratio_ ()
00076       {
00077         filter_name_ = "SamplingSurfaceNormal";
00078         srand (seed_);
00079       }
00080 
00084       inline void
00085       setSample (unsigned int sample)
00086       {
00087         sample_ = sample;
00088       }
00089 
00091       inline unsigned int
00092       getSample () const
00093       {
00094         return (sample_);
00095       }
00096 
00100       inline void
00101       setSeed (unsigned int seed)
00102       {
00103         seed_ = seed;
00104         srand (seed_);
00105       }
00106 
00108       inline unsigned int
00109       getSeed () const
00110       {
00111         return (seed_);
00112       }
00113 
00117       inline void
00118       setRatio (float ratio)
00119       {
00120         ratio_ = ratio;
00121       }
00122 
00124       inline float
00125       getRatio () const
00126       {
00127         return ratio_;
00128       }
00129 
00130     protected:
00131 
00133       unsigned int sample_;
00135       unsigned int seed_;
00137       float ratio_;
00138 
00142       void
00143       applyFilter (PointCloud &output);
00144 
00145     private:
00146 
00149       struct CompareDim
00150       {
00152         const int dim;
00154         const pcl::PointCloud <PointT>& cloud;
00155 
00157         CompareDim (const int dim, const pcl::PointCloud <PointT>& cloud) : dim (dim), cloud (cloud)
00158         {
00159         }
00160 
00162         bool 
00163         operator () (const int& p0, const int& p1)
00164         {
00165           if (dim == 0)
00166             return (cloud.points[p0].x < cloud.points[p1].x);
00167           else if (dim == 1)
00168             return (cloud.points[p0].y < cloud.points[p1].y);
00169           else if (dim == 2)
00170             return (cloud.points[p0].z < cloud.points[p1].z);
00171           return (false);
00172         }
00173       };
00174 
00180       void 
00181       findXYZMaxMin (const PointCloud& cloud, Vector& max_vec, Vector& min_vec);
00182 
00193       void 
00194       partition (const PointCloud& cloud, const int first, const int last, 
00195                  const Vector min_values, const Vector max_values, 
00196                  std::vector<int>& indices, PointCloud& outcloud);
00197 
00205       void 
00206       samplePartition (const PointCloud& data, const int first, const int last, 
00207                        std::vector<int>& indices, PointCloud& outcloud);
00208 
00214       float 
00215       findCutVal (const PointCloud& cloud, const int cut_dim, const int cut_index);
00216 
00223       void 
00224       computeNormal (const PointCloud& cloud, Eigen::Vector4f &normal, float& curvature);
00225 
00232       unsigned int 
00233       computeMeanAndCovarianceMatrix (const pcl::PointCloud<PointT> &cloud,
00234                                       Eigen::Matrix3f &covariance_matrix,
00235                                       Eigen::Vector4f &centroid);
00236 
00243       void 
00244       solvePlaneParameters (const Eigen::Matrix3f &covariance_matrix,
00245                             float &nx, float &ny, float &nz, float &curvature);
00246   };
00247 }
00248 
00249 #ifdef PCL_NO_PRECOMPILE
00250 #include <pcl/filters/impl/sampling_surface_normal.hpp>
00251 #endif
00252 
00253 #endif  //#ifndef PCL_FILTERS_SAMPLING_SURFACE_NORMAL_H_


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:32:48