I need to create a triangular mesh on vtk from a list of points that I have. The points are stored under sphere, which is a nx9 numpy array where each row represents the three points that make up one triangle. Right now I am doing this:
points = vtk.vtkPoints()
triangles = vtk.vtkCellArray()
polydata = vtk.vtkPolyData()
for i in range(len(sphere)):
points.InsertNextPoint(sphere[i][:3])
points.InsertNextPoint(sphere[i][3:6])
points.InsertNextPoint(sphere[i][6:9])
triangle = vtk.vtkTriangle()
triangle.GetPointIds().SetId(0,0)
triangle.GetPointIds().SetId(1,1)
triangle.GetPointIds().SetId(2,2)
triangles.InsertNextCell(triangle)
polydata.SetPoints(points)
polydata.SetPolys(triangles)
Which does not properly identify each triangle. How do I solve this issue?
Each InsertNextPoint returns a vtkIdType. Those are the numbers that should go into the 2nd parameter of the triangle's SetID.