# Programmatically setting a TransformProcessorNode

**URL:** <https://discourse.slicer.org/t/programmatically-setting-a-transformprocessornode/18335>\
**Category:** Development\
**Tags:** python\
**Created:** [June 25, 2021, 9:14am UTC](https://discourse.slicer.org/t/programmatically-setting-a-transformprocessornode/18335 "2021-06-25T09:14:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![atracsys-sbt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/atracsys-sbt/32/11434_2.png) [@atracsys-sbt](https://discourse.slicer.org/u/atracsys-sbt)\
**Post date:** [June 25, 2021, 9:14am UTC](https://discourse.slicer.org/t/programmatically-setting-a-transformprocessornode/18335/1 "2021-06-25T09:14:08Z")

</div>

Hi,  
I’m currently writing a module that handles two tracked markers (one attached to a phantom and one attached to a pointer i.e. a stylus).  
In a effort to obtain the pointer coordinates in the referential of the phantom, I would like to use a TransformProcessorNode (which I successfully used in the GUI).  
Here is what I wrote:

```auto
transfoProcNode = slicer.vtkMRMLTransformProcessorNode()
transfoProcNode.SetProcessingMode(transfoProcNode.PROCESSING_MODE_COMPUTE_FULL_TRANSFORM)
transfoProcNode.SetAndObserveInputFromTransformNode(pointerTransform)
transfoProcNode.SetAndObserveInputToTransformNode(phantomTransform)
phtToPtrTransfoNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLinearTransformNode', 'PointerToPhantom')
transfoProcNode.SetAndObserveOutputTransformNode(phtToPtrTransfoNode)
transfoProcNode.SetUpdateModeToAuto()
pointerModel.SetAndObserveTransformNodeID(phtToPtrTransfoNode.GetID())

```

But, looking at the resulting transform ‘PointerToPhantom’ in the Transforms module, it appears as the identity and does not change.  
Thank you for any input

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 25, 2021, 6:09pm UTC](https://discourse.slicer.org/t/programmatically-setting-a-transformprocessornode/18335/2 "2021-06-25T18:09:04Z")

</div>

Normally you would just write into the Plus configuration file to send “PointerToPhantom”. Plus toolkit can automatically compute transforms between any coordinate systems, by parsing the name and concatenating and inverting transforms as needed.

---

<div class="post-metadata">

**Author:** ![atracsys-sbt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/atracsys-sbt/32/11434_2.png) [@atracsys-sbt](https://discourse.slicer.org/u/atracsys-sbt)\
**Post date:** [August 23, 2021, 8:34am UTC](https://discourse.slicer.org/t/programmatically-setting-a-transformprocessornode/18335/3 "2021-08-23T08:34:35Z")

</div>

Despite the proposed solution (deferring the transforms multiplication to Plus) being satisfactory at first, I now also need to have access to both transforms separately for other purposes.  
What would be better in terms of performance:

- keep the actual PointerToPhantom channel from Plus and add two other channels for Pointer and Phantom (which would be kind of redundant)
- do what I tried to do in my original post: set a TransformProcessorNode  
Thank you for your feedback

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 23, 2021, 4:41pm UTC](https://discourse.slicer.org/t/programmatically-setting-a-transformprocessornode/18335/4 "2021-08-23T16:41:09Z")

</div>

Both solutions are fine.

Probably the transform in your script does not update because you did not add the transform processor node to the scene. You can fix it by changing the first line to `transfoProcNode = slicer.mrmlScene. AddNewNodeByClass('vtkMRMLTransformProcessorNode')`.
