Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
SuperElastix
Commits
a6f9e70f
Commit
a6f9e70f
authored
Jan 30, 2017
by
Floris Berendsen
Browse files
ENH: replaced ComponentFactoryTest by new ComponentSelectorTest
parent
42fadff5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Modules/Core/ComponentInterface/test/selxComponent
Fa
ctor
y
Test.cxx
→
Modules/Core/ComponentInterface/test/selxComponent
Sele
ctorTest.cxx
View file @
a6f9e70f
...
...
@@ -19,14 +19,11 @@
#include
"gtest/gtest.h"
#include
"selxComponentSelector.h"
#include
"selxTypeList.h"
#include
"selxTransformComponent1.h"
//#include "itkTransformComponent1Factory.h"
#include
"selxMetricComponent1.h"
//#include "itkMetricComponent1Factory.h"
#include
"selxComponentFactory.h"
#include
"selxGDOptimizer3rdPartyComponent.h"
#include
"selxGDOptimizer4thPartyComponent.h"
#include
"selxSSDMetric3rdPartyComponent.h"
...
...
@@ -34,11 +31,10 @@
namespace
selx
{
class
Component
Fa
ctor
y
Test
:
public
::
testing
::
Test
class
Component
Sele
ctorTest
:
public
::
testing
::
Test
{
public:
typedef
std
::
list
<
itk
::
LightObject
::
Pointer
>
RegisteredObjectsContainerType
;
typedef
ComponentBase
ComponentType
;
//typedef ComponentBase::CriteriaType CriteriaType;
...
...
@@ -46,9 +42,13 @@ public:
typedef
ComponentBase
::
ParameterValueType
ParameterValueType
;
//typedef std::map<std::string, std::string> CriteriaType;
//typedef std::pair<std::string, std::string> CriterionType;
typedef
TypeList
<>
ComponentList
;
typedef
ComponentSelector
<
ComponentList
>::
Pointer
NodePointer
;
typedef
TypeList
<>
EmptyComponentList
;
// each node can hold multiple components (or none). Its the NetworkBuilder's task to make it one per node.
//typedef ComponentSelector<EmptyComponentList>::Pointer NodePointer;
using
SmallComponentList
=
TypeList
<
TransformComponent1
,
MetricComponent1
>
;
using
BigComponentList
=
TypeList
<
TransformComponent1
,
MetricComponent1
,
GDOptimizer3rdPartyComponent
,
GDOptimizer4thPartyComponent
,
SSDMetric3rdPartyComponent
,
SSDMetric4thPartyComponent
>
;
virtual
void
SetUp
()
{
...
...
@@ -57,157 +57,118 @@ public:
virtual
void
TearDown
()
{
itk
::
ObjectFactoryBase
::
UnRegisterAllFactories
();
}
// each node can hold multiple components (or none). Its the NetworkBuilder's task to make it one per node.
NodePointer
Node1
;
NodePointer
Node2
;
};
TEST_F
(
Component
Fa
ctor
y
Test
,
Empty
ObjectFactoryBase
)
TEST_F
(
Component
Sele
ctorTest
,
Empty
ComponentList
)
{
// The Component factory is inspired/based on the ImageIO factory.
// In ITK Components (transformIO and imageIO) can be preregistered: CMake\UseITK.cmake sets up the IOFactory_Register_Manager
// In Elastix (by Denis) GPU filters are preregistered using (simpleITK's) Typelists and Cmake
// In this test we manually register 2 dummy modules: itkTransformComponent1 and itkMetricComponent1.
RegisteredObjectsContainerType
registeredComponents
;
auto
componentSelector
=
ComponentSelector
<
EmptyComponentList
>::
New
();
// "When CMake is not used to register the Component classes, there are"
EXPECT_NO_THROW
(
registeredComponents
=
itk
::
ObjectFactoryBase
::
CreateAllInstance
(
"ComponentBase"
)
);
// " 0 Component objects available to the NetworkBuilder."
EXPECT_EQ
(
registered
Components
.
size
(),
0
);
EXPECT_EQ
(
componentSelector
->
NumberOf
Components
(),
0
);
}
TEST_F
(
Component
Fa
ctor
y
Test
,
Filled
ObjectFactoryBase
)
TEST_F
(
Component
Sele
ctorTest
,
Filled
ComponentList
)
{
// In this test we manually register 2 dummy modules: itkTransformComponent1 and itkMetricComponent1.
RegisteredObjectsContainerType
registeredComponents
;
EXPECT_NO_THROW
(
ComponentFactory
<
TransformComponent1
>::
RegisterOneFactory
()
);
//EXPECT_NO_THROW(TransformComponent1Factory::RegisterOneFactory());
EXPECT_NO_THROW
(
ComponentFactory
<
MetricComponent1
>::
RegisterOneFactory
()
);
//EXPECT_NO_THROW(MetricComponent1Factory::RegisterOneFactory());
auto
componentSelector
=
ComponentSelector
<
TypeList
<
TransformComponent1
,
MetricComponent1
>>::
New
();
// After registering the TransformComponent1 and MetricComponent1object, there are
EXPECT_NO_THROW
(
registeredComponents
=
itk
::
ObjectFactoryBase
::
CreateAllInstance
(
"ComponentBase"
)
);
// " 2 Component objects available to the NetworkBuilder."
EXPECT_EQ
(
registered
Components
.
size
(),
2
);
EXPECT_EQ
(
componentSelector
->
NumberOf
Components
(),
2
);
}
TEST_F
(
Component
Fa
ctor
y
Test
,
SetEmptyCriteria
)
TEST_F
(
Component
Sele
ctorTest
,
SetEmptyCriteria
)
{
EXPECT_NO_THROW
(
ComponentFactory
<
TransformComponent1
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
MetricComponent1
>::
RegisterOneFactory
()
);
auto
componentSelector
=
ComponentSelector
<
SmallComponentList
>::
New
();
CriterionType
emptyCriterion
;
// = CriterionType();
ASSERT_NO_THROW
(
Node1
=
ComponentSelector
<
ComponentList
>::
New
());
EXPECT_NO_THROW
(
Node1
->
AddCriterion
(
emptyCriterion
)
);
ComponentType
::
Pointer
Node1Component
;
EXPECT_NO_THROW
(
Node1Component
=
Node1
->
GetComponent
()
);
EXPECT_NO_THROW
(
componentSelector
->
AddCriterion
(
emptyCriterion
));
ComponentType
::
Pointer
component
;
EXPECT_NO_THROW
(
component
=
componentSelector
->
GetComponent
());
//Too few criteria means no Component could be selected."
EXPECT_TRUE
(
Node1C
omponent
.
IsNull
()
);
EXPECT_TRUE
(
c
omponent
.
IsNull
());
}
TEST_F
(
Component
Fa
ctor
y
Test
,
SetSufficientCriteria
)
TEST_F
(
Component
Sele
ctorTest
,
SetSufficientCriteria
)
{
EXPECT_NO_THROW
(
ComponentFactory
<
TransformComponent1
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
MetricComponent1
>::
RegisterOneFactory
()
);
auto
componentSelector
=
ComponentSelector
<
SmallComponentList
>::
New
();
CriterionType
criterion2
=
{
"ComponentInput"
,
{
"Transform"
}
};
ASSERT_NO_THROW
(
Node2
=
ComponentSelector
<
ComponentList
>::
New
());
CriterionType
criterion
=
{
"ComponentInput"
,
{
"Transform"
}
};
ASSERT_NO_THROW
(
Node2
->
AddCriterion
(
criterion
2
)
);
ComponentType
::
Pointer
Node2C
omponent
;
EXPECT_NO_THROW
(
Node2C
omponent
=
Node2
->
GetComponent
()
);
ASSERT_NO_THROW
(
componentSelector
->
AddCriterion
(
criterion
)
);
ComponentType
::
Pointer
c
omponent
;
EXPECT_NO_THROW
(
c
omponent
=
componentSelector
->
GetComponent
());
//Sufficient criteria means one Component was selected."
EXPECT_FALSE
(
Node2C
omponent
.
IsNull
()
);
EXPECT_FALSE
(
c
omponent
.
IsNull
());
//Based on the criteria MetricComponent1 should be selected
EXPECT_STREQ
(
Node2C
omponent
->
GetNameOfClass
(),
"MetricComponent1"
);
EXPECT_STREQ
(
c
omponent
->
GetNameOfClass
(),
"MetricComponent1"
);
}
TEST_F
(
Component
Fa
ctor
y
Test
,
AddCriteria
)
TEST_F
(
Component
Sele
ctorTest
,
AddCriteria
)
{
EXPECT_NO_THROW
(
ComponentFactory
<
TransformComponent1
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
MetricComponent1
>::
RegisterOneFactory
()
);
auto
componentSelector
=
ComponentSelector
<
SmallComponentList
>::
New
();
CriterionType
nonSelectiveCriterion
({
"ComponentProperty"
,
{
"SomeProperty"
}
});
CriterionType
criterion1
(
{
"ComponentOutput"
,
{
"Transform"
}
}
);
Node1
=
ComponentSelector
<
ComponentList
>::
New
();
CriterionType
criterion
(
{
"ComponentOutput"
,
{
"Transform"
}
}
);
EXPECT_NO_THROW
(
Node1
->
AddCriterion
(
nonSelectiveCriterion
)
);
ComponentType
::
Pointer
Node1C
omponent
;
EXPECT_NO_THROW
(
componentSelector
->
AddCriterion
(
nonSelectiveCriterion
)
);
ComponentType
::
Pointer
c
omponent
;
EXPECT_TRUE
(
Node1
->
NumberOfComponents
()
>
1
);
EXPECT_NO_THROW
(
Node1C
omponent
=
Node1
->
GetComponent
()
);
EXPECT_TRUE
(
componentSelector
->
NumberOfComponents
()
>
1
);
EXPECT_NO_THROW
(
c
omponent
=
componentSelector
->
GetComponent
());
//Unsufficient criteria means no Component was selected."
EXPECT_TRUE
(
Node1C
omponent
.
IsNull
()
);
EXPECT_TRUE
(
c
omponent
.
IsNull
());
EXPECT_NO_THROW
(
Node1
->
AddCriterion
(
criterion
1
)
);
EXPECT_NO_THROW
(
Node1C
omponent
=
Node1
->
GetComponent
()
);
EXPECT_NO_THROW
(
componentSelector
->
AddCriterion
(
criterion
)
);
EXPECT_NO_THROW
(
c
omponent
=
componentSelector
->
GetComponent
());
//Sufficient criteria means one Component was selected."
EXPECT_FALSE
(
Node1
->
NumberOfComponents
()
>
1
);
EXPECT_FALSE
(
Node1C
omponent
.
IsNull
()
);
EXPECT_FALSE
(
componentSelector
->
NumberOfComponents
()
>
1
);
EXPECT_FALSE
(
c
omponent
.
IsNull
());
//Based on the criteria TransformComponent1 should be selected
EXPECT_STREQ
(
Node1C
omponent
->
GetNameOfClass
(),
"TransformComponent1"
);
EXPECT_STREQ
(
c
omponent
->
GetNameOfClass
(),
"TransformComponent1"
);
}
TEST_F
(
Component
Fa
ctor
y
Test
,
InterfacedObjects
)
TEST_F
(
Component
Sele
ctorTest
,
InterfacedObjects
)
{
RegisteredObjectsContainerType
registeredComponents
;
EXPECT_NO_THROW
(
ComponentFactory
<
TransformComponent1
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
MetricComponent1
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
GDOptimizer3rdPartyComponent
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
GDOptimizer4thPartyComponent
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
SSDMetric3rdPartyComponent
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
SSDMetric4thPartyComponent
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
registeredComponents
=
itk
::
ObjectFactoryBase
::
CreateAllInstance
(
"ComponentBase"
)
);
auto
componentSelectorA
=
ComponentSelector
<
BigComponentList
>::
New
();
// " 6 Component objects available to the NetworkBuilder."
EXPECT_EQ
(
registered
Components
.
size
(),
6
);
EXPECT_EQ
(
componentSelectorA
->
NumberOf
Components
()
,
6
);
NodePointer
Node3
=
ComponentSelector
<
ComponentList
>::
New
();
Node3
->
AddAcceptingInterfaceCriteria
(
{
{
"NameOfInterface"
,
"MetricDerivativeInterface"
}
}
);
componentSelectorA
->
AddAcceptingInterfaceCriteria
({
{
"NameOfInterface"
,
"MetricDerivativeInterface"
}
});
ComponentType
::
Pointer
Node3C
omponent
;
EXPECT_NO_THROW
(
Node3C
omponent
=
Node3
->
GetComponent
()
);
EXPECT_STREQ
(
Node3C
omponent
->
GetNameOfClass
(),
"GDOptimizer3rdPartyComponent"
);
ComponentType
::
Pointer
c
omponent
A
;
EXPECT_NO_THROW
(
c
omponent
A
=
componentSelectorA
->
GetComponent
());
EXPECT_STREQ
(
c
omponent
A
->
GetNameOfClass
(),
"GDOptimizer3rdPartyComponent"
);
NodePointer
Node4
=
ComponentSelector
<
ComponentList
>::
New
();
Node4
->
AddProvidingInterfaceCriteria
(
{
{
"NameOfInterface"
,
"MetricDerivativeInterface"
}
}
);
ComponentType
::
Pointer
Node4C
omponent
;
EXPECT_NO_THROW
(
Node4C
omponent
=
Node4
->
GetComponent
()
);
EXPECT_STREQ
(
Node4C
omponent
->
GetNameOfClass
(),
"SSDMetric3rdPartyComponent"
);
auto
componentSelectorB
=
ComponentSelector
<
Big
ComponentList
>::
New
();
componentSelectorB
->
AddProvidingInterfaceCriteria
({
{
"NameOfInterface"
,
"MetricDerivativeInterface"
}
});
ComponentType
::
Pointer
c
omponent
B
;
EXPECT_NO_THROW
(
c
omponent
B
=
componentSelectorB
->
GetComponent
());
EXPECT_STREQ
(
c
omponent
B
->
GetNameOfClass
(),
"SSDMetric3rdPartyComponent"
);
}
TEST_F
(
Component
Fa
ctor
y
Test
,
UnknownComponent
)
TEST_F
(
Component
Sele
ctorTest
,
UnknownComponent
)
{
// Fill our component database with some components
RegisteredObjectsContainerType
registeredComponents
;
EXPECT_NO_THROW
(
ComponentFactory
<
TransformComponent1
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
MetricComponent1
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
GDOptimizer3rdPartyComponent
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
GDOptimizer4thPartyComponent
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
SSDMetric3rdPartyComponent
>::
RegisterOneFactory
()
);
EXPECT_NO_THROW
(
ComponentFactory
<
SSDMetric4thPartyComponent
>::
RegisterOneFactory
()
);
auto
componentSelector
=
ComponentSelector
<
BigComponentList
>::
New
();
// Setup the criterion for a component that does not exist in our data base
CriterionType
criterion
(
{
"NameOfClass"
,
{
"DoYouHaveThisComponent?"
}
}
);
NodePointer
Node
=
ComponentSelector
<
ComponentList
>::
New
();
Node
->
AddCriterion
(
criterion
);
ComponentType
::
Pointer
NodeComponent
;
componentSelector
->
AddCriterion
(
criterion
);
ComponentType
::
Pointer
component
;
// we expect 0 components
EXPECT_TRUE
(
Node
->
NumberOfComponents
()
==
0
);
EXPECT_TRUE
(
Node
->
GetComponent
().
IsNull
()
);
EXPECT_TRUE
(
componentSelector
->
NumberOfComponents
()
==
0
);
EXPECT_TRUE
(
componentSelector
->
GetComponent
().
IsNull
());
}
}
// namespace selx
Modules/Core/ModuleCore.cmake
View file @
a6f9e70f
...
...
@@ -48,7 +48,7 @@ set( ${MODULE}_SOURCE_FILES
# Export tests
set
(
${
MODULE
}
_TEST_SOURCE_FILES
${${
MODULE
}
_SOURCE_DIR
}
/Blueprints/test/selxBlueprintTest.cxx
${${
MODULE
}
_SOURCE_DIR
}
/ComponentInterface/test/selxComponent
Fa
ctor
y
Test.cxx
${${
MODULE
}
_SOURCE_DIR
}
/ComponentInterface/test/selxComponent
Sele
ctorTest.cxx
${${
MODULE
}
_SOURCE_DIR
}
/ComponentInterface/test/selxComponentInterfaceTest.cxx
${${
MODULE
}
_SOURCE_DIR
}
/ComponentInterface/test/selxNetworkBuilderTest.cxx
${${
MODULE
}
_SOURCE_DIR
}
/ConfigurationReader/test/selxConfigurationReaderTest.cxx
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment