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
00041 #ifndef PCL_SAMPLE_CONSENSUS_MODEL_SPHERE_H_
00042 #define PCL_SAMPLE_CONSENSUS_MODEL_SPHERE_H_
00043
00044 #include <pcl/sample_consensus/sac_model.h>
00045 #include <pcl/sample_consensus/model_types.h>
00046
00047 namespace pcl
00048 {
00059 template <typename PointT>
00060 class SampleConsensusModelSphere : public SampleConsensusModel<PointT>
00061 {
00062 public:
00063 using SampleConsensusModel<PointT>::input_;
00064 using SampleConsensusModel<PointT>::indices_;
00065 using SampleConsensusModel<PointT>::radius_min_;
00066 using SampleConsensusModel<PointT>::radius_max_;
00067 using SampleConsensusModel<PointT>::error_sqr_dists_;
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<SampleConsensusModelSphere> Ptr;
00074
00079 SampleConsensusModelSphere (const PointCloudConstPtr &cloud,
00080 bool random = false)
00081 : SampleConsensusModel<PointT> (cloud, random), tmp_inliers_ ()
00082 {}
00083
00089 SampleConsensusModelSphere (const PointCloudConstPtr &cloud,
00090 const std::vector<int> &indices,
00091 bool random = false)
00092 : SampleConsensusModel<PointT> (cloud, indices, random), tmp_inliers_ ()
00093 {}
00094
00096 virtual ~SampleConsensusModelSphere () {}
00097
00101 SampleConsensusModelSphere (const SampleConsensusModelSphere &source) :
00102 SampleConsensusModel<PointT> (), tmp_inliers_ ()
00103 {
00104 *this = source;
00105 }
00106
00110 inline SampleConsensusModelSphere&
00111 operator = (const SampleConsensusModelSphere &source)
00112 {
00113 SampleConsensusModel<PointT>::operator=(source);
00114 tmp_inliers_ = source.tmp_inliers_;
00115 return (*this);
00116 }
00117
00124 bool
00125 computeModelCoefficients (const std::vector<int> &samples,
00126 Eigen::VectorXf &model_coefficients);
00127
00132 void
00133 getDistancesToModel (const Eigen::VectorXf &model_coefficients,
00134 std::vector<double> &distances);
00135
00141 void
00142 selectWithinDistance (const Eigen::VectorXf &model_coefficients,
00143 const double threshold,
00144 std::vector<int> &inliers);
00145
00152 virtual int
00153 countWithinDistance (const Eigen::VectorXf &model_coefficients,
00154 const double threshold);
00155
00162 void
00163 optimizeModelCoefficients (const std::vector<int> &inliers,
00164 const Eigen::VectorXf &model_coefficients,
00165 Eigen::VectorXf &optimized_coefficients);
00166
00174 void
00175 projectPoints (const std::vector<int> &inliers,
00176 const Eigen::VectorXf &model_coefficients,
00177 PointCloud &projected_points,
00178 bool copy_data_fields = true);
00179
00185 bool
00186 doSamplesVerifyModel (const std::set<int> &indices,
00187 const Eigen::VectorXf &model_coefficients,
00188 const double threshold);
00189
00191 inline pcl::SacModel getModelType () const { return (SACMODEL_SPHERE); }
00192
00193 protected:
00197 inline bool
00198 isModelValid (const Eigen::VectorXf &model_coefficients)
00199 {
00200
00201 if (model_coefficients.size () != 4)
00202 {
00203 PCL_ERROR ("[pcl::SampleConsensusModelSphere::isModelValid] Invalid number of model coefficients given (%zu)!\n", model_coefficients.size ());
00204 return (false);
00205 }
00206
00207 if (radius_min_ != -std::numeric_limits<double>::max() && model_coefficients[3] < radius_min_)
00208 return (false);
00209 if (radius_max_ != std::numeric_limits<double>::max() && model_coefficients[3] > radius_max_)
00210 return (false);
00211
00212 return (true);
00213 }
00214
00219 bool
00220 isSampleGood(const std::vector<int> &samples) const;
00221
00222 private:
00224 const std::vector<int> *tmp_inliers_;
00225
00226 #if defined BUILD_Maintainer && defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ > 3
00227 #pragma GCC diagnostic ignored "-Weffc++"
00228 #endif
00229 struct OptimizationFunctor : pcl::Functor<float>
00230 {
00236 OptimizationFunctor (int m_data_points, pcl::SampleConsensusModelSphere<PointT> *model) :
00237 pcl::Functor<float>(m_data_points), model_ (model) {}
00238
00244 int
00245 operator() (const Eigen::VectorXf &x, Eigen::VectorXf &fvec) const
00246 {
00247 Eigen::Vector4f cen_t;
00248 cen_t[3] = 0;
00249 for (int i = 0; i < values (); ++i)
00250 {
00251
00252 cen_t[0] = model_->input_->points[(*model_->tmp_inliers_)[i]].x - x[0];
00253 cen_t[1] = model_->input_->points[(*model_->tmp_inliers_)[i]].y - x[1];
00254 cen_t[2] = model_->input_->points[(*model_->tmp_inliers_)[i]].z - x[2];
00255
00256
00257 fvec[i] = sqrtf (cen_t.dot (cen_t)) - x[3];
00258 }
00259 return (0);
00260 }
00261
00262 pcl::SampleConsensusModelSphere<PointT> *model_;
00263 };
00264 #if defined BUILD_Maintainer && defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ > 3
00265 #pragma GCC diagnostic warning "-Weffc++"
00266 #endif
00267 };
00268 }
00269
00270 #ifdef PCL_NO_PRECOMPILE
00271 #include <pcl/sample_consensus/impl/sac_model_sphere.hpp>
00272 #endif
00273
00274 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_SPHERE_H_