[vtkusers] vtkImageViewer2 Orientation Scaling and Resetting the Camera

Andaharoo Andx_roo at live.com
Sat Jun 3 04:45:32 EDT 2017

I'm trying to use the vtkImageViewer2 to scrub through volume slices. I've
pretty much finished it however I'm having a scaling problem and the usage
of the class has not been an intuitive experience at all.

First off I want the entire image to fill the window (fit the size). This is
sort of the default behavior. However there are 2 problems.
1.) It doesn't fit perfectly. The XY image always fits the view suggesting
it is automatically chosen. But there's a ~50-100px border no matter the
size of image being used.
2.) It only scales to the XY orientation. If I use 3 vtkImageViewers to view
the XY, YZ, and XZ orientations, only the XY consistently fits the view.
This suggests that vtkImageViewer2 does not take into account the
orientation when it attempts to automatically fit the image.

I've search through all the functions of vtkImageViewer2 and couldn't find
anything to help me. I've also tried getting the camera from
vtkImageViewer2's renderer and editing it. So at the creation of the
vtkImageViewer2 object (in the constructor) I turn parallel projection on
and set the scale to 1. Like so:


Then I setup the image like so:

Set Image Orientation
Set Middle Slice

The results of editing the camera are a perfectly scaled XY image. This
fixes the border problem but introduces another problem. Every time I run
the function again to change the input it zooms in more. A very drastic
zoom. I have to recreate the vtkImageViewer2 object and set new input to get
it too scale correctly.

I thought it would make sense too simply reset the camera before loading the
next volume. Then everything would go back to normal. This doesn't work.
Resetting the camera doesn't change anything.

The only solution I can think of is to recreate the vtkImageViewer2 object
every time I want to use a new image to solve the zooming on multiple
loading problem (Bad idea, I shouldn't have to recreate it at all). And to
use SetParallelScale with some scalar multiplier * the width, height, or
length of the image depending on the orientation. This would solve the
orientation scaling problem (Haven't tried this yet. It may not even work.
Also seems like a bad idea.).

I have a gut feeling I'm missing some function in vtkImageViewer2,
vtkRenderer, or vtkCamera that can help me properly scale this image to the

View this message in context: http://vtk.1045678.n5.nabble.com/vtkImageViewer2-Orientation-Scaling-and-Resetting-the-Camera-tp5743526.html
Sent from the VTK - Users mailing list archive at Nabble.com.

More information about the vtkusers mailing list