#include <iostream>
#include <cstdlib>
namespace
{
unsigned int RmsCounter = 0;
double MaxRmsE[4] = { 0.8, 0.75, 0.4, 0.2 };
}
{
public:
using Self = CommandIterationUpdate;
protected:
CommandIterationUpdate() = default;
using PixelType = short;
using InternalPixelType = float;
using RegistrationFilterType =
InternalImageType,
DisplacementFieldType>;
public:
void
{
std::cout << "Warning: The const Execute method shouldn't be called"
<< std::endl;
}
void
{
auto * filter = static_cast<RegistrationFilterType *>(caller);
if (!(itk::IterationEvent().CheckEvent(&event)))
{
return;
}
if (filter)
{
filter->SetMaximumRMSError(MaxRmsE[RmsCounter]);
std::cout << filter->GetMetric()
<< " RMS Change: " << filter->GetRMSChange() << std::endl;
std::cout << "Level Tolerance= " << filter->GetMaximumRMSError()
<< std::endl;
}
}
};
{
public:
using Self = CommandResolutionLevelUpdate;
protected:
CommandResolutionLevelUpdate() = default;
public:
void
{
}
void
{
std::cout << "----------------------------------" << std::endl;
RmsCounter = RmsCounter + 1;
std::cout << "----------------------------------" << std::endl;
}
};
int
main(int argc, char * argv[])
{
if (argc != 5)
{
std::cerr << "usage: " << std::endl;
std::cerr << argv[0]
<< " fixedImage movingImage registeredImage deformationField"
<< std::endl;
return EXIT_FAILURE;
}
using PixelType = short;
using InternalPixelType = float;
targetReader->SetFileName(argv[1]);
targetReader->Update();
sourceReader->SetFileName(argv[2]);
sourceReader->Update();
targetImageCaster->SetInput(targetReader->GetOutput());
sourceImageCaster->SetInput(sourceReader->GetOutput());
using MatchingFilterType =
matcher->SetInput(sourceImageCaster->GetOutput());
matcher->SetReferenceImage(targetImageCaster->GetOutput());
matcher->SetNumberOfHistogramLevels(1024);
matcher->SetNumberOfMatchPoints(7);
matcher->ThresholdAtMeanIntensityOn();
using RegistrationFilterType =
InternalImageType,
DisplacementFieldType>;
filter->SetStandardDeviations(1.0);
filter->AddObserver(itk::IterationEvent(), observer);
using MultiResRegistrationFilterType =
InternalImageType,
DisplacementFieldType>;
multires->SetRegistrationFilter(filter);
multires->SetNumberOfLevels(4);
multires->SetFixedImage(targetImageCaster->GetOutput());
multires->SetMovingImage(matcher->GetOutput());
unsigned int nIterations[4] = { 40, 40, 32, 32 };
multires->SetNumberOfIterations(nIterations);
multires->AddObserver(itk::IterationEvent(), levelobserver);
try
{
multires->Update();
}
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
using DisplacementFieldTransformType =
displacementTransform->SetDisplacementField(multires->GetOutput());
using InterpolatorPrecisionType = double;
ImageType,
InterpolatorPrecisionType,
InternalPixelType>;
using InterpolatorType =
warper->SetInput(sourceReader->GetOutput());
warper->SetInterpolator(interpolator);
warper->SetOutputSpacing(targetImage->GetSpacing());
warper->SetOutputOrigin(targetImage->GetOrigin());
warper->SetOutputDirection(targetImage->GetDirection());
warper->SetTransform(displacementTransform);
writer->SetFileName(argv[3]);
writer->SetInput(warper->GetOutput());
try
{
writer->Update();
}
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
defwriter->SetFileName(argv[4]);
defwriter->SetInput(multires->GetOutput());
try
{
defwriter->Update();
}
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}