int main( int argc, char * argv[] )
{
if( argc < 2 )
{
std::cerr << "Usage: " << argv[0] << " transformFile" << std::endl;
return EXIT_FAILURE;
}
const char * transformFileName = argv[1];
using ScalarType = double;
CompositeTransformType::Pointer composite = CompositeTransformType::New();
AffineTransformType::Pointer affine = AffineTransformType::New();
AffineTransformType::InputPointType cor;
cor.Fill(12);
affine->SetCenter(cor);
composite->AddTransform( affine );
constexpr unsigned int SplineOrder = 5;
using BSplineTransformType =
using BSplineTransformFType =
BSplineTransformType::Pointer bspline = BSplineTransformType::New();
BSplineTransformType::OriginType origin;
origin.Fill( 100 );
BSplineTransformType::PhysicalDimensionsType dimensions;
dimensions.Fill( 1.5 * 9.0 );
bspline->SetTransformDomainOrigin( origin );
bspline->SetTransformDomainPhysicalDimensions( dimensions );
BSplineTransformType::ParametersType parameters( bspline->GetNumberOfParameters() );
bspline->SetParameters( parameters );
bspline->SetIdentity();
composite->AddTransform( bspline );
TransformWriterType::Pointer writer = TransformWriterType::New();
writer->SetInput( composite );
writer->SetFileName( transformFileName );
try
{
writer->Update();
}
{
std::cerr << "Error while saving the transforms" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
using ReadScalarType = float;
TransformReaderType::Pointer reader = TransformReaderType::New();
reader->SetFileName( transformFileName );
try
{
reader->Update();
}
{
std::cerr << "Error while reading the transform file" << std::endl;
std::cerr << excp << std::endl;
std::cerr << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}
const TransformReaderType::TransformListType * transforms =
reader->GetTransformList();
std::cout << "Number of transforms = " << transforms->size() << std::endl;
using ReadCompositeTransformType =
auto it = transforms->begin();
if( !strcmp((*it)->GetNameOfClass(),"CompositeTransform") )
{
ReadCompositeTransformType::Pointer compositeRead
= static_cast< ReadCompositeTransformType* >( (*it).GetPointer() );
compositeRead->
Print(std::cout);
}
return EXIT_SUCCESS;
}