ITK/Examples/IO/RegisterTransform: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(ITK4 api change)
(Deprecated content that is moved to sphinx)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
Not all transforms are automatically available due to the transform factory mechanism in ITK. To register a non-default transform, you can use the procedure below. For example, if you want to read this file:
{{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/*  pages likely require ITK version 4.13 or earlier releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.
 
}}
<source lang="text">
#Insight Transform File V1.0
#Transform 0
Transform: MatrixOffsetTransformBase_double_3_3
Parameters: 0.991654 0.00303429 0.0015616 -0.000274293 0.970948 0.261678 -0.00143037 -0.263587 0.953079 -0.546243 21.4937 -28.456
FixedParameters: -1.11311 -3.55441 16.6988
</source>
 
you must register MatrixOffsetTransformBase with the TransformFactory.
 
==RegisterTransform.cxx==
<source lang="cpp">
#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];
   }
 
  typedef itk::MatrixOffsetTransformBase< double, 3, 3 > MatrixOffsetTransformType;
  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 writer = itk::TransformFileReader::New();
#endif
  reader->SetFileName(fileName);
  reader->Update();
 
  std::cout << *(reader->GetTransformList()->begin()) << std::endl;
 
  return EXIT_SUCCESS;
}
</source>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 17:26, 4 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.