如何在 VTK 中暂停和重新启动动画 [英] How to pause and restart an animation in VTK

查看:57
本文介绍了如何在 VTK 中暂停和重新启动动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 VTK 中做一个动画程序,在其中我可以使 VTK 对象具有动画效果但是我没有做暂停动画和重新启动动画,我最近才知道停止 VTK 计时器但是如果我再次单击动画按钮启动然后程序因以下错误而崩溃,我只有一个线索,以下行正在崩溃,但此行将在第一次单击动画按钮时起作用,但在第二次单击按钮时失败!!.第二个函数animation_Stop"是我试图通过破坏整个函数来停止该函数,所以我希望我可以避免程序崩溃但它也是失败的!!

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!!

错误:

python.exe 停止工作

错误行:

self.renderWindowInteractor.SetRenderWindow(obj_renwin.renwin)

请注意我的动画详细代码行,请有人帮我重新启动并在 vtk python 中暂停动画

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)

推荐答案

如果你这样启动 vtkTimer:

If you start the vtkTimer like that:

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

您可以考虑使用

vtkCommand::EndInteraction

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

[暂时想到,你可以试试看] ... :)

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

这篇关于如何在 VTK 中暂停和重新启动动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