implements the computation of the surface area

This commit is contained in:
ccolin 2020-10-01 17:35:38 +02:00
parent 717603d5d3
commit 47a9897747
1 changed files with 24 additions and 0 deletions

View File

@ -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 laire 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;
}