Skip to content

Commit 12d02bb

Browse files
committed
computeTriangleMeshArea() : calculate the area of a triangle mesh
1 parent f2492bd commit 12d02bb

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

surface/include/pcl/surface/gp3.h

+45
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,51 @@ namespace pcl
513513
}
514514
};
515515

516+
/** \brief Calculate the area of a triangle mesh
517+
* \param[in] cloud the point cloud to which the mesh is applied
518+
* \param[in] triangleMesh a triangle mesh
519+
* \return the mesh area
520+
* \note example of use:
521+
* pcl::GreedyProjectionTriangulation<PointN> gp;
522+
* ...
523+
* gp.setInputCloud(cloud_with_normals)
524+
* ...
525+
* pcl::PolygonMesh pm;
526+
* gp3.reconstruct(pm);
527+
* calculatePolygonArea(cloud_with_normals, pm.vertices);
528+
* gp.reconstruct(pm);
529+
* float functArea=computeTriangleMeshArea(cloud_with_normals, pm.polygons);
530+
* \ingroup
531+
* common
532+
*/
533+
template <typename PointT>
534+
inline float
535+
computeTriangleMeshArea(const shared_ptr<pcl::PointCloud<PointT>>& cloud,
536+
std::vector<pcl::Vertices>& triangleMesh);
537+
538+
/** \brief Calculate the area of a triangle mesh
539+
* \param[in] cloud the point cloud to which the mesh is applied
540+
* \param[in] indices of the point cloud
541+
* \param[in] triangleMesh a triangle mesh
542+
* \return the mesh area
543+
* \note example of use:
544+
* pcl::GreedyProjectionTriangulation<PointN> gp;
545+
* ...
546+
* gp.setInputCloud(cloud_with_normals)
547+
* ...
548+
* pcl::PolygonMesh pm;
549+
* gp.reconstruct(pm);
550+
* float functArea=computeTriangleMeshArea(cloud_with_normals, pm.polygons);
551+
* \ingroup
552+
* common
553+
*/
554+
555+
template <typename PointT>
556+
inline float
557+
computeTriangleMeshArea(const shared_ptr<pcl::PointCloud<PointT>>& cloud,
558+
const shared_ptr<Indices>& indices,
559+
std::vector<pcl::Vertices>& triangleMesh);
560+
516561
} // namespace pcl
517562

518563
#ifdef PCL_NO_PRECOMPILE

surface/include/pcl/surface/impl/gp3.hpp

+53
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,59 @@ pcl::GreedyProjectionTriangulation<PointInT>::getTriangleList (const pcl::Polygo
16671667
#define PCL_INSTANTIATE_GreedyProjectionTriangulation(T) \
16681668
template class PCL_EXPORTS pcl::GreedyProjectionTriangulation<T>;
16691669

1670+
template <typename PointT>
1671+
inline float
1672+
pcl::computeTriangleMeshArea(const shared_ptr<pcl::PointCloud<PointT>>& cloud,
1673+
std::vector<pcl::Vertices>& triangleMesh)
1674+
{
1675+
const pcl::PointCloud<PointT>::ConstPtr input_ = cloud;
1676+
double area = 0;
1677+
for (auto& triangle_ : triangleMesh) {
1678+
if (triangle_.vertices.size() == 3) {
1679+
const Eigen::Matrix<double, 3, 1> P(
1680+
(*input_)[triangle_.vertices[0]].x - (*input_)[triangle_.vertices[2]].x,
1681+
(*input_)[triangle_.vertices[0]].y - (*input_)[triangle_.vertices[2]].y,
1682+
(*input_)[triangle_.vertices[0]].z - (*input_)[triangle_.vertices[2]].z);
1683+
const Eigen::Matrix<double, 3, 1> Q(
1684+
(*input_)[triangle_.vertices[1]].x - (*input_)[triangle_.vertices[2]].x,
1685+
(*input_)[triangle_.vertices[1]].y - (*input_)[triangle_.vertices[2]].y,
1686+
(*input_)[triangle_.vertices[1]].z - (*input_)[triangle_.vertices[2]].z);
1687+
area += 0.5 * P.cross(Q).norm();
1688+
}
1689+
}
1690+
return area;
1691+
}
1692+
1693+
template <typename PointT>
1694+
inline float
1695+
pcl::computeTriangleMeshArea(const shared_ptr<pcl::PointCloud<PointT>>& cloud,
1696+
const shared_ptr<Indices>& indices,
1697+
std::vector<pcl::Vertices>& triangleMesh)
1698+
{
1699+
const pcl::PointCloud<PointT>::ConstPtr input_ = cloud;
1700+
double area = 0;
1701+
for (auto& triangle_ : triangleMesh) {
1702+
if (triangle_.vertices.size() == 3) {
1703+
const Eigen::Matrix<double, 3, 1> P(
1704+
(*input_)[(*indices_)[triangle_.vertices[0]]].x -
1705+
(*input_)[(*indices_)[triangle_.vertices[2]]].x,
1706+
(*input_)[(*indices_)[triangle_.vertices[0]]].y -
1707+
(*input_)[(*indices_)[triangle_.vertices[2]]].y,
1708+
(*input_)[(*indices_)[triangle_.vertices[0]]].z -
1709+
(*input_)[(*indices_)[triangle_.vertices[2]]].z);
1710+
const Eigen::Matrix<double, 3, 1> Q(
1711+
(*input_)[(*indices_)[triangle_.vertices[1]]].x -
1712+
(*input_)[(*indices_)[triangle_.vertices[2]]].x,
1713+
(*input_)[(*indices_)[triangle_.vertices[1]]].y -
1714+
(*input_)[(*indices_)[triangle_.vertices[2]]].y,
1715+
(*input_)[(*indices_)[triangle_.vertices[1]]].z -
1716+
(*input_)[(*indices_)[triangle_.vertices[2]]].z);
1717+
area += 0.5 * P.cross(Q).norm();
1718+
}
1719+
}
1720+
return area;
1721+
}
1722+
16701723
#endif // PCL_SURFACE_IMPL_GP3_H_
16711724

16721725

0 commit comments

Comments
 (0)