// Copyright (c) 2015-2020 GeometryFactory // // This file is part of CGAL (www.cgal.org); // // $URL$ // $Id$ // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Laurent Rineau and Sebastien Loriot #ifndef CGAL_IO_OFF_H #define CGAL_IO_OFF_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef DOXYGEN_RUNNING #define CGAL_BGL_NP_TEMPLATE_PARAMETERS NamedParameters #define CGAL_BGL_NP_CLASS NamedParameters #endif namespace CGAL { //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // Read namespace IO { namespace internal { template bool read_OFF(std::istream& is, PointRange& points, PolygonRange& polygons, VertexNormalOutputIterator vn_out, VertexColorOutputIterator vc_out, VertexTextureOutputIterator vt_out, FaceColorOutputIterator fc_out, const bool verbose = false) { typedef typename boost::range_value::type Point; typedef typename CGAL::Kernel_traits::Kernel Kernel; typedef typename Kernel::Point_2 Texture; typedef typename Kernel::Vector_3 Normal; typedef CGAL::Color Color; if(!is.good()){ if(verbose) std::cerr<<"File doesn't exist."< bool read_OFF(std::istream& is, PointRange& points, PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np #ifndef DOXYGEN_RUNNING , typename boost::enable_if >::type* = nullptr #endif ) { using parameters::choose_parameter; using parameters::get_parameter; return IO::internal::read_OFF(is, points, polygons, choose_parameter(get_parameter(np, internal_np::vertex_normal_output_iterator), CGAL::Emptyset_iterator()), choose_parameter(get_parameter(np, internal_np::vertex_color_output_iterator), CGAL::Emptyset_iterator()), choose_parameter(get_parameter(np, internal_np::vertex_texture_output_iterator), CGAL::Emptyset_iterator()), choose_parameter(get_parameter(np, internal_np::face_color_output_iterator), CGAL::Emptyset_iterator()), choose_parameter(get_parameter(np, internal_np::verbose), true)); } /// \cond SKIP_IN_MANUAL template bool read_OFF(std::istream& is, PointRange& points, PolygonRange& polygons, typename boost::enable_if >::type* = nullptr) { return read_OFF(is, points, polygons, parameters::all_default()); } /// \endcond /*! * \ingroup PkgStreamSupportIoFuncsOFF * * \brief reads the content of the file `fname` into `points` and `polygons`, 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 concepts `SequenceContainer` and `BackInsertionSequence` * whose `value_type` is itself a model of the concept `SequenceContainer` * and `BackInsertionSequence` whose `value_type` is an unsigned integer type * convertible to `std::size_t` * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" * * \param fname the path to the input file * \param points points of the soup of polygons * \param polygons a range of polygons. Each element in it describes a polygon * using the indices of the points in `points`. * \param np optional \ref bgl_namedparameters "Named Parameters" described below * * \cgalNamedParamsBegin * \cgalParamNBegin{verbose} * \cgalParamDescription{indicates whether output warnings and error messages should be printed or not.} * \cgalParamType{Boolean} * \cgalParamDefault{`false`} * \cgalParamNEnd * \cgalNamedParamsEnd * * \returns `true` if the reading was successful, `false` otherwise. */ template bool read_OFF(const std::string& fname, PointRange& points, PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np #ifndef DOXYGEN_RUNNING , typename boost::enable_if >::type* = nullptr #endif ) { std::ifstream in(fname); return read_OFF(in, points, polygons, np); } /// \cond SKIP_IN_MANUAL template bool read_OFF(const std::string& fname, PointRange& points, PolygonRange& polygons, typename boost::enable_if >::type* = nullptr) { return read_OFF(fname, points, polygons, parameters::all_default()); } /// \endcond //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // 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 unsigned integer type convertible to `std::size_t` * \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 range of polygons. 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, const PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np #ifndef DOXYGEN_RUNNING , typename boost::enable_if >::type* = nullptr #endif ) { Generic_writer writer(os); return writer(points, polygons, np); } /// \cond SKIP_IN_MANUAL template bool write_OFF(std::ostream& os, const PointRange& points, const PolygonRange& polygons , typename boost::enable_if >::type* = nullptr) { return write_OFF(os, points, polygons, parameters::all_default()); } /// \endcond /*! * \ingroup PkgStreamSupportIoFuncsOFF * * \brief writes the content of `points` and `polygons` in the file `fname`, 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 unsigned integer type convertible to `std::size_t` * \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 range of polygons. 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 std::string& fname, const PointRange& points, const PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np #ifndef DOXYGEN_RUNNING , typename boost::enable_if >::type* = nullptr #endif ) { std::ofstream os(fname); Generic_writer writer(os); return writer(points, polygons, np); } /// \cond SKIP_IN_MANUAL template bool write_OFF(const std::string& fname, const PointRange& points, const PolygonRange& polygons, typename boost::enable_if >::type* = nullptr) { return write_OFF(fname, points, polygons, parameters::all_default()); } /// \endcond } // namespace CGAL #endif // CGAL_IO_OFF_H