Add a generic function in TDS_3 that takes a boolean argument to decide how to take care of the infinite_vertex, and use it in the T3 functions.

This commit is contained in:
Maxime Gimeno 2020-02-26 10:57:55 +01:00
parent 7964028590
commit 66cd3401f9
3 changed files with 146 additions and 58 deletions

View File

@ -0,0 +1,38 @@
#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
// <CGAL/Triangulation_3.h>
#include <CGAL/license/TDS_3.h>
#include <CGAL/internal/Tr_or_tds_file_input.h>
namespace CGAL {
template <typename Tr_src,
typename Tr_tgt,
typename ConvertVertex,
typename ConvertCell>
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

View File

@ -0,0 +1,106 @@
// 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
// <CGAL/Triangulation_3.h>
#ifndef CGAL_TR_OR_TDS_FILE_INPUT_H
#define CGAL_TR_OR_TDS_FILE_INPUT_H
#include <CGAL/license/TDS_3.h>
#include <CGAL/license/Triangulation_3.h>
#include <CGAL/basic.h>
namespace CGAL {
namespace internal{
template <typename Tr_src,
typename Tr_tgt,
typename ConvertVertex,
typename ConvertCell>
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

View File

@ -20,8 +20,7 @@
#include <CGAL/license/Triangulation_3.h>
#include <CGAL/basic.h>
#include <CGAL/internal/Tr_or_tds_file_input.h>
namespace CGAL {
@ -32,63 +31,8 @@ template <typename Tr_src,
std::istream& file_input(std::istream& is, Tr_tgt &tr,
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
{
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::vector< Vertex_handle > V(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();
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;
return internal::file_input<Tr_src>(is, tr, false, convert_vertex, convert_cell);
}
} // end namespace CGAL