ConvertToGridTransform returns vtkMRMLTransformNode instead of vtkMRMLGridTransformNode

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

Slicer/Modules/Loadable/Transforms/Logic/vtkSlicerTransformLogic.h

I’m developing a module 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

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:

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

1 Like

Thanks for the clarification! Will adopt this then