Commit 4ae204f6 authored by Laurent Belcour's avatar Laurent Belcour
Browse files

Merging with parallel branch. Not all the work is done, but the plugin system is

needed for the rest of the dev.
parents a1fabea6 fc6add90
......@@ -9,6 +9,8 @@
/*! \brief A useful class for storing the high-level arguments of a program
* or a function.
* \ingroup core
* \internal
*
* The set of parameters are parsed from the command line using the
* constructor. They are stored as std::string in a std::map.
......@@ -75,7 +77,7 @@ class arguments
}
else
{
std::cerr << "Underfined request to key : \"" << key << "\"" << std::endl ;
//std::cerr << "Underfined request to key : \"" << key << "\"" << std::endl ;
return std::string() ;
}
} ;
......
......@@ -5,12 +5,14 @@
#include <cassert>
#include <cmath>
/*! \brief A core implementation of a vector of double.
/*! \brief A core implementation of a vector of double.
* \ingroup core
* \internal
*
* \details
* This type is used for any transmission of vector data with unfixed
* dimension. It allows to have a generic fitter working for
* n-Dimensional data.
* \details
* This type is used for any transmission of vector data with unfixed
* dimension. It allows to have a generic fitter working for
* n-Dimensional data.
*/
class vec : public std::vector<double>
{
......@@ -22,11 +24,23 @@ class vec : public std::vector<double>
}
vec(int dim) : std::vector<double>(dim)
{
assign(dim, 0.0) ;
} ;
assign(dim, 0.0) ;
}
virtual ~vec()
{
} ;
}
//! \brief copy operator. It resize the left operand to the size of the
//! right operand.
vec operator=(const vec& a)
{
this->resize(a.size());
for(unsigned int i=0; i<a.size(); ++i)
{
this->at(i) = a[i];
}
return *this ;
}
// Mathematical operators
//
......
......@@ -15,19 +15,19 @@ class fitter
{
public:
// Static function to fit a data set d with the
// underling function class. Return the best
// fit (along with fitting information ?)
//
virtual bool fit_data(const data* d, function* f) = 0 ;
//! \brief static function to fit a data set d with the underling
//! function class. Return the best fit (along with fitting
//! information ?)
virtual bool fit_data(const data* d, function* f, const arguments& args) = 0 ;
virtual void set_parameters(const arguments& args) = 0 ;
/*
// Provide a function class and a data class
//
virtual data* provide_data() const = 0 ;
virtual function* provide_function() const = 0 ;
*/
} ;
Q_DECLARE_INTERFACE(fitter, "Fitter.Fitter")
......@@ -49,12 +49,16 @@ class function
// Acces to the domain of definition of the function
virtual void setMin(const vec& min)
{
#ifdef DEBUG
assert(min.size() == _nX) ;
#endif
_min = min ;
}
virtual void setMax(const vec& max)
{
#ifdef DEBUG
assert(max.size() == _nX) ;
#endif
_max = max ;
}
virtual vec getMin() const { return _min ; }
......
......@@ -5,6 +5,7 @@
#include <QCoreApplication>
#include <QPluginLoader>
#include <QtPlugin>
#include <QLibrary>
#include <QDir>
// Create the object, parse the argument and load
......@@ -78,12 +79,22 @@ plugins_manager::plugins_manager(const arguments& args)
}
}
#define USING_STATIC
#ifdef USING_STATIC
typedef function* (*FunctionPrototype)();
typedef fitter* (*FitterPrototype)();
typedef data* (*DataPrototype)();
#endif
// Get instances of the function, the data and the
// fitter
//
function* plugins_manager::get_function() const
function* plugins_manager::get_function()
{
if(_functions.empty())
#ifdef USING_STATIC
return new rational_function() ;
#else
if(_functions.empty())
{
return new rational_function() ;
}
......@@ -91,17 +102,23 @@ function* plugins_manager::get_function() const
{
return _functions.begin()->second ;
}
#endif
}
data* plugins_manager::get_data() const
{
//if(_datas.empty())
{
std::cout << "<<DEBUG>> using vertical segment data loader" << std::endl ;
#ifdef DEBUG
std::cout << "<<DEBUG>> using vertical segment data loader" << std::endl ;
#endif
return new vertical_segment() ;
}/*
else
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using \"" << _datas.begin()->first << "\" data loader" << std::endl ;
#endif
return _datas.begin()->second ;
}*/
}
......@@ -113,17 +130,45 @@ fitter* plugins_manager::get_fitter() const
}
else
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using \"" << _fitters.begin()->first << "\"" << std::endl ;
#endif
return _fitters.begin()->second ;
}
}
// Get instances of the function, the data and the
// fitter, select one based on the name. Return null
// if no one exist.
//
function* plugins_manager::get_function(const std::string& n) const
function* plugins_manager::get_function(const std::string& n)
{
if(n.empty())
{
#ifdef DEBUG
std::cout << "<<DEBUG>> no function plugin specified, returning a rational function" << std::endl;
#endif
return new rational_function();
}
#ifdef USING_STATIC
FunctionPrototype myFunction = (FunctionPrototype) QLibrary::resolve(QString(n.c_str()), "_Z16provide_functionv");
if(myFunction != NULL)
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using function provider in file \"" << n << "\"" << std::endl;
#endif
return myFunction();
}
else
{
std::cerr << "<<ERROR>> no function provider found in file \"" << n << "\"" << std::endl;
return new rational_function() ;
}
#else
if(_functions.count(n) == 0)
{
return new rational_function() ;
......@@ -132,19 +177,44 @@ function* plugins_manager::get_function(const std::string& n) const
{
return _functions.find(n)->second ;
}
#endif
}
data* plugins_manager::get_data(const std::string& n) const
data* plugins_manager::get_data(const std::string& n)
{
if(_datas.count(n) == 0)
{
std::cout << "<<DEBUG>> using vertical segment data loader" << std::endl ;
return new vertical_segment() ;
}
else
{
std::cout << "<<DEBUG>> using \"" << n << "\" data loader" << std::endl ;
return _datas.find(n)->second ;
}
if(n.empty())
{
#ifdef DEBUG
std::cout << "<<DEBUG>> no data plugin specified, returning a vertial_segment loader" << std::endl;
#endif
return new vertical_segment();
}
#ifdef USING_STATIC
DataPrototype myData = (DataPrototype) QLibrary::resolve(QString(n.c_str()), "_Z16provide_datav");
if(myData != NULL)
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using function provider in file \"" << n << "\"" << std::endl;
#endif
return myData();
}
else
{
std::cerr << "<<ERROR>> no data provider found in file \"" << n << "\"" << std::endl;
return new vertical_segment() ;
}
#else
if(_functions.count(n) == 0)
{
return new vertical_segment() ;
}
else
{
return _datas.find(n)->second ;
}
#endif
}
fitter* plugins_manager::get_fitter(const std::string& n) const
{
......@@ -154,7 +224,9 @@ fitter* plugins_manager::get_fitter(const std::string& n) const
}
else
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using \"" << n << "\"" << std::endl ;
#endif
return _fitters.find(n)->second ;
}
}
......
......@@ -25,14 +25,14 @@ class plugins_manager
//! \brief Get instances of the function, the data and the fitter. Select
//! the first in the map,
function* get_function() const ;
static function* get_function() ;
data* get_data() const ;
fitter* get_fitter() const ;
//! \brief Get instances of the function, the data and the fitter, select one
//! based on the name. Return null if no one exist.
function* get_function(const std::string& n) const ;
data* get_data(const std::string& n) const ;
static function* get_function(const std::string& n) ;
static data* get_data(const std::string& n) ;
fitter* get_fitter(const std::string& n) const ;
//! \brief Provide a measure of how much memory there is on the system.
......
......@@ -8,10 +8,15 @@
#include <algorithm>
#include <cmath>
rational_function::rational_function() : a(), b()
{
}
rational_function::rational_function(int np, int nq) : a(np), b(nq)
{
}
rational_function::rational_function(const std::vector<double>& a,
const std::vector<double>& b) :
a(a), b(b)
......
......@@ -20,6 +20,7 @@ class rational_function : public QObject, public function
public: // methods
rational_function() ;
rational_function(int np, int nq) ;
rational_function(const std::vector<double>& a, const std::vector<double>& b) ;
virtual ~rational_function() ;
......
......@@ -56,7 +56,7 @@ void vertical_segment::load(const std::string& filename, const arguments& args)
_min.resize(dimX()) ;
_max.resize(dimX()) ;
min = args.get_vec("min", _nX, -std::numeric_limits<double>::max()) ;
max = args.get_vec("max", _nX, std::numeric_limits<double>::max()) ;
......@@ -79,8 +79,7 @@ void vertical_segment::load(const std::string& filename, const arguments& args)
continue ;
}
vec v ;
v.resize(dimX() + 3*dimY()) ;
vec v(dimX() + 3*dimY()) ;
for(int i=0; i<dimX(); ++i)
linestream >> v[i] ;
......
......@@ -59,7 +59,7 @@ nonlinear_fitter_eigen::~nonlinear_fitter_eigen()
{
}
bool nonlinear_fitter_eigen::fit_data(const data* d, function* fit)
bool nonlinear_fitter_eigen::fit_data(const data* d, function* fit, const arguments &args)
{
// I need to set the dimension of the resulting function to be equal
// to the dimension of my fitting problem
......
......@@ -28,7 +28,7 @@ class nonlinear_fitter_eigen: public QObject, public fitter
// Fitting a data object
//
virtual bool fit_data(const data* d, function* fit) ;
virtual bool fit_data(const data* d, function* fit, const arguments& args) ;
// Provide user parameters to the fitter
//
......
......@@ -38,7 +38,7 @@ rational_fitter_cgal::~rational_fitter_cgal()
{
}
bool rational_fitter_cgal::fit_data(const data* dat, function* fit)
bool rational_fitter_cgal::fit_data(const data* dat, function* fit, const arguments &args)
{
rational_function* r = dynamic_cast<rational_function*>(fit) ;
const vertical_segment* d = dynamic_cast<const vertical_segment*>(dat) ;
......
......@@ -26,7 +26,7 @@ class rational_fitter_cgal : public QObject, public fitter
// Fitting a data object
//
virtual bool fit_data(const data* d, function* fit) ;
virtual bool fit_data(const data* d, function* fit, const arguments& args) ;
// Provide user parameters to the fitter
//
......
......@@ -31,7 +31,7 @@ rational_fitter_dca::~rational_fitter_dca()
{
}
bool rational_fitter_dca::fit_data(const data* dat, function* fit)
bool rational_fitter_dca::fit_data(const data* dat, function* fit, const arguments &args)
{
rational_function* r = dynamic_cast<rational_function*>(fit) ;
const vertical_segment* d = dynamic_cast<const vertical_segment*>(dat) ;
......
......@@ -26,7 +26,7 @@ class rational_fitter_dca : public QObject, public fitter
// Fitting a data object
//
virtual bool fit_data(const data* d, function* fit) ;
virtual bool fit_data(const data* d, function* fit, const arguments& args) ;
// Provide user parameters to the fitter
//
......
......@@ -29,7 +29,7 @@ rational_fitter_eigen::~rational_fitter_eigen()
{
}
bool rational_fitter_eigen::fit_data(const data* dat, function* fit)
bool rational_fitter_eigen::fit_data(const data* dat, function* fit, const arguments &args)
{
rational_function* r = dynamic_cast<rational_function*>(fit) ;
const vertical_segment* d = dynamic_cast<const vertical_segment*>(dat) ;
......
......@@ -25,7 +25,7 @@ class rational_fitter_eigen : public QObject, public fitter
// Fitting a data object
//
virtual bool fit_data(const data* d, function* fit) ;
virtual bool fit_data(const data* d, function* fit, const arguments& args) ;
// Provide user parameters to the fitter
//
......
......@@ -29,7 +29,7 @@ rational_fitter_leastsquare::~rational_fitter_leastsquare()
{
}
bool rational_fitter_leastsquare::fit_data(const data* dat, function* fit)
bool rational_fitter_leastsquare::fit_data(const data* dat, function* fit, const arguments &args)
{
rational_function* r = dynamic_cast<rational_function*>(fit) ;
const vertical_segment* d = dynamic_cast<const vertical_segment*>(dat) ;
......
......@@ -25,7 +25,7 @@ class rational_fitter_leastsquare : public QObject, public fitter
// Fitting a data object
//
virtual bool fit_data(const data* d, function* fit) ;
virtual bool fit_data(const data* d, function* fit, const arguments& args) ;
// Provide user parameters to the fitter
//
......
......@@ -31,7 +31,7 @@ rational_fitter_matlab::~rational_fitter_matlab()
{
}
bool rational_fitter_matlab::fit_data(const data* dat, function* fit)
bool rational_fitter_matlab::fit_data(const data* dat, function* fit, const arguments &args)
{
rational_function* r = dynamic_cast<rational_function*>(fit) ;
const vertical_segment* d = dynamic_cast<const vertical_segment*>(dat) ;
......
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