From c0673214359cd11bf9177f6e57135eaa0de13557 Mon Sep 17 00:00:00 2001 From: Luigi Malomo Date: Mon, 28 May 2018 14:58:38 +0200 Subject: [PATCH] added compute area function for polygonal meshes --- vcg/complex/algorithms/stat.h | 12 ++++++++++++ vcg/space/polygon3.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/vcg/complex/algorithms/stat.h b/vcg/complex/algorithms/stat.h index 64b9a2aa..676314a0 100644 --- a/vcg/complex/algorithms/stat.h +++ b/vcg/complex/algorithms/stat.h @@ -31,6 +31,7 @@ #include #include #include +#include namespace vcg { @@ -264,6 +265,17 @@ public: return area/ScalarType(2.0); } + static ScalarType ComputePolyMeshArea(MeshType & m) + { + ScalarType area=0; + + for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) + if(!(*fi).IsD()) + area += PolyArea(*fi); + + return area; + } + static ScalarType ComputeBorderLength(MeshType & m) { RequireFFAdjacency(m); diff --git a/vcg/space/polygon3.h b/vcg/space/polygon3.h index 2e02e6fc..031523df 100644 --- a/vcg/space/polygon3.h +++ b/vcg/space/polygon3.h @@ -126,6 +126,9 @@ typename PolygonType::ScalarType PolyArea(const PolygonType &F) typedef typename PolygonType::CoordType CoordType; typedef typename PolygonType::ScalarType ScalarType; + if (F.VN() == 3) + return vcg::DoubleArea(F) / 2; + CoordType bary=PolyBarycenter(F); ScalarType Area=0; for (size_t i=0;i<(size_t)F.VN();i++)