From c787e40ca7a3069bbd9a3d2181f0effb51fc3626 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 18 Mar 2019 13:14:00 +0100 Subject: [PATCH] Use boost variant for attributes to be able to send `double`s, `uint_8`s and `std::size_t`s --- Mesh_3/include/CGAL/IO/output_to_vtu.h | 46 +++++++++++++++---- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 2 +- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Mesh_3/include/CGAL/IO/output_to_vtu.h b/Mesh_3/include/CGAL/IO/output_to_vtu.h index 5c9583ba272..333f6f275d4 100644 --- a/Mesh_3/include/CGAL/IO/output_to_vtu.h +++ b/Mesh_3/include/CGAL/IO/output_to_vtu.h @@ -258,12 +258,20 @@ write_attributes(std::ostream& os, write_vector(os,att); } +enum VTU_ATTRIBUTE_TYPE{ + DOUBLE=0, + UNIT_8, + SIZE_TYPE +}; + template void output_to_vtu_with_attributes(std::ostream& os, const C3T3& c3t3, - std::vector*> >& attributes, + std::vector, std::vector, std::vector >*> >& attributes, + // std::vector& attribute_types, IO::Mode mode = IO::BINARY) { + //CGAL_assertion(attributes.size() == attribute_types.size()); typedef typename C3T3::Triangulation Tr; typedef typename Tr::Vertex_handle Vertex_handle; const Tr& tr = c3t3.triangulation(); @@ -296,7 +304,17 @@ void output_to_vtu_with_attributes(std::ostream& os, os << " \n"; for(std::size_t i = 0; i< attributes.size(); ++i) { - write_attribute_tag(os,attributes[i].first, *attributes[i].second, binary,offset); + switch(attributes[i].second->which()){ + case 0: + write_attribute_tag(os,attributes[i].first, *boost::get >(attributes[i].second), binary,offset); + break; + case 1: + write_attribute_tag(os,attributes[i].first, *boost::get >(attributes[i].second), binary,offset); + break; + default: + write_attribute_tag(os,attributes[i].first, *boost::get >(attributes[i].second), binary,offset); + break; + } } os << " \n"; os << " \n" @@ -306,7 +324,17 @@ void output_to_vtu_with_attributes(std::ostream& os, write_c3t3_points(os,tr,V); // fills V if the mode is BINARY write_cells(os,c3t3,V); for(std::size_t i = 0; i< attributes.size(); ++i) - write_attributes(os, *attributes[i].second); + switch(attributes[i].second->which()){ + case 0: + write_attributes(os, *boost::get >(attributes[i].second)); + break; + case 1: + write_attributes(os, *boost::get >(attributes[i].second)); + break; + default: + write_attributes(os, *boost::get >(attributes[i].second)); + break; + } } os << "\n"; } @@ -324,11 +352,13 @@ void output_to_vtu(std::ostream& os, 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)); + { + double v = cit->subdomain_index(); + mids.push_back(v); + } + std::vector, std::vector, std::vector >* > > atts; + boost::variant, std::vector, std::vector > v = mids; + atts.push_back(std::make_pair("MeshDomain", &v)); output_to_vtu_with_attributes(os, c3t3, atts, mode); } diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index 30855054d34..514834003fb 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -318,7 +318,7 @@ public: const Scene_facegraph_item* poly_item = qobject_cast(item); - + if (poly_item) { if (extension != "vtp")