diff --git a/example/IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx b/example/IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx index 2236c9e13d..a16e54130d 100644 --- a/example/IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx +++ b/example/IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx @@ -22,6 +22,7 @@ along with t8code; if not, write to the Free Software Foundation, Inc., #include #include #include + #include #include diff --git a/src/Makefile.am b/src/Makefile.am index 4b1c1a32ac..01610da342 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,7 @@ forestincludedir = $(includedir)/t8_forest geometryincludedir = $(includedir)/t8_geometry geometryimplincludedir = $(geometryincludedir)/t8_geometry_implementations schemesdefaultincludedir = $(includedir)/t8_schemes/t8_default +vtkincludedir = $(includedir)/t8_vtk defaultcommonincludedir = $(schemesdefaultincludedir)/t8_default_common defaultvertexincludedir = $(schemesdefaultincludedir)/t8_default_vertex defaultlineincludedir = $(schemesdefaultincludedir)/t8_default_line @@ -64,6 +65,9 @@ libt8_installed_headers_geometry_impl = \ src/t8_geometry/t8_geometry_implementations/t8_geometry_occ.hxx \ src/t8_geometry/t8_geometry_implementations/t8_geometry_linear.hxx \ src/t8_geometry/t8_geometry_implementations/t8_geometry_zero.hxx +libt8_installed_headers_vtk = \ + src/t8_vtk/t8_vtk_reader.hxx \ + src/t8_vtk/t8_vtk_types.h libt8_installed_headers_schemes_default = libt8_installed_headers_default_common = libt8_installed_headers_default_vertex = @@ -81,8 +85,6 @@ libt8_internal_headers = \ src/t8_cmesh/t8_cmesh_offset.h \ src/t8_vtk/t8_vtk_polydata.hxx \ src/t8_vtk/t8_vtk_unstructured.hxx \ - src/t8_vtk/t8_vtk_reader.hxx \ - src/t8_vtk/t8_vtk_types.h \ src/t8_forest/t8_forest_cxx.h \ src/t8_forest/t8_forest_ghost.h \ src/t8_forest/t8_forest_balance.h src/t8_forest/t8_forest_types.h \ @@ -151,6 +153,7 @@ dist_forestinclude_HEADERS = $(libt8_installed_headers_forest) dist_geometryinclude_HEADERS = $(libt8_installed_headers_geometry) dist_geometryimplinclude_HEADERS = $(libt8_installed_headers_geometry_impl) dist_schemesdefaultinclude_HEADERS = $(libt8_installed_headers_schemes_default) +dist_vtkinclude_HEADERS = $(libt8_installed_headers_vtk) dist_defaultcommoninclude_HEADERS = $(libt8_installed_headers_default_common) dist_defaultvertexinclude_HEADERS = $(libt8_installed_headers_default_vertex) dist_defaultlineinclude_HEADERS = $(libt8_installed_headers_default_line) diff --git a/src/t8_vtk/t8_vtk_reader.cxx b/src/t8_vtk/t8_vtk_reader.cxx index 4d96767d01..a2339efb3c 100644 --- a/src/t8_vtk/t8_vtk_reader.cxx +++ b/src/t8_vtk/t8_vtk_reader.cxx @@ -31,6 +31,7 @@ along with t8code; if not, write to the Free Software Foundation, Inc., #if T8_WITH_VTK #include #include +#include #include #include #include @@ -359,6 +360,39 @@ t8_vtkGrid_to_cmesh (vtkSmartPointer < vtkDataSet > vtkGrid, return cmesh; } +vtkSmartPointer < vtkPointSet > +t8_vtkGrid_to_vtkPointSet (vtkSmartPointer < vtkDataSet > vtkGrid) +{ + /* Set points */ + vtkSmartPointer < vtkPoints > points = + vtkSmartPointer < vtkPoints >::New (); + const vtkIdType num_points = vtkGrid->GetNumberOfPoints (); + points->SetDataType (VTK_DOUBLE); + points->SetNumberOfPoints (num_points); + + for (vtkIdType ipoint = 0; ipoint < num_points; ipoint++) { + double vp[3]; + vtkGrid->GetPoint (ipoint, vp); + points->SetPoint (ipoint, vp); + } + points->Modified (); + T8_ASSERT (points->GetNumberOfPoints () == num_points); + vtkSmartPointer < vtkPointSet > cloud = + vtkSmartPointer < vtkPointSet >::New (); + cloud->SetPoints (points); + + /* Map cell data to point data */ + vtkSmartPointer < vtkCellDataToPointData > c2p = + vtkCellDataToPointData::New (); + c2p->PassCellDataOff (); + c2p->SetInputData (vtkGrid); + c2p->Update (); + cloud->DeepCopy (c2p->GetOutput ()); + //cloud->DeepCopy (vtkPointSet::SafeDownCast (c2p->GetOutput ())); + + return cloud; +} + vtkSmartPointer < vtkDataSet > t8_vtk_reader (const char *filename, const int partition, const int main_proc, sc_MPI_Comm comm, @@ -407,6 +441,24 @@ t8_vtk_reader (const char *filename, const int partition, } } +vtkSmartPointer < vtkPointSet > +t8_vtk_reader_pointSet (const char *filename, + const int partition, + const int main_proc, + sc_MPI_Comm comm, const vtk_file_type_t vtk_file_type) +{ +#if T8_WITH_VTK + vtkSmartPointer < vtkDataSet > vtkGrid = + t8_vtk_reader (filename, partition, main_proc, comm, vtk_file_type); + return t8_vtkGrid_to_vtkPointSet (vtkGrid); +#else + /* Return NULL if not linked against vtk */ + t8_global_errorf + ("WARNING: t8code is not linked against the vtk library. Without proper linking t8code cannot use the vtk-reader\n"); +#endif + return NULL; +} + #endif /* T8_WITH_VTK */ t8_cmesh_t diff --git a/src/t8_vtk/t8_vtk_reader.hxx b/src/t8_vtk/t8_vtk_reader.hxx index ef7eb3667e..0f1045a6c9 100644 --- a/src/t8_vtk/t8_vtk_reader.hxx +++ b/src/t8_vtk/t8_vtk_reader.hxx @@ -30,6 +30,7 @@ along with t8code; if not, write to the Free Software Foundation, Inc., #include #include #include +#include #endif T8_EXTERN_C_BEGIN (); @@ -51,6 +52,17 @@ t8_cmesh_t t8_vtkGrid_to_cmesh (vtkSmartPointer < vtkDataSet > const int main_proc, sc_MPI_Comm comm); +/** + * Given a pointer to a vtkDataSet a vtkPointSet storing a set of points of + * is constructed. The cell data of vtkDataSet is mapt on the points of vtkPointSet. + * + * \param[in] vtkGrid A pointer to a vtkDataSet + * \return A pointer to a vtkPointSet + */ +vtkSmartPointer < vtkPointSet > t8_vtkGrid_to_vtkPointSet (vtkSmartPointer < + vtkDataSet > + vtkGrid); + /** * Given a filename to a vtkUnstructuredGrid or vtkPolyData read the file and * construct a abstract class to specify dataset behavior. The file is read and @@ -71,6 +83,30 @@ vtkSmartPointer < vtkDataSet > t8_vtk_reader (const char *filename, const vtk_file_type_t vtk_file_type); +/** + * Given a filename to a vtkUnstructuredGrid or vtkPolyData read the file and + * a set of points is constructed. This is a two stage process. First the file + * is read and stored in a vtkDataSet using \a t8_vtk_reader and + * \a t8_file_to_vtkGrid. In the second stage a vtkPointSet is constructed from + * the vtkDataSet using \a t8_vtkGrid_to_vtkPointSet. + * + * Both stages use the vtk-library, therefore the function is only available if + * t8code is linked against VTK. + * + * \param[in] filename The name of the file + * \param[in] partition Flag if the constructed mesh should be partitioned + * \param[in] main_proc The main reading processor + * \param[in] comm An mpi-communicator + * \param[in] vtk_file_type A vtk-filetype that is readable by t8code. + * \return Pointer to vtkDataSet + */ +vtkSmartPointer < vtkPointSet > t8_vtk_reader_pointSet (const char *filename, + const int partition, + const int main_proc, + sc_MPI_Comm comm, + const vtk_file_type_t + vtk_file_type); + #endif /**