Unverified Commit a477af01 authored by Floris Berendsen's avatar Floris Berendsen Committed by GitHub
Browse files

Merge pull request #120 from SuperElastix/SELX-119-SuperElastix-Application-crashes

Selx 119 super elastix application crashes
parents e8109af0 6c12e502
......@@ -20,7 +20,7 @@
#ifndef ConfigurationReader_h
#define ConfigurationReader_h
#include "selxBlueprintImpl.h"
#include "selxBlueprint.h"
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
......@@ -44,12 +44,11 @@ public:
typedef Blueprint::ParameterKeyType ParameterKeyType;
typedef Blueprint::ParameterValueType ParameterValueType;
typedef Blueprint::ParameterMapType ParameterMapType;
typedef std::shared_ptr< BlueprintImpl > BlueprintImplPointer;
using PathType = boost::filesystem::path;
using PathsType = std::list<PathType>;
static BlueprintImpl FromFile(const PathType& filename);
static void MergeFromFile(BlueprintImplPointer blueprint, const PathType & filename);
static Blueprint::Pointer FromFile(const PathType& filename);
static void MergeFromFile(Blueprint::Pointer blueprint, const PathType & filename);
private:
......@@ -61,8 +60,8 @@ private:
static PathsType FindIncludes(const PropertyTreeType &);
static ParameterValueType VectorizeValues(ComponentOrConnectionTreeType componentOrConnectionTree);
static BlueprintImpl FromPropertyTree(const PropertyTreeType &);
static void MergeProperties(BlueprintImplPointer blueprint, const PropertyTreeType &);
static Blueprint::Pointer FromPropertyTree(const PropertyTreeType &);
static void MergeProperties(Blueprint::Pointer blueprint, const PropertyTreeType &);
......
......@@ -50,7 +50,7 @@ ConfigurationReader::VectorizeValues( ComponentOrConnectionTreeType & componentO
}
BlueprintImpl
Blueprint::Pointer
ConfigurationReader::FromFile(const PathType & fileName)
{
LoggerImpl logger;
......@@ -69,21 +69,21 @@ ConfigurationReader::FromFile(const PathType & fileName)
}
else
{
BlueprintImpl baseBlueprint = BlueprintImpl();
Blueprint::Pointer baseBlueprint = Blueprint::New();
for (auto const & includePath : includesList)
{
logger.Log( LogLevel::INF, "Including file {0} ... ", includePath);
baseBlueprint.ComposeWith(FromFile(includePath));
baseBlueprint->ComposeWith(FromFile(includePath).GetPointer());
logger.Log( LogLevel::INF, "Including include file {0} ... Done", includePath);
}
baseBlueprint.ComposeWith(FromPropertyTree(propertyTree));
baseBlueprint->ComposeWith(FromPropertyTree(propertyTree).GetPointer());
logger.Log( LogLevel::INF, "Checking {0} for include files ... Done");
return baseBlueprint;
}
}
void
ConfigurationReader::MergeFromFile(BlueprintImplPointer blueprint, const PathType & fileName)
ConfigurationReader::MergeFromFile(Blueprint::Pointer blueprint, const PathType & fileName)
{
LoggerImpl logger;
......@@ -151,11 +151,11 @@ ConfigurationReader::FindIncludes(const PropertyTreeType & propertyTree)
}
BlueprintImpl
Blueprint::Pointer
ConfigurationReader::FromPropertyTree( const PropertyTreeType & pt )
{
LoggerImpl logger;
BlueprintImpl blueprint = BlueprintImpl();
Blueprint::Pointer blueprint = Blueprint::New();
BOOST_FOREACH( const PropertyTreeType::value_type & v, pt.equal_range( "Component" ) )
{
......@@ -175,7 +175,7 @@ ConfigurationReader::FromPropertyTree( const PropertyTreeType & pt )
componentPropertyMap[ propertyKey ] = propertyMultiValue;
}
blueprint.SetComponent( componentName, componentPropertyMap );
blueprint->SetComponent( componentName, componentPropertyMap );
}
BOOST_FOREACH( const PropertyTreeType::value_type & v, pt.equal_range( "Connection" ) )
......@@ -217,13 +217,13 @@ ConfigurationReader::FromPropertyTree( const PropertyTreeType & pt )
}
}
blueprint.SetConnection( outName, inName, componentPropertyMap );
blueprint->SetConnection( outName, inName, componentPropertyMap );
}
return blueprint;
}
void
ConfigurationReader::MergeProperties(BlueprintImplPointer blueprint, const PropertyTreeType & pt)
ConfigurationReader::MergeProperties(Blueprint::Pointer blueprint, const PropertyTreeType & pt)
{
LoggerImpl logger;
BOOST_FOREACH(const PropertyTreeType::value_type & v, pt.equal_range("Component"))
......
......@@ -50,9 +50,7 @@ operator<<( std::ostream & os, const std::vector< T > & v )
int
main( int ac, char * av[] )
{
// add logger
selx::Logger::Pointer logger = selx::Logger::New();
try
{
typedef std::vector< std::string > VectorOfStringsType;
......@@ -61,6 +59,9 @@ main( int ac, char * av[] )
// instantiate a SuperElastixFilter that is loaded with default components
selx::SuperElastixFilter::Pointer superElastixFilter = selx::SuperElastixFilter::New();
// add logger
logger->AddStream("cout", std::cout);
logger->SetLogLevel(selx::LogLevel::TRC);
superElastixFilter->SetLogger(logger);
boost::filesystem::path configurationPath;
......@@ -95,21 +96,19 @@ main( int ac, char * av[] )
}
// create empty blueprint
typedef std::shared_ptr< selx::BlueprintImpl> BlueprintImplPointer;
BlueprintImplPointer blueprintImpl = BlueprintImplPointer(new selx::BlueprintImpl());
selx::Blueprint::Pointer blueprint = selx::Blueprint::New();
for (const auto & configurationPath : configurationPaths)
{
selx::ConfigurationReader::MergeFromFile(blueprintImpl, configurationPath);
selx::ConfigurationReader::MergeFromFile(blueprint, configurationPath);
}
if( vm.count( "graphout" ) )
{
blueprintImpl->Write( vm[ "graphout" ].as< fs::path >().string() );
blueprint->Write(vm["graphout"].as< fs::path >().string());
}
//turn the blueprint into an itkObject to connect to the superElastix itkFilter
selx::Blueprint::Pointer blueprint = selx::Blueprint::New();
blueprint->SetBlueprint(*blueprintImpl);
superElastixFilter->SetBlueprint(blueprint);
if( vm.count( "in" ) )
......
......@@ -59,10 +59,9 @@ public:
Blueprint();
/** The actual blueprint is a pimpled member variable */
typedef std::shared_ptr< BlueprintImpl > BlueprintImplPointer;
typedef std::unique_ptr< BlueprintImpl > BlueprintImplPointer;
void SetBlueprint( BlueprintImpl & blueprint );
BlueprintImpl & GetBlueprint( void );
const BlueprintImpl & GetBlueprintImpl( void ) const;
bool SetComponent( ComponentNameType, ParameterMapType parameterMap );
......@@ -86,7 +85,7 @@ public:
//std::unique_ptr<BlueprintImpl> Clone(BlueprintImpl const &other );
// "functional" composition of blueprints is done by adding settings of other to this blueprint. Redefining/overwriting properties is not allowed and returns false.
bool ComposeWith( const BlueprintImpl & other );
bool ComposeWith( Blueprint::ConstPointer other );
// Returns a vector of the Component names at the incoming direction
ComponentNamesType GetInputNames( const ComponentNameType name ) const;
......
......@@ -29,27 +29,11 @@ Blueprint
this->m_Blueprint = BlueprintImplPointer( new BlueprintImpl() );
}
void
const BlueprintImpl &
Blueprint
::SetBlueprint( BlueprintImpl& blueprint )
::GetBlueprintImpl( void ) const
{
this->Modified();
this->m_Blueprint = BlueprintImplPointer( &blueprint );
}
BlueprintImpl &
Blueprint
::GetBlueprint( void)
{
if( this->m_Blueprint )
{
return *this->m_Blueprint;
}
else
{
itkExceptionMacro( "BlueprintImpl not set." )
}
return *this->m_Blueprint;
}
......@@ -130,10 +114,10 @@ Blueprint
bool
Blueprint
::ComposeWith( const BlueprintImpl & other)
::ComposeWith( Blueprint::ConstPointer other)
{
this->Modified();
return this->m_Blueprint->ComposeWith( other );
return this->m_Blueprint->ComposeWith( other->GetBlueprintImpl() );
}
......
......@@ -103,7 +103,7 @@ public:
bool ConnectionExists( ComponentNameType upstream, ComponentNameType downstream ) const;
bool ComposeWith( const BlueprintImpl & other);
bool ComposeWith( const BlueprintImpl & other );
// Returns a vector of the Component names at the incoming direction
ComponentNamesType GetInputNames( const ComponentNameType name ) const;
......
......@@ -58,9 +58,10 @@ public:
typedef std::map<
std::string, RegistrationControllerStartInterface::Pointer > RegistrationControllerStartInterfaceMapType;
NetworkBuilder( LoggerImpl & logger, BlueprintImpl & blueprint );
NetworkBuilder( LoggerImpl & logger, const BlueprintImpl & blueprint );
virtual ~NetworkBuilder() {}
//Disabled
virtual bool AddBlueprint( const BlueprintImpl & blueprint );
/** Read configuration at the blueprints nodes and edges and return true if all components could be uniquely selected*/
......@@ -116,7 +117,7 @@ protected:
ComponentSelectorContainerType m_ComponentSelectorContainer;
bool m_isConfigured;
LoggerImpl & m_Logger;
BlueprintImpl & m_Blueprint;
const BlueprintImpl & m_Blueprint;
private:
};
......
......@@ -25,7 +25,7 @@
namespace selx
{
template< typename ComponentList >
NetworkBuilder< ComponentList >::NetworkBuilder( LoggerImpl & logger, BlueprintImpl & blueprint ) : m_Logger( logger ), m_isConfigured( false ), m_Blueprint( blueprint )
NetworkBuilder< ComponentList >::NetworkBuilder( LoggerImpl & logger, const BlueprintImpl & blueprint ) : m_Logger( logger ), m_isConfigured( false ), m_Blueprint( blueprint )
{
}
......@@ -34,7 +34,8 @@ template< typename ComponentList >
bool
NetworkBuilder< ComponentList >::AddBlueprint( const BlueprintImpl & blueprint )
{
this->m_Blueprint.ComposeWith( blueprint );
//Disabled
//this->m_Blueprint.ComposeWith( blueprint );
//m_Blueprint = std::make_shared< BlueprintImpl >(*blueprint);
return true;
}
......
......@@ -32,7 +32,7 @@ public:
NetworkBuilderFactory() {}
virtual ~NetworkBuilderFactory() {}
virtual std::unique_ptr< NetworkBuilderBase > New( LoggerImpl & logger, BlueprintImpl & blueprint );
virtual std::unique_ptr< NetworkBuilderBase > New( LoggerImpl & logger, const BlueprintImpl & blueprint );
};
} // end namespace selx
......
......@@ -24,7 +24,7 @@ namespace selx
{
template< typename ComponentList >
std::unique_ptr< NetworkBuilderBase >
NetworkBuilderFactory< ComponentList >::New( LoggerImpl & logger, BlueprintImpl & blueprint )
NetworkBuilderFactory< ComponentList >::New( LoggerImpl & logger, const BlueprintImpl & blueprint )
{
return std::unique_ptr< NetworkBuilderBase >( new NetworkBuilder< ComponentList >( logger, blueprint ) );
}
......
......@@ -33,7 +33,7 @@ public:
virtual ~NetworkBuilderFactoryBase() {}
/** To create a derived NetworkBuilderFactory from a NetworkBuilderFactoryBase pointer without knowing the template arguments of the derived*/
virtual std::unique_ptr< NetworkBuilderBase > New( LoggerImpl & logger, BlueprintImpl & blueprint ) = 0;
virtual std::unique_ptr< NetworkBuilderBase > New( LoggerImpl & logger, const BlueprintImpl & blueprint ) = 0;
private:
};
......
......@@ -42,7 +42,7 @@ SuperElastixFilterBase
{
if( ( this->m_Blueprint->GetMTime() > this->GetMTime() || !this->m_NetworkBuilder ) )
{
m_NetworkBuilder = m_NetworkBuilderFactory->New( this->m_Logger->GetLogger(), this->m_Blueprint->GetBlueprint() );
m_NetworkBuilder = m_NetworkBuilderFactory->New( this->m_Logger->GetLogger(), this->m_Blueprint->GetBlueprintImpl() );
this->m_AllUniqueComponents = this->m_NetworkBuilder->Configure();
}
return this->m_AllUniqueComponents;
......
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