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
8d07d8a3
Commit
8d07d8a3
authored
Aug 16, 2016
by
Floris Berendsen
Browse files
DOC: beautified code by Uncrustify
parent
22451ace
Changes
128
Hide whitespace changes
Inline
Side-by-side
Modules/CommandLine/src/selxCommandLine.cxx
View file @
8d07d8a3
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -42,141 +42,142 @@ namespace po = boost::program_options;
using
namespace
std
;
using
namespace
selx
;
template
<
class
T
>
ostream
&
operator
<<
(
ostream
&
os
,
const
vector
<
T
>&
v
)
template
<
class
T
>
ostream
&
operator
<<
(
ostream
&
os
,
const
vector
<
T
>
&
v
)
{
copy
(
v
.
begin
(),
v
.
end
(),
ostream_iterator
<
T
>
(
os
,
" "
)
);
copy
(
v
.
begin
(),
v
.
end
(),
ostream_iterator
<
T
>
(
os
,
" "
)
);
return
os
;
}
int
main
(
int
ac
,
char
*
av
[])
int
main
(
int
ac
,
char
*
av
[]
)
{
try
{
try
{
typedef
vector
<
string
>
split_vector_type
;
SuperElastixFilter
<
DefaultComponents
>::
Pointer
superElastixFilter
=
SuperElastixFilter
<
DefaultComponents
>::
New
();
SuperElastixFilter
<
DefaultComponents
>::
Pointer
superElastixFilter
=
SuperElastixFilter
<
DefaultComponents
>::
New
();
fs
::
path
configurationPath
;
vector
<
string
>
inputPairs
;
vector
<
string
>
outputPairs
;
fs
::
path
configurationPath
;
vector
<
string
>
inputPairs
;
vector
<
string
>
outputPairs
;
// Store the reader so that they will not be destroyed before the pipeline is executed.
vector
<
AnyFileReader
::
Pointer
>
fileReaders
;
vector
<
AnyFileReader
::
Pointer
>
fileReaders
;
// Store the writers for the update call
//vector<ImageWriter2DType::Pointer> fileWriters;
vector
<
AnyFileWriter
::
Pointer
>
fileWriters
;
vector
<
AnyFileWriter
::
Pointer
>
fileWriters
;
po
::
options_description
desc
(
"Allowed options"
);
po
::
options_description
desc
(
"Allowed options"
);
desc
.
add_options
()
(
"help"
,
"produce help message"
)
(
"conf"
,
po
::
value
<
fs
::
path
>
(
&
configurationPath
)
->
required
(),
"Configuration file"
)
(
"in"
,
po
::
value
<
vector
<
string
>>
(
&
inputPairs
)
->
multitoken
(),
"Input data: images, labels, meshes, etc. Usage <name>=<path>"
)
(
"out"
,
po
::
value
<
vector
<
string
>>
(
&
outputPairs
)
->
multitoken
(),
"Output data: images, labels, meshes, etc. Usage <name>=<path>"
)
(
"graphout"
,
po
::
value
<
fs
::
path
>
(),
"Output Graphviz dot file"
)
;
(
"help"
,
"produce help message"
)
(
"conf"
,
po
::
value
<
fs
::
path
>
(
&
configurationPath
)
->
required
(),
"Configuration file"
)
(
"in"
,
po
::
value
<
vector
<
string
>>
(
&
inputPairs
)
->
multitoken
(),
"Input data: images, labels, meshes, etc. Usage <name>=<path>"
)
(
"out"
,
po
::
value
<
vector
<
string
>>
(
&
outputPairs
)
->
multitoken
(),
"Output data: images, labels, meshes, etc. Usage <name>=<path>"
)
(
"graphout"
,
po
::
value
<
fs
::
path
>
(),
"Output Graphviz dot file"
)
;
po
::
variables_map
vm
;
po
::
store
(
po
::
parse_command_line
(
ac
,
av
,
desc
),
vm
);
po
::
notify
(
vm
);
po
::
store
(
po
::
parse_command_line
(
ac
,
av
,
desc
),
vm
);
po
::
notify
(
vm
);
if
(
vm
.
count
(
"help"
))
{
if
(
vm
.
count
(
"help"
)
)
{
cout
<<
desc
<<
"
\n
"
;
return
0
;
}
Blueprint
::
Pointer
blueprint
;
if
(
configurationPath
.
extension
()
==
".xml"
)
if
(
configurationPath
.
extension
()
==
".xml"
)
{
// TODO: open file here and pass a stream to the ConfigurationReader
blueprint
=
ConfigurationReader
::
FromXML
(
configurationPath
.
string
());
blueprint
=
ConfigurationReader
::
FromXML
(
configurationPath
.
string
()
);
}
else
if
(
configurationPath
.
extension
()
==
".json"
)
else
if
(
configurationPath
.
extension
()
==
".json"
)
{
// TODO: open file here and pass a stream to the ConfigurationReader
blueprint
=
ConfigurationReader
::
FromJson
(
configurationPath
.
string
());
blueprint
=
ConfigurationReader
::
FromJson
(
configurationPath
.
string
()
);
}
else
{
throw
invalid_argument
(
"Configuration file requires extension .xml or .json"
);
else
{
throw
invalid_argument
(
"Configuration file requires extension .xml or .json"
);
}
if
(
vm
.
count
(
"graphout"
)
)
if
(
vm
.
count
(
"graphout"
)
)
{
blueprint
->
WriteBlueprint
(
vm
[
"graphout"
].
as
<
fs
::
path
>
().
string
());
blueprint
->
WriteBlueprint
(
vm
[
"graphout"
].
as
<
fs
::
path
>
().
string
()
);
}
superElastixFilter
->
SetBlueprint
(
blueprint
);
superElastixFilter
->
SetBlueprint
(
blueprint
);
if
(
vm
.
count
(
"in"
))
{
if
(
vm
.
count
(
"in"
)
)
{
cout
<<
"Number of input data: "
<<
inputPairs
.
size
()
<<
"
\n
"
;
int
index
=
0
;
for
(
const
auto
&
inputPair
:
inputPairs
)
for
(
const
auto
&
inputPair
:
inputPairs
)
{
split_vector_type
nameAndPath
;
boost
::
split
(
nameAndPath
,
inputPair
,
boost
::
is_any_of
(
"="
)
);
// NameAndPath == { "name","path" }
const
string
&
name
=
nameAndPath
[
0
];
const
string
&
path
=
nameAndPath
[
1
];
boost
::
split
(
nameAndPath
,
inputPair
,
boost
::
is_any_of
(
"="
)
);
// NameAndPath == { "name","path" }
const
string
&
name
=
nameAndPath
[
0
];
const
string
&
path
=
nameAndPath
[
1
];
cout
<<
" "
<<
index
<<
" "
<<
name
<<
" : "
<<
path
<<
"
\n
"
;
++
index
;
// since we do not know which reader type we should instantiate for input "name",
// since we do not know which reader type we should instantiate for input "name",
// we ask SuperElastix for a reader that matches the type of the source component "name"
AnyFileReader
::
Pointer
reader
=
superElastixFilter
->
GetInputFileReader
(
name
);
reader
->
SetFileName
(
path
);
superElastixFilter
->
SetInput
(
name
,
reader
->
GetOutput
());
fileReaders
.
push_back
(
reader
);
AnyFileReader
::
Pointer
reader
=
superElastixFilter
->
GetInputFileReader
(
name
);
reader
->
SetFileName
(
path
);
superElastixFilter
->
SetInput
(
name
,
reader
->
GetOutput
()
);
fileReaders
.
push_back
(
reader
);
}
}
if
(
vm
.
count
(
"out"
))
{
if
(
vm
.
count
(
"out"
)
)
{
cout
<<
"Number of output data: "
<<
outputPairs
.
size
()
<<
"
\n
"
;
int
index
=
0
;
for
(
const
auto
&
outputPair
:
outputPairs
)
for
(
const
auto
&
outputPair
:
outputPairs
)
{
split_vector_type
nameAndPath
;
boost
::
split
(
nameAndPath
,
outputPair
,
boost
::
is_any_of
(
"="
)
);
// NameAndPath == { "name","path" }
const
string
&
name
=
nameAndPath
[
0
];
const
string
&
path
=
nameAndPath
[
1
];
boost
::
split
(
nameAndPath
,
outputPair
,
boost
::
is_any_of
(
"="
)
);
// NameAndPath == { "name","path" }
const
string
&
name
=
nameAndPath
[
0
];
const
string
&
path
=
nameAndPath
[
1
];
cout
<<
" "
<<
index
<<
" "
<<
name
<<
" : "
<<
path
<<
"
\n
"
;
++
index
;
// since we do not know which writer type we should instantiate for output "name",
// since we do not know which writer type we should instantiate for output "name",
// we ask SuperElastix for a writer that matches the type of the sink component "name"
AnyFileWriter
::
Pointer
writer
=
superElastixFilter
->
GetOutputFileWriter
(
name
);
AnyFileWriter
::
Pointer
writer
=
superElastixFilter
->
GetOutputFileWriter
(
name
);
//ImageWriter2DType::Pointer writer = ImageWriter2DType::New();
writer
->
SetFileName
(
path
);
writer
->
SetFileName
(
path
);
//writer->SetInput(superElastixFilter->GetOutput<Image2DType>(name));
writer
->
SetInput
(
superElastixFilter
->
GetOutput
(
name
)
);
fileWriters
.
push_back
(
writer
);
writer
->
SetInput
(
superElastixFilter
->
GetOutput
(
name
)
);
fileWriters
.
push_back
(
writer
);
}
}
/* Execute SuperElastix by updating the writers */
for
(
auto
&
writer
:
fileWriters
)
for
(
auto
&
writer
:
fileWriters
)
{
writer
->
Update
();
}
}
catch
(
exception
&
e
)
{
catch
(
exception
&
e
)
{
cerr
<<
"error: "
<<
e
.
what
()
<<
"
\n
"
;
return
1
;
}
catch
(...)
{
catch
(
...
)
{
cerr
<<
"Exception of unknown type!
\n
"
;
}
return
0
;
}
\ No newline at end of file
}
Modules/Components/Controller/include/selxRegistrationController.h
View file @
8d07d8a3
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -27,48 +27,51 @@
namespace
selx
{
template
<
bool
dummy
=
true
>
class
RegistrationControllerComponent
:
public
SuperElastixComponent
<
Accepting
<
RunRegistrationInterface
,
ReconnectTransformInterface
,
AfterRegistrationInterface
>
,
Providing
<
RegistrationControllerStartInterface
>
>
{
// RegistrationControllerComponent is a work-around for broken itk-pipelines.
// Both the elastix and itkv4 require to connect their transforms *after* execution of the registration.
// This controller explicitly performs these steps
// TODO: see if signals-and-slots paradigm is appropriate here.
public:
selxNewMacro
(
RegistrationControllerComponent
,
ComponentBase
);
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
RegistrationControllerComponent
();
virtual
~
RegistrationControllerComponent
();
// Accepting Interfaces:
virtual
int
Set
(
RunRegistrationInterface
*
)
override
;
virtual
int
Set
(
ReconnectTransformInterface
*
)
override
;
virtual
int
Set
(
AfterRegistrationInterface
*
)
override
;
// Providing Interfaces:
virtual
void
RegistrationControllerStart
(
void
)
override
;
virtual
bool
MeetsCriterion
(
const
ComponentBase
::
CriterionType
&
criterion
)
override
;
static
const
char
*
GetDescription
()
{
return
"RegistrationController Component"
;
};
private:
std
::
set
<
RunRegistrationInterface
*>
m_RunRegistrationInterfaces
;
std
::
set
<
ReconnectTransformInterface
*>
m_ReconnectTransformInterfaces
;
std
::
set
<
AfterRegistrationInterface
*>
m_AfterRegistrationInterfaces
;
protected:
};
template
<
bool
dummy
=
true
>
class
RegistrationControllerComponent
:
public
SuperElastixComponent
<
Accepting
<
RunRegistrationInterface
,
ReconnectTransformInterface
,
AfterRegistrationInterface
>
,
Providing
<
RegistrationControllerStartInterface
>
>
{
// RegistrationControllerComponent is a work-around for broken itk-pipelines.
// Both the elastix and itkv4 require to connect their transforms *after* execution of the registration.
// This controller explicitly performs these steps
// TODO: see if signals-and-slots paradigm is appropriate here.
public:
selxNewMacro
(
RegistrationControllerComponent
,
ComponentBase
);
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
RegistrationControllerComponent
();
virtual
~
RegistrationControllerComponent
();
// Accepting Interfaces:
virtual
int
Set
(
RunRegistrationInterface
*
)
override
;
virtual
int
Set
(
ReconnectTransformInterface
*
)
override
;
virtual
int
Set
(
AfterRegistrationInterface
*
)
override
;
// Providing Interfaces:
virtual
void
RegistrationControllerStart
(
void
)
override
;
virtual
bool
MeetsCriterion
(
const
ComponentBase
::
CriterionType
&
criterion
)
override
;
static
const
char
*
GetDescription
()
{
return
"RegistrationController Component"
;
}
private:
std
::
set
<
RunRegistrationInterface
*
>
m_RunRegistrationInterfaces
;
std
::
set
<
ReconnectTransformInterface
*
>
m_ReconnectTransformInterfaces
;
std
::
set
<
AfterRegistrationInterface
*
>
m_AfterRegistrationInterfaces
;
protected:
};
}
//end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include
"selxRegistrationController.hxx"
#endif
#endif // #define selxRegistrationController_h
\ No newline at end of file
#endif // #define selxRegistrationController_h
Modules/Components/Controller/include/selxRegistrationController.hxx
View file @
8d07d8a3
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -21,71 +21,81 @@
namespace
selx
{
template
<
bool
dummy
>
RegistrationControllerComponent
<
dummy
>::
RegistrationControllerComponent
()
{
}
template
<
bool
dummy
>
RegistrationControllerComponent
<
dummy
>::
RegistrationControllerComponent
()
{
}
template
<
bool
dummy
>
RegistrationControllerComponent
<
dummy
>::~
RegistrationControllerComponent
()
{
}
template
<
bool
dummy
>
int
RegistrationControllerComponent
<
dummy
>::
Set
(
RunRegistrationInterface
*
other
)
{
this
->
m_RunRegistrationInterfaces
.
insert
(
other
);
return
0
;
}
template
<
bool
dummy
>
RegistrationControllerComponent
<
dummy
>::~
RegistrationControllerComponent
()
{
}
template
<
bool
dummy
>
int
RegistrationControllerComponent
<
dummy
>::
Set
(
ReconnectTransformInterface
*
other
)
{
this
->
m_ReconnectTransformInterfaces
.
insert
(
other
);
return
0
;
}
template
<
bool
dummy
>
int
RegistrationControllerComponent
<
dummy
>::
Set
(
AfterRegistrationInterface
*
other
)
template
<
bool
dummy
>
int
RegistrationControllerComponent
<
dummy
>::
Set
(
RunRegistrationInterface
*
other
)
{
this
->
m_RunRegistrationInterfaces
.
insert
(
other
);
return
0
;
}
template
<
bool
dummy
>
int
RegistrationControllerComponent
<
dummy
>::
Set
(
ReconnectTransformInterface
*
other
)
{
this
->
m_ReconnectTransformInterfaces
.
insert
(
other
);
return
0
;
}
template
<
bool
dummy
>
int
RegistrationControllerComponent
<
dummy
>::
Set
(
AfterRegistrationInterface
*
other
)
{
this
->
m_AfterRegistrationInterfaces
.
insert
(
other
);
return
0
;
}
template
<
bool
dummy
>
void
RegistrationControllerComponent
<
dummy
>::
RegistrationControllerStart
()
{
for
(
auto
&&
runRegistrationInterface
:
this
->
m_RunRegistrationInterfaces
)
{
this
->
m_AfterRegistrationInterfaces
.
insert
(
other
);
return
0
;
runRegistrationInterface
->
RunRegistration
();
}
template
<
bool
dummy
>
void
RegistrationControllerComponent
<
dummy
>::
RegistrationControllerStart
()
for
(
auto
&&
reconnectTransformInterface
:
this
->
m_ReconnectTransformInterfaces
)
{
for
(
auto
&&
runRegistrationInterface
:
this
->
m_RunRegistrationInterfaces
)
{
runRegistrationInterface
->
RunRegistration
();
}
for
(
auto
&&
reconnectTransformInterface
:
this
->
m_ReconnectTransformInterfaces
)
{
reconnectTransformInterface
->
ReconnectTransform
();
}
//for (auto && afterRegistrationInterface : this->m_AfterRegistrationInterfaces)
//{
// afterRegistrationInterface->AfterRegistration();
//}
reconnectTransformInterface
->
ReconnectTransform
();
}
//for (auto && afterRegistrationInterface : this->m_AfterRegistrationInterfaces)
//{
// afterRegistrationInterface->AfterRegistration();
//}
}
template
<
bool
dummy
>
bool
RegistrationControllerComponent
<
dummy
>::
MeetsCriterion
(
const
ComponentBase
::
CriterionType
&
criterion
)
template
<
bool
dummy
>
bool
RegistrationControllerComponent
<
dummy
>::
MeetsCriterion
(
const
ComponentBase
::
CriterionType
&
criterion
)
{
bool
hasUndefinedCriteria
(
false
);
bool
meetsCriteria
(
false
);
if
(
criterion
.
first
==
"ComponentProperty"
)
{
bool
hasUndefinedCriteria
(
false
);
bool
meetsCriteria
(
false
);
if
(
criterion
.
first
==
"ComponentProperty"
)
meetsCriteria
=
true
;
for
(
auto
const
&
criterionValue
:
criterion
.
second
)
// auto&& preferred?
{
meetsCriteria
=
true
;
for
(
auto
const
&
criterionValue
:
criterion
.
second
)
// auto&& preferred?
if
(
criterionValue
!=
"SomeProperty"
)
// e.g. "GradientDescent", "SupportsSparseSamples
{
if
(
criterionValue
!=
"SomeProperty"
)
// e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria
=
false
;
}
meetsCriteria
=
false
;
}
}
return
meetsCriteria
;
}
}
return
meetsCriteria
;
}
}
//end namespace selx
Modules/Components/Controller/src/selxRegistrationController.cxx
View file @
8d07d8a3
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
...
...
Modules/Components/Elastix/include/selxElastixComponent.h
View file @
8d07d8a3
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -32,165 +32,179 @@
#include
"selxMacro.h"
namespace
selx
{
template
<
int
Dimensionality
,
class
TPixel
>
class
ElastixComponent
:
public
SuperElastixComponent
<
Accepting
<
itkImageFixedInterface
<
Dimensionality
,
TPixel
>
,
itkImageMovingInterface
<
Dimensionality
,
TPixel
>
>
,
Providing
<
itkImageInterface
<
Dimensionality
,
TPixel
>
,
RunRegistrationInterface
>
>
{
public:
selxNewMacro
(
ElastixComponent
,
ComponentBase
);
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
ElastixComponent
();
virtual
~
ElastixComponent
();
typedef
typename
ComponentBase
::
CriterionType
CriterionType
;
typedef
TPixel
PixelType
;
// the in and output image type of the component are chosen to be the same
typedef
itk
::
Image
<
PixelType
,
Dimensionality
>
ConnectionImageType
;
// 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
ConnectionImageType
::
Pointer
ItkImagePointer
;
typedef
elastix
::
ElastixFilter
<
FixedImageType
,
MovingImageType
>
ElastixFilterType
;
typedef
elastix
::
ParameterObject
elxParameterObjectType
;
typedef
elxParameterObjectType
::
Pointer
elxParameterObjectPointer
;
typedef
elastix
::
TransformixFilter
<
FixedImageType
>
TransformixFilterType
;
typedef
itk
::
ResampleImageFilter
<
MovingImageType
,
ConnectionImageType
>
ResampleFilterType
;
virtual
int
Set
(
itkImageFixedInterface
<
Dimensionality
,
TPixel
>*
)
override
;
virtual
int
Set
(
itkImageMovingInterface
<
Dimensionality
,
TPixel
>*
)
override
;
virtual
ItkImagePointer
GetItkImage
()
override
;
virtual
void
RunRegistration
()
override
;
virtual
bool
MeetsCriterion
(
const
CriterionType
&
criterion
)
override
;
static
const
char
*
GetDescription
()
{
return
"Elastix Component"
;
};
private:
typename
ElastixFilterType
::
Pointer
m_elastixFilter
;
typename
TransformixFilterType
::
Pointer
m_transformixFilter
;
//selxParameterObjectPointer m_ParameterObject;
ItkImagePointer
m_OutputImage
;
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 ElastixComponent < Dimensionality, double >
{
static inline const std::string GetPixelTypeNameString();
};
template
<
int
Dimensionality
,
class
TPixel
>
class
ElastixComponent
:
public
SuperElastixComponent
<
Accepting
<
itkImageFixedInterface
<
Dimensionality
,
TPixel
>
,
itkImageMovingInterface
<
Dimensionality
,
TPixel
>
>
,
Providing
<
itkImageInterface
<
Dimensionality
,
TPixel
>
,
RunRegistrationInterface
>
>
{
public:
template <int Dimensionality>
inline const std::string
ElastixComponent<Dimensionality, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
*/
selxNewMacro
(
ElastixComponent
,
ComponentBase
);
template
<
>
inline
const
std
::
string
ElastixComponent
<
2
,
float
>