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
16f0cdfe
Commit
16f0cdfe
authored
Jan 19, 2017
by
Floris Berendsen
Browse files
ENH: WIP: big refactor removing itk factory for Components. Needs some
work
parent
daa52cb7
Changes
9
Hide whitespace changes
Inline
Side-by-side
Modules/Core/ComponentInterface/include/selxComponentSelector.h
View file @
16f0cdfe
...
...
@@ -22,7 +22,7 @@
#include
"itkObjectFactory.h"
#include
"selxComponentBase.h"
//#pragma once
#include
"selxTypeList.h"
namespace
selx
{
...
...
@@ -90,6 +90,11 @@ private:
ComponentSelector
(
const
Self
&
);
//purposely not implemented
void
operator
=
(
const
Self
&
);
//purposely not implemented
};
template
<
typename
>
struct
ContructComponentsFromTypeList
;
}
// end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
...
...
Modules/Core/ComponentInterface/include/selxComponentSelector.hxx
View file @
16f0cdfe
...
...
@@ -23,22 +23,46 @@
namespace
selx
{
template
<
class
ComponentList
>
ComponentSelector
<
ComponentList
>::
ComponentSelector
()
{
std
::
list
<
itk
::
LightObject
::
Pointer
>
allobjects
=
itk
::
ObjectFactoryBase
::
CreateAllInstance
(
"ComponentBase"
);
for
(
std
::
list
<
itk
::
LightObject
::
Pointer
>::
iterator
i
=
allobjects
.
begin
();
i
!=
allobjects
.
end
();
++
i
)
template
<
>
struct
ContructComponentsFromTypeList
<
TypeList
<
>
>
{
ComponentBase
*
component
=
dynamic_cast
<
ComponentBase
*
>
(
i
->
GetPointer
()
);
if
(
component
)
static
std
::
list
<
ComponentBase
::
Pointer
>
fill
(
std
::
list
<
ComponentBase
::
Pointer
>
&
components
,
std
::
string
&
name
)
{
this
->
m_PossibleComponents
.
push_back
(
component
)
;
return
component
s
;
}
}
};
template
<
typename
ComponentType
,
typename
...
Rest
>
struct
ContructComponentsFromTypeList
<
TypeList
<
ComponentType
,
Rest
...
>
>
{
static
std
::
list
<
ComponentBase
::
Pointer
>
fill
(
std
::
list
<
ComponentBase
::
Pointer
>
&
components
,
std
::
string
&
name
)
{
//components->push_back(new ComponentType(name));
components
.
push_back
(
ComponentType
::
New
().
GetPointer
());
return
ContructComponentsFromTypeList
<
TypeList
<
Rest
...
>>::
fill
(
components
,
name
);
}
};
template
<
class
ComponentList
>
ComponentSelector
<
ComponentList
>::
ComponentSelector
()
{
m_PossibleComponents
=
std
::
list
<
ComponentBase
::
Pointer
>
();
m_PossibleComponents
=
ContructComponentsFromTypeList
<
ComponentList
>::
fill
(
m_PossibleComponents
,
std
::
string
(
""
));
//std::list< itk::LightObject::Pointer > allobjects
// = itk::ObjectFactoryBase::CreateAllInstance( "ComponentBase" );
//for( std::list< itk::LightObject::Pointer >::iterator i = allobjects.begin();
// i != allobjects.end(); ++i )
//{
// ComponentBase * component
// = dynamic_cast< ComponentBase * >( i->GetPointer() );
// if (component)
// {
// this->m_PossibleComponents.push_back(component);
// }
//}
}
template
<
class
ComponentList
>
...
...
Modules/Core/ComponentInterface/include/selxNetworkBuilder.h
View file @
16f0cdfe
...
...
@@ -63,7 +63,9 @@ public:
NetworkBuilder
(
std
::
shared_ptr
<
Blueprint
>
blueprint
);
NetworkBuilder
(
Blueprint
*
blueprint
);
NetworkBuilder
();
virtual
~
NetworkBuilder
()
=
default
;
virtual
~
NetworkBuilder
()
{};
virtual
bool
AddBlueprint
(
std
::
shared_ptr
<
Blueprint
>
blueprint
);
/** Read configuration at the blueprints nodes and edges and return true if all components could be uniquely selected*/
virtual
bool
Configure
();
...
...
Modules/Core/ComponentInterface/include/selxNetworkBuilder.hxx
View file @
16f0cdfe
...
...
@@ -33,6 +33,19 @@ namespace selx
{
}
template
<
typename
ComponentList
>
NetworkBuilder
<
ComponentList
>::
NetworkBuilder
()
:
m_isConfigured
(
false
)
{
}
template
<
typename
ComponentList
>
bool
NetworkBuilder
<
ComponentList
>::
AddBlueprint
(
std
::
shared_ptr
<
Blueprint
>
blueprint
)
{
m_Blueprint
=
blueprint
;
return
true
;
}
template
<
typename
ComponentList
>
bool
NetworkBuilder
<
ComponentList
>::
Configure
()
...
...
@@ -144,6 +157,7 @@ NetworkBuilder<ComponentList>::ApplyComponentConfiguration()
for
(
auto
const
&
name
:
componentNames
)
{
std
::
cout
<<
" Blueprint Node: "
<<
name
<<
std
::
endl
;
typename
ComponentSelector
<
ComponentList
>::
Pointer
currentComponentSelectorA
=
ComponentSelector
<
ComponentList
>::
New
();
ComponentSelectorPointer
currentComponentSelector
=
ComponentSelectorType
::
New
();
currentComponentSelector
->
ComponentName
(
name
);
// Todo via constructor
...
...
Modules/Core/ComponentInterface/include/selxNetworkBuilderBase.h
View file @
16f0cdfe
...
...
@@ -58,8 +58,12 @@ public:
std
::
string
,
RegistrationControllerStartInterface
*
>
RegistrationControllerStartInterfaceMapType
;
typedef
Blueprint
::
ComponentNamesType
ComponentNamesType
;
NetworkBuilderBase
()
{};
virtual
~
NetworkBuilderBase
()
=
default
;
virtual
~
NetworkBuilderBase
()
{};
virtual
bool
AddBlueprint
(
std
::
shared_ptr
<
Blueprint
>
blueprint
)
=
0
;
/** Read configuration at the blueprints nodes and edges and return true if all components could be uniquely selected*/
virtual
bool
Configure
()
=
0
;
...
...
Modules/Core/Filter/include/selxSuperElastixFilter.h
View file @
16f0cdfe
...
...
@@ -112,11 +112,13 @@ protected:
virtual
void
GenerateData
(
void
)
ITK_OVERRIDE
;
std
::
unique_ptr
<
NetworkBuilderBase
>
m_NetworkBuilder
;
private:
//TODO make const correct
BlueprintType
::
Pointer
m_Blueprint
;
std
::
unique_ptr
<
NetworkBuilderBase
>
m_NetworkBuilder
;
bool
m_InputConnectionModified
;
bool
m_OutputConnectionModified
;
bool
m_BlueprintConnectionModified
;
...
...
Modules/Core/Filter/include/selxSuperElastixFilterCustomComponents.hxx
View file @
16f0cdfe
...
...
@@ -34,7 +34,8 @@ namespace selx
SuperElastixFilterCustomComponents
<
ComponentTypeList
>
::
SuperElastixFilterCustomComponents
(
void
)
:
SuperElastixFilter
(
true
)
{
RegisterFactoriesByTypeList
<
ComponentTypeList
>::
Register
();
//RegisterFactoriesByTypeList< ComponentTypeList >::Register();
m_NetworkBuilder
=
std
::
unique_ptr
<
NetworkBuilder
<
ComponentTypeList
>>
(
new
NetworkBuilder
<
ComponentTypeList
>
());
}
// end Constructor
}
// namespace elx
...
...
Modules/Core/Filter/src/selxSuperElastixFilter.cxx
View file @
16f0cdfe
...
...
@@ -36,7 +36,8 @@ SuperElastixFilter
::
SuperElastixFilter
(
void
)
:
SuperElastixFilter
(
true
)
{
// The default constructor registers the default components.
RegisterFactoriesByTypeList
<
DefaultComponents
>::
Register
();
//RegisterFactoriesByTypeList< DefaultComponents >::Register();
m_NetworkBuilder
=
std
::
make_unique
<
NetworkBuilder
<
DefaultComponents
>>
(
new
NetworkBuilder
<
DefaultComponents
>
());
}
// end Constructor
//
...
...
@@ -77,17 +78,14 @@ SuperElastixFilter
// are passed further down stream.
// Eventually configuration boils down to a while loop that repeatedly tries to narrow down
// the component selectors until no more unique components can be found.
if
(
!
this
->
m_NetworkBuilder
)
{
if
(
!
this
->
m_Blueprint
)
{
itkExceptionMacro
(
<<
"Setting a Blueprint is required first."
)
}
this
->
m_NetworkBuilder
=
std
::
unique_ptr
<
NetworkBuilder
<
DefaultComponents
>
>
(
new
NetworkBuilder
<
DefaultComponents
>
(
this
->
m_Blueprint
->
Get
())
)
;
this
->
m_NetworkBuilder
->
AddBlueprint
(
this
->
m_Blueprint
->
Get
());
this
->
m_AllUniqueComponents
=
this
->
m_NetworkBuilder
->
Configure
();
}
else
if
(
this
->
m_BlueprintConnectionModified
==
true
)
if
(
this
->
m_BlueprintConnectionModified
==
true
)
{
//TODO:
}
...
...
@@ -191,7 +189,7 @@ SuperElastixFilter
auto
fullyConfiguredNetwork
=
this
->
m_NetworkBuilder
->
GetRealizedNetwork
();
// delete the networkbuilder
this
->
m_NetworkBuilder
=
nullptr
;
//
this->m_NetworkBuilder = nullptr;
// This calls controller components that take over the control flow if the itk pipeline is broken.
fullyConfiguredNetwork
.
Execute
();
...
...
@@ -220,7 +218,7 @@ SuperElastixFilter
{
itkExceptionMacro
(
<<
"Setting a Blueprint is required first."
)
}
this
->
m_NetworkBuilder
=
std
::
unique_ptr
<
NetworkBuilder
<
DefaultComponents
>
>
(
new
NetworkBuilder
<
DefaultComponents
>
(
this
->
m_Blueprint
->
Get
())
)
;
this
->
m_NetworkBuilder
->
AddBlueprint
(
this
->
m_Blueprint
->
Get
());
this
->
m_AllUniqueComponents
=
this
->
m_NetworkBuilder
->
Configure
();
}
if
(
!
this
->
m_AllUniqueComponents
)
...
...
@@ -244,7 +242,7 @@ SuperElastixFilter
itkExceptionMacro
(
<<
"Setting a Blueprint is required first."
)
}
this
->
m_NetworkBuilder
=
std
::
unique_ptr
<
NetworkBuilder
<
DefaultComponents
>
>
(
new
NetworkBuilder
<
DefaultComponents
>
(
this
->
m_Blueprint
->
Get
())
)
;
this
->
m_NetworkBuilder
->
AddBlueprint
(
this
->
m_Blueprint
->
Get
());
this
->
m_AllUniqueComponents
=
this
->
m_NetworkBuilder
->
Configure
();
}
if
(
!
this
->
m_AllUniqueComponents
)
...
...
@@ -283,7 +281,7 @@ SuperElastixFilter::OutputDataType
itkExceptionMacro
(
<<
"Setting a Blueprint is required first."
)
}
this
->
m_NetworkBuilder
=
std
::
unique_ptr
<
NetworkBuilder
<
DefaultComponents
>
>
(
new
NetworkBuilder
<
DefaultComponents
>
(
this
->
m_Blueprint
->
Get
())
)
;
this
->
m_NetworkBuilder
->
AddBlueprint
(
this
->
m_Blueprint
->
Get
());
this
->
m_AllUniqueComponents
=
this
->
m_NetworkBuilder
->
Configure
();
this
->
m_BlueprintConnectionModified
=
false
;
}
...
...
Modules/Core/Filter/test/selxSuperElastixFilterTest.cxx
View file @
16f0cdfe
...
...
@@ -59,17 +59,18 @@ public:
typedef
itk
::
ImageFileReader
<
Image3DType
>
ImageReader3DType
;
typedef
itk
::
ImageFileWriter
<
Image3DType
>
ImageWriter3DType
;
/** Fill S
UPERe
lastix' component data base by registering various components */
/** Fill S
uperE
lastix' component data base by registering various components */
typedef
TypeList
<
ItkImageSinkComponent
<
3
,
double
>
,
ItkImageSourceComponent
<
3
,
double
>
,
ItkSmoothingRecursiveGaussianImageFilterComponent
<
3
,
double
>
,
ItkMeshSinkComponent
<
2
,
float
>
,
ItkMeshSourceComponent
<
2
,
float
>
>
RegisterComponents
;
ItkMeshSourceComponent
<
2
,
float
>
>
CustomComponents
;
using
RegisterComponents
=
list_append
<
CustomComponents
,
DefaultComponents
>::
type
;
typedef
std
::
shared_ptr
<
Blueprint
>
BlueprintPointer
;
typedef
SuperElastixFilter
::
Pointer
SuperElastixFilterPointer
;
typedef
SuperElastixFilter
::
BlueprintType
SuperElastixFilterBlueprintType
;
typedef
SuperElastixFilter
::
BlueprintPointer
SuperElastixFilterBlueprintPointer
;
...
...
@@ -87,13 +88,11 @@ public:
{
// Unregister all components after each test
// TODO: when SuperElastix is refactored to not use the ITK object factory this UnRegisterAllFactories call must be removed
itk
::
ObjectFactoryBase
::
UnRegisterAllFactories
();
//
itk::ObjectFactoryBase::UnRegisterAllFactories();
// Delete the SuperElastixFilter after each test
superElastixFilter
=
nullptr
;
}
// Blueprint holds a configuration for SuperElastix
BlueprintPointer
blueprint
;
SuperElastixFilter
::
Pointer
superElastixFilter
;
// Data manager provides the paths to the input and output data for unit tests
DataManagerType
::
Pointer
dataManager
;
};
...
...
@@ -116,9 +115,8 @@ TEST_F( SuperElastixFilterTest, ImageOnly )
// Instantiate SuperElastixFilter before each test and
// register the components we want to have available in SuperElastix
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
Pointer
superElastixFilter
;
EXPECT_NO_THROW
(
superElastixFilter
=
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
New
());
SuperElastixFilterBlueprintPointer
superElastixBlueprint
=
SuperElastixFilterBlueprintType
::
New
();
superElastixBlueprint
->
Set
(
blueprint
);
...
...
@@ -157,6 +155,7 @@ TEST_F( SuperElastixFilterTest, ImageAndMesh )
// Instantiate SuperElastixFilter before each test and
// register the components we want to have available in SuperElastix
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
Pointer
superElastixFilter
;
EXPECT_NO_THROW
(
superElastixFilter
=
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
New
());
SuperElastixFilterBlueprintPointer
superElastixFilterBlueprint
=
SuperElastixFilterBlueprintType
::
New
();
...
...
@@ -187,6 +186,7 @@ TEST_F( SuperElastixFilterTest, TooManyInputs )
// Instantiate SuperElastixFilter before each test and
// register the components we want to have available in SuperElastix
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
Pointer
superElastixFilter
;
EXPECT_NO_THROW
(
superElastixFilter
=
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
New
());
SuperElastixFilterBlueprintPointer
superElastixFilterBlueprint
=
SuperElastixFilterBlueprintType
::
New
();
...
...
@@ -213,6 +213,7 @@ TEST_F( SuperElastixFilterTest, TooManySources )
// Instantiate SuperElastixFilter before each test and
// register the components we want to have available in SuperElastix
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
Pointer
superElastixFilter
;
EXPECT_NO_THROW
(
superElastixFilter
=
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
New
());
SuperElastixFilterBlueprintPointer
superElastixFilterBlueprint
=
SuperElastixFilterBlueprintType
::
New
();
...
...
@@ -236,6 +237,7 @@ TEST_F( SuperElastixFilterTest, TooManyOutputs )
// Instantiate SuperElastixFilter before each test and
// register the components we want to have available in SuperElastix
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
Pointer
superElastixFilter
;
EXPECT_NO_THROW
(
superElastixFilter
=
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
New
());
SuperElastixFilterBlueprintPointer
superElastixFilterBlueprint
=
SuperElastixFilterBlueprintType
::
New
();
...
...
@@ -259,6 +261,7 @@ TEST_F( SuperElastixFilterTest, TooManySinks )
// Instantiate SuperElastixFilter before each test and
// register the components we want to have available in SuperElastix
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
Pointer
superElastixFilter
;
EXPECT_NO_THROW
(
superElastixFilter
=
SuperElastixFilterCustomComponents
<
RegisterComponents
>::
New
());
SuperElastixFilterBlueprintPointer
superElastixFilterBlueprint
=
SuperElastixFilterBlueprintType
::
New
();
...
...
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