// 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) { 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()) return false; CGAL::File_scanner_OFF scanner(is); points.resize(scanner.size_of_vertices()); polygons.resize(scanner.size_of_facets()); for(std::size_t i=0; i> ci) { has_fcolors = true; std::istringstream iss2(col); *fc_out++ = scanner.get_color_from_line(iss2); } } 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 /*! * \ingroup IOstreamFunctions * * 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, const NamedParameters& np) { 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())); } template bool read_OFF(const char* fname, PointRange& points, PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) { std::ifstream in(fname); return read_OFF(in, points, polygons, np); } //todo doc this too template bool read_OFF(const std::string& fname, PointRange& points, PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) { return read_OFF(fname.c_str(), points, polygons, np); } template bool read_OFF(std::istream& is, PointRange& points, PolygonRange& polygons) { return read_OFF(is, points, polygons, parameters::all_default()); } 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 IOstreamFunctions * * writes the content of `points` and `polygons` in `out`, 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); } template bool write_OFF(std::ostream& os, const PointRange& points, const PolygonRange& polygons) { return write_OFF(os, points, polygons, parameters::all_default()); } } // namespace CGAL #endif // CGAL_IO_OFF_H