How to pause and restart an animation in VTK

☆樱花仙子☆ 提交于 2019-12-13 00:36:33

问题


I am trying to do an animation program in VTK, in which I could make the VTK objects animate but I failed to do pausing animation and restart animation, I came to know recently to stop the VTK timer but after if I click the animate button again to start then the program got crashed with following error, I have only one clue that the following line is crashing but this line will work at the first time of animation button click but fails on the second button click!!. The second function "animation_Stop" is my attempt of stopping the function by destroying the whole function, so I hoped I could avoid the program crash but it was also a failure!!

Error:

python.exe has stopped working

Error line:

self.renderWindowInteractor.SetRenderWindow(obj_renwin.renwin)

Please note my detailed code lines for animation and someone please help me to restart and pause the animation in vtk python

def animation(self,obj_renwin,X):

    if X==1: 

           print "start or restart animation"

           self.renderWindowInteractor = vtk.vtkRenderWindowInteractor()      
           objRen=self.renderWindowInteractor.GetRenderWindow()                   
           self.renderWindowInteractor.SetRenderWindow(obj_renwin.renwin)                         
           obj_renwin.renwin.Render()
           self.renderWindowInteractor.Initialize()
           cb = vtkTimerCallback()
           cb.actor = obj_renwin.actor
           self.renderWindowInteractor.AddObserver('TimerEvent', cb.execute)
           self.timerId = self.renderWindowInteractor.CreateRepeatingTimer(5);


    if X==2:

        print "stop animation"                       
        self.renderWindowInteractor.DestroyTimer(self.timerId)



def animation_Stop(self,obj_renwin):

    print "stop animation"        
    #self.animation(obj_renwin,1).destroy()
    del (ConeRender.Cone.animation)

回答1:


If you start the vtkTimer like that:

vtkSmartPointer<vtkTimerCallback> cb = 
vtkSmartPointer<vtkTimerCallback>::New();
interactor->AddObserver(vtkCommand::TimerEvent, cb);

you may consider to stop/pause the timer with

vtkCommand::EndInteraction

i.e.

interactor->InvokeEvent(vtkCommand::TimerEvent, cb);

[It is just a moment thought, you can try it] ... :)



来源:https://stackoverflow.com/questions/25595161/how-to-pause-and-restart-an-animation-in-vtk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!