33 #ifndef _SAMPLE_CONSENSUS_SACMODELLINE_H_ 34 #define _SAMPLE_CONSENSUS_SACMODELLINE_H_ 40 #define MAX_ITERATIONS_UNIQUE 1000 57 virtual void getSamples (
int &iterations, std::vector<int> &samples);
68 virtual void refitModel (
const std::vector<int> &inliers, std::vector<double> &refit_coefficients);
69 virtual void getDistancesToModel (
const std::vector<double> &model_coefficients, std::vector<double> &distances);
70 virtual void selectWithinDistance (
const std::vector<double> &model_coefficients,
double threshold, std::vector<int> &inliers);
72 virtual void projectPoints (
const std::vector<int> &inliers,
const std::vector<double> &model_coefficients,
PointCloud &projected_points);
74 virtual void projectPointsInPlace (
const std::vector<int> &inliers,
const std::vector<double> &model_coefficients);
87 cross (
const pcl::PointXYZ &p1,
const pcl::PointXYZ &p2)
90 r.x = p1.y * p2.z - p1.z * p2.y;
91 r.y = p1.z * p2.x - p1.x * p2.z;
92 r.z = p1.x * p2.y - p1.y * p2.x;
105 centroid.x = centroid.y = centroid.z = 0;
107 for (
unsigned int i = 0; i < indices.size (); i++)
109 centroid.x += points.points.at (indices.at (i)).
x;
110 centroid.y += points.points.at (indices.at (i)).
y;
111 centroid.z += points.points.at (indices.at (i)).
z;
114 centroid.x /= indices.size ();
115 centroid.y /= indices.size ();
116 centroid.z /= indices.size ();
134 covariance_matrix = Eigen::Matrix3d::Zero ();
136 for (
unsigned int j = 0; j < indices.size (); j++)
138 covariance_matrix (0, 0) += (points.points[indices.at (j)].x - centroid.x) * (points.points[indices.at (j)].x - centroid.x);
139 covariance_matrix (0, 1) += (points.points[indices.at (j)].x - centroid.x) * (points.points[indices.at (j)].y - centroid.y);
140 covariance_matrix (0, 2) += (points.points[indices.at (j)].x - centroid.x) * (points.points[indices.at (j)].z - centroid.z);
142 covariance_matrix (1, 0) += (points.points[indices.at (j)].y - centroid.y) * (points.points[indices.at (j)].x - centroid.x);
143 covariance_matrix (1, 1) += (points.points[indices.at (j)].y - centroid.y) * (points.points[indices.at (j)].y - centroid.y);
144 covariance_matrix (1, 2) += (points.points[indices.at (j)].y - centroid.y) * (points.points[indices.at (j)].z - centroid.z);
146 covariance_matrix (2, 0) += (points.points[indices.at (j)].z - centroid.z) * (points.points[indices.at (j)].x - centroid.x);
147 covariance_matrix (2, 1) += (points.points[indices.at (j)].z - centroid.z) * (points.points[indices.at (j)].y - centroid.y);
148 covariance_matrix (2, 2) += (points.points[indices.at (j)].z - centroid.z) * (points.points[indices.at (j)].z - centroid.z);
virtual bool computeModelCoefficients(const std::vector< int > &samples)
Check whether the given index samples can form a valid line model, compute the model coefficients fro...
virtual void projectPoints(const std::vector< int > &inliers, const std::vector< double > &model_coefficients, PointCloud &projected_points)
Create a new point cloud with inliers projected onto the line model.
pcl::PointCloud< pcl::PointXYZ > PointCloud
virtual void refitModel(const std::vector< int > &inliers, std::vector< double > &refit_coefficients)
Recompute the line coefficients using the given inlier set and return them to the user...
A Sample Consensus Model class for 3D line segmentation.
TFSIMD_FORCE_INLINE const tfScalar & y() const
virtual ~SACModelLine()
Destructor for base SACModelLine.
bool testModelCoefficients(const std::vector< double > &model_coefficients)
Test whether the given model coefficients are valid given the input point cloud data.
virtual void getSamples(int &iterations, std::vector< int > &samples)
Get 2 random points as data samples and return them as point indices.
void computeCovarianceMatrix(const PointCloud &points, const std::vector< int > &indices, Eigen::Matrix3d &covariance_matrix, pcl::PointXYZ ¢roid)
Compute the 3x3 covariance matrix of a given set of points using their indices. The result is returne...
void computeCentroid(const PointCloud &points, const std::vector< int > &indices, pcl::PointXYZ ¢roid)
Compute the centroid of a set of points using their indices and return it as a Point32 message...
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & z() const
virtual void projectPointsInPlace(const std::vector< int > &inliers, const std::vector< double > &model_coefficients)
Project inliers (in place) onto the given line model.
pcl::PointXYZ cross(const pcl::PointXYZ &p1, const pcl::PointXYZ &p2)
Compute the cross product between two points (vectors).
SACModelLine()
Constructor for base SACModelLine.
virtual int getModelType()
Return an unique id for this model (SACMODEL_LINE).
virtual void getDistancesToModel(const std::vector< double > &model_coefficients, std::vector< double > &distances)
Compute all distances from the cloud data to a given line model.
virtual void selectWithinDistance(const std::vector< double > &model_coefficients, double threshold, std::vector< int > &inliers)
Select all the points which respect the given model coefficients as inliers.
virtual bool doSamplesVerifyModel(const std::set< int > &indices, double threshold)
Verify whether a subset of indices verifies the internal line model coefficients. ...