document new global IO functions

This commit is contained in:
Maxime Gimeno 2020-05-07 15:40:01 +02:00
parent ece2c67a89
commit ab86d0cc6c
7 changed files with 207 additions and 113 deletions

View File

@ -1,4 +1,3 @@
namespace CGAL {

View File

@ -0,0 +1,62 @@
namespace CGAL{
/*!
* \ingroup PkgBGLIOFct
* \brief reads a polygon mesh from a file.
* \tparam FaceGraph a model of `FaceGraph`
* \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters"
*
* \param fname the name of the file. Its extension must be one of the following :
* `.off` (\ref IOStreamOFF "OFF file format") , `.obj` (\ref IOStreamOBJ "OBJ file format"),
* `.stl` (\ref IOStreamSTL "STL file format"), `.ply` (\ref IOStreamPLY "PLY file format"),
* `.vtp`(\ref IOStreamVTK "VTP file format") or `.ts`(\ref IOStreamGocad "GOCAD file format").
* \param g the mesh
* \param np optional \ref pmp_namedparameters "Named Parameters" described below
*
* \cgalNamedParamsBegin
* \cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `g`.
* If this parameter is omitted, an internal property map for
* `CGAL::vertex_point_t` should be available in `FaceGraph`\cgalParamEnd
* \cgalNamedParamsEnd
* Other named parameters may be used according to the file extension.
* See `PkgBGLIOFct` for an exhaustive list.
* \return `true` if the reading worked, `false` otherwise.
*
* \pre The data must represent a 2-manifold
* \see \ref IOStreamOFF
*
*/
template <class FaceGraph, typename NamedParameters>
bool read_polygon_mesh(const std::string& fname,
FaceGraph& g,
const NamedParameters& np);
/*!
* \ingroup PkgBGLIOFct
* \brief writes a polygon mesh in a file.
* \tparam FaceGraph a model of `FaceGraph`
* \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters"
*
* \param fname the name of the file. Its extension must be one of the following :
* `.off` (\ref IOStreamOFF "OFF file format") , `.obj` (\ref IOStreamOBJ "OBJ file format"),
* `.stl` (\ref IOStreamSTL "STL file format"), `.ply` (\ref IOStreamPLY "PLY file format"),
* `.vtp`(\ref IOStreamVTK "VTP file format") or `.ts`(\ref IOStreamGocad "GOCAD file format").
* \param g the mesh
* \param np optional \ref pmp_namedparameters "Named Parameters" described below
*
* \cgalNamedParamsBegin
* \cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `g`.
* If this parameter is omitted, an internal property map for
* `CGAL::vertex_point_t` should be available in `FaceGraph`\cgalParamEnd
* \cgalNamedParamsEnd
* Other named parameters may be used according to the file extension.
* See `PkgBGLIOFct` for an exhaustive list.
* \return `true` if the writing worked, `false` otherwise.
*
* \see \ref IOStreamOFF
*/
template <class FaceGraph, typename NamedParameters>
bool write_polygon_mesh(const std::string& fname,
FaceGraph& g,
const NamedParameters& np);
}

View File

@ -26,6 +26,7 @@
// @todo reintroduce deprecated versions of the functions using lower case file formats
//documentation in doc/ directory
namespace CGAL {
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -79,64 +80,13 @@ bool read_OFF_BGL(std::istream& in,
} // namespace internal
} // namespace IO
/*!
\ingroup PkgBGLIOFct
reads the graph `g` from data in the OFF format. Ignores comment lines which start with a hash,
and lines with whitespace.
\cgalNamedParamsBegin
\cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `g`.
If this parameter is omitted, an internal property map for
`CGAL::vertex_point_t` should be available in `FaceGraph`\cgalParamEnd
\cgalParamBegin{vertex_normal_map} the property map with the normals associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{vertex_color_map} the property map with the colors associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{vertex_texture_map} the property map with the textures associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{face_color_map} the property map with the colors associated to the faces of `g`.\cgalParamEnd
\cgalNamedParamsEnd
\pre The data must represent a 2-manifold
\sa Overloads of this function for specific models of the concept `FaceGraph`.
\see \ref IOStreamOFF
*/
template <typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool read_OFF(std::istream& in, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, bool verbose = true)
{
return IO::internal::read_OFF_BGL(in, g, np, verbose);
}
/*!
\ingroup PkgBGLIOFct
reads the graph `g` from `fname`, a file in the OFF format. Ignores comment lines which start with a hash,
and lines with whitespace.
\cgalNamedParamsBegin
\cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `g`.
If this parameter is omitted, an internal property map for
`CGAL::vertex_point_t` should be available in `FaceGraph`\cgalParamEnd
\cgalParamBegin{vertex_normal_map} the property map with the normals associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{vertex_color_map} the property map with the colors associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{vertex_texture_map} the property map with the textures associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{face_color_map} the property map with the colors associated to the faces of `g`.\cgalParamEnd
\cgalNamedParamsEnd
\pre The data must represent a 2-manifold
\sa Overloads of this function for specific models of the concept `FaceGraph`.
\see \ref IOStreamOFF
*/
template <typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool read_OFF(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np,
bool verbose = true)
@ -184,58 +134,13 @@ bool write_OFF_BGL(std::ostream& os,
} // namespace internal
} // namespace IO
/*!
\ingroup PkgBGLIOFct
writes the graph `g` in the OFF format.
\cgalNamedParamsBegin
\cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `g`.
If this parameter is omitted, an internal property map for
`CGAL::vertex_point_t` should be available in `FaceGraph`\cgalParamEnd
\cgalParamBegin{vertex_normal_map} the property map with the normals associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{vertex_color_map} the property map with the colors associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{vertex_texture_map} the property map with the textures associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{face_color_map} the property map with the colors associated to the faces of `g`.\cgalParamEnd
\cgalNamedParamsEnd
\sa Overloads of this function for specific models of the concept `FaceGraph`.
\see \ref IOStreamOFF
*/
template <typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(std::ostream& os, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np)
{
return IO::internal::write_OFF_BGL(os, g, np);
}
/*!
\ingroup PkgBGLIOFct
writes the graph `g` in the file `fname`, in the OFF format.
\cgalNamedParamsBegin
\cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `g`.
If this parameter is omitted, an internal property map for
`CGAL::vertex_point_t` should be available in `FaceGraph`\cgalParamEnd
\cgalParamBegin{vertex_normal_map} the property map with the normals associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{vertex_color_map} the property map with the colors associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{vertex_texture_map} the property map with the textures associated to the vertices of `g`.\cgalParamEnd
\cgalParamBegin{face_color_map} the property map with the colors associated to the faces of `g`.\cgalParamEnd
\cgalNamedParamsEnd
\sa Overloads of this function for specific models of the concept `FaceGraph`.
\see \ref IOStreamOFF
*/
template <typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(const char* fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np)
{

View File

@ -381,7 +381,7 @@ void write_polys_points(std::ostream& os,
* \see \ref IOStreamVTK
*/
template<typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
void write_VTP(std::ostream& os,
bool write_VTP(std::ostream& os,
const FaceGraph& g,
const CGAL_BGL_NP_CLASS& np)
{
@ -401,7 +401,7 @@ void write_VTP(std::ostream& os,
{
case 4: os << " header_type=\"UInt32\""; break;
case 8: os << " header_type=\"UInt64\""; break;
default: CGAL_error_msg("Unknown size of std::size_t");
default: CGAL_error_msg("Unknown size of std::size_t"); return false;
}
os << ">\n"
@ -424,10 +424,12 @@ void write_VTP(std::ostream& os,
IO::internal::write_polys(os, g, np);
}
os << "</VTKFile>\n";
return true;
}
template<typename FaceGraph>
void write_VTP(std::ostream& os, const FaceGraph& g)
bool write_VTP(std::ostream& os, const FaceGraph& g)
{
write_VTP(os, g, CGAL::parameters::all_default());
}
@ -460,7 +462,7 @@ void write_VTP(std::ostream& os, const FaceGraph& g)
* \see \ref IOStreamVTK
*/
template<typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
void write_VTP(const char* fname,
bool write_VTP(const char* fname,
const FaceGraph& g,
const CGAL_BGL_NP_CLASS& np)
{
@ -469,14 +471,14 @@ void write_VTP(const char* fname,
}
template<typename FaceGraph>
void write_VTP(const char* fname,
bool write_VTP(const char* fname,
const FaceGraph& g)
{
return write_VTP(fname, g, parameters::all_default());
}
template<typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
void write_VTP(const std::string& fname,
bool write_VTP(const std::string& fname,
const FaceGraph& g,
const CGAL_BGL_NP_CLASS& np)
{
@ -484,7 +486,7 @@ void write_VTP(const std::string& fname,
}
template<typename FaceGraph>
void write_VTP(const std::string& fname,
bool write_VTP(const std::string& fname,
const FaceGraph& g)
{
return write_VTP(fname, g, parameters::all_default());

View File

@ -11,6 +11,9 @@
#define CGAL_BOOST_GRAPH_POLYGON_MESH_IO_H
#include <CGAL/boost/graph/io.h>
//doc in doc/
namespace CGAL{
//not for now.
@ -56,17 +59,13 @@ bool read_polygon_mesh(std::istream& is,
return read_polygon_mesh(is, g, parameters::all_default());
}
*/
/*!
*
*/
template <class FaceGraph, typename NamedParameters>
bool read_polygon_mesh(const std::string& fname,
FaceGraph& g,
const NamedParameters& np)
{
if (fname.find(".TS") != std::string::npos) {
return read_GOCAD(fname, g, np);
}
if (fname.find(".obj") != std::string::npos) {
return read_OBJ(fname, g, np);
@ -88,6 +87,9 @@ bool read_polygon_mesh(const std::string& fname,
return read_VTP(fname, g, np);
}
if (fname.find(".ts") != std::string::npos) {
return read_GOCAD(fname, g, np);
}
return false;
}
@ -116,6 +118,61 @@ bool read_polygon_mesh(const char* fname,
}
template <class FaceGraph, typename NamedParameters>
bool write_polygon_mesh(const std::string& fname,
FaceGraph& g,
const NamedParameters& np)
{
if (fname.find(".ts") != std::string::npos) {
return write_GOCAD(fname, g, np);
}
if (fname.find(".obj") != std::string::npos) {
return write_OBJ(fname, g, np);
}
if (fname.find(".off") != std::string::npos) {
return write_OFF(fname, g, np);
}
if (fname.find(".ply") != std::string::npos) {
return write_PLY(fname, g, np);
}
if (fname.find(".stl") != std::string::npos) {
return write_STL(fname, g, np);
}
if (fname.find(".vtp") != std::string::npos) {
return write_VTP(fname, g, np);
}
return false;
}
template <class FaceGraph>
bool write_polygon_mesh(const std::string& fname,
FaceGraph& g)
{
return write_polygon_mesh(fname, g, parameters::all_default());
}
template <class FaceGraph, typename NamedParameters>
bool write_polygon_mesh(const char* fname,
FaceGraph& g,
const NamedParameters& np)
{
return write_polygon_mesh(std::string(fname), g, np);
}
template <class FaceGraph>
bool write_polygon_mesh(const char* fname,
FaceGraph& g)
{
return write_polygon_mesh(fname, g, parameters::all_default());
}
}//end CGAL
#endif // CGAL_BOOST_GRAPH_POLYGON_MESH_IO_H

View File

@ -93,6 +93,29 @@ void test_polygon_soup_io()
}
}
template<class Mesh>
void test_polygon_mesh_io()
{
Mesh fg;
CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0),
Point(2, 0, 1), Point(3, 0, 0), fg);
std::string filenames[6] = {"mesh.obj", "mesh.off", "mesh.stl", "mesh.ts", "mesh.ply", "mesh.vtp"};
for(const std::string& name : filenames)
{
CGAL_assertion(CGAL::write_polygon_mesh(name, fg));
}
for(const std::string& name : filenames)
{
fg.clear();
CGAL_assertion(CGAL::read_polygon_mesh(name, fg));
CGAL_assertion(num_vertices(fg) == 4);
CGAL_assertion(num_faces(fg) == 4);
}
}
template<typename Mesh>
void test_bgl_OFF(const char* filename)
{
@ -443,7 +466,7 @@ bool test_soup_gocad()
poly[2] = 2;
polys[3] = poly;
std::ofstream os("tetrahedron.TS");
std::ofstream os("tetrahedron.ts");
CGAL::write_GOCAD(os, points, polys);
if(!os)
{
@ -455,7 +478,7 @@ bool test_soup_gocad()
std::vector<Point> soup_points;
std::vector<std::vector<std::size_t> > soup_polygons;
CGAL::read_GOCAD("tetrahedron.TS", soup_points, soup_polygons);
CGAL::read_GOCAD("tetrahedron.ts", soup_points, soup_polygons);
if(4 != soup_points.size()
|| 4 != soup_polygons.size())
{
@ -597,10 +620,13 @@ bool test_bgl_PLY_with_np(bool binary)
return true;
}
//todo: doc the global functions
int main(int argc, char** argv)
{
test_polygon_soup_io();
test_polygon_mesh_io<Polyhedron>();
test_polygon_mesh_io<SM>();
test_polygon_mesh_io<LCC>();
const char* filename=(argc>1) ? argv[1] : "data/prim.off";
// OFF
test_bgl_OFF<Polyhedron>(filename);

View File

@ -33,6 +33,27 @@
namespace CGAL {
/*!
* \ingroup IOstreamFunctions
* \brief reads a polygon soup from a file.
* \tparam PolygonRange a model of the concept `RandomAccessContainer`
* whose value_type is a model of the concept `RandomAccessContainer`
* whose value_type is `std::size_t`.
* \tparam PointRange a model of the concept `RandomAccessContainer`
* whose value type is the point type
*
* \param filename the name of the file. Its extension must be one of the following :
* `.off` (\ref IOStreamOFF "OFF file format") , `.obj` (\ref IOStreamOBJ "OBJ file format"),
* `.stl` (\ref IOStreamSTL "STL file format"), `.ply` (\ref IOStreamPLY "PLY file format")
* or `.ts`(\ref IOStreamGocad "GOCAD file format").
* \param polygons each element in the range describes a polygon
* using the indices of the vertices.
* \param points points of the soup of polygons
* \return `true` if the reading worked, `false` otherwise.
*
* \see \ref IOStreamOFF
*/
template <typename PointRange, typename PolygonRange>
bool read_polygon_soup(const std::string& filename,
PointRange& points,
@ -62,6 +83,28 @@ bool read_polygon_soup(const std::string& filename,
return false;
}
/*!
* \ingroup IOstreamFunctions
* \brief writes a polygon soup in a file.
* \tparam PolygonRange a model of the concept `RandomAccessContainer`
* whose value_type is a model of the concept `RandomAccessContainer`
* whose value_type is `std::size_t`.
* \tparam PointRange a model of the concept `RandomAccessContainer`
* whose value type is the point type
*
* \param filename the name of the file. Its extension must be one of the following :
* `.off` (\ref IOStreamOFF "OFF file format") , `.obj` (\ref IOStreamOBJ "OBJ file format"),
* `.stl` (\ref IOStreamSTL "STL file format"), `.ply` (\ref IOStreamPLY "PLY file format")
* or `.ts`(\ref IOStreamGocad "GOCAD file format").
* \param polygons each element in the range describes a polygon
* using the indices of the vertices.
* \param points points of the soup of polygons
* \return `true` if the writing worked, `false` otherwise.
*
* \see \ref IOStreamOFF
*/
template <typename PointRange, typename PolygonRange>
bool write_polygon_soup(const std::string& filename,
const PointRange& points,