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_SPHERE_H_
00039 #define PCL_SAMPLE_CONSENSUS_MODEL_SPHERE_H_
00040
00041 #include <pcl/sample_consensus/sac_model.h>
00042 #include <pcl/sample_consensus/model_types.h>
00043 #include <cminpack.h>
00044 #include <boost/thread/mutex.hpp>
00045
00046 namespace pcl
00047 {
00051 template <typename PointT>
00052 class SampleConsensusModelSphere : public SampleConsensusModel<PointT>
00053 {
00054 using SampleConsensusModel<PointT>::input_;
00055 using SampleConsensusModel<PointT>::indices_;
00056 using SampleConsensusModel<PointT>::radius_min_;
00057 using SampleConsensusModel<PointT>::radius_max_;
00058
00059 public:
00060 typedef typename SampleConsensusModel<PointT>::PointCloud PointCloud;
00061 typedef typename SampleConsensusModel<PointT>::PointCloudPtr PointCloudPtr;
00062 typedef typename SampleConsensusModel<PointT>::PointCloudConstPtr PointCloudConstPtr;
00063
00064 typedef boost::shared_ptr<SampleConsensusModelSphere> Ptr;
00065
00069 SampleConsensusModelSphere (const PointCloudConstPtr &cloud) : SampleConsensusModel<PointT> (cloud) { }
00070
00075 SampleConsensusModelSphere (const PointCloudConstPtr &cloud, const std::vector<int> &indices) : SampleConsensusModel<PointT> (cloud, indices) { }
00076
00087 void
00088 getSamples (int &iterations, std::vector<int> &samples);
00089
00095 bool
00096 computeModelCoefficients (const std::vector<int> &samples, Eigen::VectorXf &model_coefficients);
00097
00102 void
00103 getDistancesToModel (const Eigen::VectorXf &model_coefficients, std::vector<double> &distances);
00104
00110 void
00111 selectWithinDistance (const Eigen::VectorXf &model_coefficients, double threshold, std::vector<int> &inliers);
00112
00119 void
00120 optimizeModelCoefficients (const std::vector<int> &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients);
00121
00129 void
00130 projectPoints (const std::vector<int> &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields = true);
00131
00137 bool
00138 doSamplesVerifyModel (const std::set<int> &indices, const Eigen::VectorXf &model_coefficients, double threshold);
00139
00141 inline pcl::SacModel getModelType () const { return (SACMODEL_SPHERE); }
00142
00143 protected:
00147 inline bool
00148 isModelValid (const Eigen::VectorXf &model_coefficients)
00149 {
00150
00151 if (model_coefficients.size () != 4)
00152 {
00153 ROS_ERROR ("[pcl::SampleConsensusModelSphere::isModelValid] Invalid number of model coefficients given (%zu)!", model_coefficients.size ());
00154 return (false);
00155 }
00156
00157 if (radius_min_ != -DBL_MAX && model_coefficients[3] < radius_min_)
00158 return (false);
00159 if (radius_max_ != DBL_MAX && model_coefficients[3] > radius_max_)
00160 return (false);
00161
00162 return (true);
00163 }
00164
00165 private:
00167 boost::mutex tmp_mutex_;
00168
00170 const std::vector<int> *tmp_inliers_;
00171
00173 const static int MAX_ITERATIONS_COLLINEAR = 1000;
00174
00176
00184 static int functionToOptimize (void *p, int m, int n, const double *x, double *fvec, int iflag);
00185 };
00186 }
00187
00188 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_SPHERE_H_