From 2570c21b7017f8a73c940f60954a971c999a7eae Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 23 Aug 2018 15:24:32 +0200 Subject: [PATCH 01/47] WIP tests with c3t3 and meshdomain ID --- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 283 +++++++++++++++++- 1 file changed, 277 insertions(+), 6 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index a73e7b3f62e..dc9c79214ba 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -83,6 +83,236 @@ typedef Scene_polyhedron_item Scene_facegraph_item; #endif typedef Scene_facegraph_item::Face_graph FaceGraph; typedef boost::property_traits::type>::value_type Point; + + + +// writes the appended data into the .vtu file +template +void +write_vector(std::ostream& os, + const std::vector& vect) +{ + const char* buffer = reinterpret_cast(&(vect[0])); + std::size_t size = vect.size()*sizeof(FT); + + os.write(reinterpret_cast(&size), sizeof(std::size_t)); // number of bytes encoded + os.write(buffer, vect.size()*sizeof(FT)); // encoded data +} + +// writes the cells tags before binary data is appended +template +void +write_cells_tag(std::ostream& os, + const C3T3 & c3t3, + std::map & V, + bool binary, + std::size_t& offset) +{ + typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; + std::string formatattribute = + binary ? " format=\"appended\"" : " format=\"ascii\""; + + std::string typeattribute; + switch(sizeof(std::size_t)) { + case 8: typeattribute = " type=\"UInt64\""; break; + case 4: typeattribute = " type=\"UInt32\""; break; + default: CGAL_error_msg("Unknown size of std::size_t"); + } + + // Write connectivity table + os << " \n" + << " \n"; + offset += (4 * c3t3.number_of_cells() + 1) * sizeof(std::size_t); + // 4 indices (size_t) per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + { + for (int i=0; i<4; i++) + os << V[cit->vertex(i)] << " "; + } + os << " \n"; + } + + // Write offsets + os << " \n"; + offset += (c3t3.number_of_cells() + 1) * sizeof(std::size_t); + // 1 offset (size_t) per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + std::size_t cells_offset = 0; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + { + cells_offset += 4; + os << cells_offset << " "; + } + os << " \n"; + } + + // Write cell type (tetrahedra == 10) + os << " \n"; + offset += c3t3.number_of_cells() + sizeof(std::size_t); + // 1 unsigned char per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + os << "10 "; + os << " \n"; + } + os << " \n"; +} + +// writes the cells appended data at the end of the .vtu file +template +void +write_cells(std::ostream& os, + const C3T3 & c3t3, + std::map & V, + std::vector& mids) +{ + typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; + std::vector connectivity_table; + std::vector offsets; + std::vector cell_type(c3t3.number_of_cells(),10); // tetrahedra == 10 + + std::size_t off = 0; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + { + off += 4; + offsets.push_back(off); + for (int i=0; i<4; i++) + connectivity_table.push_back(V[cit->vertex(i)]); + mids.push_back(cit->subdomain_index()); + } + write_vector(os,connectivity_table); + write_vector(os,offsets); + write_vector(os,cell_type); +} + + +// writes the points tags before binary data is appended +template +void +write_points_tag(std::ostream& os, + const Tr & tr, + std::map & V, + bool binary, + std::size_t& offset) +{ + typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; + typedef typename Tr::Geom_traits Gt; + typedef typename Gt::FT FT; + + std::size_t inum = 0; + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; + + os << " \n" + << " \n"; + offset += 3 * tr.number_of_vertices() * sizeof(FT) + sizeof(std::size_t); + // 3 coords per points + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); + vit != tr.finite_vertices_end(); + ++vit) + { + V[vit] = inum++; + os << vit->point().x() << " " << vit->point().y() << " " << vit->point().z() << " "; + } + os << " \n"; + } + os << " \n"; +} + +// writes the points appended data at the end of the .vtu file +template +void +write_points(std::ostream& os, + const Tr & tr, + std::map & V) +{ + typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; + typedef typename Tr::Geom_traits Gt; + typedef typename Gt::FT FT; + + std::size_t inum = 0; + std::vector coordinates; + for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); + vit != tr.finite_vertices_end(); + ++vit) + { + V[vit] = inum++; // binary output => the map has not been filled yet + coordinates.push_back(vit->point().x()); + coordinates.push_back(vit->point().y()); + coordinates.push_back(vit->point().z()); + } + write_vector(os,coordinates); +} + +// writes the attribute tags before binary data is appended +template +void +write_attribute_tag(std::ostream& os, + const std::string& attr_name, + const std::vector& attribute, + bool binary, + std::size_t& offset) +{ + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(T) == 8) ? "Float64" : "Float32"; + os << " \n"; + offset += attribute.size() * sizeof(T) + sizeof(std::size_t); + } + else { + typedef typename std::vector::const_iterator Iterator; + os << "\">\n"; + for (Iterator it = attribute.begin(); + it != attribute.end(); + ++it ) + os << *it << " "; + os << " \n"; + } +} + +// writes the attributes appended data at the end of the .vtu file +template +void +write_attributes(std::ostream& os, + const std::vector& att) +{ + write_vector(os,att); +} namespace CGAL{ class ErrorObserverVtk : public vtkCommand @@ -300,6 +530,8 @@ public: return (qobject_cast(item) || qobject_cast(item)); } + + bool save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) { std::string extension = fileinfo.suffix().toLower().toStdString(); @@ -328,12 +560,51 @@ public: qobject_cast(item); if(!c3t3_item || extension != "vtu") return false; - - vtkSmartPointer writer = - vtkSmartPointer::New(); - writer->SetFileName( output_filename.data()); - writer->SetInputData(CGAL::output_c3t3_to_vtk_unstructured_grid(c3t3_item->c3t3())); - writer->Write(); + + typedef typename C3t3::Triangulation Tr; + typedef typename Tr::Vertex_handle Vertex_handle; + const C3t3& c3t3 = c3t3_item->c3t3(); + const Tr& tr = c3t3.triangulation(); + std::map V; + std::ofstream os(output_filename.data()); + os << std::setprecision(16); + //write header + os << "\n" + << "\n" + << " " << "\n"; + + os << " \n"; + bool binary = true; + std::size_t offset = 0; + write_points_tag(os,tr,V,binary,offset); + write_cells_tag(os,c3t3,V,binary,offset); + os << " \n"; + std::vector mids; + write_attribute_tag(os,"MeshDomain",mids,binary,offset); + os << " \n"; + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + write_points(os,tr,V); // write points before cells to fill the std::map V + write_cells(os,c3t3,V, mids);//todo mids should be filled by write_attribute_tag + write_attributes(os,mids); + } + os << "\n"; } return true; } From b29534c73d7b0caf1ee6356a146bde55fd13c079 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 27 Aug 2018 10:21:52 +0200 Subject: [PATCH 02/47] vtp in plugin --- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 302 +++++++++++++++++- 1 file changed, 288 insertions(+), 14 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index dc9c79214ba..eece21fd26b 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -76,6 +76,9 @@ #include #include +#include +#include + #ifdef USE_SURFACE_MESH typedef Scene_surface_mesh_item Scene_facegraph_item; #else @@ -90,7 +93,7 @@ typedef boost::property_traits void write_vector(std::ostream& os, - const std::vector& vect) + const std::vector& vect) { const char* buffer = reinterpret_cast(&(vect[0])); std::size_t size = vect.size()*sizeof(FT); @@ -103,10 +106,10 @@ write_vector(std::ostream& os, template void write_cells_tag(std::ostream& os, - const C3T3 & c3t3, - std::map & V, - bool binary, - std::size_t& offset) + const C3T3 & c3t3, + std::map & V, + bool binary, + std::size_t& offset) { typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; std::string formatattribute = @@ -187,8 +190,8 @@ write_cells_tag(std::ostream& os, template void write_cells(std::ostream& os, - const C3T3 & c3t3, - std::map & V, + const C3T3 & c3t3, + std::map & V, std::vector& mids) { typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; @@ -212,15 +215,165 @@ write_cells(std::ostream& os, write_vector(os,cell_type); } +// writes the polys appended data at the end of the .vtp file +template +void +write_polys(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + std::vector connectivity_table; + std::vector offsets; + std::vector cell_type(num_faces(mesh),5); // triangle == 5 + + std::size_t off = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + off += 3; + offsets.push_back(off); + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + connectivity_table.push_back(V[v]); + } + write_vector(os,connectivity_table); + write_vector(os,offsets); + write_vector(os,cell_type); +} +//overload +template +void +write_polys(std::ostream& os, + const Mesh & mesh) +{ + write_polys(os, mesh, CGAL::parameters::all_default()); +} +//todo use named params for maps +template +void +write_polys_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + + std::string formatattribute = + binary ? " format=\"appended\"" : " format=\"ascii\""; + std::string typeattribute; + switch(sizeof(std::size_t)) { + case 8: typeattribute = " type=\"UInt64\""; break; + case 4: typeattribute = " type=\"UInt32\""; break; + default: CGAL_error_msg("Unknown size of std::size_t"); + } + + // Write connectivity table + os << " \n" + << " \n"; + offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); + // 3 indices (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + os << V[v] << " "; + } + os << " \n"; + } + + // Write offsets + os << " \n"; + offset += (num_faces(mesh) + 1) * sizeof(std::size_t); + // 1 offset (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + std::size_t polys_offset = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + polys_offset += 3; + os << polys_offset << " "; + } + os << " \n"; + } + + // Write cell type (triangle == 5) + os << " \n"; + offset += num_faces(mesh) + sizeof(std::size_t); + // 1 unsigned char per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for(std::size_t i = 0; i< num_faces(mesh); ++i) + os << "5 "; + os << " \n"; + } + os << " \n"; +} +//overload +template +void +write_polys_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset) +{ + write_polys_tag(os, + mesh, + binary, + offset, + CGAL::parameters::all_default()); +} // writes the points tags before binary data is appended template void write_points_tag(std::ostream& os, - const Tr & tr, - std::map & V, - bool binary, - std::size_t& offset) + const Tr & tr, + std::map & V, + bool binary, + std::size_t& offset) { typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; typedef typename Tr::Geom_traits Gt; @@ -252,6 +405,58 @@ write_points_tag(std::ostream& os, os << " \n"; } +//todo : use namedparams for points and ids +//overload for facegraph +template +void +write_points_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; + + os << " \n" + << " \n"; + offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); + // 3 coords per points + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + os << get(vpm, *vit).x() << " " << get(vpm, *vit).y() << " " << get(vpm, *vit).z() << " "; + } + os << " \n"; + } + os << " \n"; +} +//overload +template +void +write_points_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset) +{ + write_points_tag(os, mesh, binary, offset, CGAL::parameters::all_default()); +} // writes the points appended data at the end of the .vtu file template void @@ -277,6 +482,40 @@ write_points(std::ostream& os, write_vector(os,coordinates); } +// writes the points appended data at the end of the .vtp file +template +void +write_polys_points(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + std::vector coordinates; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + coordinates.push_back(get(vpm, *vit).x()); + coordinates.push_back(get(vpm, *vit).y()); + coordinates.push_back(get(vpm, *vit).z()); + } + write_vector(os,coordinates); +} +//overload +template +void +write_polys_points(std::ostream& os, + const Mesh & mesh) +{ + write_polys_points(os, mesh, CGAL::parameters::all_default()); +} // writes the attribute tags before binary data is appended template void @@ -550,9 +789,44 @@ public: *poly_item->polyhedron(), output_filename.data()); else - CGAL::polygon_mesh_to_vtkUnstructured( - *poly_item->polyhedron(), - output_filename.data()); + { + const FaceGraph* mesh = poly_item->face_graph(); + std::ofstream os(output_filename.data()); + os << std::setprecision(16); + //write header + os << "\n" + << "\n" + << " " << "\n"; + + os << " \n"; + bool binary = true; + std::size_t offset = 0; + write_points_tag(os,*mesh,binary,offset); + write_polys_tag(os,*mesh,binary,offset); + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + write_polys_points(os,*mesh); // write points before cells to fill the std::map V + write_polys(os,*mesh); + } + os << "\n"; + } + // CGAL::polygon_mesh_to_vtkUnstructured( + // *poly_item->polyhedron(), + // output_filename.data()); } else { From 06db5dafbcf5180993a4a19f6d60d5997fa737ac Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 27 Aug 2018 14:56:18 +0200 Subject: [PATCH 03/47] WIP integrate functions. --- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 542 +------------- Stream_support/include/CGAL/IO/vtk_io.h | 668 ++++++++++++++++++ 2 files changed, 674 insertions(+), 536 deletions(-) create mode 100644 Stream_support/include/CGAL/IO/vtk_io.h diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index eece21fd26b..656869b2847 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -85,473 +86,12 @@ typedef Scene_surface_mesh_item Scene_facegraph_item; typedef Scene_polyhedron_item Scene_facegraph_item; #endif typedef Scene_facegraph_item::Face_graph FaceGraph; -typedef boost::property_traits::type>::value_type Point; +typedef boost::property_traits::type>::value_type Point; -// writes the appended data into the .vtu file -template -void -write_vector(std::ostream& os, - const std::vector& vect) -{ - const char* buffer = reinterpret_cast(&(vect[0])); - std::size_t size = vect.size()*sizeof(FT); - - os.write(reinterpret_cast(&size), sizeof(std::size_t)); // number of bytes encoded - os.write(buffer, vect.size()*sizeof(FT)); // encoded data -} -// writes the cells tags before binary data is appended -template -void -write_cells_tag(std::ostream& os, - const C3T3 & c3t3, - std::map & V, - bool binary, - std::size_t& offset) -{ - typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; - std::string formatattribute = - binary ? " format=\"appended\"" : " format=\"ascii\""; - - std::string typeattribute; - switch(sizeof(std::size_t)) { - case 8: typeattribute = " type=\"UInt64\""; break; - case 4: typeattribute = " type=\"UInt32\""; break; - default: CGAL_error_msg("Unknown size of std::size_t"); - } - - // Write connectivity table - os << " \n" - << " \n"; - offset += (4 * c3t3.number_of_cells() + 1) * sizeof(std::size_t); - // 4 indices (size_t) per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; - cit != c3t3.cells_in_complex_end() ; - ++cit ) - { - for (int i=0; i<4; i++) - os << V[cit->vertex(i)] << " "; - } - os << " \n"; - } - - // Write offsets - os << " \n"; - offset += (c3t3.number_of_cells() + 1) * sizeof(std::size_t); - // 1 offset (size_t) per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - std::size_t cells_offset = 0; - for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; - cit != c3t3.cells_in_complex_end() ; - ++cit ) - { - cells_offset += 4; - os << cells_offset << " "; - } - os << " \n"; - } - - // Write cell type (tetrahedra == 10) - os << " \n"; - offset += c3t3.number_of_cells() + sizeof(std::size_t); - // 1 unsigned char per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; - cit != c3t3.cells_in_complex_end() ; - ++cit ) - os << "10 "; - os << " \n"; - } - os << " \n"; -} - -// writes the cells appended data at the end of the .vtu file -template -void -write_cells(std::ostream& os, - const C3T3 & c3t3, - std::map & V, - std::vector& mids) -{ - typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; - std::vector connectivity_table; - std::vector offsets; - std::vector cell_type(c3t3.number_of_cells(),10); // tetrahedra == 10 - - std::size_t off = 0; - for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; - cit != c3t3.cells_in_complex_end() ; - ++cit ) - { - off += 4; - offsets.push_back(off); - for (int i=0; i<4; i++) - connectivity_table.push_back(V[cit->vertex(i)]); - mids.push_back(cit->subdomain_index()); - } - write_vector(os,connectivity_table); - write_vector(os,offsets); - write_vector(os,cell_type); -} - -// writes the polys appended data at the end of the .vtp file -template -void -write_polys(std::ostream& os, - const Mesh & mesh, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::face_iterator face_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; - Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), - get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - std::vector connectivity_table; - std::vector offsets; - std::vector cell_type(num_faces(mesh),5); // triangle == 5 - - std::size_t off = 0; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - off += 3; - offsets.push_back(off); - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - connectivity_table.push_back(V[v]); - } - write_vector(os,connectivity_table); - write_vector(os,offsets); - write_vector(os,cell_type); -} -//overload -template -void -write_polys(std::ostream& os, - const Mesh & mesh) -{ - write_polys(os, mesh, CGAL::parameters::all_default()); -} -//todo use named params for maps -template -void -write_polys_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::face_iterator face_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; - Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), - get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - - - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - - std::string formatattribute = - binary ? " format=\"appended\"" : " format=\"ascii\""; - - std::string typeattribute; - switch(sizeof(std::size_t)) { - case 8: typeattribute = " type=\"UInt64\""; break; - case 4: typeattribute = " type=\"UInt32\""; break; - default: CGAL_error_msg("Unknown size of std::size_t"); - } - - // Write connectivity table - os << " \n" - << " \n"; - offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); - // 3 indices (size_t) per triangle + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - os << V[v] << " "; - } - os << " \n"; - } - - // Write offsets - os << " \n"; - offset += (num_faces(mesh) + 1) * sizeof(std::size_t); - // 1 offset (size_t) per triangle + length of the encoded data (size_t) - } - else { - os << "\">\n"; - std::size_t polys_offset = 0; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - polys_offset += 3; - os << polys_offset << " "; - } - os << " \n"; - } - - // Write cell type (triangle == 5) - os << " \n"; - offset += num_faces(mesh) + sizeof(std::size_t); - // 1 unsigned char per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for(std::size_t i = 0; i< num_faces(mesh); ++i) - os << "5 "; - os << " \n"; - } - os << " \n"; -} -//overload -template -void -write_polys_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset) -{ - write_polys_tag(os, - mesh, - binary, - offset, - CGAL::parameters::all_default()); -} -// writes the points tags before binary data is appended -template -void -write_points_tag(std::ostream& os, - const Tr & tr, - std::map & V, - bool binary, - std::size_t& offset) -{ - typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; - typedef typename Tr::Geom_traits Gt; - typedef typename Gt::FT FT; - - std::size_t inum = 0; - std::string format = binary ? "appended" : "ascii"; - std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; - - os << " \n" - << " \n"; - offset += 3 * tr.number_of_vertices() * sizeof(FT) + sizeof(std::size_t); - // 3 coords per points + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); - vit != tr.finite_vertices_end(); - ++vit) - { - V[vit] = inum++; - os << vit->point().x() << " " << vit->point().y() << " " << vit->point().z() << " "; - } - os << " \n"; - } - os << " \n"; -} - -//todo : use namedparams for points and ids -//overload for facegraph -template -void -write_points_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_iterator vertex_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), - get_const_property_map(CGAL::vertex_point, mesh)); - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - - std::string format = binary ? "appended" : "ascii"; - std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; - - os << " \n" - << " \n"; - offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); - // 3 coords per points + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( vertex_iterator vit = vertices(mesh).begin(); - vit != vertices(mesh).end(); - ++vit) - { - os << get(vpm, *vit).x() << " " << get(vpm, *vit).y() << " " << get(vpm, *vit).z() << " "; - } - os << " \n"; - } - os << " \n"; -} -//overload -template -void -write_points_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset) -{ - write_points_tag(os, mesh, binary, offset, CGAL::parameters::all_default()); -} -// writes the points appended data at the end of the .vtu file -template -void -write_points(std::ostream& os, - const Tr & tr, - std::map & V) -{ - typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; - typedef typename Tr::Geom_traits Gt; - typedef typename Gt::FT FT; - - std::size_t inum = 0; - std::vector coordinates; - for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); - vit != tr.finite_vertices_end(); - ++vit) - { - V[vit] = inum++; // binary output => the map has not been filled yet - coordinates.push_back(vit->point().x()); - coordinates.push_back(vit->point().y()); - coordinates.push_back(vit->point().z()); - } - write_vector(os,coordinates); -} - -// writes the points appended data at the end of the .vtp file -template -void -write_polys_points(std::ostream& os, - const Mesh & mesh, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_iterator vertex_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), - get_const_property_map(CGAL::vertex_point, mesh)); - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - std::vector coordinates; - for( vertex_iterator vit = vertices(mesh).begin(); - vit != vertices(mesh).end(); - ++vit) - { - coordinates.push_back(get(vpm, *vit).x()); - coordinates.push_back(get(vpm, *vit).y()); - coordinates.push_back(get(vpm, *vit).z()); - } - write_vector(os,coordinates); -} -//overload -template -void -write_polys_points(std::ostream& os, - const Mesh & mesh) -{ - write_polys_points(os, mesh, CGAL::parameters::all_default()); -} -// writes the attribute tags before binary data is appended -template -void -write_attribute_tag(std::ostream& os, - const std::string& attr_name, - const std::vector& attribute, - bool binary, - std::size_t& offset) -{ - std::string format = binary ? "appended" : "ascii"; - std::string type = (sizeof(T) == 8) ? "Float64" : "Float32"; - os << " \n"; - offset += attribute.size() * sizeof(T) + sizeof(std::size_t); - } - else { - typedef typename std::vector::const_iterator Iterator; - os << "\">\n"; - for (Iterator it = attribute.begin(); - it != attribute.end(); - ++it ) - os << *it << " "; - os << " \n"; - } -} - -// writes the attributes appended data at the end of the .vtu file -template -void -write_attributes(std::ostream& os, - const std::vector& att) -{ - write_vector(os,att); -} namespace CGAL{ class ErrorObserverVtk : public vtkCommand @@ -794,39 +334,8 @@ public: std::ofstream os(output_filename.data()); os << std::setprecision(16); //write header - os << "\n" - << "\n" - << " " << "\n"; - - os << " \n"; - bool binary = true; - std::size_t offset = 0; - write_points_tag(os,*mesh,binary,offset); - write_polys_tag(os,*mesh,binary,offset); - os << " \n" - << " \n"; - if (binary) { - os << "\n_"; - write_polys_points(os,*mesh); // write points before cells to fill the std::map V - write_polys(os,*mesh); - } - os << "\n"; + CGAL::write_polydata(os, *mesh); } - // CGAL::polygon_mesh_to_vtkUnstructured( - // *poly_item->polyhedron(), - // output_filename.data()); } else { @@ -835,50 +344,11 @@ public: if(!c3t3_item || extension != "vtu") return false; - typedef typename C3t3::Triangulation Tr; - typedef typename Tr::Vertex_handle Vertex_handle; - const C3t3& c3t3 = c3t3_item->c3t3(); - const Tr& tr = c3t3.triangulation(); - std::map V; std::ofstream os(output_filename.data()); os << std::setprecision(16); - //write header - os << "\n" - << "c3t3(); - switch(sizeof(std::size_t)) { - case 4: os << " header_type=\"UInt32\""; break; - case 8: os << " header_type=\"UInt64\""; break; - default: CGAL_error_msg("Unknown size of std::size_t"); - } - os << ">\n" - << " " << "\n"; - - os << " \n"; - bool binary = true; - std::size_t offset = 0; - write_points_tag(os,tr,V,binary,offset); - write_cells_tag(os,c3t3,V,binary,offset); - os << " \n"; - std::vector mids; - write_attribute_tag(os,"MeshDomain",mids,binary,offset); - os << " \n"; - os << " \n" - << " \n"; - if (binary) { - os << "\n_"; - write_points(os,tr,V); // write points before cells to fill the std::map V - write_cells(os,c3t3,V, mids);//todo mids should be filled by write_attribute_tag - write_attributes(os,mids); - } - os << "\n"; + CGAL::write_unstructured_grid_3(os, c3t3); } return true; } diff --git a/Stream_support/include/CGAL/IO/vtk_io.h b/Stream_support/include/CGAL/IO/vtk_io.h new file mode 100644 index 00000000000..660afbd7d91 --- /dev/null +++ b/Stream_support/include/CGAL/IO/vtk_io.h @@ -0,0 +1,668 @@ +// Copyright (c) 2018 GeometryFactory (France). +// Copyright (c) 2004-2006 INRIA Sophia-Antipolis (France). +// Copyright (c) 2009 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno + +#ifndef CGAL_VTK_IO_H +#define CGAL_VTK_IO_H + +#include +#include + +#include +#include + + + +namespace CGAL{ +// writes the appended data into the .vtu file +template +void +write_vector(std::ostream& os, + const std::vector& vect) +{ + const char* buffer = reinterpret_cast(&(vect[0])); + std::size_t size = vect.size()*sizeof(FT); + + os.write(reinterpret_cast(&size), sizeof(std::size_t)); // number of bytes encoded + os.write(buffer, vect.size()*sizeof(FT)); // encoded data +} + +// writes the cells tags before binary data is appended +template +void +write_cells_tag(std::ostream& os, + const C3T3 & c3t3, + std::map & V, + bool binary, + std::size_t& offset) +{ + typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; + std::string formatattribute = + binary ? " format=\"appended\"" : " format=\"ascii\""; + + std::string typeattribute; + switch(sizeof(std::size_t)) { + case 8: typeattribute = " type=\"UInt64\""; break; + case 4: typeattribute = " type=\"UInt32\""; break; + default: CGAL_error_msg("Unknown size of std::size_t"); + } + + // Write connectivity table + os << " \n" + << " \n"; + offset += (4 * c3t3.number_of_cells() + 1) * sizeof(std::size_t); + // 4 indices (size_t) per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + { + for (int i=0; i<4; i++) + os << V[cit->vertex(i)] << " "; + } + os << " \n"; + } + + // Write offsets + os << " \n"; + offset += (c3t3.number_of_cells() + 1) * sizeof(std::size_t); + // 1 offset (size_t) per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + std::size_t cells_offset = 0; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + { + cells_offset += 4; + os << cells_offset << " "; + } + os << " \n"; + } + + // Write cell type (tetrahedra == 10) + os << " \n"; + offset += c3t3.number_of_cells() + sizeof(std::size_t); + // 1 unsigned char per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + os << "10 "; + os << " \n"; + } + os << " \n"; +} + +// writes the cells appended data at the end of the .vtu file +template +void +write_cells(std::ostream& os, + const C3T3 & c3t3, + std::map & V, + std::vector& mids) +{ + typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; + std::vector connectivity_table; + std::vector offsets; + std::vector cell_type(c3t3.number_of_cells(),10); // tetrahedra == 10 + + std::size_t off = 0; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + { + off += 4; + offsets.push_back(off); + for (int i=0; i<4; i++) + connectivity_table.push_back(V[cit->vertex(i)]); + mids.push_back(cit->subdomain_index()); + } + write_vector(os,connectivity_table); + write_vector(os,offsets); + write_vector(os,cell_type); +} + +// writes the polys appended data at the end of the .vtp file +template +void +write_polys(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + std::vector connectivity_table; + std::vector offsets; + std::vector cell_type(num_faces(mesh),5); // triangle == 5 + + std::size_t off = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + off += 3; + offsets.push_back(off); + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + connectivity_table.push_back(V[v]); + } + write_vector(os,connectivity_table); + write_vector(os,offsets); + write_vector(os,cell_type); +} +//overload +template +void +write_polys(std::ostream& os, + const Mesh & mesh) +{ + write_polys(os, mesh, CGAL::parameters::all_default()); +} +//todo use named params for maps +template +void +write_polys_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + + std::string formatattribute = + binary ? " format=\"appended\"" : " format=\"ascii\""; + + std::string typeattribute; + switch(sizeof(std::size_t)) { + case 8: typeattribute = " type=\"UInt64\""; break; + case 4: typeattribute = " type=\"UInt32\""; break; + default: CGAL_error_msg("Unknown size of std::size_t"); + } + + // Write connectivity table + os << " \n" + << " \n"; + offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); + // 3 indices (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + os << V[v] << " "; + } + os << " \n"; + } + + // Write offsets + os << " \n"; + offset += (num_faces(mesh) + 1) * sizeof(std::size_t); + // 1 offset (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + std::size_t polys_offset = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + polys_offset += 3; + os << polys_offset << " "; + } + os << " \n"; + } + + // Write cell type (triangle == 5) + os << " \n"; + offset += num_faces(mesh) + sizeof(std::size_t); + // 1 unsigned char per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for(std::size_t i = 0; i< num_faces(mesh); ++i) + os << "5 "; + os << " \n"; + } + os << " \n"; +} +//overload +template +void +write_polys_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset) +{ + write_polys_tag(os, + mesh, + binary, + offset, + CGAL::parameters::all_default()); +} +// writes the points tags before binary data is appended +template +void +write_points_tag(std::ostream& os, + const Tr & tr, + std::map & V, + bool binary, + std::size_t& offset, + std::size_t dim) +{ + typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; + typedef typename Tr::Geom_traits Gt; + typedef typename Gt::FT FT; + + std::size_t inum = 0; + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; + + os << " \n" + << " \n"; + offset += dim * tr.number_of_vertices() * sizeof(FT) + sizeof(std::size_t); + // dim coords per points + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); + vit != tr.finite_vertices_end(); + ++vit) + { + V[vit] = inum++; + os << vit->point().x() << " " << vit->point().y()<< " " ; + if(dim == 3) + os << vit->point().z() << " "; + } + os << " \n"; + } + os << " \n"; +} + +//todo : use namedparams for points and ids +//overload for facegraph +template +void +write_points_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; + + os << " \n" + << " \n"; + offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); + // 3 coords per points + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + os << get(vpm, *vit).x() << " " << get(vpm, *vit).y() << " " + << get(vpm, *vit).z() << " "; + } + os << " \n"; + } + os << " \n"; +} +//overload +template +void +write_points_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset) +{ + write_points_tag(os, mesh, binary, offset, CGAL::parameters::all_default()); +} +// writes the points appended data at the end of the .vtu file +template +void +write_points(std::ostream& os, + const Tr & tr, + std::map & V, + std::size_t dim) +{ + typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; + typedef typename Tr::Geom_traits Gt; + typedef typename Gt::FT FT; + + std::size_t inum = 0; + std::vector coordinates; + for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); + vit != tr.finite_vertices_end(); + ++vit) + { + V[vit] = inum++; // binary output => the map has not been filled yet + coordinates.push_back(vit->point().x()); + coordinates.push_back(vit->point().y()); + if(dim == 3) + coordinates.push_back(vit->point().z()); + } + write_vector(os,coordinates); +} + +// writes the points appended data at the end of the .vtp file +template +void +write_polys_points(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + std::vector coordinates; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + coordinates.push_back(get(vpm, *vit).x()); + coordinates.push_back(get(vpm, *vit).y()); + coordinates.push_back(get(vpm, *vit).z()); + } + write_vector(os,coordinates); +} +//overload +template +void +write_polys_points(std::ostream& os, + const Mesh & mesh) +{ + write_polys_points(os, mesh, CGAL::parameters::all_default()); +} +// writes the attribute tags before binary data is appended +template +void +write_attribute_tag(std::ostream& os, + const std::string& attr_name, + const std::vector& attribute, + bool binary, + std::size_t& offset) +{ + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(T) == 8) ? "Float64" : "Float32"; + os << " \n"; + offset += attribute.size() * sizeof(T) + sizeof(std::size_t); + } + else { + typedef typename std::vector::const_iterator Iterator; + os << "\">\n"; + for (Iterator it = attribute.begin(); + it != attribute.end(); + ++it ) + os << *it << " "; + os << " \n"; + } +} + +// writes the attributes appended data at the end of the .vtu file +template +void +write_attributes(std::ostream& os, + const std::vector& att) +{ + write_vector(os,att); +} + +template +void write_unstructured_grid(std::ostream& os, + const C3t3& c3t3, + std::size_t dim) +{ + typedef typename C3t3::Triangulation Tr; + typedef typename Tr::Vertex_handle Vertex_handle; + const Tr& tr = c3t3.triangulation(); + std::map V; + //write header + os << "\n" + << "\n" + << " " << "\n"; + + os << " \n"; + bool binary = true; + std::size_t offset = 0; + write_points_tag(os,tr,V,binary,offset, dim); + write_cells_tag(os,c3t3,V,binary,offset); + if(dim==3) + { + os << " \n"; + std::vector mids; + write_attribute_tag(os,"MeshDomain",mids,binary,offset); + os << " \n"; + } + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + write_points(os,tr,V, dim); // write points before cells to fill the std::map V + write_cells(os,c3t3,V, mids);//todo mids should be filled by write_attribute_tag + if(dim==3) + write_attributes(os,mids); + } + os << "\n"; +} + +//public API + +//! +//! \brief write_polydata_3 writes the content of a triangulated surface mesh in the .vtp +//! XML format. +//! +//! \tparam TriangleMesh a model of `FaceListGraph` with triangle faces. +//! \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" +//! +//! \param os a `std::ostream`. +//! \param mesh an instance of `TriangleMesh` to be written. +//! \param binary decides if the data should be written in binary(`true`) +//! or in ASCII(`false`). +//! \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the +//! ones listed below +//! +//! \cgalNamedParamsBegin +//! \cgalParamBegin{vertex_point_map} the property map with the points associated to +//! the vertices of `mesh`. If this parameter is omitted, an internal property map for +//! `CGAL::vertex_point_t` must be available in `TriangleMesh`. +//! \cgalParamEnd +//! \cgalParamBegin{vertex_index_map} the property map with the indices associated to +//! the vertices of `mesh`. If this parameter is omitted, an internal property map for +//! `CGAL::vertex_index_t` must be available in `TriangleMesh`. +//! \cgalParamEnd +//! \cgalNamedParamsEnd +template +void write_polydata(std::ostream& os, + const TriangleMesh& mesh, + bool binary, + const NamedParameters& np) +{ + os << "\n" + << "\n" + << " " << "\n"; + + os << " \n"; + std::size_t offset = 0; + write_points_tag(os,mesh,binary,offset, np); + write_polys_tag(os,mesh,binary,offset, np); + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + write_polys_points(os,mesh, np); + write_polys(os,mesh, np); + } + os << "\n"; +} + +template +void write_polydata(std::ostream& os, + const TriangleMesh& mesh, + bool binary = true) +{ + write_polydata(os, mesh, binary, CGAL::parameters::all_default()); +} + +//! +//! \brief write_unstructured_grid_3 writes the content of a `C3t3` in the .vtu +//! XML format. +//! +//! \tparam C3T3 a model of `MeshComplexWithFeatures_3InTriangulation_3`. +//! +//! \param os a `std::ostream`. +//! \param c3t3 an instance of `C3T3` to be written. +//! \param binary decides if the data should be written in binary(`true`) +//! or in ASCII(`false`). +//! +template +void write_unstructured_grid_3(std::ostream& os, + const C3T3& c3t3) +{ + write_unstructured_grid(os, c3t3, 3); +} + +//! +//! \brief write_unstructured_grid_2 writes the content of a `CDT` in the .vtu +//! XML format. +//! +//! \tparam CDT must be 2D constrained Delaunay triangulation +//! +//! \param os a `std::ostream`. +//! \param tr ????????? +//! \param binary decides if the data should be written in binary(`true`) +//! or in ASCII(`false`). +//! +//! +template +void write_unstructured_grid_2(std::ostream& os, + const CDT& tr) +{ + write_unstructured_grid(os, tr, 2); +} +} //end CGAL +#endif // CGAL_VTK_IO_H From 223fa687c238e116d2b66a553ed847533bf0519d Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 27 Aug 2018 16:29:07 +0200 Subject: [PATCH 04/47] Add function for CDT. and use it in Triangulation_2 demo. Missing Doc --- .../Constrained_Delaunay_triangulation_2.cpp | 14 +- Stream_support/include/CGAL/IO/vtk_io.h | 367 ++++++++++++------ 2 files changed, 250 insertions(+), 131 deletions(-) diff --git a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp index 818d9f04c69..e505233e119 100644 --- a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp +++ b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp @@ -22,6 +22,7 @@ #include #include #include +#include // Qt headers #include @@ -658,9 +659,10 @@ MainWindow::on_actionSaveConstraints_triggered() tr("Save Constraints"), ".", tr("Poly files (*.poly)\n" - "Edge files (*.edg)")); + "Edge files (*.edg)\n" + "VTU files (*.vtu)")); if(! fileName.isEmpty()){ - saveConstraints(fileName); + saveConstraints(fileName); } } @@ -669,7 +671,13 @@ void MainWindow::saveConstraints(QString fileName) { std::ofstream output(qPrintable(fileName)); - if (output) output << cdt; + + if(!fileName.endsWith("vtu") && output) + output << cdt; + else if (output) + { + CGAL::write_unstructured_grid_2(output, cdt); + } } diff --git a/Stream_support/include/CGAL/IO/vtk_io.h b/Stream_support/include/CGAL/IO/vtk_io.h index 660afbd7d91..13382735c42 100644 --- a/Stream_support/include/CGAL/IO/vtk_io.h +++ b/Stream_support/include/CGAL/IO/vtk_io.h @@ -30,7 +30,7 @@ #include - +//todo try to factorize with functors namespace CGAL{ // writes the appended data into the .vtu file template @@ -46,6 +46,105 @@ write_vector(std::ostream& os, } // writes the cells tags before binary data is appended + +template +void +write_cells_tag_2(std::ostream& os, + const CDT & tr, + std::size_t number_of_triangles, + std::map & V, + bool binary, + std::size_t& offset) +{ + std::string formatattribute = + binary ? " format=\"appended\"" : " format=\"ascii\""; + + std::string typeattribute; + switch(sizeof(std::size_t)) { + case 8: typeattribute = " type=\"UInt64\""; break; + case 4: typeattribute = " type=\"UInt32\""; break; + default: CGAL_error_msg("Unknown size of std::size_t"); + } + + // Write connectivity table + os << " \n" + << " \n"; + offset += (3 * number_of_triangles + 1) * sizeof(std::size_t); + // 3 indices (size_t) per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for(typename CDT::Finite_faces_iterator + fit = tr.finite_faces_begin(), + end = tr.finite_faces_end(); + fit != end; ++fit) + { + if(fit->is_in_domain()) + { + os << V[fit->vertex(0)] << " "; + os << V[fit->vertex(2)] << " "; + os << V[fit->vertex(1)] << " "; + } + } + os << " \n"; + } + + // Write offsets + os << " \n"; + offset += (number_of_triangles + 1) * sizeof(std::size_t); + // 1 offset (size_t) per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + std::size_t cells_offset = 0; + for(typename CDT::Finite_faces_iterator fit = + tr.finite_faces_begin() ; + fit != tr.finite_faces_end() ; + ++fit ) + { + if(fit->is_in_domain()) + { + cells_offset += 3; + os << cells_offset << " "; + } + } + os << " \n"; + } + + // Write cell type (triangles == 5) + os << " \n"; + offset += number_of_triangles + sizeof(std::size_t); + // 1 unsigned char per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for(typename CDT::Finite_faces_iterator fit = + tr.finite_faces_begin() ; + fit != tr.finite_faces_end() ; + ++fit ) + { + if(fit->is_in_domain()) + { + os << "5 "; + } + } + os << " \n"; + } + os << " \n"; +} + template void write_cells_tag(std::ostream& os, @@ -130,6 +229,38 @@ write_cells_tag(std::ostream& os, } // writes the cells appended data at the end of the .vtu file +template +void +write_cells_2(std::ostream& os, + const CDT & tr, + std::size_t number_of_triangles, + std::map & V) +{ + std::vector connectivity_table; + std::vector offsets; + std::vector cell_type(number_of_triangles,5); // triangles == 5 + + std::size_t off = 0; + for(typename CDT::Finite_faces_iterator + fit = tr.finite_faces_begin(), + end = tr.finite_faces_end(); + fit != end; ++fit) + { + if(fit->is_in_domain()) + { + off += 3; + offsets.push_back(off); + connectivity_table.push_back(V[fit->vertex(0)]); + connectivity_table.push_back(V[fit->vertex(2)]); + connectivity_table.push_back(V[fit->vertex(1)]); + } + } + write_vector(os,connectivity_table); + write_vector(os,offsets); + write_vector(os,cell_type); +} + + template void write_cells(std::ostream& os, @@ -166,6 +297,7 @@ write_polys(std::ostream& os, const Mesh & mesh, const NamedParameters& np) { + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits::face_iterator face_iterator; typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; @@ -174,7 +306,6 @@ write_polys(std::ostream& os, typedef typename boost::property_traits::value_type Point_t; typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; std::vector connectivity_table; std::vector offsets; std::vector cell_type(num_faces(mesh),5); // triangle == 5 @@ -194,14 +325,6 @@ write_polys(std::ostream& os, write_vector(os,offsets); write_vector(os,cell_type); } -//overload -template -void -write_polys(std::ostream& os, - const Mesh & mesh) -{ - write_polys(os, mesh, CGAL::parameters::all_default()); -} //todo use named params for maps template @@ -212,6 +335,7 @@ write_polys_tag(std::ostream& os, std::size_t& offset, const NamedParameters& np) { + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits::face_iterator face_iterator; typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; @@ -221,7 +345,6 @@ write_polys_tag(std::ostream& os, typedef typename boost::property_traits::value_type Point_t; typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; std::string formatattribute = binary ? " format=\"appended\"" : " format=\"ascii\""; @@ -295,20 +418,6 @@ write_polys_tag(std::ostream& os, } os << " \n"; } -//overload -template -void -write_polys_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset) -{ - write_polys_tag(os, - mesh, - binary, - offset, - CGAL::parameters::all_default()); -} // writes the points tags before binary data is appended template void @@ -317,7 +426,7 @@ write_points_tag(std::ostream& os, std::map & V, bool binary, std::size_t& offset, - std::size_t dim) + std::size_t dim = 3) { typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; typedef typename Tr::Geom_traits Gt; @@ -328,25 +437,27 @@ write_points_tag(std::ostream& os, std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; os << " \n" - << " \n"; - offset += dim * tr.number_of_vertices() * sizeof(FT) + sizeof(std::size_t); + offset += 3 * tr.number_of_vertices() * sizeof(FT) + sizeof(std::size_t); // dim coords per points + length of the encoded data (size_t) } else { os << "\">\n"; for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); - vit != tr.finite_vertices_end(); - ++vit) - { - V[vit] = inum++; - os << vit->point().x() << " " << vit->point().y()<< " " ; - if(dim == 3) - os << vit->point().z() << " "; + vit != tr.finite_vertices_end(); + ++vit) + { + V[vit] = inum++; + os << vit->point()[0] << " "; + os << vit->point()[1] << " "; + if(dim == 3) + os << vit->point()[2] << " "; + else + os << 0.0 << " "; } os << " \n"; } @@ -397,23 +508,15 @@ write_points_tag(std::ostream& os, } os << " \n"; } -//overload -template -void -write_points_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset) -{ - write_points_tag(os, mesh, binary, offset, CGAL::parameters::all_default()); -} + // writes the points appended data at the end of the .vtu file template void write_points(std::ostream& os, const Tr & tr, - std::map & V, - std::size_t dim) + std::map & V, + std::size_t dim = 3) { typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; typedef typename Tr::Geom_traits Gt; @@ -426,10 +529,9 @@ write_points(std::ostream& os, ++vit) { V[vit] = inum++; // binary output => the map has not been filled yet - coordinates.push_back(vit->point().x()); - coordinates.push_back(vit->point().y()); - if(dim == 3) - coordinates.push_back(vit->point().z()); + coordinates.push_back(vit->point()[0]); + coordinates.push_back(vit->point()[1]); + coordinates.push_back(dim == 3 ? vit->point()[2] : 0.0); } write_vector(os,coordinates); } @@ -460,14 +562,6 @@ write_polys_points(std::ostream& os, } write_vector(os,coordinates); } -//overload -template -void -write_polys_points(std::ostream& os, - const Mesh & mesh) -{ - write_polys_points(os, mesh, CGAL::parameters::all_default()); -} // writes the attribute tags before binary data is appended template void @@ -505,58 +599,6 @@ write_attributes(std::ostream& os, write_vector(os,att); } -template -void write_unstructured_grid(std::ostream& os, - const C3t3& c3t3, - std::size_t dim) -{ - typedef typename C3t3::Triangulation Tr; - typedef typename Tr::Vertex_handle Vertex_handle; - const Tr& tr = c3t3.triangulation(); - std::map V; - //write header - os << "\n" - << "\n" - << " " << "\n"; - - os << " \n"; - bool binary = true; - std::size_t offset = 0; - write_points_tag(os,tr,V,binary,offset, dim); - write_cells_tag(os,c3t3,V,binary,offset); - if(dim==3) - { - os << " \n"; - std::vector mids; - write_attribute_tag(os,"MeshDomain",mids,binary,offset); - os << " \n"; - } - os << " \n" - << " \n"; - if (binary) { - os << "\n_"; - write_points(os,tr,V, dim); // write points before cells to fill the std::map V - write_cells(os,c3t3,V, mids);//todo mids should be filled by write_attribute_tag - if(dim==3) - write_attributes(os,mids); - } - os << "\n"; -} - //public API //! @@ -643,26 +685,95 @@ template void write_unstructured_grid_3(std::ostream& os, const C3T3& c3t3) { - write_unstructured_grid(os, c3t3, 3); + typedef typename C3T3::Triangulation Tr; + typedef typename Tr::Vertex_handle Vertex_handle; + const Tr& tr = c3t3.triangulation(); + std::map V; + //write header + os << "\n" + << "\n" + << " " << "\n"; + + os << " \n"; + bool binary = true; + std::size_t offset = 0; + write_points_tag(os,tr,V,binary,offset); + write_cells_tag(os,c3t3,V,binary,offset); + std::vector mids; + os << " \n"; + write_attribute_tag(os,"MeshDomain",mids,binary,offset); + os << " \n"; + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + write_points(os,tr,V); // write points before cells to fill the std::map V + write_cells(os,c3t3,V, mids);//todo mids should be filled by write_attribute_tag + write_attributes(os,mids); + } + os << "\n"; } -//! -//! \brief write_unstructured_grid_2 writes the content of a `CDT` in the .vtu -//! XML format. -//! -//! \tparam CDT must be 2D constrained Delaunay triangulation -//! -//! \param os a `std::ostream`. -//! \param tr ????????? -//! \param binary decides if the data should be written in binary(`true`) -//! or in ASCII(`false`). -//! -//! template void write_unstructured_grid_2(std::ostream& os, - const CDT& tr) + const CDT& tr, + bool binary = true) { - write_unstructured_grid(os, tr, 2); + typedef typename CDT::Vertex_handle Vertex_handle; + std::map V; + //write header + os << "\n" + << "\n" + << " " << "\n"; + + int number_of_triangles = 0; + for(typename CDT::Finite_faces_iterator + fit = tr.finite_faces_begin(), + end = tr.finite_faces_end(); + fit != end; ++fit) + { + if(fit->is_in_domain()) ++number_of_triangles; + } + os << " \n"; + std::size_t offset = 0; + write_points_tag(os,tr,V,binary,offset, 2); + write_cells_tag_2(os,tr,number_of_triangles, V,binary,offset); + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + write_points(os,tr,V, 2); // write points before cells to fill the std::map V + write_cells_2(os,tr, number_of_triangles, V); + } + os << "\n"; } + } //end CGAL #endif // CGAL_VTK_IO_H From 49b88e533fb0c61e038f6f1e78d5c15395bba46b Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 3 Oct 2018 11:15:37 +0200 Subject: [PATCH 05/47] Move and split vtk_io.h to Mesh_2 and Mesh_3 to avoid license and dependencies problems. Also fix vtu writer of VTK_io_plugin for polygon meshes. --- .../Constrained_Delaunay_triangulation_2.cpp | 2 +- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 23 +- Stream_support/include/CGAL/IO/vtk_io.h | 779 ------------------ 3 files changed, 18 insertions(+), 786 deletions(-) delete mode 100644 Stream_support/include/CGAL/IO/vtk_io.h diff --git a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp index e505233e119..352151640fd 100644 --- a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp +++ b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include // Qt headers #include diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index 656869b2847..7d797ba0079 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -172,6 +173,7 @@ namespace CGAL{ vtkCell* cell_ptr = poly_data->GetCell(i); vtkIdType nb_vertices = cell_ptr->GetNumberOfPoints(); + std::cout< vr(nb_vertices); @@ -254,13 +256,13 @@ namespace CGAL{ cell->Delete(); } - vtkSmartPointer polydata = - vtkSmartPointer::New(); + vtkSmartPointer usg = + vtkSmartPointer::New(); - polydata->SetPoints(vtk_points); + usg->SetPoints(vtk_points); vtk_points->Delete(); - polydata->SetPolys(vtk_cells); + usg->SetCells(5,vtk_cells); vtk_cells->Delete(); // Combine the two data sets @@ -277,7 +279,7 @@ namespace CGAL{ vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetFileName(filename); - writer->SetInputData(polydata); + writer->SetInputData(usg); writer->Write(); } }//end namespace CGAL @@ -325,9 +327,18 @@ public: if (poly_item) { if (extension != "vtp") - CGAL::polygon_mesh_to_vtkUnstructured( + { + if(!CGAL::is_triangle_mesh(*poly_item->polyhedron())) + { + QMessageBox::warning(0, "Error", + "Cannot save a mesh in vtu format if " + "it is not pure triangle."); + return false; + } + CGAL::polygon_mesh_to_vtkUnstructured( *poly_item->polyhedron(), output_filename.data()); + } else { const FaceGraph* mesh = poly_item->face_graph(); diff --git a/Stream_support/include/CGAL/IO/vtk_io.h b/Stream_support/include/CGAL/IO/vtk_io.h deleted file mode 100644 index 13382735c42..00000000000 --- a/Stream_support/include/CGAL/IO/vtk_io.h +++ /dev/null @@ -1,779 +0,0 @@ -// Copyright (c) 2018 GeometryFactory (France). -// Copyright (c) 2004-2006 INRIA Sophia-Antipolis (France). -// Copyright (c) 2009 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// -// -// Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno - -#ifndef CGAL_VTK_IO_H -#define CGAL_VTK_IO_H - -#include -#include - -#include -#include - - -//todo try to factorize with functors -namespace CGAL{ -// writes the appended data into the .vtu file -template -void -write_vector(std::ostream& os, - const std::vector& vect) -{ - const char* buffer = reinterpret_cast(&(vect[0])); - std::size_t size = vect.size()*sizeof(FT); - - os.write(reinterpret_cast(&size), sizeof(std::size_t)); // number of bytes encoded - os.write(buffer, vect.size()*sizeof(FT)); // encoded data -} - -// writes the cells tags before binary data is appended - -template -void -write_cells_tag_2(std::ostream& os, - const CDT & tr, - std::size_t number_of_triangles, - std::map & V, - bool binary, - std::size_t& offset) -{ - std::string formatattribute = - binary ? " format=\"appended\"" : " format=\"ascii\""; - - std::string typeattribute; - switch(sizeof(std::size_t)) { - case 8: typeattribute = " type=\"UInt64\""; break; - case 4: typeattribute = " type=\"UInt32\""; break; - default: CGAL_error_msg("Unknown size of std::size_t"); - } - - // Write connectivity table - os << " \n" - << " \n"; - offset += (3 * number_of_triangles + 1) * sizeof(std::size_t); - // 3 indices (size_t) per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for(typename CDT::Finite_faces_iterator - fit = tr.finite_faces_begin(), - end = tr.finite_faces_end(); - fit != end; ++fit) - { - if(fit->is_in_domain()) - { - os << V[fit->vertex(0)] << " "; - os << V[fit->vertex(2)] << " "; - os << V[fit->vertex(1)] << " "; - } - } - os << " \n"; - } - - // Write offsets - os << " \n"; - offset += (number_of_triangles + 1) * sizeof(std::size_t); - // 1 offset (size_t) per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - std::size_t cells_offset = 0; - for(typename CDT::Finite_faces_iterator fit = - tr.finite_faces_begin() ; - fit != tr.finite_faces_end() ; - ++fit ) - { - if(fit->is_in_domain()) - { - cells_offset += 3; - os << cells_offset << " "; - } - } - os << " \n"; - } - - // Write cell type (triangles == 5) - os << " \n"; - offset += number_of_triangles + sizeof(std::size_t); - // 1 unsigned char per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for(typename CDT::Finite_faces_iterator fit = - tr.finite_faces_begin() ; - fit != tr.finite_faces_end() ; - ++fit ) - { - if(fit->is_in_domain()) - { - os << "5 "; - } - } - os << " \n"; - } - os << " \n"; -} - -template -void -write_cells_tag(std::ostream& os, - const C3T3 & c3t3, - std::map & V, - bool binary, - std::size_t& offset) -{ - typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; - std::string formatattribute = - binary ? " format=\"appended\"" : " format=\"ascii\""; - - std::string typeattribute; - switch(sizeof(std::size_t)) { - case 8: typeattribute = " type=\"UInt64\""; break; - case 4: typeattribute = " type=\"UInt32\""; break; - default: CGAL_error_msg("Unknown size of std::size_t"); - } - - // Write connectivity table - os << " \n" - << " \n"; - offset += (4 * c3t3.number_of_cells() + 1) * sizeof(std::size_t); - // 4 indices (size_t) per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; - cit != c3t3.cells_in_complex_end() ; - ++cit ) - { - for (int i=0; i<4; i++) - os << V[cit->vertex(i)] << " "; - } - os << " \n"; - } - - // Write offsets - os << " \n"; - offset += (c3t3.number_of_cells() + 1) * sizeof(std::size_t); - // 1 offset (size_t) per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - std::size_t cells_offset = 0; - for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; - cit != c3t3.cells_in_complex_end() ; - ++cit ) - { - cells_offset += 4; - os << cells_offset << " "; - } - os << " \n"; - } - - // Write cell type (tetrahedra == 10) - os << " \n"; - offset += c3t3.number_of_cells() + sizeof(std::size_t); - // 1 unsigned char per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; - cit != c3t3.cells_in_complex_end() ; - ++cit ) - os << "10 "; - os << " \n"; - } - os << " \n"; -} - -// writes the cells appended data at the end of the .vtu file -template -void -write_cells_2(std::ostream& os, - const CDT & tr, - std::size_t number_of_triangles, - std::map & V) -{ - std::vector connectivity_table; - std::vector offsets; - std::vector cell_type(number_of_triangles,5); // triangles == 5 - - std::size_t off = 0; - for(typename CDT::Finite_faces_iterator - fit = tr.finite_faces_begin(), - end = tr.finite_faces_end(); - fit != end; ++fit) - { - if(fit->is_in_domain()) - { - off += 3; - offsets.push_back(off); - connectivity_table.push_back(V[fit->vertex(0)]); - connectivity_table.push_back(V[fit->vertex(2)]); - connectivity_table.push_back(V[fit->vertex(1)]); - } - } - write_vector(os,connectivity_table); - write_vector(os,offsets); - write_vector(os,cell_type); -} - - -template -void -write_cells(std::ostream& os, - const C3T3 & c3t3, - std::map & V, - std::vector& mids) -{ - typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; - std::vector connectivity_table; - std::vector offsets; - std::vector cell_type(c3t3.number_of_cells(),10); // tetrahedra == 10 - - std::size_t off = 0; - for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; - cit != c3t3.cells_in_complex_end() ; - ++cit ) - { - off += 4; - offsets.push_back(off); - for (int i=0; i<4; i++) - connectivity_table.push_back(V[cit->vertex(i)]); - mids.push_back(cit->subdomain_index()); - } - write_vector(os,connectivity_table); - write_vector(os,offsets); - write_vector(os,cell_type); -} - -// writes the polys appended data at the end of the .vtp file -template -void -write_polys(std::ostream& os, - const Mesh & mesh, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::face_iterator face_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; - Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), - get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - std::vector connectivity_table; - std::vector offsets; - std::vector cell_type(num_faces(mesh),5); // triangle == 5 - - std::size_t off = 0; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - off += 3; - offsets.push_back(off); - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - connectivity_table.push_back(V[v]); - } - write_vector(os,connectivity_table); - write_vector(os,offsets); - write_vector(os,cell_type); -} -//todo use named params for maps -template -void -write_polys_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::face_iterator face_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; - Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), - get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - - - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - - std::string formatattribute = - binary ? " format=\"appended\"" : " format=\"ascii\""; - - std::string typeattribute; - switch(sizeof(std::size_t)) { - case 8: typeattribute = " type=\"UInt64\""; break; - case 4: typeattribute = " type=\"UInt32\""; break; - default: CGAL_error_msg("Unknown size of std::size_t"); - } - - // Write connectivity table - os << " \n" - << " \n"; - offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); - // 3 indices (size_t) per triangle + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - os << V[v] << " "; - } - os << " \n"; - } - - // Write offsets - os << " \n"; - offset += (num_faces(mesh) + 1) * sizeof(std::size_t); - // 1 offset (size_t) per triangle + length of the encoded data (size_t) - } - else { - os << "\">\n"; - std::size_t polys_offset = 0; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - polys_offset += 3; - os << polys_offset << " "; - } - os << " \n"; - } - - // Write cell type (triangle == 5) - os << " \n"; - offset += num_faces(mesh) + sizeof(std::size_t); - // 1 unsigned char per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for(std::size_t i = 0; i< num_faces(mesh); ++i) - os << "5 "; - os << " \n"; - } - os << " \n"; -} -// writes the points tags before binary data is appended -template -void -write_points_tag(std::ostream& os, - const Tr & tr, - std::map & V, - bool binary, - std::size_t& offset, - std::size_t dim = 3) -{ - typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; - typedef typename Tr::Geom_traits Gt; - typedef typename Gt::FT FT; - - std::size_t inum = 0; - std::string format = binary ? "appended" : "ascii"; - std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; - - os << " \n" - << " \n"; - offset += 3 * tr.number_of_vertices() * sizeof(FT) + sizeof(std::size_t); - // dim coords per points + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); - vit != tr.finite_vertices_end(); - ++vit) - { - V[vit] = inum++; - os << vit->point()[0] << " "; - os << vit->point()[1] << " "; - if(dim == 3) - os << vit->point()[2] << " "; - else - os << 0.0 << " "; - } - os << " \n"; - } - os << " \n"; -} - -//todo : use namedparams for points and ids -//overload for facegraph -template -void -write_points_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_iterator vertex_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), - get_const_property_map(CGAL::vertex_point, mesh)); - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - - std::string format = binary ? "appended" : "ascii"; - std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; - - os << " \n" - << " \n"; - offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); - // 3 coords per points + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( vertex_iterator vit = vertices(mesh).begin(); - vit != vertices(mesh).end(); - ++vit) - { - os << get(vpm, *vit).x() << " " << get(vpm, *vit).y() << " " - << get(vpm, *vit).z() << " "; - } - os << " \n"; - } - os << " \n"; -} - -// writes the points appended data at the end of the .vtu file -template -void -write_points(std::ostream& os, - const Tr & tr, - std::map & V, - std::size_t dim = 3) -{ - typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; - typedef typename Tr::Geom_traits Gt; - typedef typename Gt::FT FT; - - std::size_t inum = 0; - std::vector coordinates; - for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); - vit != tr.finite_vertices_end(); - ++vit) - { - V[vit] = inum++; // binary output => the map has not been filled yet - coordinates.push_back(vit->point()[0]); - coordinates.push_back(vit->point()[1]); - coordinates.push_back(dim == 3 ? vit->point()[2] : 0.0); - } - write_vector(os,coordinates); -} - -// writes the points appended data at the end of the .vtp file -template -void -write_polys_points(std::ostream& os, - const Mesh & mesh, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_iterator vertex_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), - get_const_property_map(CGAL::vertex_point, mesh)); - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - std::vector coordinates; - for( vertex_iterator vit = vertices(mesh).begin(); - vit != vertices(mesh).end(); - ++vit) - { - coordinates.push_back(get(vpm, *vit).x()); - coordinates.push_back(get(vpm, *vit).y()); - coordinates.push_back(get(vpm, *vit).z()); - } - write_vector(os,coordinates); -} -// writes the attribute tags before binary data is appended -template -void -write_attribute_tag(std::ostream& os, - const std::string& attr_name, - const std::vector& attribute, - bool binary, - std::size_t& offset) -{ - std::string format = binary ? "appended" : "ascii"; - std::string type = (sizeof(T) == 8) ? "Float64" : "Float32"; - os << " \n"; - offset += attribute.size() * sizeof(T) + sizeof(std::size_t); - } - else { - typedef typename std::vector::const_iterator Iterator; - os << "\">\n"; - for (Iterator it = attribute.begin(); - it != attribute.end(); - ++it ) - os << *it << " "; - os << " \n"; - } -} - -// writes the attributes appended data at the end of the .vtu file -template -void -write_attributes(std::ostream& os, - const std::vector& att) -{ - write_vector(os,att); -} - -//public API - -//! -//! \brief write_polydata_3 writes the content of a triangulated surface mesh in the .vtp -//! XML format. -//! -//! \tparam TriangleMesh a model of `FaceListGraph` with triangle faces. -//! \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" -//! -//! \param os a `std::ostream`. -//! \param mesh an instance of `TriangleMesh` to be written. -//! \param binary decides if the data should be written in binary(`true`) -//! or in ASCII(`false`). -//! \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the -//! ones listed below -//! -//! \cgalNamedParamsBegin -//! \cgalParamBegin{vertex_point_map} the property map with the points associated to -//! the vertices of `mesh`. If this parameter is omitted, an internal property map for -//! `CGAL::vertex_point_t` must be available in `TriangleMesh`. -//! \cgalParamEnd -//! \cgalParamBegin{vertex_index_map} the property map with the indices associated to -//! the vertices of `mesh`. If this parameter is omitted, an internal property map for -//! `CGAL::vertex_index_t` must be available in `TriangleMesh`. -//! \cgalParamEnd -//! \cgalNamedParamsEnd -template -void write_polydata(std::ostream& os, - const TriangleMesh& mesh, - bool binary, - const NamedParameters& np) -{ - os << "\n" - << "\n" - << " " << "\n"; - - os << " \n"; - std::size_t offset = 0; - write_points_tag(os,mesh,binary,offset, np); - write_polys_tag(os,mesh,binary,offset, np); - os << " \n" - << " \n"; - if (binary) { - os << "\n_"; - write_polys_points(os,mesh, np); - write_polys(os,mesh, np); - } - os << "\n"; -} - -template -void write_polydata(std::ostream& os, - const TriangleMesh& mesh, - bool binary = true) -{ - write_polydata(os, mesh, binary, CGAL::parameters::all_default()); -} - -//! -//! \brief write_unstructured_grid_3 writes the content of a `C3t3` in the .vtu -//! XML format. -//! -//! \tparam C3T3 a model of `MeshComplexWithFeatures_3InTriangulation_3`. -//! -//! \param os a `std::ostream`. -//! \param c3t3 an instance of `C3T3` to be written. -//! \param binary decides if the data should be written in binary(`true`) -//! or in ASCII(`false`). -//! -template -void write_unstructured_grid_3(std::ostream& os, - const C3T3& c3t3) -{ - typedef typename C3T3::Triangulation Tr; - typedef typename Tr::Vertex_handle Vertex_handle; - const Tr& tr = c3t3.triangulation(); - std::map V; - //write header - os << "\n" - << "\n" - << " " << "\n"; - - os << " \n"; - bool binary = true; - std::size_t offset = 0; - write_points_tag(os,tr,V,binary,offset); - write_cells_tag(os,c3t3,V,binary,offset); - std::vector mids; - os << " \n"; - write_attribute_tag(os,"MeshDomain",mids,binary,offset); - os << " \n"; - os << " \n" - << " \n"; - if (binary) { - os << "\n_"; - write_points(os,tr,V); // write points before cells to fill the std::map V - write_cells(os,c3t3,V, mids);//todo mids should be filled by write_attribute_tag - write_attributes(os,mids); - } - os << "\n"; -} - -template -void write_unstructured_grid_2(std::ostream& os, - const CDT& tr, - bool binary = true) -{ - typedef typename CDT::Vertex_handle Vertex_handle; - std::map V; - //write header - os << "\n" - << "\n" - << " " << "\n"; - - int number_of_triangles = 0; - for(typename CDT::Finite_faces_iterator - fit = tr.finite_faces_begin(), - end = tr.finite_faces_end(); - fit != end; ++fit) - { - if(fit->is_in_domain()) ++number_of_triangles; - } - os << " \n"; - std::size_t offset = 0; - write_points_tag(os,tr,V,binary,offset, 2); - write_cells_tag_2(os,tr,number_of_triangles, V,binary,offset); - os << " \n" - << " \n"; - if (binary) { - os << "\n_"; - write_points(os,tr,V, 2); // write points before cells to fill the std::map V - write_cells_2(os,tr, number_of_triangles, V); - } - os << "\n"; -} - -} //end CGAL -#endif // CGAL_VTK_IO_H From 99832879edf0d3f8aa29c515f599aea2f39109e9 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 4 Oct 2018 14:08:52 +0200 Subject: [PATCH 06/47] Add missing files --- Mesh_2/include/CGAL/IO/vtk_io_2.h | 298 +++++++++++++++ Mesh_3/include/CGAL/IO/vtk_io.h | 600 ++++++++++++++++++++++++++++++ 2 files changed, 898 insertions(+) create mode 100644 Mesh_2/include/CGAL/IO/vtk_io_2.h create mode 100644 Mesh_3/include/CGAL/IO/vtk_io.h diff --git a/Mesh_2/include/CGAL/IO/vtk_io_2.h b/Mesh_2/include/CGAL/IO/vtk_io_2.h new file mode 100644 index 00000000000..2b4f38b1ade --- /dev/null +++ b/Mesh_2/include/CGAL/IO/vtk_io_2.h @@ -0,0 +1,298 @@ +// Copyright (c) 2018 GeometryFactory (France). +// Copyright (c) 2004-2006 INRIA Sophia-Antipolis (France). +// Copyright (c) 2009 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno + +#ifndef CGAL_VTK_IO_H +#define CGAL_VTK_IO_H + +#include +#include + +//todo try to factorize with functors +namespace CGAL{ +// writes the appended data into the .vtu file +template +void +write_vector(std::ostream& os, + const std::vector& vect) +{ + const char* buffer = reinterpret_cast(&(vect[0])); + std::size_t size = vect.size()*sizeof(FT); + + os.write(reinterpret_cast(&size), sizeof(std::size_t)); // number of bytes encoded + os.write(buffer, vect.size()*sizeof(FT)); // encoded data +} + +// writes the cells tags before binary data is appended + +template +void +write_cells_tag_2(std::ostream& os, + const CDT & tr, + std::size_t number_of_triangles, + std::map & V, + bool binary, + std::size_t& offset) +{ + std::string formatattribute = + binary ? " format=\"appended\"" : " format=\"ascii\""; + + std::string typeattribute; + switch(sizeof(std::size_t)) { + case 8: typeattribute = " type=\"UInt64\""; break; + case 4: typeattribute = " type=\"UInt32\""; break; + default: CGAL_error_msg("Unknown size of std::size_t"); + } + + // Write connectivity table + os << " \n" + << " \n"; + offset += (3 * number_of_triangles + 1) * sizeof(std::size_t); + // 3 indices (size_t) per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for(typename CDT::Finite_faces_iterator + fit = tr.finite_faces_begin(), + end = tr.finite_faces_end(); + fit != end; ++fit) + { + if(fit->is_in_domain()) + { + os << V[fit->vertex(0)] << " "; + os << V[fit->vertex(2)] << " "; + os << V[fit->vertex(1)] << " "; + } + } + os << " \n"; + } + + // Write offsets + os << " \n"; + offset += (number_of_triangles + 1) * sizeof(std::size_t); + // 1 offset (size_t) per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + std::size_t cells_offset = 0; + for(typename CDT::Finite_faces_iterator fit = + tr.finite_faces_begin() ; + fit != tr.finite_faces_end() ; + ++fit ) + { + if(fit->is_in_domain()) + { + cells_offset += 3; + os << cells_offset << " "; + } + } + os << " \n"; + } + + // Write cell type (triangles == 5) + os << " \n"; + offset += number_of_triangles + sizeof(std::size_t); + // 1 unsigned char per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for(typename CDT::Finite_faces_iterator fit = + tr.finite_faces_begin() ; + fit != tr.finite_faces_end() ; + ++fit ) + { + if(fit->is_in_domain()) + { + os << "5 "; + } + } + os << " \n"; + } + os << " \n"; +} + +// writes the cells appended data at the end of the .vtu file +template +void +write_cells_2(std::ostream& os, + const CDT & tr, + std::size_t number_of_triangles, + std::map & V) +{ + std::vector connectivity_table; + std::vector offsets; + std::vector cell_type(number_of_triangles,5); // triangles == 5 + + std::size_t off = 0; + for(typename CDT::Finite_faces_iterator + fit = tr.finite_faces_begin(), + end = tr.finite_faces_end(); + fit != end; ++fit) + { + if(fit->is_in_domain()) + { + off += 3; + offsets.push_back(off); + connectivity_table.push_back(V[fit->vertex(0)]); + connectivity_table.push_back(V[fit->vertex(2)]); + connectivity_table.push_back(V[fit->vertex(1)]); + } + } + write_vector(os,connectivity_table); + write_vector(os,offsets); + write_vector(os,cell_type); +} + +// writes the points tags before binary data is appended +template +void +write_points_tag(std::ostream& os, + const Tr & tr, + std::map & V, + bool binary, + std::size_t& offset) +{ + std::size_t dim = 2; + typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; + typedef typename Tr::Geom_traits Gt; + typedef typename Gt::FT FT; + + std::size_t inum = 0; + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; + + os << " \n" + << " \n"; + offset += 3 * tr.number_of_vertices() * sizeof(FT) + sizeof(std::size_t); + // dim coords per points + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); + vit != tr.finite_vertices_end(); + ++vit) + { + V[vit] = inum++; + os << vit->point()[0] << " "; + os << vit->point()[1] << " "; + if(dim == 3) + os << vit->point()[2] << " "; + else + os << 0.0 << " "; + } + os << " \n"; + } + os << " \n"; +} + +// writes the points appended data at the end of the .vtu file +template +void +write_points(std::ostream& os, + const Tr & tr, + std::map & V) +{ + std::size_t dim = 2; + typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; + typedef typename Tr::Geom_traits Gt; + typedef typename Gt::FT FT; + + std::size_t inum = 0; + std::vector coordinates; + for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); + vit != tr.finite_vertices_end(); + ++vit) + { + V[vit] = inum++; // binary output => the map has not been filled yet + coordinates.push_back(vit->point()[0]); + coordinates.push_back(vit->point()[1]); + coordinates.push_back(dim == 3 ? vit->point()[2] : 0.0); + } + write_vector(os,coordinates); +} + + +template +void write_unstructured_grid_2(std::ostream& os, + const CDT& tr, + bool binary = true) +{ + typedef typename CDT::Vertex_handle Vertex_handle; + std::map V; + //write header + os << "\n" + << "\n" + << " " << "\n"; + + int number_of_triangles = 0; + for(typename CDT::Finite_faces_iterator + fit = tr.finite_faces_begin(), + end = tr.finite_faces_end(); + fit != end; ++fit) + { + if(fit->is_in_domain()) ++number_of_triangles; + } + os << " \n"; + std::size_t offset = 0; + write_points_tag(os,tr,V,binary,offset); + write_cells_tag_2(os,tr,number_of_triangles, V,binary,offset); + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + write_points(os,tr,V); // write points before cells to fill the std::map V + write_cells_2(os,tr, number_of_triangles, V); + } + os << "\n"; +} + +} //end CGAL +#endif // CGAL_VTK_IO_H diff --git a/Mesh_3/include/CGAL/IO/vtk_io.h b/Mesh_3/include/CGAL/IO/vtk_io.h new file mode 100644 index 00000000000..012e85d4096 --- /dev/null +++ b/Mesh_3/include/CGAL/IO/vtk_io.h @@ -0,0 +1,600 @@ +// Copyright (c) 2018 GeometryFactory (France). +// Copyright (c) 2004-2006 INRIA Sophia-Antipolis (France). +// Copyright (c) 2009 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno + +#ifndef CGAL_VTK_IO_H +#define CGAL_VTK_IO_H + +#include +#include + +#include +#include + + +//todo try to factorize with functors +namespace CGAL{ +// writes the appended data into the .vtu file +template +void +write_vector(std::ostream& os, + const std::vector& vect) +{ + const char* buffer = reinterpret_cast(&(vect[0])); + std::size_t size = vect.size()*sizeof(FT); + + os.write(reinterpret_cast(&size), sizeof(std::size_t)); // number of bytes encoded + os.write(buffer, vect.size()*sizeof(FT)); // encoded data +} + +template +void +write_cells_tag(std::ostream& os, + const C3T3 & c3t3, + std::map & V, + bool binary, + std::size_t& offset) +{ + typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; + std::string formatattribute = + binary ? " format=\"appended\"" : " format=\"ascii\""; + + std::string typeattribute; + switch(sizeof(std::size_t)) { + case 8: typeattribute = " type=\"UInt64\""; break; + case 4: typeattribute = " type=\"UInt32\""; break; + default: CGAL_error_msg("Unknown size of std::size_t"); + } + + // Write connectivity table + os << " \n" + << " \n"; + offset += (4 * c3t3.number_of_cells() + 1) * sizeof(std::size_t); + // 4 indices (size_t) per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + { + for (int i=0; i<4; i++) + os << V[cit->vertex(i)] << " "; + } + os << " \n"; + } + + // Write offsets + os << " \n"; + offset += (c3t3.number_of_cells() + 1) * sizeof(std::size_t); + // 1 offset (size_t) per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + std::size_t cells_offset = 0; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + { + cells_offset += 4; + os << cells_offset << " "; + } + os << " \n"; + } + + // Write cell type (tetrahedra == 10) + os << " \n"; + offset += c3t3.number_of_cells() + sizeof(std::size_t); + // 1 unsigned char per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + os << "10 "; + os << " \n"; + } + os << " \n"; +} + + +template +void +write_cells(std::ostream& os, + const C3T3 & c3t3, + std::map & V, + std::vector& mids) +{ + typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; + std::vector connectivity_table; + std::vector offsets; + std::vector cell_type(c3t3.number_of_cells(),10); // tetrahedra == 10 + + std::size_t off = 0; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + { + off += 4; + offsets.push_back(off); + for (int i=0; i<4; i++) + connectivity_table.push_back(V[cit->vertex(i)]); + mids.push_back(cit->subdomain_index()); + } + write_vector(os,connectivity_table); + write_vector(os,offsets); + write_vector(os,cell_type); +} + +// writes the polys appended data at the end of the .vtp file +template +void +write_polys(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + std::vector connectivity_table; + std::vector offsets; + std::vector cell_type(num_faces(mesh),5); // triangle == 5 + + std::size_t off = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + off += 3; + offsets.push_back(off); + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + connectivity_table.push_back(V[v]); + } + write_vector(os,connectivity_table); + write_vector(os,offsets); + write_vector(os,cell_type); +} +//todo use named params for maps +template +void +write_polys_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + + std::string formatattribute = + binary ? " format=\"appended\"" : " format=\"ascii\""; + + std::string typeattribute; + switch(sizeof(std::size_t)) { + case 8: typeattribute = " type=\"UInt64\""; break; + case 4: typeattribute = " type=\"UInt32\""; break; + default: CGAL_error_msg("Unknown size of std::size_t"); + } + + // Write connectivity table + os << " \n" + << " \n"; + offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); + // 3 indices (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + os << V[v] << " "; + } + os << " \n"; + } + + // Write offsets + os << " \n"; + offset += (num_faces(mesh) + 1) * sizeof(std::size_t); + // 1 offset (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + std::size_t polys_offset = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + polys_offset += 3; + os << polys_offset << " "; + } + os << " \n"; + } + + // Write cell type (triangle == 5) + os << " \n"; + offset += num_faces(mesh) + sizeof(std::size_t); + // 1 unsigned char per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for(std::size_t i = 0; i< num_faces(mesh); ++i) + os << "5 "; + os << " \n"; + } + os << " \n"; +} +// writes the points tags before binary data is appended +template +void +write_points_tag(std::ostream& os, + const Tr & tr, + std::map & V, + bool binary, + std::size_t& offset) +{ + std::size_t dim = 3; + typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; + typedef typename Tr::Geom_traits Gt; + typedef typename Gt::FT FT; + + std::size_t inum = 0; + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; + + os << " \n" + << " \n"; + offset += 3 * tr.number_of_vertices() * sizeof(FT) + sizeof(std::size_t); + // dim coords per points + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); + vit != tr.finite_vertices_end(); + ++vit) + { + V[vit] = inum++; + os << vit->point()[0] << " "; + os << vit->point()[1] << " "; + if(dim == 3) + os << vit->point()[2] << " "; + else + os << 0.0 << " "; + } + os << " \n"; + } + os << " \n"; +} + +//todo : use namedparams for points and ids +//overload for facegraph +template +void +write_points_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; + + os << " \n" + << " \n"; + offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); + // 3 coords per points + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + os << get(vpm, *vit).x() << " " << get(vpm, *vit).y() << " " + << get(vpm, *vit).z() << " "; + } + os << " \n"; + } + os << " \n"; +} + +// writes the points appended data at the end of the .vtu file +template +void +write_points(std::ostream& os, + const Tr & tr, + std::map & V) +{ + std::size_t dim = 3; + typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; + typedef typename Tr::Geom_traits Gt; + typedef typename Gt::FT FT; + + std::size_t inum = 0; + std::vector coordinates; + for( Finite_vertices_iterator vit = tr.finite_vertices_begin(); + vit != tr.finite_vertices_end(); + ++vit) + { + V[vit] = inum++; // binary output => the map has not been filled yet + coordinates.push_back(vit->point()[0]); + coordinates.push_back(vit->point()[1]); + coordinates.push_back(dim == 3 ? vit->point()[2] : 0.0); + } + write_vector(os,coordinates); +} + +// writes the points appended data at the end of the .vtp file +template +void +write_polys_points(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + std::vector coordinates; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + coordinates.push_back(get(vpm, *vit).x()); + coordinates.push_back(get(vpm, *vit).y()); + coordinates.push_back(get(vpm, *vit).z()); + } + write_vector(os,coordinates); +} +// writes the attribute tags before binary data is appended +template +void +write_attribute_tag(std::ostream& os, + const std::string& attr_name, + const std::vector& attribute, + bool binary, + std::size_t& offset) +{ + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(T) == 8) ? "Float64" : "Float32"; + os << " \n"; + offset += attribute.size() * sizeof(T) + sizeof(std::size_t); + } + else { + typedef typename std::vector::const_iterator Iterator; + os << "\">\n"; + for (Iterator it = attribute.begin(); + it != attribute.end(); + ++it ) + os << *it << " "; + os << " \n"; + } +} + +// writes the attributes appended data at the end of the .vtu file +template +void +write_attributes(std::ostream& os, + const std::vector& att) +{ + write_vector(os,att); +} + +//public API + +//! +//! \brief write_polydata_3 writes the content of a triangulated surface mesh in the .vtp +//! XML format. +//! +//! \tparam TriangleMesh a model of `FaceListGraph` with triangle faces. +//! \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" +//! +//! \param os a `std::ostream`. +//! \param mesh an instance of `TriangleMesh` to be written. +//! \param binary decides if the data should be written in binary(`true`) +//! or in ASCII(`false`). +//! \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the +//! ones listed below +//! +//! \cgalNamedParamsBegin +//! \cgalParamBegin{vertex_point_map} the property map with the points associated to +//! the vertices of `mesh`. If this parameter is omitted, an internal property map for +//! `CGAL::vertex_point_t` must be available in `TriangleMesh`. +//! \cgalParamEnd +//! \cgalParamBegin{vertex_index_map} the property map with the indices associated to +//! the vertices of `mesh`. If this parameter is omitted, an internal property map for +//! `CGAL::vertex_index_t` must be available in `TriangleMesh`. +//! \cgalParamEnd +//! \cgalNamedParamsEnd +template +void write_polydata(std::ostream& os, + const TriangleMesh& mesh, + bool binary, + const NamedParameters& np) +{ + os << "\n" + << "\n" + << " " << "\n"; + + os << " \n"; + std::size_t offset = 0; + write_points_tag(os,mesh,binary,offset, np); + write_polys_tag(os,mesh,binary,offset, np); + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + write_polys_points(os,mesh, np); + write_polys(os,mesh, np); + } + os << "\n"; +} + +template +void write_polydata(std::ostream& os, + const TriangleMesh& mesh, + bool binary = true) +{ + write_polydata(os, mesh, binary, CGAL::parameters::all_default()); +} + +//! +//! \brief write_unstructured_grid_3 writes the content of a `C3t3` in the .vtu +//! XML format. +//! +//! \tparam C3T3 a model of `MeshComplexWithFeatures_3InTriangulation_3`. +//! +//! \param os a `std::ostream`. +//! \param c3t3 an instance of `C3T3` to be written. +//! \param binary decides if the data should be written in binary(`true`) +//! or in ASCII(`false`). +//! +template +void write_unstructured_grid_3(std::ostream& os, + const C3T3& c3t3) +{ + typedef typename C3T3::Triangulation Tr; + typedef typename Tr::Vertex_handle Vertex_handle; + const Tr& tr = c3t3.triangulation(); + std::map V; + //write header + os << "\n" + << "\n" + << " " << "\n"; + + os << " \n"; + bool binary = true; + std::size_t offset = 0; + write_points_tag(os,tr,V,binary,offset); + write_cells_tag(os,c3t3,V,binary,offset); + std::vector mids; + os << " \n"; + write_attribute_tag(os,"MeshDomain",mids,binary,offset); + os << " \n"; + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + write_points(os,tr,V); // write points before cells to fill the std::map V + write_cells(os,c3t3,V, mids);//todo mids should be filled by write_attribute_tag + write_attributes(os,mids); + } + os << "\n"; +} + +} //end CGAL +#endif // CGAL_VTK_IO_H From 0c800d58308b017aa83140c41a4de33083e3602b Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 5 Oct 2018 11:48:46 +0200 Subject: [PATCH 07/47] Add SPDX stuff --- Mesh_2/include/CGAL/IO/vtk_io_2.h | 1 + Mesh_3/include/CGAL/IO/vtk_io.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Mesh_2/include/CGAL/IO/vtk_io_2.h b/Mesh_2/include/CGAL/IO/vtk_io_2.h index 2b4f38b1ade..3544142f13f 100644 --- a/Mesh_2/include/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/include/CGAL/IO/vtk_io_2.h @@ -16,6 +16,7 @@ // // $URL$ // $Id$ +// SPDX-License-Identifier: GPL-3.0+ // // // Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno diff --git a/Mesh_3/include/CGAL/IO/vtk_io.h b/Mesh_3/include/CGAL/IO/vtk_io.h index 012e85d4096..969a9a20be2 100644 --- a/Mesh_3/include/CGAL/IO/vtk_io.h +++ b/Mesh_3/include/CGAL/IO/vtk_io.h @@ -16,7 +16,7 @@ // // $URL$ // $Id$ -// +// SPDX-License-Identifier: GPL-3.0+ // // Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno From e8cf3f319283f683f3fa682183d18ef5ff719ce2 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 5 Oct 2018 17:09:43 +0200 Subject: [PATCH 08/47] add license includes --- Mesh_2/include/CGAL/IO/vtk_io_2.h | 3 +++ Mesh_3/include/CGAL/IO/vtk_io.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Mesh_2/include/CGAL/IO/vtk_io_2.h b/Mesh_2/include/CGAL/IO/vtk_io_2.h index 3544142f13f..59b2d5f1ee9 100644 --- a/Mesh_2/include/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/include/CGAL/IO/vtk_io_2.h @@ -27,6 +27,9 @@ #include #include +#include + + //todo try to factorize with functors namespace CGAL{ // writes the appended data into the .vtu file diff --git a/Mesh_3/include/CGAL/IO/vtk_io.h b/Mesh_3/include/CGAL/IO/vtk_io.h index 969a9a20be2..c062294419c 100644 --- a/Mesh_3/include/CGAL/IO/vtk_io.h +++ b/Mesh_3/include/CGAL/IO/vtk_io.h @@ -23,6 +23,9 @@ #ifndef CGAL_VTK_IO_H #define CGAL_VTK_IO_H +#include + + #include #include From b380bd8b319d030aaadbaff699dace5ea29e5df8 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 8 Oct 2018 16:25:51 +0200 Subject: [PATCH 09/47] Doc for write_unstructured_grid_2 --- Mesh_2/include/CGAL/IO/vtk_io_2.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Mesh_2/include/CGAL/IO/vtk_io_2.h b/Mesh_2/include/CGAL/IO/vtk_io_2.h index 59b2d5f1ee9..f2551ad9d4d 100644 --- a/Mesh_2/include/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/include/CGAL/IO/vtk_io_2.h @@ -250,7 +250,17 @@ write_points(std::ostream& os, write_vector(os,coordinates); } - +//! +//! \brief write_unstructured_grid_2 writes the content of a `CDT` in the .vtu +//! XML format. +//! +//! \tparam CDT a `Constrained_Delaunay_triangulation_2`. +//! +//! \param os a `std::ostream`. +//! \param cdt an instance of `CDT` to be written. +//! \param binary decides if the data should be written in binary(`true`) +//! or in ASCII(`false`). +//! template void write_unstructured_grid_2(std::ostream& os, const CDT& tr, From 14c526a37815adb4254904cd8b4779614bc783e6 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 9 Oct 2018 14:42:42 +0200 Subject: [PATCH 10/47] Add constrained edges to vtu output for cdt --- Mesh_2/include/CGAL/IO/vtk_io_2.h | 31 +++++++++++++++++++++++++++---- Mesh_3/include/CGAL/IO/vtk_io.h | 12 ++++++------ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Mesh_2/include/CGAL/IO/vtk_io_2.h b/Mesh_2/include/CGAL/IO/vtk_io_2.h index f2551ad9d4d..22e34aed107 100644 --- a/Mesh_2/include/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/include/CGAL/IO/vtk_io_2.h @@ -73,8 +73,11 @@ write_cells_tag_2(std::ostream& os, if (binary) { // if binary output, just write the xml tag os << " offset=\"" << offset << "\"/>\n"; + // 3 indices (size_t) per triangle + length of the encoded data (size_t) offset += (3 * number_of_triangles + 1) * sizeof(std::size_t); - // 3 indices (size_t) per cell + length of the encoded data (size_t) + // 2 indices (size_t) per edge (size_t) + offset += (2 * std::distance(tr.constrained_edges_begin(), + tr.constrained_edges_end())) * sizeof(std::size_t); } else { os << "\">\n"; @@ -99,7 +102,9 @@ write_cells_tag_2(std::ostream& os, if (binary) { // if binary output, just write the xml tag os << " offset=\"" << offset << "\"/>\n"; - offset += (number_of_triangles + 1) * sizeof(std::size_t); + offset += (number_of_triangles +std::distance(tr.constrained_edges_begin(), + tr.constrained_edges_end()) + 1) + * sizeof(std::size_t); // 1 offset (size_t) per cell + length of the encoded data (size_t) } else { @@ -125,7 +130,10 @@ write_cells_tag_2(std::ostream& os, if (binary) { os << " offset=\"" << offset << "\"/>\n"; - offset += number_of_triangles + sizeof(std::size_t); + offset += number_of_triangles + + std::distance(tr.constrained_edges_begin(), + tr.constrained_edges_end()) + + sizeof(std::size_t); // 1 unsigned char per cell + length of the encoded data (size_t) } else { @@ -156,6 +164,8 @@ write_cells_2(std::ostream& os, std::vector connectivity_table; std::vector offsets; std::vector cell_type(number_of_triangles,5); // triangles == 5 + cell_type.resize(cell_type.size() + std::distance(tr.constrained_edges_begin(), + tr.constrained_edges_end()), 3); // line == 3 std::size_t off = 0; for(typename CDT::Finite_faces_iterator @@ -172,6 +182,19 @@ write_cells_2(std::ostream& os, connectivity_table.push_back(V[fit->vertex(1)]); } } + for(typename CDT::Constrained_edges_iterator + cei = tr.constrained_edges_begin(), + end = tr.constrained_edges_end(); + cei != end; ++cei) + { + off += 2; + offsets.push_back(off); + for(int i=0; i<3; ++i) + { + if(i != cei->second) + connectivity_table.push_back(V[cei->first->vertex(i)]); + } + } write_vector(os,connectivity_table); write_vector(os,offsets); write_vector(os,cell_type); @@ -294,7 +317,7 @@ void write_unstructured_grid_2(std::ostream& os, if(fit->is_in_domain()) ++number_of_triangles; } os << " \n"; + << "\" NumberOfCells=\"" << number_of_triangles + std::distance(tr.constrained_edges_begin(), tr.constrained_edges_end()) << "\">\n"; std::size_t offset = 0; write_points_tag(os,tr,V,binary,offset); write_cells_tag_2(os,tr,number_of_triangles, V,binary,offset); diff --git a/Mesh_3/include/CGAL/IO/vtk_io.h b/Mesh_3/include/CGAL/IO/vtk_io.h index c062294419c..9029f304e53 100644 --- a/Mesh_3/include/CGAL/IO/vtk_io.h +++ b/Mesh_3/include/CGAL/IO/vtk_io.h @@ -80,12 +80,12 @@ write_cells_tag(std::ostream& os, else { os << "\">\n"; for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; - cit != c3t3.cells_in_complex_end() ; - ++cit ) - { - for (int i=0; i<4; i++) - os << V[cit->vertex(i)] << " "; - } + cit != c3t3.cells_in_complex_end() ; + ++cit ) + { + for (int i=0; i<4; i++) + os << V[cit->vertex(i)] << " "; + } os << " \n"; } From 9e929e39a01e335c64e2470cda64a692640344b4 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 9 Oct 2018 14:49:08 +0200 Subject: [PATCH 11/47] Clarifies the doc --- Mesh_2/include/CGAL/IO/vtk_io_2.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Mesh_2/include/CGAL/IO/vtk_io_2.h b/Mesh_2/include/CGAL/IO/vtk_io_2.h index 22e34aed107..962b7b9ee26 100644 --- a/Mesh_2/include/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/include/CGAL/IO/vtk_io_2.h @@ -275,7 +275,9 @@ write_points(std::ostream& os, //! //! \brief write_unstructured_grid_2 writes the content of a `CDT` in the .vtu -//! XML format. +//! XML format. +//! +//! The triangles inside the domain and the constrained edges will be outputted. //! //! \tparam CDT a `Constrained_Delaunay_triangulation_2`. //! From 63488d81d1c793ad6c30d00ed44ad51f320067ef Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 29 Oct 2018 12:59:44 +0100 Subject: [PATCH 12/47] Update Changes and doc --- Installation/CHANGES.md | 7 ++++ Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h | 19 ++++++++++ Mesh_2/doc/Mesh_2/PackageDescription.txt | 1 + Mesh_2/include/CGAL/IO/vtk_io_2.h | 14 +------ Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h | 47 ++++++++++++++++++++++++ Mesh_3/doc/Mesh_3/Doxyfile.in | 14 +++++++ Mesh_3/doc/Mesh_3/PackageDescription.txt | 2 + Mesh_3/include/CGAL/IO/vtk_io.h | 36 +----------------- 8 files changed, 92 insertions(+), 48 deletions(-) create mode 100644 Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h create mode 100644 Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index fcd898c453f..7e65f197641 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -20,6 +20,13 @@ Release date: March 2019 - `CGAL::Polygon_mesh_processing::merge_duplicated_vertices_in_boundary_cycle()` - `CGAL::Polygon_mesh_processing::merge_duplicated_vertices_in_boundary_cycles()` +### 2D and 3D Mesh Generation +- Added 3 functions for writing in modern VTK formats: + -`CGAL::write_unstructured_grid_3(std::ostream& os, const C3T3& c3t3)` + -`CGAL::write_unstructured_grid_2(std::ostream& os, const CDT& tr, bool binary = true)` + -`CGAL::write_polydata(std::ostream& os, const TriangleMesh& mesh, bool binary, const NamedParameters& np)` + + Release 4.13 ------------ diff --git a/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h b/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h new file mode 100644 index 00000000000..1ca341b743e --- /dev/null +++ b/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h @@ -0,0 +1,19 @@ +namespace CGAL{ +//!\ingroup PkgMesh2 +//! \brief write_unstructured_grid_2 writes the content of a `CDT` in the .vtu +//! XML format. +//! +//! The triangles inside the domain and the constrained edges will be outputted. +//! +//! \tparam CDT a `Constrained_Delaunay_triangulation_2`. +//! +//! \param os a `std::ostream`. +//! \param tr an instance of `CDT` to be written. +//! \param binary decides if the data should be written in binary(`true`) +//! or in ASCII(`false`). +//! +template +void write_unstructured_grid_2(std::ostream& os, + const CDT& tr, + bool binary = true); +} diff --git a/Mesh_2/doc/Mesh_2/PackageDescription.txt b/Mesh_2/doc/Mesh_2/PackageDescription.txt index 79733d285b8..dd5e859cbfd 100644 --- a/Mesh_2/doc/Mesh_2/PackageDescription.txt +++ b/Mesh_2/doc/Mesh_2/PackageDescription.txt @@ -57,6 +57,7 @@ The package can handle intersecting input constraints and set no restriction on - `CGAL::make_conforming_Gabriel_2` - `CGAL::refine_Delaunay_mesh_2` - `CGAL::lloyd_optimize_mesh_2` +- `CGAL::write_unstructured_grid_2()` ## Enumerations ## - `CGAL::Mesh_optimization_return_code` diff --git a/Mesh_2/include/CGAL/IO/vtk_io_2.h b/Mesh_2/include/CGAL/IO/vtk_io_2.h index 962b7b9ee26..1ad09ee3aad 100644 --- a/Mesh_2/include/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/include/CGAL/IO/vtk_io_2.h @@ -273,19 +273,7 @@ write_points(std::ostream& os, write_vector(os,coordinates); } -//! -//! \brief write_unstructured_grid_2 writes the content of a `CDT` in the .vtu -//! XML format. -//! -//! The triangles inside the domain and the constrained edges will be outputted. -//! -//! \tparam CDT a `Constrained_Delaunay_triangulation_2`. -//! -//! \param os a `std::ostream`. -//! \param cdt an instance of `CDT` to be written. -//! \param binary decides if the data should be written in binary(`true`) -//! or in ASCII(`false`). -//! + template void write_unstructured_grid_2(std::ostream& os, const CDT& tr, diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h new file mode 100644 index 00000000000..6c10de585c8 --- /dev/null +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h @@ -0,0 +1,47 @@ +namespace CGAL{ +//! \ingroup PkgMesh_3IOFunctions +//! +//! \brief write_polydata_3 writes the content of a triangulated surface mesh in the .vtp +//! XML format. +//! +//! \tparam TriangleMesh a model of `FaceListGraph` with triangle faces. +//! \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" +//! +//! \param os a `std::ostream`. +//! \param mesh an instance of `TriangleMesh` to be written. +//! \param binary decides if the data should be written in binary(`true`) +//! or in ASCII(`false`). +//! \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the +//! ones listed below +//! +//! \cgalNamedParamsBegin +//! \cgalParamBegin{vertex_point_map} the property map with the points associated to +//! the vertices of `mesh`. If this parameter is omitted, an internal property map for +//! `CGAL::vertex_point_t` must be available in `TriangleMesh`. +//! \cgalParamEnd +//! \cgalParamBegin{vertex_index_map} the property map with the indices associated to +//! the vertices of `mesh`. If this parameter is omitted, an internal property map for +//! `CGAL::vertex_index_t` must be available in `TriangleMesh`. +//! \cgalParamEnd +//! \cgalNamedParamsEnd +template +void write_polydata(std::ostream& os, + const TriangleMesh& mesh, + bool binary, + const NamedParameters& np); + +//! \ingroup PkgMesh_3IOFunctions +//! +//! \brief write_unstructured_grid_3 writes the content of a `C3t3` in the .vtu +//! XML format. +//! +//! \tparam C3T3 a model of `MeshComplexWithFeatures_3InTriangulation_3`. +//! +//! \param os a `std::ostream`. +//! \param c3t3 an instance of `C3T3` to be written. +//! +template +void write_unstructured_grid_3(std::ostream& os, + const C3T3& c3t3); +} diff --git a/Mesh_3/doc/Mesh_3/Doxyfile.in b/Mesh_3/doc/Mesh_3/Doxyfile.in index 0a6229c8c69..eafd3c94e7a 100644 --- a/Mesh_3/doc/Mesh_3/Doxyfile.in +++ b/Mesh_3/doc/Mesh_3/Doxyfile.in @@ -1,5 +1,19 @@ @INCLUDE = ${CGAL_DOC_PACKAGE_DEFAULTS} +# macros to be used inside the code +ALIASES += "cgalNamedParamsBegin=
Named Parameters
" +ALIASES += "cgalNamedParamsEnd=
" +ALIASES += "cgalParamBegin{1}=\ref PMP_\1 \"\1\"" +ALIASES += "cgalParamEnd=" +ALIASES += "cgalDescribePolylineType=A polyline is defined as a sequence of points, each pair of contiguous points defines a segment of the polyline. If the first and last points of the polyline are identical, the polyline is closed." + +#macros for NamedParameters.txt +ALIASES += "cgalNPTableBegin=
" +ALIASES += "cgalNPTableEnd=
" +ALIASES += "cgalNPBegin{1}=\1 " +ALIASES += "cgalNPEnd=" + + INPUT += \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/Polyhedral_complex_mesh_domain_3.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/Mesh_domain_with_polyline_features_3.h diff --git a/Mesh_3/doc/Mesh_3/PackageDescription.txt b/Mesh_3/doc/Mesh_3/PackageDescription.txt index 791b9c7894b..c5eda2eac45 100644 --- a/Mesh_3/doc/Mesh_3/PackageDescription.txt +++ b/Mesh_3/doc/Mesh_3/PackageDescription.txt @@ -139,6 +139,8 @@ and their associated classes: ## Input/Output Functions ## - `CGAL::output_to_medit()` +- `CGAL::write_polydata()` +- `CGAL::write_unstructured_grid_3()` */ diff --git a/Mesh_3/include/CGAL/IO/vtk_io.h b/Mesh_3/include/CGAL/IO/vtk_io.h index 9029f304e53..cbba82268bc 100644 --- a/Mesh_3/include/CGAL/IO/vtk_io.h +++ b/Mesh_3/include/CGAL/IO/vtk_io.h @@ -472,30 +472,6 @@ write_attributes(std::ostream& os, //public API -//! -//! \brief write_polydata_3 writes the content of a triangulated surface mesh in the .vtp -//! XML format. -//! -//! \tparam TriangleMesh a model of `FaceListGraph` with triangle faces. -//! \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" -//! -//! \param os a `std::ostream`. -//! \param mesh an instance of `TriangleMesh` to be written. -//! \param binary decides if the data should be written in binary(`true`) -//! or in ASCII(`false`). -//! \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the -//! ones listed below -//! -//! \cgalNamedParamsBegin -//! \cgalParamBegin{vertex_point_map} the property map with the points associated to -//! the vertices of `mesh`. If this parameter is omitted, an internal property map for -//! `CGAL::vertex_point_t` must be available in `TriangleMesh`. -//! \cgalParamEnd -//! \cgalParamBegin{vertex_index_map} the property map with the indices associated to -//! the vertices of `mesh`. If this parameter is omitted, an internal property map for -//! `CGAL::vertex_index_t` must be available in `TriangleMesh`. -//! \cgalParamEnd -//! \cgalNamedParamsEnd template void write_polydata(std::ostream& os, @@ -541,17 +517,7 @@ void write_polydata(std::ostream& os, write_polydata(os, mesh, binary, CGAL::parameters::all_default()); } -//! -//! \brief write_unstructured_grid_3 writes the content of a `C3t3` in the .vtu -//! XML format. -//! -//! \tparam C3T3 a model of `MeshComplexWithFeatures_3InTriangulation_3`. -//! -//! \param os a `std::ostream`. -//! \param c3t3 an instance of `C3T3` to be written. -//! \param binary decides if the data should be written in binary(`true`) -//! or in ASCII(`false`). -//! + template void write_unstructured_grid_3(std::ostream& os, const C3T3& c3t3) From 33a3996fa1d72557462142b19c51112c49158838 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 29 Oct 2018 15:02:20 +0100 Subject: [PATCH 13/47] Rename write_VTU and write_VTP --- .../Constrained_Delaunay_triangulation_2.cpp | 2 +- Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h | 4 ++-- Mesh_2/include/CGAL/IO/vtk_io_2.h | 2 +- Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h | 8 ++++---- Mesh_3/include/CGAL/IO/vtk_io.h | 8 ++++---- Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp index 352151640fd..9aafc882385 100644 --- a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp +++ b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp @@ -676,7 +676,7 @@ MainWindow::saveConstraints(QString fileName) output << cdt; else if (output) { - CGAL::write_unstructured_grid_2(output, cdt); + CGAL::write_VTU(output, cdt); } } diff --git a/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h b/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h index 1ca341b743e..103157509d0 100644 --- a/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h @@ -1,6 +1,6 @@ namespace CGAL{ //!\ingroup PkgMesh2 -//! \brief write_unstructured_grid_2 writes the content of a `CDT` in the .vtu +//! \brief writes the content of a `CDT` in the .vtu //! XML format. //! //! The triangles inside the domain and the constrained edges will be outputted. @@ -13,7 +13,7 @@ namespace CGAL{ //! or in ASCII(`false`). //! template -void write_unstructured_grid_2(std::ostream& os, +void write_VTU(std::ostream& os, const CDT& tr, bool binary = true); } diff --git a/Mesh_2/include/CGAL/IO/vtk_io_2.h b/Mesh_2/include/CGAL/IO/vtk_io_2.h index 1ad09ee3aad..160e383bcf6 100644 --- a/Mesh_2/include/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/include/CGAL/IO/vtk_io_2.h @@ -275,7 +275,7 @@ write_points(std::ostream& os, template -void write_unstructured_grid_2(std::ostream& os, +void write_VTU(std::ostream& os, const CDT& tr, bool binary = true) { diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h index 6c10de585c8..e58dca6acc5 100644 --- a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h @@ -1,7 +1,7 @@ namespace CGAL{ //! \ingroup PkgMesh_3IOFunctions //! -//! \brief write_polydata_3 writes the content of a triangulated surface mesh in the .vtp +//! \brief writes the content of a triangulated surface mesh in the .vtp //! XML format. //! //! \tparam TriangleMesh a model of `FaceListGraph` with triangle faces. @@ -26,14 +26,14 @@ namespace CGAL{ //! \cgalNamedParamsEnd template -void write_polydata(std::ostream& os, +void write_VTP(std::ostream& os, const TriangleMesh& mesh, bool binary, const NamedParameters& np); //! \ingroup PkgMesh_3IOFunctions //! -//! \brief write_unstructured_grid_3 writes the content of a `C3t3` in the .vtu +//! \brief writes the content of a `C3t3` in the .vtu //! XML format. //! //! \tparam C3T3 a model of `MeshComplexWithFeatures_3InTriangulation_3`. @@ -42,6 +42,6 @@ void write_polydata(std::ostream& os, //! \param c3t3 an instance of `C3T3` to be written. //! template -void write_unstructured_grid_3(std::ostream& os, +void write_VTU(std::ostream& os, const C3T3& c3t3); } diff --git a/Mesh_3/include/CGAL/IO/vtk_io.h b/Mesh_3/include/CGAL/IO/vtk_io.h index cbba82268bc..ce13b4e404a 100644 --- a/Mesh_3/include/CGAL/IO/vtk_io.h +++ b/Mesh_3/include/CGAL/IO/vtk_io.h @@ -474,7 +474,7 @@ write_attributes(std::ostream& os, template -void write_polydata(std::ostream& os, +void write_VTP(std::ostream& os, const TriangleMesh& mesh, bool binary, const NamedParameters& np) @@ -510,16 +510,16 @@ void write_polydata(std::ostream& os, } template -void write_polydata(std::ostream& os, +void write_VTP(std::ostream& os, const TriangleMesh& mesh, bool binary = true) { - write_polydata(os, mesh, binary, CGAL::parameters::all_default()); + write_VTP(os, mesh, binary, CGAL::parameters::all_default()); } template -void write_unstructured_grid_3(std::ostream& os, +void write_VTU(std::ostream& os, const C3T3& c3t3) { typedef typename C3T3::Triangulation Tr; diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index 7d797ba0079..db810b5ae02 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -345,7 +345,7 @@ public: std::ofstream os(output_filename.data()); os << std::setprecision(16); //write header - CGAL::write_polydata(os, *mesh); + CGAL::write_VTP(os, *mesh); } } else @@ -359,7 +359,7 @@ public: os << std::setprecision(16); const C3t3& c3t3 = c3t3_item->c3t3(); - CGAL::write_unstructured_grid_3(os, c3t3); + CGAL::write_VTU(os, c3t3); } return true; } From 08a98a5603652df0f7c4136e315c5319def81989 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 30 Oct 2018 11:51:34 +0100 Subject: [PATCH 14/47] Update Changes.md --- Installation/CHANGES.md | 7 +++---- Mesh_2/doc/Mesh_2/PackageDescription.txt | 2 +- Mesh_3/doc/Mesh_3/PackageDescription.txt | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index 7e65f197641..85e87b22d17 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -21,10 +21,9 @@ Release date: March 2019 - `CGAL::Polygon_mesh_processing::merge_duplicated_vertices_in_boundary_cycles()` ### 2D and 3D Mesh Generation -- Added 3 functions for writing in modern VTK formats: - -`CGAL::write_unstructured_grid_3(std::ostream& os, const C3T3& c3t3)` - -`CGAL::write_unstructured_grid_2(std::ostream& os, const CDT& tr, bool binary = true)` - -`CGAL::write_polydata(std::ostream& os, const TriangleMesh& mesh, bool binary, const NamedParameters& np)` +- Added 2 functions for writing in modern VTK formats: + -`CGAL::write_VTU()` + -`CGAL::write_VTP()` Release 4.13 diff --git a/Mesh_2/doc/Mesh_2/PackageDescription.txt b/Mesh_2/doc/Mesh_2/PackageDescription.txt index dd5e859cbfd..d76b4a3b3c4 100644 --- a/Mesh_2/doc/Mesh_2/PackageDescription.txt +++ b/Mesh_2/doc/Mesh_2/PackageDescription.txt @@ -57,7 +57,7 @@ The package can handle intersecting input constraints and set no restriction on - `CGAL::make_conforming_Gabriel_2` - `CGAL::refine_Delaunay_mesh_2` - `CGAL::lloyd_optimize_mesh_2` -- `CGAL::write_unstructured_grid_2()` +- `CGAL::write_VTU()` ## Enumerations ## - `CGAL::Mesh_optimization_return_code` diff --git a/Mesh_3/doc/Mesh_3/PackageDescription.txt b/Mesh_3/doc/Mesh_3/PackageDescription.txt index c5eda2eac45..060ddb44d1b 100644 --- a/Mesh_3/doc/Mesh_3/PackageDescription.txt +++ b/Mesh_3/doc/Mesh_3/PackageDescription.txt @@ -139,8 +139,8 @@ and their associated classes: ## Input/Output Functions ## - `CGAL::output_to_medit()` -- `CGAL::write_polydata()` -- `CGAL::write_unstructured_grid_3()` +- `CGAL::write_VTP()` +- `CGAL::write_VTU()` */ From 45b19c81349810c57bb9e114b84aa949faf5661b Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 15 Nov 2018 09:28:26 +0100 Subject: [PATCH 15/47] Remove debug code --- Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index db810b5ae02..0563ee80944 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -173,7 +173,6 @@ namespace CGAL{ vtkCell* cell_ptr = poly_data->GetCell(i); vtkIdType nb_vertices = cell_ptr->GetNumberOfPoints(); - std::cout< vr(nb_vertices); From 6e4ab58edc23c76a99ff28d12f7c521cba2d40de Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 20 Nov 2018 15:15:53 +0100 Subject: [PATCH 16/47] Put write_vtk in Polyhedron_IO --- BGL/doc/BGL/CGAL/boost/graph/vtp_io.h | 31 ++ Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h | 32 -- Mesh_3/include/CGAL/IO/vtk_io.h | 265 +---------------- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 1 + Polyhedron_IO/include/CGAL/IO/vtp_io.h | 279 ++++++++++++++++++ Stream_support/include/CGAL/IO/write_vtk.h | 16 + 6 files changed, 328 insertions(+), 296 deletions(-) create mode 100644 BGL/doc/BGL/CGAL/boost/graph/vtp_io.h create mode 100644 Polyhedron_IO/include/CGAL/IO/vtp_io.h create mode 100644 Stream_support/include/CGAL/IO/write_vtk.h diff --git a/BGL/doc/BGL/CGAL/boost/graph/vtp_io.h b/BGL/doc/BGL/CGAL/boost/graph/vtp_io.h new file mode 100644 index 00000000000..6604cdc7db3 --- /dev/null +++ b/BGL/doc/BGL/CGAL/boost/graph/vtp_io.h @@ -0,0 +1,31 @@ +//!\ingroup PkgBGLIOFct +//! +//! \brief writes the content of a triangulated surface mesh in the .vtp +//! XML format. +//! +//! \tparam TriangleMesh a model of `FaceListGraph` with triangle faces. +//! \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" +//! +//! \param os a `std::ostream`. +//! \param mesh an instance of `TriangleMesh` to be written. +//! \param binary decides if the data should be written in binary(`true`) +//! or in ASCII(`false`). +//! \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the +//! ones listed below +//! +//! \cgalNamedParamsBegin +//! \cgalParamBegin{vertex_point_map} the property map with the points associated to +//! the vertices of `mesh`. If this parameter is omitted, an internal property map for +//! `CGAL::vertex_point_t` must be available in `TriangleMesh`. +//! \cgalParamEnd +//! \cgalParamBegin{vertex_index_map} the property map with the indices associated to +//! the vertices of `mesh`. If this parameter is omitted, an internal property map for +//! `CGAL::vertex_index_t` must be available in `TriangleMesh`. +//! \cgalParamEnd +//! \cgalNamedParamsEnd +template +void write_VTP(std::ostream& os, + const TriangleMesh& mesh, + bool binary, + const NamedParameters& np); diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h index e58dca6acc5..4fa0d878bcf 100644 --- a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h @@ -1,36 +1,4 @@ namespace CGAL{ -//! \ingroup PkgMesh_3IOFunctions -//! -//! \brief writes the content of a triangulated surface mesh in the .vtp -//! XML format. -//! -//! \tparam TriangleMesh a model of `FaceListGraph` with triangle faces. -//! \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" -//! -//! \param os a `std::ostream`. -//! \param mesh an instance of `TriangleMesh` to be written. -//! \param binary decides if the data should be written in binary(`true`) -//! or in ASCII(`false`). -//! \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the -//! ones listed below -//! -//! \cgalNamedParamsBegin -//! \cgalParamBegin{vertex_point_map} the property map with the points associated to -//! the vertices of `mesh`. If this parameter is omitted, an internal property map for -//! `CGAL::vertex_point_t` must be available in `TriangleMesh`. -//! \cgalParamEnd -//! \cgalParamBegin{vertex_index_map} the property map with the indices associated to -//! the vertices of `mesh`. If this parameter is omitted, an internal property map for -//! `CGAL::vertex_index_t` must be available in `TriangleMesh`. -//! \cgalParamEnd -//! \cgalNamedParamsEnd -template -void write_VTP(std::ostream& os, - const TriangleMesh& mesh, - bool binary, - const NamedParameters& np); - //! \ingroup PkgMesh_3IOFunctions //! //! \brief writes the content of a `C3t3` in the .vtu diff --git a/Mesh_3/include/CGAL/IO/vtk_io.h b/Mesh_3/include/CGAL/IO/vtk_io.h index ce13b4e404a..934d494b57f 100644 --- a/Mesh_3/include/CGAL/IO/vtk_io.h +++ b/Mesh_3/include/CGAL/IO/vtk_io.h @@ -28,25 +28,10 @@ #include #include - -#include -#include - +#include //todo try to factorize with functors namespace CGAL{ -// writes the appended data into the .vtu file -template -void -write_vector(std::ostream& os, - const std::vector& vect) -{ - const char* buffer = reinterpret_cast(&(vect[0])); - std::size_t size = vect.size()*sizeof(FT); - - os.write(reinterpret_cast(&size), sizeof(std::size_t)); // number of bytes encoded - os.write(buffer, vect.size()*sizeof(FT)); // encoded data -} template void @@ -143,7 +128,6 @@ write_cells(std::ostream& os, std::vector connectivity_table; std::vector offsets; std::vector cell_type(c3t3.number_of_cells(),10); // tetrahedra == 10 - std::size_t off = 0; for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; cit != c3t3.cells_in_complex_end() ; @@ -160,136 +144,7 @@ write_cells(std::ostream& os, write_vector(os,cell_type); } -// writes the polys appended data at the end of the .vtp file -template -void -write_polys(std::ostream& os, - const Mesh & mesh, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::face_iterator face_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; - Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), - get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - std::vector connectivity_table; - std::vector offsets; - std::vector cell_type(num_faces(mesh),5); // triangle == 5 - - std::size_t off = 0; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - off += 3; - offsets.push_back(off); - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - connectivity_table.push_back(V[v]); - } - write_vector(os,connectivity_table); - write_vector(os,offsets); - write_vector(os,cell_type); -} -//todo use named params for maps -template -void -write_polys_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::face_iterator face_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; - Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), - get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - - - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - - std::string formatattribute = - binary ? " format=\"appended\"" : " format=\"ascii\""; - std::string typeattribute; - switch(sizeof(std::size_t)) { - case 8: typeattribute = " type=\"UInt64\""; break; - case 4: typeattribute = " type=\"UInt32\""; break; - default: CGAL_error_msg("Unknown size of std::size_t"); - } - - // Write connectivity table - os << " \n" - << " \n"; - offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); - // 3 indices (size_t) per triangle + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - os << V[v] << " "; - } - os << " \n"; - } - - // Write offsets - os << " \n"; - offset += (num_faces(mesh) + 1) * sizeof(std::size_t); - // 1 offset (size_t) per triangle + length of the encoded data (size_t) - } - else { - os << "\">\n"; - std::size_t polys_offset = 0; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - polys_offset += 3; - os << polys_offset << " "; - } - os << " \n"; - } - - // Write cell type (triangle == 5) - os << " \n"; - offset += num_faces(mesh) + sizeof(std::size_t); - // 1 unsigned char per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for(std::size_t i = 0; i< num_faces(mesh); ++i) - os << "5 "; - os << " \n"; - } - os << " \n"; -} -// writes the points tags before binary data is appended template void write_points_tag(std::ostream& os, @@ -335,51 +190,6 @@ write_points_tag(std::ostream& os, os << " \n"; } -//todo : use namedparams for points and ids -//overload for facegraph -template -void -write_points_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_iterator vertex_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), - get_const_property_map(CGAL::vertex_point, mesh)); - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - - std::string format = binary ? "appended" : "ascii"; - std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; - - os << " \n" - << " \n"; - offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); - // 3 coords per points + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( vertex_iterator vit = vertices(mesh).begin(); - vit != vertices(mesh).end(); - ++vit) - { - os << get(vpm, *vit).x() << " " << get(vpm, *vit).y() << " " - << get(vpm, *vit).z() << " "; - } - os << " \n"; - } - os << " \n"; -} - // writes the points appended data at the end of the .vtu file template void @@ -407,32 +217,6 @@ write_points(std::ostream& os, write_vector(os,coordinates); } -// writes the points appended data at the end of the .vtp file -template -void -write_polys_points(std::ostream& os, - const Mesh & mesh, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_iterator vertex_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), - get_const_property_map(CGAL::vertex_point, mesh)); - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - std::vector coordinates; - for( vertex_iterator vit = vertices(mesh).begin(); - vit != vertices(mesh).end(); - ++vit) - { - coordinates.push_back(get(vpm, *vit).x()); - coordinates.push_back(get(vpm, *vit).y()); - coordinates.push_back(get(vpm, *vit).z()); - } - write_vector(os,coordinates); -} // writes the attribute tags before binary data is appended template void @@ -471,53 +255,6 @@ write_attributes(std::ostream& os, } //public API - -template -void write_VTP(std::ostream& os, - const TriangleMesh& mesh, - bool binary, - const NamedParameters& np) -{ - os << "\n" - << "\n" - << " " << "\n"; - - os << " \n"; - std::size_t offset = 0; - write_points_tag(os,mesh,binary,offset, np); - write_polys_tag(os,mesh,binary,offset, np); - os << " \n" - << " \n"; - if (binary) { - os << "\n_"; - write_polys_points(os,mesh, np); - write_polys(os,mesh, np); - } - os << "\n"; -} - -template -void write_VTP(std::ostream& os, - const TriangleMesh& mesh, - bool binary = true) -{ - write_VTP(os, mesh, binary, CGAL::parameters::all_default()); -} - - template void write_VTU(std::ostream& os, const C3T3& c3t3) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index 0563ee80944..d74599bd2ad 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include diff --git a/Polyhedron_IO/include/CGAL/IO/vtp_io.h b/Polyhedron_IO/include/CGAL/IO/vtp_io.h new file mode 100644 index 00000000000..2c0ec6bf152 --- /dev/null +++ b/Polyhedron_IO/include/CGAL/IO/vtp_io.h @@ -0,0 +1,279 @@ +// Copyright (c) 2018 GeometryFactory (France). +// Copyright (c) 2004-2006 INRIA Sophia-Antipolis (France). +// Copyright (c) 2009 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno + +#ifndef CGAL_VTP_IO_H +#define CGAL_VTP_IO_H + +#include + + +#include +#include +#include + + +//todo try to factorize with functors +namespace CGAL{ +// writes the polys appended data at the end of the .vtp file +template +void +write_polys(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + std::vector connectivity_table; + std::vector offsets; + std::vector cell_type(num_faces(mesh),5); // triangle == 5 + + std::size_t off = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + off += 3; + offsets.push_back(off); + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + connectivity_table.push_back(V[v]); + } + write_vector(os,connectivity_table); + write_vector(os,offsets); + write_vector(os,cell_type); +} +//todo use named params for maps +template +void +write_polys_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + std::string formatattribute = + binary ? " format=\"appended\"" : " format=\"ascii\""; + + std::string typeattribute; + switch(sizeof(std::size_t)) { + case 8: typeattribute = " type=\"UInt64\""; break; + case 4: typeattribute = " type=\"UInt32\""; break; + default: CGAL_error_msg("Unknown size of std::size_t"); + } + + // Write connectivity table + os << " \n" + << " \n"; + offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); + // 3 indices (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + os << V[v] << " "; + } + os << " \n"; + } + + // Write offsets + os << " \n"; + offset += (num_faces(mesh) + 1) * sizeof(std::size_t); + // 1 offset (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + std::size_t polys_offset = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + polys_offset += 3; + os << polys_offset << " "; + } + os << " \n"; + } + + // Write cell type (triangle == 5) + os << " \n"; + offset += num_faces(mesh) + sizeof(std::size_t); + // 1 unsigned char per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for(std::size_t i = 0; i< num_faces(mesh); ++i) + os << "5 "; + os << " \n"; + } + os << " \n"; +} + +//todo : use namedparams for points and ids +//overload for facegraph +template +void +write_points_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; + + os << " \n" + << " \n"; + offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); + // 3 coords per points + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + os << get(vpm, *vit).x() << " " << get(vpm, *vit).y() << " " + << get(vpm, *vit).z() << " "; + } + os << " \n"; + } + os << " \n"; +} + + +// writes the points appended data at the end of the .vtp file +template +void +write_polys_points(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + std::vector coordinates; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + coordinates.push_back(get(vpm, *vit).x()); + coordinates.push_back(get(vpm, *vit).y()); + coordinates.push_back(get(vpm, *vit).z()); + } + write_vector(os,coordinates); +} + +//public API + +template +void write_VTP(std::ostream& os, + const TriangleMesh& mesh, + bool binary, + const NamedParameters& np) +{ + os << "\n" + << "\n" + << " " << "\n"; + + os << " \n"; + std::size_t offset = 0; + write_points_tag(os,mesh,binary,offset, np); + write_polys_tag(os,mesh,binary,offset, np); + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + write_polys_points(os,mesh, np); + write_polys(os,mesh, np); + } + os << "\n"; +} + +template +void write_VTP(std::ostream& os, + const TriangleMesh& mesh, + bool binary = true) +{ + write_VTP(os, mesh, binary, CGAL::parameters::all_default()); +} + +} //end CGAL +#endif // CGAL_VTP_IO_H diff --git a/Stream_support/include/CGAL/IO/write_vtk.h b/Stream_support/include/CGAL/IO/write_vtk.h new file mode 100644 index 00000000000..38a5c21e288 --- /dev/null +++ b/Stream_support/include/CGAL/IO/write_vtk.h @@ -0,0 +1,16 @@ +#ifndef CGAL_WRITE_VTK_IO_H +#define CGAL_WRITE_VTK_IO_H +#include +#include +template +void +write_vector(std::ostream& os, + const std::vector& vect) +{ + const char* buffer = reinterpret_cast(&(vect[0])); + std::size_t size = vect.size()*sizeof(FT); + + os.write(reinterpret_cast(&size), sizeof(std::size_t)); // number of bytes encoded + os.write(buffer, vect.size()*sizeof(FT)); // encoded data +} +#endif From 51808762906fa39a59b4482e1a6a614ac565d5aa Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 21 Nov 2018 10:48:16 +0100 Subject: [PATCH 17/47] Fix ambiguity between 2D and 3D write_VTU and restore gone bool binary in write_VTU 3D --- .../Triangulation_2/Constrained_Delaunay_triangulation_2.cpp | 2 +- Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h | 2 +- Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h | 5 ++++- Mesh_3/include/CGAL/IO/vtk_io.h | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp index 9aafc882385..28d30aee065 100644 --- a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp +++ b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp @@ -676,7 +676,7 @@ MainWindow::saveConstraints(QString fileName) output << cdt; else if (output) { - CGAL::write_VTU(output, cdt); + CGAL::write_VTU_2D(output, cdt); } } diff --git a/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h b/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h index 103157509d0..d2e4f2baa54 100644 --- a/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h @@ -13,7 +13,7 @@ namespace CGAL{ //! or in ASCII(`false`). //! template -void write_VTU(std::ostream& os, +void write_VTU_2D(std::ostream& os, const CDT& tr, bool binary = true); } diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h index 4fa0d878bcf..42e2d301617 100644 --- a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h @@ -8,8 +8,11 @@ namespace CGAL{ //! //! \param os a `std::ostream`. //! \param c3t3 an instance of `C3T3` to be written. +//! \param binary decides if the data should be written in binary(`true`) +//! or in ASCII(`false`). //! template void write_VTU(std::ostream& os, - const C3T3& c3t3); + const C3T3& c3t3, + bool binary = true); } diff --git a/Mesh_3/include/CGAL/IO/vtk_io.h b/Mesh_3/include/CGAL/IO/vtk_io.h index 934d494b57f..59668f0a2aa 100644 --- a/Mesh_3/include/CGAL/IO/vtk_io.h +++ b/Mesh_3/include/CGAL/IO/vtk_io.h @@ -257,7 +257,8 @@ write_attributes(std::ostream& os, //public API template void write_VTU(std::ostream& os, - const C3T3& c3t3) + const C3T3& c3t3, + bool binary = true) { typedef typename C3T3::Triangulation Tr; typedef typename Tr::Vertex_handle Vertex_handle; @@ -282,7 +283,6 @@ void write_VTU(std::ostream& os, os << " \n"; - bool binary = true; std::size_t offset = 0; write_points_tag(os,tr,V,binary,offset); write_cells_tag(os,c3t3,V,binary,offset); From 7b13f4a969fac3a0f583520108d5a9ad04ad8848 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 23 Nov 2018 10:11:23 +0100 Subject: [PATCH 18/47] Add misisng license header, rename vtu functions and update change.md --- BGL/doc/BGL/PackageDescription.txt | 1 + .../Constrained_Delaunay_triangulation_2.cpp | 2 +- Installation/CHANGES.md | 3 ++- Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h | 6 +++--- Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h | 2 +- Mesh_3/doc/Mesh_3/PackageDescription.txt | 4 +--- Mesh_3/include/CGAL/IO/vtk_io.h | 2 +- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 2 +- Stream_support/include/CGAL/IO/write_vtk.h | 21 +++++++++++++++++++ 9 files changed, 32 insertions(+), 11 deletions(-) diff --git a/BGL/doc/BGL/PackageDescription.txt b/BGL/doc/BGL/PackageDescription.txt index 6ba2f1ba2d6..9191c619c58 100644 --- a/BGL/doc/BGL/PackageDescription.txt +++ b/BGL/doc/BGL/PackageDescription.txt @@ -708,6 +708,7 @@ user might encounter. ## I/O Functions ## - \link PkgBGLIOFct CGAL::read_off() \endlink - \link PkgBGLIOFct CGAL::write_off() \endlink +- `CGAL::write_VTP()` */ diff --git a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp index 28d30aee065..9aafc882385 100644 --- a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp +++ b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp @@ -676,7 +676,7 @@ MainWindow::saveConstraints(QString fileName) output << cdt; else if (output) { - CGAL::write_VTU_2D(output, cdt); + CGAL::write_VTU(output, cdt); } } diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index 444b6b73fe0..20b61b4128d 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -55,7 +55,8 @@ Release date: March 2019 `Arr_polycurve_basic_traits_2`. ### 2D and 3D Mesh Generation -- Added 2 functions for writing in modern VTK formats: +- Added 3 functions for writing in modern VTK formats: + -`CGAL::output_to_vtu()` -`CGAL::write_VTU()` -`CGAL::write_VTP()` diff --git a/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h b/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h index d2e4f2baa54..27c2dce50c4 100644 --- a/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h @@ -13,7 +13,7 @@ namespace CGAL{ //! or in ASCII(`false`). //! template -void write_VTU_2D(std::ostream& os, - const CDT& tr, - bool binary = true); +void write_VTU(std::ostream& os, + const CDT& tr, + bool binary = true); } diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h index 42e2d301617..a1727dec86d 100644 --- a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h @@ -12,7 +12,7 @@ namespace CGAL{ //! or in ASCII(`false`). //! template -void write_VTU(std::ostream& os, +void output_to_vtu(std::ostream& os, const C3T3& c3t3, bool binary = true); } diff --git a/Mesh_3/doc/Mesh_3/PackageDescription.txt b/Mesh_3/doc/Mesh_3/PackageDescription.txt index e38a5da4d56..d67297572cd 100644 --- a/Mesh_3/doc/Mesh_3/PackageDescription.txt +++ b/Mesh_3/doc/Mesh_3/PackageDescription.txt @@ -139,8 +139,6 @@ and their associated classes: ## Input/Output Functions ## - `CGAL::output_to_medit()` -- `CGAL::write_VTP()` -- `CGAL::write_VTU()` - +- `CGAL::output_to_vtu()` */ diff --git a/Mesh_3/include/CGAL/IO/vtk_io.h b/Mesh_3/include/CGAL/IO/vtk_io.h index 59668f0a2aa..182a8b2cb7d 100644 --- a/Mesh_3/include/CGAL/IO/vtk_io.h +++ b/Mesh_3/include/CGAL/IO/vtk_io.h @@ -256,7 +256,7 @@ write_attributes(std::ostream& os, //public API template -void write_VTU(std::ostream& os, +void output_to_vtu(std::ostream& os, const C3T3& c3t3, bool binary = true) { diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index 01434d774f5..79ea93e2da2 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -343,7 +343,7 @@ public: os << std::setprecision(16); const C3t3& c3t3 = c3t3_item->c3t3(); - CGAL::write_VTU(os, c3t3); + CGAL::output_to_vtu(os, c3t3); } return true; } diff --git a/Stream_support/include/CGAL/IO/write_vtk.h b/Stream_support/include/CGAL/IO/write_vtk.h index 38a5c21e288..5d702e27d92 100644 --- a/Stream_support/include/CGAL/IO/write_vtk.h +++ b/Stream_support/include/CGAL/IO/write_vtk.h @@ -1,3 +1,24 @@ +// Copyright (c) 2018 +// GeometryFactory( France) All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Stephane Tayeb + #ifndef CGAL_WRITE_VTK_IO_H #define CGAL_WRITE_VTK_IO_H #include From e05feea350baea0c379d71922d0f9f8916827598 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 23 Nov 2018 10:42:47 +0100 Subject: [PATCH 19/47] Fix doc --- BGL/doc/BGL/PackageDescription.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BGL/doc/BGL/PackageDescription.txt b/BGL/doc/BGL/PackageDescription.txt index 9191c619c58..b76ff169a8f 100644 --- a/BGL/doc/BGL/PackageDescription.txt +++ b/BGL/doc/BGL/PackageDescription.txt @@ -708,7 +708,7 @@ user might encounter. ## I/O Functions ## - \link PkgBGLIOFct CGAL::read_off() \endlink - \link PkgBGLIOFct CGAL::write_off() \endlink -- `CGAL::write_VTP()` +- \link PkgBGLIOFct `CGAL::write_VTP()` \endlink */ From 756eeb7cdef053a660728c5cee23a26504709f08 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 29 Nov 2018 12:23:52 +0100 Subject: [PATCH 20/47] move vtp_io.h in BGL --- BGL/doc/BGL/CGAL/{boost/graph => IO}/vtp_io.h | 0 BGL/doc/BGL/Doxyfile.in | 2 ++ {Polyhedron_IO => BGL}/include/CGAL/IO/vtp_io.h | 0 3 files changed, 2 insertions(+) rename BGL/doc/BGL/CGAL/{boost/graph => IO}/vtp_io.h (100%) rename {Polyhedron_IO => BGL}/include/CGAL/IO/vtp_io.h (100%) diff --git a/BGL/doc/BGL/CGAL/boost/graph/vtp_io.h b/BGL/doc/BGL/CGAL/IO/vtp_io.h similarity index 100% rename from BGL/doc/BGL/CGAL/boost/graph/vtp_io.h rename to BGL/doc/BGL/CGAL/IO/vtp_io.h diff --git a/BGL/doc/BGL/Doxyfile.in b/BGL/doc/BGL/Doxyfile.in index 6948a31cf43..2ce62be128d 100644 --- a/BGL/doc/BGL/Doxyfile.in +++ b/BGL/doc/BGL/Doxyfile.in @@ -15,6 +15,8 @@ INPUT += ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/Euler_operations.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/partition.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/METIS/partition_graph.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/METIS/partition_dual_graph.h + ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/IO/vtp_io.h + EXAMPLE_PATH = ${CGAL_Surface_mesh_skeletonization_EXAMPLE_DIR} \ ${CGAL_Surface_mesh_segmentation_EXAMPLE_DIR} \ diff --git a/Polyhedron_IO/include/CGAL/IO/vtp_io.h b/BGL/include/CGAL/IO/vtp_io.h similarity index 100% rename from Polyhedron_IO/include/CGAL/IO/vtp_io.h rename to BGL/include/CGAL/IO/vtp_io.h From f8f53ba70491525862f1fb9a126c143bdd790b17 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 7 Dec 2018 15:05:14 +0100 Subject: [PATCH 21/47] Fix license in vtp_io.h --- BGL/include/CGAL/IO/vtp_io.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BGL/include/CGAL/IO/vtp_io.h b/BGL/include/CGAL/IO/vtp_io.h index 2c0ec6bf152..a616dd6b99c 100644 --- a/BGL/include/CGAL/IO/vtp_io.h +++ b/BGL/include/CGAL/IO/vtp_io.h @@ -16,7 +16,7 @@ // // $URL$ // $Id$ -// SPDX-License-Identifier: GPL-3.0+ +// SPDX-License-Identifier: LGPL-3.0+ // // Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno From c6835292d856ee3b69f70293dc47b62435686308 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 12 Dec 2018 16:50:51 +0100 Subject: [PATCH 22/47] Add include of license --- Stream_support/include/CGAL/IO/write_vtk.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Stream_support/include/CGAL/IO/write_vtk.h b/Stream_support/include/CGAL/IO/write_vtk.h index 5d702e27d92..b55df59c17e 100644 --- a/Stream_support/include/CGAL/IO/write_vtk.h +++ b/Stream_support/include/CGAL/IO/write_vtk.h @@ -21,6 +21,9 @@ #ifndef CGAL_WRITE_VTK_IO_H #define CGAL_WRITE_VTK_IO_H + +#include + #include #include template From 7e7cb6826871f1342860413f0f36ae56344b2097 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 13 Dec 2018 09:14:53 +0100 Subject: [PATCH 23/47] Fix header for vtp_io --- BGL/include/CGAL/IO/vtp_io.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BGL/include/CGAL/IO/vtp_io.h b/BGL/include/CGAL/IO/vtp_io.h index a616dd6b99c..19de9552e61 100644 --- a/BGL/include/CGAL/IO/vtp_io.h +++ b/BGL/include/CGAL/IO/vtp_io.h @@ -3,10 +3,10 @@ // Copyright (c) 2009 INRIA Sophia-Antipolis (France). // All rights reserved. // -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. From 18eaf08cc2dbd476ec7727b5e6ed85672fa95a24 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 13 Dec 2018 17:58:24 +0100 Subject: [PATCH 24/47] replace headers --- BGL/include/CGAL/IO/vtp_io.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BGL/include/CGAL/IO/vtp_io.h b/BGL/include/CGAL/IO/vtp_io.h index 19de9552e61..6a09aa5ae82 100644 --- a/BGL/include/CGAL/IO/vtp_io.h +++ b/BGL/include/CGAL/IO/vtp_io.h @@ -26,8 +26,8 @@ #include -#include -#include +#include +#include #include From cb10422e3ceaab789e56c1192b4f064e3906c8a0 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 16 Jan 2019 09:58:02 +0100 Subject: [PATCH 25/47] Fix indentation and markdown --- BGL/doc/BGL/PackageDescription.txt | 2 +- BGL/include/CGAL/IO/vtp_io.h | 42 ++++++++-------- .../Constrained_Delaunay_triangulation_2.cpp | 50 +++++++++---------- Installation/CHANGES.md | 8 +-- Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h | 4 +- 5 files changed, 53 insertions(+), 53 deletions(-) diff --git a/BGL/doc/BGL/PackageDescription.txt b/BGL/doc/BGL/PackageDescription.txt index 0bb14dfbb42..cde8cb34f89 100644 --- a/BGL/doc/BGL/PackageDescription.txt +++ b/BGL/doc/BGL/PackageDescription.txt @@ -708,7 +708,7 @@ user might encounter. ## I/O Functions ## - \link PkgBGLIOFct CGAL::read_off() \endlink - \link PkgBGLIOFct CGAL::write_off() \endlink -- \link PkgBGLIOFct `CGAL::write_VTP()` \endlink +- \link PkgBGLIOFct CGAL::write_VTP() \endlink - \link PkgBGLIOFct CGAL::write_wrl() \endlink */ diff --git a/BGL/include/CGAL/IO/vtp_io.h b/BGL/include/CGAL/IO/vtp_io.h index 6a09aa5ae82..77e7c717e13 100644 --- a/BGL/include/CGAL/IO/vtp_io.h +++ b/BGL/include/CGAL/IO/vtp_io.h @@ -50,18 +50,18 @@ write_polys(std::ostream& os, std::vector connectivity_table; std::vector offsets; std::vector cell_type(num_faces(mesh),5); // triangle == 5 - + std::size_t off = 0; for( face_iterator fit = faces(mesh).begin() ; fit != faces(mesh).end() ; ++fit ) - { - off += 3; - offsets.push_back(off); - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - connectivity_table.push_back(V[v]); - } + { + off += 3; + offsets.push_back(off); + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + connectivity_table.push_back(V[v]); + } write_vector(os,connectivity_table); write_vector(os,offsets); write_vector(os,cell_type); @@ -105,13 +105,13 @@ write_polys_tag(std::ostream& os, else { os << "\">\n"; for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - os << V[v] << " "; - } + fit != faces(mesh).end() ; + ++fit ) + { + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + os << V[v] << " "; + } os << " \n"; } @@ -128,12 +128,12 @@ write_polys_tag(std::ostream& os, os << "\">\n"; std::size_t polys_offset = 0; for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - polys_offset += 3; - os << polys_offset << " "; - } + fit != faces(mesh).end() ; + ++fit ) + { + polys_offset += 3; + os << polys_offset << " "; + } os << " \n"; } diff --git a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp index 9aafc882385..efec041a6f3 100644 --- a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp +++ b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp @@ -85,12 +85,12 @@ discoverInfiniteComponent(const CDT & ct) Face_handle fh = queue.front(); queue.pop_front(); fh->set_in_domain(false); - + for(int i = 0; i < 3; i++) { Face_handle fi = fh->neighbor(i); if(fi->is_in_domain() - && !ct.is_constrained(CDT::Edge(fh,i))) + && !ct.is_constrained(CDT::Edge(fh,i))) queue.push_back(fi); } } @@ -270,7 +270,7 @@ MainWindow::MainWindow() dgi->setFacesInDomainBrush(facesColor); QObject::connect(this, SIGNAL(changed()), - dgi, SLOT(modelChanged())); + dgi, SLOT(modelChanged())); dgi->setVerticesPen( QPen(Qt::red, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); dgi->setVoronoiPen( @@ -286,8 +286,8 @@ MainWindow::MainWindow() // the signal/slot mechanism pi = new CGAL::Qt::GraphicsViewPolylineInput(this, &scene, 0, true); // inputs polylines which are not closed QObject::connect(pi, SIGNAL(generate(CGAL::Object)), - this, SLOT(processInput(CGAL::Object))); - + this, SLOT(processInput(CGAL::Object))); + tcc = new CGAL::Qt::TriangulationCircumcircle(&scene, &cdt, this); tcc->setPen(QPen(Qt::red, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); @@ -299,8 +299,8 @@ MainWindow::MainWindow() // Manual handling of actions // QObject::connect(this->actionQuit, SIGNAL(triggered()), - this, SLOT(close())); - + this, SLOT(close())); + // We put mutually exclusive actions in an QActionGroup QActionGroup* ag = new QActionGroup(this); ag->addAction(this->actionInsertPolyline); @@ -339,7 +339,7 @@ MainWindow::MainWindow() this->addRecentFiles(this->menuFile, this->actionQuit); connect(this, SIGNAL(openRecentFile(QString)), - this, SLOT(open(QString))); + this, SLOT(open(QString))); } @@ -535,11 +535,11 @@ void MainWindow::on_actionLoadConstraints_triggered() { QString fileName = QFileDialog::getOpenFileName(this, - tr("Open Constraint File"), - ".", - tr("Edge files (*.edg);;" + tr("Open Constraint File"), + ".", + tr("Edge files (*.edg);;" "Plg files (*.plg);;" - "Poly files (*.poly)")); + "Poly files (*.poly)")); open(fileName); } @@ -656,10 +656,10 @@ void MainWindow::on_actionSaveConstraints_triggered() { QString fileName = QFileDialog::getSaveFileName(this, - tr("Save Constraints"), - ".", - tr("Poly files (*.poly)\n" - "Edge files (*.edg)\n" + tr("Save Constraints"), + ".", + tr("Poly files (*.poly)\n" + "Edge files (*.edg)\n" "VTU files (*.vtu)")); if(! fileName.isEmpty()){ saveConstraints(fileName); @@ -804,15 +804,15 @@ MainWindow::on_actionInsertRandomPoints_triggered() bool ok = false; const int number_of_points = - QInputDialog::getInt(this, - tr("Number of random points"), - tr("Enter number of random points"), - 100, - 0, - (std::numeric_limits::max)(), - 1, - &ok); - + QInputDialog::getInt(this, + tr("Number of random points"), + tr("Enter number of random points"), + 100, + 0, + (std::numeric_limits::max)(), + 1, + &ok); + if(!ok) { return; } diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index 800b85233fa..f98c94b84a4 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -63,10 +63,10 @@ Release date: March 2019 `Arr_polycurve_basic_traits_2`. ### 2D and 3D Mesh Generation -- Added 3 functions for writing in modern VTK formats: - -`CGAL::output_to_vtu()` - -`CGAL::write_VTU()` - -`CGAL::write_VTP()` +- Added 3 functions for writing in XML VTK formats: + - `CGAL::output_to_vtu()` + - `CGAL::write_VTU()` + - `CGAL::write_VTP()` ### CGAL and the Boost Graph Library (BGL) diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h index a1727dec86d..952100e9b32 100644 --- a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h @@ -13,6 +13,6 @@ namespace CGAL{ //! template void output_to_vtu(std::ostream& os, - const C3T3& c3t3, - bool binary = true); + const C3T3& c3t3, + bool binary = true); } From 3a7269b8f66e00f8e73507eb7a4dd0d3290c9978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 16 Jan 2019 12:00:07 +0100 Subject: [PATCH 26/47] improve doc --- BGL/doc/BGL/CGAL/IO/vtp_io.h | 31 ------------ BGL/doc/BGL/Doxyfile.in | 2 +- BGL/include/CGAL/IO/vtp_io.h | 73 ++++++++++++++++++---------- Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h | 22 ++++----- Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h | 17 +++---- 5 files changed, 68 insertions(+), 77 deletions(-) delete mode 100644 BGL/doc/BGL/CGAL/IO/vtp_io.h diff --git a/BGL/doc/BGL/CGAL/IO/vtp_io.h b/BGL/doc/BGL/CGAL/IO/vtp_io.h deleted file mode 100644 index 6604cdc7db3..00000000000 --- a/BGL/doc/BGL/CGAL/IO/vtp_io.h +++ /dev/null @@ -1,31 +0,0 @@ -//!\ingroup PkgBGLIOFct -//! -//! \brief writes the content of a triangulated surface mesh in the .vtp -//! XML format. -//! -//! \tparam TriangleMesh a model of `FaceListGraph` with triangle faces. -//! \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" -//! -//! \param os a `std::ostream`. -//! \param mesh an instance of `TriangleMesh` to be written. -//! \param binary decides if the data should be written in binary(`true`) -//! or in ASCII(`false`). -//! \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the -//! ones listed below -//! -//! \cgalNamedParamsBegin -//! \cgalParamBegin{vertex_point_map} the property map with the points associated to -//! the vertices of `mesh`. If this parameter is omitted, an internal property map for -//! `CGAL::vertex_point_t` must be available in `TriangleMesh`. -//! \cgalParamEnd -//! \cgalParamBegin{vertex_index_map} the property map with the indices associated to -//! the vertices of `mesh`. If this parameter is omitted, an internal property map for -//! `CGAL::vertex_index_t` must be available in `TriangleMesh`. -//! \cgalParamEnd -//! \cgalNamedParamsEnd -template -void write_VTP(std::ostream& os, - const TriangleMesh& mesh, - bool binary, - const NamedParameters& np); diff --git a/BGL/doc/BGL/Doxyfile.in b/BGL/doc/BGL/Doxyfile.in index 2ce62be128d..afdb3bfb933 100644 --- a/BGL/doc/BGL/Doxyfile.in +++ b/BGL/doc/BGL/Doxyfile.in @@ -14,7 +14,7 @@ INPUT += ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/Euler_operations.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/io.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/partition.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/METIS/partition_graph.h \ - ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/METIS/partition_dual_graph.h + ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/METIS/partition_dual_graph.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/IO/vtp_io.h diff --git a/BGL/include/CGAL/IO/vtp_io.h b/BGL/include/CGAL/IO/vtp_io.h index 77e7c717e13..75e6e722c48 100644 --- a/BGL/include/CGAL/IO/vtp_io.h +++ b/BGL/include/CGAL/IO/vtp_io.h @@ -33,7 +33,7 @@ //todo try to factorize with functors namespace CGAL{ -// writes the polys appended data at the end of the .vtp file +// writes the polys appended data at the end of the .vtp file template void @@ -46,7 +46,7 @@ write_polys(std::ostream& os, typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - + std::vector connectivity_table; std::vector offsets; std::vector cell_type(num_faces(mesh),5); // triangle == 5 @@ -69,7 +69,7 @@ write_polys(std::ostream& os, //todo use named params for maps template -void +void write_polys_tag(std::ostream& os, const Mesh & mesh, bool binary, @@ -81,7 +81,7 @@ write_polys_tag(std::ostream& os, typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - + std::string formatattribute = binary ? " format=\"appended\"" : " format=\"ascii\""; @@ -96,14 +96,14 @@ write_polys_tag(std::ostream& os, os << " \n" << " \n"; offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); // 3 indices (size_t) per triangle + length of the encoded data (size_t) } else { - os << "\">\n"; + os << "\">\n"; for( face_iterator fit = faces(mesh).begin() ; fit != faces(mesh).end() ; ++fit ) @@ -114,18 +114,18 @@ write_polys_tag(std::ostream& os, } os << " \n"; } - + // Write offsets os << " \n"; offset += (num_faces(mesh) + 1) * sizeof(std::size_t); // 1 offset (size_t) per triangle + length of the encoded data (size_t) } else { - os << "\">\n"; + os << "\">\n"; std::size_t polys_offset = 0; for( face_iterator fit = faces(mesh).begin() ; fit != faces(mesh).end() ; @@ -133,7 +133,7 @@ write_polys_tag(std::ostream& os, { polys_offset += 3; os << polys_offset << " "; - } + } os << " \n"; } @@ -147,7 +147,7 @@ write_polys_tag(std::ostream& os, // 1 unsigned char per cell + length of the encoded data (size_t) } else { - os << "\">\n"; + os << "\">\n"; for(std::size_t i = 0; i< num_faces(mesh); ++i) os << "5 "; os << " \n"; @@ -159,12 +159,12 @@ write_polys_tag(std::ostream& os, //overload for facegraph template -void +void write_points_tag(std::ostream& os, const Mesh & mesh, bool binary, std::size_t& offset, - const NamedParameters& np) + const NamedParameters& np) { typedef typename boost::graph_traits::vertex_iterator vertex_iterator; typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; @@ -182,12 +182,12 @@ write_points_tag(std::ostream& os, << format; if (binary) { - os << "\" offset=\"" << offset << "\"/>\n"; + os << "\" offset=\"" << offset << "\"/>\n"; offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); // 3 coords per points + length of the encoded data (size_t) } else { - os << "\">\n"; + os << "\">\n"; for( vertex_iterator vit = vertices(mesh).begin(); vit != vertices(mesh).end(); ++vit) @@ -201,7 +201,7 @@ write_points_tag(std::ostream& os, } -// writes the points appended data at the end of the .vtp file +// writes the points appended data at the end of the .vtp file template void @@ -228,14 +228,37 @@ write_polys_points(std::ostream& os, write_vector(os,coordinates); } -//public API - -template void write_VTP(std::ostream& os, - const TriangleMesh& mesh, - bool binary, - const NamedParameters& np) + const TriangleMesh& mesh, + bool binary, + const NamedParameters& np) { os << "\n" << "\n" << " " << "\n"; - - os << " \n"; std::size_t offset = 0; write_points_tag(os,mesh,binary,offset, np); @@ -260,7 +283,7 @@ void write_VTP(std::ostream& os, os << " \n" << " \n"; if (binary) { - os << "\n_"; + os << "\n_"; write_polys_points(os,mesh, np); write_polys(os,mesh, np); } diff --git a/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h b/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h index 27c2dce50c4..c86692d761b 100644 --- a/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h @@ -1,16 +1,16 @@ namespace CGAL{ //!\ingroup PkgMesh2 -//! \brief writes the content of a `CDT` in the .vtu -//! XML format. -//! -//! The triangles inside the domain and the constrained edges will be outputted. -//! -//! \tparam CDT a `Constrained_Delaunay_triangulation_2`. -//! -//! \param os a `std::ostream`. -//! \param tr an instance of `CDT` to be written. -//! \param binary decides if the data should be written in binary(`true`) -//! or in ASCII(`false`). +//! \brief writes the faces of a domain and its constrained edges embedded in +//! a 2D constrained Delaunay triangulation using the `PolyData` XML format. +//! +//! The faces output are those for which `DelaunayMeshFaceBase_2::is_in_domain()` returns `true`, +//! the edges are those for which `ConstrainedTriangulationFaceBase_2::is_constained()` returns `true`. +//! \tparam CDT a `Constrained_Delaunay_triangulation_2` with face type model of `DelaunayMeshFaceBase_2`. +//! +//! \param os the stream used for writting. +//! \param tr the triangulated domain to be written. +//! \param binary decides if the data should be written in binary (`true`) +//! or in ASCII (`false`). //! template void write_VTU(std::ostream& os, diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h index 952100e9b32..63c44a13a64 100644 --- a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h @@ -1,15 +1,14 @@ namespace CGAL{ //! \ingroup PkgMesh_3IOFunctions -//! -//! \brief writes the content of a `C3t3` in the .vtu -//! XML format. -//! +//! +//! \brief writes a tetrahedron mesh using the `UnstructuredGrid` XML format. +//! //! \tparam C3T3 a model of `MeshComplexWithFeatures_3InTriangulation_3`. -//! -//! \param os a `std::ostream`. -//! \param c3t3 an instance of `C3T3` to be written. -//! \param binary decides if the data should be written in binary(`true`) -//! or in ASCII(`false`). +//! +//! \param os the stream used for writting. +//! \param c3t3 the instance of `C3T3` to be written. +//! \param binary decides if the data should be written in binary (`true`) +//! or in ASCII (`false`). //! template void output_to_vtu(std::ostream& os, From 40cf3869ba1ddf183db8b10dac9c6fad64be8641 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 16 Jan 2019 16:15:01 +0100 Subject: [PATCH 27/47] My changes for write_vtp --- BGL/doc/BGL/Doxyfile.in | 3 +- BGL/doc/BGL/PackageDescription.txt | 2 +- BGL/include/CGAL/IO/vtp_io.h | 302 ------------------ BGL/include/CGAL/boost/graph/io.h | 279 ++++++++++++++++ Installation/CHANGES.md | 3 +- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 4 +- 6 files changed, 285 insertions(+), 308 deletions(-) delete mode 100644 BGL/include/CGAL/IO/vtp_io.h diff --git a/BGL/doc/BGL/Doxyfile.in b/BGL/doc/BGL/Doxyfile.in index afdb3bfb933..9681886835a 100644 --- a/BGL/doc/BGL/Doxyfile.in +++ b/BGL/doc/BGL/Doxyfile.in @@ -14,8 +14,7 @@ INPUT += ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/Euler_operations.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/io.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/partition.h \ ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/METIS/partition_graph.h \ - ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/METIS/partition_dual_graph.h \ - ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/IO/vtp_io.h + ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/METIS/partition_dual_graph.h EXAMPLE_PATH = ${CGAL_Surface_mesh_skeletonization_EXAMPLE_DIR} \ diff --git a/BGL/doc/BGL/PackageDescription.txt b/BGL/doc/BGL/PackageDescription.txt index cde8cb34f89..2ae5f33bd19 100644 --- a/BGL/doc/BGL/PackageDescription.txt +++ b/BGL/doc/BGL/PackageDescription.txt @@ -708,7 +708,7 @@ user might encounter. ## I/O Functions ## - \link PkgBGLIOFct CGAL::read_off() \endlink - \link PkgBGLIOFct CGAL::write_off() \endlink -- \link PkgBGLIOFct CGAL::write_VTP() \endlink +- \link PkgBGLIOFct CGAL::write_vtp() \endlink - \link PkgBGLIOFct CGAL::write_wrl() \endlink */ diff --git a/BGL/include/CGAL/IO/vtp_io.h b/BGL/include/CGAL/IO/vtp_io.h deleted file mode 100644 index 75e6e722c48..00000000000 --- a/BGL/include/CGAL/IO/vtp_io.h +++ /dev/null @@ -1,302 +0,0 @@ -// Copyright (c) 2018 GeometryFactory (France). -// Copyright (c) 2004-2006 INRIA Sophia-Antipolis (France). -// Copyright (c) 2009 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno - -#ifndef CGAL_VTP_IO_H -#define CGAL_VTP_IO_H - -#include - - -#include -#include -#include - - -//todo try to factorize with functors -namespace CGAL{ -// writes the polys appended data at the end of the .vtp file -template -void -write_polys(std::ostream& os, - const Mesh & mesh, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::face_iterator face_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; - Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), - get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - - std::vector connectivity_table; - std::vector offsets; - std::vector cell_type(num_faces(mesh),5); // triangle == 5 - - std::size_t off = 0; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - off += 3; - offsets.push_back(off); - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - connectivity_table.push_back(V[v]); - } - write_vector(os,connectivity_table); - write_vector(os,offsets); - write_vector(os,cell_type); -} -//todo use named params for maps -template -void -write_polys_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::face_iterator face_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; - Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), - get_const_property_map(CGAL::internal_np::vertex_index, mesh)); - - std::string formatattribute = - binary ? " format=\"appended\"" : " format=\"ascii\""; - - std::string typeattribute; - switch(sizeof(std::size_t)) { - case 8: typeattribute = " type=\"UInt64\""; break; - case 4: typeattribute = " type=\"UInt32\""; break; - default: CGAL_error_msg("Unknown size of std::size_t"); - } - - // Write connectivity table - os << " \n" - << " \n"; - offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); - // 3 indices (size_t) per triangle + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - BOOST_FOREACH(vertex_descriptor v, - vertices_around_face(halfedge(*fit, mesh), mesh)) - os << V[v] << " "; - } - os << " \n"; - } - - // Write offsets - os << " \n"; - offset += (num_faces(mesh) + 1) * sizeof(std::size_t); - // 1 offset (size_t) per triangle + length of the encoded data (size_t) - } - else { - os << "\">\n"; - std::size_t polys_offset = 0; - for( face_iterator fit = faces(mesh).begin() ; - fit != faces(mesh).end() ; - ++fit ) - { - polys_offset += 3; - os << polys_offset << " "; - } - os << " \n"; - } - - // Write cell type (triangle == 5) - os << " \n"; - offset += num_faces(mesh) + sizeof(std::size_t); - // 1 unsigned char per cell + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for(std::size_t i = 0; i< num_faces(mesh); ++i) - os << "5 "; - os << " \n"; - } - os << " \n"; -} - -//todo : use namedparams for points and ids -//overload for facegraph -template -void -write_points_tag(std::ostream& os, - const Mesh & mesh, - bool binary, - std::size_t& offset, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_iterator vertex_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), - get_const_property_map(CGAL::vertex_point, mesh)); - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - - std::string format = binary ? "appended" : "ascii"; - std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; - - os << " \n" - << " \n"; - offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); - // 3 coords per points + length of the encoded data (size_t) - } - else { - os << "\">\n"; - for( vertex_iterator vit = vertices(mesh).begin(); - vit != vertices(mesh).end(); - ++vit) - { - os << get(vpm, *vit).x() << " " << get(vpm, *vit).y() << " " - << get(vpm, *vit).z() << " "; - } - os << " \n"; - } - os << " \n"; -} - - -// writes the points appended data at the end of the .vtp file -template -void -write_polys_points(std::ostream& os, - const Mesh & mesh, - const NamedParameters& np) -{ - typedef typename boost::graph_traits::vertex_iterator vertex_iterator; - typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; - Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), - get_const_property_map(CGAL::vertex_point, mesh)); - typedef typename boost::property_traits::value_type Point_t; - typedef typename CGAL::Kernel_traits::Kernel Gt; - typedef typename Gt::FT FT; - std::vector coordinates; - for( vertex_iterator vit = vertices(mesh).begin(); - vit != vertices(mesh).end(); - ++vit) - { - coordinates.push_back(get(vpm, *vit).x()); - coordinates.push_back(get(vpm, *vit).y()); - coordinates.push_back(get(vpm, *vit).z()); - } - write_vector(os,coordinates); -} - -/*!\ingroup PkgBGLIOFct - * - * \brief writes a triangulated surface mesh in the `PolyData` XML format. - * - * \tparam TriangleMesh a model of `FaceListGraph` with only triangle faces. - * \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" - * - * \param os the stream used for writting. - * \param mesh the triangle mesh to be written. - * \param binary decides if the data should be written in binary (`true`) - * or in ASCII (`false`). - * \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the - * ones listed below - * - * \cgalNamedParamsBegin - * \cgalParamBegin{vertex_point_map} the property map with the points associated to - * the vertices of `mesh`. If this parameter is omitted, an internal property map for - * `CGAL::vertex_point_t` must be available in `TriangleMesh`. - * \cgalParamEnd - * \cgalParamBegin{vertex_index_map} the property map with the indices associated to - * the vertices of `mesh`. If this parameter is omitted, an internal property map for - * `CGAL::vertex_index_t` must be available in `TriangleMesh`. - * \cgalParamEnd - * \cgalNamedParamsEnd - */ -template -void write_VTP(std::ostream& os, - const TriangleMesh& mesh, - bool binary, - const NamedParameters& np) -{ - os << "\n" - << "\n" - << " " << "\n"; - - os << " \n"; - std::size_t offset = 0; - write_points_tag(os,mesh,binary,offset, np); - write_polys_tag(os,mesh,binary,offset, np); - os << " \n" - << " \n"; - if (binary) { - os << "\n_"; - write_polys_points(os,mesh, np); - write_polys(os,mesh, np); - } - os << "\n"; -} - -template -void write_VTP(std::ostream& os, - const TriangleMesh& mesh, - bool binary = true) -{ - write_VTP(os, mesh, binary, CGAL::parameters::all_default()); -} - -} //end CGAL -#endif // CGAL_VTP_IO_H diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index 60dcfca72ad..11a2b60ce0c 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -34,6 +34,7 @@ #include #include #include +#include namespace CGAL { /*! @@ -401,6 +402,284 @@ bool write_inp(std::ostream& os, { return write_inp(os, g, name, type, parameters::all_default()); } + +namespace internal { + namespace write_vtp { + +// writes the polys appended data at the end of the .vtp file +template +void +write_polys(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + std::vector connectivity_table; + std::vector offsets; + std::vector cell_type(num_faces(mesh),5); // triangle == 5 + + std::size_t off = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + off += 3; + offsets.push_back(off); + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + connectivity_table.push_back(V[v]); + } + write_vector(os,connectivity_table); + write_vector(os,offsets); + write_vector(os,cell_type); +} +//todo use named params for maps +template +void +write_polys_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexIndexMap::type Vimap; + Vimap V = choose_param(get_param(np, CGAL::internal_np::vertex_index), + get_const_property_map(CGAL::internal_np::vertex_index, mesh)); + + std::string formatattribute = + binary ? " format=\"appended\"" : " format=\"ascii\""; + + std::string typeattribute; + switch(sizeof(std::size_t)) { + case 8: typeattribute = " type=\"UInt64\""; break; + case 4: typeattribute = " type=\"UInt32\""; break; + default: CGAL_error_msg("Unknown size of std::size_t"); + } + + // Write connectivity table + os << " \n" + << " \n"; + offset += (3 * num_faces(mesh)+ 1) * sizeof(std::size_t); + // 3 indices (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + BOOST_FOREACH(vertex_descriptor v, + vertices_around_face(halfedge(*fit, mesh), mesh)) + os << V[v] << " "; + } + os << " \n"; + } + + // Write offsets + os << " \n"; + offset += (num_faces(mesh) + 1) * sizeof(std::size_t); + // 1 offset (size_t) per triangle + length of the encoded data (size_t) + } + else { + os << "\">\n"; + std::size_t polys_offset = 0; + for( face_iterator fit = faces(mesh).begin() ; + fit != faces(mesh).end() ; + ++fit ) + { + polys_offset += 3; + os << polys_offset << " "; + } + os << " \n"; + } + + // Write cell type (triangle == 5) + os << " \n"; + offset += num_faces(mesh) + sizeof(std::size_t); + // 1 unsigned char per cell + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for(std::size_t i = 0; i< num_faces(mesh); ++i) + os << "5 "; + os << " \n"; + } + os << " \n"; +} + +//todo : use namedparams for points and ids +//overload for facegraph +template +void +write_points_tag(std::ostream& os, + const Mesh & mesh, + bool binary, + std::size_t& offset, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(FT) == 8) ? "Float64" : "Float32"; + + os << " \n" + << " \n"; + offset += 3 * num_vertices(mesh) * sizeof(FT) + sizeof(std::size_t); + // 3 coords per points + length of the encoded data (size_t) + } + else { + os << "\">\n"; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + os << get(vpm, *vit).x() << " " << get(vpm, *vit).y() << " " + << get(vpm, *vit).z() << " "; + } + os << " \n"; + } + os << " \n"; +} + + +// writes the points appended data at the end of the .vtp file +template +void +write_polys_points(std::ostream& os, + const Mesh & mesh, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename CGAL::Polygon_mesh_processing::GetVertexPointMap::const_type Vpmap; + Vpmap vpm = choose_param(get_param(np, CGAL::vertex_point), + get_const_property_map(CGAL::vertex_point, mesh)); + typedef typename boost::property_traits::value_type Point_t; + typedef typename CGAL::Kernel_traits::Kernel Gt; + typedef typename Gt::FT FT; + std::vector coordinates; + for( vertex_iterator vit = vertices(mesh).begin(); + vit != vertices(mesh).end(); + ++vit) + { + coordinates.push_back(get(vpm, *vit).x()); + coordinates.push_back(get(vpm, *vit).y()); + coordinates.push_back(get(vpm, *vit).z()); + } + write_vector(os,coordinates); +} + + } // end namespace CGAL::internal::write_vtp +} // end namespace CGAL::internal + +/*!\ingroup PkgBGLIOFct + * + * \brief writes a triangulated surface mesh in the `PolyData` XML format. + * + * \tparam TriangleMesh a model of `FaceListGraph` with only triangle faces. + * \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" + * + * \param os the stream used for writting. + * \param mesh the triangle mesh to be written. + * \param mode decides if the data should be written in binary (`IO::BINARY`) + * or in ASCII (`IO::ASCII`). `IO::BINARY` is the default. + * \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the + * ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamBegin{vertex_point_map} the property map with the points associated to + * the vertices of `mesh`. If this parameter is omitted, an internal property map for + * `CGAL::vertex_point_t` must be available in `TriangleMesh`. + * \cgalParamEnd + * \cgalParamBegin{vertex_index_map} the property map with the indices associated to + * the vertices of `mesh`. If this parameter is omitted, an internal property map for + * `CGAL::vertex_index_t` must be available in `TriangleMesh`. + * \cgalParamEnd + * \cgalNamedParamsEnd + */ +template +void write_vtp(std::ostream& os, + const TriangleMesh& mesh, + IO::Mode mode, + const NamedParameters& np) +{ + os << "\n" + << "\n" + << " " << "\n"; + + os << " \n"; + std::size_t offset = 0; + const bool binary = (mode == IO::BINARY); + internal::write_vtp::write_points_tag(os,mesh,binary,offset, np); + internal::write_vtp::write_polys_tag(os,mesh,binary,offset, np); + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + internal::write_vtp::write_polys_points(os,mesh, np); + internal::write_vtp::write_polys(os,mesh, np); + } + os << "\n"; +} + +/*! \ingroup PkgBGLIOFct + * Overload that implements the default arguments + * + * Calls `write_vtp(os, mesh, mode, parameters::all_default())`. + */ +template +void write_vtp(std::ostream& os, + const TriangleMesh& mesh, + IO::Mode mode = IO::BINARY) +{ + write_vtp(os, mesh, mode, CGAL::parameters::all_default()); +} + } // namespace CGAL #endif // CGAL_BOOST_GRAPH_IO_H diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index f98c94b84a4..4ad6bfb5279 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -66,7 +66,8 @@ Release date: March 2019 - Added 3 functions for writing in XML VTK formats: - `CGAL::output_to_vtu()` - `CGAL::write_VTU()` - - `CGAL::write_VTP()` + - `CGAL::write_vtp()`, that writes a triangulated face graph in a + `.vtp` file. ### CGAL and the Boost Graph Library (BGL) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index 2eebc0ce1f1..24eca7c80e1 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include @@ -329,7 +329,7 @@ public: std::ofstream os(output_filename.data()); os << std::setprecision(16); //write header - CGAL::write_VTP(os, *mesh); + CGAL::write_vtp(os, *mesh); } } else From 1754057d24051840948b3e8633519596fbd85f5c Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 16 Jan 2019 16:50:45 +0100 Subject: [PATCH 28/47] My changes to write_vtu --- .../Constrained_Delaunay_triangulation_2.cpp | 4 ++-- Installation/CHANGES.md | 4 ++-- .../doc/Mesh_2/CGAL/IO/{vtk_io_2.h => write_vtu.h} | 12 ++++++------ Mesh_2/doc/Mesh_2/PackageDescription.txt | 9 ++++++++- Mesh_2/include/CGAL/IO/{vtk_io_2.h => write_vtu.h} | 7 ++++--- 5 files changed, 22 insertions(+), 14 deletions(-) rename Mesh_2/doc/Mesh_2/CGAL/IO/{vtk_io_2.h => write_vtu.h} (70%) rename Mesh_2/include/CGAL/IO/{vtk_io_2.h => write_vtu.h} (98%) diff --git a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp index efec041a6f3..3285004ecb1 100644 --- a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp +++ b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include // Qt headers #include @@ -676,7 +676,7 @@ MainWindow::saveConstraints(QString fileName) output << cdt; else if (output) { - CGAL::write_VTU(output, cdt); + CGAL::write_vtu(output, cdt); } } diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index 4ad6bfb5279..fe1fc7a4366 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -64,8 +64,8 @@ Release date: March 2019 ### 2D and 3D Mesh Generation - Added 3 functions for writing in XML VTK formats: - - `CGAL::output_to_vtu()` - - `CGAL::write_VTU()` + - `CGAL::output_to_vtu()`, + - `CGAL::write_vtu()`, that writes a 2D mesh in a `.vtu` file, - `CGAL::write_vtp()`, that writes a triangulated face graph in a `.vtp` file. diff --git a/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h b/Mesh_2/doc/Mesh_2/CGAL/IO/write_vtu.h similarity index 70% rename from Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h rename to Mesh_2/doc/Mesh_2/CGAL/IO/write_vtu.h index c86692d761b..471e824389d 100644 --- a/Mesh_2/doc/Mesh_2/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/doc/Mesh_2/CGAL/IO/write_vtu.h @@ -1,19 +1,19 @@ namespace CGAL{ -//!\ingroup PkgMesh2 +//!\ingroup PkgMesh2IO //! \brief writes the faces of a domain and its constrained edges embedded in //! a 2D constrained Delaunay triangulation using the `PolyData` XML format. //! //! The faces output are those for which `DelaunayMeshFaceBase_2::is_in_domain()` returns `true`, -//! the edges are those for which `ConstrainedTriangulationFaceBase_2::is_constained()` returns `true`. +//! the edges are those for which `ConstrainedTriangulationFaceBase_2::is_constrained()` returns `true`. //! \tparam CDT a `Constrained_Delaunay_triangulation_2` with face type model of `DelaunayMeshFaceBase_2`. //! //! \param os the stream used for writting. //! \param tr the triangulated domain to be written. -//! \param binary decides if the data should be written in binary (`true`) -//! or in ASCII (`false`). +//! \param mode decides if the data should be written in binary (`IO::BINARY`) +//! or in ASCII (`IO::ASCII`). //! template -void write_VTU(std::ostream& os, +void write_vtu(std::ostream& os, const CDT& tr, - bool binary = true); + IO::Mode mode = IO::BINARY); } diff --git a/Mesh_2/doc/Mesh_2/PackageDescription.txt b/Mesh_2/doc/Mesh_2/PackageDescription.txt index 38289e92ef8..313f3901185 100644 --- a/Mesh_2/doc/Mesh_2/PackageDescription.txt +++ b/Mesh_2/doc/Mesh_2/PackageDescription.txt @@ -11,6 +11,11 @@ /// \defgroup PkgMesh2Enum Enumerations /// \ingroup PkgMesh2Ref +/// \defgroup PkgMesh2IO I/O Functions +/// \ingroup PkgMesh2Ref +/// In addition to the stream extraction and insertion operators for +/// %CGAL 2D triangulations, the following functions can be used. + /*! \addtogroup PkgMesh2Ref \cgalPkgDescriptionBegin{2D Conforming Triangulations and Meshes,PkgMesh2} @@ -57,7 +62,9 @@ The package can handle intersecting input constraints and set no restriction on - `CGAL::make_conforming_Gabriel_2` - `CGAL::refine_Delaunay_mesh_2` - `CGAL::lloyd_optimize_mesh_2` -- `CGAL::write_VTU()` + +## I/O Functions ## +- `CGAL::write_vtu()` ## Enumerations ## - `CGAL::Mesh_optimization_return_code` diff --git a/Mesh_2/include/CGAL/IO/vtk_io_2.h b/Mesh_2/include/CGAL/IO/write_vtu.h similarity index 98% rename from Mesh_2/include/CGAL/IO/vtk_io_2.h rename to Mesh_2/include/CGAL/IO/write_vtu.h index 160e383bcf6..155e147ec7c 100644 --- a/Mesh_2/include/CGAL/IO/vtk_io_2.h +++ b/Mesh_2/include/CGAL/IO/write_vtu.h @@ -275,9 +275,9 @@ write_points(std::ostream& os, template -void write_VTU(std::ostream& os, - const CDT& tr, - bool binary = true) +void write_vtu(std::ostream& os, + const CDT& tr, + IO::Mode mode = IO::BINARY) { typedef typename CDT::Vertex_handle Vertex_handle; std::map V; @@ -309,6 +309,7 @@ void write_VTU(std::ostream& os, os << " \n"; std::size_t offset = 0; + const bool binary = (mode == IO::BINARY); write_points_tag(os,tr,V,binary,offset); write_cells_tag_2(os,tr,number_of_triangles, V,binary,offset); os << " \n" From c1d4608665caf1171849a67a4bacdce990989603 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 16 Jan 2019 16:59:08 +0100 Subject: [PATCH 29/47] My changes to output_to_vtu --- Mesh_2/include/CGAL/IO/write_vtu.h | 6 +++--- Mesh_3/doc/Mesh_3/CGAL/IO/{vtk_io.h => output_to_vtu.h} | 8 ++++---- Mesh_3/include/CGAL/IO/{vtk_io.h => output_to_vtu.h} | 9 +++++---- Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) rename Mesh_3/doc/Mesh_3/CGAL/IO/{vtk_io.h => output_to_vtu.h} (66%) rename Mesh_3/include/CGAL/IO/{vtk_io.h => output_to_vtu.h} (98%) diff --git a/Mesh_2/include/CGAL/IO/write_vtu.h b/Mesh_2/include/CGAL/IO/write_vtu.h index 155e147ec7c..15a3813e221 100644 --- a/Mesh_2/include/CGAL/IO/write_vtu.h +++ b/Mesh_2/include/CGAL/IO/write_vtu.h @@ -21,8 +21,8 @@ // // Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno -#ifndef CGAL_VTK_IO_H -#define CGAL_VTK_IO_H +#ifndef CGAL_WRITE_VTU_H +#define CGAL_WRITE_VTU_H #include #include @@ -323,4 +323,4 @@ void write_vtu(std::ostream& os, } } //end CGAL -#endif // CGAL_VTK_IO_H +#endif // CGAL_WRITE_VTU_H diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h b/Mesh_3/doc/Mesh_3/CGAL/IO/output_to_vtu.h similarity index 66% rename from Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h rename to Mesh_3/doc/Mesh_3/CGAL/IO/output_to_vtu.h index 63c44a13a64..7cd634d987c 100644 --- a/Mesh_3/doc/Mesh_3/CGAL/IO/vtk_io.h +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/output_to_vtu.h @@ -1,5 +1,5 @@ namespace CGAL{ -//! \ingroup PkgMesh_3IOFunctions +//! \ingroup PkgMesh3IOFunctions //! //! \brief writes a tetrahedron mesh using the `UnstructuredGrid` XML format. //! @@ -7,11 +7,11 @@ namespace CGAL{ //! //! \param os the stream used for writting. //! \param c3t3 the instance of `C3T3` to be written. -//! \param binary decides if the data should be written in binary (`true`) -//! or in ASCII (`false`). +//! \param mode decides if the data should be written in binary (`IO::BINARY`) +//! or in ASCII (`IO::ASCII`). //! template void output_to_vtu(std::ostream& os, const C3T3& c3t3, - bool binary = true); + IO::Mode mode = IO::BINARY); } diff --git a/Mesh_3/include/CGAL/IO/vtk_io.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h similarity index 98% rename from Mesh_3/include/CGAL/IO/vtk_io.h rename to Mesh_3/include/CGAL/IO/output_to_vtu.h index 182a8b2cb7d..37ec370ea3b 100644 --- a/Mesh_3/include/CGAL/IO/vtk_io.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -20,8 +20,8 @@ // // Author(s) : Laurent RINEAU, Stephane Tayeb, Maxime Gimeno -#ifndef CGAL_VTK_IO_H -#define CGAL_VTK_IO_H +#ifndef CGAL_OUTPUT_TO_VTU_H +#define CGAL_OUTPUT_TO_VTU_H #include @@ -257,8 +257,8 @@ write_attributes(std::ostream& os, //public API template void output_to_vtu(std::ostream& os, - const C3T3& c3t3, - bool binary = true) + const C3T3& c3t3, + IO::Mode mode = IO::BINARY) { typedef typename C3T3::Triangulation Tr; typedef typename Tr::Vertex_handle Vertex_handle; @@ -284,6 +284,7 @@ void output_to_vtu(std::ostream& os, os << " \n"; std::size_t offset = 0; + const bool binary = (mode == IO::BINARY); write_points_tag(os,tr,V,binary,offset); write_cells_tag(os,c3t3,V,binary,offset); std::vector mids; diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index 24eca7c80e1..f91da4aaf92 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include From 11db055bfe116c2783808fb5023db3e0fc6132b4 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 16 Jan 2019 17:16:40 +0100 Subject: [PATCH 30/47] Modify CHANGES.md Split the changes into two different paragraphs (2D/3D meshes, and BGL). --- Installation/CHANGES.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index fe1fc7a4366..9a50868e0ef 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -63,15 +63,17 @@ Release date: March 2019 `Arr_polycurve_basic_traits_2`. ### 2D and 3D Mesh Generation -- Added 3 functions for writing in XML VTK formats: - - `CGAL::output_to_vtu()`, + +- Added two functions for writing in XML VTK formats: - `CGAL::write_vtu()`, that writes a 2D mesh in a `.vtu` file, - - `CGAL::write_vtp()`, that writes a triangulated face graph in a - `.vtp` file. + - `CGAL::output_to_vtu()`, that writes a 3D mesh in a `.vtu` file. ### CGAL and the Boost Graph Library (BGL) -- Add function `write_wrl()` for writing into VRML 2.0 format. +- Added function `write_wrl()` for writing into VRML 2.0 format. +- Added functions `CGAL::write_vtp()` for writing a triangulated + face graph in a `.vtp` file (XML VTK format). + Release 4.13 ------------ From 06b973b5348e63ccb630624f69347a282b47fbe2 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 16 Jan 2019 17:17:13 +0100 Subject: [PATCH 31/47] Update the Doxygen link --- BGL/doc/BGL/PackageDescription.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BGL/doc/BGL/PackageDescription.txt b/BGL/doc/BGL/PackageDescription.txt index 2ae5f33bd19..a3b67ca990c 100644 --- a/BGL/doc/BGL/PackageDescription.txt +++ b/BGL/doc/BGL/PackageDescription.txt @@ -708,8 +708,8 @@ user might encounter. ## I/O Functions ## - \link PkgBGLIOFct CGAL::read_off() \endlink - \link PkgBGLIOFct CGAL::write_off() \endlink -- \link PkgBGLIOFct CGAL::write_vtp() \endlink - \link PkgBGLIOFct CGAL::write_wrl() \endlink +- `CGAL::write_vtp()` */ From eadb08d976161381dd80a1d2b1984bd8ac4d77cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 17 Jan 2019 15:43:42 +0100 Subject: [PATCH 32/47] replace mode by a np --- BGL/doc/BGL/NamedParameters.txt | 7 +++++++ BGL/include/CGAL/boost/graph/io.h | 20 +++++++------------ .../CGAL/boost/graph/parameters_interface.h | 1 + BGL/test/BGL/test_cgal_bgl_named_params.cpp | 3 +++ Mesh_2/doc/Mesh_2/CGAL/IO/write_vtu.h | 2 +- Mesh_3/doc/Mesh_3/CGAL/IO/output_to_vtu.h | 2 +- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/BGL/doc/BGL/NamedParameters.txt b/BGL/doc/BGL/NamedParameters.txt index f775e26ce48..ce3be60f8f4 100644 --- a/BGL/doc/BGL/NamedParameters.txt +++ b/BGL/doc/BGL/NamedParameters.txt @@ -81,6 +81,13 @@ being marked or not.\n Default: a default property map where no edge is constrained \cgalNPEnd +\cgalNPBegin{use_binary_mode} \anchor BGL_use_binary_mode +is a Boolean indicating whether the binary mode or the ASCII mode should be used +when writing data into a stream.\n +Type: `bool`\n +Default: Function specific. +\cgalNPEnd + \cgalNPBegin{METIS_options} \anchor BGL_METIS_options is a parameter used in `partition_graph()` and `partition_dual_graph()` to pass options to the METIS graph partitioner. The many options of METIS diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index 11a2b60ce0c..cb5c8082b21 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -611,14 +611,15 @@ write_polys_points(std::ostream& os, * \tparam TriangleMesh a model of `FaceListGraph` with only triangle faces. * \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" * - * \param os the stream used for writting. + * \param os the stream used for writing. * \param mesh the triangle mesh to be written. - * \param mode decides if the data should be written in binary (`IO::BINARY`) - * or in ASCII (`IO::ASCII`). `IO::BINARY` is the default. * \param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the * ones listed below * * \cgalNamedParamsBegin + * \cgalParamBegin{use_binary_mode} a Boolean indicating if the + * data should be written in binary (`true`, the default) or in ASCII (`false`). + * \cgalParamEnd * \cgalParamBegin{vertex_point_map} the property map with the points associated to * the vertices of `mesh`. If this parameter is omitted, an internal property map for * `CGAL::vertex_point_t` must be available in `TriangleMesh`. @@ -633,7 +634,6 @@ template void write_vtp(std::ostream& os, const TriangleMesh& mesh, - IO::Mode mode, const NamedParameters& np) { os << "\n" @@ -654,7 +654,7 @@ void write_vtp(std::ostream& os, os << " \n"; std::size_t offset = 0; - const bool binary = (mode == IO::BINARY); + const bool binary = boost::choose_param(boost::get_param(np, internal_np::use_binary_mode), true); internal::write_vtp::write_points_tag(os,mesh,binary,offset, np); internal::write_vtp::write_polys_tag(os,mesh,binary,offset, np); os << " \n" @@ -667,17 +667,11 @@ void write_vtp(std::ostream& os, os << "\n"; } -/*! \ingroup PkgBGLIOFct - * Overload that implements the default arguments - * - * Calls `write_vtp(os, mesh, mode, parameters::all_default())`. - */ template void write_vtp(std::ostream& os, - const TriangleMesh& mesh, - IO::Mode mode = IO::BINARY) + const TriangleMesh& mesh) { - write_vtp(os, mesh, mode, CGAL::parameters::all_default()); + write_vtp(os, mesh, CGAL::parameters::all_default()); } } // namespace CGAL diff --git a/BGL/include/CGAL/boost/graph/parameters_interface.h b/BGL/include/CGAL/boost/graph/parameters_interface.h index 9e38eec688d..8c8d7549ab1 100644 --- a/BGL/include/CGAL/boost/graph/parameters_interface.h +++ b/BGL/include/CGAL/boost/graph/parameters_interface.h @@ -28,6 +28,7 @@ CGAL_add_named_parameter(edge_is_constrained_t, edge_is_constrained, edge_is_con CGAL_add_named_parameter(first_index_t, first_index, first_index) CGAL_add_named_parameter(number_of_iterations_t, number_of_iterations, number_of_iterations) CGAL_add_named_parameter(verbosity_level_t, verbosity_level, verbosity_level) +CGAL_add_named_parameter(use_binary_mode_t, use_binary_mode, use_binary_mode) CGAL_add_named_parameter(metis_options_t, METIS_options, METIS_options) CGAL_add_named_parameter(vertex_partition_id_t, vertex_partition_id, vertex_partition_id_map) diff --git a/BGL/test/BGL/test_cgal_bgl_named_params.cpp b/BGL/test/BGL/test_cgal_bgl_named_params.cpp index 71cf1369565..346043ff037 100644 --- a/BGL/test/BGL/test_cgal_bgl_named_params.cpp +++ b/BGL/test/BGL/test_cgal_bgl_named_params.cpp @@ -102,6 +102,7 @@ void test(const NamedParameters& np) assert(get_param(np, CGAL::internal_np::weight_calculator).v == 39); assert(get_param(np, CGAL::internal_np::preserve_genus).v == 40); assert(get_param(np, CGAL::internal_np::verbosity_level).v == 41); + assert(get_param(np, CGAL::internal_np::use_binary_mode).v == 51); assert(get_param(np, CGAL::internal_np::projection_functor).v == 42); assert(get_param(np, CGAL::internal_np::apply_per_connected_component).v == 46); assert(get_param(np, CGAL::internal_np::output_iterator).v == 47); @@ -182,6 +183,7 @@ void test(const NamedParameters& np) check_same_type<39>(get_param(np, CGAL::internal_np::weight_calculator)); check_same_type<40>(get_param(np, CGAL::internal_np::preserve_genus)); check_same_type<41>(get_param(np, CGAL::internal_np::verbosity_level)); + check_same_type<51>(get_param(np, CGAL::internal_np::use_binary_mode)); check_same_type<42>(get_param(np, CGAL::internal_np::projection_functor)); check_same_type<46>(get_param(np, CGAL::internal_np::apply_per_connected_component)); check_same_type<47>(get_param(np, CGAL::internal_np::output_iterator)); @@ -241,6 +243,7 @@ int main() .weight_calculator(A<39>(39)) .preserve_genus(A<40>(40)) .verbosity_level(A<41>(41)) + .use_binary_mode(A<51>(51)) .projection_functor(A<42>(42)) .throw_on_self_intersection(A<43>(43)) .clip_volume(A<44>(44)) diff --git a/Mesh_2/doc/Mesh_2/CGAL/IO/write_vtu.h b/Mesh_2/doc/Mesh_2/CGAL/IO/write_vtu.h index 471e824389d..146cb6bb785 100644 --- a/Mesh_2/doc/Mesh_2/CGAL/IO/write_vtu.h +++ b/Mesh_2/doc/Mesh_2/CGAL/IO/write_vtu.h @@ -7,7 +7,7 @@ namespace CGAL{ //! the edges are those for which `ConstrainedTriangulationFaceBase_2::is_constrained()` returns `true`. //! \tparam CDT a `Constrained_Delaunay_triangulation_2` with face type model of `DelaunayMeshFaceBase_2`. //! -//! \param os the stream used for writting. +//! \param os the stream used for writing. //! \param tr the triangulated domain to be written. //! \param mode decides if the data should be written in binary (`IO::BINARY`) //! or in ASCII (`IO::ASCII`). diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/output_to_vtu.h b/Mesh_3/doc/Mesh_3/CGAL/IO/output_to_vtu.h index 7cd634d987c..70a64f586c7 100644 --- a/Mesh_3/doc/Mesh_3/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/output_to_vtu.h @@ -5,7 +5,7 @@ namespace CGAL{ //! //! \tparam C3T3 a model of `MeshComplexWithFeatures_3InTriangulation_3`. //! -//! \param os the stream used for writting. +//! \param os the stream used for writing. //! \param c3t3 the instance of `C3T3` to be written. //! \param mode decides if the data should be written in binary (`IO::BINARY`) //! or in ASCII (`IO::ASCII`). From dbd569d51c2b8ddc8c1f013059cba0c1280d854e Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 17 Jan 2019 18:29:27 +0100 Subject: [PATCH 33/47] Fix the result of check_headers --- Mesh_2/include/CGAL/IO/write_vtu.h | 9 ++++++--- Mesh_3/include/CGAL/IO/output_to_vtu.h | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Mesh_2/include/CGAL/IO/write_vtu.h b/Mesh_2/include/CGAL/IO/write_vtu.h index 15a3813e221..e2a5b71b911 100644 --- a/Mesh_2/include/CGAL/IO/write_vtu.h +++ b/Mesh_2/include/CGAL/IO/write_vtu.h @@ -24,11 +24,14 @@ #ifndef CGAL_WRITE_VTU_H #define CGAL_WRITE_VTU_H -#include -#include - #include +#include +#include +#include +#include +#include +#include //todo try to factorize with functors namespace CGAL{ diff --git a/Mesh_3/include/CGAL/IO/output_to_vtu.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h index 37ec370ea3b..7e802343cfe 100644 --- a/Mesh_3/include/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -26,8 +26,11 @@ #include -#include +#include #include +#include +#include +#include #include //todo try to factorize with functors From 8f658695f81de2f0afb13c2679b0561c713904f6 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 21 Jan 2019 16:17:28 +0100 Subject: [PATCH 34/47] Rename internal methods to avoid a namespace class There was two methods named `CGAL::write_points_tag`. I renamed then to: - `write_c3t3_points_tag`, and - `write_cdt_points_tag`. --- Mesh_2/include/CGAL/IO/write_vtu.h | 12 ++++++------ Mesh_3/include/CGAL/IO/output_to_vtu.h | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Mesh_2/include/CGAL/IO/write_vtu.h b/Mesh_2/include/CGAL/IO/write_vtu.h index e2a5b71b911..4af962fba72 100644 --- a/Mesh_2/include/CGAL/IO/write_vtu.h +++ b/Mesh_2/include/CGAL/IO/write_vtu.h @@ -206,11 +206,11 @@ write_cells_2(std::ostream& os, // writes the points tags before binary data is appended template void -write_points_tag(std::ostream& os, - const Tr & tr, - std::map & V, - bool binary, - std::size_t& offset) +write_cdt_points_tag(std::ostream& os, + const Tr & tr, + std::map & V, + bool binary, + std::size_t& offset) { std::size_t dim = 2; typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; @@ -313,7 +313,7 @@ void write_vtu(std::ostream& os, << "\" NumberOfCells=\"" << number_of_triangles + std::distance(tr.constrained_edges_begin(), tr.constrained_edges_end()) << "\">\n"; std::size_t offset = 0; const bool binary = (mode == IO::BINARY); - write_points_tag(os,tr,V,binary,offset); + write_cdt_points_tag(os,tr,V,binary,offset); write_cells_tag_2(os,tr,number_of_triangles, V,binary,offset); os << " \n" << " \n"; diff --git a/Mesh_3/include/CGAL/IO/output_to_vtu.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h index 7e802343cfe..369a0d45a47 100644 --- a/Mesh_3/include/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -150,11 +150,11 @@ write_cells(std::ostream& os, template void -write_points_tag(std::ostream& os, - const Tr & tr, - std::map & V, - bool binary, - std::size_t& offset) +write_c3t3_points_tag(std::ostream& os, + const Tr & tr, + std::map & V, + bool binary, + std::size_t& offset) { std::size_t dim = 3; typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; @@ -288,7 +288,7 @@ void output_to_vtu(std::ostream& os, << "\" NumberOfCells=\"" << c3t3.number_of_cells() << "\">\n"; std::size_t offset = 0; const bool binary = (mode == IO::BINARY); - write_points_tag(os,tr,V,binary,offset); + write_c3t3_points_tag(os,tr,V,binary,offset); write_cells_tag(os,c3t3,V,binary,offset); std::vector mids; os << " Date: Mon, 21 Jan 2019 16:32:37 +0100 Subject: [PATCH 35/47] Rename two write_points functions as well --- Mesh_2/include/CGAL/IO/write_vtu.h | 10 +++++----- Mesh_3/include/CGAL/IO/output_to_vtu.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Mesh_2/include/CGAL/IO/write_vtu.h b/Mesh_2/include/CGAL/IO/write_vtu.h index 4af962fba72..9580d434b49 100644 --- a/Mesh_2/include/CGAL/IO/write_vtu.h +++ b/Mesh_2/include/CGAL/IO/write_vtu.h @@ -252,10 +252,10 @@ write_cdt_points_tag(std::ostream& os, // writes the points appended data at the end of the .vtu file template void -write_points(std::ostream& os, - const Tr & tr, - std::map & V) +write_cdt_points(std::ostream& os, + const Tr & tr, + std::map & V) { std::size_t dim = 2; typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; @@ -319,7 +319,7 @@ void write_vtu(std::ostream& os, << " \n"; if (binary) { os << "\n_"; - write_points(os,tr,V); // write points before cells to fill the std::map V + write_cdt_points(os,tr,V); // write points before cells to fill the std::map V write_cells_2(os,tr, number_of_triangles, V); } os << "\n"; diff --git a/Mesh_3/include/CGAL/IO/output_to_vtu.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h index 369a0d45a47..c5d621462c4 100644 --- a/Mesh_3/include/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -196,10 +196,10 @@ write_c3t3_points_tag(std::ostream& os, // writes the points appended data at the end of the .vtu file template void -write_points(std::ostream& os, - const Tr & tr, - std::map & V) +write_c3t3_points(std::ostream& os, + const Tr & tr, + std::map & V) { std::size_t dim = 3; typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; @@ -299,7 +299,7 @@ void output_to_vtu(std::ostream& os, << " \n"; if (binary) { os << "\n_"; - write_points(os,tr,V); // write points before cells to fill the std::map V + write_c3t3_points(os,tr,V); // write points before cells to fill the std::map V write_cells(os,c3t3,V, mids);//todo mids should be filled by write_attribute_tag write_attributes(os,mids); } From ae108c5d96a00c33cb5778fb5bcd65278c4a1764 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 21 Jan 2019 17:14:14 +0100 Subject: [PATCH 36/47] Improve comments and fix indentation --- Mesh_3/include/CGAL/IO/output_to_vtu.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Mesh_3/include/CGAL/IO/output_to_vtu.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h index c5d621462c4..ad14ca8b417 100644 --- a/Mesh_3/include/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -289,18 +289,18 @@ void output_to_vtu(std::ostream& os, std::size_t offset = 0; const bool binary = (mode == IO::BINARY); write_c3t3_points_tag(os,tr,V,binary,offset); - write_cells_tag(os,c3t3,V,binary,offset); + write_cells_tag(os,c3t3,V,binary,offset); // fills V if the mode is ASCII std::vector mids; - os << " \n"; - write_attribute_tag(os,"MeshDomain",mids,binary,offset); - os << " \n"; + os << " \n"; + write_attribute_tag(os,"MeshDomain",mids,binary,offset); + os << " \n"; os << "
\n" << " \n"; if (binary) { os << "\n_"; - write_c3t3_points(os,tr,V); // write points before cells to fill the std::map V - write_cells(os,c3t3,V, mids);//todo mids should be filled by write_attribute_tag + write_c3t3_points(os,tr,V); // fills V if the mode is BINARY + write_cells(os,c3t3,V, mids); write_attributes(os,mids); } os << "\n"; From 4d3df85cb3b02139b83ca27a4ee97f46f0d96b67 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 22 Jan 2019 10:38:48 +0100 Subject: [PATCH 37/47] Remove far points --- Mesh_3/include/CGAL/IO/output_to_vtu.h | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Mesh_3/include/CGAL/IO/output_to_vtu.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h index ad14ca8b417..5eda1cab3d3 100644 --- a/Mesh_3/include/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -152,6 +152,7 @@ template void write_c3t3_points_tag(std::ostream& os, const Tr & tr, + std::size_t size_of_vertices, std::map & V, bool binary, std::size_t& offset) @@ -171,7 +172,7 @@ write_c3t3_points_tag(std::ostream& os, if (binary) { os << "\" offset=\"" << offset << "\"/>\n"; - offset += 3 * tr.number_of_vertices() * sizeof(FT) + sizeof(std::size_t); + offset += 3 * size_of_vertices * sizeof(FT) + sizeof(std::size_t); // dim coords per points + length of the encoded data (size_t) } else { @@ -180,14 +181,15 @@ write_c3t3_points_tag(std::ostream& os, vit != tr.finite_vertices_end(); ++vit) { + if(vit->in_dimension() <= -1) continue; V[vit] = inum++; - os << vit->point()[0] << " "; - os << vit->point()[1] << " "; - if(dim == 3) - os << vit->point()[2] << " "; - else - os << 0.0 << " "; - } + os << vit->point()[0] << " "; + os << vit->point()[1] << " "; + if(dim == 3) + os << vit->point()[2] << " "; + else + os << 0.0 << " "; + } os << " \n"; } os << " \n"; @@ -212,6 +214,7 @@ write_c3t3_points(std::ostream& os, vit != tr.finite_vertices_end(); ++vit) { + if(vit->in_dimension() <= -1) continue; V[vit] = inum++; // binary output => the map has not been filled yet coordinates.push_back(vit->point()[0]); coordinates.push_back(vit->point()[1]); @@ -283,12 +286,13 @@ void output_to_vtu(std::ostream& os, } os << ">\n" << " " << "\n"; - - os << " \n"; std::size_t offset = 0; const bool binary = (mode == IO::BINARY); - write_c3t3_points_tag(os,tr,V,binary,offset); + write_c3t3_points_tag(os,tr,number_of_vertices,V,binary,offset); write_cells_tag(os,c3t3,V,binary,offset); // fills V if the mode is ASCII std::vector mids; os << " Date: Tue, 22 Jan 2019 12:03:05 +0100 Subject: [PATCH 38/47] Fix "\n"; write_attribute_tag(os,"MeshDomain",mids,binary,offset); os << " \n"; From a57db0bac4cfffb97f421025de17996f2cc74d29 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 22 Jan 2019 12:20:53 +0100 Subject: [PATCH 39/47] Fix the filling of 'mids' --- Mesh_3/include/CGAL/IO/output_to_vtu.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Mesh_3/include/CGAL/IO/output_to_vtu.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h index 1b4b8ba9e15..020faeb33b7 100644 --- a/Mesh_3/include/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -124,8 +124,7 @@ template void write_cells(std::ostream& os, const C3T3 & c3t3, - std::map & V, - std::vector& mids) + std::map & V) { typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; std::vector connectivity_table; @@ -140,7 +139,6 @@ write_cells(std::ostream& os, offsets.push_back(off); for (int i=0; i<4; i++) connectivity_table.push_back(V[cit->vertex(i)]); - mids.push_back(cit->subdomain_index()); } write_vector(os,connectivity_table); write_vector(os,offsets); @@ -294,7 +292,15 @@ void output_to_vtu(std::ostream& os, const bool binary = (mode == IO::BINARY); write_c3t3_points_tag(os,tr,number_of_vertices,V,binary,offset); write_cells_tag(os,c3t3,V,binary,offset); // fills V if the mode is ASCII - std::vector mids; + + std::vector mids; + mids.reserve(c3t3.number_of_cells_in_complex()); + for( typename C3T3::Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) { + mids.push_back(cit->subdomain_index()); + } + os << " \n"; write_attribute_tag(os,"MeshDomain",mids,binary,offset); @@ -304,7 +310,7 @@ void output_to_vtu(std::ostream& os, if (binary) { os << "\n_"; write_c3t3_points(os,tr,V); // fills V if the mode is BINARY - write_cells(os,c3t3,V, mids); + write_cells(os,c3t3,V); write_attributes(os,mids); } os << "\n"; From 1ce8c87b64316d41c75c2937ea8a56e59de33f3a Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 25 Jan 2019 13:45:43 +0100 Subject: [PATCH 40/47] Add a function that writes a vtu from a c3t3 and a list of attributes --- Mesh_3/include/CGAL/IO/output_to_vtu.h | 51 ++++++++++++++++++-------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/Mesh_3/include/CGAL/IO/output_to_vtu.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h index 020faeb33b7..9a2be82e1b4 100644 --- a/Mesh_3/include/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -258,11 +258,11 @@ write_attributes(std::ostream& os, write_vector(os,att); } -//public API template -void output_to_vtu(std::ostream& os, - const C3T3& c3t3, - IO::Mode mode = IO::BINARY) +void output_to_vtu_with_attributes(std::ostream& os, + const C3T3& c3t3, + std::vector*> >& attributes, + IO::Mode mode = IO::BINARY) { typedef typename C3T3::Triangulation Tr; typedef typename Tr::Vertex_handle Vertex_handle; @@ -289,21 +289,16 @@ void output_to_vtu(std::ostream& os, os << " \n"; std::size_t offset = 0; + + const bool binary = (mode == IO::BINARY); write_c3t3_points_tag(os,tr,number_of_vertices,V,binary,offset); write_cells_tag(os,c3t3,V,binary,offset); // fills V if the mode is ASCII - - std::vector mids; - mids.reserve(c3t3.number_of_cells_in_complex()); - for( typename C3T3::Cell_iterator cit = c3t3.cells_in_complex_begin() ; - cit != c3t3.cells_in_complex_end() ; - ++cit ) { - mids.push_back(cit->subdomain_index()); + os << " \n"; + for(std::size_t i = 0; i< attributes.size(); ++i) + { + write_attribute_tag(os,attributes[i].first, *attributes[i].second, binary,offset); } - - os << " \n"; - write_attribute_tag(os,"MeshDomain",mids,binary,offset); os << " \n"; os << " \n" << " \n"; @@ -311,10 +306,34 @@ void output_to_vtu(std::ostream& os, os << "\n_"; write_c3t3_points(os,tr,V); // fills V if the mode is BINARY write_cells(os,c3t3,V); - write_attributes(os,mids); + for(std::size_t i = 0; i< attributes.size(); ++i) + write_attributes(os, *attributes[i].second); } os << "\n"; } + + +//public API +template +void output_to_vtu(std::ostream& os, + const C3T3& c3t3, + IO::Mode mode = IO::BINARY) +{ + typedef typename C3T3::Triangulation Tr; + typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; + typedef typename Tr::Vertex_handle Vertex_handle; + std::vector mids; + for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; + cit != c3t3.cells_in_complex_end() ; + ++cit ) + { + mids.push_back(cit->subdomain_index()); + } + std::vector* > > atts; + atts.push_back(std::make_pair("MeshDomain", &mids)); + output_to_vtu_with_attributes(os, c3t3, atts, mode); +} + } //end CGAL #endif // CGAL_VTK_IO_H From 06b42de0558863a9158a6973dbcfcf56dbea2a93 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 25 Jan 2019 14:43:58 +0100 Subject: [PATCH 41/47] Fixes --- Mesh_3/include/CGAL/IO/output_to_vtu.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Mesh_3/include/CGAL/IO/output_to_vtu.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h index 9a2be82e1b4..e1f67ec3b33 100644 --- a/Mesh_3/include/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -261,7 +261,7 @@ write_attributes(std::ostream& os, template void output_to_vtu_with_attributes(std::ostream& os, const C3T3& c3t3, - std::vector*> >& attributes, + std::vector*> >& attributes, IO::Mode mode = IO::BINARY) { typedef typename C3T3::Triangulation Tr; @@ -289,12 +289,11 @@ void output_to_vtu_with_attributes(std::ostream& os, os << " \n"; std::size_t offset = 0; - - + const bool binary = (mode == IO::BINARY); write_c3t3_points_tag(os,tr,number_of_vertices,V,binary,offset); write_cells_tag(os,c3t3,V,binary,offset); // fills V if the mode is ASCII - os << " \n"; + os << " \n"; for(std::size_t i = 0; i< attributes.size(); ++i) { write_attribute_tag(os,attributes[i].first, *attributes[i].second, binary,offset); From b812f333a0e5f2124c077100b584a086e5d3c9a1 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 25 Jan 2019 15:04:37 +0100 Subject: [PATCH 42/47] Dont export far points when converting to vtkUnstructuredGrid --- .../CGAL/IO/Complex_3_in_triangulation_3_to_vtk.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Mesh_3/include/CGAL/IO/Complex_3_in_triangulation_3_to_vtk.h b/Mesh_3/include/CGAL/IO/Complex_3_in_triangulation_3_to_vtk.h index 8b9cd7e7520..8370bab261f 100644 --- a/Mesh_3/include/CGAL/IO/Complex_3_in_triangulation_3_to_vtk.h +++ b/Mesh_3/include/CGAL/IO/Complex_3_in_triangulation_3_to_vtk.h @@ -50,7 +50,7 @@ output_c3t3_to_vtk_unstructured_grid(const C3T3& c3t3, vtkCellArray* const vtk_facets = vtkCellArray::New(); vtkCellArray* const vtk_cells = vtkCellArray::New(); - vtk_points->Allocate(c3t3.triangulation().number_of_vertices()); + vtk_points->Allocate(c3t3.triangulation().number_of_vertices()- c3t3.number_of_far_points()); vtk_facets->Allocate(c3t3.number_of_facets_in_complex()); vtk_cells->Allocate(c3t3.number_of_cells_in_complex()); @@ -64,11 +64,14 @@ output_c3t3_to_vtk_unstructured_grid(const C3T3& c3t3, ++vit) { typedef typename Triangulation::Weighted_point Weighted_point; - const Weighted_point& p = tr.point(vit); - vtk_points->InsertNextPoint(CGAL::to_double(p.x()), - CGAL::to_double(p.y()), - CGAL::to_double(p.z())); - V[vit] = inum++; + if(vit->in_dimension() > -1) + { + const Weighted_point& p = tr.point(vit); + vtk_points->InsertNextPoint(CGAL::to_double(p.x()), + CGAL::to_double(p.y()), + CGAL::to_double(p.z())); + V[vit] = inum++; + } } for(typename C3T3::Facets_in_complex_iterator fit = c3t3.facets_in_complex_begin(), From e456d29abfa671252ac409fc7ccc31b72bfee724 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 25 Jan 2019 16:10:03 +0100 Subject: [PATCH 43/47] WIP write_vtu_with_attributes --- Mesh_2/include/CGAL/IO/write_vtu.h | 93 ++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/Mesh_2/include/CGAL/IO/write_vtu.h b/Mesh_2/include/CGAL/IO/write_vtu.h index 9580d434b49..15aeb489e8c 100644 --- a/Mesh_2/include/CGAL/IO/write_vtu.h +++ b/Mesh_2/include/CGAL/IO/write_vtu.h @@ -276,6 +276,99 @@ write_cdt_points(std::ostream& os, write_vector(os,coordinates); } +// writes the attribute tags before binary data is appended +template +void +write_attribute_tag_2 (std::ostream& os, + const std::string& attr_name, + const std::vector& attribute, + bool binary, + std::size_t& offset) +{ + std::string format = binary ? "appended" : "ascii"; + std::string type = (sizeof(T) == 8) ? "Float64" : "Float32"; + os << " \n"; + offset += attribute.size() * sizeof(T) + sizeof(std::size_t); + } + else { + typedef typename std::vector::const_iterator Iterator; + os << "\">\n"; + for (Iterator it = attribute.begin(); + it != attribute.end(); + ++it ) + os << *it << " "; + os << " \n"; + } +} + +// writes the attributes appended data at the end of the .vtu file +template +void +write_attributes_2(std::ostream& os, + const std::vector& att) +{ + write_vector(os,att); +} + +template +void write_vtu_with_attributes(std::ostream& os, + const CDT& tr, + std::vector*> >& attributes, + IO::Mode mode = IO::BINARY) +{ + typedef typename CDT::Vertex_handle Vertex_handle; + std::map V; + //write header + os << "\n" + << "\n" + << " " << "\n"; + + int number_of_triangles = 0; + for(typename CDT::Finite_faces_iterator + fit = tr.finite_faces_begin(), + end = tr.finite_faces_end(); + fit != end; ++fit) + { + if(fit->is_in_domain()) ++number_of_triangles; + } + os << " \n"; + std::size_t offset = 0; + const bool binary = (mode == IO::BINARY); + write_cdt_points_tag(os,tr,V,binary,offset); + write_cells_tag_2(os,tr,number_of_triangles, V,binary,offset); + os << " \n"; + for(std::size_t i = 0; i< attributes.size(); ++i) + { + write_attribute_tag_2(os,attributes[i].first, *attributes[i].second, binary,offset); + } + os << " \n" + << " \n"; + if (binary) { + os << "\n_"; + write_cdt_points(os,tr,V); // write points before cells to fill the std::map V + write_cells_2(os,tr, number_of_triangles, V); + for(std::size_t i = 0; i< attributes.size(); ++i) + write_attributes_2(os, *attributes[i].second); + } + os << "\n"; +} + template void write_vtu(std::ostream& os, From ad300da617a09bfe934042c95f19d1ee8dd01a1f Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 30 Jan 2019 16:55:27 +0100 Subject: [PATCH 44/47] Fix write_vtu_with_argumetns --- Mesh_2/include/CGAL/IO/write_vtu.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Mesh_2/include/CGAL/IO/write_vtu.h b/Mesh_2/include/CGAL/IO/write_vtu.h index 15aeb489e8c..41534385280 100644 --- a/Mesh_2/include/CGAL/IO/write_vtu.h +++ b/Mesh_2/include/CGAL/IO/write_vtu.h @@ -357,6 +357,7 @@ void write_vtu_with_attributes(std::ostream& os, { write_attribute_tag_2(os,attributes[i].first, *attributes[i].second, binary,offset); } + os << " \n"; os << " \n" << " \n"; if (binary) { From 6cff52c485616d94cac4fd537e52a6a041a6f653 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 4 Feb 2019 09:58:47 +0100 Subject: [PATCH 45/47] write_vtu uses write_vtu_with_attributes --- Mesh_2/include/CGAL/IO/write_vtu.h | 48 ++++-------------------------- 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/Mesh_2/include/CGAL/IO/write_vtu.h b/Mesh_2/include/CGAL/IO/write_vtu.h index 41534385280..bab5d5b4c11 100644 --- a/Mesh_2/include/CGAL/IO/write_vtu.h +++ b/Mesh_2/include/CGAL/IO/write_vtu.h @@ -352,7 +352,10 @@ void write_vtu_with_attributes(std::ostream& os, const bool binary = (mode == IO::BINARY); write_cdt_points_tag(os,tr,V,binary,offset); write_cells_tag_2(os,tr,number_of_triangles, V,binary,offset); - os << " \n"; + if(attributes.empty()) + os << " \n"; + else + os << " \n"; for(std::size_t i = 0; i< attributes.size(); ++i) { write_attribute_tag_2(os,attributes[i].first, *attributes[i].second, binary,offset); @@ -376,47 +379,8 @@ void write_vtu(std::ostream& os, const CDT& tr, IO::Mode mode = IO::BINARY) { - typedef typename CDT::Vertex_handle Vertex_handle; - std::map V; - //write header - os << "\n" - << "\n" - << " " << "\n"; - - int number_of_triangles = 0; - for(typename CDT::Finite_faces_iterator - fit = tr.finite_faces_begin(), - end = tr.finite_faces_end(); - fit != end; ++fit) - { - if(fit->is_in_domain()) ++number_of_triangles; - } - os << " \n"; - std::size_t offset = 0; - const bool binary = (mode == IO::BINARY); - write_cdt_points_tag(os,tr,V,binary,offset); - write_cells_tag_2(os,tr,number_of_triangles, V,binary,offset); - os << " \n" - << " \n"; - if (binary) { - os << "\n_"; - write_cdt_points(os,tr,V); // write points before cells to fill the std::map V - write_cells_2(os,tr, number_of_triangles, V); - } - os << "\n"; + std::vector*> > dummy_atts; + write_vtu_with_attributes(os, tr, dummy_atts, mode); } } //end CGAL From dc275ec013e2a10083ba99ef323c9399617eccba Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 4 Feb 2019 15:47:07 +0100 Subject: [PATCH 46/47] Fix a warning about unused local type --- Mesh_3/include/CGAL/IO/output_to_vtu.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Mesh_3/include/CGAL/IO/output_to_vtu.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h index e1f67ec3b33..040bebd7d6c 100644 --- a/Mesh_3/include/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -319,9 +319,7 @@ void output_to_vtu(std::ostream& os, const C3T3& c3t3, IO::Mode mode = IO::BINARY) { - typedef typename C3T3::Triangulation Tr; typedef typename C3T3::Cells_in_complex_iterator Cell_iterator; - typedef typename Tr::Vertex_handle Vertex_handle; std::vector mids; for( Cell_iterator cit = c3t3.cells_in_complex_begin() ; cit != c3t3.cells_in_complex_end() ; From 37cc9b03c720a17c4a60cb317864afd8de2250fc Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 5 Feb 2019 16:42:00 +0100 Subject: [PATCH 47/47] Fix output_to_vtu --- Mesh_3/include/CGAL/IO/output_to_vtu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mesh_3/include/CGAL/IO/output_to_vtu.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h index 040bebd7d6c..5c9583ba272 100644 --- a/Mesh_3/include/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -327,7 +327,7 @@ void output_to_vtu(std::ostream& os, { mids.push_back(cit->subdomain_index()); } - std::vector* > > atts; + std::vector* > > atts; atts.push_back(std::make_pair("MeshDomain", &mids)); output_to_vtu_with_attributes(os, c3t3, atts, mode); }