From 9f96f2a1ca1e34232e55a2bb2954c6a9f95cd424 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 26 Sep 2016 14:32:52 +0200 Subject: [PATCH] Makes the VTK_IO_plugin able to save a c3t3_item as a .ctu file. Those files can be read by ParaView, for example. --- .../demo/Polyhedron/Plugins/IO/CMakeLists.txt | 6 ++-- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 29 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt index 4f14780d4a8..016753dddc2 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt @@ -39,9 +39,9 @@ if (VTK_FOUND) if ("${VTK_VERSION_MAJOR}" GREATER "5") if(VTK_LIBRARIES) polyhedron_demo_plugin(vtk_plugin VTK_io_plugin) - target_link_libraries(vtk_plugin scene_polyhedron_item scene_polylines_item - vtkCommonCore vtkIOCore vtkIOLegacy vtkIOXML - vtkFiltersCore vtkFiltersSources) + target_link_libraries(vtk_plugin scene_polyhedron_item scene_polylines_item scene_c3t3_item + vtkCommonCore vtkIOCore vtkIOLegacy vtkIOXML + vtkFiltersCore vtkFiltersSources) else() message(STATUS "NOTICE : the vtk IO plugin needs VTK libraries and will not be compiled.") endif() diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index a9e3f4edfff..e22ab8eb8e9 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -18,6 +18,8 @@ // Jane Tournois // +#include +#include "Scene_c3t3_item.h" #include #include "Polyhedron_type.h" @@ -42,6 +44,7 @@ #include #include #include +#include #include #include @@ -66,7 +69,7 @@ #include #include #include - +#include namespace CGAL{ class ErrorObserverVtk : public vtkCommand @@ -271,17 +274,18 @@ public: typedef boost::graph_traits::face_descriptor face_descriptor; QString nameFilters() const { - return "VTK PolyData files (*.vtk);; VTK XML PolyData (*.vtp)"; } + return "VTK PolyData files (*.vtk);; VTK XML PolyData (*.vtp);; VTK XML UnstructuredGrid (*.vtu)"; } QString name() const { return "vtk_plugin"; } bool canSave(const CGAL::Three::Scene_item* item) { - return qobject_cast(item); + return (qobject_cast(item) + || qobject_cast(item)); } bool save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) { std::string extension = fileinfo.suffix().toLower().toStdString(); - if ( extension != "vtk" && extension != "vtp") + if ( extension != "vtk" && extension != "vtp" && extension != "vtu") return false; std::string output_filename = fileinfo.absoluteFilePath().toStdString(); @@ -289,9 +293,7 @@ public: const Scene_polyhedron_item* poly_item = qobject_cast(item); - if (!poly_item) - return false; - else + if (poly_item) { if (extension != "vtp") CGAL::polygon_mesh_to_vtkUnstructured( @@ -302,6 +304,19 @@ public: *poly_item->polyhedron(), output_filename.data()); } + else + { + const Scene_c3t3_item* c3t3_item = + 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(); + } return true; }