38 #ifndef PCL_COMMON_IMPL_H_
39 #define PCL_COMMON_IMPL_H_
47 pcl::getAngle3D (
const Eigen::Vector4f &v1,
const Eigen::Vector4f &v2,
const bool in_degree)
50 double rad = v1.normalized ().dot (v2.normalized ());
55 return (in_degree ? std::acos (rad) * 180.0 /
M_PI : std::acos (rad));
59 pcl::getAngle3D (
const Eigen::Vector3f &v1,
const Eigen::Vector3f &v2,
const bool in_degree)
62 double rad = v1.normalized ().dot (v2.normalized ());
67 return (in_degree ? std::acos (rad) * 180.0 /
M_PI : std::acos (rad));
81 if (values.size () == 1)
88 double sum = 0, sq_sum = 0;
90 for (
const float &value : values)
93 sq_sum += value * value;
95 mean = sum /
static_cast<double>(values.size ());
96 double variance = (sq_sum - sum * sum /
static_cast<double>(values.size ())) / (
static_cast<double>(values.size ()) - 1);
97 stddev = sqrt (variance);
101 template <
typename Po
intT>
inline void
103 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
106 indices.resize (cloud.
size ());
112 for (std::size_t i = 0; i < cloud.
size (); ++i)
115 if (cloud[i].x < min_pt[0] || cloud[i].y < min_pt[1] || cloud[i].z < min_pt[2])
117 if (cloud[i].x > max_pt[0] || cloud[i].y > max_pt[1] || cloud[i].z > max_pt[2])
119 indices[l++] = int (i);
125 for (std::size_t i = 0; i < cloud.
size (); ++i)
128 if (!std::isfinite (cloud[i].x) ||
129 !std::isfinite (cloud[i].y) ||
130 !std::isfinite (cloud[i].z))
133 if (cloud[i].x < min_pt[0] || cloud[i].y < min_pt[1] || cloud[i].z < min_pt[2])
135 if (cloud[i].x > max_pt[0] || cloud[i].y > max_pt[1] || cloud[i].z > max_pt[2])
137 indices[l++] = int (i);
144 template<
typename Po
intT>
inline void
147 float max_dist = -FLT_MAX;
150 const Eigen::Vector3f pivot_pt3 = pivot_pt.head<3> ();
155 for (std::size_t i = 0; i < cloud.
size (); ++i)
158 dist = (pivot_pt3 - pt).norm ();
169 for (std::size_t i = 0; i < cloud.
size (); ++i)
172 if (!std::isfinite (cloud[i].x) || !std::isfinite (cloud[i].y) || !std::isfinite (cloud[i].z))
175 dist = (pivot_pt3 - pt).norm ();
185 max_pt = cloud[max_idx].getVector4fMap ();
187 max_pt = Eigen::Vector4f(std::numeric_limits<float>::quiet_NaN(),std::numeric_limits<float>::quiet_NaN(),std::numeric_limits<float>::quiet_NaN(),std::numeric_limits<float>::quiet_NaN());
191 template<
typename Po
intT>
inline void
193 const Eigen::Vector4f &pivot_pt, Eigen::Vector4f &max_pt)
195 float max_dist = -FLT_MAX;
198 const Eigen::Vector3f pivot_pt3 = pivot_pt.head<3> ();
203 for (std::size_t i = 0; i < indices.size (); ++i)
206 dist = (pivot_pt3 - pt).norm ();
209 max_idx =
static_cast<int> (i);
217 for (std::size_t i = 0; i < indices.size (); ++i)
220 if (!std::isfinite (cloud[indices[i]].x) || !std::isfinite (cloud[indices[i]].y)
222 !std::isfinite (cloud[indices[i]].z))
226 dist = (pivot_pt3 - pt).norm ();
229 max_idx =
static_cast<int> (i);
236 max_pt = cloud[indices[max_idx]].getVector4fMap ();
238 max_pt = Eigen::Vector4f(std::numeric_limits<float>::quiet_NaN(),std::numeric_limits<float>::quiet_NaN(),std::numeric_limits<float>::quiet_NaN(),std::numeric_limits<float>::quiet_NaN());
242 template <
typename Po
intT>
inline void
245 Eigen::Array4f min_p, max_p;
246 min_p.setConstant (FLT_MAX);
247 max_p.setConstant (-FLT_MAX);
252 for (
const auto& point: cloud.
points)
254 const auto pt = point.getArray4fMap ();
255 min_p = min_p.min (pt);
256 max_p = max_p.max (pt);
262 for (
const auto& point: cloud.
points)
265 if (!std::isfinite (point.x) ||
266 !std::isfinite (point.y) ||
267 !std::isfinite (point.z))
269 const auto pt = point.getArray4fMap ();
270 min_p = min_p.min (pt);
271 max_p = max_p.max (pt);
274 min_pt.x = min_p[0]; min_pt.y = min_p[1]; min_pt.z = min_p[2];
275 max_pt.x = max_p[0]; max_pt.y = max_p[1]; max_pt.z = max_p[2];
279 template <
typename Po
intT>
inline void
282 Eigen::Array4f min_p, max_p;
283 min_p.setConstant (FLT_MAX);
284 max_p.setConstant (-FLT_MAX);
289 for (
const auto& point: cloud.
points)
291 const auto pt = point.getArray4fMap ();
292 min_p = min_p.min (pt);
293 max_p = max_p.max (pt);
299 for (
const auto& point: cloud.
points)
302 if (!std::isfinite (point.x) ||
303 !std::isfinite (point.y) ||
304 !std::isfinite (point.z))
306 const auto pt = point.getArray4fMap ();
307 min_p = min_p.min (pt);
308 max_p = max_p.max (pt);
317 template <
typename Po
intT>
inline void
319 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt)
321 Eigen::Array4f min_p, max_p;
322 min_p.setConstant (FLT_MAX);
323 max_p.setConstant (-FLT_MAX);
328 for (
const int &index : indices.
indices)
331 min_p = min_p.min (pt);
332 max_p = max_p.max (pt);
338 for (
const int &index : indices.
indices)
341 if (!std::isfinite (cloud[index].x) ||
342 !std::isfinite (cloud[index].y) ||
343 !std::isfinite (cloud[index].z))
346 min_p = min_p.min (pt);
347 max_p = max_p.max (pt);
355 template <
typename Po
intT>
inline void
357 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt)
359 min_pt.setConstant (FLT_MAX);
360 max_pt.setConstant (-FLT_MAX);
365 for (
const int &index : indices)
368 min_pt = min_pt.array ().min (pt);
369 max_pt = max_pt.array ().max (pt);
375 for (
const int &index : indices)
378 if (!std::isfinite (cloud[index].x) ||
379 !std::isfinite (cloud[index].y) ||
380 !std::isfinite (cloud[index].z))
383 min_pt = min_pt.array ().min (pt);
384 max_pt = max_pt.array ().max (pt);
390 template <
typename Po
intT>
inline double
393 Eigen::Vector4f p1 (pa.x, pa.y, pa.z, 0);
394 Eigen::Vector4f p2 (pb.x, pb.y, pb.z, 0);
395 Eigen::Vector4f p3 (pc.x, pc.y, pc.z, 0);
397 double p2p1 = (p2 - p1).norm (), p3p2 = (p3 - p2).norm (), p1p3 = (p1 - p3).norm ();
400 double semiperimeter = (p2p1 + p3p2 + p1p3) / 2.0;
401 double area = sqrt (semiperimeter * (semiperimeter - p2p1) * (semiperimeter - p3p2) * (semiperimeter - p1p3));
403 return ((p2p1 * p3p2 * p1p3) / (4.0 * area));
407 template <
typename Po
intT>
inline void
413 for (
int i = 0; i < len; ++i)
415 min_p = (histogram[i] > min_p) ? min_p : histogram[i];
416 max_p = (histogram[i] < max_p) ? max_p : histogram[i];
421 template <
typename Po
intT>
inline float
425 int num_points = polygon.
size ();
426 Eigen::Vector3f va,vb,res;
428 res(0) = res(1) = res(2) = 0.0f;
429 for (
int i = 0; i < num_points; ++i)
431 int j = (i + 1) % num_points;
432 va = polygon[i].getVector3fMap ();
433 vb = polygon[j].getVector3fMap ();
434 res += va.cross (vb);
An exception that is thrown when the arguments number or type is wrong/unhandled.
PointCloud represents the base class in PCL for storing collections of 3D points.
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Define standard C methods and C++ classes that are common to all methods.
Defines all the PCL implemented PointT point type structures.
void getMaxDistance(const pcl::PointCloud< PointT > &cloud, const Eigen::Vector4f &pivot_pt, Eigen::Vector4f &max_pt)
Get the point at maximum distance from a given point and a given pointcloud.
float calculatePolygonArea(const pcl::PointCloud< PointT > &polygon)
Calculate the area of a polygon given a point cloud that defines the polygon.
void getMinMax3D(const pcl::PointCloud< PointT > &cloud, PointT &min_pt, PointT &max_pt)
Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud.
void getMeanStd(const std::vector< float > &values, double &mean, double &stddev)
Compute both the mean and the standard deviation of an array of values.
double getAngle3D(const Eigen::Vector4f &v1, const Eigen::Vector4f &v2, const bool in_degree=false)
Compute the smallest angle between two 3D vectors in radians (default) or degree.
void getPointsInBox(const pcl::PointCloud< PointT > &cloud, Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt, Indices &indices)
Get a set of points residing in a box given its bounds.
void getMinMax(const PointT &histogram, int len, float &min_p, float &max_p)
Get the minimum and maximum values on a point histogram.
double getCircumcircleRadius(const PointT &pa, const PointT &pb, const PointT &pc)
Compute the radius of a circumscribed circle for a triangle formed of three points pa,...
const Eigen::Map< const Eigen::Vector3f > Vector3fMapConst
const Eigen::Map< const Eigen::Array4f, Eigen::Aligned > Array4fMapConst
IndicesAllocator<> Indices
Type used for indices in PCL.
A point structure representing Euclidean xyz coordinates, and the RGB color.