41 #ifndef PCL_SAMPLE_CONSENSUS_MODEL_CYLINDER_H_ 42 #define PCL_SAMPLE_CONSENSUS_MODEL_CYLINDER_H_ 44 #include <pcl/sample_consensus/sac_model.h> 45 #include <pcl/sample_consensus/model_types.h> 46 #include <pcl/pcl_macros.h> 65 template <
typename Po
intT,
typename Po
intNT>
82 typedef boost::shared_ptr<SampleConsensusModelCylinder>
Ptr;
91 , axis_ (
Eigen::Vector3f::Zero ())
106 const std::vector<int> &indices,
110 , axis_ (
Eigen::Vector3f::Zero ())
125 axis_ (
Eigen::Vector3f::Zero ()),
144 axis_ = source.axis_;
145 eps_angle_ = source.eps_angle_;
146 tmp_inliers_ = source.tmp_inliers_;
164 setAxis (
const Eigen::Vector3f &ax) { axis_ = ax; }
167 inline Eigen::Vector3f
178 Eigen::VectorXf &model_coefficients);
186 std::vector<double> &distances);
195 const double threshold,
196 std::vector<int> &inliers);
206 const double threshold);
216 const Eigen::VectorXf &model_coefficients,
217 Eigen::VectorXf &optimized_coefficients);
228 const Eigen::VectorXf &model_coefficients,
230 bool copy_data_fields =
true);
239 const Eigen::VectorXf &model_coefficients,
240 const double threshold);
255 pointToLineDistance (
const Eigen::Vector4f &pt,
const Eigen::VectorXf &model_coefficients);
265 const Eigen::Vector4f &line_pt,
266 const Eigen::Vector4f &line_dir,
267 Eigen::Vector4f &pt_proj)
269 float k = (pt.dot (line_dir) - line_pt.dot (line_dir)) / line_dir.dot (line_dir);
271 pt_proj = line_pt + k * line_dir;
282 const Eigen::VectorXf &model_coefficients,
283 Eigen::Vector4f &pt_proj);
286 PCL_DEPRECATED (
"[pcl::SampleConsensusModelCylinder::getName] getName is deprecated. Please use getClassName instead.")
295 isModelValid (
const Eigen::VectorXf &model_coefficients);
306 Eigen::Vector3f axis_;
312 const std::vector<int> *tmp_inliers_;
314 #if defined BUILD_Maintainer && defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ > 3 315 #pragma GCC diagnostic ignored "-Weffc++" 326 pcl::
Functor<float> (m_data_points), model_ (model) {}
334 operator() (
const Eigen::VectorXf &x, Eigen::VectorXf &fvec)
const 336 Eigen::Vector4f line_pt (x[0], x[1], x[2], 0);
337 Eigen::Vector4f line_dir (x[3], x[4], x[5], 0);
339 for (
int i = 0; i < values (); ++i)
342 Eigen::Vector4f pt (model_->input_->points[(*model_->tmp_inliers_)[i]].x,
343 model_->input_->points[(*model_->tmp_inliers_)[i]].y,
344 model_->input_->points[(*model_->tmp_inliers_)[i]].z, 0);
353 #if defined BUILD_Maintainer && defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ > 3 354 #pragma GCC diagnostic warning "-Weffc++" 359 #ifdef PCL_NO_PRECOMPILE 360 #include <pcl/sample_consensus/impl/sac_model_cylinder.hpp> 363 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_CYLINDER_H_ SampleConsensusModel< PointT >::PointCloud PointCloud
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances)
Compute all distances from the cloud data to a given cylinder model.
SampleConsensusModelCylinder defines a model for 3D cylinder segmentation.
pcl::SacModel getModelType() const
Return an unique id for this model (SACMODEL_CYLINDER).
Eigen::Vector3f getAxis()
Get the axis along which we need to search for a cylinder direction.
SampleConsensusModelCylinder(const PointCloudConstPtr &cloud, const std::vector< int > &indices, bool random=false)
Constructor for base SampleConsensusModelCylinder.
void optimizeModelCoefficients(const std::vector< int > &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients)
Recompute the cylinder coefficients using the given inlier set and return them to the user.
void setEpsAngle(const double ea)
Set the angle epsilon (delta) threshold.
bool doSamplesVerifyModel(const std::set< int > &indices, const Eigen::VectorXf &model_coefficients, const double threshold)
Verify whether a subset of indices verifies the given cylinder model coefficients.
unsigned int model_size_
The number of coefficients in the model.
Base functor all the models that need non linear optimization must define their own one and implement...
SampleConsensusModelCylinder & operator=(const SampleConsensusModelCylinder &source)
Copy constructor.
boost::shared_ptr< SampleConsensusModelCylinder > Ptr
bool computeModelCoefficients(const std::vector< int > &samples, Eigen::VectorXf &model_coefficients)
Check whether the given index samples can form a valid cylinder model, compute the model coefficients...
Define standard C methods to do distance calculations.
SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
virtual bool isModelValid(const Eigen::VectorXf &model_coefficients)
Check whether a model is valid given the user constraints.
double pointToLineDistance(const Eigen::Vector4f &pt, const Eigen::VectorXf &model_coefficients)
Get the distance from a point to a line (represented by a point and a direction)
void setAxis(const Eigen::Vector3f &ax)
Set the axis along which we need to search for a cylinder direction.
Define standard C methods and C++ classes that are common to all methods.
virtual int countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold)
Count all the points which respect the given model coefficients as inliers.
SampleConsensusModel represents the base model class.
double sqrPointToLineDistance(const Eigen::Vector4f &pt, const Eigen::Vector4f &line_pt, const Eigen::Vector4f &line_dir)
Get the square distance from a point to a line (represented by a point and a direction)
void projectPointToLine(const Eigen::Vector4f &pt, const Eigen::Vector4f &line_pt, const Eigen::Vector4f &line_dir, Eigen::Vector4f &pt_proj)
Project a point onto a line given by a point and a direction vector.
std::string model_name_
The model name.
pcl::PointCloud< PointT >::Ptr PointCloudPtr
SampleConsensusModelCylinder(const SampleConsensusModelCylinder &source)
Copy constructor.
bool isSampleGood(const std::vector< int > &samples) const
Check if a sample of indices results in a good sample of points indices.
SampleConsensusModelFromNormals represents the base model class for models that require the use of su...
PointCloud represents the base class in PCL for storing collections of 3D points.
pcl::PointCloud< PointT >::ConstPtr PointCloudConstPtr
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, std::vector< int > &inliers)
Select all the points which respect the given model coefficients as inliers.
void projectPointToCylinder(const Eigen::Vector4f &pt, const Eigen::VectorXf &model_coefficients, Eigen::Vector4f &pt_proj)
Project a point onto a cylinder given by its model coefficients (point_on_axis, axis_direction,...
std::string getName() const
Get a string representation of the name of this class.
A point structure representing Euclidean xyz coordinates, and the RGB color.
virtual ~SampleConsensusModelCylinder()
Empty destructor.
double getEpsAngle()
Get the angle epsilon (delta) threshold.
void projectPoints(const std::vector< int > &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields=true)
Create a new point cloud with inliers projected onto the cylinder model.
SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
SampleConsensusModelCylinder(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelCylinder.
unsigned int sample_size_
The size of a sample from which the model is computed.