Reading Arbitrary Transforms, Compute Something if Linear

I’m working on trying to extend the antsTransformInfo tool to print the Determinant of a transform if its Linear as part of its summary information.

The existing implementation is very very simple, a copy of an ITK example:

The transform IO seems to not need to know anything about the transform, not the dimension, nor the type, and immediately supports all the ITK transform types, and can print a summary.

I implemented a partial version for linear transforms, and I’ve already had to instantiate 2D and 3D handlers separately, and this doesn’t support unpacking a composite transform at the least, and probably has other corner cases where it will fall over.

Am I going about this the wrong way? Is there a better way? I want this to support reading arbitrary ITK transforms and print the summary object, and if it’s Linear, add the Determinant.

Or, is the better solution to add the Determinant to all Linear transform summaries in ITK?

Thanks for your advice…

I think the 2D vs 3D instantiation can be solved by templating over dimension.

For determining type, maybe this example would help?

https://itk.org/Doxygen/html/Examples_2IO_2TransformReadWrite_8cxx-example.html

  using ReadCompositeTransformType =
    itk::CompositeTransform<ReadScalarType, Dimension>;
  auto it = transforms->begin();
  if (!strcmp((*it)->GetNameOfClass(), "CompositeTransform"))
  {
    ReadCompositeTransformType::Pointer compositeRead =
      static_cast<ReadCompositeTransformType *>((*it).GetPointer());
    compositeRead->Print(std::cout);
  }

You can see the initial logic for loading an arbitrary Transform transforms here:

The SimpleITK Transform constructor ends up doing a dynamic cast to determine what is the concrete transform type.

:edit: Additionally, you probably only need to cast to “MatrixOffsetTransformBase” to support just about all of the linear ITK transforms.

1 Like

Thanks @blowekamp!

1 Like