Using vtkImageReslice to mimic a cut plane cutting through 3D Image data

I am interested in having a way of visualizing any given oblique slice through a volumetric image data set.

I have a working implementation that utilizes vtkImageSlice, with vtkImageResliceMapper’s SetSlicePlane method and a moveable vtkPlane. This gives me any oblique slice that I want to see.

Now i’m interested in recreating the exact output that I can visually see, but output it to a new 2D vtkImageData object. I would display this new 2D image data using a separate object, sort of as a reference view (since the user will generally be working with a vtkVolume object).

It seems like vtkImageReslice is the way to go. Based on the parameters of the vtkPlane object that I use above, I have been able to calculate the correct ResliceAxes to set to the vtkImageReslice object (as far as I can tell). However, I have been having issues in trying to match the output 2D image exactly - it seems like my SetOutputExtent, SetOutputSpacing, and SetOutputOrigin may be incorrect, but I’m not sure in what way. If I just use the values from the original 3D vtkImageData for extent, spacing, and origin, and I then slice through the 3D image data at a different angle, the output will often be cut off rather than showing the full extent of the image slice. I have also tried SetAutoCropOutput(true); without any success.

Any advice or workarounds would be greatly appreciated. Thanks in advance!

You might be able to get some ideas from the vtkImageResliceMapper code, specifically the code in
vtkImageResliceMapper::UpdateResliceInformation() that sets these parameters for vtkImageReslice. That code gets the points where the plane cuts the volume’s bounding box, and uses them to compute the bounds to use for the plane. Once the bounds are known, they can be used to compute the OutputOrigin and OutputExtent if the Spacing is known.

If the input volume has isotropic spacing (same in all directions), then the OutputSpacing can just be the input volume spacing. Otherwise, it’s often best to use min(spacing[0], spacing[1]) or min(min(spacing[0],spacing[1]),spacing[2]).