This commit is contained in:
Tarik Moussa
2026-03-04 14:00:58 +02:00
committed by Tarik Moussa
parent 5be43c90bc
commit e1a90dbd85
9 changed files with 161 additions and 21 deletions

View File

@@ -0,0 +1,93 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/IO/polygon_mesh_io.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CLI11.hpp>
#include <iostream>
#include <string>
#include <igl/opengl/glfw/Viewer.h>
#include <Eigen/Core>
using Kernel = CGAL::Simple_cartesian<double>;
using Point = Kernel::Point_3;
using Mesh = CGAL::Surface_mesh<Point>;
namespace PMP = CGAL::Polygon_mesh_processing;
int main(int argc, char* argv[])
{
CLI::App app{"demo of conformallab"};
std::string input_file;
std::string output_file; // default output file name
app.add_option("-i,--input", input_file, "Input OFF file")->required();
app.add_option("-o,--output", output_file, "Output OFF file (optional)");
CLI11_PARSE(app, argc, argv);
if (input_file.empty()) {
std::cerr << "Input file is required.\n";
return EXIT_FAILURE;
}
if (input_file.substr(input_file.find_last_of('.') + 1) != "off") {
std::cerr << "Unsupported file format. Please provide an OFF file.\n";
return EXIT_FAILURE;
}
Mesh surface_mesh;
if (!CGAL::IO::read_polygon_mesh(input_file, surface_mesh) || surface_mesh.is_empty()) {
std::cerr << "Invalid input file: " << input_file << "\n";
return EXIT_FAILURE;
}
// #TODO: later: here we would call the unwrapping code, e.g.:
// UnwrapSettings settings;
// settings.target_geometry = TargetGeometry::Euclidean;
// UnwrapJob job(surface_mesh, settings);
// auto result = job.run();
// Mesh unwrapped = result.surface_unwrapped;
// CGAL -> libigl
PMP::triangulate_faces(surface_mesh);
//todo : we should check if the mesh is already triangulated, and only call this if it isn't, to avoid unnecessary processing. CGAL::Polygon_mesh_processing::is_triangulated() can be used for this check.
Eigen::MatrixXd Vertices;
Eigen::MatrixXi Faces;
Vertices.resize(surface_mesh.number_of_vertices(), 3);
Faces.resize(surface_mesh.number_of_faces(), 3);
for (auto v : surface_mesh.vertices()) {
const auto& p = surface_mesh.point(v);
Vertices(v.idx(), 0) = p.x();
Vertices(v.idx(), 1) = p.y();
Vertices(v.idx(), 2) = p.z();
}
int f_i = 0;
for (auto f : surface_mesh.faces()) {
int k = 0;
for (auto hv : CGAL::halfedges_around_face(surface_mesh.halfedge(f), surface_mesh)) {
auto v = surface_mesh.target(hv);
Faces(f_i, k) = v.idx();
++k;
}
++f_i;
}
igl::opengl::glfw::Viewer viewer;
viewer.data().set_mesh(Vertices, Faces);
viewer.launch();
// for now, we just write the input mesh to the output file as a placeholder
if (!output_file.empty() && !CGAL::IO::write_polygon_mesh(output_file, surface_mesh)) {
std::cerr << "Failed to write output file: " << output_file << "\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}