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 b09ae4f1229..f2777aa5b1b 100644 --- a/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h +++ b/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h @@ -105,6 +105,13 @@ bool read_polygon_mesh(std::istream& is, * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` * must be available in `Graph`.} * \cgalParamNEnd + * + * \cgalParamNBegin{use_binary_mode} + * \cgalParamDescription{indicates whether data should be read in binary (`true`) or in ASCII (`false`)} + * \cgalParamType{Boolean} + * \cgalParamDefault{`true`} + * \cgalParamExtra{This applies only the \ref IOStreamPLY file format. } + * \cgalParamNEnd * \cgalNamedParamsEnd * * Other named parameters may be used according to the file extension, see \ref PkgBGLIOFct for an exhaustive list. @@ -197,6 +204,13 @@ bool read_polygon_mesh(const char* fname, Graph& g) * \param np optional \ref bgl_namedparameters "Named Parameters" described below * * \cgalNamedParamsBegin + * \cgalParamNBegin{use_binary_mode} + * \cgalParamDescription{indicates whether data should be written in binary (`true`) or in ASCII (`false`)} + * \cgalParamType{Boolean} + * \cgalParamDefault{`true`} + * \cgalParamExtra{This applies only the \ref IOStreamPLY file format. } + * \cgalParamNEnd + * * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `g`} * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` diff --git a/Stream_support/include/CGAL/IO/GOCAD.h b/Stream_support/include/CGAL/IO/GOCAD.h index aadfb8e2329..d7789b81249 100644 --- a/Stream_support/include/CGAL/IO/GOCAD.h +++ b/Stream_support/include/CGAL/IO/GOCAD.h @@ -300,6 +300,33 @@ bool write_GOCAD(std::ostream& os, } // namespace internal } // namespace IO +/*! + * \ingroup PkgStreamSupportIoFuncsGOCAD + * + * \brief writes the content of `points` and `polygons` in `os`, using the \ref IOStreamGocad. + * + * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is the point type. + * \tparam PolygonRange a model of the concept `SequenceContainer` + * whose value_type is itself a model of the concept `SequenceContainer` + * whose value_type is an integer type. + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" + * + * \param os the output stream + * \param points points of the soup of polygons. + * \param polygons a `PolygonRange`. Each element in it describes a polygon + * using the indices of the points in `points`. + * \param np optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{stream_precision} + * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + * \cgalParamType{int} + * \cgalParamDefault{`6`} + * \cgalParamNEnd + * \cgalNamedParamsEnd + * + * \return `true` if the writing was successful, `false` otherwise. +*/ template @@ -311,35 +338,6 @@ bool write_GOCAD(std::ostream& os, return IO::internal::write_GOCAD(os, "anonymous", points, polygons, np); } -template -bool write_GOCAD(const char* fname, - const PointRange& points, - const PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np) -{ - std::ofstream os(fname); - return IO::internal::write_GOCAD(os, fname, points, polygons, np); -} - -/*! - * \ingroup PkgStreamSupportIoFuncsGOCAD - * - * \brief writes the content of `points` and `polygons` in `os`, using the \ref IOStreamGocad. - * - * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is the point type. - * \tparam PolygonRange a model of the concept `SequenceContainer` - * whose value_type is itself a model of the concept `SequenceContainer` - * whose value_type is an integer type. - * - * \param os the output stream - * \param points points of the soup of polygons. - * \param polygons a `PolygonRange`. Each element in it describes a polygon - * using the indices of the points in `points`. - * - * \return `true` if the writing was successful, `false` otherwise. -*/ template bool write_GOCAD(std::ostream& os, const PointRange& points, const PolygonRange& polygons) { @@ -355,14 +353,36 @@ bool write_GOCAD(std::ostream& os, const PointRange& points, const PolygonRange& * \tparam PolygonRange a model of the concept `SequenceContainer` * whose value_type is itself a model of the concept `SequenceContainer` * whose value_type is an integer type. + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" * * \param fname the path to the output file * \param points points of the soup of polygons. * \param polygons a `PolygonRange`. Each element in it describes a polygon * using the indices of the points in `points`. + * \param np optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{stream_precision} + * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + * \cgalParamType{int} + * \cgalParamDefault{`6`} + * \cgalParamNEnd + * \cgalNamedParamsEnd * * \return `true` if the writing was successful, `false` otherwise. */ +template +bool write_GOCAD(const char* fname, + const PointRange& points, + const PolygonRange& polygons, + const CGAL_BGL_NP_CLASS& np) +{ + std::ofstream os(fname); + return IO::internal::write_GOCAD(os, fname, points, polygons, np); +} + template bool write_GOCAD(const char* fname, const PointRange& points, const PolygonRange& polygons) { @@ -377,14 +397,13 @@ bool write_GOCAD(const std::string& fname, const PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) { - std::ofstream os(fname.c_str()); - return IO::internal::write_GOCAD(os, fname.c_str(), points, polygons, np); + return IO::internal::write_GOCAD(fname.c_str(), fname.c_str(), points, polygons, np); } template bool write_GOCAD(const std::string& fname, const PointRange& points, const PolygonRange& polygons) { - return write_GOCAD(fname, points, polygons, parameters::all_default()); + return write_GOCAD(fname.c_str(), points, polygons, parameters::all_default()); } } // namespace CGAL diff --git a/Stream_support/include/CGAL/IO/OBJ.h b/Stream_support/include/CGAL/IO/OBJ.h index 5a5fa2ff92d..244849b496a 100644 --- a/Stream_support/include/CGAL/IO/OBJ.h +++ b/Stream_support/include/CGAL/IO/OBJ.h @@ -259,6 +259,33 @@ bool read_OBJ(const std::string& fname, PointRange& points, PolygonRange& polygo //////////////////////////////////////////////////////////////////////////////////////////////////// // Write +/*! + * \ingroup PkgStreamSupportIoFuncsOBJ + * + * \brief writes the content of `points` and `polygons` in `os`, using the \ref IOStreamOBJ. + * + * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is the point type. + * \tparam PolygonRange a model of the concept `SequenceContainer` + * whose value_type is itself a model of the concept `SequenceContainer` + * whose value_type is an integer type. + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" + * + * \param os the output stream + * \param points points of the soup of polygons. + * \param polygons a `PolygonRange`. Each element in it describes a polygon + * using the indices of the points in `points`. + * \param np optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{stream_precision} + * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + * \cgalParamType{int} + * \cgalParamDefault{`6`} + * \cgalParamNEnd + * \cgalNamedParamsEnd + * + * \return `true` if the writing was successful, `false` otherwise. + */ template @@ -272,42 +299,6 @@ bool write_OBJ(std::ostream& os, return writer(points, polygons, np); } -template -bool write_OBJ(const char* fname, const PointRange& points, const PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np) -{ - std::ofstream out(fname); - return write_OBJ(out, points, polygons, np); -} - -template -bool write_OBJ(const std::string& fname, const PointRange& points, const PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np) -{ - return write_OBJ(fname.c_str(), points, polygons, np); -} - -/*! - * \ingroup PkgStreamSupportIoFuncsOBJ - * - * \brief writes the content of `points` and `polygons` in `os`, using the \ref IOStreamOBJ. - * - * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is the point type. - * \tparam PolygonRange a model of the concept `SequenceContainer` - * whose value_type is itself a model of the concept `SequenceContainer` - * whose value_type is an integer type. - * - * \param os the output stream - * \param points points of the soup of polygons. - * \param polygons a `PolygonRange`. Each element in it describes a polygon - * using the indices of the points in `points`. - * - * \return `true` if the writing was successful, `false` otherwise. - */ template bool write_OBJ(std::ostream& os, const PointRange& points, const PolygonRange& polygons) { @@ -323,24 +314,50 @@ bool write_OBJ(std::ostream& os, const PointRange& points, const PolygonRange& p * \tparam PolygonRange a model of the concept `SequenceContainer` * whose value_type is itself a model of the concept `SequenceContainer` * whose value_type is an integer type. + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" * * \param fname the path to the output file * \param points points of the soup of polygons. * \param polygons a `PolygonRange`. Each element in it describes a polygon * using the indices of the points in `points`. + * \param np optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{stream_precision} + * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + * \cgalParamType{int} + * \cgalParamDefault{`6`} + * \cgalParamNEnd + * \cgalNamedParamsEnd * * \return `true` if the writing was successful, `false` otherwise. */ +template +bool write_OBJ(const char* fname, const PointRange& points, const PolygonRange& polygons, + const CGAL_BGL_NP_CLASS& np) +{ + std::ofstream out(fname); + return write_OBJ(out, points, polygons, np); +} + template bool write_OBJ(const char* fname, const PointRange& points, const PolygonRange& polygons) { return write_OBJ(fname, points, polygons, parameters::all_default()); } +template +bool write_OBJ(const std::string& fname, const PointRange& points, const PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) +{ + return write_OBJ(fname.c_str(), points, polygons, np); +} + template bool write_OBJ(const std::string& fname, const PointRange& points, const PolygonRange& polygons) { - return write_OBJ(fname, points, polygons, parameters::all_default()); + return write_OBJ(fname.c_str(), points, polygons, parameters::all_default()); } } // namespace CGAL diff --git a/Stream_support/include/CGAL/IO/OFF.h b/Stream_support/include/CGAL/IO/OFF.h index 0fb76d074ff..f8c9bfb66ce 100644 --- a/Stream_support/include/CGAL/IO/OFF.h +++ b/Stream_support/include/CGAL/IO/OFF.h @@ -255,6 +255,33 @@ bool read_OFF(const std::string& fname, PointRange& points, PolygonRange& polygo //////////////////////////////////////////////////////////////////////////////////////////////////// // Write +/*! + * \ingroup PkgStreamSupportIoFuncsOFF + * + * \brief writes the content of `points` and `polygons` in `os`, using the \ref IOStreamOFF. + * + * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is the point type. + * \tparam PolygonRange a model of the concept `SequenceContainer` + * whose value_type is itself a model of the concept `SequenceContainer` + * whose value_type is an integer type. + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" + * + * \param os the output stream + * \param points points of the soup of polygons. + * \param polygons a `PolygonRange`. Each element in it describes a polygon + * using the indices of the points in `points`. + * \param np optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{stream_precision} + * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + * \cgalParamType{int} + * \cgalParamDefault{`6`} + * \cgalParamNEnd + * \cgalNamedParamsEnd + * + * \return `true` if the writing was successful, `false` otherwise. + */ template bool write_OFF(std::ostream& os, const PointRange& points, @@ -265,40 +292,9 @@ bool write_OFF(std::ostream& os, return writer(points, polygons, np); } -template -bool write_OFF(const char* fname, - const PointRange& points, - const PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np) -{ - std::ofstream os(fname); - Generic_writer writer(os); - return writer(points, polygons, np); -} - -/*! - * \ingroup PkgStreamSupportIoFuncsOFF - * - * \brief writes the content of `points` and `polygons` in `os`, using the \ref IOStreamOFF. - * - * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is the point type. - * \tparam PolygonRange a model of the concept `SequenceContainer` - * whose value_type is itself a model of the concept `SequenceContainer` - * whose value_type is an integer type. - * - * \param os the output stream - * \param points points of the soup of polygons. - * \param polygons a `PolygonRange`. Each element in it describes a polygon - * using the indices of the points in `points`. - * - * \return `true` if the writing was successful, `false` otherwise. - */ template bool write_OFF(std::ostream& os, const PointRange& points, const PolygonRange& polygons -#ifndef DOXYGEN_RUNNING - , typename boost::enable_if >::type* = nullptr -#endif - ) + , typename boost::enable_if >::type* = nullptr) { return write_OFF(os, points, polygons, parameters::all_default()); } @@ -312,14 +308,35 @@ bool write_OFF(std::ostream& os, const PointRange& points, const PolygonRange& p * \tparam PolygonRange a model of the concept `SequenceContainer` * whose value_type is itself a model of the concept `SequenceContainer` * whose value_type is an integer type. + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" * * \param fname the path to the output file * \param points points of the soup of polygons. * \param polygons a `PolygonRange`. Each element in it describes a polygon * using the indices of the points in `points`. + * \param np optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{stream_precision} + * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + * \cgalParamType{int} + * \cgalParamDefault{`6`} + * \cgalParamNEnd + * \cgalNamedParamsEnd * * \return `true` if the writing was successful, `false` otherwise. */ +template +bool write_OFF(const char* fname, + const PointRange& points, + const PolygonRange& polygons, + const CGAL_BGL_NP_CLASS& np) +{ + std::ofstream os(fname); + Generic_writer writer(os); + return writer(points, polygons, np); +} + template bool write_OFF(const char* fname, const PointRange& points, diff --git a/Stream_support/include/CGAL/IO/PLY.h b/Stream_support/include/CGAL/IO/PLY.h index e5320fd0444..f43fbab287d 100644 --- a/Stream_support/include/CGAL/IO/PLY.h +++ b/Stream_support/include/CGAL/IO/PLY.h @@ -233,7 +233,12 @@ bool read_PLY(std::istream& is, const bool verbose = true, typename boost::enable_if >::type* = nullptr) { - return IO::internal::read_PLY(is, points, polygons, std::back_inserter(hedges), std::back_inserter(fcolors), std::back_inserter(vcolors), std::back_inserter(huvs), verbose); + return IO::internal::read_PLY(is, points, polygons, + std::back_inserter(hedges), + std::back_inserter(fcolors), + std::back_inserter(vcolors), + std::back_inserter(huvs), + verbose); } template @@ -247,7 +252,30 @@ bool read_PLY(std::istream& is, std::vector > dummy_pui; std::vector > dummy_pf; - return IO::internal::read_PLY(is, points, polygons, std::back_inserter(dummy_pui), std::back_inserter(fcolors), std::back_inserter(vcolors), std::back_inserter(dummy_pf), verbose); + return IO::internal::read_PLY(is, points, polygons, + std::back_inserter(dummy_pui), + std::back_inserter(fcolors), + std::back_inserter(vcolors), + std::back_inserter(dummy_pf), + verbose); +} + +template +bool read_PLY(std::istream& is, PointRange& points, PolygonRange& polygons, + const CGAL_BGL_NP_CLASS& np, const bool verbose = true) +{ + using parameters::choose_parameter; + using parameters::get_parameter; + + std::vector > dummy_pui; + std::vector > dummy_pf; + + return IO::internal::read_PLY(is, points, polygons, std::back_inserter(dummy_pui), + choose_parameter(get_parameter(np, internal_np::face_color_output_iterator), + CGAL::Emptyset_iterator()), + choose_parameter(get_parameter(np, internal_np::vertex_color_output_iterator), + CGAL::Emptyset_iterator()), + std::back_inserter(dummy_pf), verbose); } /*! @@ -264,41 +292,21 @@ bool read_PLY(std::istream& is, * \param points points of the soup of polygons. * \param polygons a `PolygonRange`. Each element in it describes a polygon * using the indices of the points in `points`. - * \param verbose: if `true`, will output warnings and error messages. + * \param verbose if `true`, will output warnings and error messages. * * \attention Be mindful of the flag `std::ios::binary` flag when creating the `ifstream` when reading a binary file * * \returns `true` if the reading was successful, `false` otherwise. */ -template +template bool read_PLY(std::istream& is, PointRange& points, PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np, const bool verbose = true #ifndef DOXYGEN_RUNNING , typename boost::enable_if >::type* = nullptr #endif ) -{ - using parameters::choose_parameter; - using parameters::get_parameter; - - std::vector > dummy_pui; - std::vector > dummy_pf; - - return IO::internal::read_PLY(is, points, polygons, std::back_inserter(dummy_pui), - choose_parameter(get_parameter(np, internal_np::face_color_output_iterator), - CGAL::Emptyset_iterator()), - choose_parameter(get_parameter(np, internal_np::vertex_color_output_iterator), - CGAL::Emptyset_iterator()), - std::back_inserter(dummy_pf), verbose); -} - - -template -bool read_PLY(std::istream& is, PointRange& points, PolygonRange& polygons, - const bool verbose = true, typename boost::enable_if >::type* = nullptr) { return read_PLY(is, points, polygons, parameters::all_default(), verbose); } @@ -318,6 +326,7 @@ bool read_PLY(std::istream& is, PointRange& points, PolygonRange& polygons, * \param points points of the soup of polygons. * \param polygons a `PolygonRange`. Each element in it describes a polygon * using the indices of the points in `points`. + * \param verbose if `true`, will output warnings and error messages. * \param np optional \ref bgl_namedparameters "Named Parameters" described below * * \cgalNamedParamsBegin diff --git a/Stream_support/include/CGAL/IO/STL.h b/Stream_support/include/CGAL/IO/STL.h index ed46925b4f3..549c430c646 100644 --- a/Stream_support/include/CGAL/IO/STL.h +++ b/Stream_support/include/CGAL/IO/STL.h @@ -128,21 +128,21 @@ bool read_STL(std::istream& is, * \brief reads the content of `is` into `points` and `facets`, using the \ref IOStreamSTL. * * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is the point type. - * \tparam PolygonRange a model of the concept `SequenceContainer` + * \tparam TriangleRange a model of the concept `SequenceContainer` * whose value_type is itself a model of the concept `SequenceContainer` * whose value_type is an integer type. * * \param is the input stream - * \param points points of the soup of polygons. - * \param polygons a `PolygonRange`. Each element in it describes a polygon + * \param points points of the soup of triangles + * \param facets a `TriangleRange`. Each element in it describes a triangle * using the indices of the points in `points`. * * \returns `true` if the reading was successful, `false` otherwise. */ template -bool read_STL(std::istream& is, PointRange& points, TriangleRange& polygons) +bool read_STL(std::istream& is, PointRange& points, TriangleRange& facets) { - return read_STL(is, points, polygons, parameters::all_default()); + return read_STL(is, points, facets, parameters::all_default()); } template @@ -162,24 +162,24 @@ bool read_STL(const std::string& fname, PointRange& points, TriangleRange& facet /*! * \ingroup PkgStreamSupportIoFuncsSTL * - * \brief reads the content of a file named `fname` into `points` and `polygons`, using the \ref IOStreamSTL. + * \brief reads the content of a file named `fname` into `points` and `facets`, using the \ref IOStreamSTL. * * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is the point type. - * \tparam PolygonRange a model of the concept `SequenceContainer` + * \tparam TriangleRange a model of the concept `SequenceContainer` * whose value_type is itself a model of the concept `SequenceContainer` * whose value_type is an integer type. * * \param fname the path to the input file - * \param points points of the soup of polygons. - * \param polygons a `PolygonRange`. Each element in it describes a polygon + * \param points points of the soup of triangles + * \param facets a `TriangleRange`. Each element in it describes a triangle * using the indices of the points in `points`. * * \returns `true` if the reading was successful, `false` otherwise. */ template -bool read_STL(const char* fname, PointRange& points, TriangleRange& polygons) +bool read_STL(const char* fname, PointRange& points, TriangleRange& facets) { - return read_STL(fname, points, polygons, parameters::all_default()); + return read_STL(fname, points, facets, parameters::all_default()); } template @@ -192,6 +192,33 @@ bool read_STL(const std::string& fname, PointRange& points, TriangleRange& facet //////////////////////////////////////////////////////////////////////////////////////////////////// // Write +/*! + * \ingroup PkgStreamSupportIoFuncsSTL + * + * writes the content of `points` and `facets` in `os`, using the \ref IOStreamSTL. + * + * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is the point type. + * \tparam TriangleRange a model of the concept `SequenceContainer` + * whose value_type is itself a model of the concept `SequenceContainer` + * whose value_type is an integer type. + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" + * + * \param os the output stream + * \param points points of the soup of triangles + * \param facets a `TriangleRange`. Each element in it describes a triangle + * using the indices of the points in `points`. + * \param np optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{stream_precision} + * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + * \cgalParamType{int} + * \cgalParamDefault{`6`} + * \cgalParamNEnd + * \cgalNamedParamsEnd + * + * \return `true` if the writing was successful, `false` otherwise. + */ template bool write_STL(std::ostream& os, const PointRange& points, @@ -263,29 +290,39 @@ bool write_STL(std::ostream& os, return !os.fail(); } +template +bool write_STL(std::ostream& os, const PointRange& points, const TriangleRange& facets) +{ + return write_STL(os, points, facets, parameters::all_default()); +} + /*! * \ingroup PkgStreamSupportIoFuncsSTL * - * writes the content of `points` and `polygons` in `os`, using the \ref IOStreamSTL. + * \brief writes the content of `points` and `facets` in a file named `fname`, using the \ref IOStreamSTL. * * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is the point type. - * \tparam PolygonRange a model of the concept `SequenceContainer` + * \tparam TriangleRange a model of the concept `SequenceContainer` * whose value_type is itself a model of the concept `SequenceContainer` * whose value_type is an integer type. + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" * - * \param os the output stream - * \param points points of the soup of polygons. - * \param polygons a `PolygonRange`. Each element in it describes a polygon + * \param fname the path to the output file + * \param points points of the soup of triangles + * \param facets a `TriangleRange`. Each element in it describes a triangle * using the indices of the points in `points`. + * \param np optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{stream_precision} + * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + * \cgalParamType{int} + * \cgalParamDefault{`6`} + * \cgalParamNEnd + * \cgalNamedParamsEnd * * \return `true` if the writing was successful, `false` otherwise. */ -template -bool write_STL(std::ostream& os, const PointRange& points, const TriangleRange& polygons) -{ - return write_STL(os, points, polygons, parameters::all_default()); -} - template bool write_STL(const char* fname, const PointRange& points, const TriangleRange& facets, const CGAL_BGL_NP_CLASS& np) @@ -294,27 +331,10 @@ bool write_STL(const char* fname, const PointRange& points, const TriangleRange& return write_STL(os, points, facets, np); } -/*! - * \ingroup PkgStreamSupportIoFuncsSTL - * - * \brief writes the content of `points` and `polygons` in a file named `fname`, using the \ref IOStreamSTL. - * - * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is the point type. - * \tparam PolygonRange a model of the concept `SequenceContainer` - * whose value_type is itself a model of the concept `SequenceContainer` - * whose value_type is an integer type. - * - * \param fname the path to the output file - * \param points points of the soup of polygons. - * \param polygons a `PolygonRange`. Each element in it describes a polygon - * using the indices of the points in `points`. - * - * \return `true` if the writing was successful, `false` otherwise. - */ template -bool write_STL(const char* fname, const PointRange& points, const TriangleRange& polygons) +bool write_STL(const char* fname, const PointRange& points, const TriangleRange& facets) { - return write_STL(fname, points, polygons, parameters::all_default()); + return write_STL(fname, points, facets, parameters::all_default()); } template diff --git a/Stream_support/include/CGAL/IO/VTK.h b/Stream_support/include/CGAL/IO/VTK.h index 648d50c3089..06d7ca21bed 100644 --- a/Stream_support/include/CGAL/IO/VTK.h +++ b/Stream_support/include/CGAL/IO/VTK.h @@ -49,9 +49,6 @@ bool vtkPointSet_to_polygon_soup(vtkPointSet* poly_data, { typedef typename boost::range_value::type Point; - using parameters::get_parameter; - using parameters::choose_parameter; - vtkIdType nb_points = poly_data->GetNumberOfPoints(); vtkIdType nb_cells = poly_data->GetNumberOfCells(); polygons.reserve(nb_cells); @@ -63,7 +60,7 @@ bool vtkPointSet_to_polygon_soup(vtkPointSet* poly_data, { double coords[3]; poly_data->GetPoint(i, coords); - points.push_back(Point(coords[0], coords[1], coords[2])); + points.emplace_back(coords[0], coords[1], coords[2]); } // extract cells @@ -111,7 +108,7 @@ bool read_VTP(const char* fname, std::cerr<<"File doesn't exist."< data; vtkSmartPointer obs = vtkSmartPointer::New(); @@ -119,16 +116,8 @@ bool read_VTP(const char* fname, data = vtkPolyData::SafeDownCast(IO::internal::read_vtk_file(fname, obs)->GetOutput()); if (obs->GetError()) return false; - return IO::internal::vtkPointSet_to_polygon_soup(data, points, polygons, np); -} -template -bool read_VTP(const std::string& fname, - PointRange& points, - PolygonRange& polygons, - const NamedParameters& np) -{ - return read_VTP(fname.c_str(), points, polygons, np); + return IO::internal::vtkPointSet_to_polygon_soup(data, points, polygons, np); } /*! @@ -149,17 +138,18 @@ bool read_VTP(const std::string& fname, * \returns `true` if the reading was successful, `false` otherwise. */ template -bool read_VTP(const char* fname, - PointRange& points, - PolygonRange& polygons) +bool read_VTP(const char* fname, PointRange& points, PolygonRange& polygons) { return read_VTP(fname, points, polygons, parameters::all_default()); } +template +bool read_VTP(const std::string& fname, PointRange& points, PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) +{ + return read_VTP(fname.c_str(), points, polygons, np); +} template -bool read_VTP(const std::string& fname, - PointRange& points, - PolygonRange& polygons) +bool read_VTP(const std::string& fname, PointRange& points, PolygonRange& polygons) { return read_VTP(fname.c_str(), points, polygons, parameters::all_default()); } @@ -398,13 +388,9 @@ void write_soup_polys_points(std::ostream& os, * * \return `true` if the writing was successful, `false` otherwise. */ -template +template bool write_VTP(std::ostream& os, const PointRange& points, const PolygonRange& polygons, @@ -459,9 +445,7 @@ bool write_VTP(std::ostream& os, } template -bool write_VTP(std::ostream& os, - const PointRange& points, - const PolygonRange& polygons) +bool write_VTP(std::ostream& os, const PointRange& points, const PolygonRange& polygons) { return write_VTP(os, points, polygons, parameters::all_default()); } @@ -477,7 +461,7 @@ bool write_VTP(std::ostream& os, * whose value_type is an integer type. * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" * - * \param os the output stream + * \param fname the path to the output file * \param points points of the soup of polygons. * \param polygons a `PolygonRange`. Each element in it describes a polygon * using the indices of the points in `points`. @@ -489,6 +473,12 @@ bool write_VTP(std::ostream& os, * \cgalParamType{Boolean} * \cgalParamDefault{`true`} * \cgalParamNEnd + * + * \cgalParamNBegin{stream_precision} + * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + * \cgalParamType{int} + * \cgalParamDefault{`6`} + * \cgalParamNEnd * \cgalNamedParamsEnd * * \return `true` if the writing was successful, `false` otherwise. @@ -499,33 +489,37 @@ bool write_VTP(const char* fname, const PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) { - std::ofstream out(fname); - return write_VTP(out, points, polygons, np); + const bool binary = CGAL::parameters::choose_parameter(CGAL::parameters::get_parameter(np, internal_np::use_binary_mode), true); + if(binary) + { + std::ofstream os(fname, std::ios::binary); + CGAL::set_mode(os, CGAL::IO::BINARY); + return write_VTP(os, points, polygons, np); + } + else + { + std::ofstream os(fname); + CGAL::set_mode(os, CGAL::IO::ASCII); + return write_VTP(os, points, polygons, np); + } } template -bool write_VTP(const char* fname, - const PointRange& points, - const PolygonRange& polygons) +bool write_VTP(const char* fname, const PointRange& points, const PolygonRange& polygons) { return write_VTP(fname, points, polygons, parameters::all_default()); } template -bool write_VTP(const std::string& fname, - const PointRange& points, - const PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np) +bool write_VTP(const std::string& fname, const PointRange& points, const PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) { return write_VTP(fname.c_str(), points, polygons, np); } template -bool write_VTP(const std::string& fname, - const PointRange& points, - const PolygonRange& polygons) +bool write_VTP(const std::string& fname, const PointRange& points, const PolygonRange& polygons) { - return write_VTP(fname, points, polygons, parameters::all_default()); + return write_VTP(fname.c_str(), points, polygons, parameters::all_default()); } } // namespace CGAL diff --git a/Stream_support/include/CGAL/IO/WKT.h b/Stream_support/include/CGAL/IO/WKT.h index 576e82ee06d..400b89d0f1b 100644 --- a/Stream_support/include/CGAL/IO/WKT.h +++ b/Stream_support/include/CGAL/IO/WKT.h @@ -78,10 +78,7 @@ bool read_point_WKT(std::istream& in, Point& point) { if(!in.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return false; - } std::string line; while(std::getline(in, line)) @@ -130,10 +127,8 @@ bool read_multi_point_WKT(std::istream& in, MultiPoint& mp) { if(!in.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return false; - } + internal::Geometry_container gc(mp); std::string line; while(std::getline(in, line)) @@ -179,10 +174,8 @@ bool read_linestring_WKT(std::istream& in, LineString& polyline) { if(!in.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return false; - } + internal::Geometry_container gc(polyline); std::string line; while(std::getline(in, line)) @@ -226,10 +219,7 @@ bool read_multi_linestring_WKT(std::istream& in, MultiLineString& mls) { if(!in.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return false; - } typedef typename MultiLineString::value_type PointRange; typedef internal::Geometry_container LineString; @@ -282,10 +272,7 @@ bool read_polygon_WKT(std::istream& in, Polygon& polygon) { if(!in.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return false; - } std::string line; while(std::getline(in, line)) @@ -333,10 +320,7 @@ bool read_multi_polygon_WKT(std::istream& in, MultiPolygon& polygons) { if(!in.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return false; - } internal::Geometry_container gc(polygons); std::string line; @@ -383,10 +367,7 @@ std::ostream& write_point_WKT(std::ostream& out, const Point& point) { if(!out.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return out; - } out << boost::geometry::wkt(point) << std::endl; return out; @@ -407,10 +388,7 @@ std::ostream& write_polygon_WKT(std::ostream& out, const Polygon& poly) { if(!out.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return out; - } out << boost::geometry::wkt(poly) << std::endl; return out; @@ -431,10 +409,7 @@ std::ostream& write_linestring_WKT(std::ostream& out, LineString ls) { if(!out.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return out; - } internal::Geometry_container gc(ls); out << boost::geometry::wkt(gc) << std::endl; @@ -456,10 +431,7 @@ std::ostream& write_multi_point_WKT(std::ostream& out, MultiPoint& mp) { if(!out.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return out; - } internal::Geometry_container gc(mp); out << boost::geometry::wkt(gc) << std::endl; @@ -481,10 +453,7 @@ std::ostream& write_multi_polygon_WKT(std::ostream& out, MultiPolygon& polygons) { if(!out.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return out; - } internal::Geometry_container gc(polygons); out << boost::geometry::wkt(gc) << std::endl; @@ -506,10 +475,7 @@ std::ostream& write_multi_linestring_WKT(std::ostream& out, MultiLineString& mls) { if(!out.good()) - { - std::cerr << "Error: cannot open file" << std::endl; return out; - } typedef typename MultiLineString::value_type PointRange; typedef internal::Geometry_container LineString;