00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef PCL_SAMPLE_CONSENSUS_MODEL_PLANE_H_
00039 #define PCL_SAMPLE_CONSENSUS_MODEL_PLANE_H_
00040
00041 #include <pcl/sample_consensus/sac_model.h>
00042 #include <pcl/sample_consensus/model_types.h>
00043
00044 #include <pcl/features/normal_3d.h>
00045
00046 namespace pcl
00047 {
00055 template <typename Point> inline double
00056 pointToPlaneDistanceSigned (const Point &p, double a, double b, double c, double d)
00057 {
00058 return (a * p.x + b * p.y + c * p.z + d);
00059 }
00060
00065 template <typename Point> inline double
00066 pointToPlaneDistanceSigned (const Point &p, const Eigen::Vector4f &plane_coefficients)
00067 {
00068 return ( plane_coefficients[0] * p.x + plane_coefficients[1] * p.y + plane_coefficients[2] * p.z + plane_coefficients[3] );
00069 }
00070
00078 template <typename Point> inline double
00079 pointToPlaneDistance (const Point &p, double a, double b, double c, double d)
00080 {
00081 return (fabs (pointToPlaneDistanceSigned (p, a, b, c, d)) );
00082 }
00083
00088 template <typename Point> inline double
00089 pointToPlaneDistance (const Point &p, const Eigen::Vector4f &plane_coefficients)
00090 {
00091 return ( fabs (pointToPlaneDistanceSigned (p, plane_coefficients)) );
00092 }
00093
00095
00098 template <typename PointT>
00099 class SampleConsensusModelPlane : public SampleConsensusModel<PointT>
00100 {
00101 public:
00102 using SampleConsensusModel<PointT>::input_;
00103 using SampleConsensusModel<PointT>::indices_;
00104
00105 typedef typename SampleConsensusModel<PointT>::PointCloud PointCloud;
00106 typedef typename SampleConsensusModel<PointT>::PointCloudPtr PointCloudPtr;
00107 typedef typename SampleConsensusModel<PointT>::PointCloudConstPtr PointCloudConstPtr;
00108
00109 typedef boost::shared_ptr<SampleConsensusModelPlane> Ptr;
00110
00114 SampleConsensusModelPlane (const PointCloudConstPtr &cloud) : SampleConsensusModel<PointT> (cloud) {};
00115
00120 SampleConsensusModelPlane (const PointCloudConstPtr &cloud, const std::vector<int> &indices) : SampleConsensusModel<PointT> (cloud, indices) {};
00121
00127 void getSamples (int &iterations, std::vector<int> &samples);
00128
00135 bool computeModelCoefficients (const std::vector<int> &samples, Eigen::VectorXf &model_coefficients);
00136
00141 void getDistancesToModel (const Eigen::VectorXf &model_coefficients, std::vector<double> &distances);
00142
00148 void selectWithinDistance (const Eigen::VectorXf &model_coefficients, double threshold, std::vector<int> &inliers);
00149
00156 void optimizeModelCoefficients (const std::vector<int> &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients);
00157
00164 void projectPoints (const std::vector<int> &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields = true);
00165
00171 bool doSamplesVerifyModel (const std::set<int> &indices, const Eigen::VectorXf &model_coefficients, double threshold);
00172
00174 inline pcl::SacModel getModelType () const { return (SACMODEL_PLANE); }
00175
00176 protected:
00180 inline bool
00181 isModelValid (const Eigen::VectorXf &model_coefficients)
00182 {
00183
00184 if (model_coefficients.size () != 4)
00185 {
00186 ROS_ERROR ("[pcl::SampleConsensusModelPlane::isModelValid] Invalid number of model coefficients given (%zu)!", model_coefficients.size ());
00187 return (false);
00188 }
00189 return (true);
00190 }
00191
00192 private:
00194 const static int MAX_ITERATIONS_COLLINEAR = 1000;
00195 };
00196 }
00197
00198 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_PLANE_H_