How to Copy Nodes with Synchronization

Hello all,

I would like to apply gridTransform to a specific Slice View (panoramic view) to visualize the data, as shown in the image below.

I was advised that the easiest way to do this is to copy all the data, apply the Transform, and then visualize it.
https://discourse.slicer.org/t/apply-transform-matirx-to-only-specific-2d-view/36273/3

Therefore, I am seeking advice on how to copy the data.

When I have the original node A and the copied node A’, I want to ensure that any transformations (such as color, transparency, position, etc.) applied to node A are reflected in node A’ and vice versa.

This way, any modifications made in one view will be consistently reflected in both the transformed view and the non-transformed view.

The nodes to be copied include Volume, Model, Markup, and Transform. I also plan to create copies for any new nodes that are added.

Thank you for your assistance.

I don’t think there’s any code that does the specific operation currently, but it shouldn’t be too much work to make a kind of “dynamic clone” node.

Effectively you would just need to observe modify events from the source node and copy parameters to the cloned nodes when anything change, but filter out any changes you don’t have to have apply to the clone, like setting the transforms. This same code could handle the shared bulk data (both nodes pointing to the same vtkImageData for example).

If this approach works and you find it useful it would be great to consider making it a core feature somehow, or maybe part of an extension or just an example in the script repository.

Here is the codes I made.
This synch A → A’ one way

# Get hierarchyNode
shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
  
# Get info from origin node
nodeItem = shNode.GetItemByDataNode(node)
nodeName = node.GetName()

# Clone node
cloneItem = slicer.modules.subjecthierarchy.logic().CloneSubjectHierarchyItem(shNode, nodeItem)
clonedNode = shNode.GetItemDataNode(cloneItem)
clonedNode.SetName(nodeName+'Clone')
  
# Set clone data unber origin data 
shNode.CreateItem(nodeItem, clonedNode)

# Clone data synch 
def synchOriginToClone(unusedArg1=None, unusedArg2=None, unusedArg3=None):
    clonedNode.CopyContent(node)
    
node.AddObserver(slicer.vtkMRMLMarkupsNode.PointModifiedEvent, synchOriginToClone)
node.AddObserver(slicer.vtkMRMLTransformNode.TransformModifiedEvent, synchOriginToClone)
2 Likes