From b926d1c433c26bd4d062fd6e4d68d71de426400b Mon Sep 17 00:00:00 2001
From: BEYER Astrid <astrid.beyer@etu.univ-amu.fr>
Date: Thu, 20 Apr 2023 16:07:35 +0200
Subject: [PATCH] =?UTF-8?q?feat:=20g=C3=A8re=20bien=20le=20cas=20o=C3=B9?=
 =?UTF-8?q?=20un=20obj=20a=20besoin=20d'=C3=AAtre=20triangul=C3=A9,=20pr?=
 =?UTF-8?q?=C3=A9cise=20si=20ce=20n'est=20pas=20possible?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 CMakeLists.txt    |  2 +-
 isTriangulate.cpp | 35 -----------------------------------
 isTriangulate.h   |  9 ---------
 main.cpp          | 21 +++++++++++++++++++--
 triangulate.cpp   | 34 ++++++++++++++++++++++++++++++++++
 triangulate.h     | 23 +++++++++++++++++++++++
 6 files changed, 77 insertions(+), 47 deletions(-)
 delete mode 100644 isTriangulate.cpp
 delete mode 100644 isTriangulate.h
 create mode 100644 triangulate.cpp
 create mode 100644 triangulate.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b02cc5f..9d8c7e8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 11)
 
 find_package(TTKVTK REQUIRED)
 
