Apply transform to a volume

I used python script to use the landmark registration plugin and applied a custom transformation matrix like following:
transformed_node = slicer.util.getNode(“Transform”)
transformed_node.SetMatrixTransformToParent(reg_mat)
seg

Now as denoted in the picture, the transformation works perfectly on the red circled area. However, I want to also apply in green cirlced area. Which is the “Moving” volume. How can I achieve that?
I can grab all the volume node by using

 for sliceViewName in layoutManager.sliceViewNames():
...   view = layoutManager.sliceWidget(sliceViewName).sliceView()
...   sliceNode = view.mrmlSliceNode()
...   sliceLogic = slicer.app.applicationLogic().GetSliceLogic(sliceNode)
...   compositeNode = sliceLogic.GetSliceCompositeNode()
...   print('Slice view ' + str(sliceViewName))
...   print('  Name: ' + sliceNode.GetName())
...   print('  ID: ' + sliceNode.GetID())

When I try to apply a tranform matrix on one of nodes in the green area, I got bellow error:
AttributeError: 'MRMLCorePython.vtkMRMLSliceNode' object has no attribute 'SetMatrixTransformToParent'
So, My question is how I can apply then change in the green area, which is seen in the read area using the same transformation matrix?

You need to apply transform to a volume, not to the slice node (vtkMRMLSliceNode). If the transform is applied to the volume, then it is used in all views. Probably what you actually mean is that you would like to see the transformed moving image in the second row (instead of the original moving image). See slice viewer documentation for instructions for setting background/foreground volume: https://slicer.readthedocs.io/en/latest/user_guide/user_interface.html#slice-view

You are correct. I want to see the transformed moving image in the second row instead of showing the original moving image. But using python script /command line. How can I trigger that ? Can you provide any example script or command line ?

Thanks : )

There are many examples for this in the script repository, for example: https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Iterate_over_current_visible_slice_views.2C_and_set_foreground_and_background_images

I looked into the code snippet you shared. And tried to do it like below snippet.

tnode = slicer.util.getNode("Transform")

 for sliceViewName in layoutManager.sliceViewNames():
      compositeNode = layoutManager.sliceWidget(sliceViewName).sliceLogic().GetSliceCompositeNode()
     compositeNode.SetForegroundVolumeID(tnode.GetID())

But as you said, I need to apply the transform into a volume, not volume node. So obviously I am getting here wrong output. In the second row I did not get the expected change.

So, How can I get the transformed volume not the volume node and replace the green circled area with the transformed volume view, shown in red circled area?

compositeNode.SetForegroundVolumeID expects a volume node’s ID as input. You tried to use the transform node’s ID.

May be I failed to explain.

The red circled area shows the transformed moving volume overlayed on the fixed volume. In the green circled area I want to show the transformed moving volume instead of original moving volume. That is why I tried to take the transformed volume node ID and replace the view of the green circled volume with the transformed one.

If you want to show the transformed volume node in the second row then you can call compositeNode.SetForegroundVolumeID(transformedVolumeNode.GetID()) for the slice views of the second row (where transformedVolumeNode is the transformed moving volume node).

Hi Andras,
Although, the view change works, in case I set a new landmark on the overlayed volume, it does not show the default ‘yellow colored’ landmark ID ( L0, L1 …etc). Is it because of the overlay ? Or there is other way to make the landmark visible on the overlayed volume ?

Each landmark (markups fiducial) list node is set up to be shown in certain views. You can add all the view node IDs where you want the landmarks to appear in the landmark node’s display node (or remove all the view node IDs from the landmark node’s display node - then the landmark node is displayed in all views).