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

Merge branch 'ELASTIX-86-Wrap-itkv4-Optimizer' into develop

parents 54f96caa 3ed78f70
......@@ -53,12 +53,14 @@ namespace selx
typedef typename itk::ImageFileWriter<DeformationFieldImageType> DeformationFieldImageWriterType;
typedef FileWriterDecorator<DeformationFieldImageWriterType> DecoratedWriterType;
//Accepting Interfaces:
virtual int Set(AcceptingDisplacementFieldInterfaceType*) override;
virtual void SetMiniPipelineOutput(itk::DataObject::Pointer) override;
virtual itk::DataObject::Pointer GetMiniPipelineOutput(void) override;
virtual AnyFileWriter::Pointer GetOutputFileWriter(void) override;
virtual itk::DataObject::Pointer GetInitializedOutput(void) override;
//Providing Interfaces:
virtual void AfterRegistration() override;
virtual bool MeetsCriterion(const ComponentBase::CriterionType &criterion) override;
......
......@@ -43,7 +43,7 @@ namespace selx
// Store pointer to MiniPipelineOutputImage for later grafting onto Overlord output.
this->m_MiniPipelineOutputImage = other->GetDisplacementFieldItkImage();
// Graft Overlord output onto MiniPipelineOutputImage.
this->m_MiniPipelineOutputImage->Graft(this->m_OverlordOutputImage);
//this->m_MiniPipelineOutputImage->Graft(this->m_OverlordOutputImage);
return 0;
}
......
......@@ -45,7 +45,7 @@ namespace selx
typedef itk::Image<TPixel, Dimensionality> ItkImageType;
typedef typename itk::ImageFileReader<ItkImageType> ItkImageReaderType;
typedef typename FileReaderDecorator<ItkImageReaderType> DecoratedReaderType;
typedef FileReaderDecorator<ItkImageReaderType> DecoratedReaderType;
virtual typename ItkImageType::Pointer GetItkImage() override;
virtual void SetMiniPipelineInput(itk::DataObject::Pointer) override;
......
......@@ -33,7 +33,9 @@ namespace selx
class ItkImageSourceFixedComponent :
public Implements<
Accepting<>,
Providing< SourceInterface, itkImageFixedInterface<Dimensionality, TPixel > >
Providing< SourceInterface,
itkImageFixedInterface<Dimensionality, TPixel >,
itkImageDomainFixedInterface<Dimensionality>>
>
{
public:
......@@ -45,14 +47,19 @@ namespace selx
virtual ~ItkImageSourceFixedComponent();
typedef typename itkImageFixedInterface<Dimensionality, TPixel >::ItkImageType ItkImageType;
typedef typename itkImageDomainFixedInterface<Dimensionality>::ItkImageDomainType ItkImageDomainType;
typedef typename itk::ImageFileReader<ItkImageType> ItkImageReaderType;
typedef typename FileReaderDecorator<ItkImageReaderType> DecoratedReaderType;
typedef FileReaderDecorator<ItkImageReaderType> DecoratedReaderType;
// providing interfaces
virtual typename ItkImageType::Pointer GetItkImageFixed() override;
virtual void SetMiniPipelineInput(itk::DataObject::Pointer) override;
virtual AnyFileReader::Pointer GetInputFileReader(void) override;
virtual typename ItkImageDomainType::Pointer GetItkImageDomainFixed() override;
virtual bool MeetsCriterion(const ComponentBase::CriterionType &criterion) override;
static const char * GetDescription() { return "ItkImageSourceFixed Component"; };
private:
......
......@@ -65,6 +65,18 @@ namespace selx
return DecoratedReaderType::New().GetPointer();
}
template<int Dimensionality, class TPixel>
typename ItkImageSourceFixedComponent< Dimensionality, TPixel>::ItkImageDomainType::Pointer
ItkImageSourceFixedComponent< Dimensionality, TPixel>
::GetItkImageDomainFixed()
{
if (this->m_Image == nullptr)
{
itkExceptionMacro("SourceComponent needs to be initialized by SetMiniPipelineInput()");
}
return this->m_Image.GetPointer();
}
template<int Dimensionality, class TPixel>
bool
ItkImageSourceFixedComponent< Dimensionality, TPixel>
......
......@@ -46,7 +46,7 @@ namespace selx
typedef typename itkImageMovingInterface<Dimensionality, TPixel >::ItkImageType ItkImageType;
typedef typename itk::ImageFileReader<ItkImageType> ItkImageReaderType;
typedef typename FileReaderDecorator<ItkImageReaderType> DecoratedReaderType;
typedef FileReaderDecorator<ItkImageReaderType> DecoratedReaderType;
virtual typename ItkImageType::Pointer GetItkImageMoving() override;
virtual void SetMiniPipelineInput(itk::DataObject::Pointer) override;
......
......@@ -45,7 +45,7 @@ namespace selx
typedef itk::Mesh<TPixel, Dimensionality> ItkMeshType;
typedef typename itk::MeshFileReader<ItkMeshType> ItkMeshReaderType;
typedef typename FileReaderDecorator<ItkMeshReaderType> DecoratedReaderType;
typedef FileReaderDecorator<ItkMeshReaderType> DecoratedReaderType;
virtual typename ItkMeshType::Pointer GetItkMesh() override;
virtual void SetMiniPipelineInput(itk::DataObject::Pointer) override;
......
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef selxItkAffineTransformComponent_h
#define selxItkAffineTransformComponent_h
#include "ComponentBase.h"
#include "Interfaces.h"
#include "itkAffineTransform.h"
#include <string.h>
#include "selxMacro.h"
namespace selx
{
template <class InternalComputationValueType, int Dimensionality>
class ItkAffineTransformComponent :
public Implements<
Accepting< >,
Providing< itkTransformInterface<InternalComputationValueType,Dimensionality>>
>
{
public:
selxNewMacro(ItkAffineTransformComponent, ComponentBase);
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
ItkAffineTransformComponent();
virtual ~ItkAffineTransformComponent();
//typedef double InternalComputationValueType;
/** Type of the optimizer. */
using TransformType = typename itkTransformInterface<InternalComputationValueType,Dimensionality>::TransformType;
using TransformPointer = typename itkTransformInterface<InternalComputationValueType,Dimensionality>::TransformPointer;
typedef typename itk::AffineTransform<InternalComputationValueType, Dimensionality> AffineTransformType;
virtual TransformPointer GetItkTransform() override;
virtual bool MeetsCriterion(const ComponentBase::CriterionType &criterion) override;
//static const char * GetName() { return "ItkAffineTransform"; } ;
static const char * GetDescription() { return "ItkAffineTransform Component"; };
private:
typename AffineTransformType::Pointer m_Transform;
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
};
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkAffineTransform.hxx"
#endif
#endif // #define selxItkAffineTransformComponent_h
\ No newline at end of file
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "selxItkAffineTransform.h"
namespace selx
{
template<class InternalComputationValueType, int Dimensionality>
ItkAffineTransformComponent< InternalComputationValueType,Dimensionality>::ItkAffineTransformComponent()
{
m_Transform = AffineTransformType::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.
// we could choose to keep the component light weighted (for checking criteria such as names and connections) until the settings are passed to the filter, but this requires an additional initialization step.
}
template<class InternalComputationValueType, int Dimensionality>
ItkAffineTransformComponent< InternalComputationValueType, Dimensionality>::~ItkAffineTransformComponent()
{
}
template<class InternalComputationValueType, int Dimensionality>
typename ItkAffineTransformComponent< InternalComputationValueType, Dimensionality>::TransformPointer ItkAffineTransformComponent< InternalComputationValueType, Dimensionality>::GetItkTransform()
{
return (TransformPointer) this->m_Transform;
}
template<class InternalComputationValueType, int Dimensionality>
bool
ItkAffineTransformComponent< InternalComputationValueType, Dimensionality>
::MeetsCriterion(const ComponentBase::CriterionType &criterion)
{
bool hasUndefinedCriteria(false);
bool meetsCriteria(false);
if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
return meetsCriteria;
}
} //end namespace selx
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef selxItkGaussianExponentialDiffeomorphicTransformComponent_h
#define selxItkGaussianExponentialDiffeomorphicTransformComponent_h
#include "ComponentBase.h"
#include "Interfaces.h"
#include "itkGaussianExponentialDiffeomorphicTransform.h"
#include <string.h>
#include "selxMacro.h"
namespace selx
{
template <class InternalComputationValueType, int Dimensionality>
class ItkGaussianExponentialDiffeomorphicTransformComponent :
public Implements<
Accepting< itkImageDomainFixedInterface<Dimensionality> >,
Providing< itkTransformInterface<InternalComputationValueType,Dimensionality>,
RunRegistrationInterface>
>
{
public:
selxNewMacro(ItkGaussianExponentialDiffeomorphicTransformComponent, ComponentBase);
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
ItkGaussianExponentialDiffeomorphicTransformComponent();
virtual ~ItkGaussianExponentialDiffeomorphicTransformComponent();
/** Get types from interfaces */
using TransformType = typename itkTransformInterface<InternalComputationValueType,Dimensionality>::TransformType;
using TransformPointer = typename itkTransformInterface<InternalComputationValueType,Dimensionality>::TransformPointer;
using ItkImageDomainType = typename itkImageDomainFixedInterface<Dimensionality>::ItkImageDomainType;
using GaussianExponentialDiffeomorphicTransformType = typename itk::GaussianExponentialDiffeomorphicTransform<InternalComputationValueType, Dimensionality>;
//Accepting Interfaces:
virtual int Set(itkImageDomainFixedInterface<Dimensionality>*) override;
//Providing Interfaces:
virtual TransformPointer GetItkTransform() override;
virtual void RunRegistration() override;
//BaseClass methods
virtual bool MeetsCriterion(const ComponentBase::CriterionType &criterion) override;
//static const char * GetName() { return "ItkGaussianExponentialDiffeomorphicTransform"; } ;
static const char * GetDescription() { return "ItkGaussianExponentialDiffeomorphicTransform Component"; };
private:
typename GaussianExponentialDiffeomorphicTransformType::Pointer m_Transform;
typename ItkImageDomainType::Pointer m_FixedImageDomain;
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
};
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkGaussianExponentialDiffeomorphicTransform.hxx"
#endif
#endif // #define selxItkGaussianExponentialDiffeomorphicTransformComponent_h
\ No newline at end of file
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "selxItkGaussianExponentialDiffeomorphicTransform.h"
namespace selx
{
template<class InternalComputationValueType, int Dimensionality>
ItkGaussianExponentialDiffeomorphicTransformComponent< InternalComputationValueType,Dimensionality>::ItkGaussianExponentialDiffeomorphicTransformComponent()
{
m_Transform = GaussianExponentialDiffeomorphicTransformType::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.
// we could choose to keep the component light weighted (for checking criteria such as names and connections) until the settings are passed to the filter, but this requires an additional initialization step.
}
template<class InternalComputationValueType, int Dimensionality>
ItkGaussianExponentialDiffeomorphicTransformComponent< InternalComputationValueType, Dimensionality>::~ItkGaussianExponentialDiffeomorphicTransformComponent()
{
}
template<class InternalComputationValueType, int Dimensionality>
int ItkGaussianExponentialDiffeomorphicTransformComponent< InternalComputationValueType, Dimensionality>
::Set(itkImageDomainFixedInterface<Dimensionality>* component)
{
this->m_FixedImageDomain = component->GetItkImageDomainFixed();
auto displacementField = GaussianExponentialDiffeomorphicTransformType::DisplacementFieldType::New();
//auto zeroVector = itk::NumericTraits<GaussianExponentialDiffeomorphicTransformType::DisplacementFieldType::PixelType>::Zero();
auto zeroVector = typename GaussianExponentialDiffeomorphicTransformType::DisplacementFieldType::PixelType(0.0);
displacementField->CopyInformation(this->m_FixedImageDomain);
displacementField->SetRegions(this->m_FixedImageDomain->GetBufferedRegion());
displacementField->Allocate();
displacementField->FillBuffer(zeroVector);
m_Transform->SetGaussianSmoothingVarianceForTheUpdateField(3.0);
m_Transform->SetGaussianSmoothingVarianceForTheConstantVelocityField(6.0);
m_Transform->SetConstantVelocityField(displacementField);
m_Transform->SetCalculateNumberOfIntegrationStepsAutomatically(true);
m_Transform->IntegrateVelocityField();
return 0;
}
template<class InternalComputationValueType, int Dimensionality>
typename ItkGaussianExponentialDiffeomorphicTransformComponent< InternalComputationValueType, Dimensionality>::TransformPointer ItkGaussianExponentialDiffeomorphicTransformComponent< InternalComputationValueType, Dimensionality>::GetItkTransform()
{
return (TransformPointer) this->m_Transform;
}
template<class InternalComputationValueType, int Dimensionality>
void ItkGaussianExponentialDiffeomorphicTransformComponent< InternalComputationValueType, Dimensionality>::RunRegistration()
{
}
template<class InternalComputationValueType, int Dimensionality>
bool
ItkGaussianExponentialDiffeomorphicTransformComponent< InternalComputationValueType, Dimensionality>
::MeetsCriterion(const ComponentBase::CriterionType &criterion)
{
bool hasUndefinedCriteria(false);
bool meetsCriteria(false);
if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
else if (criterion.first == "Dimensionality") //Supports this?
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (std::stoi(criterionValue) != Dimensionality)
{
meetsCriteria = false;
}
}
}
return meetsCriteria;
}
} //end namespace selx
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef selxItkGradientDescentOptimizerv4Component_h
#define selxItkGradientDescentOptimizerv4Component_h
#include "ComponentBase.h"
#include "Interfaces.h"
#include "itkGradientDescentOptimizerv4.h"
#include <string.h>
#include "selxMacro.h"
namespace selx
{
template <class InternalComputationValueType>
class ItkGradientDescentOptimizerv4Component :
public Implements<
Accepting< >,
Providing< itkOptimizerv4Interface<InternalComputationValueType>>
>
{
public:
selxNewMacro(ItkGradientDescentOptimizerv4Component, ComponentBase);
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
ItkGradientDescentOptimizerv4Component();
virtual ~ItkGradientDescentOptimizerv4Component();
/** Type of the optimizer. */
typedef typename itk::ObjectToObjectOptimizerBaseTemplate<InternalComputationValueType> OptimizerType;
typedef typename OptimizerType::Pointer Optimizerv4Pointer;
typedef typename itk::GradientDescentOptimizerv4Template<InternalComputationValueType> GradientDescentOptimizerv4Type;
virtual Optimizerv4Pointer GetItkOptimizerv4() override;
virtual bool MeetsCriterion(const ComponentBase::CriterionType &criterion) override;
//static const char * GetName() { return "ItkGradientDescentOptimizerv4"; } ;
static const char * GetDescription() { return "ItkGradientDescentOptimizerv4 Component"; };
private:
typename GradientDescentOptimizerv4Type::Pointer m_Optimizer;
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
};
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkGradientDescentOptimizerv4.hxx"
#endif
#endif // #define selxItkGradientDescentOptimizerv4Component_h
\ No newline at end of file
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "selxItkGradientDescentOptimizerv4.h"
#include <boost/lexical_cast.hpp>
namespace selx
{
template<class InternalComputationValueType>
ItkGradientDescentOptimizerv4Component< InternalComputationValueType>::ItkGradientDescentOptimizerv4Component()
{
m_Optimizer = GradientDescentOptimizerv4Type::New();
m_Optimizer->SetNumberOfIterations(100);
m_Optimizer->SetLearningRate(1.0);
//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.
// we could choose to keep the component light weighted (for checking criteria such as names and connections) until the settings are passed to the filter, but this requires an additional initialization step.
}
template<class InternalComputationValueType>
ItkGradientDescentOptimizerv4Component< InternalComputationValueType>::~ItkGradientDescentOptimizerv4Component()
{
}
template<class InternalComputationValueType>
typename ItkGradientDescentOptimizerv4Component< InternalComputationValueType>::Optimizerv4Pointer ItkGradientDescentOptimizerv4Component< InternalComputationValueType>::GetItkOptimizerv4()
{
return (Optimizerv4Pointer) this->m_Optimizer;
}
template<class InternalComputationValueType>
bool
ItkGradientDescentOptimizerv4Component< InternalComputationValueType>
::MeetsCriterion(const ComponentBase::CriterionType &criterion)
{
bool hasUndefinedCriteria(false);
bool meetsCriteria(false);
if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples