diff --git a/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_on_sphere_2.h b/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_on_sphere_2.h index cfa30343a96..9012a72b79c 100644 --- a/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_on_sphere_2.h +++ b/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_on_sphere_2.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include diff --git a/Triangulation_on_sphere_2/include/CGAL/Triangulation_on_sphere_2/IO/OFF.h b/Triangulation_on_sphere_2/include/CGAL/Triangulation_on_sphere_2/IO/OFF.h new file mode 100644 index 00000000000..082ff3ab5f2 --- /dev/null +++ b/Triangulation_on_sphere_2/include/CGAL/Triangulation_on_sphere_2/IO/OFF.h @@ -0,0 +1,173 @@ +// Copyright (c) 2021 GeometryFactory (France). All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Mael Rouxel-Labbé + +#ifndef CGAL_TOS2_IO_OFF_H +#define CGAL_TOS2_IO_OFF_H + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#ifdef DOXYGEN_RUNNING +#define CGAL_BGL_NP_TEMPLATE_PARAMETERS NamedParameters +#define CGAL_BGL_NP_CLASS NamedParameters +#define CGAL_DEPRECATED +#endif + +namespace CGAL { + +template +class Delaunay_triangulation_on_sphere_2; + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Read + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Write + +/*! + \ingroup PkgPointSet3IOOFF + + \brief writes the content of a triangulation on the sphere into an output stream in the \ref IOStreamOFF. + + \tparam Gt the geometric traits type of the triangulation + \tparam Tds the triangulation data structure type of the triangulation + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" + + \param os the output stream + \param dt the triangulation + \param np an 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{the precision of the stream `os`} + \cgalParamNEnd + \cgalNamedParamsEnd + + \return `true` if the writing was successful, `false` otherwise. + */ +template +bool write_OFF(std::ostream& os, + const CGAL::Delaunay_triangulation_on_sphere_2& dt, + const CGAL_BGL_NP_CLASS& np) +{ + typedef Delaunay_triangulation_on_sphere_2 Tr; + typedef typename Tr::Vertex_handle Vertex_handle; + typedef typename Tr::All_vertices_iterator Vertex_iterator; + typedef typename Tr::All_faces_iterator Face_iterator; + + typename Gt::Construct_point_3 cp3 = dt.geom_traits().construct_point_3_object(); + + const size_t n = dt.number_of_vertices(); + + std::stringstream output; + + // write the vertices + std::unordered_map index_of_vertex; + int i = 0; + for(Vertex_iterator it = dt.vertices_begin(); it != dt.vertices_end(); ++it, ++i) + { + Vertex_handle vh = it; + output << cp3(vh->point()) << " 0 0 0 \n"; // '0 0 0' for colors + index_of_vertex[vh] = i; + } + + CGAL_assertion( i == n ); + + size_t number_of_triangles = 0; + + for (Face_iterator fit = dt.all_faces_begin() ; fit != dt.all_faces_end() ; ++fit) + { + output << "3 " + << index_of_vertex[fit->vertex(0)] << " " + << index_of_vertex[fit->vertex(1)] << " " + << index_of_vertex[fit->vertex(2)] + << " "; + if(fit->is_ghost()) + output << " 229 117 0\n"; + else + output << " 0 117 229\n"; + + ++number_of_triangles; + } + + os << "COFF \n" + << n << " " + << number_of_triangles << " 0\n" + << output.str(); + + return !os.fail(); +} + +/// \cond SKIP_IN_MANUAL + +template +bool write_OFF(std::ostream& os, const CGAL::Delaunay_triangulation_on_sphere_2& dt) +{ + return write_OFF(os, dt, parameters::all_default()); +} + +/// \endcond + +/*! + \ingroup PkgPointSet3IOOFF + + \brief writes the content of a triangulation on the sphere into an output file in the \ref IOStreamOFF. + + \tparam Gt the geometric traits type of the triangulation + \tparam Tds the triangulation data structure type of the triangulation + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" + + \param fname the path to the output file + \param point_set the point set + \param np an 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 CGAL::Delaunay_triangulation_on_sphere_2& dt, const CGAL_BGL_NP_CLASS& np) +{ + std::ofstream os(fname); + return write_OFF(os, dt, np); +} + +/// \cond SKIP_IN_MANUAL + +template +bool write_OFF(const std::string& fname, const CGAL::Delaunay_triangulation_on_sphere_2& dt) +{ + std::ofstream os(fname); + return write_OFF(os, dt, parameters::all_default()); +} + +/// \endcond + +} // namespace CGAL + +#endif // CGAL_TOS2_IO_OFF_H