from __future__ import print_function
import vtk
class vtkTimerCallback():
def __init__(self):
self.timer_count = 0
def execute(self, obj, event):
# print(self.timer_count)
self.actor.RotateY(self.timer_count % 360)
# self.actor.SetPosition(self.timer_count, self.timer_count, 0)
iren = obj
iren.GetRenderWindow().Render()
self.timer_count += 1
def main():
# Create a sphere
cubeSource = vtk.vtkCubeSource()
cubeSource.SetCenter(0.0, 0.0, 0.0)
# Create a mapper and actor
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(cubeSource.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(0.1,0.2,0.4)
# prop = actor.GetProperty()
# Setup a renderer, render window, and interactor
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
# renderWindow.SetWindowName("Test")
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
# Add the actor to the scene
renderer.AddActor(actor)
renderer.SetBackground(1, 1, 1) # Background color white
# Render and interact
renderWindow.Render()
# Initialize must be called prior to creating timer events.
renderWindowInteractor.Initialize()
# Sign up to receive TimerEvent
cb = vtkTimerCallback()
cb.actor = actor
renderWindowInteractor.AddObserver('TimerEvent', cb.execute)
renderWindowInteractor.CreateRepeatingTimer(100)
# start the interaction and timer
renderWindowInteractor.Start()
if __name__ == '__main__':
main()
vtk python 如何使actor一直旋转
最新推荐文章于 2024-07-12 23:15:31 发布