implements the computation of the surface area
This commit is contained in:
parent
717603d5d3
commit
47a9897747
24
src/main.cpp
24
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user