Commit d9e4a654 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

using read_polygon_mesh for input to support more file formats

parent d8069eae
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#include <string>
#include <sstream>

#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Mesh_triangulation_3.h>
@@ -331,15 +332,15 @@ struct Parameters
};

template< typename Polyhedron >
void readPolyhedron(Polyhedron & polyhedron, const std::string & filePath)
void readPolyhedron(Polyhedron & polyhedron, const std::string & filePath, bool verbose = true)
{
	std::ifstream input(filePath);
	input >> polyhedron;
	if (input.fail()) {
	// the function from the Polygon_mesh_processing does some repairs and orientations
	// to obtain a valid polygon mesh
	// https://doc.cgal.org/latest/Polygon_mesh_processing/group__PMP__IO__grp.html
	if (!CGAL::Polygon_mesh_processing::IO::read_polygon_mesh(filePath, polyhedron, CGAL::parameters::verbose(verbose))) {
		std::cerr << "Error: Could not read file '" <<  filePath << "'" << std::endl;
		std::exit(EXIT_FAILURE);
	}
	input.close();

	if (!CGAL::is_triangle_mesh(polyhedron)) {
		std::cout << "Input surface mesh is not triangular, calling triangulate_faces..." << std::endl;
@@ -450,7 +451,7 @@ int main(int argc, char * argv[])
	args.set_cli_options(cli);

	// positional arguments (should be generally defined after optional arguments)
	cli |= lyra::arg(input_file, "input_file")("Input file (must be in the OFF format).").required();
	cli |= lyra::arg(input_file, "input_file")("Input file (supported formats: OFF, STL, VTP, OBJ, GOCAD).").required();
	cli |= lyra::arg(output_dir, "output_dir")("Output directory." + fmt_default(output_dir));

	auto result = cli.parse({ argc, argv });