Reputation: 179
I know how to get the coordinates of the points in an unstructured grid from this post: vtk to matplotlib using numpy
However, I am trying to find a function that takes the unstructured VTK grid and returns the coordinates of the "centers" of the cells/elements. In particular, I'm working with a cylinder composed of quad elements. Here's the code I have so far:
from srlife import writers #library that helps make vtk grid
import numpy as np
import vtk
from vtk.util.numpy_support import vtk_to_numpy
vtkTube1 = writers.VTKWriter(tube1, 'tube1.vtk')
grid = vtk.vtkUnstructuredGrid()
points = vtk.vtkPoints()
for x,y,z in zip(X.flatten(), Y.flatten(), Z.flatten()):
points.InsertNextPoint(x,y,z)
grid.SetPoints(points)
vtkTube1._set_grid(grid)
getCellLocations = vtk_to_numpy(grid.GetCellLocationsArray()) #this just returns 1D array of integers that I don't know what to do with
I tried looking into meshio and griddata from scipy.interpolate but the documentation wasn't very helpful.
Upvotes: 0
Views: 1362
Reputation: 2488
GetCellLocationsArray
does not return geometrical information (see doc) but the indices of the beginning of each cell in the cell array returned by GetCells
You can try the vtkCellCenters filter.
Note: doc is C++ but python API is really similar.
Upvotes: 1