// Copyright (c) 2015 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 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, bool verbose = true) { 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; CGAL_USE(verbose); if(!is.good()){ if(verbose) std::cerr<<"File doesn't exist."<> ci) { has_fcolors = true; std::istringstream iss2(col); bool dum; *fc_out++ = scanner.get_color_from_line(iss2, dum); } } else if(has_fcolors) { unsigned char r=0, g=0, b=0; scanner.scan_color(r,g,b); *fc_out++ = Color(r,g,b); } } return !is.fail(); } } // namespace internal } // namespace IO template bool read_OFF(std::istream& is, PointRange& points, PolygonRange& polygons, const NamedParameters& np, bool verbose = true) { 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()), verbose); } template bool read_OFF(const char* fname, PointRange& points, PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np, bool verbose = true) { std::ifstream in(fname); return read_OFF(in, points, polygons, np, verbose); } template bool read_OFF(const std::string& fname, PointRange& points, PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np, bool verbose = true) { return read_OFF(fname.c_str(), points, polygons, np, verbose); } /*! * \ingroup OffIoFuncs * * reads the content of `is` into `points` and `polygons`, in the OFF format. * * * \see \ref IOStreamOFF */ template bool read_OFF(std::istream& is, PointRange& points, PolygonRange& polygons) { return read_OFF(is, points, polygons, parameters::all_default()); } /*! * \ingroup OffIoFuncs * * reads the content of the file `fname` into `points` and `polygons`, in the OFF format. * * * \see \ref IOStreamOFF */ template bool read_OFF(const char* fname, PointRange& points, PolygonRange& polygons) { return read_OFF(fname, points, polygons, parameters::all_default()); } template bool read_OFF(const std::string& fname, PointRange& points, PolygonRange& polygons) { return read_OFF(fname, points, polygons, parameters::all_default()); } //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// /// Write /*! * \ingroup OffIoFuncs * * writes the content of `points` and `polygons` in `os`, in the OFF format. * * \see \ref IOStreamOFF */ template bool write_OFF(std::ostream& os, const PointRange& points, const PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) { Generic_writer writer(os); return writer(points, polygons, np); } /*! * \ingroup OffIoFuncs * * writes the content of `points` and `polygons` in the file `fname`, in the OFF format. * * \see \ref IOStreamOFF */ 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(std::ostream& os, const PointRange& points, const PolygonRange& polygons, typename boost::enable_if< typename boost::has_range_const_iterator::type >::type* =0) { return write_OFF(os, points, polygons, parameters::all_default()); } template bool write_OFF(const char* fname, const PointRange& points, const PolygonRange& polygons, typename boost::enable_if< typename boost::has_range_const_iterator::type >::type* =0) { return write_OFF(fname, points, polygons, parameters::all_default()); } template bool write_OFF(const std::string& fname, const PointRange& points, const PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) { return write_OFF(fname.c_str(), points, polygons, np); } template bool write_OFF(const std::string& fname, const PointRange& points, const PolygonRange& polygons, typename boost::enable_if< typename boost::has_range_const_iterator::type >::type* =0) { return write_OFF(fname, points, polygons, parameters::all_default()); } } // namespace CGAL #endif // CGAL_IO_OFF_H