viewport in vispy scene

389 views
Skip to first unread message

Pieter Eendebak

unread,
Jan 15, 2016, 11:12:59 AM1/15/16
to vispy
Hi all,

How can I change the viewport of a camera? I am using the SceneCanvas framwork and I have set the camera with

view = canvas.central_widget.add_view()
view.camera = 'turntable'
view.camera.fov=60
Tmatrix=np.eye(4)
Tmatrix[3,2]=100
view.camera.transform.matrix=Tmatrix

This places my camera at 100 units from the origin of the scene. My canvas has size 800x600 pixels, and the viewport is then -400, 400 by -300, 300. How can I specify my own viewport? For example if I only want to render to bottom left quadrant of the image.

I have tried setting view.camera.viewbox.transform with a translation, but this does not give me the proper result.

With kind regards,
Pieter Eendebak

Luke Campagnola

unread,
Jan 17, 2016, 5:37:32 PM1/17/16
to Vispy list
Hi Pieter,

The region of the window that will be rendered to is determined by the boundaries of the ViewBox (the view variable in your example), and currently that ViewBox fills the entire window because its boundaries are determined by canvas.central_widget. You have a couple of options:

* Add the view inside a Grid with other widgets filling the rest of the space
* Add a ViewBox to the scene (but not via central_widget) and manually set its position and size.


Luke

--
You received this message because you are subscribed to the Google Groups "vispy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vispy+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pieter Eendebak

unread,
Jan 18, 2016, 4:12:57 AM1/18/16
to vispy
Hi Luke,

My previous email was not entirely clear I think. I want the region of the window that is rendered to be the full window (e.g. 800x600 pixels), but I want to change what is rendered by the camera. (so I want to change the projection of the camera).

The 3D scene is projected to the screen (pixels) using several transformations. First there is the transformation form the world to camera coordinates (this is a 4x4 matrix, view.camera.transform.matrix). Next there is a transformation from camera coordinates to pixels. This is usually a 3x4 matrix called the intrinsic calibration. I cannot find this matrix in vispy, altough part of it I can be influenced through the fov.

From the intrinsic calibration I want to be able to set the optical centre. In vispy/scene/cameras/perspective.py I found (line 154) the self._viewbox_tr and self._projection. I think I have to modify these matrices.

With kind regards,
Pieter Eendebak



Op zondag 17 januari 2016 23:37:32 UTC+1 schreef luke.campagnola:

Pieter Eendebak

unread,
Jan 25, 2016, 3:23:31 AM1/25/16
to vispy
I finally was able to set the viewport by manually setting camera._projection.matrix. The necessary transformations were calculated using examples from http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl/

With kind regards,
Pieter Eendebak


Op maandag 18 januari 2016 10:12:57 UTC+1 schreef Pieter Eendebak:
Reply all
Reply to author
Forward
0 new messages