Go to the documentation of this file.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
00039
00040 #ifndef PCL_SAMPLE_CONSENSUS_MODEL_PLANE_H_
00041 #define PCL_SAMPLE_CONSENSUS_MODEL_PLANE_H_
00042
00043 #include <pcl/sample_consensus/sac_model.h>
00044 #include <pcl/sample_consensus/model_types.h>
00045
00046 namespace pcl
00047 {
00048
00054 template <typename Point> inline void
00055 projectPoint (const Point &p, const Eigen::Vector4f &model_coefficients, Point &q)
00056 {
00057
00058 Eigen::Vector4f pp (p.x, p.y, p.z, 1);
00059
00060 float distance_to_plane = pp.dot(model_coefficients);
00061
00062
00063
00064
00065
00066
00067 Eigen::Vector4f q_e = pp - distance_to_plane * model_coefficients;
00068 q.x = q_e[0];
00069 q.y = q_e[1];
00070 q.z = q_e[2];
00071 }
00072
00081 template <typename Point> inline double
00082 pointToPlaneDistanceSigned (const Point &p, double a, double b, double c, double d)
00083 {
00084 return (a * p.x + b * p.y + c * p.z + d);
00085 }
00086
00092 template <typename Point> inline double
00093 pointToPlaneDistanceSigned (const Point &p, const Eigen::Vector4f &plane_coefficients)
00094 {
00095 return ( plane_coefficients[0] * p.x + plane_coefficients[1] * p.y + plane_coefficients[2] * p.z + plane_coefficients[3] );
00096 }
00097
00106 template <typename Point> inline double
00107 pointToPlaneDistance (const Point &p, double a, double b, double c, double d)
00108 {
00109 return (fabs (pointToPlaneDistanceSigned (p, a, b, c, d)) );
00110 }
00111
00117 template <typename Point> inline double
00118 pointToPlaneDistance (const Point &p, const Eigen::Vector4f &plane_coefficients)
00119 {
00120 return ( fabs (pointToPlaneDistanceSigned (p, plane_coefficients)) );
00121 }
00122
00124
00134 template <typename PointT>
00135 class SampleConsensusModelPlane : public SampleConsensusModel<PointT>
00136 {
00137 public:
00138 using SampleConsensusModel<PointT>::input_;
00139 using SampleConsensusModel<PointT>::indices_;
00140
00141 typedef typename SampleConsensusModel<PointT>::PointCloud PointCloud;
00142 typedef typename SampleConsensusModel<PointT>::PointCloudPtr PointCloudPtr;
00143 typedef typename SampleConsensusModel<PointT>::PointCloudConstPtr PointCloudConstPtr;
00144
00145 typedef boost::shared_ptr<SampleConsensusModelPlane> Ptr;
00146
00150 SampleConsensusModelPlane (const PointCloudConstPtr &cloud) : SampleConsensusModel<PointT> (cloud) {};
00151
00156 SampleConsensusModelPlane (const PointCloudConstPtr &cloud, const std::vector<int> &indices) : SampleConsensusModel<PointT> (cloud, indices) {};
00157
00164 bool
00165 computeModelCoefficients (const std::vector<int> &samples,
00166 Eigen::VectorXf &model_coefficients);
00167
00172 void
00173 getDistancesToModel (const Eigen::VectorXf &model_coefficients,
00174 std::vector<double> &distances);
00175
00181 void
00182 selectWithinDistance (const Eigen::VectorXf &model_coefficients,
00183 const double threshold,
00184 std::vector<int> &inliers);
00185
00192 virtual int
00193 countWithinDistance (const Eigen::VectorXf &model_coefficients,
00194 const double threshold);
00195
00202 void
00203 optimizeModelCoefficients (const std::vector<int> &inliers,
00204 const Eigen::VectorXf &model_coefficients,
00205 Eigen::VectorXf &optimized_coefficients);
00206
00213 void
00214 projectPoints (const std::vector<int> &inliers,
00215 const Eigen::VectorXf &model_coefficients,
00216 PointCloud &projected_points,
00217 bool copy_data_fields = true);
00218
00224 bool
00225 doSamplesVerifyModel (const std::set<int> &indices,
00226 const Eigen::VectorXf &model_coefficients,
00227 const double threshold);
00228
00230 inline pcl::SacModel
00231 getModelType () const { return (SACMODEL_PLANE); }
00232
00233 protected:
00237 inline bool
00238 isModelValid (const Eigen::VectorXf &model_coefficients)
00239 {
00240
00241 if (model_coefficients.size () != 4)
00242 {
00243 PCL_ERROR ("[pcl::SampleConsensusModelPlane::isModelValid] Invalid number of model coefficients given (%zu)!\n", model_coefficients.size ());
00244 return (false);
00245 }
00246 return (true);
00247 }
00248
00249 private:
00254 virtual bool
00255 isSampleGood (const std::vector<int> &samples) const;
00256 };
00257 }
00258
00259 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_PLANE_H_