Please help how to get IDs of points attached to the given cell (in order to to find coordinates of the points forming the given cell)? I have cell and point data after the next script:
Generally, I need to determine the geometric center of the cells in python. I see that the Cell Centers Filter is not fully consistent with the task of determining the exact geometric center. So I am going to determine the center of gravity of the cell explicitly through the coordinates of its vertices using Python script
There may be several ways, you can try this:
from vtk import *
cellIds = vtkIdList() # cell ids store to
pythonData.GetCellPoints(0, cellIds) # get cell ids
for i in range(0, cellIds.GetNumberOfIds()):
pythonData.GetPoint(cellIds.GetId(i)) # get coordinate, type : class tuple
btw You can use dir(pythonData) to get documents or check c++ code in paraview source to findout which function to use
Many thanks for the help!
I completed the above example according to your advice
paraViewData=FindSource('my_project.pvd')
SetActiveSource(paraViewData)
UpdatePipeline()
pythonData=servermanager.Fetch(paraViewData)
numberOfCells=pythonData.GetNumberOfCells()
from vtk import *
cellIds = vtkIdList() # cell ids store to
for cellIndex in range(numberOfCells): # for every cell
pythonData.GetCellPoints(cellIndex, cellIds) # get ids of points of the given cell
for i in range(0, cellIds.GetNumberOfIds()): # for every points of the given cell
coord=pythonData.GetPoint(cellIds.GetId(i)) # get coordinates of the given point of the given cell, type: class 'tuple'
x=coord[0] # get coordinates of the given point of the given cell, type: class 'float'
y=coord[1]
z=coord[2]
Regarding the definition of geometric centers of cells the Cell Centers filter reliability can be improved by adding the Clean to Grid filter before Cell Centers as explained here ParaView Cell Centers possible unstable program behavior