How to initialize a triangular mesh in vtk

1k views Asked by At

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?

1

There are 1 answers

0
Dave Chen On

Each InsertNextPoint returns a vtkIdType. Those are the numbers that should go into the 2nd parameter of the triangle's SetID.