project_inliers.h

Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * $Id: project_inliers.h 1370 2011-06-19 01:06:01Z jspricke $
00035  *
00036  */
00037 
00038 #ifndef PCL_FILTERS_PROJECT_INLIERS_H_
00039 #define PCL_FILTERS_PROJECT_INLIERS_H_
00040 
00041 #include "pcl/point_types.h"
00042 #include "pcl/filters/filter.h"
00043 #include "pcl/ModelCoefficients.h"
00044 // Sample Consensus models
00045 #include "pcl/sample_consensus/model_types.h"
00046 #include "pcl/sample_consensus/sac_model.h"
00047 #include "pcl/sample_consensus/sac_model_circle.h"
00048 #include "pcl/sample_consensus/sac_model_cylinder.h"
00049 #include "pcl/sample_consensus/sac_model_line.h"
00050 #include "pcl/sample_consensus/sac_model_normal_plane.h"
00051 #include "pcl/sample_consensus/sac_model_parallel_plane.h"
00052 #include "pcl/sample_consensus/sac_model_normal_parallel_plane.h"
00053 #include "pcl/sample_consensus/sac_model_parallel_line.h"
00054 #include "pcl/sample_consensus/sac_model_perpendicular_plane.h"
00055 #include "pcl/sample_consensus/sac_model_plane.h"
00056 #include "pcl/sample_consensus/sac_model_sphere.h"
00057 
00058 namespace pcl
00059 {
00061 
00067   template<typename PointT>
00068   class ProjectInliers : public Filter<PointT>
00069   {
00070     using Filter<PointT>::input_;
00071     using Filter<PointT>::indices_;
00072     using Filter<PointT>::filter_name_;
00073     using Filter<PointT>::getClassName;
00074 
00075     typedef typename Filter<PointT>::PointCloud PointCloud;
00076     typedef typename PointCloud::Ptr PointCloudPtr;
00077     typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00078 
00079     typedef typename SampleConsensusModel<PointT>::Ptr SampleConsensusModelPtr;
00080     public:
00082       ProjectInliers () : copy_all_data_ (false)
00083       {
00084         filter_name_ = "ProjectInliers";
00085       }
00086 
00090       inline void
00091       setModelType (int model)
00092       {
00093         model_type_ = model;
00094       }
00095 
00097       inline int
00098       getModelType ()
00099       {
00100         return (model_type_);
00101       }
00102 
00106       inline void
00107       setModelCoefficients (const ModelCoefficientsConstPtr &model)
00108       {
00109         model_ = model;
00110       }
00111 
00113       inline ModelCoefficientsConstPtr
00114       getModelCoefficients ()
00115       {
00116         return (model_);
00117       }
00118 
00122       inline void
00123       setCopyAllData (bool val)
00124       {
00125         copy_all_data_ = val;
00126       }
00127 
00129       inline bool
00130       getCopyAllData ()
00131       {
00132         return (copy_all_data_);
00133       }
00134     protected:
00136 
00139       void
00140       applyFilter (PointCloud &output);
00141 
00142     private:
00144       ModelCoefficientsConstPtr model_;
00145 
00147       SampleConsensusModelPtr sacmodel_;
00148 
00150       int model_type_;
00151 
00153       bool copy_all_data_;
00154 
00158       virtual bool
00159       initSACModel (int model_type);
00160   };
00161 
00163 
00169   template<>
00170   class PCL_EXPORTS ProjectInliers<sensor_msgs::PointCloud2> : public Filter<sensor_msgs::PointCloud2>
00171   {
00172     using Filter<sensor_msgs::PointCloud2>::filter_name_;
00173     using Filter<sensor_msgs::PointCloud2>::getClassName;
00174 
00175     typedef sensor_msgs::PointCloud2 PointCloud2;
00176     typedef PointCloud2::Ptr PointCloud2Ptr;
00177     typedef PointCloud2::ConstPtr PointCloud2ConstPtr;
00178 
00179     typedef SampleConsensusModel<PointXYZ>::Ptr SampleConsensusModelPtr;
00180 
00181     public:
00183       ProjectInliers () : copy_all_data_ (false), copy_all_fields_ (true)
00184       {
00185         filter_name_ = "ProjectInliers";
00186       }
00187 
00191       inline void
00192       setModelType (int model)
00193       {
00194         model_type_ = model;
00195       }
00196 
00198       inline int
00199       getModelType ()
00200       {
00201         return (model_type_);
00202       }
00203 
00207       inline void
00208       setModelCoefficients (const ModelCoefficientsConstPtr &model)
00209       {
00210         model_ = model;
00211       }
00212 
00214       inline ModelCoefficientsConstPtr
00215       getModelCoefficients ()
00216       {
00217         return (model_);
00218       }
00219 
00223       inline void
00224       setCopyAllFields (bool val)
00225       {
00226         copy_all_fields_ = val;
00227       }
00228 
00230       inline bool
00231       getCopyAllFields ()
00232       {
00233         return (copy_all_fields_);
00234       }
00235 
00239       inline void
00240       setCopyAllData (bool val)
00241       {
00242         copy_all_data_ = val;
00243       }
00244 
00246       inline bool
00247       getCopyAllData ()
00248       {
00249         return (copy_all_data_);
00250       }
00251     protected:
00253       int model_type_;
00254 
00256       bool copy_all_data_;
00257 
00259       bool copy_all_fields_;
00260 
00262       ModelCoefficientsConstPtr model_;
00263 
00264       void
00265       applyFilter (PointCloud2 &output);
00266 
00267     private:
00269       SampleConsensusModelPtr sacmodel_;
00270 
00271       virtual bool
00272       initSACModel (int model_type);
00273   };
00274 }
00275 
00276 #endif  //#ifndef PCL_FILTERS_PROJECT_INLIERS_H_