# ConvertToGridTransform returns vtkMRMLTransformNode instead of vtkMRMLGridTransformNode

**URL:** <https://discourse.slicer.org/t/converttogridtransform-returns-vtkmrmltransformnode-instead-of-vtkmrmlgridtransformnode/18467>\
**Category:** Support\
**Created:** [July 1, 2021, 6:08pm UTC](https://discourse.slicer.org/t/converttogridtransform-returns-vtkmrmltransformnode-instead-of-vtkmrmlgridtransformnode/18467 "2021-07-01T18:08:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonoxen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/simonoxen/32/66398_2.png) [@simonoxen](https://discourse.slicer.org/u/simonoxen)\
**Post date:** [July 1, 2021, 6:08pm UTC](https://discourse.slicer.org/t/converttogridtransform-returns-vtkmrmltransformnode-instead-of-vtkmrmlgridtransformnode/18467/1 "2021-07-01T18:08:28Z")

</div>

Is there a reason why the ConvertToGridTransform method outputs a vtkMRMLTransformNode instead of a vtkMRMLGridTransformNode?

[Slicer/Modules/Loadable/Transforms/Logic/vtkSlicerTransformLogic.h](https://github.com/Slicer/Slicer/blob/aaa9f918a4ee4f35bf09e05c5d7e53d083b2e4e3/Modules/Loadable/Transforms/Logic/vtkSlicerTransformLogic.h#L112)

I’m developing a [module](https://github.com/netstim/SlicerNetstim/tree/master/WarpDrive) that takes grid transforms as input. When implementing I tried to strictly take vtkMRMLGridTransformNode as input and this way might be more straightforward for the user.

I usually load non linear transforms that are loaded as grid transforms so there’s no problem. But I realised that if I wanted to this from within Slicer, vtkMRMLTransformNode are generated (and therefore not recognised as possible input).

Of course, this is easy to change on my side, but I wonder if there’s a reason for this. If not, I can also try to contribute a change.

Thanks

---

<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:** [July 2, 2021, 4:43am UTC](https://discourse.slicer.org/t/converttogridtransform-returns-vtkmrmltransformnode-instead-of-vtkmrmlgridtransformnode/18467/2 "2021-07-02T04:43:09Z")

</div>

This is a very good question.

There is a bit of history behind this: When MRML library was initially designed, different classes were added for linear, b-spline, and grid transforms. However, about 5-10 years ago when we implemented support for composite transforms (that can store an arbitrary set of concatenated transforms, each of them potentially inverted) then we realized that we cannot dynamically split and merge transforms if a transform object is statically assigned to a specific transform class. Therefore, we made the `vtkTransformNode` class to be a universal transform container, which can store linear, b-spline, grid, thin-plate-spline, and composite transforms. However, we did not remove the old classes because the class names were used for filtering in MRML node selectors in the user interfaces in many modules.

In the future, we’ll remove these classes and use node attributes to filter for transform types in node selectors - see this ticket:

> <https://github.com/Slicer/Slicer/issues/5718>
>
> When MRML library was initially designed, different classes were added for linea…r, b-spline, grid, and thin-plate-spline transforms. However, when we implemented support for composite transforms (that can store an arbitrary set of concatenated transforms each of them potentially inverted) we realized that we cannot dynamically split and merge transforms if a transform object is statically assigned to a specific transform class. Therefore, we made the \`vtkTransformNode\` class to be a universal transform container, which can store linear, b-spline, grid, thin-plate-spline, and composite transforms. However, we did not remove the old classes because the class names were used for filtering in MRML node selectors. This causes confusion for developers (see for example \[here\](https://discourse.slicer.org/t/converttogridtransform-returns-vtkmrmltransformnode-instead-of-vtkmrmlgridtransformnode/18467/2)).
> 
> We should remove the vtkMRMLLinearTransformNode, vtkMRMLBSplineTransformNode, and vtkMRMLGridTransformNode classes and set transform type into a custom attribute (Transforms.type = linear, bspline, grid, tps, composite; maybe also Transforms.linear = 0/1; and potentially Transforms.toWorldType, Transforms.toWorldLinear), which node selectors could use as filter criteria.
> 
> A slight difficulty is that determining transform type (especially transform type all the way up to the world coordinate system) may be expensive if the transform is changing frequently.

Until this is implemented, I would recommend to use vtkMRMLTransformNode class everywhere, and only use child classes if it is absolutely necessary.

---

<div class="post-metadata">

**Author:** ![simonoxen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/simonoxen/32/66398_2.png) [@simonoxen](https://discourse.slicer.org/u/simonoxen)\
**Post date:** [July 2, 2021, 6:19am UTC](https://discourse.slicer.org/t/converttogridtransform-returns-vtkmrmltransformnode-instead-of-vtkmrmlgridtransformnode/18467/3 "2021-07-02T06:19:18Z")

</div>

Thanks for the clarification! Will adopt this then
