From 47a989774797c3af5a37d377e13beabff06bd5b7 Mon Sep 17 00:00:00 2001 From: ccolin Date: Thu, 1 Oct 2020 17:35:38 +0200 Subject: [PATCH] implements the computation of the surface area --- src/main.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 0dfd3d5..7587b2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,6 +54,29 @@ bool check_edges_arent_lonely(const char *path) { } +float face_area(MyMesh &mesh, const MyMesh::FaceHandle &face) { + MyMesh::Point p0, p1, p2; + auto fv_it = mesh.fv_iter(face); + p0 = mesh.point(*fv_it++); + p1 = mesh.point(*fv_it++); + p2 = mesh.point(*fv_it); + return ((p1 - p0) % (p2 - p0)).norm() / 2; +} + + +float total_area(MyMesh &mesh) { + if (!check_faces_are_triangles(mesh)) { + std::cerr << "Le calcul de l’aire ne peu se faire que sur un maillage triangulaire." << std::endl; + return -1; + } + float ret = 0; + for (const MyMesh::FaceHandle &face : mesh.faces()) { + ret += face_area(mesh, face); + } + return ret; +} + + int main(int argc, char *argv[]) { using namespace std; @@ -75,5 +98,6 @@ int main(int argc, char *argv[]) { cout << "Les arêtes sont sur une face : " << (check_edges_arent_lonely(argv[1]) ? "oui" : "non") << endl; + cout << "Aire totale : " << total_area(mesh) << endl; return 0; }