Commit f7aa64c8 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

STYLE: Uncrustify new files

parent 0dca0c4c
/*=========================================================================
*
* 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");
......@@ -39,138 +39,142 @@ namespace po = boost::program_options;
#include <string>
#include <stdexcept>
template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
template< class T >
std::ostream &
operator<<( std::ostream & os, const std::vector< T > & v )
{
std::copy(v.begin(), v.end(), std::ostream_iterator<T>(os, " "));
std::copy( v.begin(), v.end(), std::ostream_iterator< T >( os, " " ) );
return os;
}
int main(int ac, char* av[])
{
try {
int
main( int ac, char * av[] )
{
try
{
typedef std::vector< std::string > VectorOfStringsType;
selx::SuperElastixFilter<selx::DefaultComponents>::Pointer superElastixFilter = selx::SuperElastixFilter<selx::DefaultComponents>::New();
selx::SuperElastixFilter< selx::DefaultComponents >::Pointer superElastixFilter = selx::SuperElastixFilter< selx::DefaultComponents >::New();
fs::path configurationPath;
fs::path configurationPath;
VectorOfStringsType inputPairs;
VectorOfStringsType outputPairs;
// Store the reader so that they will not be destroyed before the pipeline is executed.
std::vector<selx::AnyFileReader::Pointer> fileReaders;
std::vector< selx::AnyFileReader::Pointer > fileReaders;
// Store the writers for the update call
//vector<ImageWriter2DType::Pointer> fileWriters;
std::vector<selx::AnyFileWriter::Pointer> fileWriters;
std::vector< selx::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<VectorOfStringsType>(&inputPairs)->multitoken(), "Input data: images, labels, meshes, etc. Usage <name>=<path>")
("out", po::value<VectorOfStringsType>(&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< VectorOfStringsType >( &inputPairs )->multitoken(), "Input data: images, labels, meshes, etc. Usage <name>=<path>" )
( "out", po::value< VectorOfStringsType >( &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" ) )
{
std::cout << desc << "\n";
return 0;
}
selx::Blueprint::Pointer blueprint;
if (configurationPath.extension() == ".xml")
if( configurationPath.extension() == ".xml" )
{
// TODO: open file here and pass a stream to the ConfigurationReader
blueprint = selx::ConfigurationReader::FromXML(configurationPath.string());
blueprint = selx::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 = selx::ConfigurationReader::FromJson(configurationPath.string());
blueprint = selx::ConfigurationReader::FromJson( configurationPath.string() );
}
else {
throw std::invalid_argument("Configuration file requires extension .xml or .json");
else
{
throw std::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" ) )
{
std::cout << "Number of input data: " << inputPairs.size() << "\n";
int index = 0;
for (const auto & inputPair : inputPairs)
for( const auto & inputPair : inputPairs )
{
VectorOfStringsType nameAndPath;
boost::split(nameAndPath, inputPair, boost::is_any_of("=")); // NameAndPath == { "name","path" }
const std::string & name = nameAndPath[0];
const std::string & path = nameAndPath[1];
boost::split( nameAndPath, inputPair, boost::is_any_of( "=" ) ); // NameAndPath == { "name","path" }
const std::string & name = nameAndPath[ 0 ];
const std::string & path = nameAndPath[ 1 ];
std::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"
selx::AnyFileReader::Pointer reader = superElastixFilter->GetInputFileReader(name);
reader->SetFileName(path);
superElastixFilter->SetInput(name, reader->GetOutput());
fileReaders.push_back(reader);
selx::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" ) )
{
std::cout << "Number of output data: " << outputPairs.size() << "\n";
int index = 0;
for (const auto & outputPair : outputPairs)
for( const auto & outputPair : outputPairs )
{
VectorOfStringsType nameAndPath;
boost::split(nameAndPath, outputPair, boost::is_any_of("=")); // NameAndPath == { "name","path" }
const std::string & name = nameAndPath[0];
const std::string & path = nameAndPath[1];
boost::split( nameAndPath, outputPair, boost::is_any_of( "=" ) ); // NameAndPath == { "name","path" }
const std::string & name = nameAndPath[ 0 ];
const std::string & path = nameAndPath[ 1 ];
std::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"
selx::AnyFileWriter::Pointer writer = superElastixFilter->GetOutputFileWriter(name);
selx::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 (std::exception& e) {
catch( std::exception & e )
{
std::cerr << "error: " << e.what() << "\n";
return 1;
}
catch (...) {
catch( ... )
{
std::cerr << "Exception of unknown type!\n";
}
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
*
* Licensed under the Apache License, Version 2.0 (the "License");
......@@ -29,149 +29,162 @@
#include <string.h>
#include "selxMacro.h"
#include "itkComposeDisplacementFieldsImageFilter.h"
#include "itkGaussianExponentialDiffeomorphicTransform.h"
#include "itkGaussianExponentialDiffeomorphicTransformParametersAdaptor.h"
namespace selx
{
template <int Dimensionality, class TPixel>
class ItkSyNImageRegistrationMethodComponent :
public SuperElastixComponent<
Accepting< itkImageFixedInterface<Dimensionality, TPixel>,
itkImageMovingInterface<Dimensionality, TPixel>,
itkMetricv4Interface<Dimensionality, TPixel>
>,
Providing< itkTransformInterface<double, Dimensionality>,
RunRegistrationInterface
>
>
{
public:
selxNewMacro(ItkSyNImageRegistrationMethodComponent, ComponentBase);
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
ItkSyNImageRegistrationMethodComponent();
virtual ~ItkSyNImageRegistrationMethodComponent();
typedef TPixel PixelType;
// Get the type definitions from the interfaces
typedef typename itkImageFixedInterface<Dimensionality, TPixel>::ItkImageType FixedImageType;
typedef typename itkImageMovingInterface<Dimensionality, TPixel>::ItkImageType MovingImageType;
typedef typename itkTransformInterface<double, Dimensionality>::TransformType TransformType;
typedef typename itkTransformInterface<double, Dimensionality>::TransformPointer TransformPointer;
typedef typename itkTransformInterface<double, Dimensionality>::InternalComputationValueType TransformInternalComputationValueType; //should be from class template
typedef itk::SyNImageRegistrationMethod<FixedImageType, MovingImageType> TheItkFilterType;
typedef typename TheItkFilterType::ImageMetricType ImageMetricType;
typedef itk::RegistrationParameterScalesFromPhysicalShift<ImageMetricType> ScalesEstimatorType;
//Accepting Interfaces:
virtual int Set(itkImageFixedInterface<Dimensionality, TPixel>*) override;
virtual int Set(itkImageMovingInterface<Dimensionality, TPixel>*) override;
virtual int Set(itkMetricv4Interface<Dimensionality, TPixel>*) override;
//Providing Interfaces:
virtual TransformPointer GetItkTransform() override;
virtual void RunRegistration() override;
//BaseClass methods
virtual bool MeetsCriterion(const ComponentBase::CriterionType &criterion) override;
//static const char * GetName() { return "ItkSyNImageRegistrationMethod"; } ;
static const char * GetDescription() { return "ItkSyNImageRegistrationMethod Component"; };
private:
typename TheItkFilterType::Pointer m_theItkFilter;
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
}
};
template <>
inline const std::string
ItkSyNImageRegistrationMethodComponent<2, float>
::GetPixelTypeNameString()
{
return std::string("float");
}
template< int Dimensionality, class TPixel >
class ItkSyNImageRegistrationMethodComponent :
public SuperElastixComponent<
Accepting< itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >,
itkMetricv4Interface< Dimensionality, TPixel >
>,
Providing< itkTransformInterface< double, Dimensionality >,
RunRegistrationInterface
>
>
{
public:
selxNewMacro( ItkSyNImageRegistrationMethodComponent, ComponentBase );
template <>
inline const std::string
ItkSyNImageRegistrationMethodComponent<2, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
template <>
inline const std::string
ItkSyNImageRegistrationMethodComponent<3, float>
::GetPixelTypeNameString()
{
return std::string("float");
}
ItkSyNImageRegistrationMethodComponent();
virtual ~ItkSyNImageRegistrationMethodComponent();
template <>
inline const std::string
ItkSyNImageRegistrationMethodComponent<3, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
template <>
inline const std::string
ItkSyNImageRegistrationMethodComponent<2, float>
::GetTypeNameString()
{
return std::string("2_float");
}
typedef TPixel PixelType;
template <>
inline const std::string
ItkSyNImageRegistrationMethodComponent<2, double>
::GetTypeNameString()
{
return std::string("2_double");
}
// Get the type definitions from the interfaces
typedef typename itkImageFixedInterface< Dimensionality, TPixel >::ItkImageType FixedImageType;
typedef typename itkImageMovingInterface< Dimensionality, TPixel >::ItkImageType MovingImageType;
typedef typename itkTransformInterface< double, Dimensionality >::TransformType TransformType;
typedef typename itkTransformInterface< double, Dimensionality >::TransformPointer TransformPointer;
typedef typename itkTransformInterface< double, Dimensionality >::InternalComputationValueType TransformInternalComputationValueType; //should be from class template
typedef itk::SyNImageRegistrationMethod< FixedImageType, MovingImageType > TheItkFilterType;
typedef typename TheItkFilterType::ImageMetricType ImageMetricType;
typedef itk::RegistrationParameterScalesFromPhysicalShift< ImageMetricType > ScalesEstimatorType;
//Accepting Interfaces:
virtual int Set( itkImageFixedInterface< Dimensionality, TPixel > * ) override;
virtual int Set( itkImageMovingInterface< Dimensionality, TPixel > * ) override;
virtual int Set( itkMetricv4Interface< Dimensionality, TPixel > * ) override;
//Providing Interfaces:
virtual TransformPointer GetItkTransform() override;
virtual void RunRegistration() override;
//BaseClass methods
virtual bool MeetsCriterion( const ComponentBase::CriterionType & criterion ) override;
//static const char * GetName() { return "ItkSyNImageRegistrationMethod"; } ;
static const char * GetDescription() { return "ItkSyNImageRegistrationMethod Component"; }
private:
typename TheItkFilterType::Pointer m_theItkFilter;
template <>
inline const std::string
ItkSyNImageRegistrationMethodComponent<3,float>
::GetTypeNameString()
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
static inline const std::string GetTypeNameString()
{
return std::string("3_float");
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
}
template <>
inline const std::string
ItkSyNImageRegistrationMethodComponent<3,double>
::GetTypeNameString()
static inline const std::string GetPixelTypeNameString()
{
return std::string("3_double");
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
}
};
template< >
inline const std::string
ItkSyNImageRegistrationMethodComponent< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkSyNImageRegistrationMethodComponent< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkSyNImageRegistrationMethodComponent< 3, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkSyNImageRegistrationMethodComponent< 3, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkSyNImageRegistrationMethodComponent< 2, float >
::GetTypeNameString()
{
return std::string( "2_float" );
}
template< >
inline const std::string
ItkSyNImageRegistrationMethodComponent< 2, double >
::GetTypeNameString()
{
return std::string( "2_double" );
}
template< >
inline const std::string
ItkSyNImageRegistrationMethodComponent< 3, float >
::GetTypeNameString()
{
return std::string( "3_float" );
}
template< >
inline const std::string
ItkSyNImageRegistrationMethodComponent< 3, double >
::GetTypeNameString()
{
return std::string( "3_double" );
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkSyNImageRegistrationMethodComponent.hxx"
#endif
#endif // #define selxItkSyNImageRegistrationMethodComponent_h
\ No newline at end of file
#endif // #define selxItkSyNImageRegistrationMethodComponent_h
/*=========================================================================
*
* 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");
......@@ -20,17 +20,14 @@
#include "selxItkSyNImageRegistrationMethodComponent.h"
#include "selxItkImageRegistrationMethodv4Component.h"
#include "itkDisplacementFieldTransformParametersAdaptor.h"
//TODO: get rid of these
#include "itkGradientDescentOptimizerv4.h"
namespace selx
{
template<int Dimensionality, class TPixel>
ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel>::ItkSyNImageRegistrationMethodComponent()
template< int Dimensionality, class TPixel >
ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel >::ItkSyNImageRegistrationMethodComponent()
{
m_theItkFilter = TheItkFilterType::New();
m_theItkFilter->InPlaceOn();
......@@ -39,157 +36,157 @@ namespace selx
// we could choose to keep the component light weighted (for checking criteria such as names and connections) until the settings are passed to the filter, but this requires an additional initialization step.
}
template<int Dimensionality, class TPixel>
ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel>::~ItkSyNImageRegistrationMethodComponent()
template< int Dimensionality, class TPixel >
ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel >::~ItkSyNImageRegistrationMethodComponent()
{
}
template<int Dimensionality, class TPixel>
int ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel>
::Set(itkImageFixedInterface<Dimensionality, TPixel>* component)
template< int Dimensionality, class TPixel >
int
ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel >
::Set( itkImageFixedInterface< Dimensionality, TPixel > * component )
{
auto fixedImage = component->GetItkImageFixed();
// connect the itk pipeline
this->m_theItkFilter->SetFixedImage(fixedImage);
this->m_theItkFilter->SetFixedImage( fixedImage );
return 0;
}
template<int Dimensionality, class TPixel>
int ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel>
::Set(itkImageMovingInterface<Dimensionality, TPixel>* component)
template< int Dimensionality, class TPixel >
int
ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel >
::Set( itkImageMovingInterface< Dimensionality, TPixel > * component )
{
auto movingImage = component->GetItkImageMoving();