Go to the documentation of this file.00001 #ifndef PCL_IAS_SAMPLE_CONSENSUS_SACMODELORIENTATION_H_
00002 #define PCL_IAS_SAMPLE_CONSENSUS_SACMODELORIENTATION_H_
00003
00004 #include <ros/assert.h>
00005
00006 #include <pcl/sample_consensus/sac_model.h>
00007 #include <pcl/sample_consensus/model_types.h>
00008
00009 #include <pcl/features/normal_3d.h>
00010
00011 #include <boost/make_shared.hpp>
00012
00013
00014
00015
00016
00017
00018
00019 namespace pcl
00020 {
00027 inline Eigen::Vector3f rotateAroundAxis (Eigen::Vector3f r, Eigen::Vector3f axis, float angle)
00028 {
00029
00030 return r * cos(angle) + (axis.cross(r)) * sin(angle) + axis * axis.dot(r) * (1-cos(angle));
00031 }
00032
00034 template <typename NormalT>
00035 class NormalPointRepresentation : public PointRepresentation <NormalT>
00036 {
00037 public:
00038
00039 using PointRepresentation<NormalT>::nr_dimensions_;
00040
00041 typedef boost::shared_ptr<NormalPointRepresentation<NormalT> > Ptr;
00042 typedef boost::shared_ptr<const NormalPointRepresentation<NormalT> > ConstPtr;
00043
00044 NormalPointRepresentation ()
00045 {
00046 nr_dimensions_ = 3;
00047 }
00048
00049 virtual void
00050 copyToFloatArray (const NormalT &p, float * out) const
00051 {
00052 out[0] = p.normal[0];
00053 out[1] = p.normal[1];
00054 out[2] = p.normal[2];
00055 }
00056 };
00057
00060 template <typename NormalT>
00061 class SACModelOrientation : public SampleConsensusModel<NormalT>
00062 {
00063 public:
00064 using SampleConsensusModel<NormalT>::input_;
00065 using SampleConsensusModel<NormalT>::indices_;
00066
00067 typedef typename SampleConsensusModel<NormalT>::PointCloud Normals;
00068 typedef typename SampleConsensusModel<NormalT>::PointCloudPtr NormalsPtr;
00069 typedef typename SampleConsensusModel<NormalT>::PointCloudConstPtr NormalsConstPtr;
00070
00071 typedef boost::shared_ptr<SACModelOrientation> Ptr;
00072 typedef boost::shared_ptr<const SACModelOrientation> ConstPtr;
00073
00075
00076 Eigen::Vector3f axis_;
00077
00079
00082 SACModelOrientation (const NormalsConstPtr &cloud) : SampleConsensusModel<NormalT> (cloud)
00083 {
00084 typename NormalPointRepresentation<NormalT>::ConstPtr repr (new NormalPointRepresentation<NormalT>);
00085 kdtree_ = boost::make_shared<KdTreeFLANN <NormalT> >();
00086 kdtree_->setPointRepresentation (repr);
00087 kdtree_->setInputCloud (cloud);
00088 }
00089
00091
00095 SACModelOrientation (const NormalsConstPtr &cloud, const std::vector<int> &indices) : SampleConsensusModel<NormalT> (cloud, indices)
00096 {
00097 kdtree_ = boost::make_shared<KdTreeFLANN <NormalT> >();
00098 kdtree_->setInputCloud (cloud);
00099 }
00100
00102
00105 inline void setAxis (Eigen::Vector3f axis) { axis_ = axis; }
00106
00108
00109 inline Eigen::Vector3f getAxis () const { return (axis_); }
00110
00112
00116 void getSamples (int &iterations, std::vector<int> &samples);
00117
00119
00124 bool computeModelCoefficients (const std::vector<int> &samples, Eigen::VectorXf &model_coefficients);
00125
00127
00132 void refitModel (const std::vector<int> &inliers, std::vector<double> &refit_coefficients);
00133
00135
00139 void getDistancesToModel (const Eigen::VectorXf &model_coefficients, std::vector<double> &distances) {}
00140
00142
00149 void selectWithinDistance (const Eigen::VectorXf &model_coefficients, double threshold, std::vector<int> &inliers);
00150
00151
00153
00159 int countWithinDistance(const Eigen::VectorXf& model_coefficients, double threshold)
00160 {
00161 std::vector<int> inliers;
00162 selectWithinDistance (model_coefficients, threshold, inliers);
00163 return inliers.size ();
00164 }
00165
00167
00172 void projectPoints (const std::vector<int> &inliers, const Eigen::VectorXf &model_coefficients, Normals &projected_points, bool copy_data_fields = true){}
00173
00174
00176
00180 bool doSamplesVerifyModel (const std::set<int> &indices, const Eigen::VectorXf &model_coefficients, double threshold) { return true; }
00181
00186 bool
00187 isSampleGood(const std::vector<int> &samples) const;
00188
00190
00191
00192 inline pcl::SacModel getModelType () const { return pcl::SacModel(SACMODEL_PLANE);}
00193
00194 inline void optimizeModelCoefficients( const std::vector<int> &inliers, const Eigen::VectorXf &model_coefficients,
00195 Eigen::VectorXf &optimized_coefficients){}
00196
00197 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00198
00199 protected:
00200
00202
00205 inline bool
00206 isModelValid (const Eigen::VectorXf &model_coefficients)
00207 {
00208
00209 ROS_ASSERT (model_coefficients.size () == 4);
00210 return (true);
00211 }
00212
00214
00215
00216
00217 private:
00219
00220 typename KdTreeFLANN<NormalT>::Ptr kdtree_;
00221 std::vector<int> front_indices_;
00222 std::vector<int> back_indices_;
00223 std::vector<int> left_indices_;
00224 std::vector<int> right_indices_;
00225 std::vector<float> points_sqr_distances_;
00226
00227 };
00228 }
00229
00230 #include "pcl_ias_sample_consensus/pcl_sac_model_orientation.hpp"
00231
00232 #endif