From 451223a2e8611ff40dff8de074de3ad4690bd262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 18 Apr 2023 11:20:04 +0200 Subject: [PATCH 1/4] Fix not forwarding verbose NP to inner functions --- .../include/CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h index 4fe8a9deaf0..fe136bd4545 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h @@ -101,7 +101,7 @@ bool read_polygon_mesh(const std::string& fname, std::vector points; std::vector > faces; - if(!CGAL::IO::read_polygon_soup(fname, points, faces)) + if(!CGAL::IO::read_polygon_soup(fname, points, faces, CGAL::parameters::verbose(verbose))) { if(verbose) std::cerr << "Warning: cannot read polygon soup" << std::endl; From b7ca320000b92d378e9e97f28d0e41e064eee09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 18 Apr 2023 11:20:49 +0200 Subject: [PATCH 2/4] Fix null char reading and backslash separated multi lines --- Stream_support/include/CGAL/IO/OBJ.h | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Stream_support/include/CGAL/IO/OBJ.h b/Stream_support/include/CGAL/IO/OBJ.h index 9cdc507e3cc..da8b51f9af6 100644 --- a/Stream_support/include/CGAL/IO/OBJ.h +++ b/Stream_support/include/CGAL/IO/OBJ.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -72,12 +73,30 @@ bool read_OBJ(std::istream& is, bool tex_found(false), norm_found(false); while(getline(is, line)) { - if(line.empty()) - continue; + // get last non-whitespace, non-null character + auto last = std::find_if(line.rbegin(), line.rend(), [](char c) { return c != '\0' && !std::isspace(c); }); + if(last == line.rend()) + continue; // line is empty or only whitespace + + // keep reading lines as long as the last non-whitespace, non-null character is a backslash + while(last != line.rend() && *last == '\\') + { + // remove everything from the backslash (included) + line = line.substr(0, line.size() - (last - line.rbegin()) - 1); + + std::string next_line; + if(!getline(is, next_line)) + break; + + line += next_line; + last = std::find_if(line.rbegin(), line.rend(), [](char c) { return c != '\0' && !std::isspace(c); }); + } + + CGAL_assertion(!line.empty()); std::istringstream iss(line); if(!(iss >> s)) - continue; // can't read anything on the line, whitespace only? + continue; if(s == "v") { From d33fc1ad075c123adaa68d583c1a79b70e147f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 18 Apr 2023 11:21:54 +0200 Subject: [PATCH 3/4] Add missing error message --- Stream_support/include/CGAL/IO/OBJ.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Stream_support/include/CGAL/IO/OBJ.h b/Stream_support/include/CGAL/IO/OBJ.h index da8b51f9af6..5d9a14e94b0 100644 --- a/Stream_support/include/CGAL/IO/OBJ.h +++ b/Stream_support/include/CGAL/IO/OBJ.h @@ -146,7 +146,11 @@ bool read_OBJ(std::istream& is, } if(iss.bad()) + { + if(verbose) + std::cerr << "error while reading OBJ face." << std::endl; return false; + } } else if(s.front() == '#') { @@ -172,15 +176,15 @@ bool read_OBJ(std::istream& is, else { if(verbose) - std::cerr << "error: unrecognized line: " << s << std::endl; + std::cerr << "Error: unrecognized line: " << s << std::endl; return false; } } if(norm_found && verbose) - std::cout<<"NOTE: normals were found in this file, but were discarded."< Date: Tue, 18 Apr 2023 12:08:39 +0200 Subject: [PATCH 4/4] Minor example improvements --- .../triangulate_faces_example.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/triangulate_faces_example.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/triangulate_faces_example.cpp index ce098ae6d4b..52982dbb923 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/triangulate_faces_example.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/triangulate_faces_example.cpp @@ -23,18 +23,32 @@ int main(int argc, char* argv[]) Surface_mesh mesh; if(!PMP::IO::read_polygon_mesh(filename, mesh)) { - std::cerr << "Invalid input." << std::endl; - return 1; + std::cerr << "Error: Invalid input." << std::endl; + return EXIT_FAILURE; } + if(is_empty(mesh)) + { + std::cerr << "Warning: empty file?" << std::endl; + return EXIT_SUCCESS; + } + + if(!CGAL::is_triangle_mesh(mesh)) + std::cout << "Input mesh is not triangulated." << std::endl; + else + std::cout << "Input mesh is triangulated." << std::endl; + PMP::triangulate_faces(mesh); // Confirm that all faces are triangles. for(boost::graph_traits::face_descriptor f : faces(mesh)) + { if(!CGAL::is_triangle(halfedge(f, mesh), mesh)) std::cerr << "Error: non-triangular face left in mesh." << std::endl; + } + CGAL::IO::write_polygon_mesh(outfilename, mesh, CGAL::parameters::stream_precision(17)); - return 0; + return EXIT_SUCCESS; }