#include <fstream>
int
main(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " landmarksFile inputImage ";
std::cerr << "DeformedImage " << std::endl;
std::cerr << "deformationField" << std::endl;
return EXIT_FAILURE;
}
constexpr unsigned int ImageDimension = 3;
using PixelType = unsigned char;
using CoordinateRepType = double;
using TransformType =
using PointSetType = TransformType::PointSetType;
using PointIdType = PointSetType::PointIdentifier;
using ResamplerType =
using InterpolatorType =
reader->SetFileName(argv[2]);
try
{
reader->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
sourceLandMarks->GetPoints();
targetLandMarks->GetPoints();
PointIdType id{};
std::ifstream infile;
infile.open(argv[1]);
while (!infile.eof())
{
infile >> p1[0] >> p1[1] >> p1[2] >> p2[0] >> p2[1] >> p2[2];
sourceLandMarkContainer->InsertElement(id, p1);
targetLandMarkContainer->InsertElement(id++, p2);
}
infile.close();
tps->SetSourceLandmarks(sourceLandMarks);
tps->SetTargetLandmarks(targetLandMarks);
tps->ComputeWMatrix();
resampler->SetInterpolator(interpolator);
InputImageType::SpacingType spacing = inputImage->GetSpacing();
resampler->SetOutputSpacing(spacing);
resampler->SetOutputDirection(direction);
resampler->SetOutputOrigin(origin);
resampler->SetSize(size);
resampler->SetTransform(tps);
resampler->SetOutputStartIndex(region.GetIndex());
resampler->SetInput(reader->GetOutput());
deformedImageWriter->SetInput(resampler->GetOutput());
deformedImageWriter->SetFileName(argv[3]);
try
{
deformedImageWriter->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
field->SetRegions(region);
field->SetOrigin(origin);
field->SetSpacing(spacing);
field->Allocate();
FieldIterator fi(field, region);
fi.GoToBegin();
TransformType::InputPointType point1;
TransformType::OutputPointType point2;
FieldVectorType displacement;
while (!fi.IsAtEnd())
{
field->TransformIndexToPhysicalPoint(index, point1);
point2 = tps->TransformPoint(point1);
for (unsigned int i = 0; i < ImageDimension; ++i)
{
displacement[i] = point2[i] - point1[i];
}
fi.Set(displacement);
++fi;
}
fieldWriter->SetFileName(argv[4]);
fieldWriter->SetInput(field);
try
{
fieldWriter->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}