Hello all,
I have the problem with imageReslice position. In my code, I have the vtkDICOMReader that reads the volume. Then I extract part of the volume by the vtkExtractVOI (regular cube form). This two things work according to my needs.
What I need is to create the slice from the vtkExtractVOI output. It means, I want to show it inside the extracted cube. I’ve tried many different settings of the output extent, output origin, input origin, etc. but I’m not able to place the reslice to the correct position.
The problem is demonstrated on the following images (yellow cube is the correctly positioned vtkExtractVOI, the red cube is the imageReslice output):
Here is my code snippet:
self.extractor = vtk.vtkExtractVOI()
#the reader is vtkDICOMReader
self.extractor.SetInputConnection(self.reader.GetOutputPort())
self.extractor.SetVOI(80, 100, 80, 100, 60, 80)
self.extractor.Update()
extractorMapper = vtk.vtkFixedPointVolumeRayCastMapper()
extractorMapper.SetInputConnection(self.extractor.GetOutputPort())
extractorVolume = vtk.vtkVolume()
extractorVolume.SetMapper(extractorMapper)
transform = vtk.vtkTransform()
transform.RotateX(-20)
transform.RotateY(20)
transform.PostMultiply()
transform.Update()
#setting the 4th matrix column to 1 according to vtkImageReslice documentation
t = vtk.vtkMatrix4x4()
transform.GetMatrix(t)
t.SetElement(0, 3, 1)
t.SetElement(1, 3, 1)
t.SetElement(2, 3, 1)
t.SetElement(3, 3, 1)
self.imageReslice = vtk.vtkImageReslice()
self.imageReslice.SetInputConnection(self.extractor.GetOutputPort())
self.imageReslice.SetOutputDimensionality(3)
self.imageReslice.SetResliceAxes(t)
self.imageReslice.InterpolateOn()
#I'm not sure to which values the output extent has to be set. The values in code are found by trying
#many different ones
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)
#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)
What can I do to place the imageReslice slice correctly for I can rotate it inside the extractor cube?
Thank you and have a nice day all!
Jirka