Commit 3e67e5c4 authored by Cyril Poupon's avatar Cyril Poupon
Browse files

wip

parent e4b39cbf
#include <gkg-qmri-plugin-functors/SingleCompartmentRelaxometryMapper/AcquisitionParameterSet.h>
#include <gkg-core-exception/Exception.h>
#include <fstream>
gkg::AcquisitionParameterSet::AcquisitionParameterSet()
{
}
gkg::AcquisitionParameterSet::~AcquisitionParameterSet()
{
}
void gkg::AcquisitionParameterSet::readTextFile( const std::string& fileName,
int32_t count,
gkg::Vector& values )
{
try
{
if ( values.getSize() != count )
{
values.reallocate( count );
}
std::ifstream is ( fileName.c_str() );
if ( !is )
{
throw std::runtime_error( std::string("unable to open '" ) +
fileName + "'" );
}
int32_t t;
for ( t = 0; t < count; t++ )
{
if ( is.eof() )
{
throw std::runtime_error(
"not enough values provided in the text file" );
}
is >> values( t );
}
is.close();
}
GKG_CATCH( "void gkg::SingleCompartmentRelaxometryMCMCFunction::"
"readTextFile( "
"const std::string& fileName, "
"int32_t count, "
"gkg::Vector& values ) const" );
}
#ifndef _gkg_qmri_plugin_functors_SingleCompartmentRelaxometryMapper_AcquisitionParameterSet_h_
#define _gkg_qmri_plugin_functors_SingleCompartmentRelaxometryMapper_AcquisitionParameterSet_h_
#include <gkg-processing-numericalanalysis/Vector.h>
#include <string>
namespace gkg
{
class AcquisitionParameterSet
{
public:
virtual ~AcquisitionParameterSet();
static void readTextFile( const std::string& fileName,
int32_t count,
Vector& values );
protected:
AcquisitionParameterSet();
};
}
#endif
#include <gkg-qmri-plugin-functors/SingleCompartmentRelaxometryMapper/AcquisitionParameterSetFactory.h>
#include <gkg-core-exception/Exception.h>
#include <iostream>
gkg::AcquisitionParameterSetFactory::AcquisitionParameterSetFactory()
{
}
gkg::AcquisitionParameterSetFactory::~AcquisitionParameterSetFactory()
{
}
bool gkg::AcquisitionParameterSetFactory::registerCreator(
const std::string& name,
gkg::AcquisitionParameterSetFactory::AcquisitionParameterSetCreator
acquisitionParameterSetCreator )
{
try
{
if ( acquisitionParameterSetCreator )
{
std::map< std::string,
gkg::AcquisitionParameterSetFactory::
AcquisitionParameterSetCreator
>::const_iterator
c = _acquisitionParameterSetCreators.find( name );
if ( c == _acquisitionParameterSetCreators.end() )
{
_acquisitionParameterSetCreators[ name ] =
acquisitionParameterSetCreator;
return true;
}
#ifdef GKG_DEBUG
else
{
std::cerr << "gkg::AcquisitionParameterSetFactory::"
<< "registerCreator: " << name
<< " already exists"
<< std::endl;
return false;
}
#endif
}
return false;
}
GKG_CATCH( "bool gkg::AcquisitionParameterSetFactory::"
"registerCreator( const std::string& name, "
"gkg::AcquisitionParameterSetFactory::"
"AcquisitionParameterSetCreator "
"acquisitionParameterSetCreator )" );
}
gkg::AcquisitionParameterSet*
gkg::AcquisitionParameterSetFactory::create(
const std::string& name,
const std::vector< int32_t >& measurementCounts,
const std::vector< std::string >& stringParameters ) const
{
try
{
std::map< std::string,
gkg::AcquisitionParameterSetFactory::
AcquisitionParameterSetCreator >::const_iterator
c = _acquisitionParameterSetCreators.find( name );
if ( c != _acquisitionParameterSetCreators.end() )
{
return ( *c->second )( measurementCounts,
stringParameters );
}
else
{
throw std::runtime_error( std::string( "'" ) + name + "' not found" );
}
}
GKG_CATCH( "gkg::AcquisitionParameterSet* "
"gkg::AcquisitionParameterSetFactory::create( "
"const std::string& name, "
"const std::vector< int32_t >& measurementCounts, "
"const std::vector< std::string >& stringParameters ) const" );
}
bool
gkg::AcquisitionParameterSetFactory::
hasAcquisitionParameterSet( const std::string& name ) const
{
try
{
std::map< std::string,
gkg::AcquisitionParameterSetFactory::
AcquisitionParameterSetCreator >::const_iterator
c = _acquisitionParameterSetCreators.find( name );
if ( c != _acquisitionParameterSetCreators.end() )
{
return true;
}
return false;
}
GKG_CATCH( "bool "
"gkg::AcquisitionParameterSetFactory::"
"hasAcquisitionParameterSet( const std::string& name ) const" );
}
std::list< std::string >
gkg::AcquisitionParameterSetFactory::getNames() const
{
try
{
std::list< std::string > names;
std::map< std::string,
gkg::AcquisitionParameterSetFactory::
AcquisitionParameterSetCreator >::const_iterator
c = _acquisitionParameterSetCreators.begin(),
ce = _acquisitionParameterSetCreators.end();
while ( c != ce )
{
names.push_back( c->first );
++ c;
}
return names;
}
GKG_CATCH( "std::list< std::string > "
"gkg::AcquisitionParameterSetFactory::getNames() "
"const" );
}
#ifndef _gkg_qmri_plugin_functors_SingleCompartmentRelaxometryMapper_AcquisitionParameterSetFactory_h_
#define _gkg_qmri_plugin_functors_SingleCompartmentRelaxometryMapper_AcquisitionParameterSetFactory_h_
#include <gkg-core-pattern/Singleton.h>
#include <gkg-qmri-plugin-functors/SingleCompartmentRelaxometryMapper/AcquisitionParameterSet.h>
#include <string>
#include <map>
#include <list>
namespace gkg
{
class AcquisitionParameterSetFactory :
public Singleton< AcquisitionParameterSetFactory >
{
public:
typedef AcquisitionParameterSet*
( *AcquisitionParameterSetCreator )(
const std::vector< int32_t >& measurementCounts,
const std::vector< std::string >& stringParameters );
~AcquisitionParameterSetFactory();
bool registerCreator(
const std::string& name,
AcquisitionParameterSetCreator acquisitionParameterSetCreator );
AcquisitionParameterSet*
create(
const std::string& name,
const std::vector< int32_t >& measurementCounts,
const std::vector< std::string >& stringParameters ) const;
bool hasAcquisitionParameterSet( const std::string& name ) const;
std::list< std::string > getNames() const;
protected:
friend class Singleton< AcquisitionParameterSetFactory >;
AcquisitionParameterSetFactory();
std::map< std::string,
AcquisitionParameterSetCreator > _acquisitionParameterSetCreators;
};
}
#define RegisterAcquisitionParameterSet( NameSpace, Implementation ) \
static bool init_##NameSpace##_##Implementation \
__attribute__((unused)) = \
gkg::AcquisitionParameterSetFactory::getInstance(). \
registerCreator( NameSpace::Implementation::getStaticName(), \
&NameSpace::Implementation::createInstance )
#endif
#include <gkg-qmri-plugin-functors/SingleCompartmentRelaxometryMapper/SingleCompartmentRelaxometryMCMCFunctionFactory.h>
#include <gkg-core-exception/Exception.h>
#include <iostream>
gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::
SingleCompartmentRelaxometryMCMCFunctionFactory()
{
}
gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::
~SingleCompartmentRelaxometryMCMCFunctionFactory()
{
}
bool gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::registerCreator(
const std::string& name,
gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::
RelaxometryMCMCFunctionCreator relaxometryMCMCFunctionCreator )
{
try
{
if ( relaxometryMCMCFunctionCreator )
{
std::map< std::string,
gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::
RelaxometryMCMCFunctionCreator >::const_iterator
c = _relaxometryMCMCFunctionCreators.find( name );
if ( c == _relaxometryMCMCFunctionCreators.end() )
{
_relaxometryMCMCFunctionCreators[ name ] =
relaxometryMCMCFunctionCreator;
return true;
}
#ifdef GKG_DEBUG
else
{
std::cerr << "gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::"
<< "registerCreator: " << name
<< " already exists"
<< std::endl;
return false;
}
#endif
}
return false;
}
GKG_CATCH( "bool gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::"
"registerCreator( const std::string& name, "
"gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::"
"RelaxometryMCMCFunctionCreator "
"relaxometryMCMCFunctionCreator )" );
}
gkg::SingleCompartmentRelaxometryMCMCFunction*
gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::create(
const std::string& name,
const std::vector< int32_t >& measurementCounts,
const std::vector< double >& noiseStandardDeviations,
const gkg::RCPointer< gkg::AcquisitionParameterSet >&
acquisitionParameterSet ) const
{
try
{
std::map< std::string,
gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::
RelaxometryMCMCFunctionCreator >::const_iterator
c = _relaxometryMCMCFunctionCreators.find( name );
if ( c != _relaxometryMCMCFunctionCreators.end() )
{
return ( *c->second )( measurementCounts,
noiseStandardDeviations,
acquisitionParameterSet );
}
else
{
throw std::runtime_error( std::string( "'" ) + name + "' not found" );
}
}
GKG_CATCH( "gkg::SingleCompartmentRelaxometryMCMCFunction* "
"gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::create( "
"const std::string& name, "
"const std::vector< int32_t >& measurementCounts, "
"const std::vector< double >& noiseStandardDeviations, "
"const gkg::RCPointer< gkg::AcquisitionParameterSet >& "
"acquisitionParameterSet ) const" );
}
bool
gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::
hasRelaxometryMCMCFunction( const std::string& name ) const
{
try
{
std::map< std::string,
gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::
RelaxometryMCMCFunctionCreator >::const_iterator
c = _relaxometryMCMCFunctionCreators.find( name );
if ( c != _relaxometryMCMCFunctionCreators.end() )
{
return true;
}
return false;
}
GKG_CATCH( "bool "
"gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::"
"hasRelaxometryMCMCFunction( const std::string& name ) const" );
}
std::list< std::string >
gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::getNames() const
{
try
{
std::list< std::string > names;
std::map< std::string,
gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::
RelaxometryMCMCFunctionCreator >::const_iterator
c = _relaxometryMCMCFunctionCreators.begin(),
ce = _relaxometryMCMCFunctionCreators.end();
while ( c != ce )
{
names.push_back( c->first );
++ c;
}
return names;
}
GKG_CATCH( "std::list< std::string > "
"gkg::SingleCompartmentRelaxometryMCMCFunctionFactory::getNames() "
"const" );
}
#ifndef _gkg_qmri_plugin_functors_SingleCompartmentRelaxometryMapper_SingleCompartmentRelaxometryMCMCFunctionFactory_h_
#define _gkg_qmri_plugin_functors_SingleCompartmentRelaxometryMapper_SingleCompartmentRelaxometryMCMCFunctionFactory_h_
#include <gkg-core-pattern/Singleton.h>
#include <gkg-qmri-plugin-functors/SingleCompartmentRelaxometryMapper/SingleCompartmentRelaxometryMCMCFunction.h>
#include <gkg-qmri-plugin-functors/SingleCompartmentRelaxometryMapper/AcquisitionParameterSet.h>
#include <gkg-core-pattern/RCPointer.h>
#include <string>
#include <map>
#include <list>
namespace gkg
{
class SingleCompartmentRelaxometryMCMCFunctionFactory :
public Singleton< SingleCompartmentRelaxometryMCMCFunctionFactory >
{
public:
typedef SingleCompartmentRelaxometryMCMCFunction*
( *RelaxometryMCMCFunctionCreator )(
const std::vector< int32_t >& measurementCounts,
const std::vector< double >& noiseStandardDeviations,
const RCPointer< AcquisitionParameterSet >& acquisitionParameterSet );
~SingleCompartmentRelaxometryMCMCFunctionFactory();
bool registerCreator(
const std::string& name,
RelaxometryMCMCFunctionCreator relaxometryMCMCFunctionCreator );
SingleCompartmentRelaxometryMCMCFunction*
create(
const std::string& name,
const std::vector< int32_t >& measurementCounts,
const std::vector< double >& noiseStandardDeviations,
const RCPointer< AcquisitionParameterSet >& acquisitionParameterSet ) const;
bool hasRelaxometryMCMCFunction( const std::string& name ) const;
std::list< std::string > getNames() const;
protected: