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
5da4a145
Commit
5da4a145
authored
Aug 02, 2016
by
Floris Berendsen
Browse files
BUG: ENH: added ReconnectInterface since Itk TransformOutput does not
comply with pipeline functionality
parent
d7229b42
Changes
11
Hide whitespace changes
Inline
Side-by-side
Modules/Components/SinksAndSources/include/selxDisplacementFieldItkImageFilterSink.h
View file @
5da4a145
...
...
@@ -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
;
...
...
Modules/Components/itkImageRegistrationMethodv4/include/selxItkImageRegistrationMethodv4Component.hxx
View file @
5da4a145
...
...
@@ -208,6 +208,7 @@ void ItkImageRegistrationMethodv4Component< Dimensionality, TPixel>::RunRegistra
auto
optimizer
=
dynamic_cast
<
itk
::
GradientDescentOptimizerv4
*>
(
this
->
m_theItkFilter
->
GetModifiableOptimizer
());
//auto optimizer = dynamic_cast<itk::ObjectToObjectOptimizerBaseTemplate< InternalComputationValueType > *>(this->m_theItkFilter->GetModifiableOptimizer());
auto
transform
=
this
->
m_theItkFilter
->
GetModifiableTransform
();
if
(
msdMetric
)
{
...
...
Modules/Components/itkImageRegistrationMethodv4/include/selxItkResampleFilter.h
View file @
5da4a145
...
...
@@ -44,7 +44,8 @@ namespace selx
itkImageFixedInterface
<
Dimensionality
,
TPixel
>
,
//TODO should be FixedImageDomainInterface, we do not require intensities
itkImageMovingInterface
<
Dimensionality
,
TPixel
>
>
,
Providing
<
itkImageInterface
<
Dimensionality
,
TPixel
>
Providing
<
itkImageInterface
<
Dimensionality
,
TPixel
>
,
ReconnectTransformInterface
>
>
{
...
...
@@ -72,6 +73,7 @@ namespace selx
//Providing Interfaces:
virtual
typename
ResultImageType
::
Pointer
GetItkImage
()
override
;
virtual
void
ReconnectTransform
()
override
;
//BaseClass methods
virtual
bool
MeetsCriterion
(
const
ComponentBase
::
CriterionType
&
criterion
)
override
;
...
...
@@ -80,6 +82,7 @@ namespace selx
private:
typename
ResampleFilterType
::
Pointer
m_ResampleFilter
;
itkTransformInterface
<
TInternalComputationValue
,
Dimensionality
>*
m_TransformComponent
;
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
...
...
Modules/Components/itkImageRegistrationMethodv4/include/selxItkResampleFilter.hxx
View file @
5da4a145
...
...
@@ -65,9 +65,12 @@ template <int Dimensionality, class TPixel, class TInternalComputationValue>
int
ItkResampleFilterComponent
<
Dimensionality
,
TPixel
,
TInternalComputationValue
>
::
Set
(
itkTransformInterface
<
TInternalComputationValue
,
Dimensionality
>*
component
)
{
//Store interface for later use
this
->
m_TransformComponent
=
component
;
auto
transform
=
component
->
GetItkTransform
();
// connect the itk pipeline
this
->
m_ResampleFilter
->
SetTransform
(
transform
.
GetPointer
()
);
this
->
m_ResampleFilter
->
SetTransform
(
transform
);
return
0
;
}
...
...
@@ -82,6 +85,14 @@ ItkResampleFilterComponent< Dimensionality, TPixel, TInternalComputationValue>
return
this
->
m_ResampleFilter
->
GetOutput
();
}
template
<
int
Dimensionality
,
class
TPixel
,
class
TInternalComputationValue
>
void
ItkResampleFilterComponent
<
Dimensionality
,
TPixel
,
TInternalComputationValue
>
::
ReconnectTransform
()
{
auto
transform
=
this
->
m_TransformComponent
->
GetItkTransform
();
// reconnect the tranform, since it does not comply with the itk pipeline
this
->
m_ResampleFilter
->
SetTransform
(
transform
);
}
template
<
int
Dimensionality
,
class
TPixel
,
class
TInternalComputationValue
>
bool
...
...
Modules/Components/itkImageRegistrationMethodv4/include/selxItkTransformDisplacementFilter.h
View file @
5da4a145
...
...
@@ -41,9 +41,10 @@ namespace selx
class
ItkTransformDisplacementFilterComponent
:
public
Implements
<
Accepting
<
itkTransformInterface
<
TInternalComputationValue
,
Dimensionality
>
,
itkImageFixedInterface
<
Dimensionality
,
TPixel
>
//TODO should be FixedImageDomainInterface, we do not require intensities
itkImage
Domain
FixedInterface
<
Dimensionality
>
>
,
Providing
<
DisplacementFieldItkImageSourceInterface
<
Dimensionality
,
TPixel
>
Providing
<
DisplacementFieldItkImageSourceInterface
<
Dimensionality
,
TPixel
>
,
ReconnectTransformInterface
>
>
{
...
...
@@ -58,19 +59,18 @@ namespace selx
typedef
TPixel
PixelType
;
// Get the type definitions from the interfaces
typedef
typename
itkImageFixedInterface
<
Dimensionality
,
TPixel
>::
ItkImage
Type
FixedImage
Type
;
typedef
typename
DisplacementFieldItkImageSourceInterface
<
Dimensionality
,
TPixel
>::
ItkImageType
DisplacementFieldImageType
;
using
itkImageDomainFixedType
=
typename
itkImage
Domain
FixedInterface
<
Dimensionality
>::
ItkImage
Domain
Type
;
using
DisplacementFieldImageType
=
typename
DisplacementFieldItkImageSourceInterface
<
Dimensionality
,
TPixel
>::
ItkImageType
;
// TODO for now we hard code the transform to be a stationary velocity field. See Set(*MetricInterface) for implementation
typedef
itk
::
TransformToDisplacementFieldFilter
<
DisplacementFieldImageType
>
DisplacementFieldFilterType
;
using
DisplacementFieldFilterType
=
itk
::
TransformToDisplacementFieldFilter
<
DisplacementFieldImageType
>
;
//Accepting Interfaces:
virtual
int
Set
(
itkImageFixedInterface
<
Dimensionality
,
TPixel
>*
)
override
;
virtual
int
Set
(
itkImage
Domain
FixedInterface
<
Dimensionality
>*
)
override
;
virtual
int
Set
(
itkTransformInterface
<
TInternalComputationValue
,
Dimensionality
>*
)
override
;
//Providing Interfaces:
virtual
typename
DisplacementFieldImageType
::
Pointer
GetDisplacementFieldItkImage
()
override
;
virtual
void
ReconnectTransform
()
override
;
//BaseClass methods
virtual
bool
MeetsCriterion
(
const
ComponentBase
::
CriterionType
&
criterion
)
override
;
...
...
@@ -79,6 +79,7 @@ namespace selx
private:
typename
DisplacementFieldFilterType
::
Pointer
m_DisplacementFieldFilter
;
itkTransformInterface
<
TInternalComputationValue
,
Dimensionality
>*
m_TransformComponent
;
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
...
...
Modules/Components/itkImageRegistrationMethodv4/include/selxItkTransformDisplacementFilter.hxx
View file @
5da4a145
...
...
@@ -37,15 +37,15 @@ namespace selx
template
<
int
Dimensionality
,
class
TPixel
,
class
TInternalComputationValue
>
int
ItkTransformDisplacementFilterComponent
<
Dimensionality
,
TPixel
,
TInternalComputationValue
>
::
Set
(
itkImageFixedInterface
<
Dimensionality
,
TPixel
>*
component
)
::
Set
(
itkImage
Domain
FixedInterface
<
Dimensionality
>*
component
)
{
auto
fixedImage
=
component
->
GetItkImageFixed
();
auto
fixedImage
Domain
=
component
->
GetItkImage
Domain
Fixed
();
// connect the itk pipeline
//this->m_DisplacementFieldFilter->SetSize(fixedImage->GetBufferedRegion().GetSize()); //should be virtual image...
this
->
m_DisplacementFieldFilter
->
SetSize
(
fixedImage
->
GetLargestPossibleRegion
().
GetSize
());
//should be virtual image...
this
->
m_DisplacementFieldFilter
->
SetOutputOrigin
(
fixedImage
->
GetOrigin
());
this
->
m_DisplacementFieldFilter
->
SetOutputSpacing
(
fixedImage
->
GetSpacing
());
this
->
m_DisplacementFieldFilter
->
SetOutputDirection
(
fixedImage
->
GetDirection
());
this
->
m_DisplacementFieldFilter
->
SetSize
(
fixedImage
Domain
->
GetLargestPossibleRegion
().
GetSize
());
//should be virtual image...
this
->
m_DisplacementFieldFilter
->
SetOutputOrigin
(
fixedImage
Domain
->
GetOrigin
());
this
->
m_DisplacementFieldFilter
->
SetOutputSpacing
(
fixedImage
Domain
->
GetSpacing
());
this
->
m_DisplacementFieldFilter
->
SetOutputDirection
(
fixedImage
Domain
->
GetDirection
());
this
->
m_DisplacementFieldFilter
->
UpdateOutputInformation
();
return
0
;
...
...
@@ -55,9 +55,12 @@ template <int Dimensionality, class TPixel, class TInternalComputationValue>
int
ItkTransformDisplacementFilterComponent
<
Dimensionality
,
TPixel
,
TInternalComputationValue
>
::
Set
(
itkTransformInterface
<
TInternalComputationValue
,
Dimensionality
>*
component
)
{
//Store interface for later use
this
->
m_TransformComponent
=
component
;
auto
transform
=
component
->
GetItkTransform
();
// connect the itk pipeline
this
->
m_DisplacementFieldFilter
->
SetTransform
(
transform
.
GetPointer
()
);
this
->
m_DisplacementFieldFilter
->
SetTransform
(
transform
);
return
0
;
}
...
...
@@ -73,6 +76,15 @@ ItkTransformDisplacementFilterComponent< Dimensionality, TPixel, TInternalComput
}
template
<
int
Dimensionality
,
class
TPixel
,
class
TInternalComputationValue
>
void
ItkTransformDisplacementFilterComponent
<
Dimensionality
,
TPixel
,
TInternalComputationValue
>
::
ReconnectTransform
()
{
auto
transform
=
this
->
m_TransformComponent
->
GetItkTransform
();
// reconnect the tranform, since it does not comply with the itk pipeline
this
->
m_DisplacementFieldFilter
->
SetTransform
(
transform
);
}
template
<
int
Dimensionality
,
class
TPixel
,
class
TInternalComputationValue
>
bool
ItkTransformDisplacementFilterComponent
<
Dimensionality
,
TPixel
,
TInternalComputationValue
>
...
...
Modules/Components/itkImageRegistrationMethodv4/test/selxWBIRDemoTest.cxx
View file @
5da4a145
...
...
@@ -121,7 +121,7 @@ TEST_F(WBIRDemoTest, itkv4_SVF_ANTSCC)
blueprint
->
AddComponent
(
"Metric"
,
{
{
"NameOfClass"
,
{
"ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component"
}
}
});
blueprint
->
AddComponent
(
"Optimizer"
,
{
{
"NameOfClass"
,
{
"ItkGradientDescentOptimizerv4Component"
}
},
{
"NumberOfIterations"
,
{
"100"
}
},
{
"LearningRate"
,
{
"
0.
00
1
"
}
}
});
{
"LearningRate"
,
{
"
1
00"
}
}
});
blueprint
->
AddComponent
(
"Transform"
,
{
{
"NameOfClass"
,
{
"ItkGaussianExponentialDiffeomorphicTransformComponent"
}
}
});
blueprint
->
AddComponent
(
"ResampleFilter"
,
{
{
"NameOfClass"
,
{
"ItkResampleFilterComponent"
}
}
});
...
...
Modules/Core/ComponentInterface/include/InterfaceTraits.h
View file @
5da4a145
...
...
@@ -217,6 +217,16 @@ struct InterfaceName < AfterRegistrationInterface >
}
};
template
<
>
struct
InterfaceName
<
ReconnectTransformInterface
>
{
static
const
char
*
Get
()
{
return
"ReconnectTransformInterface"
;
}
};
// partial specialization of InterfaceName
// InterfaceName<T>::Get() should return the same name no matter whether T is an acceptor or provider interface.
template
<
typename
T1
>
...
...
Modules/Core/ComponentInterface/include/Interfaces.h
View file @
5da4a145
...
...
@@ -101,6 +101,7 @@ namespace selx
typedef
typename
itk
::
Image
<
TPixel
,
Dimensionality
>
ItkImageType
;
virtual
typename
ItkImageType
::
Pointer
GetItkImageMoving
()
=
0
;
};
template
<
int
Dimensionality
,
class
TPixel
>
class
DisplacementFieldItkImageSourceInterface
{
// An interface that passes the pointer of an output image
...
...
@@ -157,6 +158,13 @@ namespace selx
virtual
bool
RunResolution
()
=
0
;
};
class
ReconnectTransformInterface
{
// A special interface: the Overlord checks components for this type of interface.
// This interface is for to control the execution of the network
public:
virtual
void
ReconnectTransform
()
=
0
;
};
template
<
int
Dimensionality
,
class
TPixel
>
class
itkMetricv4Interface
{
public:
...
...
Modules/Core/ComponentInterface/include/Overlord.h
View file @
5da4a145
...
...
@@ -101,7 +101,7 @@ namespace selx
bool
ConnectSinks
();
bool
RunRegistrations
();
bool
AfterRegistrations
();
bool
ReconnectTransforms
();
//TODO make const correct
//Blueprint::ConstPointer m_Blueprint;
BlueprintType
::
Pointer
m_Blueprint
;
...
...
Modules/Core/ComponentInterface/src/Overlord.cxx
View file @
5da4a145
...
...
@@ -300,6 +300,35 @@ namespace selx
}
return
true
;
}
bool
Overlord
::
ReconnectTransforms
()
{
/** Scans all Components to find those with ReconnectTransform capability and call them */
const
CriterionType
criterion
=
CriterionType
(
"HasProvidingInterface"
,
{
"ReconnectTransformInterface"
});
// TODO redesign ComponentBase class to accept a single criterion instead of a criteria mapping.
CriteriaType
criteria
;
criteria
.
insert
(
criterion
);
for
(
auto
const
&
componentSelector
:
(
this
->
m_ComponentSelectorContainer
))
{
ComponentBase
::
Pointer
component
=
componentSelector
.
second
->
GetComponent
();
if
(
component
->
MeetsCriteria
(
criteria
))
// TODO MeetsCriterion
{
ReconnectTransformInterface
*
providingInterface
=
dynamic_cast
<
ReconnectTransformInterface
*>
(
component
.
GetPointer
());
if
(
providingInterface
==
nullptr
)
// is actually a double-check for sanity: based on criterion cast should be successful
{
itkExceptionMacro
(
"dynamic_cast<ReconnectTransformInterface*> fails, but based on component criterion it shouldn't"
)
}
// For testing purposes, all Sources are connected to an ImageWriter
providingInterface
->
ReconnectTransform
();
}
}
return
true
;
}
bool
Overlord
::
Execute
()
{
...
...
@@ -314,6 +343,7 @@ namespace selx
// TODO: see if signals-and-slots paradigm is appropriate here.
this
->
RunRegistrations
();
this
->
ReconnectTransforms
();
this
->
AfterRegistrations
();
//update all writers...
...
...
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