From 0790dc623d19c29b971d68077b1839189469efbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 22 Jun 2020 19:49:35 +0200 Subject: [PATCH] Fix PMP IO + doc --- .../CGAL/boost/graph/IO/polygon_mesh_io.h | 2 + .../PackageDescription.txt | 6 +- .../doc/Polygon_mesh_processing/dependencies | 1 + .../IO/polygon_mesh_io.h | 140 +++++++++++------- .../repair_polygon_soup.h | 2 +- 5 files changed, 97 insertions(+), 54 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h b/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h index 50de6ae713d..b5672a74e9f 100644 --- a/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h +++ b/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h @@ -98,6 +98,8 @@ bool read_polygon_mesh(std::istream& is, * \pre The data must represent a 2-manifold * * \return `true` if reading was successful, `false` otherwise. + * + * \sa \link PMP_IO_grp `CGAL::Polygon_mesh_processing::read_polygon_mesh()`\endlink if the data is not 2-manifold */ template bool read_polygon_mesh(const std::string& fname, diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt index 7823b2c47a3..16a543199f9 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt @@ -10,7 +10,6 @@ /// /// \ingroup PkgPolygonMeshProcessingRef - /// \defgroup hole_filling_grp Hole Filling /// Functions to fill holes given as a range of halfedges or as range of points. /// \ingroup PkgPolygonMeshProcessingRef @@ -39,7 +38,6 @@ /// Functions to repair polygon soups and polygon meshes. /// \ingroup PkgPolygonMeshProcessingRef - /// \defgroup PMP_distance_grp Distance Functions /// Functions to compute the distance between meshes, between a mesh and a point set and between a point set and a mesh. /// \ingroup PkgPolygonMeshProcessingRef @@ -226,6 +224,8 @@ The page \ref bgl_namedparameters "Named Parameters" describes their usage. - `CGAL::Polygon_mesh_processing::border_halfedges()` - `CGAL::Polygon_mesh_processing::extract_boundary_cycles()` - `CGAL::Polygon_mesh_processing::transform()` -- \link PMP_IO_grp `CGAL::Polygon_mesh_processing::IO::read_polygon_mesh()`\endlink + +\cgalCRPSection{I/O Functions} +- \link PMP_IO_grp `CGAL::Polygon_mesh_processing::read_polygon_mesh()`\endlink */ diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/dependencies b/Polygon_mesh_processing/doc/Polygon_mesh_processing/dependencies index 7fe692df305..39d01b08ad0 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/dependencies +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/dependencies @@ -6,6 +6,7 @@ Circulator Generator Kernel_23 Property_map +Polygon_mesh_processing Polyhedron Solver_interface Spatial_sorting 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 454179e482f..016710a90eb 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 @@ -8,21 +8,23 @@ // // $URL$ // $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Mael Rouxel-Labbé #ifndef CGAL_PMP_IO_POLYGON_MESH_IO_H #define CGAL_PMP_IO_POLYGON_MESH_IO_H -#include +#include + #include #include +#include -#include #include #include #include +#include #include #include @@ -31,88 +33,126 @@ namespace CGAL { namespace Polygon_mesh_processing { -namespace IO { - /*! \ingroup PMP_IO_grp - * \brief read a file as a polygon soup, and then repair and orient it before trying to convert it - * into a `FaceGraph`. - * \param fname the name of the input file. - * \param g the FaceGraph. + * \brief Attempts to read a file as a polygon mesh; in case of failure, reads the file as a polygon soup, + * repairs and orients it to obtain a polygon mesh. + * + * \tparam Graph a model of `MutableFaceGraph` + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" + * + * \param fname the name of the input file + * \param g the graph * \param np sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin - * \cgalParamBegin{vertex_point_map} - * a model of `WritablePropertyMap`, the property map with the points associated to the vertices of `out`. - * If this parameter is omitted, an internal property map for - * `CGAL::vertex_point_t` must be available in `PolygonMesh`. - * \cgalParamEnd + * \cgalParamNBegin{repair_polygon_soup} + * \cgalParamDescription{a parameter used indicate whether `CGAL::Polygon_mesh_processing::repair_polygon_soup()` + * should be called on the soup in case of issues in the input.} + * \cgalParamType{Boolean} + * \cgalParamDefault{`true`} + * \cgalParamNEnd + * + * \cgalParamNBegin{vertex_point_map} + * \cgalParamDescription{a property map associating points to the vertices of `g`} + * \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits::%vertex_descriptor` + * as key type and `%Point_3` as value type} + * \cgalParamDefault{`boost::get(CGAL::vertex_point, g)`} + * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` + * must be available in `Graph`.} + * \cgalParamNEnd + * + * \cgalParamNBegin{geom_traits} + * \cgalParamDescription{an instance of a geometric traits class} + * \cgalParamType{The traits class must provide the nested functors `Less_xyz_3` and `Equal_3` + * to respectivelycompare lexicographically two points and to check if two points + * are identical. For each functor `Foo`, a function `Foo foo_object()` must be provided.} + * \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`} + * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} + * \cgalParamNEnd + * + * \cgalParamNBegin{erase_all_duplicates} + * \cgalParamDescription{Parameter to indicate, when multiple polygons are duplicates, + * whether all the duplicate polygons should be removed + * or if one (arbitrarily chosen) face should be kept.} + * \cgalParamType{Boolean} + * \cgalParamDefault{`false`} + * \cgalParamNEnd + * + * \cgalParamNBegin{require_same_orientation} + * \cgalParamDescription{Parameter to indicate if polygon orientation should be taken + * into account when determining whether two polygons are duplicates, + * that is, whether e.g. the triangles `0,1,2` and `0,2,1` are duplicates.} + * \cgalParamType{Boolean} + * \cgalParamDefault{`false`} + * \cgalParamNEnd * \cgalNamedParamsEnd - * `repair_polygon_soup` a boolean that decides if the soup should be repaired or not. Default is `true`; \n - * named parameters used for `CGAL::Polygon_mesh_processing::repair_polygon_soup()` can also be used with this function. * * \return `true` if the reading and conversion worked, `false` otherwise. */ -template +template bool read_polygon_mesh(const char* fname, - FaceGraph& g, + Graph& g, const NamedParameter& np) { - typedef typename CGAL::GetVertexPointMap::type VPM; + namespace PMP = CGAL::Polygon_mesh_processing; + + typedef typename CGAL::GetVertexPointMap::type VPM; typedef typename boost::property_traits::value_type Point; + using parameters::choose_parameter; using parameters::get_parameter; - bool ok = ::CGAL::read_polygon_mesh(fname, g, np); + bool ok = CGAL::read_polygon_mesh(fname, g, np); - if(!ok) + if(ok) + return true; + + std::vector points; + std::vector > faces; + if(!CGAL::read_polygon_soup(fname, points, faces)) { - std::vector points; - std::vector > faces; - if(!CGAL::read_polygon_soup(fname, points, faces)) - { - std::cerr << "Error: cannot read file\n"; - return false; - } - - std::cout << "Cleaning polygon soup..." << std::endl; - const bool do_repair = choose_parameter(get_parameter(np, internal_np::repair_polygon_soup), true); - if(do_repair) - CGAL::Polygon_mesh_processing::repair_polygon_soup(points, faces, np); - - if(!CGAL::Polygon_mesh_processing::orient_polygon_soup(points, faces)) - { - std::cerr << "W: File does not describe a polygon mesh" << std::endl; - } - - CGAL::Polygon_mesh_processing:: - polygon_soup_to_polygon_mesh(points, faces, g, parameters::all_default(), np); + std::cerr << "Error: cannot read file\n"; + return false; } + + std::cout << "Cleaning polygon soup..." << std::endl; + const bool do_repair = choose_parameter(get_parameter(np, internal_np::repair_polygon_soup), true); + if(do_repair) + PMP::repair_polygon_soup(points, faces, np); + + if(!PMP::orient_polygon_soup(points, faces)) + std::cerr << "W: File does not describe a polygon mesh" << std::endl; + + if(!PMP::is_polygon_soup_a_polygon_mesh(faces)) + return false; + + clear(g); + PMP::polygon_soup_to_polygon_mesh(points, faces, g, parameters::all_default(), np); + return true; } -template -bool read_polygon_mesh(const char* fname, FaceGraph& g) +template +bool read_polygon_mesh(const char* fname, Graph& g) { return CGAL::Polygon_mesh_processing::IO::read_polygon_mesh(fname, g, parameters::all_default()); } -template -bool read_polygon_mesh(const std::string& fname, - FaceGraph& g, - const NamedParameter& np) +template +bool read_polygon_mesh(const std::string& fname, Graph& g, const NamedParameter& np) { return CGAL::Polygon_mesh_processing::IO::read_polygon_mesh(fname.c_str(), g, np); } -template -bool read_polygon_mesh(const std::string& fname, FaceGraph& g) +template +bool read_polygon_mesh(const std::string& fname, Graph& g) { return CGAL::Polygon_mesh_processing::IO::read_polygon_mesh(fname, g, parameters::all_default()); } -} // namespace IO + } // namespace Polygon_mesh_processing } // namespace CGAL diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_polygon_soup.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_polygon_soup.h index e4b7241bba7..309f8a3a3f8 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_polygon_soup.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_polygon_soup.h @@ -1055,7 +1055,7 @@ std::size_t merge_duplicate_polygons_in_polygon_soup(PointRange& points, /// \cgalParamNBegin{geom_traits} /// \cgalParamDescription{an instance of a geometric traits class} /// \cgalParamType{The traits class must provide the nested functors `Less_xyz_3` and `Equal_3` -/// to respectivelycompare lexicographically two points and to check if 2 points +/// to respectivelycompare lexicographically two points and to check if two points /// are identical. For each functor `Foo`, a function `Foo foo_object()` must be provided.} /// \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`} /// \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.}