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 34544 2010-12-06 11:22:55Z rusu $ 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 { 00063 00068 template <typename PointT> 00069 class ProjectInliers: public Filter<PointT> 00070 { 00071 using Filter<PointT>::input_; 00072 using Filter<PointT>::indices_; 00073 using Filter<PointT>::filter_name_; 00074 using Filter<PointT>::getClassName; 00075 00076 typedef typename Filter<PointT>::PointCloud PointCloud; 00077 typedef typename PointCloud::Ptr PointCloudPtr; 00078 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00079 00080 typedef typename SampleConsensusModel<PointT>::Ptr SampleConsensusModelPtr; 00081 public: 00083 00084 ProjectInliers () : copy_all_data_ (false) 00085 { 00086 filter_name_ = "ProjectInliers"; 00087 }; 00088 00090 00093 inline void setModelType (int model) { model_type_ = model; } 00094 00096 00097 inline int getModelType () { return (model_type_); } 00098 00100 00103 inline void setModelCoefficients (const ModelCoefficientsConstPtr &model) { model_ = model; } 00104 00106 00107 inline ModelCoefficientsConstPtr getModelCoefficients () { return (model_); } 00108 00112 inline void setCopyAllData (bool val) { copy_all_data_ = val; } 00114 inline bool getCopyAllData () { return (copy_all_data_); } 00115 protected: 00117 00120 void applyFilter (PointCloud &output); 00121 00122 private: 00124 ModelCoefficientsConstPtr model_; 00125 00127 SampleConsensusModelPtr sacmodel_; 00128 00130 int model_type_; 00131 00133 bool copy_all_data_; 00134 00136 00139 virtual bool initSACModel (int model_type); 00140 }; 00141 00145 00150 template <> 00151 class ProjectInliers<sensor_msgs::PointCloud2> : public Filter<sensor_msgs::PointCloud2> 00152 { 00153 using Filter<sensor_msgs::PointCloud2>::filter_name_; 00154 using Filter<sensor_msgs::PointCloud2>::getClassName; 00155 00156 typedef sensor_msgs::PointCloud2 PointCloud2; 00157 typedef PointCloud2::Ptr PointCloud2Ptr; 00158 typedef PointCloud2::ConstPtr PointCloud2ConstPtr; 00159 00160 typedef SampleConsensusModel<PointXYZ>::Ptr SampleConsensusModelPtr; 00161 00162 public: 00164 00165 ProjectInliers () : copy_all_data_ (false), copy_all_fields_ (true) 00166 { 00167 filter_name_ = "ProjectInliers"; 00168 }; 00169 00171 00174 inline void setModelType (int model) { model_type_ = model; } 00175 00177 00178 inline int getModelType () { return (model_type_); } 00179 00181 00184 inline void setModelCoefficients (const ModelCoefficientsConstPtr &model) { model_ = model; } 00185 00187 00188 inline ModelCoefficientsConstPtr getModelCoefficients () { return (model_); } 00189 00193 inline void setCopyAllFields (bool val) { copy_all_fields_ = val; } 00195 inline bool getCopyAllFields () { return (copy_all_fields_); } 00196 00200 inline void setCopyAllData (bool val) { copy_all_data_ = val; } 00202 inline bool getCopyAllData () { return (copy_all_data_); } 00203 protected: 00205 int model_type_; 00206 00208 bool copy_all_data_; 00209 00211 bool copy_all_fields_; 00212 00214 ModelCoefficientsConstPtr model_; 00215 00216 void applyFilter (PointCloud2 &output); 00217 00218 private: 00220 SampleConsensusModelPtr sacmodel_; 00221 00222 virtual bool initSACModel (int model_type); 00223 00224 }; 00225 } 00226 00227 #endif //#ifndef PCL_FILTERS_PROJECT_INLIERS_H_