#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();
}
{
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);
const 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();
}
{
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();
}
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Standard exception handling object.
Data source that reads image data from a single file.
Writes image data to a single file.
A multi-dimensional iterator templated over image type that walks a region of pixels.
Templated n-dimensional image class.
Linearly interpolate an image at specified positions.
A templated class holding a geometric point in n-Dimensional space.
Resample an image via a coordinate transform.
A templated class holding a n-Dimensional vector.
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
ImageBaseType::DirectionType DirectionType
ImageBaseType::RegionType RegionType
ImageBaseType::IndexType IndexType
ImageBaseType::PointType PointType
ImageBaseType::SizeType SizeType
const IndexValueType * GetIndex() const
const SizeValueType * GetSize() const