diff --git a/BGL/doc/BGL/Doxyfile.in b/BGL/doc/BGL/Doxyfile.in index afdb3bfb933..9681886835a 100644 --- a/BGL/doc/BGL/Doxyfile.in +++ b/BGL/doc/BGL/Doxyfile.in @@ -14,8 +14,7 @@ INPUT += ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/Euler_operations.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/io.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/partition.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/METIS/partition_graph.h \ - ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/METIS/partition_dual_graph.h \ - ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/IO/vtp_io.h + ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/METIS/partition_dual_graph.h EXAMPLE_PATH = ${CGAL_Surface_mesh_skeletonization_EXAMPLE_DIR} \ diff --git a/BGL/doc/BGL/PackageDescription.txt b/BGL/doc/BGL/PackageDescription.txt index cde8cb34f89..2ae5f33bd19 100644 --- a/BGL/doc/BGL/PackageDescription.txt +++ b/BGL/doc/BGL/PackageDescription.txt @@ -708,7 +708,7 @@ user might encounter. ## I/O Functions ## - \link PkgBGLIOFct CGAL::read_off() \endlink - \link PkgBGLIOFct CGAL::write_off() \endlink -- \link PkgBGLIOFct CGAL::write_VTP() \endlink +- \link PkgBGLIOFct CGAL::write_vtp() \endlink - \link PkgBGLIOFct CGAL::write_wrl() \endlink */ diff --git a/BGL/include/CGAL/IO/vtp_io.h b/BGL/include/CGAL/IO/vtp_io.h deleted file mode 100644 index 75e6e722c48..00000000000 --- a/BGL/include/CGAL/IO/vtp_io.h +++ /dev/null @@ -1,302 +0,0 @@ -// Copyright (c) 2018 GeometryFactory (France). -// Copyright (c) 2004-2006 INRIA Sophia-Antipolis (France). -// Copyright (c) 2009 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno - -#ifndef CGAL_VTP_IO_H -#define CGAL_VTP_IO_H - -#include - - -#include -#include -#include - - -//todo try to factorize with functors -namespace CGAL{ -// writes the polys appended data at the end of the .vtp file -template -void -write_polys(std::ostream& os, - const Mesh & mesh, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::face_iterator face_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; - Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), - get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - - std::vector connectivity_table; - std::vector offsets; - std::vector cell_type(num_faces(mesh),5); // triangle == 5 - - std::size_t off = 0; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - off += 3; - offsets.push_back(off); - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - connectivity_table.push_back(V[v]); - } - write_vector(os,connectivity_table); - write_vector(os,offsets); - write_vector(os,cell_type); -} -//todo use named params for maps -template -void -write_polys_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::face_iterator face_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; - Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), - get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - - std::string formatattribute = - binary ? " format=\"appended\"" : " format=\"ascii\""; - - std::string typeattribute; - switch(sizeof(std::size_t)) { - case 8: typeattribute = " type=\"UInt64\""; break; - case 4: typeattribute = " type=\"UInt32\""; break; - default: CGAL_error_msg("Unknown size of std::size_t"); - } - - // Write connectivity table - os << " \n" - << " \n"; - offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); - // 3 indices (size_t) per triangle + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - os << V[v] << " "; - } - os << " \n"; - } - - // Write offsets - os << " \n"; - offset += (num_faces(mesh) + 1) * sizeof(std::size_t); - // 1 offset (size_t) per triangle + length of the encoded data (size_t) - } - else { - os << "\">\n"; - std::size_t polys_offset = 0; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - polys_offset += 3; - os << polys_offset << " "; - } - os << " \n"; - } - - // Write cell type (triangle == 5) - os << " \n"; - offset += num_faces(mesh) + sizeof(std::size_t); - // 1 unsigned char per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for(std::size_t i = 0; i< num_faces(mesh); ++i) - os << "5 "; - os << " \n"; - } - os << " \n"; -} - -//todo : use namedparams for points and ids -//overload for facegraph -template -void -write_points_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_iterator vertex_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), - get_const_property_map(CGAL::vertex_point, mesh)); - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - - std::string format = binary ? "appended" : "ascii"; - std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; - - os << " \n" - << " \n"; - offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); - // 3 coords per points + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( vertex_iterator vit = vertices(mesh).begin(); - vit != vertices(mesh).end(); - ++vit) - { - os << get(vpm, *vit).x() << " " << get(vpm, *vit).y() << " " - << get(vpm, *vit).z() << " "; - } - os << " \n"; - } - os << " \n"; -} - - -// writes the points appended data at the end of the .vtp file -template -void -write_polys_points(std::ostream& os, - const Mesh & mesh, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_iterator vertex_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), - get_const_property_map(CGAL::vertex_point, mesh)); - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - std::vector coordinates; - for( vertex_iterator vit = vertices(mesh).begin(); - vit != vertices(mesh).end(); - ++vit) - { - coordinates.push_back(get(vpm, *vit).x()); - coordinates.push_back(get(vpm, *vit).y()); - coordinates.push_back(get(vpm, *vit).z()); - } - write_vector(os,coordinates); -} - -/*!\ingroup PkgBGLIOFct - * - * \brief writes a triangulated surface mesh in the `PolyData` XML format. - * - * \tparam TriangleMesh a model of `FaceListGraph` with only triangle faces. - * \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" - * - * \param os the stream used for writting. - * \param mesh the triangle mesh to be written. - * \param binary decides if the data should be written in binary (`true`) - * or in ASCII (`false`). - * \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the - * ones listed below - * - * \cgalNamedParamsBegin - * \cgalParamBegin{vertex_point_map} the property map with the points associated to - * the vertices of `mesh`. If this parameter is omitted, an internal property map for - * `CGAL::vertex_point_t` must be available in `TriangleMesh`. - * \cgalParamEnd - * \cgalParamBegin{vertex_index_map} the property map with the indices associated to - * the vertices of `mesh`. If this parameter is omitted, an internal property map for - * `CGAL::vertex_index_t` must be available in `TriangleMesh`. - * \cgalParamEnd - * \cgalNamedParamsEnd - */ -template -void write_VTP(std::ostream& os, - const TriangleMesh& mesh, - bool binary, - const NamedParameters& np) -{ - os << "\n" - << "\n" - << " " << "\n"; - - os << " \n"; - std::size_t offset = 0; - write_points_tag(os,mesh,binary,offset, np); - write_polys_tag(os,mesh,binary,offset, np); - os << " \n" - << " \n"; - if (binary) { - os << "\n_"; - write_polys_points(os,mesh, np); - write_polys(os,mesh, np); - } - os << "\n"; -} - -template -void write_VTP(std::ostream& os, - const TriangleMesh& mesh, - bool binary = true) -{ - write_VTP(os, mesh, binary, CGAL::parameters::all_default()); -} - -} //end CGAL -#endif // CGAL_VTP_IO_H diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index 60dcfca72ad..11a2b60ce0c 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -34,6 +34,7 @@ #include #include #include +#include namespace CGAL { /*! @@ -401,6 +402,284 @@ bool write_inp(std::ostream& os, { return write_inp(os, g, name, type, parameters::all_default()); } + +namespace internal { + namespace write_vtp { + +// writes the polys appended data at the end of the .vtp file +template +void +write_polys(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + std::vector connectivity_table; + std::vector offsets; + std::vector cell_type(num_faces(mesh),5); // triangle == 5 + + std::size_t off = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + off += 3; + offsets.push_back(off); + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + connectivity_table.push_back(V[v]); + } + write_vector(os,connectivity_table); + write_vector(os,offsets); + write_vector(os,cell_type); +} +//todo use named params for maps +template +void +write_polys_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + std::string formatattribute = + binary ? " format=\"appended\"" : " format=\"ascii\""; + + std::string typeattribute; + switch(sizeof(std::size_t)) { + case 8: typeattribute = " type=\"UInt64\""; break; + case 4: typeattribute = " type=\"UInt32\""; break; + default: CGAL_error_msg("Unknown size of std::size_t"); + } + + // Write connectivity table + os << " \n" + << " \n"; + offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); + // 3 indices (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + os << V[v] << " "; + } + os << " \n"; + } + + // Write offsets + os << " \n"; + offset += (num_faces(mesh) + 1) * sizeof(std::size_t); + // 1 offset (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + std::size_t polys_offset = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + polys_offset += 3; + os << polys_offset << " "; + } + os << " \n"; + } + + // Write cell type (triangle == 5) + os << " \n"; + offset += num_faces(mesh) + sizeof(std::size_t); + // 1 unsigned char per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for(std::size_t i = 0; i< num_faces(mesh); ++i) + os << "5 "; + os << " \n"; + } + os << " \n"; +} + +//todo : use namedparams for points and ids +//overload for facegraph +template +void +write_points_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; + + os << " \n" + << " \n"; + offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); + // 3 coords per points + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + os << get(vpm, *vit).x() << " " << get(vpm, *vit).y() << " " + << get(vpm, *vit).z() << " "; + } + os << " \n"; + } + os << " \n"; +} + + +// writes the points appended data at the end of the .vtp file +template +void +write_polys_points(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + std::vector coordinates; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + coordinates.push_back(get(vpm, *vit).x()); + coordinates.push_back(get(vpm, *vit).y()); + coordinates.push_back(get(vpm, *vit).z()); + } + write_vector(os,coordinates); +} + + } // end namespace CGAL::internal::write_vtp +} // end namespace CGAL::internal + +/*!\ingroup PkgBGLIOFct + * + * \brief writes a triangulated surface mesh in the `PolyData` XML format. + * + * \tparam TriangleMesh a model of `FaceListGraph` with only triangle faces. + * \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" + * + * \param os the stream used for writting. + * \param mesh the triangle mesh to be written. + * \param mode decides if the data should be written in binary (`IO::BINARY`) + * or in ASCII (`IO::ASCII`). `IO::BINARY` is the default. + * \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the + * ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamBegin{vertex_point_map} the property map with the points associated to + * the vertices of `mesh`. If this parameter is omitted, an internal property map for + * `CGAL::vertex_point_t` must be available in `TriangleMesh`. + * \cgalParamEnd + * \cgalParamBegin{vertex_index_map} the property map with the indices associated to + * the vertices of `mesh`. If this parameter is omitted, an internal property map for + * `CGAL::vertex_index_t` must be available in `TriangleMesh`. + * \cgalParamEnd + * \cgalNamedParamsEnd + */ +template +void write_vtp(std::ostream& os, + const TriangleMesh& mesh, + IO::Mode mode, + const NamedParameters& np) +{ + os << "\n" + << "\n" + << " " << "\n"; + + os << " \n"; + std::size_t offset = 0; + const bool binary = (mode == IO::BINARY); + internal::write_vtp::write_points_tag(os,mesh,binary,offset, np); + internal::write_vtp::write_polys_tag(os,mesh,binary,offset, np); + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + internal::write_vtp::write_polys_points(os,mesh, np); + internal::write_vtp::write_polys(os,mesh, np); + } + os << "\n"; +} + +/*! \ingroup PkgBGLIOFct + * Overload that implements the default arguments + * + * Calls `write_vtp(os, mesh, mode, parameters::all_default())`. + */ +template +void write_vtp(std::ostream& os, + const TriangleMesh& mesh, + IO::Mode mode = IO::BINARY) +{ + write_vtp(os, mesh, mode, CGAL::parameters::all_default()); +} + } // namespace CGAL #endif // CGAL_BOOST_GRAPH_IO_H diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index f98c94b84a4..4ad6bfb5279 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -66,7 +66,8 @@ Release date: March 2019 - Added 3 functions for writing in XML VTK formats: - `CGAL::output_to_vtu()` - `CGAL::write_VTU()` - - `CGAL::write_VTP()` + - `CGAL::write_vtp()`, that writes a triangulated face graph in a + `.vtp` file. ### CGAL and the Boost Graph Library (BGL) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index 2eebc0ce1f1..24eca7c80e1 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include @@ -329,7 +329,7 @@ public: std::ofstream os(output_filename.data()); os << std::setprecision(16); //write header - CGAL::write_VTP(os, *mesh); + CGAL::write_vtp(os, *mesh); } } else