Another problem with vtkImageReslice in 2D

Hi all,

according to solution of my topic with 3D reslicing using vtkImageReslice and transformation matrix I can rotate the reslicing cube inside the vtkExtractVOI.

You can see the topic here:

It works great. What I need now is to have only the XY plane slice. According to the vtk documentation and SetOutputDimensionality method:
“If the dimensionality is 2D, then the Z extent of the output is forced to (0,0) and the Z origin of the output is forced to 0.0 (i.e. the output extent is confined to the xy plane).”

But, when I try to set the output dimensionality to 2, I get no output. If I set the value of 3 then I have some 2D output but I’m not sure what is it exactly (is it XY plane? Or something else?).

You can see my problem in the following pictures and code snippet:

And the output in the vtkImageViewer2:

2D_rotateX_45 degrees

    center = self.extractor.GetOutput().GetCenter()

    transform = vtk.vtkTransform()
    transform.Translate(-center[0], -center[1], -center[2])

   # Moving the reslice cube to the center of the cube, i.e. up in the Z-axe direction. 
   # I need to do the same for all 6 diagonal planes of the extractor cube, so for other rotations 
   # another axe center will be shifted. The cube size is 20, that's why I move it by 10
  # (XY plane to the extractor cube center)  
    transform.Translate(+center[0], +center[1], +center[2] + 10) 

    self.imageReslice = vtk.vtkImageReslice()
    self.imageReslice.SetOutputSpacing(xSpacing, ySpacing, zSpacing)

    viewer = vtk.vtkImageViewer2()

    reslicedVolumeMapper = vtk.vtkFixedPointVolumeRayCastMapper()
    reslicedImageVolume = vtk.vtkVolume()

    reslicedImageVolume.SetProperty(volumeProperty1)  #mapping the reslice to the red pallete

    self.ren2.AddVolume(volume) #ren2 is renderer of one of the windows.

Using dimensionality of 2 in the above code gives no output in the vtkImageVIewer2 window (and also in the 3D window). In the vtkImageViewer2 window there is only black image. Also, if I try to save reslice to the file on disk, it is all black.

  1. What am I doing wrong? What can I do to have 2D output of my reslice?
  2. What is the output in vtkImageViewer2 if I let dimensionality set to 3? If I can be sure that it is the XY plane then I don’t need answer for the 1st question as it is what I need :slight_smile:

Thank you for any advice and have a nice day!


Setting the dimensionality to 2D is essentially slicing through the dataset. To achieve that your reslice transform should define a plane passing through the 3D data.

Try this:

transform.Translate(center[0], center[1], center[2]);
transform.Translate(-center[0], -center[1], -center[2]);

The above code ensures that the plane is rotated about the center of the 3D data.