int
main(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0]
<< " inputImageFile inputDisplacementField outputImageFile"
<< std::endl;
return EXIT_FAILURE;
}
using VectorComponentType = float;
using PixelType = unsigned char;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName(argv[1]);
writer->SetFileName(argv[3]);
FieldReaderType::Pointer fieldReader = FieldReaderType::New();
fieldReader->SetFileName(argv[2]);
fieldReader->Update();
DisplacementFieldType::ConstPointer deformationField =
fieldReader->GetOutput();
using FilterType =
FilterType::Pointer filter = FilterType::New();
using InterpolatorType =
InterpolatorType::Pointer interpolator = InterpolatorType::New();
filter->SetInterpolator(interpolator);
filter->SetOutputSpacing(deformationField->GetSpacing());
filter->SetOutputOrigin(deformationField->GetOrigin());
filter->SetOutputDirection(deformationField->GetDirection());
filter->SetDisplacementField(deformationField);
filter->SetInput(reader->GetOutput());
writer->SetInput(filter->GetOutput());
try
{
writer->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
}
return EXIT_SUCCESS;
}