Animation and transpose

79 views
Skip to first unread message

Loïc Gouarin

unread,
Apr 29, 2015, 4:25:16 AM4/29/15
to vi...@googlegroups.com
Hi,

I have several questions about vispy and for that, I write this simple example

import numpy as np
from vispy import scene, app


def sincos(x, y, t):
   
return np.cos(x[:, np.newaxis] + t)*np.cos(y[np.newaxis, :])


if __name__ == '__main__':
    nx
, ny, scale = 100, 200, 3
    x
= np.linspace(0., 2.*np.pi, nx)
    y
= np.linspace(0., np.pi, ny)
    dt
= .1
    t
= 0.
   
    canvas
= scene.SceneCanvas(keys='interactive')
    canvas
.size = nx*scale, ny*scale
    view
= canvas.central_widget.add_view()
   
   
def update(event):
       
global t
        canvas
.title = "Solution t={0:f}".format(t)
        image
= scene.visuals.Image(sincos(x, y, t).T, parent=view.scene)


       
#tr = scene.transforms.AffineTransform()
       
#tr.rotate(-90, (0, 0, 1))
       
#tr.translate ??
       
#image.transform = tr
           
        view
.camera = scene.PanZoomCamera(aspect=1)
        t
+= dt
       
    timer
= app.Timer('auto', connect=update, start=True)
    canvas
.show()
    app
.run()

- How can I avoid the transpose of my array ? I try to set an AffineTransform without success.

- What is the best way to speedup the animation ? It seems that create an image at each time slows down the animation.

- Is it possible to update a scene without to create an app and execute app.run() ? In other words, I would like that my code set a refresh of the scene when the computation for a given time step is finished.

Thanks,
Loic

Luke Campagnola

unread,
Apr 29, 2015, 7:17:44 AM4/29/15
to Vispy list
On Wed, Apr 29, 2015 at 4:25 AM, Loïc Gouarin <loic.g...@gmail.com> wrote:

- How can I avoid the transpose of my array ? I try to set an AffineTransform without success.

A transpose is a 180-degree rotation around the x=y line, so:

        tr.rotate(180, (1, 1, 0))

- What is the best way to speedup the animation ? It seems that create an image at each time slows down the animation.

Don't create an image on every frame :)
Instead, use `Image.set_data(...)` to update a single image. 
 
- Is it possible to update a scene without to create an app and execute app.run() ? In other words, I would like that my code set a refresh of the scene when the computation for a given time step is finished.

You should be able to call `app.process_events()` to force an update.

Loïc Gouarin

unread,
Apr 29, 2015, 8:10:54 AM4/29/15
to vi...@googlegroups.com
Thanks Luke for your answer.


Le mercredi 29 avril 2015 13:17:44 UTC+2, luke.campagnola a écrit :

On Wed, Apr 29, 2015 at 4:25 AM, Loïc Gouarin <loic.g...@gmail.com> wrote:

- How can I avoid the transpose of my array ? I try to set an AffineTransform without success.

A transpose is a 180-degree rotation around the x=y line, so:

        tr.rotate(180, (1, 1, 0))
Yes but the image is not well scaled on the view.

I though that the line 

view.camera = scene.PanZoomCamera(aspect=1)

 rescales the image...

Thanks, 
Loic
Reply all
Reply to author
Forward
0 new messages