Skip to content

Commit

Permalink
Merge pull request #541 from DLR-AMR/featur-vtk_DataSet_PointSet_tran…
Browse files Browse the repository at this point in the history
…slator

vtkDataSet to vtkPointSet translator
  • Loading branch information
Davknapp authored Jun 26, 2023
2 parents 362a735 + 9de12a9 commit f490fbc
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
1 change: 1 addition & 0 deletions example/IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ along with t8code; if not, write to the Free Software Foundation, Inc.,
#include <sc_options.h>
#include <t8.h>
#include <t8_vtk.h>

#include <t8_forest/t8_forest.h>
#include <t8_schemes/t8_default/t8_default_cxx.hxx>

Expand Down
7 changes: 5 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand All @@ -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 \
Expand Down Expand Up @@ -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)
Expand Down
52 changes: 52 additions & 0 deletions src/t8_vtk/t8_vtk_reader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ along with t8code; if not, write to the Free Software Foundation, Inc.,
#if T8_WITH_VTK
#include <vtkCellIterator.h>
#include <vtkCellData.h>
#include <vtkCellDataToPointData.h>
#include <vtkCellTypes.h>
#include <vtkUnstructuredGrid.h>
#include <vtkUnstructuredGridReader.h>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions src/t8_vtk/t8_vtk_reader.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ along with t8code; if not, write to the Free Software Foundation, Inc.,
#include <vtkSmartPointer.h>
#include <vtkCellData.h>
#include <vtkDataSet.h>
#include <vtkPointSet.h>
#endif

T8_EXTERN_C_BEGIN ();
Expand All @@ -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
Expand All @@ -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

/**
Expand Down

0 comments on commit f490fbc

Please sign in to comment.