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

DOC: beautified code by Uncrustify

parent 22451ace
/*========================================================================= /*=========================================================================
* *
* Copyright Leiden University Medical Center, Erasmus University Medical * Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors * Center and contributors
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -42,141 +42,142 @@ namespace po = boost::program_options; ...@@ -42,141 +42,142 @@ namespace po = boost::program_options;
using namespace std; using namespace std;
using namespace selx; using namespace selx;
template<class T> template< class T >
ostream& operator<<(ostream& os, const vector<T>& v) 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; return os;
} }
int
main( int ac, char * av[] )
int main(int ac, char* av[])
{ {
try { try
{
typedef vector< string > split_vector_type; typedef vector< string > split_vector_type;
SuperElastixFilter<DefaultComponents>::Pointer superElastixFilter = SuperElastixFilter<DefaultComponents>::New(); SuperElastixFilter< DefaultComponents >::Pointer superElastixFilter = SuperElastixFilter< DefaultComponents >::New();
fs::path configurationPath; fs::path configurationPath;
vector<string> inputPairs; vector< string > inputPairs;
vector<string> outputPairs; vector< string > outputPairs;
// Store the reader so that they will not be destroyed before the pipeline is executed. // 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 // Store the writers for the update call
//vector<ImageWriter2DType::Pointer> fileWriters; //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() desc.add_options()
("help", "produce help message") ( "help", "produce help message" )
("conf", po::value<fs::path>(&configurationPath)->required(), "Configuration file") ( "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>") ( "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>") ( "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") ( "graphout", po::value< fs::path >(), "Output Graphviz dot file" )
; ;
po::variables_map vm; po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm); po::store( po::parse_command_line( ac, av, desc ), vm );
po::notify(vm); po::notify( vm );
if (vm.count("help")) { if( vm.count( "help" ) )
{
cout << desc << "\n"; cout << desc << "\n";
return 0; return 0;
} }
Blueprint::Pointer blueprint; Blueprint::Pointer blueprint;
if (configurationPath.extension() == ".xml") if( configurationPath.extension() == ".xml" )
{ {
// TODO: open file here and pass a stream to the ConfigurationReader // 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 // TODO: open file here and pass a stream to the ConfigurationReader
blueprint = ConfigurationReader::FromJson(configurationPath.string()); blueprint = ConfigurationReader::FromJson( configurationPath.string() );
} }
else { else
throw invalid_argument("Configuration file requires extension .xml or .json"); {
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"; cout << "Number of input data: " << inputPairs.size() << "\n";
int index = 0; int index = 0;
for (const auto & inputPair : inputPairs) for( const auto & inputPair : inputPairs )
{ {
split_vector_type nameAndPath; split_vector_type nameAndPath;
boost::split(nameAndPath, inputPair, boost::is_any_of("=")); // NameAndPath == { "name","path" } boost::split( nameAndPath, inputPair, boost::is_any_of( "=" ) ); // NameAndPath == { "name","path" }
const string & name = nameAndPath[0]; const string & name = nameAndPath[ 0 ];
const string & path = nameAndPath[1]; const string & path = nameAndPath[ 1 ];
cout << " " << index << " " << name << " : " << path << "\n"; cout << " " << index << " " << name << " : " << path << "\n";
++index; ++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" // we ask SuperElastix for a reader that matches the type of the source component "name"
AnyFileReader::Pointer reader = superElastixFilter->GetInputFileReader(name); AnyFileReader::Pointer reader = superElastixFilter->GetInputFileReader( name );
reader->SetFileName(path); reader->SetFileName( path );
superElastixFilter->SetInput(name, reader->GetOutput()); superElastixFilter->SetInput( name, reader->GetOutput() );
fileReaders.push_back(reader); fileReaders.push_back( reader );
} }
} }
if (vm.count("out")) { if( vm.count( "out" ) )
{
cout << "Number of output data: " << outputPairs.size() << "\n"; cout << "Number of output data: " << outputPairs.size() << "\n";
int index = 0; int index = 0;
for (const auto & outputPair : outputPairs) for( const auto & outputPair : outputPairs )
{ {
split_vector_type nameAndPath; split_vector_type nameAndPath;
boost::split(nameAndPath, outputPair, boost::is_any_of("=")); // NameAndPath == { "name","path" } boost::split( nameAndPath, outputPair, boost::is_any_of( "=" ) ); // NameAndPath == { "name","path" }
const string & name = nameAndPath[0]; const string & name = nameAndPath[ 0 ];
const string & path = nameAndPath[1]; const string & path = nameAndPath[ 1 ];
cout << " " << index << " " << name << " : " << path << "\n"; cout << " " << index << " " << name << " : " << path << "\n";
++index; ++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" // 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(); //ImageWriter2DType::Pointer writer = ImageWriter2DType::New();
writer->SetFileName(path); writer->SetFileName( path );
//writer->SetInput(superElastixFilter->GetOutput<Image2DType>(name)); //writer->SetInput(superElastixFilter->GetOutput<Image2DType>(name));
writer->SetInput(superElastixFilter->GetOutput(name)); writer->SetInput( superElastixFilter->GetOutput( name ) );
fileWriters.push_back(writer); fileWriters.push_back( writer );
} }
} }
/* Execute SuperElastix by updating the writers */ /* Execute SuperElastix by updating the writers */
for (auto & writer : fileWriters) for( auto & writer : fileWriters )
{ {
writer->Update(); writer->Update();
} }
} }
catch (exception& e) { catch( exception & e )
{
cerr << "error: " << e.what() << "\n"; cerr << "error: " << e.what() << "\n";
return 1; return 1;
} }
catch (...) { catch( ... )
{
cerr << "Exception of unknown type!\n"; cerr << "Exception of unknown type!\n";
} }
return 0; return 0;
} }
\ No newline at end of file
/*========================================================================= /*=========================================================================
* *
* Copyright Leiden University Medical Center, Erasmus University Medical * Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors * Center and contributors
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -27,48 +27,51 @@ ...@@ -27,48 +27,51 @@
namespace selx namespace selx
{ {
template<bool dummy = true> template< bool dummy = true >
class RegistrationControllerComponent : class RegistrationControllerComponent :
public SuperElastixComponent < public SuperElastixComponent<
Accepting< RunRegistrationInterface, ReconnectTransformInterface, AfterRegistrationInterface >, Accepting< RunRegistrationInterface, ReconnectTransformInterface, AfterRegistrationInterface >,
Providing < RegistrationControllerStartInterface > Providing< RegistrationControllerStartInterface >
> >
{ {
// RegistrationControllerComponent is a work-around for broken itk-pipelines. // RegistrationControllerComponent is a work-around for broken itk-pipelines.
// Both the elastix and itkv4 require to connect their transforms *after* execution of the registration. // Both the elastix and itkv4 require to connect their transforms *after* execution of the registration.
// This controller explicitly performs these steps // This controller explicitly performs these steps
// TODO: see if signals-and-slots paradigm is appropriate here. // TODO: see if signals-and-slots paradigm is appropriate here.
public:
public:
selxNewMacro(RegistrationControllerComponent, ComponentBase); selxNewMacro( RegistrationControllerComponent, ComponentBase );
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality); //itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
RegistrationControllerComponent(); RegistrationControllerComponent();
virtual ~RegistrationControllerComponent(); virtual ~RegistrationControllerComponent();
// Accepting Interfaces:
// Accepting Interfaces: virtual int Set( RunRegistrationInterface * ) override;
virtual int Set(RunRegistrationInterface*) override;
virtual int Set(ReconnectTransformInterface*) override; virtual int Set( ReconnectTransformInterface * ) override;
virtual int Set(AfterRegistrationInterface*) override;
virtual int Set( AfterRegistrationInterface * ) override;
// Providing Interfaces:
virtual void RegistrationControllerStart(void) override; // Providing Interfaces:
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;
private:
std::set<RunRegistrationInterface*> m_RunRegistrationInterfaces; static const char * GetDescription() { return "RegistrationController Component"; }
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 } //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION #ifndef ITK_MANUAL_INSTANTIATION
#include "selxRegistrationController.hxx" #include "selxRegistrationController.hxx"
#endif #endif
#endif // #define selxRegistrationController_h #endif // #define selxRegistrationController_h
\ No newline at end of file
/*========================================================================= /*=========================================================================
* *
* Copyright Leiden University Medical Center, Erasmus University Medical * Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors * Center and contributors
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -21,71 +21,81 @@ ...@@ -21,71 +21,81 @@
namespace selx namespace selx
{ {
template<bool dummy> template< bool dummy >
RegistrationControllerComponent< dummy>::RegistrationControllerComponent() RegistrationControllerComponent< dummy >::RegistrationControllerComponent()
{ {
} }
template<bool dummy>
RegistrationControllerComponent< dummy>::~RegistrationControllerComponent()
{
}
template<bool dummy> template< bool dummy >
int RegistrationControllerComponent< dummy>::Set(RunRegistrationInterface* other) RegistrationControllerComponent< dummy >::~RegistrationControllerComponent()
{ {
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> template< bool dummy >
int RegistrationControllerComponent< dummy>::Set(AfterRegistrationInterface* other) 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); runRegistrationInterface->RunRegistration();
return 0;
} }
for( auto && reconnectTransformInterface : this->m_ReconnectTransformInterfaces )
template<bool dummy>
void RegistrationControllerComponent< dummy>::RegistrationControllerStart()
{ {
for (auto && runRegistrationInterface : this->m_RunRegistrationInterfaces) reconnectTransformInterface->ReconnectTransform();
{
runRegistrationInterface->RunRegistration();
}
for (auto && reconnectTransformInterface : this->m_ReconnectTransformInterfaces)
{
reconnectTransformInterface->ReconnectTransform();
}
//for (auto && afterRegistrationInterface : this->m_AfterRegistrationInterfaces)
//{
// afterRegistrationInterface->AfterRegistration();
//}
} }
//for (auto && afterRegistrationInterface : this->m_AfterRegistrationInterfaces)
//{
// afterRegistrationInterface->AfterRegistration();
//}
}
template<bool dummy> template< bool dummy >
bool RegistrationControllerComponent< dummy>::MeetsCriterion(const ComponentBase::CriterionType &criterion) bool
RegistrationControllerComponent< dummy >::MeetsCriterion( const ComponentBase::CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
{ {
bool hasUndefinedCriteria(false); meetsCriteria = true;
bool meetsCriteria(false); for( auto const & criterionValue : criterion.second ) // auto&& preferred?
if (criterion.first == "ComponentProperty")
{ {
meetsCriteria = true; if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{ {
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples meetsCriteria = false;
{
meetsCriteria = false;
}
} }
} }
return meetsCriteria;
} }
return meetsCriteria;
}
} //end namespace selx } //end namespace selx
/*========================================================================= /*=========================================================================
* *
* Copyright Leiden University Medical Center, Erasmus University Medical * Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors * Center and contributors
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
......
/*========================================================================= /*=========================================================================
* *
* Copyright Leiden University Medical Center, Erasmus University Medical * Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors * Center and contributors
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -32,165 +32,179 @@ ...@@ -32,165 +32,179 @@
#include "selxMacro.h" #include "selxMacro.h"
namespace selx namespace selx
{ {
template <int Dimensionality, class TPixel> template< int Dimensionality, class TPixel >
class ElastixComponent : class ElastixComponent :
public SuperElastixComponent< public SuperElastixComponent<
Accepting< Accepting<
itkImageFixedInterface<Dimensionality, TPixel>, itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface<Dimensionality, TPixel> itkImageMovingInterface< Dimensionality, TPixel >
>, >,
Providing< Providing<
itkImageInterface<Dimensionality, TPixel>, itkImageInterface< Dimensionality, TPixel >,
RunRegistrationInterface RunRegistrationInterface
> >
> >
{ {
public: public:
selxNewMacro(ElastixComponent, ComponentBase);
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
ElastixComponent();
virtual ~ElastixComponent();