John R
John R

Reputation: 129

How to stop VTK Timer

I am doing an animation program with VTK python, I don't understand how to stop or pause this animation. Somebody please tell me on how to stop this timer. Right now my animation is continuing for infinite time, I tried to put my code in for loop but it failed to stop. please note my below code and someone kindly share some idea.

Code lines:

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

Detailed Code lines:

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()

Upvotes: 0

Views: 1754

Answers (1)

Flaviu_
Flaviu_

Reputation: 1371

I guess that you use the timer into vtkRenderWindowInteractor object, there you start the timer:

renderWindowInteractor->CreateRepeatingTimer(100);

so, vtkRenderWindowInteractor can pause, and stop the timer:

here, you see some details: http://www.vtk.org/doc/nightly/html/classvtkRenderWindowInteractor.html#a7ef06e3e7c8cff5767c3b0d328934f55

Upvotes: 0

Related Questions