Skip to content
Snippets Groups Projects
Commit f13d4597 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: added MeanSquaresMetricv4 Component and Test

parent b63fafa7
No related branches found
No related tags found
No related merge requests found
#ifndef selxItkMeanSquaresImageToImageMetricv4Component_h
#define selxItkMeanSquaresImageToImageMetricv4Component_h
#include "ComponentBase.h"
#include "Interfaces.h"
#include "itkMeanSquaresImageToImageMetricv4.h"
#include <string.h>
#include "elxMacro.h"
namespace selx
{
template <int Dimensionality, class TPixel>
class ItkMeanSquaresImageToImageMetricv4Component :
public Implements<
Accepting< >,
Providing< itkMetricv4Interface<Dimensionality, TPixel>>
>
{
public:
elxNewMacro(ItkMeanSquaresImageToImageMetricv4Component, ComponentBase);
itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
ItkMeanSquaresImageToImageMetricv4Component();
virtual ~ItkMeanSquaresImageToImageMetricv4Component();
typedef TPixel PixelType;
// fixed and moving image types are all the same, these aliases can be used to be explicit.
typedef itk::Image<PixelType, Dimensionality> FixedImageType;
typedef itk::Image<PixelType, Dimensionality> MovingImageType;
typedef typename itk::ImageToImageMetricv4<FixedImageType, MovingImageType> ImageToImageMetricv4Type;
//typedef typename ItkMetricv4Interface<Dimensionality, TPixel>::ImageToImageMetricv4Type ImageToImageMetricv4Type;
//typedef ItkMetricv4Interface<Dimensionality, TPixel>::ImageToImageMetricv4Type ItkMetricv4Pointer
typedef typename ImageToImageMetricv4Type::Pointer ItkMetricv4Pointer;
typedef typename itk::ANTSNeighborhoodCorrelationImageToImageMetricv4<FixedImageType, MovingImageType> TheItkFilterType;
virtual typename ItkMetricv4Pointer GetItkMetricv4() override;
virtual bool MeetsCriterion(const CriterionType &criterion) override;
//static const char * GetName() { return "ItkMeanSquaresImageToImageMetricv4"; } ;
static const char * GetDescription() { return "ItkMeanSquaresImageToImageMetricv4 Component"; };
private:
typename TheItkFilterType::Pointer m_theItkFilter;
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
static inline const std::string GetTypeNameString()
{
itkGenericExceptionMacro(<< "Unknown ScalarType" << typeid(TPixel).name());
// TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
// We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
}
static inline const std::string GetPixelTypeNameString()
{
itkGenericExceptionMacro(<< "Unknown PixelType" << typeid(TPixel).name());
// TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
// We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
}
};
// unfortunately partial specialization of member functions is not allowed, without partially specializing the entire class.
/*
template <int Dimensionality>
class ItkMeanSquaresImageToImageMetricv4Component < Dimensionality, double >
{
static inline const std::string GetPixelTypeNameString();
};
template <int Dimensionality>
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component<Dimensionality, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
*/
template <>
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component<2, float>
::GetPixelTypeNameString()
{
return std::string("float");
}
template <>
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component<2, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
template <>
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component<3, float>
::GetPixelTypeNameString()
{
return std::string("float");
}
template <>
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component<3, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
template <>
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component<2, float>
::GetTypeNameString()
{
return std::string("2_float");
}
template <>
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component<2, double>
::GetTypeNameString()
{
return std::string("2_double");
}
template <>
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component<3,float>
::GetTypeNameString()
{
return std::string("3_float");
}
template <>
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component<3,double>
::GetTypeNameString()
{
return std::string("3_double");
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkMeanSquaresImageToImageMetricv4.hxx"
#endif
#endif // #define GDOptimizer3rdPartyComponent_h
\ No newline at end of file
#include "selxItkMeanSquaresImageToImageMetricv4.h"
namespace selx
{
template<int Dimensionality, class TPixel>
ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel>::ItkMeanSquaresImageToImageMetricv4Component()
{
m_theItkFilter = TheItkFilterType::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<int Dimensionality, class TPixel>
ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel>::~ItkMeanSquaresImageToImageMetricv4Component()
{
}
template<int Dimensionality, class TPixel>
typename ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel>::ItkMetricv4Pointer ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel>::GetItkMetricv4()
{
return (ItkMetricv4Pointer) this->m_theItkFilter;
}
template<int Dimensionality, class TPixel>
bool
ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel>
::MeetsCriterion(const 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) != Self::Dimensionality)
{
meetsCriteria = false;
}
}
}
else if (criterion.first == "PixelType") //Supports this?
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != Self::GetPixelTypeNameString())
{
meetsCriteria = false;
}
}
}
return meetsCriteria;
}
} //end namespace selx
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "selxItkImageRegistrationMethodv4Component.h" #include "selxItkImageRegistrationMethodv4Component.h"
#include "selxItkANTSNeighborhoodCorrelationImageToImageMetricv4.h" #include "selxItkANTSNeighborhoodCorrelationImageToImageMetricv4.h"
#include "selxItkMeanSquaresImageToImageMetricv4.h"
#include "selxItkImageSourceFixed.h" #include "selxItkImageSourceFixed.h"
#include "selxItkImageSourceMoving.h" #include "selxItkImageSourceMoving.h"
...@@ -56,7 +57,7 @@ public: ...@@ -56,7 +57,7 @@ public:
ComponentFactory<ItkImageRegistrationMethodv4Component<3, double>>::RegisterOneFactory(); ComponentFactory<ItkImageRegistrationMethodv4Component<3, double>>::RegisterOneFactory();
ComponentFactory<ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component<3, double>>::RegisterOneFactory(); ComponentFactory<ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component<3, double>>::RegisterOneFactory();
ComponentFactory<ItkMeanSquaresImageToImageMetricv4Component<3, double>>::RegisterOneFactory();
} }
virtual void TearDown() { virtual void TearDown() {
...@@ -158,8 +159,57 @@ TEST_F(RegistrationItkv4Test, WithANTSCCMetric) ...@@ -158,8 +159,57 @@ TEST_F(RegistrationItkv4Test, WithANTSCCMetric)
bool allUniqueComponents; bool allUniqueComponents;
EXPECT_NO_THROW(allUniqueComponents = overlord->Configure()); EXPECT_NO_THROW(allUniqueComponents = overlord->Configure());
EXPECT_TRUE(allUniqueComponents); EXPECT_TRUE(allUniqueComponents);
//EXPECT_NO_THROW(overlord->Execute()); EXPECT_NO_THROW(overlord->Execute());
overlord->Execute(); //overlord->Execute();
} }
TEST_F(RegistrationItkv4Test, WithMeanSquaresMetric)
{
/** make example blueprint configuration */
blueprint = Blueprint::New();
ParameterMapType component0Parameters;
component0Parameters["NameOfClass"] = { "ItkImageRegistrationMethodv4Component" };
ComponentIndexType index0 = blueprint->AddComponent(component0Parameters);
ParameterMapType component1Parameters;
component1Parameters["NameOfClass"] = { "ItkImageSourceFixedComponent" };
ComponentIndexType index1 = blueprint->AddComponent(component1Parameters);
ParameterMapType component2Parameters;
component2Parameters["NameOfClass"] = { "ItkImageSourceMovingComponent" };
ComponentIndexType index2 = blueprint->AddComponent(component2Parameters);
ParameterMapType component3Parameters;
component3Parameters["NameOfClass"] = { "ItkImageSinkComponent" };
ComponentIndexType index3 = blueprint->AddComponent(component3Parameters);
ParameterMapType component4Parameters;
component4Parameters["NameOfClass"] = { "ItkMeanSquaresImageToImageMetricv4Component" };
ComponentIndexType index4 = blueprint->AddComponent(component4Parameters);
ParameterMapType connection1Parameters;
connection1Parameters["NameOfInterface"] = { "itkImageSourceFixedInterface" };
blueprint->AddConnection(index1, index0, connection1Parameters);
ParameterMapType connection2Parameters;
connection2Parameters["NameOfInterface"] = { "itkImageSourceMovingInterface" };
blueprint->AddConnection(index2, index0, connection2Parameters);
ParameterMapType connection3Parameters;
connection3Parameters["NameOfInterface"] = { "itkImageSourceInterface" };
blueprint->AddConnection(index0, index3, connection3Parameters);
ParameterMapType connection4Parameters;
connection4Parameters["NameOfInterface"] = { "itkMetricv4Interface" };
blueprint->AddConnection(index4, index0, connection4Parameters);
EXPECT_NO_THROW(overlord = Overlord::New());
EXPECT_NO_THROW(overlord->SetBlueprint(blueprint));
bool allUniqueComponents;
EXPECT_NO_THROW(allUniqueComponents = overlord->Configure());
EXPECT_TRUE(allUniqueComponents);
EXPECT_NO_THROW(overlord->Execute());
//overlord->Execute();
}
} // namespace elx } // namespace elx
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment