Fix missing overloads + document stream_precision/use_binary in SS/IO

This commit is contained in:
Mael Rouxel-Labbé 2020-06-25 15:16:34 +02:00
parent 04c3b647e9
commit cc523c09d2
8 changed files with 302 additions and 246 deletions

View File

@ -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<Graph>::%vertex_descriptor`

View File

@ -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 <typename PointRange,
typename PolygonRange,
typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
@ -311,35 +338,6 @@ bool write_GOCAD(std::ostream& os,
return IO::internal::write_GOCAD(os, "anonymous", points, polygons, np);
}
template <typename PointRange,
typename PolygonRange,
typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
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 <typename PointRange, typename PolygonRange>
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 <typename PointRange,
typename PolygonRange,
typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
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 <typename PointRange, typename PolygonRange>
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 <typename PointRange, typename PolygonRange>
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

View File

@ -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 <typename PointRange,
typename PolygonRange,
typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
@ -272,42 +299,6 @@ bool write_OBJ(std::ostream& os,
return writer(points, polygons, np);
}
template <typename PointRange,
typename PolygonRange,
typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
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 <typename PointRange,
typename PolygonRange,
typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
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 <typename PointRange, typename PolygonRange>
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 <typename PointRange,
typename PolygonRange,
typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
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 <typename PointRange, typename PolygonRange>
bool write_OBJ(const char* fname, const PointRange& points, const PolygonRange& polygons)
{
return write_OBJ(fname, points, polygons, parameters::all_default());
}
template <typename PointRange, typename PolygonRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
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 <typename PointRange, typename PolygonRange>
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

View File

@ -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 <typename PointRange, typename PolygonRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
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 <typename PointRange, typename PolygonRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(const char* fname,
const PointRange& points,
const PolygonRange& polygons,
const CGAL_BGL_NP_CLASS& np)
{
std::ofstream os(fname);
Generic_writer<std::ostream, File_writer_OFF> 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 <typename PointRange, typename PolygonRange>
bool write_OFF(std::ostream& os, const PointRange& points, const PolygonRange& polygons
#ifndef DOXYGEN_RUNNING
, typename boost::enable_if<IO::internal::is_Range<PolygonRange> >::type* = nullptr
#endif
)
, typename boost::enable_if<IO::internal::is_Range<PolygonRange> >::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 <typename PointRange, typename PolygonRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(const char* fname,
const PointRange& points,
const PolygonRange& polygons,
const CGAL_BGL_NP_CLASS& np)
{
std::ofstream os(fname);
Generic_writer<std::ostream, File_writer_OFF> writer(os);
return writer(points, polygons, np);
}
template <typename PointRange, typename PolygonRange>
bool write_OFF(const char* fname,
const PointRange& points,

View File

@ -233,7 +233,12 @@ bool read_PLY(std::istream& is,
const bool verbose = true,
typename boost::enable_if<IO::internal::is_Range<PolygonRange> >::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 <class PointRange, class PolygonRange, class ColorRange>
@ -247,7 +252,30 @@ bool read_PLY(std::istream& is,
std::vector<std::pair<unsigned int, unsigned int> > dummy_pui;
std::vector<std::pair<float, float> > 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 <typename PointRange, typename PolygonRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
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<std::pair<unsigned int, unsigned int> > dummy_pui;
std::vector<std::pair<float, float> > 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 <typename PointRange, typename PolygonRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
template <class PointRange, class PolygonRange>
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<IO::internal::is_Range<PolygonRange> >::type* = nullptr
#endif
)
{
using parameters::choose_parameter;
using parameters::get_parameter;
std::vector<std::pair<unsigned int, unsigned int> > dummy_pui;
std::vector<std::pair<float, float> > 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 <class PointRange, class PolygonRange>
bool read_PLY(std::istream& is, PointRange& points, PolygonRange& polygons,
const bool verbose = true, typename boost::enable_if<IO::internal::is_Range<PolygonRange> >::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

View File

@ -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 <typename PointRange, typename TriangleRange>
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 <typename PointRange, typename TriangleRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
@ -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 <typename PointRange, typename TriangleRange>
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 <typename PointRange, typename TriangleRange>
@ -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 <typename PointRange, typename TriangleRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_STL(std::ostream& os,
const PointRange& points,
@ -263,29 +290,39 @@ bool write_STL(std::ostream& os,
return !os.fail();
}
template <typename PointRange, typename TriangleRange>
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 <typename PointRange, typename TriangleRange>
bool write_STL(std::ostream& os, const PointRange& points, const TriangleRange& polygons)
{
return write_STL(os, points, polygons, parameters::all_default());
}
template <typename PointRange, typename TriangleRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
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 <typename PointRange, typename TriangleRange>
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 <typename PointRange, typename TriangleRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>

View File

@ -49,9 +49,6 @@ bool vtkPointSet_to_polygon_soup(vtkPointSet* poly_data,
{
typedef typename boost::range_value<PointRange>::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."<<std::endl;
return false;
}
test.close();
vtkSmartPointer<vtkPointSet> data;
vtkSmartPointer<IO::internal::ErrorObserverVtk> obs =
vtkSmartPointer<IO::internal::ErrorObserverVtk>::New();
@ -119,16 +116,8 @@ bool read_VTP(const char* fname,
data = vtkPolyData::SafeDownCast(IO::internal::read_vtk_file<vtkXMLPolyDataReader>(fname, obs)->GetOutput());
if (obs->GetError())
return false;
return IO::internal::vtkPointSet_to_polygon_soup(data, points, polygons, np);
}
template <typename PointRange, typename PolygonRange, typename NamedParameters>
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 <typename PointRange, typename PolygonRange>
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 <typename PointRange, typename PolygonRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
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 <typename PointRange, typename PolygonRange>
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 <typename PointRange, typename PolygonRange,
#ifndef DOXYGEN_RUNNING
typename CGAL_BGL_NP_TEMPLATE_PARAMETERS
#else
typename NamedParameters
#endif
>
template <typename PointRange,
typename PolygonRange,
typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_VTP(std::ostream& os,
const PointRange& points,
const PolygonRange& polygons,
@ -459,9 +445,7 @@ bool write_VTP(std::ostream& os,
}
template <typename PointRange, typename PolygonRange>
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 <typename PointRange, typename PolygonRange>
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 <typename PointRange, typename PolygonRange, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
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 <typename PointRange, typename PolygonRange>
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

View File

@ -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<MultiPoint, boost::geometry::multi_point_tag> 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<LineString, boost::geometry::linestring_tag> 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<PointRange, boost::geometry::linestring_tag> 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<MultiPolygon, boost::geometry::multi_polygon_tag> 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<LineString, boost::geometry::linestring_tag> 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<MultiPoint, boost::geometry::multi_point_tag> 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<MultiPolygon, boost::geometry::multi_polygon_tag> 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<PointRange, boost::geometry::linestring_tag> LineString;