Commit a2581c63 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: Removed TransformDisplacementFilter functionality from

RegistrationMethod.
parent bcf5d2b6
......@@ -46,7 +46,7 @@ namespace selx
itkOptimizerv4Interface<double>
>,
Providing< itkImageInterface<Dimensionality, TPixel>,
DisplacementFieldItkImageSourceInterface<Dimensionality, TPixel>,
itkTransformInterface<double, Dimensionality>,
RunRegistrationInterface
>
>
......@@ -60,26 +60,24 @@ namespace selx
virtual ~ItkImageRegistrationMethodv4Component();
typedef TPixel PixelType;
typedef itkOptimizerv4Interface<double>::InternalComputationValueType InternalComputationValueType;
// the in and output image type of the component are chosen to be the same
typedef itk::Image<PixelType, Dimensionality> ConnectionImageType;
// fixed and moving image types are all the same, these aliases can be used to be explicit.
// Get the type definitions from the interfaces
typedef typename itkImageFixedInterface<Dimensionality, TPixel>::ItkImageType FixedImageType;
typedef typename itkImageMovingInterface<Dimensionality, TPixel>::ItkImageType MovingImageType;
typedef typename itk::Image<itk::Vector<PixelType, Dimensionality>, Dimensionality> DisplacementFieldImageType;
typedef typename itkTransformInterface<double, Dimensionality>::TransformPointer TransformPointer;
typedef typename itkOptimizerv4Interface<double>::InternalComputationValueType InternalComputationValueType;
typedef typename itkImageInterface<Dimensionality, TPixel>::ItkImageType ResultItkImageType;
// TODO for now we hard code the transform to be a stationary velocity field. See Set(*MetricInterface) for implementation
typedef double RealType;
typedef itk::GaussianExponentialDiffeomorphicTransform<RealType, Dimensionality> ConstantVelocityFieldTransformType;
typedef itk::ImageRegistrationMethodv4<FixedImageType, MovingImageType, ConstantVelocityFieldTransformType> TheItkFilterType;
//typedef itk::ImageRegistrationMethodv4<FixedImageType, MovingImageType, ConstantVelocityFieldTransformType> TheItkFilterType;
typedef itk::ImageRegistrationMethodv4<FixedImageType, MovingImageType> TheItkFilterType;
typedef typename TheItkFilterType::ImageMetricType ImageMetricType;
typedef itk::RegistrationParameterScalesFromPhysicalShift<ImageMetricType> ScalesEstimatorType;
typedef itk::ResampleImageFilter<MovingImageType, ConnectionImageType> ResampleFilterType;
typedef itk::TransformToDisplacementFieldFilter<DisplacementFieldImageType> DisplacementFieldFilterType;
typedef itk::ResampleImageFilter<MovingImageType, ResultItkImageType> ResampleFilterType;
//typedef itk::TransformToDisplacementFieldFilter<DisplacementFieldImageType> DisplacementFieldFilterType;
//Accepting Interfaces:
virtual int Set(itkImageFixedInterface<Dimensionality, TPixel>*) override;
......@@ -89,7 +87,8 @@ namespace selx
//Providing Interfaces:
virtual typename ResultItkImageType::Pointer GetItkImage() override;
virtual typename DisplacementFieldImageType::Pointer GetDisplacementFieldItkImage() override;
virtual TransformPointer GetItkTransform() override;
//virtual typename DisplacementFieldImageType::Pointer GetDisplacementFieldItkImage() override;
virtual void RunRegistration() override;
......@@ -100,7 +99,6 @@ namespace selx
private:
typename TheItkFilterType::Pointer m_theItkFilter;
typename ResampleFilterType::Pointer m_resampler;
typename DisplacementFieldFilterType::Pointer m_DisplacementFieldFilter;
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
......
......@@ -122,10 +122,15 @@ namespace selx
{
m_theItkFilter = TheItkFilterType::New();
m_resampler = ResampleFilterType::New();
m_DisplacementFieldFilter = DisplacementFieldFilterType::New();
//m_DisplacementFieldFilter = DisplacementFieldFilterType::New();
//m_DisplacementFieldFilter->GetTransformInput()->Graft<ConstantVelocityFieldTransformType>(&(const_cast<ConstantVelocityFieldTransformType>( m_theItkFilter->GetOutput())));
//m_DisplacementFieldFilter->GetTransformInput()->Graft(m_theItkFilter->GetOutput());
ConstantVelocityFieldTransformType::Pointer transform = ConstantVelocityFieldTransformType::New();
m_theItkFilter->SetInitialTransform(transform);
m_theItkFilter->InPlaceOff();
typename itk::DataObjectDecorator<typename ConstantVelocityFieldTransformType::Superclass::Superclass::Superclass>::Pointer decoratedDummyTransform = itk::DataObjectDecorator<typename ConstantVelocityFieldTransformType::Superclass::Superclass::Superclass>::New();
typename ConstantVelocityFieldTransformType::Pointer dummyTranform = ConstantVelocityFieldTransformType::New();
decoratedDummyTransform->Set(dummyTranform);
......@@ -133,7 +138,7 @@ namespace selx
//decoratedTransform->Set(m_theItkFilter->GetOutput()->Get());
//m_DisplacementFieldFilter->SetTransformInput(const_cast< itk::DataObjectDecorator<ConstantVelocityFieldTransformType::Superclass::Superclass::Superclass>*>(decoratedTransform));
m_DisplacementFieldFilter->SetTransformInput(decoratedDummyTransform);
//m_DisplacementFieldFilter->SetTransformInput(decoratedDummyTransform);
//m_theItkFilter->GetOutput()->Graft(m_DisplacementFieldFilter->GetTransformInput());
//m_DisplacementFieldFilter->GetTransformInput()->Graft(decoratedTransform);
......@@ -157,13 +162,6 @@ int ItkImageRegistrationMethodv4Component< Dimensionality, TPixel>
// connect the itk pipeline
this->m_theItkFilter->SetFixedImage(fixedImage);
//this->m_DisplacementFieldFilter->SetSize(fixedImage->GetBufferedRegion().GetSize()); //should be virtual image...
this->m_DisplacementFieldFilter->SetSize(fixedImage->GetLargestPossibleRegion().GetSize()); //should be virtual image...
this->m_DisplacementFieldFilter->SetOutputOrigin(fixedImage->GetOrigin());
this->m_DisplacementFieldFilter->SetOutputSpacing(fixedImage->GetSpacing());
this->m_DisplacementFieldFilter->SetOutputDirection(fixedImage->GetDirection());
this->m_DisplacementFieldFilter->UpdateOutputInformation();
//this->m_resampler->SetSize(fixedImage->GetBufferedRegion().GetSize()); //should be virtual image...
this->m_resampler->SetSize(fixedImage->GetLargestPossibleRegion().GetSize()); //should be virtual image...
this->m_resampler->SetOutputOrigin(fixedImage->GetOrigin());
......@@ -419,18 +417,6 @@ void ItkImageRegistrationMethodv4Component< Dimensionality, TPixel>::RunRegistra
//this->m_DisplacementFieldFilter->SetTransform(inversetranform);
//this->m_DisplacementFieldFilter->SetTransform(fieldTransform);
this->m_DisplacementFieldFilter->SetTransform(forwardDisplacement);
//this->m_DisplacementFieldFilter->SetTransform(this->m_theItkFilter->GetTransformOutput()->Get());
this->m_DisplacementFieldFilter->SetSize(fixedImage->GetBufferedRegion().GetSize()); //should be virtual image...
this->m_DisplacementFieldFilter->SetOutputOrigin(fixedImage->GetOrigin());
this->m_DisplacementFieldFilter->SetOutputSpacing(fixedImage->GetSpacing());
this->m_DisplacementFieldFilter->SetOutputDirection(fixedImage->GetDirection());
this->m_DisplacementFieldFilter->SetReferenceImage(fixedImage);
// TODO: is this needed?
this->m_DisplacementFieldFilter->Update();
}
template<int Dimensionality, class TPixel>
......@@ -443,12 +429,13 @@ ItkImageRegistrationMethodv4Component< Dimensionality, TPixel>
template<int Dimensionality, class TPixel>
typename ItkImageRegistrationMethodv4Component< Dimensionality, TPixel>::DisplacementFieldImageType::Pointer
typename ItkImageRegistrationMethodv4Component< Dimensionality, TPixel>::TransformPointer
ItkImageRegistrationMethodv4Component< Dimensionality, TPixel>
::GetDisplacementFieldItkImage()
::GetItkTransform()
{
return this->m_DisplacementFieldFilter->GetOutput();
//return this->m_theItkFilter->GetOutput().GetPointer();
return this->m_theItkFilter->GetModifiableTransform();
}
......
......@@ -38,7 +38,7 @@
namespace selx
{
template <int Dimensionality, class TPixel, class TInternalComputationValue>
class ItkTransformDisplacementFilter :
class ItkTransformDisplacementFilterComponent :
public Implements<
Accepting< itkTransformInterface<TInternalComputationValue, Dimensionality>,
itkImageFixedInterface<Dimensionality, TPixel> //TODO should be FixedImageDomainInterface, we do not require intensities
......@@ -48,18 +48,18 @@ namespace selx
>
{
public:
selxNewMacro(ItkTransformDisplacementFilter, ComponentBase);
selxNewMacro(ItkTransformDisplacementFilterComponent, ComponentBase);
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
ItkTransformDisplacementFilter();
virtual ~ItkTransformDisplacementFilter();
ItkTransformDisplacementFilterComponent();
virtual ~ItkTransformDisplacementFilterComponent();
typedef TPixel PixelType;
// Get the type definitions from the interfaces
typedef typename itkImageFixedInterface<Dimensionality, TPixel>::ItkImageType FixedImageType;
typedef typename DisplacementFieldItkImageSourceInterface<Dimensionality, TPixel>::ItkImageType DisplacementFieldImageType;
typedef typename DisplacementFieldItkImageSourceInterface<Dimensionality, TPixel>::ItkImageType DisplacementFieldImageType;
// TODO for now we hard code the transform to be a stationary velocity field. See Set(*MetricInterface) for implementation
......@@ -119,7 +119,7 @@ namespace selx
template <>
inline const std::string
ItkTransformDisplacementFilter<2, float, double>
ItkTransformDisplacementFilterComponent<2, float, double>
::GetPixelTypeNameString()
{
return std::string("float");
......@@ -128,7 +128,7 @@ namespace selx
template <>
inline const std::string
ItkTransformDisplacementFilter<2, double, double>
ItkTransformDisplacementFilterComponent<2, double, double>
::GetPixelTypeNameString()
{
return std::string("double");
......@@ -136,7 +136,7 @@ namespace selx
template <>
inline const std::string
ItkTransformDisplacementFilter<3, float, double>
ItkTransformDisplacementFilterComponent<3, float, double>
::GetPixelTypeNameString()
{
return std::string("float");
......@@ -144,14 +144,14 @@ namespace selx
template <>
inline const std::string
ItkTransformDisplacementFilter<3, double, double>
ItkTransformDisplacementFilterComponent<3, double, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
template <>
inline const std::string
ItkTransformDisplacementFilter<2, float, double>
ItkTransformDisplacementFilterComponent<2, float, double>
::GetTypeNameString()
{
return std::string("2_float");
......@@ -159,7 +159,7 @@ namespace selx
template <>
inline const std::string
ItkTransformDisplacementFilter<2, double, double>
ItkTransformDisplacementFilterComponent<2, double, double>
::GetTypeNameString()
{
return std::string("2_double");
......@@ -167,7 +167,7 @@ namespace selx
template <>
inline const std::string
ItkTransformDisplacementFilter<3, float, double>
ItkTransformDisplacementFilterComponent<3, float, double>
::GetTypeNameString()
{
return std::string("3_float");
......@@ -175,7 +175,7 @@ namespace selx
template <>
inline const std::string
ItkTransformDisplacementFilter<3, double, double>
ItkTransformDisplacementFilterComponent<3, double, double>
::GetTypeNameString()
{
return std::string("3_double");
......
......@@ -23,7 +23,7 @@ namespace selx
{
template <int Dimensionality, class TPixel, class TInternalComputationValue>
ItkTransformDisplacementFilter< Dimensionality, TPixel, TInternalComputationValue>::ItkTransformDisplacementFilter()
ItkTransformDisplacementFilterComponent< Dimensionality, TPixel, TInternalComputationValue>::ItkTransformDisplacementFilterComponent()
{
m_DisplacementFieldFilter = DisplacementFieldFilterType::New();
//TODO: instantiating the filter in the constructor might be heavy for the use in component selector factory, since all components of the database are created during the selection process.
......@@ -31,12 +31,12 @@ namespace selx
}
template <int Dimensionality, class TPixel, class TInternalComputationValue>
ItkTransformDisplacementFilter< Dimensionality, TPixel, TInternalComputationValue>::~ItkTransformDisplacementFilter()
ItkTransformDisplacementFilterComponent< Dimensionality, TPixel, TInternalComputationValue>::~ItkTransformDisplacementFilterComponent()
{
}
template <int Dimensionality, class TPixel, class TInternalComputationValue>
int ItkTransformDisplacementFilter< Dimensionality, TPixel, TInternalComputationValue>
int ItkTransformDisplacementFilterComponent< Dimensionality, TPixel, TInternalComputationValue>
::Set(itkImageFixedInterface<Dimensionality, TPixel>* component)
{
auto fixedImage = component->GetItkImageFixed();
......@@ -52,7 +52,7 @@ int ItkTransformDisplacementFilter< Dimensionality, TPixel, TInternalComputation
}
template <int Dimensionality, class TPixel, class TInternalComputationValue>
int ItkTransformDisplacementFilter< Dimensionality, TPixel, TInternalComputationValue>
int ItkTransformDisplacementFilterComponent< Dimensionality, TPixel, TInternalComputationValue>
::Set(itkTransformInterface<TInternalComputationValue, Dimensionality >* component)
{
auto transform = component->GetItkTransform();
......@@ -64,8 +64,8 @@ int ItkTransformDisplacementFilter< Dimensionality, TPixel, TInternalComputation
template <int Dimensionality, class TPixel, class TInternalComputationValue>
typename ItkTransformDisplacementFilter< Dimensionality, TPixel, TInternalComputationValue>::DisplacementFieldImageType::Pointer
ItkTransformDisplacementFilter< Dimensionality, TPixel, TInternalComputationValue>
typename ItkTransformDisplacementFilterComponent< Dimensionality, TPixel, TInternalComputationValue>::DisplacementFieldImageType::Pointer
ItkTransformDisplacementFilterComponent< Dimensionality, TPixel, TInternalComputationValue>
::GetDisplacementFieldItkImage()
{
......@@ -75,7 +75,7 @@ ItkTransformDisplacementFilter< Dimensionality, TPixel, TInternalComputationValu
template <int Dimensionality, class TPixel, class TInternalComputationValue>
bool
ItkTransformDisplacementFilter< Dimensionality, TPixel, TInternalComputationValue>
ItkTransformDisplacementFilterComponent< Dimensionality, TPixel, TInternalComputationValue>
::MeetsCriterion(const ComponentBase::CriterionType &criterion)
{
bool hasUndefinedCriteria(false);
......
......@@ -88,7 +88,8 @@ public:
ItkMeanSquaresImageToImageMetricv4Component < 2, float >,
ItkGradientDescentOptimizerv4Component<double>,
ItkAffineTransformComponent<double,3>,
ItkTransformDisplacementFilter<2, float, double >> RegisterComponents;
ItkTransformDisplacementFilterComponent<2, float, double >,
ItkTransformDisplacementFilterComponent<3, double, double >> RegisterComponents;
typedef SuperElastixFilter<RegisterComponents> SuperElastixFilterType;
......@@ -386,6 +387,10 @@ TEST_F(RegistrationItkv4Test, DisplacementField)
component5Parameters["Dimensionality"] = { "3" }; // should be derived from the inputs
blueprint->AddComponent("Metric", component5Parameters);
ParameterMapType component6Parameters;
component6Parameters["NameOfClass"] = { "ItkTransformDisplacementFilterComponent" };
component6Parameters["Dimensionality"] = { "3" }; // should be derived from the outputs
blueprint->AddComponent("TransformDisplacementFilter", component6Parameters);
ParameterMapType connection1Parameters;
connection1Parameters["NameOfInterface"] = { "itkImageFixedInterface" };
......@@ -401,12 +406,15 @@ TEST_F(RegistrationItkv4Test, DisplacementField)
ParameterMapType connection4Parameters;
connection4Parameters["NameOfInterface"] = { "DisplacementFieldItkImageSourceInterface" };
blueprint->AddConnection("RegistrationMethod", "ResultDisplacementFieldSink", connection4Parameters);
blueprint->AddConnection("TransformDisplacementFilter", "ResultDisplacementFieldSink", connection4Parameters);
ParameterMapType connection5Parameters;
connection5Parameters["NameOfInterface"] = { "itkMetricv4Interface" };
blueprint->AddConnection("Metric", "RegistrationMethod", connection5Parameters);
blueprint->AddConnection("RegistrationMethod", "TransformDisplacementFilter", { {} });
blueprint->AddConnection("FixedImageSource", "TransformDisplacementFilter", { {} });
// Instantiate SuperElastix
SuperElastixFilterType::Pointer superElastixFilter;
EXPECT_NO_THROW(superElastixFilter = SuperElastixFilterType::New());
......
......@@ -236,6 +236,7 @@ protected:
//{
//};
//TODO rename Implements to SuperElastixComponent
template<typename AcceptingInterfaces, typename ProvidingInterfaces>
class Implements : public AcceptingInterfaces, public ProvidingInterfaces, public ComponentBase
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment