ad simple visualization
This commit is contained in:
@@ -1,31 +1,38 @@
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Surface_mesh.h>
|
||||
#include <CGAL/IO/polygon_mesh_io.h>
|
||||
#include "simple_visualize.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[])
|
||||
{
|
||||
|
||||
|
||||
|
||||
bool parse_arguments(int argc, char* argv[], std::string& input_file, std::string& output_file, bool& show, bool& verbose) {
|
||||
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);
|
||||
app.add_flag("-s,--show", show, "Show the input mesh in a viewer");
|
||||
app.add_flag("-v,--verbose",verbose, "Enable verbose output");
|
||||
app.set_help_flag("-h,--help", "Show this help message and exit");
|
||||
|
||||
try {
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
} catch (const CLI::ParseError &e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
if (input_file.empty()) {
|
||||
std::cerr << "Input file is required.\n";
|
||||
@@ -36,6 +43,28 @@ int main(int argc, char* argv[])
|
||||
std::cerr << "Unsupported file format. Please provide an OFF file.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::string input_file;
|
||||
std::string output_file;
|
||||
bool show = false;
|
||||
bool verbose = false;
|
||||
|
||||
if(!parse_arguments(argc, argv, input_file, output_file, show, verbose)) {
|
||||
std::cerr << "Failed to parse arguments.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
std::cout << "Input file: " << input_file << "\n";
|
||||
std::cout << "Output file: " << output_file << "\n";
|
||||
std::cout << "Show mesh: " << (show ? "Yes" : "No") << "\n";
|
||||
std::cout << "Verbose: " << (verbose ? "Yes" : "No") << "\n";
|
||||
|
||||
Mesh surface_mesh;
|
||||
if (!CGAL::IO::read_polygon_mesh(input_file, surface_mesh) || surface_mesh.is_empty()) {
|
||||
@@ -52,36 +81,9 @@ int main(int argc, char* argv[])
|
||||
|
||||
|
||||
// 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();
|
||||
|
||||
|
||||
if(show){
|
||||
mesh_utils::simple_visualize_mesh<Kernel>(surface_mesh,true);
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
|
||||
Reference in New Issue
Block a user