from vtk import * import time # create a rendering window and renderer ren = vtkRenderer() renWin = vtkRenderWindow() renWin.AddRenderer(ren) WIDTH=1280 HEIGHT=720 renWin.SetSize(WIDTH,HEIGHT) iren = vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) camera = vtkCamera() camera.SetClippingRange(1, 100) camera.SetFocalPoint(0, 0, 0) camera.SetPosition(0, 15, 5) camera.SetViewAngle(30) camera.SetViewUp(0, 0, 1) ren.SetActiveCamera(camera) #cam = iren.GetRenderWindow().GetCamera() # create cone cone = vtkConeSource() cone.SetResolution(60) cone.SetCenter(-2,0,0) coneMapper = vtkPolyDataMapper() coneMapper.SetInput(cone.GetOutput()) coneActor = vtkActor() coneActor.SetMapper(coneMapper) # create sphere sp = vtkSphereSource() sp.SetCenter(0,2,0) sp.SetThetaResolution(50) sp.SetPhiResolution(50) spMapper = vtkPolyDataMapper() spMapper.SetInput(sp.GetOutput()) spActor = vtkActor() spActor.SetMapper(spMapper) spActor.GetProperty().SetColor(1,0,0) #create cube cu = vtkCubeSource() cu.SetCenter(2,2,0) cuMapper=vtkPolyDataMapper() cuMapper.SetInput(cu.GetOutput()) cuActor=vtkActor() cuActor.SetMapper(cuMapper) cuActor.GetProperty().SetColor(0,1,0) #arrow ar = vtkArrowSource() arMapper=vtkPolyDataMapper() arMapper.SetInputConnection(ar.GetOutputPort()) arActor=vtkActor() arActor.SetMapper(arMapper) arActor.GetProperty().SetColor(0,0,1) # point po = vtkPointSource() po.SetCenter(-2,-2,0) po.SetRadius(0.4) poMapper=vtkPolyDataMapper() poMapper.SetInputConnection(po.GetOutputPort()) poActor=vtkActor() poActor.SetMapper(poMapper) poActor.GetProperty().SetColor(0,1,1) # line li = vtkLineSource() li.SetPoint1(1,-1,0) li.SetPoint2(2,-3,0) liMapper=vtkPolyDataMapper() liMapper.SetInputConnection(li.GetOutputPort()) liActor=vtkActor() liActor.SetMapper(liMapper) liActor.GetProperty().SetColor(1,0,1) te = vtkTextActor() te.SetInput("VTK animation Test, AW 2009Nov11") tprop=te.GetTextProperty() tprop.SetFontFamilyToArial() tprop.SetFontSize(18) tprop.SetColor(1,1,1) te.SetDisplayPosition(WIDTH-330,HEIGHT-30) te2 = vtkTextActor() te2.SetInput("Frame %d" % 0) tprop=te2.GetTextProperty() tprop.SetFontFamilyToArial() tprop.SetFontSize(18) tprop.SetColor(1,1,1) te2.SetDisplayPosition(20,30) # assign actors to the renderer ren.AddActor(coneActor) ren.AddActor(spActor) ren.AddActor(cuActor) ren.AddActor(arActor) ren.AddActor(poActor) ren.AddActor(liActor) ren.AddActor2D(te) ren.AddActor2D(te2) # screenshot stuff w2if = vtkWindowToImageFilter() w2if.SetInput(renWin) lwr = vtkPNGWriter() lwr.SetInput( w2if.GetOutput() ) # enable user interface interactor iren.Initialize() for n in range(1,360): te2.SetInput("Frame %d" % n) camera.Azimuth( 1 ) renWin.Render() w2if.Modified() lwr.SetFileName("frame"+ ('%03d' % n)+".png") lwr.Write() time.sleep(0.01) iren.Start()