Commit ee79dbf4 authored by Laurent Belcour's avatar Laurent Belcour

Refactoring the core lib and the plugin manager to provide

static access to function data and fitter objects. It will
be used later in the parallel fitter plugin to evaluate the
resulting function per thread.
parent c89559f9
......@@ -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,37 @@ 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)
{
#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,17 +169,22 @@ 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
{
if(_datas.count(n) == 0)
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using vertical segment data loader" << std::endl ;
#endif
return new vertical_segment() ;
}
else
{
#ifdef DEBUG
std::cout << "<<DEBUG>> using \"" << n << "\" data loader" << std::endl ;
#endif
return _datas.find(n)->second ;
}
}
......@@ -154,7 +196,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,13 +25,13 @@ 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 ;
static function* get_function(const std::string& n) ;
data* get_data(const std::string& n) const ;
fitter* get_fitter(const std::string& n) const ;
......
......@@ -8,6 +8,7 @@
#include <algorithm>
#include <cmath>
rational_function::rational_function() : a(), b()
{
}
......
......@@ -85,7 +85,8 @@ bool rational_fitter_parallel::fit_data(const data* dat, function* fit)
double min_delta = std::numeric_limits<double>::max();
int nb_sol_found = 0;
int np, nq ;
#pragma omp parallel for
#pragma omp parallel for
for(int j=1; j<i; ++j)
{
int temp_np = i - j;
......@@ -97,7 +98,7 @@ bool rational_fitter_parallel::fit_data(const data* dat, function* fit)
bool is_fitted = fit_data(d, temp_np, temp_nq, r, p, q, delta);
if(is_fitted)
{
#pragma omp critical
#pragma omp critical
{
++nb_sol_found ;
if(delta < min_delta)
......@@ -164,7 +165,7 @@ bool rational_fitter_parallel::fit_data(const vertical_segment* d, int np, int n
// the function return a ration BRDF function and a boolean
bool rational_fitter_parallel::fit_data(const vertical_segment* dat, int np, int nq, int ny,
rational_function* rf,
vec& p, vec& q, double& delta)
vec& p, vec& q, double& delta)
{
rational_function* r = dynamic_cast<rational_function*>(rf) ;
const vertical_segment* d = dynamic_cast<const vertical_segment*>(dat) ;
......@@ -175,25 +176,25 @@ bool rational_fitter_parallel::fit_data(const vertical_segment* dat, int np, int
}
const int m = d->size(); // 2*m = number of constraints
const int n = np+nq; // n = np+nq
const int n = np+nq; // n = np+nq
quadratic_program qp(np, nq);
#ifndef TODO_PUT_IN_METHOD
for(int i=0; i<d->size()/2; ++i)
for(int i=0; i<d->size()/10; ++i)
{
// Create two vector of constraints
vec c1(n), c2(n);
get_constraint(2*i, np, nq, ny, d, r, c1, c2);
get_constraint(10*i, np, nq, ny, d, r, c1, c2);
qp.add_constraints(c1);
qp.add_constraints(c2);
}
#endif
// do
do
{
QuadProgPP::Vector<double> x(n);
......@@ -206,11 +207,26 @@ bool rational_fitter_parallel::fit_data(const vertical_segment* dat, int np, int
#endif
return true;
}
/*
int current = 0, i=0;
while(i < 100 && current < m)
{
int next = quadratic_program::next_unmatching_constraint(current, ny, );
// Create two vector of constraints
vec c1(n), c2(n);
get_constraint(next, np, nq, ny, d, r, c1, c2);
qp.add_constraints(c1);
qp.add_constraints(c2);
// int current = 0;
// int next = quadratic_program::next_unmatching_constraint(current, ny, );
++i;
current = next;
}
*/
}
// while(qp.nb_constraints() < 2*m);
while(qp.nb_constraints() < 2*m);
return false;
}
......
......@@ -7,6 +7,11 @@
#include <algorithm>
#include <cmath>
function* provide_function()
{
return new rational_function_chebychev();
}
rational_function_chebychev::rational_function_chebychev() : rational_function()
{
}
......
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