From b456446e0822f77a0b3d9cc1ca8a235ada9fa8ae Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Wed, 10 Feb 2016 10:32:33 +0100 Subject: [PATCH] deal with xml and discriminate with a template parameter --- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index 728f144cc75..37171a5ac73 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 @@ -113,9 +114,9 @@ namespace CGAL{ return true; } - template - void polygon_mesh_to_vtkPolyData(const PM& pmesh, - const char* filename) //PolygonMesh + template + void polygon_mesh_to_vtkUnstructured(const PM& pmesh,//PolygonMesh + const char* filename) { typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits::face_descriptor face_descriptor; @@ -173,8 +174,8 @@ namespace CGAL{ unstructuredGrid->ShallowCopy(appendFilter->GetOutput()); // Write the unstructured grid - vtkSmartPointer writer = - vtkSmartPointer::New(); + vtkSmartPointer writer = + vtkSmartPointer::New(); writer->SetFileName(filename); writer->SetInputData(unstructuredGrid); writer->Write(); @@ -203,7 +204,8 @@ public: } bool save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) { - if (fileinfo.suffix().toLower() != "vtk") + if (fileinfo.suffix().toLower() != "vtk" + && fileinfo.suffix().toLower() != "vtp") return false; std::string output_filename = fileinfo.absoluteFilePath().toStdString(); @@ -214,9 +216,17 @@ public: if (!poly_item) return false; else - CGAL::polygon_mesh_to_vtkPolyData(*poly_item->polyhedron(), - output_filename.data()); - + { + char last_char = output_filename.back(); + if (last_char != 'p' && last_char != 'P') + CGAL::polygon_mesh_to_vtkUnstructured( + *poly_item->polyhedron(), + output_filename.data()); + else + CGAL::polygon_mesh_to_vtkUnstructured( + *poly_item->polyhedron(), + output_filename.data()); + } return true; }