Commit 2733afe7 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: added Test for ImageRegistrationMethodv4

parent eb744278
......@@ -13,6 +13,11 @@ set( ${MODULE}_LIBRARIES
${MODULE}
)
# Export tests
set( ${MODULE}_TESTS
elxitkImageFilterTest.cxx
)
# Module source files
set( ${MODULE}_SOURCE_FILES
${${MODULE}_SOURCE_DIR}/src/selxItkImageSource.cxx
......
......@@ -13,9 +13,17 @@ set( ${MODULE}_LIBRARIES
${MODULE}
)
# Export tests
set( ${MODULE}_TESTS
elxRegistrationItkv4Test.cxx
)
# Module source files
set( ${MODULE}_SOURCE_FILES
${${MODULE}_SOURCE_DIR}/src/selxItkImageRegistrationMethodv4.cxx )
${${MODULE}_SOURCE_DIR}/src/selxItkImageRegistrationMethodv4.cxx
${${MODULE}_SOURCE_DIR}/src/selxItkImageSourceFixed.cxx
${${MODULE}_SOURCE_DIR}/src/selxItkImageSourceMoving.cxx
)
# Compile library
......
......@@ -12,7 +12,7 @@ namespace selx
template <int Dimensionality, class TPixel>
class ItkImageRegistrationMethodv4Component :
public Implements<
Accepting< itkImageSourceInterface<Dimensionality, TPixel> >,
Accepting< itkImageSourceFixedInterface<Dimensionality, TPixel>, itkImageSourceMovingInterface<Dimensionality, TPixel>>,
Providing< itkImageSourceInterface<Dimensionality, TPixel> >
>
{
......@@ -40,7 +40,9 @@ namespace selx
typedef itk::ResampleImageFilter<MovingImageType, ConnectionImageType> ResampleFilterType;
virtual int Set(itkImageSourceInterface<Dimensionality, TPixel>*) override;
virtual int Set(itkImageSourceFixedInterface<Dimensionality, TPixel>*) override;
virtual int Set(itkImageSourceMovingInterface<Dimensionality, TPixel>*) override;
virtual ItkImageSourcePointer GetItkImageSource() override;
virtual bool MeetsCriterion(const CriterionType &criterion) override;
......
......@@ -16,12 +16,21 @@ ItkImageRegistrationMethodv4Component< Dimensionality, TPixel>::~ItkImageRegistr
}
template<int Dimensionality, class TPixel>
int ItkImageRegistrationMethodv4Component< Dimensionality, TPixel>::Set(itkImageSourceInterface<Dimensionality, TPixel>* component)
int ItkImageRegistrationMethodv4Component< Dimensionality, TPixel>::Set(itkImageSourceFixedInterface<Dimensionality, TPixel>* component)
{
auto other = component->GetItkImageSource();
auto other = component->GetItkImageSourceFixed();
// connect the itk pipeline
this->m_theItkFilter->SetFixedImage(other->GetOutput());
return 1;
}
template<int Dimensionality, class TPixel>
int ItkImageRegistrationMethodv4Component< Dimensionality, TPixel>::Set(itkImageSourceMovingInterface<Dimensionality, TPixel>* component)
{
auto other = component->GetItkImageSourceMoving();
// connect the itk pipeline
this->m_theItkFilter->SetMovingImage(other->GetOutput());
return 0;
return 1;
}
//ItkImageSourceType::Pointer
......
......@@ -93,7 +93,22 @@ struct InterfaceName < itkImageSourceInterface <D, TPixel> >
}
};
template <int D, class TPixel>
struct InterfaceName < itkImageSourceFixedInterface <D, TPixel> >
{
static const char* Get()
{
return "itkImageSourceFixedInterface";
}
};
template <int D, class TPixel>
struct InterfaceName < itkImageSourceMovingInterface <D, TPixel> >
{
static const char* Get()
{
return "itkImageSourceMovingInterface";
}
};
template <>
struct InterfaceName < SourceInterface >
{
......
......@@ -41,13 +41,21 @@ namespace selx
// The (failing) criteria can be printed as well.
if (numberOfComponents == 0)
{
itkExceptionMacro("Too many criteria for component");
//TODO report about m_Criteria
std::stringstream message;
message << "Too many criteria for component " << this->m_ComponentSelectorContainer[*componentIt]->GetNameOfClass();
// "There is no component in our database that fulfills your set of criteria
std::cout << message.str();
//TODO how does this work for strings?
itkExceptionMacro("Too many criteria for component ");
}
else if (numberOfComponents > 1)
{
allUniqueComponents = false;
}
std::cout << "blueprint node " << *componentIt << " has selected" << numberOfComponents << " components" << std::endl;
std::cout << "blueprint node " << *componentIt << " has selected " << numberOfComponents << " components" << std::endl;
}
return allUniqueComponents;
......@@ -169,7 +177,7 @@ namespace selx
//TODO GetComponent returns NULL if possible components !=1 we can check for that, but Overlord::UpdateSelectors() does something similar.
ComponentBase::Pointer sourceComponent = this->m_ComponentSelectorContainer[ouputIt->m_source]->GetComponent();
ComponentBase::Pointer targetComponent = this->m_ComponentSelectorContainer[ouputIt->m_target]->GetComponent();
targetComponent->ConnectFrom(sourceComponent);
targetComponent->AcceptConnectionFrom(sourceComponent);
}
}
//TODO should we communicate by exceptions instead of returning booleans?
......
......@@ -69,26 +69,26 @@ TEST_F( InterfaceTest, DynamicCast )
TEST_F( InterfaceTest, ConnectByName )
{
ComponentBase::interfaceStatus IFstatus;
EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricValueInterface", metric3p));
EXPECT_NO_THROW(IFstatus = optimizer3p->AcceptConnectionFrom("MetricValueInterface", metric3p));
EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::success);
EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricValueInterface", metric4p));
EXPECT_NO_THROW(IFstatus = optimizer3p->AcceptConnectionFrom("MetricValueInterface", metric4p));
EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::success);
EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricValueInterface", metric3p));
EXPECT_NO_THROW(IFstatus = optimizer4p->AcceptConnectionFrom("MetricValueInterface", metric3p));
EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::success);
EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricValueInterface", metric4p));
EXPECT_NO_THROW(IFstatus = optimizer4p->AcceptConnectionFrom("MetricValueInterface", metric4p));
EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::success);
EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricDerivativeInterface", metric3p));
EXPECT_NO_THROW(IFstatus = optimizer3p->AcceptConnectionFrom("MetricDerivativeInterface", metric3p));
EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::success);
EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricDerivativeInterface", metric4p));
EXPECT_NO_THROW(IFstatus = optimizer3p->AcceptConnectionFrom("MetricDerivativeInterface", metric4p));
EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::noprovider);
EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricDerivativeInterface", metric3p));
EXPECT_NO_THROW(IFstatus = optimizer4p->AcceptConnectionFrom("MetricDerivativeInterface", metric3p));
EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::noaccepter);
}
......@@ -98,7 +98,7 @@ TEST_F(InterfaceTest, ConnectAll)
int connectionCount = 0;
int returnval;
OptimizerUpdateInterface* updateIF;
EXPECT_NO_THROW(connectionCount = optimizer3p->ConnectFrom(metric3p));
EXPECT_NO_THROW(connectionCount = optimizer3p->AcceptConnectionFrom(metric3p));
EXPECT_EQ(connectionCount, 2); // both MetricValueInterface and MetricDerivativeInterface are connected
//optimizer3p should have a OptimizerUpdateInterface
......@@ -106,27 +106,27 @@ TEST_F(InterfaceTest, ConnectAll)
ASSERT_NE(updateIF, nullptr);
EXPECT_NO_THROW(returnval = updateIF->Update()); // Update can only be called if metric and optimizer are connected
EXPECT_NO_THROW(connectionCount = optimizer3p->ConnectFrom(metric4p));
EXPECT_NO_THROW(connectionCount = optimizer3p->AcceptConnectionFrom(metric4p));
EXPECT_EQ(connectionCount, 1); // only MetricValueInterface is connected
//metric4p does not have MetricDerivativeInterface, so optimizer3p cannot run
EXPECT_NO_THROW(connectionCount = optimizer4p->ConnectFrom(metric3p));
EXPECT_NO_THROW(connectionCount = optimizer4p->AcceptConnectionFrom(metric3p));
EXPECT_EQ(connectionCount, 1); // only MetricValueInterface is connected
updateIF = dynamic_cast<OptimizerUpdateInterface*> (optimizer4p);
ASSERT_NE(updateIF, nullptr);
EXPECT_NO_THROW(returnval = updateIF->Update());
EXPECT_NO_THROW(connectionCount = optimizer4p->ConnectFrom(metric4p));
EXPECT_NO_THROW(connectionCount = optimizer4p->AcceptConnectionFrom(metric4p));
EXPECT_EQ(connectionCount, 1); // only MetricValueInterface is connected
updateIF = dynamic_cast<OptimizerUpdateInterface*> (optimizer4p);
ASSERT_NE(updateIF, nullptr);
EXPECT_NO_THROW(returnval = updateIF->Update());
EXPECT_NO_THROW(connectionCount = metric4p->ConnectFrom(optimizer4p));
EXPECT_NO_THROW(connectionCount = metric4p->AcceptConnectionFrom(optimizer4p));
EXPECT_EQ(connectionCount, 0); // cannot connect in this direction
ConflictinUpdateInterface* update2IF = dynamic_cast<ConflictinUpdateInterface*> (optimizer4p);
......
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