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 #ifndef PCL_SAMPLE_CONSENSUS_MODEL_CIRCLE3D_H_
00039 #define PCL_SAMPLE_CONSENSUS_MODEL_CIRCLE3D_H_
00040
00041 #include <pcl/sample_consensus/sac_model.h>
00042 #include <pcl/sample_consensus/model_types.h>
00043
00044 namespace pcl
00045 {
00060 template <typename PointT>
00061 class SampleConsensusModelCircle3D : public SampleConsensusModel<PointT>
00062 {
00063 public:
00064 using SampleConsensusModel<PointT>::input_;
00065 using SampleConsensusModel<PointT>::indices_;
00066 using SampleConsensusModel<PointT>::radius_min_;
00067 using SampleConsensusModel<PointT>::radius_max_;
00068
00069 typedef typename SampleConsensusModel<PointT>::PointCloud PointCloud;
00070 typedef typename SampleConsensusModel<PointT>::PointCloudPtr PointCloudPtr;
00071 typedef typename SampleConsensusModel<PointT>::PointCloudConstPtr PointCloudConstPtr;
00072
00073 typedef boost::shared_ptr<SampleConsensusModelCircle3D<PointT> > Ptr;
00074 typedef boost::shared_ptr<const SampleConsensusModelCircle3D<PointT> > ConstPtr;
00075
00080 SampleConsensusModelCircle3D (const PointCloudConstPtr &cloud,
00081 bool random = false)
00082 : SampleConsensusModel<PointT> (cloud, random) {};
00083
00089 SampleConsensusModelCircle3D (const PointCloudConstPtr &cloud,
00090 const std::vector<int> &indices,
00091 bool random = false)
00092 : SampleConsensusModel<PointT> (cloud, indices, random) {};
00093
00095 virtual ~SampleConsensusModelCircle3D () {}
00096
00100 SampleConsensusModelCircle3D (const SampleConsensusModelCircle3D &source) :
00101 SampleConsensusModel<PointT> (), tmp_inliers_ ()
00102 {
00103 *this = source;
00104 }
00105
00109 inline SampleConsensusModelCircle3D&
00110 operator = (const SampleConsensusModelCircle3D &source)
00111 {
00112 SampleConsensusModel<PointT>::operator=(source);
00113 tmp_inliers_ = source.tmp_inliers_;
00114 return (*this);
00115 }
00116
00122 bool
00123 computeModelCoefficients (const std::vector<int> &samples,
00124 Eigen::VectorXf &model_coefficients);
00125
00130 void
00131 getDistancesToModel (const Eigen::VectorXf &model_coefficients,
00132 std::vector<double> &distances);
00133
00139 void
00140 selectWithinDistance (const Eigen::VectorXf &model_coefficients,
00141 const double threshold,
00142 std::vector<int> &inliers);
00143
00150 virtual int
00151 countWithinDistance (const Eigen::VectorXf &model_coefficients,
00152 const double threshold);
00153
00160 void
00161 optimizeModelCoefficients (const std::vector<int> &inliers,
00162 const Eigen::VectorXf &model_coefficients,
00163 Eigen::VectorXf &optimized_coefficients);
00164
00171 void
00172 projectPoints (const std::vector<int> &inliers,
00173 const Eigen::VectorXf &model_coefficients,
00174 PointCloud &projected_points,
00175 bool copy_data_fields = true);
00176
00182 bool
00183 doSamplesVerifyModel (const std::set<int> &indices,
00184 const Eigen::VectorXf &model_coefficients,
00185 const double threshold);
00186
00188 inline pcl::SacModel
00189 getModelType () const { return (SACMODEL_CIRCLE3D); }
00190
00191 protected:
00195 bool
00196 isModelValid (const Eigen::VectorXf &model_coefficients);
00197
00201 bool
00202 isSampleGood(const std::vector<int> &samples) const;
00203
00204 private:
00206 const std::vector<int> *tmp_inliers_;
00207
00209 struct OptimizationFunctor : pcl::Functor<double>
00210 {
00216 OptimizationFunctor (int m_data_points, pcl::SampleConsensusModelCircle3D<PointT> *model) :
00217 pcl::Functor<double> (m_data_points), model_ (model) {}
00218
00224 int operator() (const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const
00225 {
00226 for (int i = 0; i < values (); ++i)
00227 {
00228
00229
00230 Eigen::Vector3d P (model_->input_->points[(*model_->tmp_inliers_)[i]].x, model_->input_->points[(*model_->tmp_inliers_)[i]].y, model_->input_->points[(*model_->tmp_inliers_)[i]].z);
00231
00232 Eigen::Vector3d C (x[0], x[1], x[2]);
00233
00234 Eigen::Vector3d N (x[4], x[5], x[6]);
00235
00236 double r = x[3];
00237
00238 Eigen::Vector3d helperVectorPC = P - C;
00239
00240
00241 double lambda = (-(helperVectorPC.dot (N))) / N.dot (N);
00242
00243 Eigen::Vector3d P_proj = P + lambda * N;
00244 Eigen::Vector3d helperVectorP_projC = P_proj - C;
00245
00246
00247 Eigen::Vector3d K = C + r * helperVectorP_projC.normalized ();
00248 Eigen::Vector3d distanceVector = P - K;
00249
00250 fvec[i] = distanceVector.norm ();
00251 }
00252 return (0);
00253 }
00254
00255 pcl::SampleConsensusModelCircle3D<PointT> *model_;
00256 };
00257 };
00258 }
00259
00260 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_CIRCLE3D_H_