-add_executable(projet-stage main.cpp isTriangulate.cpp)
+add_executable(projet-stage main.cpp triangulate.cpp)
 
 target_link_libraries(projet-stage
   PUBLIC
diff --git a/isTriangulate.cpp b/isTriangulate.cpp
deleted file mode 100644
index 9e0a153..0000000
--- a/isTriangulate.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include <vtkTriangleFilter.h>
-#include "isTriangulate.h"
-
-// Fonction pour construire une triangulation valide à partir d'un vtkPolyData contenant des quadrilatères
-vtkSmartPointer<vtkPolyData> triangulate::buildValidTriangulation(vtkSmartPointer<vtkPolyData> polyData)
-{
-    vtkSmartPointer<vtkPolyData> triPolyData = vtkSmartPointer<vtkPolyData>::New();
-
-    // Si le maillage en entrée est composé de quadrilatères, on construit une triangulation valide
-    if (polyData->GetMaxCellSize() > 3)
-    {
-        std::cout << "maillage composé de quads";
-        // On utilise un filtre vtkQuadToTriangle pour convertir les quadrilatères en triangles
-        vtkSmartPointer<vtkTriangleFilter> quadToTri = vtkSmartPointer<vtkTriangleFilter>::New();
-        quadToTri->SetInputData(polyData);
-        quadToTri->Update();
-
-        triPolyData = quadToTri->GetOutput();
-    }
-    else if (polyData->GetMaxCellSize() == 3) // Si le maillage en entrée est déjà triangulé, on renvoie le vtkPolyData d'origine
-    {
-        triPolyData = polyData;
-    }
-    else
-    {
-        std::cout << "Ce maillage n'est pas géré par ce programme, sont acceptés les maillages triangulés et quadrilatérisés";
-    }
-
-    // On ajoute un filtre vtkTriangleFilter pour garantir que la sortie est bien un maillage triangulé
-    vtkSmartPointer<vtkTriangleFilter> triangleFilter = vtkSmartPointer<vtkTriangleFilter>::New();
-    triangleFilter->SetInputData(triPolyData);
-    triangleFilter->Update();
-
-    return triangleFilter->GetOutput();
-}
\ No newline at end of file
diff --git a/isTriangulate.h b/isTriangulate.h
deleted file mode 100644
index 0c25de8..0000000
--- a/isTriangulate.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef IS_TRIANGULATE_H // Vérification d'inclusion multiple
-#define IS_TRIANGULATE_H
-
-namespace triangulate
-{
-    vtkSmartPointer<vtkPolyData> buildValidTriangulation(vtkSmartPointer<vtkPolyData> polyData); // Prototype de la fonction
-}
-
-#endif // Fin de vérification d'inclusion multiple
diff --git a/main.cpp b/main.cpp
index 057a537..0ebd704 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,3 +1,20 @@
+/**=========================================================================
+* @file     main.cpp
+*
+* @brief    This script reads mesh files and translate them in VTKPolyData.
+*           It calculates the main curvature of the mesh, then the shape index in
+*           each vertex of the mesh. Generates a Reeb's graph of shape index.
+*           Finally, it writes the graph in .vtp format and colors the map with
+*           the shape index of mesh.
+*
+* @authors  Lucie CLERAND, Eve REGA
+*           Astrid BEYER
+*
+* @date     2023
+* @version  1.0.1
+*
+=========================================================================**/
+
 #include <vtkNew.h>
 #include <vtkSmartPointer.h>
 #include <vtkOBJReader.h>
@@ -38,10 +55,11 @@
 #include <vtkAppendPolyData.h>
 #include <vtkSortDataArray.h>
 
-#include "isTriangulate.h"
+#include "triangulate.h"
 
 int main(int argc, char *argv[])
 {
+  vtkObject::GlobalWarningDisplayOff();
   if (argc != 2)
   {
     std::cout << "Required arguments: Filename(.obj)" << std::endl;
@@ -60,7 +78,6 @@ int main(int argc, char *argv[])
     vtkNew<vtkOBJReader> reader;
     reader->SetFileName(filename.c_str());
     reader->Update();
-
     source = triangulate::buildValidTriangulation(reader->GetOutput());
   }
   else
diff --git a/triangulate.cpp b/triangulate.cpp
new file mode 100644
index 0000000..d985f36
--- /dev/null
+++ b/triangulate.cpp
@@ -0,0 +1,34 @@
+#include <vtkTriangleFilter.h>
+#include "triangulate.h"
+
+vtkSmartPointer<vtkPolyData> triangulate::buildValidTriangulation(vtkSmartPointer<vtkPolyData> polyData)
+{
+    vtkSmartPointer<vtkPolyData> triPolyData = vtkSmartPointer<vtkPolyData>::New();
+
+    // if mesh is composed of quads, builds a valid triangulation
+    if (polyData->GetMaxCellSize() == 4)
+    {
+        // we're using a vtkQuadToTriangle filter to convert quads in triangles
+        vtkSmartPointer<vtkTriangleFilter> quadToTri = vtkSmartPointer<vtkTriangleFilter>::New();
+        quadToTri->SetInputData(polyData);
+        quadToTri->Update();
+
+        triPolyData = quadToTri->GetOutput();
+    }
+    else if (polyData->GetMaxCellSize() == 3) // if mesh is already triangulated, return origin's vtkPolyData
+    {
+        triPolyData = polyData;
+    }
+    else
+    {
+        std::cout << "This mesh is not handled by this program, allows only triangulated and quadrilated meshes.\n";
+        std::cout << "Maximum cell size for this mesh: " << polyData->GetMaxCellSize() << ".\n";
+        exit(0);
+    }
+    // adding a vtkTriangleFilter to ensure that the output is a well triangulated mesh
+    vtkSmartPointer<vtkTriangleFilter> triangleFilter = vtkSmartPointer<vtkTriangleFilter>::New();
+    triangleFilter->SetInputData(triPolyData);
+    triangleFilter->Update();
+
+    return triangleFilter->GetOutput();
+}
\ No newline at end of file
diff --git a/triangulate.h b/triangulate.h
new file mode 100644
index 0000000..f873fbf
--- /dev/null
+++ b/triangulate.h
@@ -0,0 +1,23 @@
+/**
+ * @class     triangulate
+ *
+ * @author   Astrid BEYER
+ * @date     2023
+ * @version  1.1
+ *
+ */
+
+#ifndef TRIANGULATE_H
+#define TRIANGULATE_H
+
+namespace triangulate
+{
+    /**
+     * @brief buildValidTriangulation : transforms, if necessary, input's polyData so it ensure it's triangulated
+     * @param polyData
+     * @returns vtkSmartPointer<vtkPolyData>
+     */
+    vtkSmartPointer<vtkPolyData> buildValidTriangulation(vtkSmartPointer<vtkPolyData> polyData);
+}
+
+#endif
-- 
GitLab