Commit 8d07d8a3 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

DOC: beautified code by Uncrustify

parent 22451ace
......@@ -42,85 +42,86 @@ 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;
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;
......@@ -128,55 +129,55 @@ int main(int ac, char* av[])
// 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",
// 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;
}
......@@ -27,46 +27,49 @@
namespace selx
{
template<bool dummy = true>
class RegistrationControllerComponent :
public SuperElastixComponent <
template< bool dummy = true >
class RegistrationControllerComponent :
public SuperElastixComponent<
Accepting< RunRegistrationInterface, ReconnectTransformInterface, AfterRegistrationInterface >,
Providing < RegistrationControllerStartInterface >
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:
public:
selxNewMacro(RegistrationControllerComponent, ComponentBase);
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;
virtual int Set( RunRegistrationInterface * ) override;
virtual int Set( ReconnectTransformInterface * ) override;
virtual int Set( AfterRegistrationInterface * ) override;
// Providing Interfaces:
virtual void RegistrationControllerStart(void) override;
virtual void RegistrationControllerStart( void ) override;
virtual bool MeetsCriterion( const ComponentBase::CriterionType & criterion ) override;
static const char * GetDescription() { return "RegistrationController Component"; }
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;
private:
protected:
};
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"
......
......@@ -21,45 +21,54 @@
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);
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>
int RegistrationControllerComponent< dummy>::Set(ReconnectTransformInterface* other)
{
this->m_ReconnectTransformInterfaces.insert(other);
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);
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)
template< bool dummy >
void
RegistrationControllerComponent< dummy >::RegistrationControllerStart()
{
for( auto && runRegistrationInterface : this->m_RunRegistrationInterfaces )
{
runRegistrationInterface->RunRegistration();
}
for (auto && reconnectTransformInterface : this->m_ReconnectTransformInterfaces)
for( auto && reconnectTransformInterface : this->m_ReconnectTransformInterfaces )
{
reconnectTransformInterface->ReconnectTransform();
}
......@@ -67,25 +76,26 @@ namespace selx
//{
// afterRegistrationInterface->AfterRegistration();
//}
}
}
template<bool dummy>
bool RegistrationControllerComponent< dummy>::MeetsCriterion(const ComponentBase::CriterionType &criterion)
{
bool hasUndefinedCriteria(false);
bool meetsCriteria(false);
if (criterion.first == "ComponentProperty")
template< bool dummy >
bool
RegistrationControllerComponent< dummy >::MeetsCriterion( const ComponentBase::CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
return meetsCriteria;
}
}
} //end namespace selx
......@@ -32,21 +32,22 @@
#include "selxMacro.h"
namespace selx
{
template <int Dimensionality, class TPixel>
class ElastixComponent :
template< int Dimensionality, class TPixel >
class ElastixComponent :
public SuperElastixComponent<
Accepting<
itkImageFixedInterface<Dimensionality, TPixel>,
itkImageMovingInterface<Dimensionality, TPixel>
itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >
>,
Providing<
itkImageInterface<Dimensionality, TPixel>,
itkImageInterface< Dimensionality, TPixel >,
RunRegistrationInterface
>
>
{
public:
selxNewMacro(ElastixComponent, ComponentBase);
{
public:
selxNewMacro( ElastixComponent, ComponentBase );
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
......@@ -57,11 +58,11 @@ namespace selx
typedef TPixel PixelType;
// the in and output image type of the component are chosen to be the same
typedef itk::Image<PixelType, Dimensionality> ConnectionImageType;
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 itk::Image< PixelType, Dimensionality > FixedImageType;
typedef itk::Image< PixelType, Dimensionality > MovingImageType;
typedef typename ConnectionImageType::Pointer ItkImagePointer;
......@@ -69,126 +70,139 @@ namespace selx
typedef elastix::ParameterObject elxParameterObjectType;
typedef elxParameterObjectType::Pointer elxParameterObjectPointer;
typedef elastix::TransformixFilter<FixedImageType> TransformixFilterType;
typedef elastix::TransformixFilter< FixedImageType > TransformixFilterType;
typedef itk::ResampleImageFilter< MovingImageType, ConnectionImageType > ResampleFilterType;
typedef itk::ResampleImageFilter<MovingImageType, ConnectionImageType> ResampleFilterType;
virtual int Set( itkImageFixedInterface< Dimensionality, TPixel > * ) override;
virtual int Set(itkImageFixedInterface<Dimensionality, TPixel>*) override;
virtual int Set(itkImageMovingInterface<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:
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:
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());
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());
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.
// unfortunately partial specialization of member functions is not allowed, without partially specializing the entire class.
/*
template <int Dimensionality>
class ElastixComponent < Dimensionality, double >
{
/*
template <int Dimensionality>
class ElastixComponent < Dimensionality, double >
{
static inline const std::string GetPixelTypeNameString();
};
};
template <int Dimensionality>
inline const std::string
template <int Dimensionality>
inline const std::string
ElastixComponent<Dimensionality, double>
::GetPixelTypeNameString()
{
{
return std::string("double");
}
*/
}
*/
template <>
inline const std::string
ElastixComponent<2, float>
::GetPixelTypeNameString()
{
return std::string("float");
}
template< >
inline const std::string
ElastixComponent< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template <>
inline const std::string
ElastixComponent<2, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
template< >
inline const std::string
ElastixComponent< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template <>
inline const std::string
ElastixComponent<3, float>
::GetPixelTypeNameString()
{
return std::string("float");
}
template <>
inline const std::string
ElastixComponent<3, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
template <>
inline const std::string
ElastixComponent<2, float>
::GetTypeNameString()
{
return std::string("2_float");
}
template< >
inline const std::string
ElastixComponent< 3, float >
::GetPixelTypeNameString()
{