如何停止VTK定时器

时间:2014-08-28 13:31:04

标签: vtk

我正在用VTK python做一个动画程序,我不明白如何停止或暂停 这个动画。有人请告诉我如何停止这个计时器。现在我的动画 正在继续无限的时间,我试图将我的代码放入for循环,但它没有停止。 请注意我的下面代码,并且有人会分享一些想法。

代码行:

renderWindowInteractor.AddObserver('TimerEvent', cb.execute)
timerId = renderWindowInteractor.CreateRepeatingTimer(10);

详细代码行:

class vtkTimerCallback():

def __init__(self):

   self.timer_count = 0
   self.timerCycle=0 

def execute(self,obj,event):

   self.timerCycle+=1
   if self.timerCycle==3:       
      self.timerCycle=0      
      for A in range(3):
          for B in range(2):
              for C in range(1):
                  self.actor.SetPosition(A,1,C);
                  iren = obj
                  iren.GetRenderWindow().Render()
                  self.timer_count += 1      
   else:           

      for X in range(1):
          for Y in range(2):
              for Z in range(3):
                  self.actor.SetPosition(1,Y,Z);
                  iren = obj
                  iren.GetRenderWindow().Render()
                  self.timer_count += 1  



class Cone():


def animation(self,obj_renwin):

    renderwininstance=obj_renwin             
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(obj_renwin.renwin)
    obj_renwin.renwin.Render()
    renderWindowInteractor.Initialize()                   

    cb = vtkTimerCallback()
    cb.actor = obj_renwin.actor
    for X in range(2):
        print "animation time is" + str(X)
        renderWindowInteractor.AddObserver('TimerEvent', cb.execute)       
        timerId = renderWindowInteractor.CreateRepeatingTimer(10);


cone_Obj = Cone()

1 个答案:

答案 0 :(得分:0)

我猜你用定时器进入vtkRenderWindowInteractor对象,在那里启动定时器:

renderWindowInteractor->CreateRepeatingTimer(100);

所以,vtkRenderWindowInteractor可以暂停,并停止计时器:

在这里,您会看到一些细节: http://www.vtk.org/doc/nightly/html/classvtkRenderWindowInteractor.html#a7ef06e3e7c8cff5767c3b0d328934f55