From d8b0e2904e1e37be64a408e66e358d20178e0a1b Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Tue, 17 Jun 2014 14:48:03 +0200 Subject: [PATCH] New data for 2D and 3D + improved export --- .../data/{points.cin => points_2.cin} | 6 +- .../Triangulation/data/points_3.cin | 11 ++++ .../Triangulation/points_to_RT_to_off.cpp | 26 ++++++--- .../CGAL/IO/Triangulation_off_ostream.h | 57 +++++++++++++++---- 4 files changed, 78 insertions(+), 22 deletions(-) rename Triangulation/applications/Triangulation/data/{points.cin => points_2.cin} (59%) create mode 100644 Triangulation/applications/Triangulation/data/points_3.cin diff --git a/Triangulation/applications/Triangulation/data/points.cin b/Triangulation/applications/Triangulation/data/points_2.cin similarity index 59% rename from Triangulation/applications/Triangulation/data/points.cin rename to Triangulation/applications/Triangulation/data/points_2.cin index 68477fd5d57..19b563f4835 100644 --- a/Triangulation/applications/Triangulation/data/points.cin +++ b/Triangulation/applications/Triangulation/data/points_2.cin @@ -1,11 +1,11 @@ 2 -0.0071 1.6899 1.2 0 +0.0071 1.6899 0 0.3272 1.3694 0.05 1.3697 1.8296 0.1 0.6722 0.3012 0.15 1.1726 0.1899 0.2 -0.4374 2.8541 0.25 +0.4374 2.8541 100.25 2.5923 0.1904 0.3 -1.3083 2.5462 0.35 +1.3083 2.5462 200.35 1.4981 1.3929 0.4 2.1304 2.055 0.45 \ No newline at end of file diff --git a/Triangulation/applications/Triangulation/data/points_3.cin b/Triangulation/applications/Triangulation/data/points_3.cin new file mode 100644 index 00000000000..5ffbc05d517 --- /dev/null +++ b/Triangulation/applications/Triangulation/data/points_3.cin @@ -0,0 +1,11 @@ +3 +0.0071 1.6899 2.521 0 +0.3272 1.3694 3.15 100.05 +1.3697 1.8296 2.654 0.1 +0.6722 0.3012 0.1548 100.15 +1.1726 0.1899 0.3658 0.2 +0.4374 2.8541 1.45894 200.25 +2.5923 0.1904 0.6971 0.3 +1.3083 2.5462 1.3658 100.35 +1.4981 1.3929 2.949 0.4 +2.1304 2.055 0.6597455 1.45 \ No newline at end of file diff --git a/Triangulation/applications/Triangulation/points_to_RT_to_off.cpp b/Triangulation/applications/Triangulation/points_to_RT_to_off.cpp index f35d94ced4d..3c227738ed7 100644 --- a/Triangulation/applications/Triangulation/points_to_RT_to_off.cpp +++ b/Triangulation/applications/Triangulation/points_to_RT_to_off.cpp @@ -9,22 +9,34 @@ typedef CGAL::Epick_d K; typedef CGAL::Regular_triangulation_euclidean_traits Traits; typedef CGAL::Regular_triangulation RT; -int main() +void test(int dim) { - std::ifstream in("data/points.cin"); + std::stringstream input_filename; + input_filename << "data/points_" << dim << ".cin"; + std::ifstream in(input_filename.str()); RT::Weighted_point wp; std::vector wpoints; - int dim; - in >> dim; + int dim_from_file; + in >> dim_from_file; while(in >> wp) wpoints.push_back(wp); // Build the Regular Triangulation - RT rt(dim); + RT rt(dim_from_file); rt.insert(wpoints.begin(), wpoints.end()); - std::ofstream off_stream("data/rt.off"); - CGAL::export_triangulation_to_off(off_stream, rt); + + // Export + std::stringstream output_filename; + output_filename << "data/rt_dim" << dim << ".off"; + std::ofstream off_stream(output_filename.str()); + CGAL::export_triangulation_to_off(off_stream, rt, false); +} + +int main() +{ + test(2); + test(3); return 0; } diff --git a/Triangulation/include/CGAL/IO/Triangulation_off_ostream.h b/Triangulation/include/CGAL/IO/Triangulation_off_ostream.h index d28e54a8a6c..9f40181db6c 100644 --- a/Triangulation/include/CGAL/IO/Triangulation_off_ostream.h +++ b/Triangulation/include/CGAL/IO/Triangulation_off_ostream.h @@ -107,7 +107,8 @@ operator>>(std::istream &is, typename Wrap::Weighted_point_d & wp) template < class GT, class TDS > std::ostream & export_triangulation_to_off(std::ostream & os, - const Triangulation & tr) + const Triangulation & tr, + bool in_3D_export_surface_only = true) { typedef Triangulation Tr; typedef typename Tr::Vertex_const_handle Vertex_handle; @@ -162,21 +163,53 @@ export_triangulation_to_off(std::ostream & os, } else if (tr.maximal_dimension() == 3) { - // Parse boundary facets - for (Full_cell_iterator fch = tr.full_cells_begin() ; - fch != tr.full_cells_end() ; ++fch) + if (in_3D_export_surface_only) { - if (tr.is_infinite(fch)) + // Parse boundary facets + for (Full_cell_iterator fch = tr.full_cells_begin() ; + fch != tr.full_cells_end() ; ++fch) { - output << "3 "; - for (Full_cell_vertex_iterator vit = fch->vertices_begin() ; - vit != fch->vertices_end() ; ++vit, ++i) + if (tr.is_infinite(fch)) { - if (!tr.is_infinite(*vit)) - output << index_of_vertex[*vit] << " "; + output << "3 "; + for (Full_cell_vertex_iterator vit = fch->vertices_begin() ; + vit != fch->vertices_end() ; ++vit) + { + if (!tr.is_infinite(*vit)) + output << index_of_vertex[*vit] << " "; + } + output << std::endl; + ++number_of_triangles; } - output << std::endl; - ++number_of_triangles; + } + } + else + { + // Parse boundary facets + for (Finite_full_cell_iterator fch = tr.finite_full_cells_begin() ; + fch != tr.finite_full_cells_end() ; ++fch) + { + output << "3 " + << index_of_vertex[fch->vertex(0)] << " " + << index_of_vertex[fch->vertex(1)] << " " + << index_of_vertex[fch->vertex(2)] + << std::endl; + output << "3 " + << index_of_vertex[fch->vertex(0)] << " " + << index_of_vertex[fch->vertex(2)] << " " + << index_of_vertex[fch->vertex(3)] + << std::endl; + output << "3 " + << index_of_vertex[fch->vertex(1)] << " " + << index_of_vertex[fch->vertex(2)] << " " + << index_of_vertex[fch->vertex(3)] + << std::endl; + output << "3 " + << index_of_vertex[fch->vertex(0)] << " " + << index_of_vertex[fch->vertex(1)] << " " + << index_of_vertex[fch->vertex(3)] + << std::endl; + number_of_triangles += 4; } } }