[vtkusers] parallel camera: how to get image to fill viewport?

Steve M. Robbins steven.robbins at videotron.ca
Sat Nov 12 03:20:50 EST 2005


Howdy,

I'm using vtkImageViewer2 to render an image.  I'd like to set the
camera scale so that the image fills the window width or height.  
I have 1 viewport that fills the entire window.

I've set the camera to parallel projection, set the focal point to the
centre of the image, set the position to just above the centre, and
set view up to the Y axis.  After some time grepping through the
sources, I've found that setting the camera parallel scale to (
windowHeight - 1 ) / 2 works well.  See attached code for details.

So I figure that if the image dimension and window dimension match,
the transformation should be the identity.  I've stumbled across the
following comment in vtkViewport.cxx:

    // the 0.5 offset is here because the viewport uses pixel centers
    // while the display uses pixel edges.
 
So I started computing the various transforms and dumping them (see
attached code).  It turns out that my code will generate an identity
mapping between world and viewport, but there's a half-pixel shift in
world-to-display.  So I am presuming that the world coordinate system
specifies pixel centres, too.  True?

At any rate, I can get an identity world->viewport mapping when the
image and viewport sizes agree, but only when they are square.
As the attached code and output shows, when the width != height,
I no longer get the identity.  

How should I set up the camera so that the image fills the viewport?

Thanks,
-Steve

P.S. Attached code was built and run against CVS HEAD, as of
late Friday evening.  Also built and run against 4.2 with 
similar results.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestParallelCamera.java
Type: text/x-java
Size: 7168 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051112/2fc045c8/attachment.java>
-------------- next part --------------
Loaded VTK version 5.1.0
  Source version: vtk version 5.1.0, vtk source $Revision: 1.2260 $, $Date: 2005/11/11 10:51:14 $ (GMT)
5x5
Renderer tiled aspect ratio: 1.0
Camera parallel scale: 2.0

Normalized Viewport-to-Viewport transform
4.0   0.0   0.0
0.0   4.0   0.0

Normalized Display-to-Display transform
5.0   0.0   0.0
0.0   5.0   0.0

View-to-Viewport transform
2.0   0.0   2.0
0.0   2.0   2.0

View-to-Display transform
2.0   0.0   2.5
0.0   2.0   2.5

World-to-Viewport transform
1.0   0.0   0.0
0.0   1.0   0.0

World-to-Display transform
1.0   0.0   0.5
0.0   1.0   0.5


15x5
Renderer tiled aspect ratio: 3.0
Camera parallel scale: 2.0

Normalized Viewport-to-Viewport transform
14.0   0.0   0.0
0.0   4.0   0.0

Normalized Display-to-Display transform
15.0   0.0   0.0
0.0   5.0   0.0

View-to-Viewport transform
7.0   0.0   7.0
0.0   2.0   2.0

View-to-Display transform
7.0   0.0   7.5
0.0   2.0   2.5

World-to-Viewport transform
1.1666666666666665   0.0   -1.1666666666666656
0.0   1.0   0.0

World-to-Display transform
1.1666666666666665   0.0   -0.6666666666666656
0.0   1.0   0.5



More information about the vtkusers mailing list