Commit 29a41ad7 authored by Kasper Marstal's avatar Kasper Marstal
Browse files

Merge branch 'develop' of https://github.com/kaspermarstal/SuperElastix into develop

parents aa1535da 903d919b
......@@ -122,7 +122,6 @@ main( int ac, char * av[] )
if( vm.count( "in" ) )
{
std::cout << "Number of input data: " << inputPairs.size() << "\n";
int index = 0;
for( const auto & inputPair : inputPairs )
{
......@@ -131,8 +130,7 @@ main( int ac, char * av[] )
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",
// we ask SuperElastix for a reader that matches the type of the source component "name"
......@@ -141,12 +139,14 @@ main( int ac, char * av[] )
reader->SetFileName( path );
superElastixFilter->SetInput( name, reader->GetOutput() );
fileReaders.push_back( reader );
std::cout << "Input data " << index << " " << name << " : " << path << "\n";
++index;
}
}
if( vm.count( "out" ) )
{
std::cout << "Number of output data: " << outputPairs.size() << "\n";
int index = 0;
for( const auto & outputPair : outputPairs )
{
......@@ -155,9 +155,6 @@ main( int ac, char * av[] )
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",
// we ask SuperElastix for a writer that matches the type of the sink component "name"
selx::AnyFileWriter::Pointer writer = superElastixFilter->GetOutputFileWriter( name );
......@@ -167,6 +164,10 @@ main( int ac, char * av[] )
//writer->SetInput(superElastixFilter->GetOutput<Image2DType>(name));
writer->SetInput( superElastixFilter->GetOutput( name ) );
fileWriters.push_back( writer );
std::cout << "Output data " << index << " " << name << " : " << path << "\n";
++index;
}
}
......
......@@ -69,6 +69,11 @@ private:
std::set< AfterRegistrationInterface * > m_AfterRegistrationInterfaces;
protected:
// return the class name and the template arguments to uniquely identify this component.
static inline const std::map< std::string, std::string > TemplateProperties()
{
return{ { keys::NameOfClass, "RegistrationControllerComponent" } };
}
};
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
......
......@@ -18,6 +18,7 @@
*=========================================================================*/
#include "selxRegistrationController.h"
#include "selxCheckTemplateProperties.h"
namespace selx
{
......@@ -83,19 +84,17 @@ 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);
auto status = CheckTemplateProperties(this->TemplateProperties(), criterion);
if (status == CriterionStatus::Satisfied)
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
return true;
}
else if (status == CriterionStatus::Failed)
{
return false;
} // else: CriterionStatus::Unknown
return meetsCriteria;
}
} //end namespace selx
......@@ -65,12 +65,23 @@ GDOptimizer3rdPartyComponent
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "GDOptimizer3rdPartyComponent" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
else if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
......
......@@ -57,12 +57,23 @@ GDOptimizer4thPartyComponent
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "GDOptimizer4rdPartyComponent" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
else if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
......
......@@ -41,12 +41,24 @@ MetricComponent1
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "MetricComponent1" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
}
}
}
else if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
......
......@@ -52,17 +52,29 @@ SSDMetric3rdPartyComponent
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "SSDMetric3rdPartyComponent" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
else if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
}
}
}
return meetsCriteria;
}
} //end namespace selx
......@@ -45,17 +45,29 @@ SSDMetric4thPartyComponent
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "SSDMetric4thPartyComponent" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
else if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
}
}
}
return meetsCriteria;
}
} //end namespace selx
......@@ -33,12 +33,24 @@ TransformComponent1::MeetsCriterion( const CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "TransformComponent1" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
}
}
}
if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
......
......@@ -66,113 +66,13 @@ private:
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()
// return the class name and the template arguments to uniquely identify this component.
static inline const std::map< std::string, std::string > TemplateProperties()
{
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
return{ { keys::NameOfClass, "ItkSmoothingRecursiveGaussianImageFilterComponent" }, { keys::PixelType, PodString< TPixel >::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
};
// unfortunately partial specialization of member functions is not allowed, without partially specializing the entire class.
/*
template <int Dimensionality>
class ItkSmoothingRecursiveGaussianImageFilterComponent < Dimensionality, double >
{
static inline const std::string GetPixelTypeNameString();
};
template <int Dimensionality>
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent<Dimensionality, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
*/
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 3, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 3, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 2, float >
::GetTypeNameString()
{
return std::string( "2_float" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 2, double >
::GetTypeNameString()
{
return std::string( "2_double" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 3, float >
::GetTypeNameString()
{
return std::string( "3_float" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 3, double >
::GetTypeNameString()
{
return std::string( "3_double" );
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkSmoothingRecursiveGaussianImageFilterComponent.hxx"
......
......@@ -18,6 +18,7 @@
*=========================================================================*/
#include "selxItkSmoothingRecursiveGaussianImageFilterComponent.h"
#include "selxCheckTemplateProperties.h"
namespace selx
{
......@@ -61,41 +62,18 @@ bool
ItkSmoothingRecursiveGaussianImageFilterComponent< Dimensionality, TPixel >
::MeetsCriterion( const ComponentBase::CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
bool hasUndefinedCriteria(false);
bool meetsCriteria(false);
auto status = CheckTemplateProperties(this->TemplateProperties(), criterion);
if (status == CriterionStatus::Satisfied)
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
return true;
}
else if( criterion.first == "Dimensionality" ) //Supports this?
else if (status == CriterionStatus::Failed)
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( std::stoi( criterionValue ) != Dimensionality )
{
meetsCriteria = false;
}
}
}
else if( criterion.first == "PixelType" ) //Supports this?
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != Self::GetPixelTypeNameString() )
{
meetsCriteria = false;
}
}
}
return false;
} // else: CriterionStatus::Unknown
else if( criterion.first == "Sigma" ) //Supports this?
{
if( criterion.second.size() != 1 )
......
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef selxItkCompositeTransformComponent_h
#define selxItkCompositeTransformComponent_h
#include "selxComponentBase.h"
#include "selxInterfaces.h"
#include "itkCompositeTransform.h"
#include <string.h>
#include "selxMacro.h"
namespace selx
{
template< class InternalComputationValueType, int Dimensionality >
class ItkCompositeTransformComponent :
public SuperElastixComponent<
Accepting<MultiStageTransformInterface< InternalComputationValueType, Dimensionality >, ReconnectTransformInterface >,
Providing<itkTransformInterface<InternalComputationValueType, Dimensionality>,
RegistrationControllerStartInterface>
>
{
public:
selxNewMacro(ItkCompositeTransformComponent, ComponentBase);
//itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
ItkCompositeTransformComponent();
virtual ~ItkCompositeTransformComponent();
/** Type of the optimizer. */
using TransformType = typename MultiStageTransformInterface< InternalComputationValueType, Dimensionality >::TransformBaseType;
typedef typename itk::CompositeTransform< InternalComputationValueType, Dimensionality > CompositeTransformType;
virtual int Set(MultiStageTransformInterface< InternalComputationValueType, Dimensionality > *) override;
virtual int Set(ReconnectTransformInterface * ) override;
virtual void RegistrationControllerStart() override;
virtual typename TransformType::Pointer GetItkTransform() override;
virtual bool MeetsCriterion( const ComponentBase::CriterionType & criterion ) override;
//static const char * GetName() { return "ItkCompositeTransform"; } ;
static const char * GetDescription() { return "ItkCompositeTransform Component"; }
private:
typename CompositeTransformType::Pointer m_CompositeTransform;
typename std::vector<MultiStageTransformInterface< InternalComputationValueType, Dimensionality >*> m_registrationStages;
std::set< ReconnectTransformInterface * > m_ReconnectTransformInterfaces;
std::vector<std::string> m_ExecutionOrder;
protected:
// return the class name and the template arguments to uniquely identify this component.
static inline const std::map< std::string, std::string > TemplateProperties()
{
return { { keys::NameOfClass, "ItkCompositeTransformComponent" }, { keys::InternalComputationValueType, PodString< InternalComputationValueType >::Get() }, { keys::Dimensionality, std::to_string( Dimensionality ) } };
}
};
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkCompositeTransformComponent.hxx"
#endif
#endif // #define selxItkCompositeTransformComponent_h
/*=========================================================================
*
* Copyright Leiden University Medical Center, Erasmus University Medical
* Center and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "selxItkCompositeTransformComponent.h"
#include "selxCheckTemplateProperties.h"
namespace selx
{
template< class InternalComputationValueType, int Dimensionality >
ItkCompositeTransformComponent< InternalComputationValueType, Dimensionality >::ItkCompositeTransformComponent()
{
m_CompositeTransform = CompositeTransformType::New();
//TODO: instantiating the filter in the constructor might be heavy for the use in component selector factory, since all components of the database are created during the selection process.