How to visualise vtkImageReslice in volume?

Hi all,

I have a DICOM volume (read by the vtkDICOMreader) visualized using the vtkGPUVolumeRayCastMapper. Working fine.

Moreover, I have vtkImageReslice with Dimensions set on 2, so the output is the plane in fact.

I can output the resliced plane to 2D image viewer window. This works fine too.

What I need now is to visualize the vtkImageReslice output in the volume rendering window, i.e. to visualize exactly the vtkImageReslice output (the plane) placed correctly inside the volume and see its bounds.

I have no clue how to do it. I will appreciate any advice.

Thank you and have a nice day,

Jirka

Hello all,

I have solved this by myself. Following is the solution, for everyone that needs it.

  1. First, dimensions are set to 3 for visualisation. Once you see the correct 3D imageReslice output, we can change it back to 2.
  2. Create the mapper and volume for imageReslice
  3. Set volume mapper to the created one
  4. Add the volume to the renderer

Here is the code snippet (Python):

  #creating volume property - I want only the red color mapping for the imageReslice for visualisation 
    opacityTransferFunction1 = vtk.vtkPiecewiseFunction()
    opacityTransferFunction1.AddPoint(1, 0.0)
    opacityTransferFunction1.AddPoint(255, 1.0)

    colorTransferFunction1 = vtk.vtkColorTransferFunction()
    colorTransferFunction1.AddRGBPoint(0.0, 0.1, 0.0, 0.0)
    colorTransferFunction1.AddRGBPoint(255.0, 1.0, 0.0, 0.0)

    volumeProperty1 = vtk.vtkVolumeProperty()
    volumeProperty1.SetColor(colorTransferFunction1)
    volumeProperty1.SetScalarOpacity(opacityTransferFunction1)
    volumeProperty1.ShadeOn()
    volumeProperty1.SetInterpolationTypeToLinear()

    self.imageReslice = vtk.vtkImageReslice()
    self.imageReslice.SetInputConnection(self.extractor.GetOutputPort())
    self.imageReslice.SetOutputDimensionality(3)
    self.imageReslice.SetResliceAxesDirectionCosines(1, 0, 0, 0, 0, 1, 0, -1, 0) 
    self.imageReslice.InterpolateOn()
    
    self.imageReslice.SetOutputExtent(0, 100, 0, 100, 0, 200)
    self.imageReslice.AutoCropOutputOn()
   #extractor is the vtkExtractVOI object 
    self.imageReslice.SetResliceAxesOrigin(self.extractor.GetOutput().GetOrigin())
    
    self.imageReslice.SetOutputOrigin(self.extractor.GetOutput().GetOrigin())
    self.imageReslice.SetOutputSpacing(1, 1, 1)

    self.imageReslice.UpdateWholeExtent()

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

    reslicedVolumeMapper.SetInputConnection(self.imageReslice.GetOutputPort())
    reslicedImageVolume.SetMapper(reslicedVolumeMapper)

    reslicedImageVolume.SetProperty(volumeProperty1)  

   #the following volume is the volume created from the vtkDICOMReader output. Commented as I don't need to show it always. "ren2" is the renderer of one of the windows I use in my code. 
    #self.ren2.AddVolume(volume)
   #the following extractorVolume is the volume created from the vtkExtractVOI output.  
    self.ren2.AddVolume(extractorVolume)
    self.ren2.AddVolume(reslicedImageVolume)

As I wanted to show only the question relevant code part, the above code snippet is missing parts of adding renderer to window, window interractor, etc. that are standard parts of the vtk pipeline and we can find it in many examples. If you don’t use classes (OOP), remove the “self.” from the above code…

Hope, it can be useful for someone.