Dear everyone,
I am working on a python script that overwrite the Background Image Stencil Data used in the display volume node.
It is natively defined in Slicer/vtkMRMLSliceLayerLogic.cxx at 0673b1c05404b21d259cfaf85a5f89d9cf1f3771 · Slicer/Slicer · GitHub
I have basically commented all occurrences of SetBackgroundImageStencilDataConnection in the slice layer logic.
Instead, I have initialized my own stencil from a vtkMRMLAnnotationROINode (roiNode)
# Create a box implicit function that will be used as a stencil
roiBox = vtk.vtkBox()
roiCenter = [0, 0, 0]
roiNode.GetXYZ(roiCenter)
roiRadius = [0, 0, 0]
roiNode.GetRadiusXYZ(roiRadius)
roiBox.SetBounds(roiCenter[0] - roiRadius[0], roiCenter[0] + roiRadius[0], roiCenter[1] - roiRadius[1], roiCenter[1] + roiRadius[1], roiCenter[2] - roiRadius[2], roiCenter[2] + roiRadius[2])
rasToBox = vtk.vtkMatrix4x4()
if roiNode.GetTransformNodeID() != None:
roiBoxTransformNode = slicer.mrmlScene.GetNodeByID(roiNode.GetTransformNodeID())
boxToRas = vtk.vtkMatrix4x4()
roiBoxTransformNode.GetMatrixTransformToWorld(boxToRas)
rasToBox.DeepCopy(boxToRas)
rasToBox.Invert()
ijkToRas = vtk.vtkMatrix4x4()
volumeNode.GetIJKToRASMatrix(ijkToRas)
ijkToBox = vtk.vtkMatrix4x4()
vtk.vtkMatrix4x4.Multiply4x4(rasToBox, ijkToRas, ijkToBox)
ijkToBoxTransform = vtk.vtkTransform()
ijkToBoxTransform.SetMatrix(ijkToBox)
roiBox.SetTransform(ijkToBoxTransform)
# Use the stencil to fill the volume
imageData = volumeNode.GetImageData()
# Convert the implicit function to a stencil
functionToStencil = vtk.vtkImplicitFunctionToImageStencil()
functionToStencil.SetInput(roiBox)
functionToStencil.SetOutputOrigin(imageData.GetOrigin())
functionToStencil.SetOutputSpacing(imageData.GetSpacing())
functionToStencil.SetOutputWholeExtent(imageData.GetExtent())
functionToStencil.Update()
Then, I bound the output to the volume
volumeNode.GetScalarVolumeDisplayNode().SetBackgroundImageStencilDataConnection(functionToStencil.GetOutputPort())
This has no effects and I cannot figure out why.
Does anyone have an idea why?
Thank you in advance,
Pierre
Pierre