38 #ifndef PCL_SEGMENTATION_IMPL_EXTRACT_POLYGONAL_PRISM_DATA_H_
39 #define PCL_SEGMENTATION_IMPL_EXTRACT_POLYGONAL_PRISM_DATA_H_
46 template <
typename Po
intT>
bool
50 Eigen::Vector4f model_coefficients;
52 Eigen::Vector4f xyz_centroid;
59 eigen33 (covariance_matrix, eigen_value, eigen_vector);
61 model_coefficients[0] = eigen_vector [0];
62 model_coefficients[1] = eigen_vector [1];
63 model_coefficients[2] = eigen_vector [2];
64 model_coefficients[3] = 0;
67 model_coefficients[3] = -1 * model_coefficients.dot (xyz_centroid);
69 float distance_to_plane = model_coefficients[0] * point.x +
70 model_coefficients[1] * point.y +
71 model_coefficients[2] * point.z +
72 model_coefficients[3];
75 ppoint.x = point.x - distance_to_plane * model_coefficients[0];
76 ppoint.y = point.y - distance_to_plane * model_coefficients[1];
77 ppoint.z = point.z - distance_to_plane * model_coefficients[2];
82 k0 = (fabs (model_coefficients[0] ) > fabs (model_coefficients[1])) ? 0 : 1;
83 k0 = (fabs (model_coefficients[k0]) > fabs (model_coefficients[2])) ? k0 : 2;
89 for (
size_t i = 0; i < polygon.
points.size (); ++i)
92 xy_polygon.
points[i].x = pt[k1];
93 xy_polygon.
points[i].y = pt[k2];
94 xy_polygon.
points[i].z = 0;
98 Eigen::Vector4f pt (ppoint.x, ppoint.y, ppoint.z, 0);
106 template <
typename Po
intT>
bool
109 bool in_poly =
false;
110 double x1, x2, y1, y2;
112 int nr_poly_points =
static_cast<int> (polygon.
points.size ());
113 double xold = polygon.
points[nr_poly_points - 1].x;
114 double yold = polygon.
points[nr_poly_points - 1].y;
115 for (
int i = 0; i < nr_poly_points; i++)
117 double xnew = polygon.
points[i].x;
118 double ynew = polygon.
points[i].y;
134 if ( (xnew < point.x) == (point.x <= xold) && (point.y - y1) * (x2 - x1) < (y2 - y1) * (point.x - x1) )
145 template <
typename Po
intT>
void
148 output.
header = input_->header;
156 if (static_cast<int> (planar_hull_->points.size ()) < min_pts_hull_)
158 PCL_ERROR (
"[pcl::%s::segment] Not enough points (%zu) in the hull!\n", getClassName ().c_str (), planar_hull_->points.size ());
164 Eigen::Vector4f model_coefficients;
166 Eigen::Vector4f xyz_centroid;
173 eigen33 (covariance_matrix, eigen_value, eigen_vector);
175 model_coefficients[0] = eigen_vector [0];
176 model_coefficients[1] = eigen_vector [1];
177 model_coefficients[2] = eigen_vector [2];
178 model_coefficients[3] = 0;
181 model_coefficients[3] = -1 * model_coefficients.dot (xyz_centroid);
184 Eigen::Vector4f vp (vpx_, vpy_, vpz_, 0);
186 vp -= planar_hull_->points[0].getVector4fMap ();
189 float cos_theta = vp.dot (model_coefficients);
193 model_coefficients *= -1;
194 model_coefficients[3] = 0;
196 model_coefficients[3] = -1 * (model_coefficients.dot (planar_hull_->points[0].getVector4fMap ()));
202 sacmodel.
projectPoints (*indices_, model_coefficients, projected_points,
false);
207 k0 = (fabs (model_coefficients[0] ) > fabs (model_coefficients[1])) ? 0 : 1;
208 k0 = (fabs (model_coefficients[k0]) > fabs (model_coefficients[2])) ? k0 : 2;
213 polygon.
points.resize (planar_hull_->points.size ());
214 for (
size_t i = 0; i < planar_hull_->points.size (); ++i)
216 Eigen::Vector4f pt (planar_hull_->points[i].x, planar_hull_->points[i].y, planar_hull_->points[i].z, 0);
217 polygon.
points[i].x = pt[k1];
218 polygon.
points[i].y = pt[k2];
225 output.
indices.resize (indices_->size ());
227 for (
size_t i = 0; i < projected_points.
points.size (); ++i)
231 if (distance < height_limit_min_ || distance > height_limit_max_)
235 Eigen::Vector4f pt (projected_points.
points[i].x,
236 projected_points.
points[i].y,
237 projected_points.
points[i].z, 0);
244 output.
indices[l++] = (*indices_)[i];
251 #define PCL_INSTANTIATE_ExtractPolygonalPrismData(T) template class PCL_EXPORTS pcl::ExtractPolygonalPrismData<T>;
252 #define PCL_INSTANTIATE_isPointIn2DPolygon(T) template bool PCL_EXPORTS pcl::isPointIn2DPolygon<T>(const T&, const pcl::PointCloud<T> &);
253 #define PCL_INSTANTIATE_isXYPointIn2DXYPolygon(T) template bool PCL_EXPORTS pcl::isXYPointIn2DXYPolygon<T>(const T &, const pcl::PointCloud<T> &);
255 #endif // PCL_SEGMENTATION_IMPL_EXTRACT_POLYGONAL_PRISM_DATA_H_