Move the file_input.h file to Triangulation_3 and write some doc. Unify with the API of copy_tds() and adapt the c3t3_io plugin.

This commit is contained in:
Maxime Gimeno 2020-01-08 16:37:39 +01:00
parent c97123f303
commit 2bfdc8398f
4 changed files with 95 additions and 34 deletions

View File

@ -401,6 +401,11 @@ struct Update_vertex
typedef typename Tr2::Vertex V2; typedef typename Tr2::Vertex V2;
typedef typename Tr2::Point Point; typedef typename Tr2::Point Point;
V2 operator()(const V1&)
{
return V2();
}
bool operator()(const V1& v1, V2& v2) bool operator()(const V1& v1, V2& v2)
{ {
v2.set_point(Point(v1.point())); v2.set_point(Point(v1.point()));
@ -421,9 +426,18 @@ struct Update_vertex
} }
}; // end struct Update_vertex }; // end struct Update_vertex
template <typename Tr1, typename Tr2>
struct Update_cell { struct Update_cell {
typedef Fake_mesh_domain::Surface_patch_index Sp_index; typedef Fake_mesh_domain::Surface_patch_index Sp_index;
template <typename C1, typename C2> typedef typename Tr2::Cell C2;
template <typename C1>
C2 operator()(const C1&) {
return C2();
}
template <typename C1>
bool operator()(const C1& c1, C2& c2) { bool operator()(const C1& c1, C2& c2) {
c2.set_subdomain_index(c1.subdomain_index()); c2.set_subdomain_index(c1.subdomain_index());
for(int i = 0; i < 4; ++i) { for(int i = 0; i < 4; ++i) {
@ -437,7 +451,7 @@ struct Update_cell {
} }
}; // end struct Update_cell }; // end struct Update_cell
#include <CGAL/Triangulation_file_input.h> #include <CGAL/IO/Triangulation_file_input.h>
template <typename Tr1, typename Tr2> template <typename Tr1, typename Tr2>
struct Update_vertex_from_CDT_3 { struct Update_vertex_from_CDT_3 {
@ -447,24 +461,35 @@ struct Update_vertex_from_CDT_3 {
typedef typename Tr2::Vertex V2; typedef typename Tr2::Vertex V2;
typedef typename Tr2::Point Point; typedef typename Tr2::Point Point;
bool operator()(const V1& v1, V2& v2) V2 operator()(const V1&)
{
return V2();
}
void operator()(const V1& v1, V2& v2)
{ {
v2.set_point(Point(v1.point())); v2.set_point(Point(v1.point()));
v2.set_dimension(2); v2.set_dimension(2);
v2.set_special(false); v2.set_special(false);
return true;
} }
}; // end struct Update_vertex }; // end struct Update_vertex
template <typename Tr1, typename Tr2>
struct Update_cell_from_CDT_3 { struct Update_cell_from_CDT_3 {
typedef Fake_mesh_domain::Surface_patch_index Sp_index; typedef Fake_mesh_domain::Surface_patch_index Sp_index;
template <typename C1, typename C2> typedef typename Tr2::Cell C2;
bool operator()(const C1& c1, C2& c2) {
template <typename C1>
C2 operator()(const C1&) {
return C2();
}
template <typename C1>
void operator()(const C1& c1, C2& c2) {
c2.set_subdomain_index(1); c2.set_subdomain_index(1);
for(int i = 0; i < 4; ++i) { for(int i = 0; i < 4; ++i) {
c2.set_surface_patch_index(i, c1.constrained_facet[i]); c2.set_surface_patch_index(i, c1.constrained_facet[i]);
} }
return true;
} }
}; // end struct Update_cell }; // end struct Update_cell
@ -499,7 +524,7 @@ try_load_a_cdt_3(std::istream& is, C3t3& c3t3)
Fake_CDT_3, Fake_CDT_3,
C3t3::Triangulation, C3t3::Triangulation,
Update_vertex_from_CDT_3<Fake_CDT_3, C3t3::Triangulation>, Update_vertex_from_CDT_3<Fake_CDT_3, C3t3::Triangulation>,
Update_cell_from_CDT_3>(is, c3t3.triangulation())) Update_cell_from_CDT_3<Fake_CDT_3, C3t3::Triangulation> >(is, c3t3.triangulation()))
{ {
c3t3.rescan_after_load_of_triangulation(); c3t3.rescan_after_load_of_triangulation();
std::cerr << "Try load a CDT_3... DONE"; std::cerr << "Try load a CDT_3... DONE";
@ -543,7 +568,7 @@ try_load_other_binary_format(std::istream& is, C3t3& c3t3)
Fake_c3t3::Triangulation, Fake_c3t3::Triangulation,
C3t3::Triangulation, C3t3::Triangulation,
Update_vertex<Fake_c3t3::Triangulation, C3t3::Triangulation>, Update_vertex<Fake_c3t3::Triangulation, C3t3::Triangulation>,
Update_cell>(is, c3t3.triangulation()); Update_cell<Fake_c3t3::Triangulation, C3t3::Triangulation> >(is, c3t3.triangulation());
c3t3.rescan_after_load_of_triangulation(); c3t3.rescan_after_load_of_triangulation();
return f_is.good(); return f_is.good();

View File

@ -251,10 +251,10 @@ otherwise `Vertex_handle()` is returned.
- A model of `ConvertVertex` must provide two operator()'s that are responsible for converting the source vertex `v_src` into the target vertex: - A model of `ConvertVertex` must provide two operator()'s that are responsible for converting the source vertex `v_src` into the target vertex:
- `Vertex operator()(const TDS_src::Vertex& v_src) const;` This operator is used to create the vertex from `v_src`. - `Vertex operator()(const TDS_src::Vertex& v_src) const;` This operator is used to create the vertex from `v_src`.
- `void operator()(const TDS_src::Vertex& v_src, Vertex& v_tgt) const;` This operator is meant to be used in case heavy data should transferred to `v_tgt`. - `void operator()(const TDS_src::Vertex& v_src, 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 two operator()'s that are responsible for converting the source cell `c_src` into the target cell: - A model of ConvertCell must provide two operator()'s that are responsible for converting the source cell `c_src` into the target cell:
- `Cell operator()(const TDS_src::Cell& c_src) const;` This operator is used to create the cell from `c_src`. - `Cell operator()(const TDS_src::Cell& c_src) const;` This operator is used to create the cell from `c_src`.
- `void operator()(const TDS_src::Cell& c_src, Cell& c_tgt) const;` This operator is meant to be used in case heavy data should transferred to `c_tgt`. - `void operator()(const TDS_src::Cell& c_src, Cell& c_tgt) const;` This operator is meant to be used in case heavy data should be transferred to `c_tgt`.
\pre The optional argument `v` is a vertex of `tds_src` or is `Vertex_handle()`. \pre The optional argument `v` is a vertex of `tds_src` or is `Vertex_handle()`.
*/ */

View File

@ -0,0 +1,37 @@
namespace CGAL {
/*!
The triangulation streamed in `is` is written into `tr`. 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 `in`, 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. If `v != Tr_src::Vertex_handle()`,
a handle to the vertex created in `tr` that is the copy of `v` is returned,
otherwise `Tr_tgt::Vertex_handle()` is returned.
- 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 two operator()'s that are responsible for
converting the source cell `c_src` into the target cell:
- `Tr_tgt::Cell operator()(const Tr_src::Cell& c_src) const;` This operator is used to
create the cell from `c_src`.
- `void operator()(const Tr_src::Cell& c_src, Tr_tgt::Cell& c_tgt) const;` This operator
is meant to be used in case heavy data should be transferred to `c_tgt`.
\pre The optional argument `v` is a vertex of `tr_src` or is `Vertex_handle()`.
*/
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());
}

View File

@ -15,7 +15,7 @@
// $URL$ // $URL$
// $Id$ // $Id$
// //
// Author(s) : Laurent Rineau // Author(s) : Laurent Rineau, Maxime Gimeno
// //
// Adapted from operator>>(std::istream&, Triangulation_3&) from // Adapted from operator>>(std::istream&, Triangulation_3&) from
@ -28,13 +28,13 @@
namespace CGAL { namespace CGAL {
template <typename Tr1, template <typename Tr_src,
typename Tr2, typename Tr_tgt,
typename Update_vertex, typename ConvertVertex,
typename Update_cell> typename ConvertCell>
std::istream& file_input(std::istream& is, Tr2 &tr, std::istream& file_input(std::istream& is, Tr_tgt &tr,
Update_vertex update_vertex = Update_vertex(), ConvertVertex convert_vertex = ConvertVertex(),
Update_cell update_cell = Update_cell()) ConvertCell convert_cell = ConvertCell())
// reads // reads
// the dimension // the dimension
// the number of finite vertices // the number of finite vertices
@ -45,12 +45,12 @@ std::istream& file_input(std::istream& is, Tr2 &tr,
// the neighbors of each cell by their index in the preceding list of cells // the neighbors of each cell by their index in the preceding list of cells
// when dimension < 3 : the same with faces of maximal dimension // when dimension < 3 : the same with faces of maximal dimension
{ {
typedef Tr2 Triangulation; typedef Tr_tgt Triangulation;
typedef typename Triangulation::Vertex_handle Vertex_handle; typedef typename Triangulation::Vertex_handle Vertex_handle;
typedef typename Triangulation::Cell_handle Cell_handle; typedef typename Triangulation::Cell_handle Cell_handle;
typedef typename Tr1::Vertex Vertex1; typedef typename Tr_src::Vertex Vertex1;
typedef typename Tr1::Cell Cell1; typedef typename Tr_src::Cell Cell1;
tr.clear(); tr.clear();
tr.tds().cells().clear(); tr.tds().cells().clear();
@ -71,13 +71,12 @@ std::istream& file_input(std::istream& is, Tr2 &tr,
// the infinite vertex is numbered 0 // the infinite vertex is numbered 0
for (std::size_t i=1; i <= n; i++) { for (std::size_t i=1; i <= n; i++) {
V[i] = tr.tds().create_vertex(); //V[i] = tr.tds().create_vertex();
Vertex1 v; Vertex1 v;
if(!(is >> v)) return is; if(!(is >> v)) return is;
if(!update_vertex(v, *V[i])) { Vertex_handle vh=tr.tds().create_vertex( convert_vertex(v) );
is.setstate(std::ios_base::failbit); V[i] = vh;
return is; convert_vertex(v, *V[i]);
}
} }
std::vector< Cell_handle > C; std::vector< Cell_handle > C;
@ -88,10 +87,9 @@ std::istream& file_input(std::istream& is, Tr2 &tr,
for (std::size_t j=0 ; j < m; j++) { for (std::size_t j=0 ; j < m; j++) {
Cell1 c; Cell1 c;
if(!(is >> c)) return is; if(!(is >> c)) return is;
if(!update_cell(c, *(C[j]))) { Cell_handle ch=tr.tds().create_cell(convert_cell(c));
is.setstate(std::ios_base::failbit); C[j] = ch;
return is; convert_cell(c, *ch);
}
} }
CGAL_triangulation_assertion( tr.is_valid(false) ); CGAL_triangulation_assertion( tr.is_valid(false) );
@ -100,4 +98,5 @@ std::istream& file_input(std::istream& is, Tr2 &tr,
} // end namespace CGAL } // end namespace CGAL
#endif // CGAL_TRIANGULATION_FILE_INPUT_3_H
#endif // TRIANGULATION_FILE_INPUT_H