Register Transform With Transform Factory#

Synopsis#

Register a non-default transform with the transform factory.

Results#

Warning

Fix Errors Example contains errors needed to be fixed for proper output.

Code#

C++#

#include "itkTransformFileReader.h"
#include "itkTransformFactoryBase.h"
#include "itkTransformFactory.h"
#include "itkMatrixOffsetTransformBase.h"

int
main(int argc, char * argv[])
{
  std::string fileName;
  if (argc == 1) // No arguments were provided
  {
    fileName = "test.tfm";
  }
  else
  {
    fileName = argv[1];
  }

  using MatrixOffsetTransformType = itk::MatrixOffsetTransformBase<double, 3, 3>;
  itk::TransformFactory<MatrixOffsetTransformType>::RegisterTransform();

#if (ITK_VERSION_MAJOR == 4 && ITK_VERSION_MINOR >= 5) || ITK_VERSION_MAJOR > 4
  itk::TransformFileReaderTemplate<float>::Pointer reader = itk::TransformFileReaderTemplate<float>::New();
#else
  itk::TransformFileReader::Pointer reader = itk::TransformFileReader::New();
#endif
  reader->SetFileName(fileName);
  reader->Update();

  std::cout << *(reader->GetTransformList()->begin()) << std::endl;

  return EXIT_SUCCESS;
}

Classes demonstrated#

template<typename T>
class TransformFactory : public itk::TransformFactoryBase

Create instances of Transforms.

/sphinx /sphinxexample{IO/TransformFactory/RegisterTransformWithTransformFactory,Register Transform With Transform Factory} /endsphinx

See itk::TransformFactory for additional documentation.