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> 64 template <
typename Po
intT,
typename Po
intNT>
81 typedef boost::shared_ptr<SampleConsensusModelCylinder>
Ptr;
90 , axis_ (
Eigen::Vector3f::Zero ())
104 const std::vector<int> &indices,
108 , axis_ (
Eigen::Vector3f::Zero ())
122 axis_ (
Eigen::Vector3f::Zero ()),
140 axis_ = source.axis_;
141 eps_angle_ = source.eps_angle_;
159 setAxis (
const Eigen::Vector3f &ax) { axis_ = ax; }
162 inline Eigen::Vector3f
173 Eigen::VectorXf &model_coefficients)
const;
181 std::vector<double> &distances)
const;
190 const double threshold,
191 std::vector<int> &inliers);
201 const double threshold)
const;
211 const Eigen::VectorXf &model_coefficients,
212 Eigen::VectorXf &optimized_coefficients)
const;
223 const Eigen::VectorXf &model_coefficients,
225 bool copy_data_fields =
true)
const;
234 const Eigen::VectorXf &model_coefficients,
235 const double threshold)
const;
250 pointToLineDistance (
const Eigen::Vector4f &pt,
const Eigen::VectorXf &model_coefficients)
const;
260 const Eigen::Vector4f &line_pt,
261 const Eigen::Vector4f &line_dir,
262 Eigen::Vector4f &pt_proj)
const 264 float k = (pt.dot (line_dir) - line_pt.dot (line_dir)) / line_dir.dot (line_dir);
266 pt_proj = line_pt + k * line_dir;
277 const Eigen::VectorXf &model_coefficients,
278 Eigen::Vector4f &pt_proj)
const;
284 isModelValid (
const Eigen::VectorXf &model_coefficients)
const;
295 Eigen::Vector3f axis_;
300 #if defined BUILD_Maintainer && defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ > 3 301 #pragma GCC diagnostic ignored "-Weffc++" 319 operator() (
const Eigen::VectorXf &x, Eigen::VectorXf &fvec)
const 321 Eigen::Vector4f line_pt (x[0], x[1], x[2], 0);
322 Eigen::Vector4f line_dir (x[3], x[4], x[5], 0);
324 for (
int i = 0; i < values (); ++i)
327 Eigen::Vector4f pt (model_->input_->points[
indices_[i]].x,
328 model_->input_->points[
indices_[i]].y,
329 model_->input_->points[
indices_[i]].z, 0);
339 #if defined BUILD_Maintainer && defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ > 3 340 #pragma GCC diagnostic warning "-Weffc++" 345 #ifdef PCL_NO_PRECOMPILE 346 #include <pcl/sample_consensus/impl/sac_model_cylinder.hpp> 349 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_CYLINDER_H_ SampleConsensusModel< PointT >::PointCloud PointCloud
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 setEpsAngle(const double ea)
Set the angle epsilon (delta) threshold.
This file defines compatibility wrappers for low level I/O functions.
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.
bool computeModelCoefficients(const std::vector< int > &samples, Eigen::VectorXf &model_coefficients) const
Check whether the given index samples can form a valid cylinder model, compute the model coefficients...
virtual bool isModelValid(const Eigen::VectorXf &model_coefficients) const
Check whether a model is valid given the user constraints.
boost::shared_ptr< std::vector< int > > indices_
A pointer to the vector of point indices to use.
boost::shared_ptr< SampleConsensusModelCylinder > Ptr
void projectPointToLine(const Eigen::Vector4f &pt, const Eigen::Vector4f &line_pt, const Eigen::Vector4f &line_dir, Eigen::Vector4f &pt_proj) const
Project a point onto a line given by a point and a direction vector.
Define standard C methods to do distance calculations.
bool doSamplesVerifyModel(const std::set< int > &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const
Verify whether a subset of indices verifies the given cylinder model coefficients.
SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
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.
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)
std::string model_name_
The model name.
pcl::PointCloud< PointT >::Ptr PointCloudPtr
SampleConsensusModelCylinder(const SampleConsensusModelCylinder &source)
Copy constructor.
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const
Compute all distances from the cloud data to a given cylinder model.
bool isSampleGood(const std::vector< int > &samples) const
Check if a sample of indices results in a good sample of points indices.
void projectPoints(const std::vector< int > &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields=true) const
Create a new point cloud with inliers projected onto the cylinder model.
SampleConsensusModelFromNormals represents the base model class for models that require the use of su...
double pointToLineDistance(const Eigen::Vector4f &pt, const Eigen::VectorXf &model_coefficients) const
Get the distance from a point to a line (represented by a point and a direction)
PointCloud represents the base class in PCL for storing collections of 3D points.
void projectPointToCylinder(const Eigen::Vector4f &pt, const Eigen::VectorXf &model_coefficients, Eigen::Vector4f &pt_proj) const
Project a point onto a cylinder given by its model coefficients (point_on_axis, axis_direction,...
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.
A point structure representing Euclidean xyz coordinates, and the RGB color.
virtual ~SampleConsensusModelCylinder()
Empty destructor.
double getEpsAngle()
Get the angle epsilon (delta) threshold.
SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
virtual int countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const
Count all the points which respect the given model coefficients as inliers.
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.
void optimizeModelCoefficients(const std::vector< int > &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const
Recompute the cylinder coefficients using the given inlier set and return them to the user.