Discussion:
[vtkusers] CreateRepeatingTimer Loop with memory
Andreas Pedroni
2018-11-20 20:48:56 UTC
Permalink
Dear list

Is there a way to use a RepeatingTimer as in this example: https://www.vtk.org/Wiki/VTK/Examples/Python/Animation <https://www.vtk.org/Wiki/VTK/Examples/Python/Animation> in which the loop for the animation (in the example the method execute()) can return output in each iteration that is used in the the next iteration? In other words, is there a way to use information that is calculated in one iteration for the next iteration? Sorry, I am not sure if the question is understandable.

best
Andreas
Elvis Stansvik
2018-11-20 21:06:42 UTC
Permalink
Post by Andreas Pedroni
Dear list
Is there a way to use a RepeatingTimer as in this example: https://www.vtk.org/Wiki/VTK/Examples/Python/Animation in which the loop for the animation (in the example the method execute()) can return output in each iteration that is used in the the next iteration? In other words, is there a way to use information that is calculated in one iteration for the next iteration? Sorry, I am not sure if the question is understandable.
I think you have your answer right there in that example :) In each
iteration, the self.timer_count field holds the output from the
previous iteration.

So yes, I think you can simply save the output from one iteration in a
field of the callback class, and use that as input in the next
iteration.

Hope that makes sense.

Cheers,
Elvis
Post by Andreas Pedroni
best
Andreas
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Search the list archives at: http://markmail.org/search/?q=vtkusers
https://public.kitware.com/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2018-11-20 21:24:10 UTC
Permalink
Basically what Elvis said: you can store whatever you want in the callback.
For example, you can do this:

cb.actor = actor
cb.mapper = mapper

And then in the callback execute() method, you can do whatever you want
with cb.mapper, i.e. you can give the mapper a new input.

Whether you really want to do this, though, depends on exactly what you are
trying to achieve at each iteration. If you just want to adjust the
position or orientation, then it's best to just do something similar to
what the example does. Actually getting the output and using it as the
next input is computationally expensive, whereas changing the position and
orientation of an actor is cheap.

If you are hoping to get the output of the Render() and feed it back into
the mapper, that is actually impossible. The Render() draws to the screen,
so its output is a 2D bitmap, which isn't something you can feed back into
the pipeline as a replacement of the original polydata.

David
Post by Andreas Pedroni
Post by Andreas Pedroni
Dear list
https://www.vtk.org/Wiki/VTK/Examples/Python/Animation in which the loop
for the animation (in the example the method execute()) can return output
in each iteration that is used in the the next iteration? In other words,
is there a way to use information that is calculated in one iteration for
the next iteration? Sorry, I am not sure if the question is understandable.
I think you have your answer right there in that example :) In each
iteration, the self.timer_count field holds the output from the
previous iteration.
So yes, I think you can simply save the output from one iteration in a
field of the callback class, and use that as input in the next
iteration.
Hope that makes sense.
Cheers,
Elvis
Post by Andreas Pedroni
best
Andreas
Andreas Pedroni
2018-11-21 08:04:04 UTC
Permalink
Thanks a lot David and Elvis,

I’ll try your suggestion tonight. And sorry for the rather stupid question. I’m both new to Python and VTK and at times struggling at different fronts, especially with oop. :)
David, actually, I need this updating mechanism to temporally smooth some movement of one of the actors and for this I need to store previous movements.

all the best
Andreas
Post by David Gobbi
Basically what Elvis said: you can store whatever you want in the callback.
cb.actor = actor
cb.mapper = mapper
And then in the callback execute() method, you can do whatever you want with cb.mapper, i.e. you can give the mapper a new input.
Whether you really want to do this, though, depends on exactly what you are trying to achieve at each iteration. If you just want to adjust the position or orientation, then it's best to just do something similar to what the example does. Actually getting the output and using it as the next input is computationally expensive, whereas changing the position and orientation of an actor is cheap.
If you are hoping to get the output of the Render() and feed it back into the mapper, that is actually impossible. The Render() draws to the screen, so its output is a 2D bitmap, which isn't something you can feed back into the pipeline as a replacement of the original polydata.
David
Post by Andreas Pedroni
Dear list
Is there a way to use a RepeatingTimer as in this example: https://www.vtk.org/Wiki/VTK/Examples/Python/Animation <https://www.vtk.org/Wiki/VTK/Examples/Python/Animation> in which the loop for the animation (in the example the method execute()) can return output in each iteration that is used in the the next iteration? In other words, is there a way to use information that is calculated in one iteration for the next iteration? Sorry, I am not sure if the question is understandable.
I think you have your answer right there in that example :) In each
iteration, the self.timer_count field holds the output from the
previous iteration.
So yes, I think you can simply save the output from one iteration in a
field of the callback class, and use that as input in the next
iteration.
Hope that makes sense.
Cheers,
Elvis
Post by Andreas Pedroni
best
Andreas
mmusy
2018-11-21 10:54:04 UTC
Permalink
..maybe it's "dirty" but one may achieve the same with using global variables
(var in the example).

BTW, the vtkInteractorStyleTrackballCamera has a weird behaviour in rotating
the scene.



from __future__ import print_function
import vtk

var = 0

class vtkTimerCallback():
def __init__(self):
self.timer_count = 0

def execute(self,obj,event):
global var
print(self.timer_count, var)
self.actor.SetPosition(self.timer_count, self.timer_count,0);
iren = obj
iren.GetRenderWindow().Render()
self.timer_count += 1
var += 1

def main():
...


if __name__ == '__main__':
main()



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2018-11-21 13:35:21 UTC
Permalink
Hi Marco,

Yes, global variables could be used here, but global variables are evil ;)

The issue with vtkInteractorStyleTrackballInteractor sounded familiar, so I
searched the bugtracker:
https://gitlab.kitware.com/vtk/vtk/issues/15966
http://vtk.1045678.n5.nabble.com/interaction-problem-after-timer-added-td5736076.html
I just tried the code listed in the discussion, it looks like the bug is
still present in VTK.

David
Post by mmusy
..maybe it's "dirty" but one may achieve the same with using global variables
(var in the example).
BTW, the vtkInteractorStyleTrackballCamera has a weird behaviour in rotating
the scene.
from __future__ import print_function
import vtk
var = 0
self.timer_count = 0
global var
print(self.timer_count, var)
self.actor.SetPosition(self.timer_count, self.timer_count,0);
iren = obj
iren.GetRenderWindow().Render()
self.timer_count += 1
var += 1
...
main()
Loading...