Skip to content
Snippets Groups Projects
Commit b926d1c4 authored by Astrid Beyer's avatar Astrid Beyer
Browse files

feat: gère bien le cas où un obj a besoin d'être triangulé, précise si ce n'est pas possible

parent fe98a605
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 11) ...@@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 11)
find_package(TTKVTK REQUIRED) 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 target_link_libraries(projet-stage
PUBLIC PUBLIC
......
#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
/**=========================================================================
* @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 <vtkNew.h>
#include <vtkSmartPointer.h> #include <vtkSmartPointer.h>
#include <vtkOBJReader.h> #include <vtkOBJReader.h>
...@@ -38,10 +55,11 @@ ...@@ -38,10 +55,11 @@
#include <vtkAppendPolyData.h> #include <vtkAppendPolyData.h>
#include <vtkSortDataArray.h> #include <vtkSortDataArray.h>
#include "isTriangulate.h" #include "triangulate.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
vtkObject::GlobalWarningDisplayOff();
if (argc != 2) if (argc != 2)
{ {
std::cout << "Required arguments: Filename(.obj)" << std::endl; std::cout << "Required arguments: Filename(.obj)" << std::endl;
...@@ -60,7 +78,6 @@ int main(int argc, char *argv[]) ...@@ -60,7 +78,6 @@ int main(int argc, char *argv[])
vtkNew<vtkOBJReader> reader; vtkNew<vtkOBJReader> reader;
reader->SetFileName(filename.c_str()); reader->SetFileName(filename.c_str());
reader->Update(); reader->Update();
source = triangulate::buildValidTriangulation(reader->GetOutput()); source = triangulate::buildValidTriangulation(reader->GetOutput());
} }
else else
......
#include <vtkTriangleFilter.h> #include <vtkTriangleFilter.h>
#include "isTriangulate.h" #include "triangulate.h"
// Fonction pour construire une triangulation valide à partir d'un vtkPolyData contenant des quadrilatères
vtkSmartPointer<vtkPolyData> triangulate::buildValidTriangulation(vtkSmartPointer<vtkPolyData> polyData) vtkSmartPointer<vtkPolyData> triangulate::buildValidTriangulation(vtkSmartPointer<vtkPolyData> polyData)
{ {
vtkSmartPointer<vtkPolyData> triPolyData = vtkSmartPointer<vtkPolyData>::New(); vtkSmartPointer<vtkPolyData> triPolyData = vtkSmartPointer<vtkPolyData>::New();
// Si le maillage en entrée est composé de quadrilatères, on construit une triangulation valide // if mesh is composed of quads, builds a valid triangulation
if (polyData->GetMaxCellSize() > 3) if (polyData->GetMaxCellSize() == 4)
{ {
std::cout << "maillage composé de quads"; // we're using a vtkQuadToTriangle filter to convert quads in triangles
// On utilise un filtre vtkQuadToTriangle pour convertir les quadrilatères en triangles
vtkSmartPointer<vtkTriangleFilter> quadToTri = vtkSmartPointer<vtkTriangleFilter>::New(); vtkSmartPointer<vtkTriangleFilter> quadToTri = vtkSmartPointer<vtkTriangleFilter>::New();
quadToTri->SetInputData(polyData); quadToTri->SetInputData(polyData);
quadToTri->Update(); quadToTri->Update();
triPolyData = quadToTri->GetOutput(); triPolyData = quadToTri->GetOutput();
} }
else if (polyData->GetMaxCellSize() == 3) // Si le maillage en entrée est déjà triangulé, on renvoie le vtkPolyData d'origine else if (polyData->GetMaxCellSize() == 3) // if mesh is already triangulated, return origin's vtkPolyData
{ {
triPolyData = polyData; triPolyData = polyData;
} }
else else
{ {
std::cout << "Ce maillage n'est pas géré par ce programme, sont acceptés les maillages triangulés et quadrilatérisés"; 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
// On ajoute un filtre vtkTriangleFilter pour garantir que la sortie est bien un maillage triangulé
vtkSmartPointer<vtkTriangleFilter> triangleFilter = vtkSmartPointer<vtkTriangleFilter>::New(); vtkSmartPointer<vtkTriangleFilter> triangleFilter = vtkSmartPointer<vtkTriangleFilter>::New();
triangleFilter->SetInputData(triPolyData); triangleFilter->SetInputData(triPolyData);
triangleFilter->Update(); triangleFilter->Update();
......
/**
* @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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment