mirror of https://github.com/CGAL/cgal
Fix PMP IO + doc
This commit is contained in:
parent
33e1329101
commit
0790dc623d
|
|
@ -98,6 +98,8 @@ bool read_polygon_mesh(std::istream& is,
|
||||||
* \pre The data must represent a 2-manifold
|
* \pre The data must represent a 2-manifold
|
||||||
*
|
*
|
||||||
* \return `true` if reading was successful, `false` otherwise.
|
* \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 <class Graph, typename NamedParameters>
|
template <class Graph, typename NamedParameters>
|
||||||
bool read_polygon_mesh(const std::string& fname,
|
bool read_polygon_mesh(const std::string& fname,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@
|
||||||
///
|
///
|
||||||
/// \ingroup PkgPolygonMeshProcessingRef
|
/// \ingroup PkgPolygonMeshProcessingRef
|
||||||
|
|
||||||
|
|
||||||
/// \defgroup hole_filling_grp Hole Filling
|
/// \defgroup hole_filling_grp Hole Filling
|
||||||
/// Functions to fill holes given as a range of halfedges or as range of points.
|
/// Functions to fill holes given as a range of halfedges or as range of points.
|
||||||
/// \ingroup PkgPolygonMeshProcessingRef
|
/// \ingroup PkgPolygonMeshProcessingRef
|
||||||
|
|
@ -39,7 +38,6 @@
|
||||||
/// Functions to repair polygon soups and polygon meshes.
|
/// Functions to repair polygon soups and polygon meshes.
|
||||||
/// \ingroup PkgPolygonMeshProcessingRef
|
/// \ingroup PkgPolygonMeshProcessingRef
|
||||||
|
|
||||||
|
|
||||||
/// \defgroup PMP_distance_grp Distance Functions
|
/// \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.
|
/// Functions to compute the distance between meshes, between a mesh and a point set and between a point set and a mesh.
|
||||||
/// \ingroup PkgPolygonMeshProcessingRef
|
/// \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::border_halfedges()`
|
||||||
- `CGAL::Polygon_mesh_processing::extract_boundary_cycles()`
|
- `CGAL::Polygon_mesh_processing::extract_boundary_cycles()`
|
||||||
- `CGAL::Polygon_mesh_processing::transform()`
|
- `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
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ Circulator
|
||||||
Generator
|
Generator
|
||||||
Kernel_23
|
Kernel_23
|
||||||
Property_map
|
Property_map
|
||||||
|
Polygon_mesh_processing
|
||||||
Polyhedron
|
Polyhedron
|
||||||
Solver_interface
|
Solver_interface
|
||||||
Spatial_sorting
|
Spatial_sorting
|
||||||
|
|
|
||||||
|
|
@ -8,21 +8,23 @@
|
||||||
//
|
//
|
||||||
// $URL$
|
// $URL$
|
||||||
// $Id$
|
// $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é
|
// Author(s) : Mael Rouxel-Labbé
|
||||||
|
|
||||||
#ifndef CGAL_PMP_IO_POLYGON_MESH_IO_H
|
#ifndef CGAL_PMP_IO_POLYGON_MESH_IO_H
|
||||||
#define CGAL_PMP_IO_POLYGON_MESH_IO_H
|
#define CGAL_PMP_IO_POLYGON_MESH_IO_H
|
||||||
|
|
||||||
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h>
|
#include <CGAL/license/Polygon_mesh_processing.h>
|
||||||
|
|
||||||
#include <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
|
#include <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
|
||||||
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
|
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
|
||||||
|
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h>
|
||||||
|
|
||||||
#include <CGAL/IO/polygon_soup_io.h>
|
|
||||||
#include <CGAL/boost/graph/IO/polygon_mesh_io.h>
|
#include <CGAL/boost/graph/IO/polygon_mesh_io.h>
|
||||||
#include <CGAL/boost/graph/Named_function_parameters.h>
|
#include <CGAL/boost/graph/Named_function_parameters.h>
|
||||||
#include <CGAL/boost/graph/named_params_helper.h>
|
#include <CGAL/boost/graph/named_params_helper.h>
|
||||||
|
#include <CGAL/IO/polygon_soup_io.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
@ -31,88 +33,126 @@
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
namespace Polygon_mesh_processing {
|
namespace Polygon_mesh_processing {
|
||||||
namespace IO {
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\ingroup PMP_IO_grp
|
\ingroup PMP_IO_grp
|
||||||
|
|
||||||
* \brief read a file as a polygon soup, and then repair and orient it before trying to convert it
|
* \brief Attempts to read a file as a polygon mesh; in case of failure, reads the file as a polygon soup,
|
||||||
* into a `FaceGraph`.
|
* repairs and orients it to obtain a polygon mesh.
|
||||||
* \param fname the name of the input file.
|
*
|
||||||
* \param g the FaceGraph.
|
* \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
|
* \param np sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
|
||||||
*
|
*
|
||||||
* \cgalNamedParamsBegin
|
* \cgalNamedParamsBegin
|
||||||
* \cgalParamBegin{vertex_point_map}
|
* \cgalParamNBegin{repair_polygon_soup}
|
||||||
* a model of `WritablePropertyMap`, the property map with the points associated to the vertices of `out`.
|
* \cgalParamDescription{a parameter used indicate whether `CGAL::Polygon_mesh_processing::repair_polygon_soup()`
|
||||||
* If this parameter is omitted, an internal property map for
|
* should be called on the soup in case of issues in the input.}
|
||||||
* `CGAL::vertex_point_t` must be available in `PolygonMesh`.
|
* \cgalParamType{Boolean}
|
||||||
* \cgalParamEnd
|
* \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<Graph>::%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
|
* \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.
|
* \return `true` if the reading and conversion worked, `false` otherwise.
|
||||||
*/
|
*/
|
||||||
template <typename FaceGraph, typename NamedParameter>
|
template <typename Graph, typename NamedParameter>
|
||||||
bool read_polygon_mesh(const char* fname,
|
bool read_polygon_mesh(const char* fname,
|
||||||
FaceGraph& g,
|
Graph& g,
|
||||||
const NamedParameter& np)
|
const NamedParameter& np)
|
||||||
{
|
{
|
||||||
typedef typename CGAL::GetVertexPointMap<FaceGraph, NamedParameter>::type VPM;
|
namespace PMP = CGAL::Polygon_mesh_processing;
|
||||||
|
|
||||||
|
typedef typename CGAL::GetVertexPointMap<Graph, NamedParameter>::type VPM;
|
||||||
typedef typename boost::property_traits<VPM>::value_type Point;
|
typedef typename boost::property_traits<VPM>::value_type Point;
|
||||||
|
|
||||||
using parameters::choose_parameter;
|
using parameters::choose_parameter;
|
||||||
using parameters::get_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<Point> points;
|
||||||
|
std::vector<std::vector<std::size_t> > faces;
|
||||||
|
if(!CGAL::read_polygon_soup(fname, points, faces))
|
||||||
{
|
{
|
||||||
std::vector<Point> points;
|
std::cerr << "Error: cannot read file\n";
|
||||||
std::vector<std::vector<std::size_t> > faces;
|
return false;
|
||||||
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::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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FaceGraph>
|
template <typename Graph>
|
||||||
bool read_polygon_mesh(const char* fname, FaceGraph& g)
|
bool read_polygon_mesh(const char* fname, Graph& g)
|
||||||
{
|
{
|
||||||
return CGAL::Polygon_mesh_processing::IO::read_polygon_mesh(fname, g, parameters::all_default());
|
return CGAL::Polygon_mesh_processing::IO::read_polygon_mesh(fname, g, parameters::all_default());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FaceGraph, typename NamedParameter>
|
template <typename Graph, typename NamedParameter>
|
||||||
bool read_polygon_mesh(const std::string& fname,
|
bool read_polygon_mesh(const std::string& fname, Graph& g, const NamedParameter& np)
|
||||||
FaceGraph& g,
|
|
||||||
const NamedParameter& np)
|
|
||||||
{
|
{
|
||||||
return CGAL::Polygon_mesh_processing::IO::read_polygon_mesh(fname.c_str(), g, np);
|
return CGAL::Polygon_mesh_processing::IO::read_polygon_mesh(fname.c_str(), g, np);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FaceGraph>
|
template <typename Graph>
|
||||||
bool read_polygon_mesh(const std::string& fname, FaceGraph& g)
|
bool read_polygon_mesh(const std::string& fname, Graph& g)
|
||||||
{
|
{
|
||||||
return CGAL::Polygon_mesh_processing::IO::read_polygon_mesh(fname, g, parameters::all_default());
|
return CGAL::Polygon_mesh_processing::IO::read_polygon_mesh(fname, g, parameters::all_default());
|
||||||
}
|
}
|
||||||
} // namespace IO
|
|
||||||
} // namespace Polygon_mesh_processing
|
} // namespace Polygon_mesh_processing
|
||||||
} // namespace CGAL
|
} // namespace CGAL
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1055,7 +1055,7 @@ std::size_t merge_duplicate_polygons_in_polygon_soup(PointRange& points,
|
||||||
/// \cgalParamNBegin{geom_traits}
|
/// \cgalParamNBegin{geom_traits}
|
||||||
/// \cgalParamDescription{an instance of a geometric traits class}
|
/// \cgalParamDescription{an instance of a geometric traits class}
|
||||||
/// \cgalParamType{The traits class must provide the nested functors `Less_xyz_3` and `Equal_3`
|
/// \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.}
|
/// 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`}
|
/// \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.}
|
/// \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue