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 4a7c004be2b..3f36d847090 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp @@ -400,7 +400,12 @@ struct Update_vertex typedef typename Tr1::Vertex V1; typedef typename Tr2::Vertex V2; typedef typename Tr2::Point Point; - + + V2 operator()(const V1&) + { + return V2(); + } + bool operator()(const V1& v1, V2& v2) { v2.set_point(Point(v1.point())); @@ -413,7 +418,7 @@ struct Update_vertex const Sp_index sp_index = boost::get(index); v2.set_index((std::max)(sp_index.first, sp_index.second)); } - break; + break; default:// -1, 0, 1, 3 v2.set_index(boost::get(v1.index())); } @@ -421,9 +426,18 @@ struct Update_vertex } }; // end struct Update_vertex +template struct Update_cell { + typedef Fake_mesh_domain::Surface_patch_index Sp_index; - template + typedef typename Tr2::Cell C2; + + template + C2 operator()(const C1&) { + return C2(); + } + + template bool operator()(const C1& c1, C2& c2) { c2.set_subdomain_index(c1.subdomain_index()); for(int i = 0; i < 4; ++i) { @@ -437,7 +451,7 @@ struct Update_cell { } }; // end struct Update_cell -#include +#include template struct Update_vertex_from_CDT_3 { @@ -447,24 +461,35 @@ struct Update_vertex_from_CDT_3 { typedef typename Tr2::Vertex V2; 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_dimension(2); v2.set_special(false); - return true; } }; // end struct Update_vertex +template struct Update_cell_from_CDT_3 { + typedef Fake_mesh_domain::Surface_patch_index Sp_index; - template - bool operator()(const C1& c1, C2& c2) { + typedef typename Tr2::Cell C2; + + template + C2 operator()(const C1&) { + return C2(); + } + + template + void operator()(const C1& c1, C2& c2) { c2.set_subdomain_index(1); for(int i = 0; i < 4; ++i) { c2.set_surface_patch_index(i, c1.constrained_facet[i]); } - return true; } }; // end struct Update_cell @@ -499,7 +524,7 @@ try_load_a_cdt_3(std::istream& is, C3t3& c3t3) Fake_CDT_3, C3t3::Triangulation, Update_vertex_from_CDT_3, - Update_cell_from_CDT_3>(is, c3t3.triangulation())) + Update_cell_from_CDT_3 >(is, c3t3.triangulation())) { c3t3.rescan_after_load_of_triangulation(); 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, C3t3::Triangulation, Update_vertex, - Update_cell>(is, c3t3.triangulation()); + Update_cell >(is, c3t3.triangulation()); c3t3.rescan_after_load_of_triangulation(); return f_is.good(); diff --git a/TDS_3/doc/TDS_3/Concepts/TriangulationDataStructure_3.h b/TDS_3/doc/TDS_3/Concepts/TriangulationDataStructure_3.h index 175a64c4e20..e97594ba277 100644 --- a/TDS_3/doc/TDS_3/Concepts/TriangulationDataStructure_3.h +++ b/TDS_3/doc/TDS_3/Concepts/TriangulationDataStructure_3.h @@ -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: - `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: - `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()`. */ 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 new file mode 100644 index 00000000000..6b9f8645638 --- /dev/null +++ b/Triangulation_3/doc/Triangulation_3/CGAL/IO/Triangulation_file_input.h @@ -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 +std::istream& file_input(std::istream& is, Tr_tgt &tr, + ConvertVertex convert_vertex = ConvertVertex(), + ConvertCell convert_cell = ConvertCell()); + +} diff --git a/Polyhedron/demo/Polyhedron/include/CGAL/Triangulation_file_input.h b/Triangulation_3/include/CGAL/IO/Triangulation_file_input.h similarity index 73% rename from Polyhedron/demo/Polyhedron/include/CGAL/Triangulation_file_input.h rename to Triangulation_3/include/CGAL/IO/Triangulation_file_input.h index 6c2906c7ccb..4cbb63a7c3b 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/Triangulation_file_input.h +++ b/Triangulation_3/include/CGAL/IO/Triangulation_file_input.h @@ -15,7 +15,7 @@ // $URL$ // $Id$ // -// Author(s) : Laurent Rineau +// Author(s) : Laurent Rineau, Maxime Gimeno // // Adapted from operator>>(std::istream&, Triangulation_3&) from @@ -28,13 +28,13 @@ namespace CGAL { -template -std::istream& file_input(std::istream& is, Tr2 &tr, - Update_vertex update_vertex = Update_vertex(), - Update_cell update_cell = Update_cell()) +template +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 @@ -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 // 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::Cell_handle Cell_handle; - typedef typename Tr1::Vertex Vertex1; - typedef typename Tr1::Cell Cell1; + typedef typename Tr_src::Vertex Vertex1; + typedef typename Tr_src::Cell Cell1; tr.clear(); tr.tds().cells().clear(); @@ -71,13 +71,12 @@ std::istream& file_input(std::istream& is, Tr2 &tr, // the infinite vertex is numbered 0 for (std::size_t i=1; i <= n; i++) { - V[i] = tr.tds().create_vertex(); + //V[i] = tr.tds().create_vertex(); Vertex1 v; if(!(is >> v)) return is; - if(!update_vertex(v, *V[i])) { - is.setstate(std::ios_base::failbit); - 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; @@ -88,10 +87,9 @@ std::istream& file_input(std::istream& is, Tr2 &tr, for (std::size_t j=0 ; j < m; j++) { Cell1 c; if(!(is >> c)) return is; - if(!update_cell(c, *(C[j]))) { - is.setstate(std::ios_base::failbit); - return is; - } + Cell_handle ch=tr.tds().create_cell(convert_cell(c)); + C[j] = ch; + convert_cell(c, *ch); } CGAL_triangulation_assertion( tr.is_valid(false) ); @@ -100,4 +98,5 @@ std::istream& file_input(std::istream& is, Tr2 &tr, } // end namespace CGAL -#endif // CGAL_TRIANGULATION_FILE_INPUT_3_H + +#endif // TRIANGULATION_FILE_INPUT_H