Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. def main2():
  2.    
  3.     #Array of vectors containing the coordinates of each point
  4.     nodes = np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 1, 0], [2, 2, 0], [1, 2, 0], [0, 2, 0], [0, 1, 0], [1, 1, 0]])
  5.    
  6.     #Array of tuples containing the nodes correspondent of each element
  7.     elements = np.array([(0, 1, 8, 7), (7, 8, 5, 6), (1, 2, 3, 8), (8, 3, 4, 5)])
  8.    
  9.     #Make the building blocks of polyData attributes
  10.     Mesh = vtk.vtkPolyData()
  11.     Points = vtk.vtkPoints()
  12.     Cells = vtk.vtkCellArray()  
  13.    
  14.     #Load the point and cell's attributes
  15.     for i in range(len(nodes)):
  16.         Points.InsertPoint(i, nodes[i])
  17.        
  18.     for i in range(len(elements)):
  19.         Cells.InsertNextCell(mkVtkIdList(elements[i]))
  20.        
  21.     #Assign pieces to vtkPolyData
  22.     Mesh.SetPoints(Points)
  23.     Mesh.SetPolys(Cells)
  24.        
  25.     #Mapping the whole thing
  26.     MeshMapper = vtk.vtkPolyDataMapper()
  27.     if vtk.VTK_MAJOR_VERSION <= 5:
  28.         MeshMapper.SetInput(Mesh)
  29.     else:
  30.         MeshMapper.SetInputData(Mesh)
  31.    
  32.     #Create an actor
  33.     MeshActor = vtk.vtkActor()
  34.     MeshActor.SetMapper(MeshMapper)
  35.    
  36.     #Rendering Stuff
  37.     camera = vtk.vtkCamera()
  38.     camera.SetPosition(1,1,1)
  39.     camera.SetFocalPoint(0,0,0)
  40.  
  41.     renderer = vtk.vtkRenderer()
  42.     renWin   = vtk.vtkRenderWindow()
  43.     renWin.AddRenderer(renderer)
  44.  
  45.     iren = vtk.vtkRenderWindowInteractor()
  46.     iren.SetRenderWindow(renWin)
  47.  
  48.     renderer.AddActor(MeshActor)
  49.     renderer.SetActiveCamera(camera)
  50.     renderer.ResetCamera()
  51.     renderer.SetBackground(1,1,1)
  52.  
  53.     renWin.SetSize(300,300)
  54.    
  55.     #Interact with data
  56.     renWin.Render()
  57.     iren.Start()
  58.    
  59.    
  60. main2()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement