VTK/Examples/Python/WriteTriangleToFile
From KitwarePublic
< VTK | Examples(Redirected from Write a triangle to a file (python))
import vtk from vtk import * import hybrid from hybrid import * Points = vtk.vtkPoints() Triangles = vtk.vtkCellArray() Triangle = vtk.vtkTriangle(); id = Points.InsertNextPoint(1.0, 0.0, 0.0) id = Points.InsertNextPoint(0.0, 0.0, 0.0) id = Points.InsertNextPoint(0.0, 1.0, 0.0) Triangle.GetPointIds().SetId(0, 0); Triangle.GetPointIds().SetId(1, 1); Triangle.GetPointIds().SetId(2, 2); Triangles.InsertNextCell(Triangle); polydata = vtk.vtkPolyData() polydata.SetPoints(Points) polydata.SetPolys(Triangles) polydata.Modified() polydata.Update() writer = vtk.vtkXMLPolyDataWriter(); writer.SetFileName("Triangle.vtp"); writer.SetInput(polydata); writer.Write();

