There are quite a lot of for-loops in the vtk_loader module which would get really slow on bigger VTK datasets. This library can handle NumPy arrays, correct?
Perhaps we should reimplement that whole module to only leverage PyVista instead of VTK to access those data arrays in a much faster implementation. PyVista has accessors to the VTK arrays over a direct interface in memory (i.e. no Python for-loops) but everything comes as a NumPy array. The get_ugrid_triangles would simply be replaced by grid.extract_geometry().faces and the get_ugrid_tetrahedrons() would be replaced with a triangulate() filter and grabbing the .cells array from the PyVista mesh.
As for the get_ugrid_data method... this seems a bit convoluted. PyVista can give you all the point/cell data as a dictionary: keys are the name of the arrays and values are numpy arrays of the data values (length corresponds to the number of points or cells and 2nd dimension is the number of components) (F-ordered).
Also, you could just use PyVista to load any VTK dataset or file format supported by PyVista/VTK and not have to worry about all the type checking in load_vtk. This would also add a lot more supported file formats to this library.
If PyVista can make this VTK loading logic faster and simpler, then it is a big yes for me! I am really not an expert in the VTK library so any help is very much appreciated.
There are quite a lot of
for
-loops in thevtk_loader
module which would get really slow on bigger VTK datasets. This library can handle NumPy arrays, correct?Perhaps we should reimplement that whole module to only leverage PyVista instead of VTK to access those data arrays in a much faster implementation. PyVista has accessors to the VTK arrays over a direct interface in memory (i.e. no Python
for
-loops) but everything comes as a NumPy array. Theget_ugrid_triangles
would simply be replaced bygrid.extract_geometry().faces
and theget_ugrid_tetrahedrons()
would be replaced with atriangulate()
filter and grabbing the.cells
array from the PyVista mesh.As for the
get_ugrid_data
method... this seems a bit convoluted. PyVista can give you all the point/cell data as a dictionary: keys are the name of the arrays and values are numpy arrays of the data values (length corresponds to the number of points or cells and 2nd dimension is the number of components) (F-ordered).Also, you could just use PyVista to load any VTK dataset or file format supported by PyVista/VTK and not have to worry about all the type checking in
load_vtk
. This would also add a lot more supported file formats to this library.