Advertisement
Guest User

vtk color example

a guest
Apr 28th, 2010
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import vtk
  2.  
  3. #setup points and vertices
  4. Points = vtk.vtkPoints()
  5. Triangles = vtk.vtkCellArray()
  6.  
  7. Points.InsertNextPoint(1.0, 0.0, 0.0)
  8. Points.InsertNextPoint(0.0, 0.0, 0.0)
  9. Points.InsertNextPoint(0.0, 1.0, 0.0)
  10.  
  11. Triangle = vtk.vtkTriangle();
  12. Triangle.GetPointIds().SetId(0, 0);
  13. Triangle.GetPointIds().SetId(1, 1);
  14. Triangle.GetPointIds().SetId(2, 2);
  15. Triangles.InsertNextCell(Triangle);
  16.  
  17. #setup colors
  18. Colors = vtk.vtkUnsignedCharArray()
  19. Colors.SetNumberOfComponents(3)
  20. Colors.SetName('Colors')
  21. Colors.InsertNextTuple3( 1,0,0 )
  22. Colors.InsertNextTuple3( 0,1,0)
  23. Colors.InsertNextTuple3( 0,0,1 )
  24.  
  25. polydata = vtk.vtkPolyData()
  26. polydata.SetPoints(Points)
  27. polydata.SetPolys(Triangles)
  28. polydata.GetPointData().SetVectors(Colors)
  29. polydata.Modified()
  30. polydata.Update()
  31.  
  32. mapper = vtk.vtkPolyDataMapper()
  33. mapper.SetInput(polydata)
  34. actor = vtk.vtkActor()
  35. actor.SetMapper(mapper)
  36.  
  37. ren = vtk.vtkRenderer()
  38. renWin = vtk.vtkRenderWindow()
  39. renWin.AddRenderer(ren)
  40. iren = vtk.vtkRenderWindowInteractor()
  41. iren.SetRenderWindow(renWin)
  42. ren.AddActor(actor)
  43. iren.Start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement