From 52cf9815e4fef12ec7a792ba123ba6f35a014257 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 28 Feb 2020 15:33:03 +0100 Subject: [PATCH] Remove free function and fix TDS3 test --- .../CGAL/Triangulation_data_structure_3.h | 50 +++++---- .../TDS_3/CGAL/Triangulation_ds_cell_base_3.h | 3 +- .../CGAL/Triangulation_ds_vertex_base_3.h | 3 +- TDS_3/include/CGAL/IO/TDS_3_file_input.h | 38 ------- .../CGAL/Triangulation_data_structure_3.h | 79 +++++++++++-- .../CGAL/internal/Tr_or_tds_file_input.h | 106 ------------------ TDS_3/test/TDS_3/test_io_tds3.cpp | 22 +++- .../CGAL/IO/Triangulation_file_input.h | 38 ------- .../CGAL/IO/Triangulation_file_input.h | 41 ------- .../include/CGAL/Triangulation_3.h | 63 ++++++++++- 10 files changed, 182 insertions(+), 261 deletions(-) delete mode 100644 TDS_3/include/CGAL/IO/TDS_3_file_input.h delete mode 100644 TDS_3/include/CGAL/internal/Tr_or_tds_file_input.h delete mode 100644 Triangulation_3/doc/Triangulation_3/CGAL/IO/Triangulation_file_input.h delete mode 100644 Triangulation_3/include/CGAL/IO/Triangulation_file_input.h diff --git a/TDS_3/doc/TDS_3/CGAL/Triangulation_data_structure_3.h b/TDS_3/doc/TDS_3/CGAL/Triangulation_data_structure_3.h index 742ea25c03c..22fc2c4d296 100644 --- a/TDS_3/doc/TDS_3/CGAL/Triangulation_data_structure_3.h +++ b/TDS_3/doc/TDS_3/CGAL/Triangulation_data_structure_3.h @@ -15,21 +15,16 @@ see below). The class may offer some flexibility for the choice of container in the future, in the form of additional template parameters. -\cgalHeading{Parameters} +\tparam VertexBase must be a model of `TriangulationDSVertexBase_3`. The default is `Triangulation_ds_vertex_base_3`. -It is parameterized by base classes for vertices and cells which have to match -the requirements for the concepts `TriangulationDSCellBase_3` and -`TriangulationDSVertexBase_3` respectively. +\tparam CellBase must be a model of `TriangulationDSCellBase_3`. The default is `Triangulation_ds_cell_base_3`. -They have the default values `Triangulation_ds_vertex_base_3` and -`Triangulation_ds_cell_base_3` respectively. - -The `Concurrency_tag` parameter allows to enable the use of a concurrent +\tparam ConcurrencyTag enables the use of a concurrent container to store vertices and cells. It can be `Sequential_tag` (use of a -`Compact_container` to store vertices and cells) or `Parallel_tag` +`Compact_container` to store vertices and cells) or `Parallel_tag` (use of a `Concurrent_compact_container`). If it is `Parallel_tag`, the following functions can be called concurrently: -`create_vertex`, `create_cell`, `delete_vertex`, `delete_cell`. +`create_vertex()`, `create_cell()`, `delete_vertex()`, and `delete_cell()`. `Sequential_tag` is the default value. \cgalModels `TriangulationDataStructure_3` @@ -37,37 +32,50 @@ container to store vertices and cells. It can be `Sequential_tag` (use of a The base class `Triangulation_utils_3` defines basic computations on indices of vertices and neighbors of cells. -\attention All members listed here are additional to the interface -specified by the concept. - \sa `CGAL::Triangulation_ds_vertex_base_3` \sa `CGAL::Triangulation_ds_cell_base_3` -\sa `CGAL::Triangulation_vertex_base_with_info_3` -\sa `CGAL::Triangulation_cell_base_with_info_3` */ -template< typename TriangulationDSVertexBase_3, - typename TriangulationDSCellBase_3, - typename Concurrency_tag > -class Triangulation_data_structure_3 : public CGAL::Triangulation_utils_3 { +template< typename VertexBase, + typename CellBase, + typename ConcurrencyTag > +class Triangulation_data_structure_3 + : public CGAL::Triangulation_utils_3 +{ public: /// \name Types /// @{ +typedef Triangulation_data_structure_2 Tds; + +/// The vertex type. +/// +/// \sa Section \ref tds3cyclic +typedef typename VertexBase::template Rebind_TDS::Other Vertex; + +/// The face type. +/// +/// \sa Section \ref tds3cyclic +typedef typename CellBase::template Rebind_TDS::Other Cell; + /*! -Vertex container type. If Concurrency_tag is Parallel_tag, a +Vertex container type. If `ConcurrencyTag` is `Parallel_tag`, a `Concurrent_compact_container` is used instead of a `Compact_container`. */ typedef Compact_container Vertex_range; /*! -Cell container type. If Concurrency_tag is Parallel_tag, a +Cell container type. If `ConcurrencyTag` is `Parallel_tag`, a `Concurrent_compact_container` is used instead of a `Compact_container`. */ typedef Compact_container Cell_range; /// @} /// \name Operations +/// +/// In addition to the interface documented in the concept, +/// the class offers the following functions. +/// /// @{ /*! diff --git a/TDS_3/doc/TDS_3/CGAL/Triangulation_ds_cell_base_3.h b/TDS_3/doc/TDS_3/CGAL/Triangulation_ds_cell_base_3.h index 51c3048d577..90f86670ea8 100644 --- a/TDS_3/doc/TDS_3/CGAL/Triangulation_ds_cell_base_3.h +++ b/TDS_3/doc/TDS_3/CGAL/Triangulation_ds_cell_base_3.h @@ -10,9 +10,10 @@ The class `Triangulation_ds_cell_base_3<>` is a model for the concept \cgalModels `TriangulationDSCellBase_3` +\tparam TDS should not be specified (see Section \ref tds3cyclic and examples) + \sa `CGAL::Triangulation_cell_base_3` \sa `CGAL::Triangulation_ds_vertex_base_3` -\sa `CGAL::Triangulation_cell_base_with_info_3` */ template< typename TDS = void > diff --git a/TDS_3/doc/TDS_3/CGAL/Triangulation_ds_vertex_base_3.h b/TDS_3/doc/TDS_3/CGAL/Triangulation_ds_vertex_base_3.h index 10a7a078f09..c54caf3952a 100644 --- a/TDS_3/doc/TDS_3/CGAL/Triangulation_ds_vertex_base_3.h +++ b/TDS_3/doc/TDS_3/CGAL/Triangulation_ds_vertex_base_3.h @@ -20,9 +20,10 @@ example) tuned for a specific application. \cgalModels `TriangulationDSVertexBase_3` +\tparam TDS should not be specified (see Section \ref tds3cyclic and examples) + \sa `CGAL::Triangulation_vertex_base_3` \sa `CGAL::Triangulation_ds_cell_base_3` -\sa `CGAL::Triangulation_vertex_base_with_info_3` */ template< typename TDS = void > diff --git a/TDS_3/include/CGAL/IO/TDS_3_file_input.h b/TDS_3/include/CGAL/IO/TDS_3_file_input.h deleted file mode 100644 index 50b698ecdf6..00000000000 --- a/TDS_3/include/CGAL/IO/TDS_3_file_input.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef TDS_3_FILE_INPUT_H -#define TDS_3_FILE_INPUT_H -// Copyright (c) 1997-2010 INRIA Sophia-Antipolis (France). -// Copyright (c) 2011, 2020 GeometryFactory Sarl (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) : Laurent Rineau, Maxime Gimeno - -// Adapted from operator>>(std::istream&, Triangulation_3&) from -// - -#include - - -#include - -namespace CGAL { - -template -std::istream& file_input(std::istream& is, Tr_tgt &tr, - ConvertVertex convert_vertex = ConvertVertex(), - ConvertCell convert_cell = ConvertCell()) -{ - return internal::file_input(is, tr, true, convert_vertex, convert_cell); -} - -} //end CGAL -#endif // TDS_3_FILE_INPUT_H diff --git a/TDS_3/include/CGAL/Triangulation_data_structure_3.h b/TDS_3/include/CGAL/Triangulation_data_structure_3.h index 9ddc129e82f..8ae2d277f7a 100644 --- a/TDS_3/include/CGAL/Triangulation_data_structure_3.h +++ b/TDS_3/include/CGAL/Triangulation_data_structure_3.h @@ -51,8 +51,6 @@ #include #include -#include - #ifdef CGAL_LINKED_WITH_TBB # include #endif @@ -1524,6 +1522,73 @@ public: return s <= maximal_nb_of_facets_of_small_hole; } + //IO + 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 + + // 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 typename Tds::Vertex_handle Vertex_handle; + typedef typename Tds::Cell_handle Cell_handle; + + typedef typename TDS_src::Vertex Vertex1; + typedef typename TDS_src::Cell Cell1; + clear(); + cells().clear(); + + std::size_t n; + int d; + if(is_ascii(is)) + is >> d >> n; + else { + read(is, d); + read(is, n); + } + if(!is) return is; + set_dimension(d); + + std::size_t V_size = n; + std::vector< Vertex_handle > V(V_size); + + // the infinite vertex is numbered 0 + for (std::size_t i=0 ; i < V_size; ++i) { + Vertex1 v; + if(!(is >> v)) return is; + Vertex_handle vh=create_vertex( convert_vertex(v) ); + V[i] = vh; + convert_vertex(v, *V[i]); + } + + std::vector< Cell_handle > C; + + std::size_t m; + 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_triangulation_assertion(is_valid(false)); + return is; + } + private: // Change the orientation of the cell by swapping indices 0 and 1. @@ -1554,16 +1619,6 @@ private: bool count_cells(size_type &i, bool verbose = false, int level = 0) const; // counts AND checks the validity - //IO - template - std::istream& file_input(std::istream& is, - ConvertVertex convert_vertex = ConvertVertex(), - ConvertCell convert_cell = ConvertCell()) - { - return CGAL::file_input(is, *this, convert_vertex, convert_cell); - } }; #ifdef CGAL_TDS_USE_RECURSIVE_CREATE_STAR_3 diff --git a/TDS_3/include/CGAL/internal/Tr_or_tds_file_input.h b/TDS_3/include/CGAL/internal/Tr_or_tds_file_input.h deleted file mode 100644 index 516bbb60d25..00000000000 --- a/TDS_3/include/CGAL/internal/Tr_or_tds_file_input.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) 1997-2010 INRIA Sophia-Antipolis (France). -// Copyright (c) 2011, 2020 GeometryFactory Sarl (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) : Laurent Rineau, Maxime Gimeno - -// Adapted from operator>>(std::istream&, Triangulation_3&) from -// - - -#ifndef CGAL_TR_OR_TDS_FILE_INPUT_H -#define CGAL_TR_OR_TDS_FILE_INPUT_H - -#include - -#include - - -#include - -namespace CGAL { -namespace internal{ - -template -std::istream& file_input(std::istream& is, Tr_tgt &tr, bool is_tds, - 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 - - // 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 Tr_tgt 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; - - tr.clear(); - tr.tds().cells().clear(); - - std::size_t n; - int d; - if(is_ascii(is)) - is >> d >> n; - else { - read(is, d); - read(is, n); - } - if(!is) return is; - tr.tds().set_dimension(d); - - std::size_t V_size = is_tds ? n : n+1; - std::vector< Vertex_handle > V(V_size); - - // the infinite vertex is numbered 0 - if(!is_tds) - V[0] = tr.infinite_vertex(); - - for (std::size_t i=is_tds ? 0 : 1; i < V_size; ++i) { - Vertex1 v; - if(!(is >> v)) return is; - Vertex_handle vh=tr.tds().create_vertex( convert_vertex(v) ); - V[i] = vh; - convert_vertex(v, *V[i]); - } - - 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++) { - Cell1 c; - if(!(is >> c)) return is; - convert_cell(c, *C[j]); - } - - CGAL_triangulation_assertion( tr.is_valid(false) ); - return is; -} - -} //end internal -} // end namespace CGAL - - -#endif // CGAL_TR_OR_TDS_FILE_INPUT_H diff --git a/TDS_3/test/TDS_3/test_io_tds3.cpp b/TDS_3/test/TDS_3/test_io_tds3.cpp index fb1dc31092f..98ed299540e 100644 --- a/TDS_3/test/TDS_3/test_io_tds3.cpp +++ b/TDS_3/test/TDS_3/test_io_tds3.cpp @@ -26,8 +26,28 @@ struct Update_vertex { } + + }; // end struct Update_vertex +template +struct Update_cell +{ + typedef typename T1::Cell C1; + typedef typename T2::Cell C2; + + C2 operator()(const C1&) + { + return C2(); + } + + void operator()(const C1&, C2&) + { + + } + + +}; // end struct Update_vertex int main() { @@ -52,7 +72,7 @@ int main() out.close(); Tds T2; std::ifstream in("tr"); - //T2.file_input, Update_cell>(in); + T2.file_input, Update_cell >(in); in.close(); return 0; } diff --git a/Triangulation_3/doc/Triangulation_3/CGAL/IO/Triangulation_file_input.h b/Triangulation_3/doc/Triangulation_3/CGAL/IO/Triangulation_file_input.h deleted file mode 100644 index 128448543d9..00000000000 --- a/Triangulation_3/doc/Triangulation_3/CGAL/IO/Triangulation_file_input.h +++ /dev/null @@ -1,38 +0,0 @@ -namespace CGAL { - -///@{ -/*! -\ingroup PkgIOTriangulation3 - -The triangulation streamed in `is`, of original type `Tr_src`, is written into `tr`, of type `Tr_tgt`. As the vertex and cell - types might be different and incompatible, the creation of new cells and vertices -is made thanks to the functors `convert_vertex` and `convert_cell`, that convert -vertex and cell types. For each vertex `v_src` in `is`, the corresponding -vertex `v_tgt` in `tr` is a copy of the vertex returned by `convert_vertex(v_src)`. -The same operations are done for cells with the functor convert_cell, except cells -in `tr` are created using the default constructor, and then filled with the data -contained in the stream. - - - - A model of `ConvertVertex` must provide two `operator()`s that are responsible - for converting the source vertex `v_src` into the target vertex: - - `Tr_tgt::Vertex operator()(const Tr_src::Vertex& v_src) const;` This operator is -used to create the vertex from `v_src`. - - `void operator()(const Tr_src::Vertex& v_src, Tr_tgt::Vertex& v_tgt) const;` This - operator is meant to be used in case heavy data should be transferred to `v_tgt`. - - A model of ConvertCell must provide an `operator()` that is responsible for -converting the source cell `c_src` into the target cell: - - `void operator()(const Tr_src::Cell& c_src, Tr_tgt::Cell& c_tgt) const;` This operator - is meant to be used in case data should be transferred to `c_tgt`. - -\note The triangulation contained in `is` can be obtained with the `operator>>` of a `Triangulation_3`. -*/ -template -std::istream& file_input(std::istream& is, Tr_tgt &tr, - ConvertVertex convert_vertex = ConvertVertex(), - ConvertCell convert_cell = ConvertCell()); -///@} -} diff --git a/Triangulation_3/include/CGAL/IO/Triangulation_file_input.h b/Triangulation_3/include/CGAL/IO/Triangulation_file_input.h deleted file mode 100644 index 0d6159489d7..00000000000 --- a/Triangulation_3/include/CGAL/IO/Triangulation_file_input.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 1997-2010 INRIA Sophia-Antipolis (France). -// Copyright (c) 2011, 2020 GeometryFactory Sarl (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) : Laurent Rineau, Maxime Gimeno - -// Adapted from operator>>(std::istream&, Triangulation_3&) from -// - - -#ifndef CGAL_TRIANGULATION_FILE_INPUT_3_H -#define CGAL_TRIANGULATION_FILE_INPUT_3_H - -#include - -#include - -namespace CGAL { - -template -std::istream& file_input(std::istream& is, Tr_tgt &tr, - ConvertVertex convert_vertex = ConvertVertex(), - ConvertCell convert_cell = ConvertCell()) -{ - return internal::file_input(is, tr, false, convert_vertex, convert_cell); -} - -} // end namespace CGAL - - -#endif // TRIANGULATION_FILE_INPUT_H diff --git a/Triangulation_3/include/CGAL/Triangulation_3.h b/Triangulation_3/include/CGAL/Triangulation_3.h index 6f05f4e52e9..682a5b8837e 100644 --- a/Triangulation_3/include/CGAL/Triangulation_3.h +++ b/Triangulation_3/include/CGAL/Triangulation_3.h @@ -60,7 +60,6 @@ #include #include #include -#include #ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO #include @@ -2203,7 +2202,67 @@ public: ConvertVertex convert_vertex = ConvertVertex(), ConvertCell convert_cell = ConvertCell()) { - return CGAL::file_input(is, *this, convert_vertex, convert_cell); + // 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(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_triangulation_assertion( is_valid(false) ); + return is; } };