From eb6405af6cb28e8593e45d26578cd4ec0aa199a9 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Mon, 23 Oct 2023 13:54:49 +0200 Subject: [PATCH 01/17] Traingulation IO API Changes --- .../CGAL/Mesh_complex_3_in_triangulation_3.h | 134 ++++++- .../CGAL/IO/Triangulation_raw_iostream_3.h | 332 ++++++++++++++++++ .../include/CGAL/Triangulation_3.h | 140 +------- 3 files changed, 469 insertions(+), 137 deletions(-) create mode 100644 Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h diff --git a/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h b/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h index f77f1d9c07f3..b346427704c1 100644 --- a/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h +++ b/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h @@ -1205,6 +1205,12 @@ class Mesh_complex_3_in_triangulation_3 std::istream& operator>>(std::istream& is, Mesh_complex_3_in_triangulation_3& c3t3); + template + friend + std::ostream & operator<<(std::ostream& os, + const Mesh_complex_3_in_triangulation_3 &c3t3); + + static std::string io_signature() { return Get_io_signature()(); @@ -2071,8 +2077,69 @@ std::ostream & operator<< (std::ostream& os, const Mesh_complex_3_in_triangulation_3 &c3t3) { - // TODO: implement edge saving - return os << c3t3.triangulation(); + /* Writes: + * [Triangulation] + * [Header] + * - the dimension + * [Vertices] + * - the number of finite vertices + * - the non combinatorial information on vertices (point, etc) + * [Cells] + * - the number of cells + * - the cells by the indices of their vertices in the preceding list + * of vertices, plus the non combinatorial information on each cell + * [Cells combinatorial information] + * - the neighbors of each cell by their index in the preceding list of cells + * [Cells other info] + * - when dimension < 3 : the same with faces of maximal dimension + * [1D features] + * - the number of edges + * - the edges by the indices of their vertices and their curve_index + */ + using C3t3 = Mesh_complex_3_in_triangulation_3; + using Vertex_handle = typename C3t3::Vertex_handle; + using Curve_index = typename C3t3::Curve_index; + + // Writes triangulation + Unique_hash_map vertices_map; + if (!CGAL::IO::export_triangulation_3(os, c3t3.triangulation(), vertices_map)) + { + os.setstate(std::ios_base::failbit); + return os; + } + + // Writes 1D features + std::size_t nEdges = c3t3.edges_.size(); + if(IO::is_ascii(os)) + { + os << nEdges << '\n'; + } + else + { + write(os, nEdges); + } + + if (!os) + return os; + + for ( typename C3t3::Edge_map::const_iterator it = c3t3.edges_.begin(), + end = c3t3.edges_.end() ; it != end ; ++it ) + { + const Vertex_handle& v1 = it->left; + const Vertex_handle& v2 = it->right; + const std::size_t& iv1 = vertices_map[v1]; + const std::size_t& iv2 = vertices_map[v2]; + const Curve_index& index = it->info; + if (IO::is_ascii(os)) + os << iv1 << ' ' << iv2 << ' ' << index << '\n'; + else { + write(os, iv1); + write(os, iv2); + write(os, index); + } + } + + return os; } @@ -2081,15 +2148,72 @@ std::istream & operator>> (std::istream& is, Mesh_complex_3_in_triangulation_3 &c3t3) { - // TODO: implement edge loading + /* Reads: + * [Triangulation] + * [Header] + * - the dimension + * [Vertices] + * - the number of finite vertices + * - the non combinatorial information on vertices (point, etc) + * [Cells] + * - the number of cells + * - the cells by the indices of their vertices in the preceding list + * of vertices, plus the non combinatorial information on each cell + * [Cells combinatorial information] + * - the neighbors of each cell by their index in the preceding list of cells + * [Cells other info] + * - when dimension < 3 : the same with faces of maximal dimension + * [1D features] + * - the number of edges + * - the edges by the indices of their vertices and their curve_index + */ + using C3t3 = Mesh_complex_3_in_triangulation_3; + using Vertex_handle = typename C3t3::Vertex_handle; + using Curve_index = typename C3t3::Curve_index; + using Internal_edge = typename C3t3::Internal_edge; + c3t3.clear(); - is >> c3t3.triangulation(); - if (!is) { + // Reads triangulation + std::vector< Vertex_handle > vertices_handles; + if (!CGAL::IO::import_triangulation_3(is, c3t3.triangulation(), vertices_handles)) + { c3t3.clear(); + is.setstate(std::ios_base::failbit); + return is; + } + + // Reads 1D features + std::size_t nEdges; + if(IO::is_ascii(is)) + { + is >> nEdges; + } + else + { + read(is, nEdges); + } + // If the file did not have edges + if (!is) { return is; } + for (std::size_t i = 0; i < nEdges; i++) + { + std::size_t iv1; + std::size_t iv2; + Curve_index index; + if (IO::is_ascii(is)) + is >> iv1 >> iv2 >> index; + else { + read(is, iv1); + read(is, iv2); + read(is, index); + } + Internal_edge edge(vertices_handles[iv1], vertices_handles[iv2]); + c3t3.add_to_complex(edge, index); + } + c3t3.rescan_after_load_of_triangulation(); return is; } diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h new file mode 100644 index 000000000000..7ede46cb7bc1 --- /dev/null +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -0,0 +1,332 @@ +#ifndef CGAL_TRIANGULATION_RAW_IOSTREAM_3_H +#define CGAL_TRIANGULATION_RAW_IOSTREAM_3_H + +#include +#include + +#include +#include +#include + +namespace CGAL { + +template < class GT, class Tds = Default, + class Lock_data_structure = Default > +class Triangulation_3; + +namespace IO { + +namespace internal { + +template < class GT, class Tds, class Lds > +bool construct_vertices_map(const Triangulation_3& tr, Unique_hash_map& vertices_map) +{ + typedef Triangulation_3 Triangulation; + typedef typename Triangulation::size_type size_type; + typedef typename Triangulation::Vertex_iterator Vertex_iterator; + + size_type i = 0; + vertices_map[tr.infinite_vertex()] = 0; + for(Vertex_iterator it = tr.vertices_begin(), end = tr.vertices_end(); it != end; ++it) + { + vertices_map[it] = i++; + } + + CGAL_assertion(i == tr.number_of_vertices()+1); + + return true; +} + +template < class GT, class Tds, class Lds > +bool write_header(std::ostream& os, const Triangulation_3& tr) +{ + // Writes: + // - the dimension + if(IO::is_ascii(os)) + { + os << tr.dimension() << "\n"; + } + else + { + write(os, tr.dimension()); + } + return (bool)os; +} + +template < class GT, class Tds, class Lds > +bool read_header(std::istream& is, Triangulation_3& tr) +{ + // Reads: + // - the dimension + int dimension; + if(IO::is_ascii(is)) + { + is >> dimension; + } + else + { + read(is, dimension); + } + if(dimension > 3 || dimension < -2) + return false; + tr.tds().set_dimension(dimension); + return (bool)is; +} + +template < class GT, class Tds, class Lds > +bool write_vertices(std::ostream& os, const Triangulation_3& tr) +{ + // Writes: + // - the number of finite vertices + // - the non combinatorial information on vertices (point, etc) + typedef Triangulation_3 Triangulation; + typedef typename Triangulation::size_type size_type; + typedef typename Triangulation::Vertex_iterator Vertex_iterator; + + size_type n = tr.number_of_vertices(); + if (n == 0) + return false; + + if(IO::is_ascii(os)) + { + os << n << '\n'; + } + else + { + write(os, n); + } + + for(Vertex_iterator it = ++tr.vertices_begin(), end = tr.vertices_end(); it != end; ++it) + { + os << *it; + if(IO::is_ascii(os)) + os << '\n'; + } + + return (bool)os; +} + +template < class GT, class Tds, class Lds > +bool read_vertices(std::istream& is, Triangulation_3& tr, std::vector< typename Tds::Vertex_handle >& vertices_handles) +{ + // Reads: + // - the number of finite vertices + // - the non combinatorial information on vertices (point, etc) + typedef Triangulation_3 Triangulation; + typedef typename Triangulation::size_type size_type; + + size_type n; + if(IO::is_ascii(is)) + { + is >> n; + } + else + { + read(is, n); + } + if((n+1) > vertices_handles.max_size()) + return false; + + vertices_handles.resize(n+1); + vertices_handles[0] = tr.infinite_vertex(); // the infinite vertex is numbered 0 + + std::cout << tr.dimension() << " " << n << std::endl; + for(std::size_t i=1; i <= n; i++) + { + vertices_handles[i] = tr.tds().create_vertex(); + if(!(is >> *vertices_handles[i])) + return false; + std::cout << i << " : " << vertices_handles[i]->in_dimension() << " " << vertices_handles[i]->point().x() << std::endl; + } + std::cout << tr.dimension() << " " << n << std::endl; + + return (bool)is; +} + +struct Cell_accessor +{ + template + auto operator()(const Iterator& it) { return it; } +}; + +struct Cell_accessor_first +{ + template + auto operator()(const Iterator& it) { return it->first; } +}; + +template +bool write_cell_info(std::ostream& os, Iterator start, const Iterator& end) +{ + Cell_accessor accessor; + if(IO::is_ascii(os)) + { + for(; start != end; ++start) + { + os << *(accessor(start)) << '\n'; + } + } + else + { + for(; start != end; ++start) + { + os << *(accessor(start)); + } + } + return (bool)os; +} + +template < class GT, class Tds, class Lds > +bool write_cells(std::ostream& os, const Triangulation_3& tr, const Unique_hash_map& vertices_map) +{ + // Writes: + // [Call to Tds::print_cells] + // - the number of cells + // - the cells by the indices of their vertices in the preceding list + // of vertices, plus the non combinatorial information on each cell + // - the neighbors of each cell by their index in the preceding list of cells + // [Cells other info] + // - when dimension < 3 : the same with faces of maximal dimension + + typedef Triangulation_3 Triangulation; + typedef typename Triangulation::Cell_iterator Cell_iterator; + typedef typename Triangulation::Edge_iterator Edge_iterator; + typedef typename Triangulation::Facet_iterator Facet_iterator; + + tr.tds().print_cells(os, vertices_map); + if (!os) + return false; + + // Write the non combinatorial information on the cells + // using the << operator of Cell. + // Works because the iterator of the tds traverses the cells in the + // same order as the iterator of the triangulation + switch(tr.dimension()) + { + case 3: + { + return write_cell_info(os, tr.cells_begin(), tr.cells_end()); + break; + } + case 2: + { + return write_cell_info(os, tr.facets_begin(), tr.facets_end()); + break; + } + case 1: + { + return write_cell_info(os, tr.edges_begin(), tr.edges_end()); + break; + } + } + return false; +} + + +template < class GT, class Tds, class Lds > +bool read_cells(std::istream& is, Triangulation_3& tr, const std::vector< typename Tds::Vertex_handle >& vertices_handles) +{ + // Writes: + // [Call to Tds::print_cells] + // - the number of cells + // - the cells by the indices of their vertices in the preceding list + // of vertices, plus the non combinatorial information on each cell + // - the neighbors of each cell by their index in the preceding list of cells + // [Cells other info] + // - when dimension < 3 : the same with faces of maximal dimension + + typedef Triangulation_3 Triangulation; + typedef typename Triangulation::Cell_handle Cell_handle; + + std::vector< Cell_handle > C; + + std::size_t m; + tr.tds().read_cells(is, vertices_handles, m, C); + if(!is) + return false; + + for(std::size_t i=0 ; i < m; i++) + if(!(is >> *(C[i]))) + return false; + + return (bool)is; +} + +} // end namespace internal + + +template < class GT, class Tds, class Lds > +bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr) +{ + Unique_hash_map vertices_map; + return export_triangulation_3(os, tr, vertices_map); +} + +template < class GT, class Tds, class Lds > +bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr, Unique_hash_map& vertices_map) +{ + // Writes: + // [Header] + // - the dimension + // [Vertices] + // - the number of finite vertices + // - the non combinatorial information on vertices (point, etc) + // [Cells] + // - the number of cells + // - the cells by the indices of their vertices in the preceding list + // of vertices, plus the non combinatorial information on each cell + // [Cells combinatorial information] + // - the neighbors of each cell by their index in the preceding list of cells + // [Cells other info] + // - when dimension < 3 : the same with faces of maximal dimension + + return internal::write_header(os, tr) + && internal::write_vertices(os, tr) + && internal::construct_vertices_map(tr, vertices_map) + && internal::write_cells(os, tr, vertices_map); +} + + +template < class GT, class Tds, class Lds > +bool import_triangulation_3(std::istream& is, const Triangulation_3& tr) +{ + std::vector vertices_handles; + return import_triangulation_3(is, tr, vertices_handles); +} + +template < class GT, class Tds, class Lds > +bool import_triangulation_3(std::istream& is, Triangulation_3& tr, std::vector& vertices_handles) +{ + // Reads: + // [Header] + // - the dimension + // [Vertices] + // - the number of finite vertices + // - the non combinatorial information on vertices (point, etc) + // [Cells] + // - the number of cells + // - the cells by the indices of their vertices in the preceding list + // of vertices, plus the non combinatorial information on each cell + // [Cells combinatorial information] + // - the neighbors of each cell by their index in the preceding list of cells + // [Cells other info] + // - when dimension < 3 : the same with faces of maximal dimension + + tr.tds().clear(); // infinite vertex deleted + tr.set_infinite_vertex(tr.tds().create_vertex()); + + bool result = internal::read_header(is, tr) + && internal::read_vertices(is, tr, vertices_handles) + && internal::read_cells(is, tr, vertices_handles); + + CGAL_assertion(tr.is_valid(true)); + return result; +} + + + +} // end namespace IO + +} // end namespace CGAL + +#endif // CGAL_TRIANGULATION_RAW_IOSTREAM_3_H diff --git a/Triangulation_3/include/CGAL/Triangulation_3.h b/Triangulation_3/include/CGAL/Triangulation_3.h index 7b8ef9ab6c8a..9a9bcd86d1c4 100644 --- a/Triangulation_3/include/CGAL/Triangulation_3.h +++ b/Triangulation_3/include/CGAL/Triangulation_3.h @@ -45,6 +45,8 @@ #include #include +#include + #include #include #include @@ -81,9 +83,11 @@ namespace CGAL { +#ifndef CGAL_TRIANGULATION_RAW_IOSTREAM_3_H template < class GT, class Tds = Default, class Lock_data_structure = Default > class Triangulation_3; +#endif template < class GT, class Tds, class Lds > std::istream& operator>> (std::istream& is, Triangulation_3& tr); @@ -2385,54 +2389,8 @@ std::istream& operator>> (std::istream& is, Triangulation_3& tr) // of vertices, plus the non combinatorial information on each cell // - the neighbors of each cell by their index in the preceding list of cells // - when dimension < 3 : the same with faces of maximal dimension - - typedef Triangulation_3 Triangulation; - typedef typename Triangulation::Vertex_handle Vertex_handle; - typedef typename Triangulation::Cell_handle Cell_handle; - - tr._tds.clear(); // infinite vertex deleted - tr.infinite = tr._tds.create_vertex(); - - std::size_t n; - int d; - if(IO::is_ascii(is)) - { - is >> d >> n; - } - else - { - read(is, d); - read(is, n); - } - if(!is) - return is; - - std::vector< Vertex_handle > V; - if(d > 3 || d < -2 || (n+1) > V.max_size()) { + if (!CGAL::IO::import_triangulation_3(is, tr)) is.setstate(std::ios_base::failbit); - return is; - } - tr._tds.set_dimension(d); - V.resize(n+1); - V[0] = tr.infinite_vertex(); // the infinite vertex is numbered 0 - - for(std::size_t i=1; i <= n; i++) - { - V[i] = tr._tds.create_vertex(); - if(!(is >> *V[i])) - return is; - } - - std::vector< Cell_handle > C; - - std::size_t m; - tr._tds.read_cells(is, V, m, C); - - for(std::size_t j=0 ; j < m; j++) - if(!(is >> *(C[j]))) - return is; - - CGAL_assertion(tr.is_valid(false)); return is; } @@ -2448,91 +2406,9 @@ std::ostream& operator<< (std::ostream& os, const Triangulation_3& // of vertices, plus the non combinatorial information on each cell // - the neighbors of each cell by their index in the preceding list of cells // - when dimension < 3 : the same with faces of maximal dimension - - typedef Triangulation_3 Triangulation; - typedef typename Triangulation::size_type size_type; - typedef typename Triangulation::Vertex_handle Vertex_handle; - typedef typename Triangulation::Vertex_iterator Vertex_iterator; - typedef typename Triangulation::Cell_iterator Cell_iterator; - typedef typename Triangulation::Edge_iterator Edge_iterator; - typedef typename Triangulation::Facet_iterator Facet_iterator; - - // outputs dimension and number of vertices - size_type n = tr.number_of_vertices(); - if(IO::is_ascii(os)) - { - os << tr.dimension() << std::endl << n << std::endl; - } - else - { - write(os, tr.dimension()); - write(os, n); - } - - if(n == 0) - return os; - - std::vector TV(n+1); - size_type i = 0; - - // write the vertices - for(Vertex_iterator it = tr.vertices_begin(), end = tr.vertices_end(); it != end; ++it) - TV[i++] = it; - - CGAL_assertion(i == n+1); - CGAL_assertion(tr.is_infinite(TV[0])); - - Unique_hash_map V; - V[tr.infinite_vertex()] = 0; - for(i=1; i <= n; i++) - { - os << *TV[i]; - V[TV[i]] = i; - if(IO::is_ascii(os)) - os << std::endl; - } - - // Asks the tds for the combinatorial information - tr.tds().print_cells(os, V); - - // Write the non combinatorial information on the cells - // using the << operator of Cell. - // Works because the iterator of the tds traverses the cells in the - // same order as the iterator of the triangulation - switch(tr.dimension()) - { - case 3: - { - for(Cell_iterator it = tr.cells_begin(), end = tr.cells_end(); it != end; ++it) - { - os << *it; // other information - if(IO::is_ascii(os)) - os << std::endl; - } - break; - } - case 2: - { - for(Facet_iterator it = tr.facets_begin(), end = tr.facets_end(); it != end; ++it) - { - os << *((*it).first); // other information - if(IO::is_ascii(os)) - os << std::endl; - } - break; - } - case 1: - { - for(Edge_iterator it = tr.edges_begin(), end = tr.edges_end(); it != end; ++it) - { - os << *((*it).first); // other information - if(IO::is_ascii(os)) - os << std::endl; - } - break; - } - } - return os ; + if (!CGAL::IO::export_triangulation_3(os, tr)) + os.setstate(std::ios_base::failbit); + return os; } template < class GT, class Tds, class Lds > From d89f1bb4a3511e9bb6d158b5ebc718c3a295c7ce Mon Sep 17 00:00:00 2001 From: ange-clement Date: Mon, 23 Oct 2023 15:12:05 +0200 Subject: [PATCH 02/17] Fix IO Mesh_3 plugin --- .../demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp | 6 ++++++ .../include/CGAL/IO/Triangulation_raw_iostream_3.h | 7 ++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp index 4cadd392fd38..f333590a8643 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp @@ -499,6 +499,9 @@ try_load_a_cdt_3(std::istream& is, C3t3& c3t3) } std::getline(is, s); if(s != "") { + if(s[s.size()-1] == '\r') { // deal with Windows EOL + s.resize(s.size() - 1); + } if(s != std::string(" ") + CGAL::Get_io_signature()()) { std::cerr << "load_binary_file:" << "\n expected format: " << CGAL::Get_io_signature()() @@ -582,6 +585,9 @@ try_load_other_binary_format(std::istream& is, C3t3& c3t3) } std::getline(is, s); if(s != "") { + if(s[s.size()-1] == '\r') { // deal with Windows EOL + s.resize(s.size() - 1); + } if(s != std::string(" ") + CGAL::Get_io_signature()()) { std::cerr << "Polyhedron_demo_c3t3_binary_io_plugin::try_load_other_binary_format:" << "\n expected format: " << CGAL::Get_io_signature()() diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h index 7ede46cb7bc1..6f0709dbd3a2 100644 --- a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -130,15 +130,12 @@ bool read_vertices(std::istream& is, Triangulation_3& tr, std::vec vertices_handles.resize(n+1); vertices_handles[0] = tr.infinite_vertex(); // the infinite vertex is numbered 0 - std::cout << tr.dimension() << " " << n << std::endl; for(std::size_t i=1; i <= n; i++) { vertices_handles[i] = tr.tds().create_vertex(); if(!(is >> *vertices_handles[i])) return false; - std::cout << i << " : " << vertices_handles[i]->in_dimension() << " " << vertices_handles[i]->point().x() << std::endl; } - std::cout << tr.dimension() << " " << n << std::endl; return (bool)is; } @@ -288,7 +285,7 @@ bool export_triangulation_3(std::ostream& os, const Triangulation_3 -bool import_triangulation_3(std::istream& is, const Triangulation_3& tr) +bool import_triangulation_3(std::istream& is, Triangulation_3& tr) { std::vector vertices_handles; return import_triangulation_3(is, tr, vertices_handles); @@ -319,7 +316,7 @@ bool import_triangulation_3(std::istream& is, Triangulation_3& tr, && internal::read_vertices(is, tr, vertices_handles) && internal::read_cells(is, tr, vertices_handles); - CGAL_assertion(tr.is_valid(true)); + CGAL_assertion(tr.is_valid(false)); return result; } From bf245cfb549af009393a2a7a81d2dd4b0dff27d7 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Mon, 23 Oct 2023 16:04:09 +0200 Subject: [PATCH 03/17] License --- .../include/CGAL/IO/Triangulation_raw_iostream_3.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h index 6f0709dbd3a2..b64aebf1c2f2 100644 --- a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -1,6 +1,20 @@ +// Copyright (c) 20XX,20XX GeometryFactory +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Ange Clément + + #ifndef CGAL_TRIANGULATION_RAW_IOSTREAM_3_H #define CGAL_TRIANGULATION_RAW_IOSTREAM_3_H +#include + #include #include From 7c3bd39852dafc88bea4b689ba209e4c5acf6e98 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Wed, 25 Oct 2023 10:52:28 +0200 Subject: [PATCH 04/17] Fix CI --- .../CGAL/IO/Triangulation_raw_iostream_3.h | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h index b64aebf1c2f2..c6d04e857a38 100644 --- a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -233,7 +233,6 @@ bool write_cells(std::ostream& os, const Triangulation_3& tr, cons return false; } - template < class GT, class Tds, class Lds > bool read_cells(std::istream& is, Triangulation_3& tr, const std::vector< typename Tds::Vertex_handle >& vertices_handles) { @@ -266,13 +265,6 @@ bool read_cells(std::istream& is, Triangulation_3& tr, const std:: } // end namespace internal -template < class GT, class Tds, class Lds > -bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr) -{ - Unique_hash_map vertices_map; - return export_triangulation_3(os, tr, vertices_map); -} - template < class GT, class Tds, class Lds > bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr, Unique_hash_map& vertices_map) { @@ -297,14 +289,14 @@ bool export_triangulation_3(std::ostream& os, const Triangulation_3 -bool import_triangulation_3(std::istream& is, Triangulation_3& tr) +bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr) { - std::vector vertices_handles; - return import_triangulation_3(is, tr, vertices_handles); + Unique_hash_map vertices_map; + return export_triangulation_3(os, tr, vertices_map); } + template < class GT, class Tds, class Lds > bool import_triangulation_3(std::istream& is, Triangulation_3& tr, std::vector& vertices_handles) { @@ -334,6 +326,12 @@ bool import_triangulation_3(std::istream& is, Triangulation_3& tr, return result; } +template < class GT, class Tds, class Lds > +bool import_triangulation_3(std::istream& is, Triangulation_3& tr) +{ + std::vector vertices_handles; + return import_triangulation_3(is, tr, vertices_handles); +} } // end namespace IO From 759723c4406c2e6847b53be69ff2c295184582cb Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 26 Oct 2023 10:17:25 +0200 Subject: [PATCH 05/17] Remove duplication of code : Triangulation_3 file_input now uses the new IO --- .../CGAL/IO/Triangulation_raw_iostream_3.h | 86 +++++++++++++++---- .../include/CGAL/Triangulation_3.h | 69 +++------------ 2 files changed, 83 insertions(+), 72 deletions(-) diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h index c6d04e857a38..d7ce83ef4a53 100644 --- a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -120,8 +120,22 @@ bool write_vertices(std::ostream& os, const Triangulation_3& tr) return (bool)os; } -template < class GT, class Tds, class Lds > -bool read_vertices(std::istream& is, Triangulation_3& tr, std::vector< typename Tds::Vertex_handle >& vertices_handles) +struct IdentityConvertVertex +{ + template + void operator()(const V& v_input, V& v_output) + { + auto time_stamp_ = v_output.time_stamp(); + v_output = v_input; + v_output.set_time_stamp(time_stamp_); + } +}; + +template < class GT, class Tds, class Lds, + typename Tr_src = Triangulation_3, + typename ConvertVertex = IdentityConvertVertex > +bool read_vertices(std::istream& is, Triangulation_3& tr, std::vector< typename Tds::Vertex_handle >& vertices_handles, + ConvertVertex convert_vertex = ConvertVertex()) { // Reads: // - the number of finite vertices @@ -129,6 +143,8 @@ bool read_vertices(std::istream& is, Triangulation_3& tr, std::vec typedef Triangulation_3 Triangulation; typedef typename Triangulation::size_type size_type; + typedef typename Tr_src::Vertex Vertex1; + size_type n; if(IO::is_ascii(is)) { @@ -146,9 +162,11 @@ bool read_vertices(std::istream& is, Triangulation_3& tr, std::vec for(std::size_t i=1; i <= n; i++) { - vertices_handles[i] = tr.tds().create_vertex(); - if(!(is >> *vertices_handles[i])) + Vertex1 v; + if(!(is >> v)) return false; + vertices_handles[i] = tr.tds().create_vertex(); + convert_vertex(v, *vertices_handles[i]); } return (bool)is; @@ -233,8 +251,23 @@ bool write_cells(std::ostream& os, const Triangulation_3& tr, cons return false; } -template < class GT, class Tds, class Lds > -bool read_cells(std::istream& is, Triangulation_3& tr, const std::vector< typename Tds::Vertex_handle >& vertices_handles) +struct IdentityConvertCell +{ + template + void operator()(const C& c_input, C& c_output) + { + c_output.set_subdomain_index(c_input.subdomain_index()); + for(int i = 0; i < 4; ++i) { + c_output.set_surface_patch_index(i, c_input.surface_patch_index(i)); + } + } +}; + +template < class GT, class Tds, class Lds, + typename Tr_src = Triangulation_3, + typename ConvertCell = IdentityConvertCell > +bool read_cells(std::istream& is, Triangulation_3& tr, const std::vector< typename Tds::Vertex_handle >& vertices_handles, + ConvertCell convert_cell = ConvertCell()) { // Writes: // [Call to Tds::print_cells] @@ -248,6 +281,8 @@ bool read_cells(std::istream& is, Triangulation_3& tr, const std:: typedef Triangulation_3 Triangulation; typedef typename Triangulation::Cell_handle Cell_handle; + typedef typename Tr_src::Cell Cell1; + std::vector< Cell_handle > C; std::size_t m; @@ -256,8 +291,12 @@ bool read_cells(std::istream& is, Triangulation_3& tr, const std:: return false; for(std::size_t i=0 ; i < m; i++) - if(!(is >> *(C[i]))) + { + Cell1 c; + if(!(is >> c)) return false; + convert_cell(c, *C[i]); + } return (bool)is; } @@ -289,16 +328,26 @@ bool export_triangulation_3(std::ostream& os, const Triangulation_3 -bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr) +template < class GT, class Tds, class Lds, + typename Tr_src = Triangulation_3, + typename ConvertVertex = internal::IdentityConvertVertex, + typename ConvertCell = internal::IdentityConvertCell > +bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr, + ConvertVertex convert_vertex = ConvertVertex(), + ConvertCell convert_cell = ConvertCell()) { Unique_hash_map vertices_map; - return export_triangulation_3(os, tr, vertices_map); + return export_triangulation_3(os, tr, vertices_map, convert_vertex, convert_cell); } -template < class GT, class Tds, class Lds > -bool import_triangulation_3(std::istream& is, Triangulation_3& tr, std::vector& vertices_handles) +template < class GT, class Tds, class Lds, + typename Tr_src = Triangulation_3, + typename ConvertVertex = internal::IdentityConvertVertex, + typename ConvertCell = internal::IdentityConvertCell > +bool import_triangulation_3(std::istream& is, Triangulation_3& tr, std::vector& vertices_handles, + ConvertVertex convert_vertex = ConvertVertex(), + ConvertCell convert_cell = ConvertCell()) { // Reads: // [Header] @@ -322,15 +371,20 @@ bool import_triangulation_3(std::istream& is, Triangulation_3& tr, && internal::read_vertices(is, tr, vertices_handles) && internal::read_cells(is, tr, vertices_handles); - CGAL_assertion(tr.is_valid(false)); + CGAL_assertion(result && tr.is_valid(true)); return result; } -template < class GT, class Tds, class Lds > -bool import_triangulation_3(std::istream& is, Triangulation_3& tr) +template < class GT, class Tds, class Lds, + typename Tr_src = Triangulation_3, + typename ConvertVertex = internal::IdentityConvertVertex, + typename ConvertCell = internal::IdentityConvertCell > +bool import_triangulation_3(std::istream& is, Triangulation_3& tr, + ConvertVertex convert_vertex = ConvertVertex(), + ConvertCell convert_cell = ConvertCell()) { std::vector vertices_handles; - return import_triangulation_3(is, tr, vertices_handles); + return import_triangulation_3(is, tr, vertices_handles, convert_vertex, convert_cell); } diff --git a/Triangulation_3/include/CGAL/Triangulation_3.h b/Triangulation_3/include/CGAL/Triangulation_3.h index 9a9bcd86d1c4..b4689ab77382 100644 --- a/Triangulation_3/include/CGAL/Triangulation_3.h +++ b/Triangulation_3/include/CGAL/Triangulation_3.h @@ -2312,66 +2312,23 @@ class Triangulation_3 ConvertVertex convert_vertex = ConvertVertex(), ConvertCell convert_cell = ConvertCell()) { - // reads - // the dimension - // the number of finite vertices - // the non combinatorial information on vertices (point, etc) - // the number of cells - // the cells by the indices of their vertices in the preceding list - // of vertices, plus the non combinatorial information on each cell - // the neighbors of each cell by their index in the preceding list of cells - // when dimension < 3 : the same with faces of maximal dimension + // Reads: + // - the dimension + // - the number of finite vertices + // - the non combinatorial information on vertices (point, etc) + // - the number of cells + // - the cells by the indices of their vertices in the preceding list + // of vertices, plus the non combinatorial information on each cell + // - the neighbors of each cell by their index in the preceding list of cells + // - when dimension < 3 : the same with faces of maximal dimension // If this is used for a TDS, the vertices are processed from 0 to n. // Else, we make V[0] the infinite vertex and work from 1 to n+1. - typedef Self Triangulation; - typedef typename Triangulation::Vertex_handle Vertex_handle; - typedef typename Triangulation::Cell_handle Cell_handle; - - typedef typename Tr_src::Vertex Vertex1; - typedef typename Tr_src::Cell Cell1; - - clear(); - tds().cells().clear(); - - std::size_t n; - int d; - if(IO::is_ascii(is)) - is >> d >> n; - else { - read(is, d); - read(is, n); - } - if(!is) return is; - tds().set_dimension(d); - - std::size_t V_size = n+1; - std::vector< Vertex_handle > V(V_size); - - // the infinite vertex is numbered 0 - V[0] = infinite_vertex(); - - for (std::size_t i = 1; i < V_size; ++i) { - Vertex1 v; - if(!(is >> v)) return is; - Vertex_handle vh=tds().create_vertex( convert_vertex(v) ); - V[i] = vh; - convert_vertex(v, *V[i]); - } - - std::vector< Cell_handle > C; - - std::size_t m; - tds().read_cells(is, V, m, C); - - for (std::size_t j=0 ; j < m; j++) { - Cell1 c; - if(!(is >> c)) return is; - convert_cell(c, *C[j]); - } - - CGAL_assertion( is_valid(false) ); + if (!CGAL::IO::import_triangulation_3 + (is, *this, convert_vertex, convert_cell)) + is.setstate(std::ios_base::failbit); return is; } }; From 06fa376a79c7d7e79cf868f3d79dec4c8285e4d7 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 26 Oct 2023 13:56:06 +0200 Subject: [PATCH 06/17] Made demo use new saving features + Fix CI --- .../Plugins/Mesh_3/C3t3_io_plugin.cpp | 4 +- .../CGAL/Mesh_complex_3_in_triangulation_3.h | 104 +++++++++++++----- .../CGAL/IO/Triangulation_raw_iostream_3.h | 15 +-- .../include/CGAL/Triangulation_3.h | 17 ++- 4 files changed, 100 insertions(+), 40 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp index f333590a8643..0cec41713fe9 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp @@ -510,7 +510,7 @@ try_load_a_cdt_3(std::istream& is, C3t3& c3t3) } } if(binary) CGAL::IO::set_binary_mode(is); - if(c3t3.triangulation().file_input< + if(c3t3.file_input< Fake_CDT_3, Update_vertex_from_CDT_3, Update_cell_from_CDT_3>(is)) @@ -597,7 +597,7 @@ try_load_other_binary_format(std::istream& is, C3t3& c3t3) } if(binary) CGAL::IO::set_binary_mode(is); else CGAL::IO::set_ascii_mode(is); - std::istream& f_is = c3t3.triangulation().file_input< + std::istream& f_is = c3t3.file_input< Fake_c3t3::Triangulation, Update_vertex, Update_cell>(is); diff --git a/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h b/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h index b346427704c1..c4295587d784 100644 --- a/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h +++ b/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h @@ -1216,6 +1216,79 @@ class Mesh_complex_3_in_triangulation_3 return Get_io_signature()(); } + std::istream& read_edges(std::istream& is, const std::vector< Vertex_handle >& vertices_handles) + { + // Reads 1D features + std::size_t nEdges; + if(IO::is_ascii(is)) + { + is >> nEdges; + } + else + { + read(is, nEdges); + } + // If the file did not have edges + if (!is) { + return is; + } + + for (std::size_t i = 0; i < nEdges; i++) + { + std::size_t iv1; + std::size_t iv2; + Curve_index index; + if (IO::is_ascii(is)) + is >> iv1 >> iv2 >> index; + else { + read(is, iv1); + read(is, iv2); + read(is, index); + } + Internal_edge edge(vertices_handles[iv1], vertices_handles[iv2]); + add_to_complex(edge, index); + } + return is; + } + + template + std::istream& file_input(std::istream& is, + ConvertVertex convert_vertex = ConvertVertex(), + ConvertCell convert_cell = ConvertCell()) + { + // Reads: + // - the dimension + // - the number of finite vertices + // - the non combinatorial information on vertices (point, etc) + // - the number of cells + // - the cells by the indices of their vertices in the preceding list + // of vertices, plus the non combinatorial information on each cell + // - the neighbors of each cell by their index in the preceding list of cells + // - when dimension < 3 : the same with faces of maximal dimension + // - the number of edges + // - the edges by the indices of their vertices and their curve_index + + // If this is used for a TDS, the vertices are processed from 0 to n. + // Else, we make V[0] the infinite vertex and work from 1 to n+1. + + // Reads triangulation + std::vector< Vertex_handle > vertices_handles; + if (!tr_.template file_input + (is, vertices_handles, convert_vertex, convert_cell)) + { + clear(); + is.setstate(std::ios_base::failbit); + return is; + } + + // Reads 1D Features + read_edges(is, vertices_handles); + + return is; + } + /** * @cond SKIP_IN_MANUAL * creates an `Internal_edge` object (i.e a pair of ordered `Vertex_handle`) @@ -2183,36 +2256,9 @@ operator>> (std::istream& is, return is; } - // Reads 1D features - std::size_t nEdges; - if(IO::is_ascii(is)) - { - is >> nEdges; - } - else - { - read(is, nEdges); - } - // If the file did not have edges - if (!is) { + c3t3.read_edges(is, vertices_handles); + if (!is) return is; - } - - for (std::size_t i = 0; i < nEdges; i++) - { - std::size_t iv1; - std::size_t iv2; - Curve_index index; - if (IO::is_ascii(is)) - is >> iv1 >> iv2 >> index; - else { - read(is, iv1); - read(is, iv2); - read(is, index); - } - Internal_edge edge(vertices_handles[iv1], vertices_handles[iv2]); - c3t3.add_to_complex(edge, index); - } c3t3.rescan_after_load_of_triangulation(); return is; diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h index d7ce83ef4a53..8fac4dcda927 100644 --- a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -332,12 +332,10 @@ template < class GT, class Tds, class Lds, typename Tr_src = Triangulation_3, typename ConvertVertex = internal::IdentityConvertVertex, typename ConvertCell = internal::IdentityConvertCell > -bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr, - ConvertVertex convert_vertex = ConvertVertex(), - ConvertCell convert_cell = ConvertCell()) +bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr) { Unique_hash_map vertices_map; - return export_triangulation_3(os, tr, vertices_map, convert_vertex, convert_cell); + return export_triangulation_3(os, tr, vertices_map); } @@ -368,8 +366,10 @@ bool import_triangulation_3(std::istream& is, Triangulation_3& tr, tr.set_infinite_vertex(tr.tds().create_vertex()); bool result = internal::read_header(is, tr) - && internal::read_vertices(is, tr, vertices_handles) - && internal::read_cells(is, tr, vertices_handles); + && internal::read_vertices + (is, tr, vertices_handles, convert_vertex) + && internal::read_cells + (is, tr, vertices_handles, convert_cell); CGAL_assertion(result && tr.is_valid(true)); return result; @@ -384,7 +384,8 @@ bool import_triangulation_3(std::istream& is, Triangulation_3& tr, ConvertCell convert_cell = ConvertCell()) { std::vector vertices_handles; - return import_triangulation_3(is, tr, vertices_handles, convert_vertex, convert_cell); + return import_triangulation_3 + (is, tr, vertices_handles, convert_vertex, convert_cell); } diff --git a/Triangulation_3/include/CGAL/Triangulation_3.h b/Triangulation_3/include/CGAL/Triangulation_3.h index b4689ab77382..5b25c2d09b0c 100644 --- a/Triangulation_3/include/CGAL/Triangulation_3.h +++ b/Triangulation_3/include/CGAL/Triangulation_3.h @@ -2308,7 +2308,7 @@ class Triangulation_3 template - std::istream& file_input(std::istream& is, + std::istream& file_input(std::istream& is, std::vector< Vertex_handle >& vertices_handles, ConvertVertex convert_vertex = ConvertVertex(), ConvertCell convert_cell = ConvertCell()) { @@ -2327,10 +2327,23 @@ class Triangulation_3 if (!CGAL::IO::import_triangulation_3 - (is, *this, convert_vertex, convert_cell)) + (is, *this, vertices_handles, convert_vertex, convert_cell)) is.setstate(std::ios_base::failbit); return is; } + + //IO + template + std::istream& file_input(std::istream& is, + ConvertVertex convert_vertex = ConvertVertex(), + ConvertCell convert_cell = ConvertCell()) + { + std::vector< Vertex_handle > vertices_handles; + file_input(is, vertices_handles, convert_vertex, convert_cell); + return is; + } }; From e85cb39cdd544660e55855dc81c6753b48c623c1 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 2 Nov 2023 09:28:15 +0100 Subject: [PATCH 07/17] Moved triangulation forward declaration --- .../include/CGAL/Mesh_3/Triangulation_3_fwd.h | 29 +++++++ .../mesh_3D_image_with_input_features.cpp | 83 +++++++++++++++++-- .../CGAL/IO/Triangulation_raw_iostream_3.h | 23 +++-- .../include/CGAL/Triangulation_3.h | 7 +- 4 files changed, 115 insertions(+), 27 deletions(-) create mode 100644 Installation/include/CGAL/Mesh_3/Triangulation_3_fwd.h diff --git a/Installation/include/CGAL/Mesh_3/Triangulation_3_fwd.h b/Installation/include/CGAL/Mesh_3/Triangulation_3_fwd.h new file mode 100644 index 000000000000..ee3a088b2b95 --- /dev/null +++ b/Installation/include/CGAL/Mesh_3/Triangulation_3_fwd.h @@ -0,0 +1,29 @@ +// Copyright (c) 1999-2003 INRIA Sophia-Antipolis (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) : Monique Teillaud +// Sylvain Pion +// Clement Jamin + +#ifndef CGAL_MESH_3_TRIANGULATION_3_FWD_H +#define CGAL_MESH_3_TRIANGULATION_3_FWD_H + +#include + +#include + +namespace CGAL { + +template < class GT, class Tds = Default, + class Lock_data_structure = Default > +class Triangulation_3; + +} // end namespace CGAL + +#endif // CGAL_MESH_3_TRIANGULATION_3_FWD_H diff --git a/Mesh_3/examples/Mesh_3/mesh_3D_image_with_input_features.cpp b/Mesh_3/examples/Mesh_3/mesh_3D_image_with_input_features.cpp index 8a83efae986d..d70b1e55de9e 100644 --- a/Mesh_3/examples/Mesh_3/mesh_3D_image_with_input_features.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_3D_image_with_input_features.cpp @@ -13,6 +13,8 @@ #include #include +#include + typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Labeled_mesh_domain_3 Image_domain; typedef CGAL::Mesh_domain_with_polyline_features_3 Mesh_domain; @@ -62,21 +64,84 @@ int main(int argc, char* argv[]) /// [Domain creation] /// Note that `edge_size` is needed with 1D-features [Mesh criteria] - Mesh_criteria criteria(params::edge_size = 6, - params::facet_angle = 30, - params::facet_size = 6, - params::facet_distance = 4, - params::cell_radius_edge_ratio = 3, - params::cell_size = 8); + Mesh_criteria criteria(params::edge_size = 6//, +// params::facet_angle = 30, +// params::facet_size = 6, +// params::facet_distance = 4, +// params::cell_radius_edge_ratio = 3, +// params::cell_size = 8 + ); /// [Mesh criteria] // Meshing C3t3 c3t3 = CGAL::make_mesh_3(domain, criteria); // Output - std::ofstream medit_file("out.mesh"); - CGAL::IO::write_MEDIT(medit_file, c3t3); - medit_file.close(); +// std::ofstream medit_file("out.mesh"); +// CGAL::IO::write_MEDIT(medit_file, c3t3); +// medit_file.close(); +// CGAL::dump_c3t3(c3t3, "out"); + + std::cout << "Saving" << std::endl; + std::ofstream output_file("out.mesh"); + CGAL::IO::save_binary_file(output_file, c3t3, /*binary=*/false); +// output_file << c3t3; + output_file.close(); + std::cout << "Saved" << std::endl; + + std::cout << "Saving binary" << std::endl; + std::ofstream output_bin_file("out_bin.mesh", std::ios_base::binary); + CGAL::IO::save_binary_file(output_bin_file, c3t3, /*binary=*/true); + output_bin_file.close(); + std::cout << "Saved" << std::endl; + + std::cout << "Reading" << std::endl; + C3t3 readC3t3; + std::ifstream read_file("out.mesh", std::ios_base::binary); + CGAL::IO::load_binary_file(read_file, readC3t3); +// read_file >> readC3t3; + read_file.close(); + std::cout << "Read" << std::endl; + + std::cout << "Saveing the read" << std::endl; + std::ofstream output_read_file("out_read.mesh"); + CGAL::IO::save_binary_file(output_read_file, readC3t3, /*binary=*/false); +// output_read_file << readC3t3; + output_read_file.close(); + std::cout << "Saved the read" << std::endl; + + std::cout << "Compare original and read" << std::endl; + std::ifstream read_file_wr("out.mesh"); + std::ifstream read_file_re("out_read.mesh"); + int line = 0; + int col = 0; + while (read_file_wr && read_file_re) + { + char c1; + char c2; + read_file_wr >> c1; + read_file_re >> c2; + if (c1 != c2) + { + std::cout << "Different (" << line << ", " << col << " ): " + << c1 << " (" << (int)c1 << ") != " + << c2 << " (" << (int)c2 << ")" << std::endl; + return EXIT_FAILURE; + } + if (c1 == '\n') { + line++; + col = 0; + } + else { + col++; + } + } + if (read_file_wr || read_file_re) + { + std::cout << "Different : not same length" << std::endl; + return EXIT_FAILURE; + } + std::cout << "All good" << std::endl; return EXIT_SUCCESS; } diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h index 8fac4dcda927..eee5edddd677 100644 --- a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -1,17 +1,20 @@ -// Copyright (c) 20XX,20XX GeometryFactory +// Copyright (c) 1999-2003 INRIA Sophia-Antipolis (France). // All rights reserved. // -// This file is part of CGAL (www.cgal.org) +// This file is part of CGAL (www.cgal.org). // // $URL$ // $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Ange Clément +// Author(s) : Monique Teillaud +// Sylvain Pion +// Clement Jamin +// Ange Clement -#ifndef CGAL_TRIANGULATION_RAW_IOSTREAM_3_H -#define CGAL_TRIANGULATION_RAW_IOSTREAM_3_H +#ifndef CGAL_IO_TRIANGULATION_RAW_IOSTREAM_3_H +#define CGAL_IO_TRIANGULATION_RAW_IOSTREAM_3_H #include @@ -19,15 +22,11 @@ #include #include -#include #include +#include namespace CGAL { -template < class GT, class Tds = Default, - class Lock_data_structure = Default > -class Triangulation_3; - namespace IO { namespace internal { @@ -393,4 +392,4 @@ bool import_triangulation_3(std::istream& is, Triangulation_3& tr, } // end namespace CGAL -#endif // CGAL_TRIANGULATION_RAW_IOSTREAM_3_H +#endif // CGAL_IO_TRIANGULATION_RAW_IOSTREAM_3_H diff --git a/Triangulation_3/include/CGAL/Triangulation_3.h b/Triangulation_3/include/CGAL/Triangulation_3.h index 5b25c2d09b0c..416f7c533fb0 100644 --- a/Triangulation_3/include/CGAL/Triangulation_3.h +++ b/Triangulation_3/include/CGAL/Triangulation_3.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -83,12 +84,6 @@ namespace CGAL { -#ifndef CGAL_TRIANGULATION_RAW_IOSTREAM_3_H -template < class GT, class Tds = Default, - class Lock_data_structure = Default > -class Triangulation_3; -#endif - template < class GT, class Tds, class Lds > std::istream& operator>> (std::istream& is, Triangulation_3& tr); From 660c88a707ef4c9701a6959a495a3bb1295d8a53 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 2 Nov 2023 11:27:42 +0100 Subject: [PATCH 08/17] Added compability + Removed unused type aliases + Removed the need for default convertor --- .../CGAL/Mesh_complex_3_in_triangulation_3.h | 16 +- .../CGAL/IO/Triangulation_raw_iostream_3.h | 144 ++++++++++++------ 2 files changed, 115 insertions(+), 45 deletions(-) diff --git a/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h b/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h index c4295587d784..9bcb9a3d47c2 100644 --- a/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h +++ b/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h @@ -1285,6 +1285,14 @@ class Mesh_complex_3_in_triangulation_3 // Reads 1D Features read_edges(is, vertices_handles); + // To keep compatibility with previous files, + // the istream errors should be cleared and the progress reversed + if (!is) + { + is.clear(); + edges_.clear(); + return is; + } return is; } @@ -2242,8 +2250,6 @@ operator>> (std::istream& is, */ using C3t3 = Mesh_complex_3_in_triangulation_3; using Vertex_handle = typename C3t3::Vertex_handle; - using Curve_index = typename C3t3::Curve_index; - using Internal_edge = typename C3t3::Internal_edge; c3t3.clear(); @@ -2257,8 +2263,14 @@ operator>> (std::istream& is, } c3t3.read_edges(is, vertices_handles); + // To keep compatibility with previous files, + // the istream errors should be cleared and the progress reversed if (!is) + { + is.clear(); + c3t3.edges_.clear(); return is; + } c3t3.rescan_after_load_of_triangulation(); return is; diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h index eee5edddd677..d235559fe35a 100644 --- a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -119,20 +119,58 @@ bool write_vertices(std::ostream& os, const Triangulation_3& tr) return (bool)os; } -struct IdentityConvertVertex +template < class GT, class Tds, class Lds, + typename Tr_src = Triangulation_3, + typename ConvertVertex = Nullptr_t > +struct read_vertices_functor { - template - void operator()(const V& v_input, V& v_output) + bool operator()(std::istream& is, Triangulation_3& tr, std::vector< typename Tds::Vertex_handle >& vertices_handles, + typename Triangulation_3::size_type n, + ConvertVertex convert_vertex = ConvertVertex()) { - auto time_stamp_ = v_output.time_stamp(); - v_output = v_input; - v_output.set_time_stamp(time_stamp_); + // Reads: + // - the non combinatorial information on vertices (point, etc) + // The vertices are read with the type Tr_src::Vertex + // and converted to type Triangulation_3::Vertex + // using the ConvertVertex convertor. + typedef typename Tr_src::Vertex Vertex1; + + for(std::size_t i=1; i <= n; i++) + { + Vertex1 v; + if(!(is >> v)) + return false; + vertices_handles[i] = tr.tds().create_vertex(); + convert_vertex(v, *vertices_handles[i]); + } + + return (bool)is; } }; +template < class GT, class Tds, class Lds, class Tr_src > +struct read_vertices_functor < GT, Tds, Lds, Tr_src, Nullptr_t > +{ + bool operator()(std::istream& is, Triangulation_3& tr, std::vector< typename Tds::Vertex_handle >& vertices_handles, + typename Triangulation_3::size_type n, + Nullptr_t _ = Nullptr_t()) + { + // Reads: + // - the non combinatorial information on vertices (point, etc) + for(std::size_t i=1; i <= n; i++) + { + vertices_handles[i] = tr.tds().create_vertex(); + if(!(is >> *vertices_handles[i])) + return false; + } + return (bool)is; + } +}; + + template < class GT, class Tds, class Lds, typename Tr_src = Triangulation_3, - typename ConvertVertex = IdentityConvertVertex > + typename ConvertVertex = Nullptr_t > bool read_vertices(std::istream& is, Triangulation_3& tr, std::vector< typename Tds::Vertex_handle >& vertices_handles, ConvertVertex convert_vertex = ConvertVertex()) { @@ -142,8 +180,6 @@ bool read_vertices(std::istream& is, Triangulation_3& tr, std::vec typedef Triangulation_3 Triangulation; typedef typename Triangulation::size_type size_type; - typedef typename Tr_src::Vertex Vertex1; - size_type n; if(IO::is_ascii(is)) { @@ -159,14 +195,8 @@ bool read_vertices(std::istream& is, Triangulation_3& tr, std::vec vertices_handles.resize(n+1); vertices_handles[0] = tr.infinite_vertex(); // the infinite vertex is numbered 0 - for(std::size_t i=1; i <= n; i++) - { - Vertex1 v; - if(!(is >> v)) - return false; - vertices_handles[i] = tr.tds().create_vertex(); - convert_vertex(v, *vertices_handles[i]); - } + if (!read_vertices_functor()(is, tr, vertices_handles, n, convert_vertex)) + return false; return (bool)is; } @@ -250,26 +280,64 @@ bool write_cells(std::ostream& os, const Triangulation_3& tr, cons return false; } -struct IdentityConvertCell + +template < class GT, class Tds, class Lds, + typename Tr_src = Triangulation_3, + typename ConvertCell = Nullptr_t > +struct read_cells_functor +{ + bool operator()(std::istream& is, Triangulation_3& tr, const std::vector< typename Tds::Vertex_handle >& vertices_handles, + typename Triangulation_3::size_type m, std::vector< typename Triangulation_3::Cell_handle >& C, + ConvertCell convert_cell = ConvertCell()) + { + // Reads: + // [Cells other info] + // - when dimension < 3 : the same with faces of maximal dimension + // The cell are read with the type Tr_src::Cell + // and converted to type Triangulation_3::Cell + // using the ConvertCell convertor. + + typedef typename Tr_src::Cell Cell1; + + for(std::size_t i=0 ; i < m; i++) + { + Cell1 c; + if(!(is >> c)) + return false; + convert_cell(c, *C[i]); + } + + return (bool)is; + } +}; + +template < class GT, class Tds, class Lds, class Tr_src > +struct read_cells_functor < GT, Tds, Lds, Tr_src, Nullptr_t > { - template - void operator()(const C& c_input, C& c_output) + bool operator()(std::istream& is, Triangulation_3& tr, const std::vector< typename Tds::Vertex_handle >& vertices_handles, + typename Triangulation_3::size_type m, std::vector< typename Triangulation_3::Cell_handle >& C, + Nullptr_t _ = Nullptr_t()) { - c_output.set_subdomain_index(c_input.subdomain_index()); - for(int i = 0; i < 4; ++i) { - c_output.set_surface_patch_index(i, c_input.surface_patch_index(i)); + // Reads: + // - the non combinatorial information on vertices (point, etc) + for(std::size_t i=0 ; i < m; i++) + { + if(!(is >> *C[i])) + return false; } + + return (bool)is; } }; template < class GT, class Tds, class Lds, typename Tr_src = Triangulation_3, - typename ConvertCell = IdentityConvertCell > + typename ConvertCell = Nullptr_t > bool read_cells(std::istream& is, Triangulation_3& tr, const std::vector< typename Tds::Vertex_handle >& vertices_handles, ConvertCell convert_cell = ConvertCell()) { - // Writes: - // [Call to Tds::print_cells] + // Reads: + // [Call to Tds::read_cells] // - the number of cells // - the cells by the indices of their vertices in the preceding list // of vertices, plus the non combinatorial information on each cell @@ -280,8 +348,6 @@ bool read_cells(std::istream& is, Triangulation_3& tr, const std:: typedef Triangulation_3 Triangulation; typedef typename Triangulation::Cell_handle Cell_handle; - typedef typename Tr_src::Cell Cell1; - std::vector< Cell_handle > C; std::size_t m; @@ -289,13 +355,8 @@ bool read_cells(std::istream& is, Triangulation_3& tr, const std:: if(!is) return false; - for(std::size_t i=0 ; i < m; i++) - { - Cell1 c; - if(!(is >> c)) - return false; - convert_cell(c, *C[i]); - } + if (!read_cells_functor()(is, tr, vertices_handles, m, C, convert_cell)) + return false; return (bool)is; } @@ -327,10 +388,7 @@ bool export_triangulation_3(std::ostream& os, const Triangulation_3, - typename ConvertVertex = internal::IdentityConvertVertex, - typename ConvertCell = internal::IdentityConvertCell > +template < class GT, class Tds, class Lds > bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr) { Unique_hash_map vertices_map; @@ -340,8 +398,8 @@ bool export_triangulation_3(std::ostream& os, const Triangulation_3, - typename ConvertVertex = internal::IdentityConvertVertex, - typename ConvertCell = internal::IdentityConvertCell > + typename ConvertVertex = Nullptr_t, + typename ConvertCell = Nullptr_t > bool import_triangulation_3(std::istream& is, Triangulation_3& tr, std::vector& vertices_handles, ConvertVertex convert_vertex = ConvertVertex(), ConvertCell convert_cell = ConvertCell()) @@ -376,8 +434,8 @@ bool import_triangulation_3(std::istream& is, Triangulation_3& tr, template < class GT, class Tds, class Lds, typename Tr_src = Triangulation_3, - typename ConvertVertex = internal::IdentityConvertVertex, - typename ConvertCell = internal::IdentityConvertCell > + typename ConvertVertex = Nullptr_t, + typename ConvertCell = Nullptr_t > bool import_triangulation_3(std::istream& is, Triangulation_3& tr, ConvertVertex convert_vertex = ConvertVertex(), ConvertCell convert_cell = ConvertCell()) From 083b7632ebf40a71aa009bd05aad98c3477884be Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 2 Nov 2023 12:26:51 +0100 Subject: [PATCH 09/17] Revert example change --- .../mesh_3D_image_with_input_features.cpp | 83 ++----------------- 1 file changed, 9 insertions(+), 74 deletions(-) diff --git a/Mesh_3/examples/Mesh_3/mesh_3D_image_with_input_features.cpp b/Mesh_3/examples/Mesh_3/mesh_3D_image_with_input_features.cpp index d70b1e55de9e..8a83efae986d 100644 --- a/Mesh_3/examples/Mesh_3/mesh_3D_image_with_input_features.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_3D_image_with_input_features.cpp @@ -13,8 +13,6 @@ #include #include -#include - typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Labeled_mesh_domain_3 Image_domain; typedef CGAL::Mesh_domain_with_polyline_features_3 Mesh_domain; @@ -64,84 +62,21 @@ int main(int argc, char* argv[]) /// [Domain creation] /// Note that `edge_size` is needed with 1D-features [Mesh criteria] - Mesh_criteria criteria(params::edge_size = 6//, -// params::facet_angle = 30, -// params::facet_size = 6, -// params::facet_distance = 4, -// params::cell_radius_edge_ratio = 3, -// params::cell_size = 8 - ); + Mesh_criteria criteria(params::edge_size = 6, + params::facet_angle = 30, + params::facet_size = 6, + params::facet_distance = 4, + params::cell_radius_edge_ratio = 3, + params::cell_size = 8); /// [Mesh criteria] // Meshing C3t3 c3t3 = CGAL::make_mesh_3(domain, criteria); // Output -// std::ofstream medit_file("out.mesh"); -// CGAL::IO::write_MEDIT(medit_file, c3t3); -// medit_file.close(); -// CGAL::dump_c3t3(c3t3, "out"); - - std::cout << "Saving" << std::endl; - std::ofstream output_file("out.mesh"); - CGAL::IO::save_binary_file(output_file, c3t3, /*binary=*/false); -// output_file << c3t3; - output_file.close(); - std::cout << "Saved" << std::endl; - - std::cout << "Saving binary" << std::endl; - std::ofstream output_bin_file("out_bin.mesh", std::ios_base::binary); - CGAL::IO::save_binary_file(output_bin_file, c3t3, /*binary=*/true); - output_bin_file.close(); - std::cout << "Saved" << std::endl; - - std::cout << "Reading" << std::endl; - C3t3 readC3t3; - std::ifstream read_file("out.mesh", std::ios_base::binary); - CGAL::IO::load_binary_file(read_file, readC3t3); -// read_file >> readC3t3; - read_file.close(); - std::cout << "Read" << std::endl; - - std::cout << "Saveing the read" << std::endl; - std::ofstream output_read_file("out_read.mesh"); - CGAL::IO::save_binary_file(output_read_file, readC3t3, /*binary=*/false); -// output_read_file << readC3t3; - output_read_file.close(); - std::cout << "Saved the read" << std::endl; - - std::cout << "Compare original and read" << std::endl; - std::ifstream read_file_wr("out.mesh"); - std::ifstream read_file_re("out_read.mesh"); - int line = 0; - int col = 0; - while (read_file_wr && read_file_re) - { - char c1; - char c2; - read_file_wr >> c1; - read_file_re >> c2; - if (c1 != c2) - { - std::cout << "Different (" << line << ", " << col << " ): " - << c1 << " (" << (int)c1 << ") != " - << c2 << " (" << (int)c2 << ")" << std::endl; - return EXIT_FAILURE; - } - if (c1 == '\n') { - line++; - col = 0; - } - else { - col++; - } - } - if (read_file_wr || read_file_re) - { - std::cout << "Different : not same length" << std::endl; - return EXIT_FAILURE; - } - std::cout << "All good" << std::endl; + std::ofstream medit_file("out.mesh"); + CGAL::IO::write_MEDIT(medit_file, c3t3); + medit_file.close(); return EXIT_SUCCESS; } From f7344e5cd3968f319805774afa0d63ee62e5f9ee Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 2 Nov 2023 12:39:08 +0100 Subject: [PATCH 10/17] Deleted redundant checks --- .../demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp index 0cec41713fe9..513b4100ccb6 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp @@ -499,9 +499,6 @@ try_load_a_cdt_3(std::istream& is, C3t3& c3t3) } std::getline(is, s); if(s != "") { - if(s[s.size()-1] == '\r') { // deal with Windows EOL - s.resize(s.size() - 1); - } if(s != std::string(" ") + CGAL::Get_io_signature()()) { std::cerr << "load_binary_file:" << "\n expected format: " << CGAL::Get_io_signature()() @@ -585,9 +582,6 @@ try_load_other_binary_format(std::istream& is, C3t3& c3t3) } std::getline(is, s); if(s != "") { - if(s[s.size()-1] == '\r') { // deal with Windows EOL - s.resize(s.size() - 1); - } if(s != std::string(" ") + CGAL::Get_io_signature()()) { std::cerr << "Polyhedron_demo_c3t3_binary_io_plugin::try_load_other_binary_format:" << "\n expected format: " << CGAL::Get_io_signature()() From 960a8424cf471746cc701df1c5c40c28396fccdb Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 2 Nov 2023 15:36:26 +0100 Subject: [PATCH 11/17] Fix for triangulation_3 tests + maybe Fix license --- .../CGAL/IO/Triangulation_raw_iostream_3.h | 148 ++++++++++-------- 1 file changed, 79 insertions(+), 69 deletions(-) diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h index d235559fe35a..702e14011469 100644 --- a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -10,7 +10,6 @@ // Author(s) : Monique Teillaud // Sylvain Pion // Clement Jamin -// Ange Clement #ifndef CGAL_IO_TRIANGULATION_RAW_IOSTREAM_3_H @@ -31,12 +30,13 @@ namespace IO { namespace internal { -template < class GT, class Tds, class Lds > -bool construct_vertices_map(const Triangulation_3& tr, Unique_hash_map& vertices_map) +template < class GT, class Tds_, class Lds_ > +bool construct_vertices_map(const Triangulation_3& tr, + Unique_hash_map::Vertex_handle, std::size_t>& vertices_map) { - typedef Triangulation_3 Triangulation; - typedef typename Triangulation::size_type size_type; - typedef typename Triangulation::Vertex_iterator Vertex_iterator; + typedef Triangulation_3 Triangulation; + typedef typename Triangulation::size_type size_type; + typedef typename Triangulation::Vertex_iterator Vertex_iterator; size_type i = 0; vertices_map[tr.infinite_vertex()] = 0; @@ -50,8 +50,8 @@ bool construct_vertices_map(const Triangulation_3& tr, Unique_hash return true; } -template < class GT, class Tds, class Lds > -bool write_header(std::ostream& os, const Triangulation_3& tr) +template < class GT, class Tds_, class Lds_ > +bool write_header(std::ostream& os, const Triangulation_3& tr) { // Writes: // - the dimension @@ -66,8 +66,8 @@ bool write_header(std::ostream& os, const Triangulation_3& tr) return (bool)os; } -template < class GT, class Tds, class Lds > -bool read_header(std::istream& is, Triangulation_3& tr) +template < class GT, class Tds_, class Lds_ > +bool read_header(std::istream& is, Triangulation_3& tr) { // Reads: // - the dimension @@ -86,19 +86,17 @@ bool read_header(std::istream& is, Triangulation_3& tr) return (bool)is; } -template < class GT, class Tds, class Lds > -bool write_vertices(std::ostream& os, const Triangulation_3& tr) +template < class GT, class Tds_, class Lds_ > +bool write_vertices(std::ostream& os, const Triangulation_3& tr) { // Writes: // - the number of finite vertices // - the non combinatorial information on vertices (point, etc) - typedef Triangulation_3 Triangulation; - typedef typename Triangulation::size_type size_type; - typedef typename Triangulation::Vertex_iterator Vertex_iterator; + typedef Triangulation_3 Triangulation; + typedef typename Triangulation::size_type size_type; + typedef typename Triangulation::Vertex_iterator Vertex_iterator; size_type n = tr.number_of_vertices(); - if (n == 0) - return false; if(IO::is_ascii(os)) { @@ -109,6 +107,9 @@ bool write_vertices(std::ostream& os, const Triangulation_3& tr) write(os, n); } + if (n == 0) + return false; + for(Vertex_iterator it = ++tr.vertices_begin(), end = tr.vertices_end(); it != end; ++it) { os << *it; @@ -119,19 +120,20 @@ bool write_vertices(std::ostream& os, const Triangulation_3& tr) return (bool)os; } -template < class GT, class Tds, class Lds, - typename Tr_src = Triangulation_3, +template < class GT, class Tds_, class Lds_, + typename Tr_src = Triangulation_3, typename ConvertVertex = Nullptr_t > struct read_vertices_functor { - bool operator()(std::istream& is, Triangulation_3& tr, std::vector< typename Tds::Vertex_handle >& vertices_handles, - typename Triangulation_3::size_type n, + bool operator()(std::istream& is, Triangulation_3& tr, + std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, + typename Triangulation_3::size_type n, ConvertVertex convert_vertex = ConvertVertex()) { // Reads: // - the non combinatorial information on vertices (point, etc) // The vertices are read with the type Tr_src::Vertex - // and converted to type Triangulation_3::Vertex + // and converted to type Triangulation_3::Vertex // using the ConvertVertex convertor. typedef typename Tr_src::Vertex Vertex1; @@ -148,11 +150,12 @@ struct read_vertices_functor } }; -template < class GT, class Tds, class Lds, class Tr_src > -struct read_vertices_functor < GT, Tds, Lds, Tr_src, Nullptr_t > +template < class GT, class Tds_, class Lds_, class Tr_src > +struct read_vertices_functor < GT, Tds_, Lds_, Tr_src, Nullptr_t > { - bool operator()(std::istream& is, Triangulation_3& tr, std::vector< typename Tds::Vertex_handle >& vertices_handles, - typename Triangulation_3::size_type n, + bool operator()(std::istream& is, Triangulation_3& tr, + std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, + typename Triangulation_3::size_type n, Nullptr_t _ = Nullptr_t()) { // Reads: @@ -168,17 +171,18 @@ struct read_vertices_functor < GT, Tds, Lds, Tr_src, Nullptr_t > }; -template < class GT, class Tds, class Lds, - typename Tr_src = Triangulation_3, +template < class GT, class Tds_, class Lds_, + typename Tr_src = Triangulation_3, typename ConvertVertex = Nullptr_t > -bool read_vertices(std::istream& is, Triangulation_3& tr, std::vector< typename Tds::Vertex_handle >& vertices_handles, +bool read_vertices(std::istream& is, Triangulation_3& tr, + std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, ConvertVertex convert_vertex = ConvertVertex()) { // Reads: // - the number of finite vertices // - the non combinatorial information on vertices (point, etc) - typedef Triangulation_3 Triangulation; - typedef typename Triangulation::size_type size_type; + typedef Triangulation_3 Triangulation; + typedef typename Triangulation::size_type size_type; size_type n; if(IO::is_ascii(is)) @@ -195,7 +199,7 @@ bool read_vertices(std::istream& is, Triangulation_3& tr, std::vec vertices_handles.resize(n+1); vertices_handles[0] = tr.infinite_vertex(); // the infinite vertex is numbered 0 - if (!read_vertices_functor()(is, tr, vertices_handles, n, convert_vertex)) + if (!read_vertices_functor()(is, tr, vertices_handles, n, convert_vertex)) return false; return (bool)is; @@ -234,11 +238,12 @@ bool write_cell_info(std::ostream& os, Iterator start, const Iterator& end) return (bool)os; } -template < class GT, class Tds, class Lds > -bool write_cells(std::ostream& os, const Triangulation_3& tr, const Unique_hash_map& vertices_map) +template < class GT, class Tds_, class Lds_ > +bool write_cells(std::ostream& os, const Triangulation_3& tr, + const Unique_hash_map::Vertex_handle, std::size_t>& vertices_map) { // Writes: - // [Call to Tds::print_cells] + // [Call to Tds_::print_cells] // - the number of cells // - the cells by the indices of their vertices in the preceding list // of vertices, plus the non combinatorial information on each cell @@ -246,10 +251,10 @@ bool write_cells(std::ostream& os, const Triangulation_3& tr, cons // [Cells other info] // - when dimension < 3 : the same with faces of maximal dimension - typedef Triangulation_3 Triangulation; - typedef typename Triangulation::Cell_iterator Cell_iterator; - typedef typename Triangulation::Edge_iterator Edge_iterator; - typedef typename Triangulation::Facet_iterator Facet_iterator; + typedef Triangulation_3 Triangulation; + typedef typename Triangulation::Cell_iterator Cell_iterator; + typedef typename Triangulation::Edge_iterator Edge_iterator; + typedef typename Triangulation::Facet_iterator Facet_iterator; tr.tds().print_cells(os, vertices_map); if (!os) @@ -281,20 +286,21 @@ bool write_cells(std::ostream& os, const Triangulation_3& tr, cons } -template < class GT, class Tds, class Lds, - typename Tr_src = Triangulation_3, +template < class GT, class Tds_, class Lds_, + typename Tr_src = Triangulation_3, typename ConvertCell = Nullptr_t > struct read_cells_functor { - bool operator()(std::istream& is, Triangulation_3& tr, const std::vector< typename Tds::Vertex_handle >& vertices_handles, - typename Triangulation_3::size_type m, std::vector< typename Triangulation_3::Cell_handle >& C, + bool operator()(std::istream& is, Triangulation_3& tr, + const std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, + typename Triangulation_3::size_type m, std::vector< typename Triangulation_3::Cell_handle >& C, ConvertCell convert_cell = ConvertCell()) { // Reads: // [Cells other info] // - when dimension < 3 : the same with faces of maximal dimension // The cell are read with the type Tr_src::Cell - // and converted to type Triangulation_3::Cell + // and converted to type Triangulation_3::Cell // using the ConvertCell convertor. typedef typename Tr_src::Cell Cell1; @@ -311,11 +317,12 @@ struct read_cells_functor } }; -template < class GT, class Tds, class Lds, class Tr_src > -struct read_cells_functor < GT, Tds, Lds, Tr_src, Nullptr_t > +template < class GT, class Tds_, class Lds_, class Tr_src > +struct read_cells_functor < GT, Tds_, Lds_, Tr_src, Nullptr_t > { - bool operator()(std::istream& is, Triangulation_3& tr, const std::vector< typename Tds::Vertex_handle >& vertices_handles, - typename Triangulation_3::size_type m, std::vector< typename Triangulation_3::Cell_handle >& C, + bool operator()(std::istream& is, Triangulation_3& tr, + const std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, + typename Triangulation_3::size_type m, std::vector< typename Triangulation_3::Cell_handle >& C, Nullptr_t _ = Nullptr_t()) { // Reads: @@ -330,14 +337,15 @@ struct read_cells_functor < GT, Tds, Lds, Tr_src, Nullptr_t > } }; -template < class GT, class Tds, class Lds, - typename Tr_src = Triangulation_3, +template < class GT, class Tds_, class Lds_, + typename Tr_src = Triangulation_3, typename ConvertCell = Nullptr_t > -bool read_cells(std::istream& is, Triangulation_3& tr, const std::vector< typename Tds::Vertex_handle >& vertices_handles, +bool read_cells(std::istream& is, Triangulation_3& tr, + const std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, ConvertCell convert_cell = ConvertCell()) { // Reads: - // [Call to Tds::read_cells] + // [Call to Tds_::read_cells] // - the number of cells // - the cells by the indices of their vertices in the preceding list // of vertices, plus the non combinatorial information on each cell @@ -345,7 +353,7 @@ bool read_cells(std::istream& is, Triangulation_3& tr, const std:: // [Cells other info] // - when dimension < 3 : the same with faces of maximal dimension - typedef Triangulation_3 Triangulation; + typedef Triangulation_3 Triangulation; typedef typename Triangulation::Cell_handle Cell_handle; std::vector< Cell_handle > C; @@ -355,7 +363,7 @@ bool read_cells(std::istream& is, Triangulation_3& tr, const std:: if(!is) return false; - if (!read_cells_functor()(is, tr, vertices_handles, m, C, convert_cell)) + if (!read_cells_functor()(is, tr, vertices_handles, m, C, convert_cell)) return false; return (bool)is; @@ -364,8 +372,9 @@ bool read_cells(std::istream& is, Triangulation_3& tr, const std:: } // end namespace internal -template < class GT, class Tds, class Lds > -bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr, Unique_hash_map& vertices_map) +template < class GT, class Tds_, class Lds_ > +bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr, + Unique_hash_map::Vertex_handle, std::size_t>& vertices_map) { // Writes: // [Header] @@ -388,19 +397,20 @@ bool export_triangulation_3(std::ostream& os, const Triangulation_3 -bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr) +template < class GT, class Tds_, class Lds_ > +bool export_triangulation_3(std::ostream& os, const Triangulation_3& tr) { - Unique_hash_map vertices_map; + Unique_hash_map::Vertex_handle, std::size_t> vertices_map; return export_triangulation_3(os, tr, vertices_map); } -template < class GT, class Tds, class Lds, - typename Tr_src = Triangulation_3, +template < class GT, class Tds_, class Lds_, + typename Tr_src = Triangulation_3, typename ConvertVertex = Nullptr_t, typename ConvertCell = Nullptr_t > -bool import_triangulation_3(std::istream& is, Triangulation_3& tr, std::vector& vertices_handles, +bool import_triangulation_3(std::istream& is, Triangulation_3& tr, + std::vector::Vertex_handle >& vertices_handles, ConvertVertex convert_vertex = ConvertVertex(), ConvertCell convert_cell = ConvertCell()) { @@ -423,25 +433,25 @@ bool import_triangulation_3(std::istream& is, Triangulation_3& tr, tr.set_infinite_vertex(tr.tds().create_vertex()); bool result = internal::read_header(is, tr) - && internal::read_vertices + && internal::read_vertices (is, tr, vertices_handles, convert_vertex) - && internal::read_cells + && internal::read_cells (is, tr, vertices_handles, convert_cell); CGAL_assertion(result && tr.is_valid(true)); return result; } -template < class GT, class Tds, class Lds, - typename Tr_src = Triangulation_3, +template < class GT, class Tds_, class Lds_, + typename Tr_src = Triangulation_3, typename ConvertVertex = Nullptr_t, typename ConvertCell = Nullptr_t > -bool import_triangulation_3(std::istream& is, Triangulation_3& tr, +bool import_triangulation_3(std::istream& is, Triangulation_3& tr, ConvertVertex convert_vertex = ConvertVertex(), ConvertCell convert_cell = ConvertCell()) { - std::vector vertices_handles; - return import_triangulation_3 + std::vector::Vertex_handle > vertices_handles; + return import_triangulation_3 (is, tr, vertices_handles, convert_vertex, convert_cell); } From 3278d7f878504c5e500706ed4247fef63e439fbe Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 2 Nov 2023 15:52:37 +0100 Subject: [PATCH 12/17] Fix licence --- Installation/include/CGAL/Mesh_3/Triangulation_3_fwd.h | 10 +++------- .../include/CGAL/IO/Triangulation_raw_iostream_3.h | 3 +-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Installation/include/CGAL/Mesh_3/Triangulation_3_fwd.h b/Installation/include/CGAL/Mesh_3/Triangulation_3_fwd.h index ee3a088b2b95..6207a973e66d 100644 --- a/Installation/include/CGAL/Mesh_3/Triangulation_3_fwd.h +++ b/Installation/include/CGAL/Mesh_3/Triangulation_3_fwd.h @@ -1,15 +1,11 @@ -// Copyright (c) 1999-2003 INRIA Sophia-Antipolis (France). -// All rights reserved. +// Copyright (C) 2023 GeometryFactory Sarl // -// This file is part of CGAL (www.cgal.org). +// This file is part of CGAL (www.cgal.org) // // $URL$ // $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Monique Teillaud -// Sylvain Pion -// Clement Jamin #ifndef CGAL_MESH_3_TRIANGULATION_3_FWD_H #define CGAL_MESH_3_TRIANGULATION_3_FWD_H diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h index 702e14011469..80c3ca69f78c 100644 --- a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -11,7 +11,6 @@ // Sylvain Pion // Clement Jamin - #ifndef CGAL_IO_TRIANGULATION_RAW_IOSTREAM_3_H #define CGAL_IO_TRIANGULATION_RAW_IOSTREAM_3_H @@ -438,7 +437,7 @@ bool import_triangulation_3(std::istream& is, Triangulation_3& t && internal::read_cells (is, tr, vertices_handles, convert_cell); - CGAL_assertion(result && tr.is_valid(true)); + CGAL_assertion(result && tr.is_valid(false)); return result; } From 9ffc93e3dee56331f8fb01419d61e44775ce6c12 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Mon, 6 Nov 2023 10:32:41 +0100 Subject: [PATCH 13/17] Added windows EOL check with an error message --- .../Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp | 12 ++++++++++++ SMDS_3/include/CGAL/IO/File_binary_mesh_3.h | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp index 513b4100ccb6..f01d386ab35c 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp @@ -499,6 +499,12 @@ try_load_a_cdt_3(std::istream& is, C3t3& c3t3) } std::getline(is, s); if(s != "") { + if(s.back() == '\r') { // Windows EOL if the file was written without the ios_base::binary flag. + is.setstate(std::ios_base::failbit); + std::cerr << "load_binary_file:" + << "\n Unexpected char : '\\r'. The file's content was probably written without the ios_base::binary flag." << std::endl; + return false; + } if(s != std::string(" ") + CGAL::Get_io_signature()()) { std::cerr << "load_binary_file:" << "\n expected format: " << CGAL::Get_io_signature()() @@ -582,6 +588,12 @@ try_load_other_binary_format(std::istream& is, C3t3& c3t3) } std::getline(is, s); if(s != "") { + if(s.back() == '\r') { // Windows EOL if the file was written without the ios_base::binary flag. + is.setstate(std::ios_base::failbit); + std::cerr << "Polyhedron_demo_c3t3_binary_io_plugin::try_load_other_binary_format:" + << "\n Unexpected char : '\\r'. The file's content was probably written without the ios_base::binary flag." << std::endl; + return false; + } if(s != std::string(" ") + CGAL::Get_io_signature()()) { std::cerr << "Polyhedron_demo_c3t3_binary_io_plugin::try_load_other_binary_format:" << "\n expected format: " << CGAL::Get_io_signature()() diff --git a/SMDS_3/include/CGAL/IO/File_binary_mesh_3.h b/SMDS_3/include/CGAL/IO/File_binary_mesh_3.h index e7363047a924..80887131f10e 100644 --- a/SMDS_3/include/CGAL/IO/File_binary_mesh_3.h +++ b/SMDS_3/include/CGAL/IO/File_binary_mesh_3.h @@ -87,8 +87,11 @@ bool load_binary_file(std::istream& is, C3T3& c3t3) } std::getline(is, s); if(!s.empty()) { - if(s[s.size()-1] == '\r') { // deal with Windows EOL - s.resize(s.size() - 1); + if(s.back() == '\r') { // Windows EOL if the file was written without the ios_base::binary flag. + is.setstate(std::ios_base::failbit); + std::cerr << "load_binary_file:" + << "\n Unexpected char : '\\r'. The file's content was probably written without the ios_base::binary flag." << std::endl; + return false; } if(s != std::string(" ") + CGAL::Get_io_signature()()) { std::cerr << "load_binary_file:" From f7583ae2186d38a087eab966e07ea84d68690652 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 30 Nov 2023 12:01:28 +0100 Subject: [PATCH 14/17] Removed unused variables --- .../CGAL/IO/Triangulation_raw_iostream_3.h | 180 +++++++++--------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h index 80c3ca69f78c..ac702e37b3c8 100644 --- a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -60,7 +60,7 @@ bool write_header(std::ostream& os, const Triangulation_3& tr) } else { - write(os, tr.dimension()); + CGAL::write(os, tr.dimension()); } return (bool)os; } @@ -77,7 +77,7 @@ bool read_header(std::istream& is, Triangulation_3& tr) } else { - read(is, dimension); + CGAL::read(is, dimension); } if(dimension > 3 || dimension < -2) return false; @@ -103,7 +103,7 @@ bool write_vertices(std::ostream& os, const Triangulation_3& tr) } else { - write(os, n); + CGAL::write(os, n); } if (n == 0) @@ -120,54 +120,47 @@ bool write_vertices(std::ostream& os, const Triangulation_3& tr) } template < class GT, class Tds_, class Lds_, - typename Tr_src = Triangulation_3, - typename ConvertVertex = Nullptr_t > -struct read_vertices_functor + typename Tr_src, + typename ConvertVertex > +bool read_vertices_with_convertion(std::istream& is, Triangulation_3& tr, + std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, + typename Triangulation_3::size_type n, + ConvertVertex convert_vertex = ConvertVertex()) { - bool operator()(std::istream& is, Triangulation_3& tr, - std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, - typename Triangulation_3::size_type n, - ConvertVertex convert_vertex = ConvertVertex()) - { - // Reads: - // - the non combinatorial information on vertices (point, etc) - // The vertices are read with the type Tr_src::Vertex - // and converted to type Triangulation_3::Vertex - // using the ConvertVertex convertor. - typedef typename Tr_src::Vertex Vertex1; - - for(std::size_t i=1; i <= n; i++) - { - Vertex1 v; - if(!(is >> v)) - return false; - vertices_handles[i] = tr.tds().create_vertex(); - convert_vertex(v, *vertices_handles[i]); - } + // Reads: + // - the non combinatorial information on vertices (point, etc) + // The vertices are read with the type Tr_src::Vertex + // and converted to type Triangulation_3::Vertex + // using the ConvertVertex convertor. + typedef typename Tr_src::Vertex Vertex1; - return (bool)is; + for(std::size_t i=1; i <= n; i++) + { + Vertex1 v; + if(!(is >> v)) + return false; + vertices_handles[i] = tr.tds().create_vertex(); + convert_vertex(v, *vertices_handles[i]); } -}; -template < class GT, class Tds_, class Lds_, class Tr_src > -struct read_vertices_functor < GT, Tds_, Lds_, Tr_src, Nullptr_t > + return (bool)is; +} + +template < class GT, class Tds_, class Lds_> +bool read_vertices_without_convertion(std::istream& is, Triangulation_3& tr, + std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, + typename Triangulation_3::size_type n) { - bool operator()(std::istream& is, Triangulation_3& tr, - std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, - typename Triangulation_3::size_type n, - Nullptr_t _ = Nullptr_t()) + // Reads: + // - the non combinatorial information on vertices (point, etc) + for(std::size_t i=1; i <= n; i++) { - // Reads: - // - the non combinatorial information on vertices (point, etc) - for(std::size_t i=1; i <= n; i++) - { - vertices_handles[i] = tr.tds().create_vertex(); - if(!(is >> *vertices_handles[i])) - return false; - } - return (bool)is; + vertices_handles[i] = tr.tds().create_vertex(); + if(!(is >> *vertices_handles[i])) + return false; } -}; + return (bool)is; +} template < class GT, class Tds_, class Lds_, @@ -190,7 +183,7 @@ bool read_vertices(std::istream& is, Triangulation_3& tr, } else { - read(is, n); + CGAL::read(is, n); } if((n+1) > vertices_handles.max_size()) return false; @@ -198,8 +191,16 @@ bool read_vertices(std::istream& is, Triangulation_3& tr, vertices_handles.resize(n+1); vertices_handles[0] = tr.infinite_vertex(); // the infinite vertex is numbered 0 - if (!read_vertices_functor()(is, tr, vertices_handles, n, convert_vertex)) - return false; + if constexpr (std::is_same::value) + { + if (!read_vertices_without_convertion(is, tr, vertices_handles, n)) + return false; + } + else + { + if (!read_vertices_with_convertion(is, tr, vertices_handles, n, convert_vertex)) + return false; + } return (bool)is; } @@ -286,55 +287,46 @@ bool write_cells(std::ostream& os, const Triangulation_3& tr, template < class GT, class Tds_, class Lds_, - typename Tr_src = Triangulation_3, - typename ConvertCell = Nullptr_t > -struct read_cells_functor + typename Tr_src, + typename ConvertCell > +bool read_cells_with_convertion(std::istream& is, typename Triangulation_3::size_type m, + std::vector< typename Triangulation_3::Cell_handle >& C, + ConvertCell convert_cell = ConvertCell()) { - bool operator()(std::istream& is, Triangulation_3& tr, - const std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, - typename Triangulation_3::size_type m, std::vector< typename Triangulation_3::Cell_handle >& C, - ConvertCell convert_cell = ConvertCell()) - { - // Reads: - // [Cells other info] - // - when dimension < 3 : the same with faces of maximal dimension - // The cell are read with the type Tr_src::Cell - // and converted to type Triangulation_3::Cell - // using the ConvertCell convertor. - - typedef typename Tr_src::Cell Cell1; + // Reads: + // [Cells other info] + // - when dimension < 3 : the same with faces of maximal dimension + // The cell are read with the type Tr_src::Cell + // and converted to type Triangulation_3::Cell + // using the ConvertCell convertor. - for(std::size_t i=0 ; i < m; i++) - { - Cell1 c; - if(!(is >> c)) - return false; - convert_cell(c, *C[i]); - } + typedef typename Tr_src::Cell Cell1; - return (bool)is; + for(std::size_t i=0 ; i < m; i++) + { + Cell1 c; + if(!(is >> c)) + return false; + convert_cell(c, *C[i]); } -}; -template < class GT, class Tds_, class Lds_, class Tr_src > -struct read_cells_functor < GT, Tds_, Lds_, Tr_src, Nullptr_t > + return (bool)is; +} + +template < class GT, class Tds_, class Lds_ > +bool read_cells_without_convertion(std::istream& is, typename Triangulation_3::size_type m, + std::vector< typename Triangulation_3::Cell_handle >& C) { - bool operator()(std::istream& is, Triangulation_3& tr, - const std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, - typename Triangulation_3::size_type m, std::vector< typename Triangulation_3::Cell_handle >& C, - Nullptr_t _ = Nullptr_t()) + // Reads: + // - the non combinatorial information on vertices (point, etc) + for(std::size_t i=0 ; i < m; i++) { - // Reads: - // - the non combinatorial information on vertices (point, etc) - for(std::size_t i=0 ; i < m; i++) - { - if(!(is >> *C[i])) - return false; - } - - return (bool)is; + if(!(is >> *C[i])) + return false; } -}; + + return (bool)is; +} template < class GT, class Tds_, class Lds_, typename Tr_src = Triangulation_3, @@ -362,8 +354,16 @@ bool read_cells(std::istream& is, Triangulation_3& tr, if(!is) return false; - if (!read_cells_functor()(is, tr, vertices_handles, m, C, convert_cell)) - return false; + if constexpr (std::is_same::value) + { + if (!read_cells_without_convertion(is, m, C)) + return false; + } + else + { + if (!read_cells_with_convertion(is, m, C, convert_cell)) + return false; + } return (bool)is; } From f712666530dce91264fb8d7859d5aac47d22adf0 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 30 Nov 2023 12:15:08 +0100 Subject: [PATCH 15/17] typo 'convertion' -> 'conversion' --- .../CGAL/IO/Triangulation_raw_iostream_3.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h index ac702e37b3c8..085c1d7a038c 100644 --- a/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_raw_iostream_3.h @@ -122,7 +122,7 @@ bool write_vertices(std::ostream& os, const Triangulation_3& tr) template < class GT, class Tds_, class Lds_, typename Tr_src, typename ConvertVertex > -bool read_vertices_with_convertion(std::istream& is, Triangulation_3& tr, +bool read_vertices_with_conversion(std::istream& is, Triangulation_3& tr, std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, typename Triangulation_3::size_type n, ConvertVertex convert_vertex = ConvertVertex()) @@ -147,7 +147,7 @@ bool read_vertices_with_convertion(std::istream& is, Triangulation_3 -bool read_vertices_without_convertion(std::istream& is, Triangulation_3& tr, +bool read_vertices_without_conversion(std::istream& is, Triangulation_3& tr, std::vector< typename Triangulation_3::Vertex_handle >& vertices_handles, typename Triangulation_3::size_type n) { @@ -193,12 +193,12 @@ bool read_vertices(std::istream& is, Triangulation_3& tr, if constexpr (std::is_same::value) { - if (!read_vertices_without_convertion(is, tr, vertices_handles, n)) + if (!read_vertices_without_conversion(is, tr, vertices_handles, n)) return false; } else { - if (!read_vertices_with_convertion(is, tr, vertices_handles, n, convert_vertex)) + if (!read_vertices_with_conversion(is, tr, vertices_handles, n, convert_vertex)) return false; } @@ -289,7 +289,7 @@ bool write_cells(std::ostream& os, const Triangulation_3& tr, template < class GT, class Tds_, class Lds_, typename Tr_src, typename ConvertCell > -bool read_cells_with_convertion(std::istream& is, typename Triangulation_3::size_type m, +bool read_cells_with_conversion(std::istream& is, typename Triangulation_3::size_type m, std::vector< typename Triangulation_3::Cell_handle >& C, ConvertCell convert_cell = ConvertCell()) { @@ -314,7 +314,7 @@ bool read_cells_with_convertion(std::istream& is, typename Triangulation_3 -bool read_cells_without_convertion(std::istream& is, typename Triangulation_3::size_type m, +bool read_cells_without_conversion(std::istream& is, typename Triangulation_3::size_type m, std::vector< typename Triangulation_3::Cell_handle >& C) { // Reads: @@ -356,12 +356,12 @@ bool read_cells(std::istream& is, Triangulation_3& tr, if constexpr (std::is_same::value) { - if (!read_cells_without_convertion(is, m, C)) + if (!read_cells_without_conversion(is, m, C)) return false; } else { - if (!read_cells_with_convertion(is, m, C, convert_cell)) + if (!read_cells_with_conversion(is, m, C, convert_cell)) return false; } From 31aea5fec879f557914dddd0cd2d9bee15ae3da2 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 4 Apr 2024 15:10:06 +0200 Subject: [PATCH 16/17] Fixed error when loading from a legacy c3t3 file : the number of cells was not updated due to the call to rescan_after_load_of_triangulation not being done. --- SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h | 1 - 1 file changed, 1 deletion(-) diff --git a/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h b/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h index 395546de0631..c08eb15f3c19 100644 --- a/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h +++ b/SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h @@ -2272,7 +2272,6 @@ operator>> (std::istream& is, { is.clear(); c3t3.edges_.clear(); - return is; } c3t3.rescan_after_load_of_triangulation(); From 786b6532caf40a0f42a6a62807e695518e45122e Mon Sep 17 00:00:00 2001 From: ange-clement Date: Thu, 4 Apr 2024 17:13:01 +0200 Subject: [PATCH 17/17] Updated c3t3 io test --- SMDS_3/test/SMDS_3/test_c3t3_io.cpp | 96 +++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 24 deletions(-) diff --git a/SMDS_3/test/SMDS_3/test_c3t3_io.cpp b/SMDS_3/test/SMDS_3/test_c3t3_io.cpp index cb9e18171511..d092ff04be92 100644 --- a/SMDS_3/test/SMDS_3/test_c3t3_io.cpp +++ b/SMDS_3/test/SMDS_3/test_c3t3_io.cpp @@ -245,13 +245,8 @@ struct Test_c3t3_io { end1 = t1.finite_vertices_end(); vit1 != end1; ++vit1, ++vit2) { - if(!( vit1->in_dimension() == vit2->in_dimension() && - vit1->index() == vit2->index()) ) + if(!compare_vertices(vit1, vit2)) { - std::cerr << "Error: vertices are different:\n"; - std::cerr << *vit1 << "\n" - << *vit2 << std::endl; - assert(false); return false; } } @@ -292,32 +287,84 @@ struct Test_c3t3_io { end1 = t1.finite_cells_end(); cit1 != end1; ++cit1, ++cit2) { - if(cit1->subdomain_index() != cit2->subdomain_index() ) + if (!compare_cells(cit1, cit2)) + return false; + } + return true; + } + + static bool compare_vertices(const Vertex_handle& vit1, const Vertex_handle& vit2) { + if(!( vit1->in_dimension() == vit2->in_dimension() && + vit1->index() == vit2->index()) ) + { + std::cerr << "Error: vertices are different:\n"; + std::cerr << *vit1 << "\n" + << *vit2 << std::endl; + assert(false); + return false; + } + return true; + } + + static bool compare_cells(const Cell_handle& cit1, const Cell_handle& cit2) { + if(cit1->subdomain_index() != cit2->subdomain_index() ) + { + std::cerr << "Error: cells are different:\n"; + std::cerr << *cit1 << "\n" + << *cit2 << std::endl; + assert(false); + return false; + } + for(int i = 0; i < 4; ++i) { + if( cit1->surface_patch_index(i) != + cit2->surface_patch_index(i) ) { std::cerr << "Error: cells are different:\n"; std::cerr << *cit1 << "\n" - << *cit2 << std::endl; + << *cit2 << "\n" + << "surface_patch_index(" << i << "):\n" + << cit1->surface_patch_index(i) << "\n" + << cit2->surface_patch_index(i) << "\n"; assert(false); return false; } - for(int i = 0; i < 4; ++i) { - if( cit1->surface_patch_index(i) != - cit2->surface_patch_index(i) ) - { - std::cerr << "Error: cells are different:\n"; - std::cerr << *cit1 << "\n" - << *cit2 << "\n" - << "surface_patch_index(" << i << "):\n" - << cit1->surface_patch_index(i) << "\n" - << cit2->surface_patch_index(i) << "\n"; - assert(false); - return false; - } - } } return true; } + static bool check_features(const C3t3& c1, const C3t3& c2) { + typedef typename C3t3::Edges_in_complex_iterator Edges_in_complex_iterator; + + if (c1.number_of_edges_in_complex() != c2.number_of_edges_in_complex()) + { + assert(false); + return false; + } +#if 0 + // Not sure if the C3t3 edges in complex iterator order changes after a reload... + for (Edges_in_complex_iterator + eit1 = c1.edges_in_complex_begin(), + eit2 = c2.edges_in_complex_begin(), + end1 = c1.edges_in_complex_end(); + eit1 != end1; ++eit1, ++eit2) + { + Cell_handle cell1 = eit1->first; + Cell_handle cell2 = eit2->first; + if (!compare_cells(cell1, cell2)) + return false; + Vertex_handle vertex1_1 = cell1->vertex(eit1->second); + Vertex_handle vertex1_2 = cell2->vertex(eit2->second); + if (!compare_vertices(vertex1_1, vertex1_2)) + return false; + Vertex_handle vertex2_1 = cell1->vertex(eit1->third); + Vertex_handle vertex2_2 = cell2->vertex(eit2->third); + if (!compare_vertices(vertex2_1, vertex2_2)) + return false; + } +#endif + return true; + } + static bool test_io(const C3t3& c3t3, const char* prefix, bool binary) { std::string filename(prefix); std::cout << "test_io"; @@ -358,7 +405,7 @@ struct Test_c3t3_io { assert(ss_c3t3); assert(ss_c3t3_bis); assert(ss_c3t3.str() == ss_c3t3_bis.str()); - if(!check_equality(c3t3, c3t3_bis)) return false; + if(!check_equality(c3t3, c3t3_bis) || !check_features(c3t3, c3t3_bis)) return false; } c3t3_bis.clear(); @@ -372,7 +419,7 @@ struct Test_c3t3_io { CGAL::IO::load_binary_file(ss, c3t3_bis); assert(ss); } - if(!check_equality(c3t3, c3t3_bis)) return false; + if(!check_equality(c3t3, c3t3_bis) || !check_features(c3t3, c3t3_bis)) return false; #ifndef CGAL_LITTLE_ENDIAN // skip binary I/O with the existing file for big endian @@ -404,6 +451,7 @@ struct Test_c3t3_io { CGAL::IO::load_binary_file(input, c3t3_bis); assert(input); } + // reading from a feature-less c3t3 file, do not check feature if(!check_equality(c3t3, c3t3_bis)) return false; return true;