Commit 3f51456f authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: all Components have access to the Logger

parent 934ff167
......@@ -38,10 +38,12 @@ public:
return InterfaceStatus::noaccepter;
}
//Empty RestInterfaces does 0 successful connects ;
int ConnectFromImpl( ComponentBase::Pointer ) { return 0; }
int ConnectFromImpl( ComponentBase::Pointer ) { return 0; }
bool AreAllAccepted() { return true; }
protected:
};
......@@ -60,6 +62,7 @@ public:
// Helper function by which a component can check if all its Accepting interfaces have been set after the handshakes
bool AreAllAccepted();
protected:
};
} //end namespace selx
......
......@@ -109,24 +109,24 @@ Accepting< FirstInterface, RestInterfaces ... >::CountMeetsCriteria( const Compo
return Count< FirstInterface, RestInterfaces ... >::MeetsCriteria( interfaceCriteria );
}
template< typename FirstInterface, typename ... RestInterfaces >
bool
Accepting< FirstInterface, RestInterfaces ... >::AreAllAccepted()
{
InterfaceAcceptor< FirstInterface > * acceptIF = (this);
if (acceptIF->isSet() == false)
InterfaceAcceptor< FirstInterface > * acceptIF = ( this );
if( acceptIF->isSet() == false )
{
auto const & properties = Properties<FirstInterface>::Get();
for (auto const & keyvalue : properties)
auto const & properties = Properties< FirstInterface >::Get();
for( auto const & keyvalue : properties )
{
std::cout << "{ """ << keyvalue.first << """: """ << keyvalue.second << """}" << std::endl;
std::cout << "{ " "" << keyvalue.first << "" ": " "" << keyvalue.second << "" "}" << std::endl;
}
//std::cout << std::endl;
return false;
}
return Accepting<RestInterfaces ...>::AreAllAccepted();
}
return Accepting< RestInterfaces ... >::AreAllAccepted();
}
} //end namespace selx
#endif // Accepting_hxx
......@@ -39,7 +39,7 @@ public:
//ComponentBase() = delete;
ComponentBase();
ComponentBase( const std::string & name );
ComponentBase( const std::string & name, const LoggerInterface & logger );
virtual ~ComponentBase() {}
typedef std::shared_ptr< ComponentBase > Pointer;
......@@ -69,9 +69,10 @@ public:
// Each component is checked if its required connections are made after all handshakes.
// SuperElastixComponent provides a default implementation which may be overridden by the component developer
virtual bool ConnectionsSatisfied() = 0 ;
const std::string m_Name;
LoggerInterface* m_Logger;
virtual bool ConnectionsSatisfied() = 0;
const std::string m_Name;
const LoggerInterface & m_Logger;
};
} // end namespace selx
......
......@@ -50,7 +50,7 @@ public:
typedef ComponentListType::size_type NumberOfComponentsType;
/** set selection criteria for possibleComponents*/
ComponentSelector( const std::string & name);
ComponentSelector( const std::string & name, const LoggerInterface & logger );
/** Narrow selection criteria*/
void AddCriterion( const CriterionType & criterion );
......
......@@ -26,7 +26,9 @@ namespace selx
template< >
struct ContructComponentsFromTypeList< TypeList< >>
{
static std::list< ComponentBase::Pointer > fill(std::list< ComponentBase::Pointer > & components, const std::string & name )
static std::list< ComponentBase::Pointer > fill( std::list< ComponentBase::Pointer > & components,
const std::string & name,
const LoggerInterface & logger )
{
return components;
}
......@@ -35,18 +37,20 @@ struct ContructComponentsFromTypeList< TypeList< >>
template< typename ComponentType, typename ... Rest >
struct ContructComponentsFromTypeList< TypeList< ComponentType, Rest ... >>
{
static std::list< ComponentBase::Pointer > fill( std::list< ComponentBase::Pointer > & components, const std::string & name )
static std::list< ComponentBase::Pointer > fill( std::list< ComponentBase::Pointer > & components,
const std::string & name,
const LoggerInterface & logger )
{
components.push_back( std::make_shared< ComponentType >( name) );
return ContructComponentsFromTypeList< TypeList< Rest ... >>::fill(components, name);
components.push_back( std::make_shared< ComponentType >( name, logger ) );
return ContructComponentsFromTypeList< TypeList< Rest ... >>::fill( components, name, logger );
}
};
template< class ComponentList >
ComponentSelector< ComponentList >::ComponentSelector(const std::string & name)
ComponentSelector< ComponentList >::ComponentSelector( const std::string & name, const LoggerInterface & logger )
{
m_PossibleComponents = std::list< ComponentBase::Pointer >();
m_PossibleComponents = ContructComponentsFromTypeList< ComponentList >::fill(m_PossibleComponents, name);
m_PossibleComponents = ContructComponentsFromTypeList< ComponentList >::fill( m_PossibleComponents, name, logger );
}
......
......@@ -46,8 +46,11 @@ public:
bool isSet()
{
return m_isSet;
};
}
private:
bool m_isSet = false;
};
} //end namespace selx
......
......@@ -119,7 +119,8 @@ protected:
// A selector for each node, that each can hold multiple instantiated components. Ultimately is should be 1 component each.
ComponentSelectorContainerType m_ComponentSelectorContainer;
bool m_isConfigured;
Logger m_Logger;
Logger m_Logger;
private:
};
} // end namespace selx
......
......@@ -159,7 +159,7 @@ NetworkBuilder< ComponentList >::ApplyComponentConfiguration()
for( auto const & name : componentNames )
{
std::cout << " Blueprint Node: " << name << std::endl;
ComponentSelectorPointer currentComponentSelector = std::make_shared< ComponentSelectorType >( name , this->m_Logger );
ComponentSelectorPointer currentComponentSelector = std::make_shared< ComponentSelectorType >( name, this->m_Logger );
Blueprint::ParameterMapType currentProperty = this->m_Blueprint->GetComponent( name );
for( auto const & criterion : currentProperty )
......@@ -386,6 +386,7 @@ NetworkBuilder< ComponentList >::ConnectComponents()
return isAllSuccess;
}
template< typename ComponentList >
bool
NetworkBuilder< ComponentList >::CheckConnectionsSatisfied()
......@@ -393,11 +394,11 @@ NetworkBuilder< ComponentList >::CheckConnectionsSatisfied()
bool isAllSatisfied = true;
Blueprint::ComponentNamesType componentNames = this->m_Blueprint->GetComponentNames();
for (auto const & name : componentNames)
for( auto const & name : componentNames )
{
ComponentBase::Pointer component = this->m_ComponentSelectorContainer[name]->GetComponent();
bool isSatisfied = component->ConnectionsSatisfied();
if (isSatisfied == false)
ComponentBase::Pointer component = this->m_ComponentSelectorContainer[ name ]->GetComponent();
bool isSatisfied = component->ConnectionsSatisfied();
if( isSatisfied == false )
{
isAllSatisfied = false;
std::cout << "Component " << name << " has unsatisfied connections" << std::endl;
......@@ -406,6 +407,7 @@ NetworkBuilder< ComponentList >::CheckConnectionsSatisfied()
return isAllSatisfied;
}
template< typename ComponentList >
NetworkBuilderBase::SourceInterfaceMapType
NetworkBuilder< ComponentList >::GetSourceInterfaces()
......
......@@ -40,7 +40,8 @@ public:
using AcceptingInterfacesTypeList = AcceptingInterfaces;
using ProvidingInterfacesTypeList = ProvidingInterfaces;
SuperElastixComponent( const std::string & name ) : ComponentBase( name ) {}
SuperElastixComponent( const std::string & name, const LoggerInterface & logger ) : ComponentBase( name, logger ) {}
virtual int AcceptConnectionFrom( ComponentBase::Pointer other, const InterfaceCriteriaType interfaceCriteria );
virtual int AcceptConnectionFrom( ComponentBase::Pointer );
......
......@@ -48,6 +48,7 @@ SuperElastixComponent< AcceptingInterfaces, ProvidingInterfaces >
return AcceptingInterfaces::CanAcceptConnectionFrom( other, interfaceCriteria );
}
template< typename AcceptingInterfaces, typename ProvidingInterfaces >
bool
SuperElastixComponent< AcceptingInterfaces, ProvidingInterfaces >
......@@ -56,7 +57,6 @@ SuperElastixComponent< AcceptingInterfaces, ProvidingInterfaces >
// Default implementation. Components that allow unused connections should override this function.
return AcceptingInterfaces::AreAllAccepted();
}
} // end namespace selx
#endif // #define selxSuperElastixComponent_hxx
......@@ -22,16 +22,16 @@
namespace selx
{
// TODO delete this constructor
ComponentBase::ComponentBase() : m_Name( "undefined" )
ComponentBase::ComponentBase() : m_Name( "undefined" ), m_Logger( *( new Logger() ) )
{
}
ComponentBase::ComponentBase( const std::string & name ) : m_Name( name )
ComponentBase::ComponentBase( const std::string & name, const LoggerInterface & logger ) : m_Logger( logger )
{
}
//const std::map< std::string, std::string > ComponentBase::TemplateProperties()
// { return{}; }
} // end namespace selx
......@@ -32,11 +32,12 @@ public:
virtual void SetUp()
{
metric3p = std::make_shared< SSDMetric3rdPartyComponent >( "nameless" );
optimizer3p = std::make_shared< GDOptimizer3rdPartyComponent >( "nameless" );
Logger * logger = new Logger();
metric3p = std::make_shared< SSDMetric3rdPartyComponent >( "nameless", *logger );
optimizer3p = std::make_shared< GDOptimizer3rdPartyComponent >( "nameless", *logger );
metric4p = std::make_shared< SSDMetric4thPartyComponent >( "nameless" );
optimizer4p = std::make_shared< GDOptimizer4thPartyComponent >( "nameless" );
metric4p = std::make_shared< SSDMetric4thPartyComponent >( "nameless", *logger );
optimizer4p = std::make_shared< GDOptimizer4thPartyComponent >( "nameless", *logger );
}
......
......@@ -64,7 +64,7 @@ public:
TEST_F( ComponentSelectorTest, EmptyComponentList )
{
auto componentSelector = std::make_shared< ComponentSelector< EmptyComponentList >>( "nameless" );
auto componentSelector = std::make_shared< ComponentSelector< EmptyComponentList >>( "nameless", *( new Logger() ) );
// " 0 Component objects available to the NetworkBuilder."
EXPECT_EQ( componentSelector->NumberOfComponents(), 0 );
......@@ -73,7 +73,7 @@ TEST_F( ComponentSelectorTest, EmptyComponentList )
TEST_F( ComponentSelectorTest, FilledComponentList )
{
// In this test we manually register 2 dummy modules: itkTransformComponent1 and itkMetricComponent1.
auto componentSelector = std::make_shared< ComponentSelector< TypeList< TransformComponent1, MetricComponent1 >>>( "nameless" );
auto componentSelector = std::make_shared< ComponentSelector< TypeList< TransformComponent1, MetricComponent1 >>>( "nameless", *( new Logger() ) );
// After registering the TransformComponent1 and MetricComponent1object, there are
// " 2 Component objects available to the NetworkBuilder."
......@@ -82,7 +82,7 @@ TEST_F( ComponentSelectorTest, FilledComponentList )
TEST_F( ComponentSelectorTest, SetEmptyCriteria )
{
auto componentSelector = std::make_shared< ComponentSelector< SmallComponentList >>( "nameless" );
auto componentSelector = std::make_shared< ComponentSelector< SmallComponentList >>( "nameless", *( new Logger() ) );
CriterionType emptyCriterion; // = CriterionType();
......@@ -96,7 +96,7 @@ TEST_F( ComponentSelectorTest, SetEmptyCriteria )
TEST_F( ComponentSelectorTest, SetSufficientCriteria )
{
auto componentSelector = std::make_shared< ComponentSelector< SmallComponentList >>( "nameless" );
auto componentSelector = std::make_shared< ComponentSelector< SmallComponentList >>( "nameless", *( new Logger() ) );
CriterionType criterion = { "ComponentInput", { "Transform" } };
......@@ -109,7 +109,7 @@ TEST_F( ComponentSelectorTest, SetSufficientCriteria )
}
TEST_F( ComponentSelectorTest, AddCriteria )
{
auto componentSelector = std::make_shared< ComponentSelector< SmallComponentList >>( "nameless" );
auto componentSelector = std::make_shared< ComponentSelector< SmallComponentList >>( "nameless", *( new Logger() ) );
CriterionType nonSelectiveCriterion( { "ComponentProperty", { "SomeProperty" } } );
......@@ -135,7 +135,7 @@ TEST_F( ComponentSelectorTest, AddCriteria )
TEST_F( ComponentSelectorTest, InterfacedObjects )
{
auto componentSelectorA = std::make_shared< ComponentSelector< BigComponentList >>( "nameless" );
auto componentSelectorA = std::make_shared< ComponentSelector< BigComponentList >>( "nameless", *( new Logger() ) );
// " 6 Component objects available to the NetworkBuilder."
EXPECT_EQ( componentSelectorA->NumberOfComponents(), 6 );
......@@ -145,7 +145,7 @@ TEST_F( ComponentSelectorTest, InterfacedObjects )
EXPECT_NO_THROW( componentA = componentSelectorA->GetComponent() );
EXPECT_TRUE( componentA->MeetsCriterion( { "NameOfClass", { "GDOptimizer3rdPartyComponent" } } ) );
auto componentSelectorB = std::make_shared< ComponentSelector< BigComponentList >>( "nameless" );
auto componentSelectorB = std::make_shared< ComponentSelector< BigComponentList >>( "nameless", *( new Logger() ) );
componentSelectorB->AddProvidingInterfaceCriteria( { { "NameOfInterface", "MetricDerivativeInterface" } } );
ComponentType::Pointer componentB;
EXPECT_NO_THROW( componentB = componentSelectorB->GetComponent() );
......@@ -155,7 +155,7 @@ TEST_F( ComponentSelectorTest, InterfacedObjects )
TEST_F( ComponentSelectorTest, UnknownComponent )
{
// Fill our component database with some components
auto componentSelector = std::make_shared< ComponentSelector< BigComponentList >>( "nameless" );
auto componentSelector = std::make_shared< ComponentSelector< BigComponentList >>( "nameless", *( new Logger() ) );
// Setup the criterion for a component that does not exist in our data base
CriterionType criterion( { "NameOfClass", { "DoYouHaveThisComponent?" } } );
......
......@@ -172,8 +172,8 @@ TEST_F( NetworkBuilderTest, DeduceComponentsFromConnections )
blueprint->SetComponent( "TransformResolutionAdaptor",
{ { "NameOfClass", { "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent" } },
{ "Dimensionality", { "3" } },
{ "ShrinkFactorsPerLevel", { "2", "1" } } } );
{ "Dimensionality", { "3" } },
{ "ShrinkFactorsPerLevel", { "2", "1" } } } );
blueprint->SetComponent( "Controller", { { "NameOfClass", { "RegistrationControllerComponent" } } } );
......
......@@ -44,11 +44,14 @@ public:
/** Standard ITK typedefs. */
typedef RegistrationControllerComponent Self;
typedef ComponentBase Superclass;
typedef std::shared_ptr< Self > Pointer;
typedef std::shared_ptr< const Self > ConstPointer;
RegistrationControllerComponent( const std::string & name );
typedef SuperElastixComponent<
Accepting< RunRegistrationInterface, ReconnectTransformInterface, AfterRegistrationInterface >,
Providing< RegistrationControllerStartInterface >
> Superclass;
typedef std::shared_ptr< Self > Pointer;
typedef std::shared_ptr< const Self > ConstPointer;
RegistrationControllerComponent( const std::string & name, const LoggerInterface & logger );
virtual ~RegistrationControllerComponent();
// Accepting Interfaces:
......
......@@ -23,7 +23,9 @@
namespace selx
{
template< bool dummy >
RegistrationControllerComponent< dummy >::RegistrationControllerComponent( const std::string & name ) : SuperElastixComponent( name )
RegistrationControllerComponent< dummy >::RegistrationControllerComponent( const std::string & name, const LoggerInterface & logger ) : Superclass(
name,
logger )
{
}
......
......@@ -36,36 +36,36 @@ namespace selx
template< int Dimensionality, class TPixel >
class ElastixComponent :
public SuperElastixComponent<
Accepting<
itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >
>,
Providing<
itkImageInterface< Dimensionality, TPixel >,
RunRegistrationInterface
>
Accepting<
itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >
>,
Providing<
itkImageInterface< Dimensionality, TPixel >,
RunRegistrationInterface
>
>
{
public:
/** Standard ITK typedefs. */
typedef ElastixComponent<
Dimensionality, TPixel
> Self;
typedef ElastixComponent<
Dimensionality, TPixel
> Self;
typedef SuperElastixComponent<
Accepting<
itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >
itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >
>,
Providing<
itkImageInterface< Dimensionality, TPixel >,
RunRegistrationInterface
itkImageInterface< Dimensionality, TPixel >,
RunRegistrationInterface
>
> Superclass;
> Superclass;
typedef std::shared_ptr< Self > Pointer;
typedef std::shared_ptr< const Self > ConstPointer;
ElastixComponent( const std::string & name );
ElastixComponent( const std::string & name, const LoggerInterface & logger );
virtual ~ElastixComponent();
typedef typename ComponentBase::CriterionType CriterionType;
......
......@@ -23,7 +23,7 @@
namespace selx
{
template< int Dimensionality, class TPixel >
ElastixComponent< Dimensionality, TPixel >::ElastixComponent( const std::string & name ) : Superclass( name )
ElastixComponent< Dimensionality, TPixel >::ElastixComponent( const std::string & name, const LoggerInterface & logger ) : Superclass( name, logger )
{
m_elastixFilter = ElastixFilterType::New();
m_transformixFilter = TransformixFilterType::New();
......
......@@ -36,15 +36,15 @@ namespace selx
template< int Dimensionality, class TPixel >
class MonolithicElastixComponent :
public SuperElastixComponent<
Accepting<
itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >
>,
Providing<
elastixTransformParameterObjectInterface< itk::Image< TPixel, Dimensionality >, itk::Image< TPixel, Dimensionality >>,
itkImageInterface< Dimensionality, TPixel >,
RunRegistrationInterface
>
Accepting<
itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >
>,
Providing<
elastixTransformParameterObjectInterface< itk::Image< TPixel, Dimensionality >, itk::Image< TPixel, Dimensionality >>,
itkImageInterface< Dimensionality, TPixel >,
RunRegistrationInterface
>
>
{
public:
......@@ -52,22 +52,22 @@ public:
/** Standard ITK typedefs. */
typedef MonolithicElastixComponent<
Dimensionality, TPixel
> Self;
> Self;
typedef SuperElastixComponent<
Accepting<
itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >
itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >
>,
Providing<
elastixTransformParameterObjectInterface< itk::Image< TPixel, Dimensionality >, itk::Image< TPixel, Dimensionality >>,
itkImageInterface< Dimensionality, TPixel >,
RunRegistrationInterface
elastixTransformParameterObjectInterface< itk::Image< TPixel, Dimensionality >, itk::Image< TPixel, Dimensionality >>,
itkImageInterface< Dimensionality, TPixel >,
RunRegistrationInterface
>
> Superclass;
> Superclass;
typedef std::shared_ptr< Self > Pointer;
typedef std::shared_ptr< const Self > ConstPointer;
MonolithicElastixComponent( const std::string & name );
MonolithicElastixComponent( const std::string & name, const LoggerInterface & logger );
virtual ~MonolithicElastixComponent();
typedef typename ComponentBase::CriterionType CriterionType;
......
......@@ -23,7 +23,8 @@
namespace selx
{
template< int Dimensionality, class TPixel >
MonolithicElastixComponent< Dimensionality, TPixel >::MonolithicElastixComponent( const std::string & name ) : Superclass( name )
MonolithicElastixComponent< Dimensionality, TPixel >::MonolithicElastixComponent( const std::string & name,
const LoggerInterface & logger ) : Superclass( name, logger )
{
m_elastixFilter = ElastixFilterType::New();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment