51 Eigen::Vector4f model_coefficients;
52 EIGEN_ALIGN16 Eigen::Matrix3f covariance_matrix;
53 Eigen::Vector4f xyz_centroid;
58 EIGEN_ALIGN16 Eigen::Vector3f::Scalar eigen_value;
59 EIGEN_ALIGN16 Eigen::Vector3f eigen_vector;
60 eigen33 (covariance_matrix, eigen_value, eigen_vector);
62 model_coefficients[0] = eigen_vector [0];
63 model_coefficients[1] = eigen_vector [1];
64 model_coefficients[2] = eigen_vector [2];
65 model_coefficients[3] = 0;
68 model_coefficients[3] = -1 * model_coefficients.dot (xyz_centroid);
70 float distance_to_plane = model_coefficients[0] * point.x +
71 model_coefficients[1] * point.y +
72 model_coefficients[2] * point.z +
73 model_coefficients[3];
76 ppoint.x = point.x - distance_to_plane * model_coefficients[0];
77 ppoint.y = point.y - distance_to_plane * model_coefficients[1];
78 ppoint.z = point.z - distance_to_plane * model_coefficients[2];
83 k0 = (std::abs (model_coefficients[0] ) > std::abs (model_coefficients[1])) ? 0 : 1;
84 k0 = (std::abs (model_coefficients[k0]) > std::abs (model_coefficients[2])) ? k0 : 2;
90 for (std::size_t i = 0; i < polygon.
size (); ++i)
92 Eigen::Vector4f pt (polygon[i].x, polygon[i].y, polygon[i].z, 0);
93 xy_polygon[i].x = pt[k1];
94 xy_polygon[i].y = pt[k2];
99 Eigen::Vector4f pt (ppoint.x, ppoint.y, ppoint.z, 0);
110 bool in_poly =
false;
111 double x1, x2, y1, y2;
113 const auto nr_poly_points = polygon.
size ();
115 double xold = polygon[nr_poly_points - 1].x;
116 double yold = polygon[nr_poly_points - 1].y;
117 for (std::size_t i = 0; i < nr_poly_points; i++)
119 double xnew = polygon[i].x;
120 double ynew = polygon[i].y;
136 if ( (xnew < point.x) == (point.x <= xold) && (point.y - y1) * (x2 - x1) < (y2 - y1) * (point.x - x1) )
161 PCL_ERROR(
"[pcl::%s::segment] Not enough points (%zu) in the hull!\n",
169 Eigen::Vector4f model_coefficients;
170 EIGEN_ALIGN16 Eigen::Matrix3f covariance_matrix;
171 Eigen::Vector4f xyz_centroid;
176 EIGEN_ALIGN16 Eigen::Vector3f::Scalar eigen_value;
177 EIGEN_ALIGN16 Eigen::Vector3f eigen_vector;
178 eigen33 (covariance_matrix, eigen_value, eigen_vector);
180 model_coefficients[0] = eigen_vector [0];
181 model_coefficients[1] = eigen_vector [1];
182 model_coefficients[2] = eigen_vector [2];
183 model_coefficients[3] = 0;
186 model_coefficients[3] = -1 * model_coefficients.dot (xyz_centroid);
191 vp -= (*planar_hull_)[0].getVector4fMap ();
194 float cos_theta = vp.dot (model_coefficients);
198 model_coefficients *= -1;
199 model_coefficients[3] = 0;
201 model_coefficients[3] = -1 * (model_coefficients.dot ((*
planar_hull_)[0].getVector4fMap ()));
212 k0 = (std::abs (model_coefficients[0] ) > std::abs (model_coefficients[1])) ? 0 : 1;
213 k0 = (std::abs (model_coefficients[k0]) > std::abs (model_coefficients[2])) ? k0 : 2;
222 polygon[i].x = pt[k1];
223 polygon[i].y = pt[k2];
230 std::vector<pcl::PointCloud<PointT>> polygons(
polygons_.size());
232 polygons.push_back(polygon);
235 for (
size_t i = 0; i <
polygons_.size(); i++) {
237 polygons[i].reserve(polygon_i.vertices.size());
238 for (
const auto& pointIdx : polygon_i.vertices) {
239 polygons[i].points.push_back(polygon[pointIdx]);
246 for (std::size_t i = 0; i < projected_points.
size (); ++i)
254 Eigen::Vector4f pt (projected_points[i].x,
255 projected_points[i].y,
256 projected_points[i].z, 0);
260 bool in_poly =
false;
261 for (
const auto& poly : polygons) {
269 output.
indices[l++] = (*indices_)[i];
void projectPoints(const Indices &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields=true) const override
Create a new point cloud with inliers projected onto the plane model.
unsigned int computeMeanAndCovarianceMatrix(const pcl::PointCloud< PointT > &cloud, Eigen::Matrix< Scalar, 3, 3 > &covariance_matrix, Eigen::Matrix< Scalar, 4, 1 > ¢roid)
Compute the normalized 3x3 covariance matrix and the centroid of a given set of points in a single lo...
void eigen33(const Matrix &mat, typename Matrix::Scalar &eigenvalue, Vector &eigenvector)
determines the eigenvector and eigenvalue of the smallest eigenvalue of the symmetric positive semi d...
double pointToPlaneDistanceSigned(const Point &p, double a, double b, double c, double d)
Get the distance from a point to a plane (signed) defined by ax+by+cz+d=0.