Commit 370355cc authored by Laurent Belcour's avatar Laurent Belcour

Fixing the dynamic loading thing

parent a5ac60aa
......@@ -62,11 +62,10 @@ class arguments
} ;
float get_float(const std::string& key, float default_value = 0.0f) const
{
std::string value = _map.at(key) ;
if(value.empty())
return default_value ;
if(_map.count(key) > 0)
return atof(_map.at(key).c_str()) ;
else
return atof(value.c_str()) ;
return default_value ;
} ;
int get_int(const std::string& key, int default_value = 0) const
{
......
......@@ -170,6 +170,11 @@ bool rational_1d_data::get(int i, double& x, double& yl, double& yu) const
return true ;
}
const std::vector<double>& rational_1d_data::get(int i) const
{
return _data[i] ;
}
int rational_1d_data::input_dimension() const
{
......
......@@ -53,6 +53,7 @@ class rational_1d_data : public data
// Acces to data
virtual bool get(int i, double& x, double& yl, double& yu) const ;
virtual const std::vector<double>& get(int i) const ;
virtual const std::vector<double>& operator[](int i) const ;
// Get data size
......@@ -84,11 +85,11 @@ class rational_1d_fitter : public fitter
public: // methods
// Fitting a data object
virtual bool fit_data(const rational_1d_data* data, rational_1d*& fit) ;
virtual bool fit_data(const data* d, function*& f) ;
// Fitting a data object using np elements in the numerator and nq
// elements in the denominator
virtual bool fit_data(const rational_1d_data* data, int np, int nq, rational_1d*& fit) = 0 ;
virtual bool fit_data(const data* d, int np, int nq, function*& f) = 0 ;
virtual void set_parameters(const arguments& args) ;
......
......@@ -9,7 +9,7 @@ class rational_1d_fitter_eigen : public rational_1d_fitter
// Fitting a data object using np elements
// in the numerator and nq elements in the
// denominator
virtual bool fit_data(const rational_1d_data* data, int np, int nq, rational_1d*& fit) ;
virtual bool fit_data(const data* d, int np, int nq, function*& f) ;
private:
} ;
TEMPLATE = lib
CONFIG += plugin
CONFIG *= qt \
plugin
DESTDIR = ../build
INCLUDEPATH += ../..
HEADERS = rational_data.h
......@@ -7,5 +10,4 @@ SOURCES = rational_data.cpp
LIBS += -lboost_regex
QMAKE_CXXFLAGS += -std=c++11 -frounding-math
QMAKE_CXXFLAGS += -std=c++11 -frounding-math -fPIC
......@@ -22,7 +22,14 @@ typedef CGAL::Quadratic_program<ET> Program ;
typedef CGAL::Quadratic_program_solution<ET> Solution ;
typedef CGAL::Quadratic_program_options Options ;
bool rational_1d_fitter_cgal::fit_data(const data* d, function*& fit)
rational_fitter_cgal::rational_fitter_cgal() : QObject()
{
}
rational_fitter_cgal::~rational_fitter_cgal()
{
}
bool rational_fitter_cgal::fit_data(const data* d, function*& fit)
{
std::cout << "<<INFO>> np in [" << _min_np << ", " << _max_np << "] & nq in [" << _min_nq << ", " << _max_nq << "]" << std::endl ;
int temp_np = _min_np, temp_nq = _min_nq ;
......@@ -48,7 +55,7 @@ bool rational_1d_fitter_cgal::fit_data(const data* d, function*& fit)
return false ;
}
void rational_1d_fitter_cgal::set_parameters(const arguments& args)
void rational_fitter_cgal::set_parameters(const arguments& args)
{
_max_np = args.get_float("np", 10) ;
_max_nq = args.get_float("nq", 10) ;
......@@ -57,7 +64,7 @@ void rational_1d_fitter_cgal::set_parameters(const arguments& args)
}
bool rational_1d_fitter_cgal::fit_data(const data* d, int np, int nq, function*& rf)
bool rational_fitter_cgal::fit_data(const data* d, int np, int nq, function*& rf)
{
// by default, we have a nonnegative QP with Ax - b >= 0
Program qp (CGAL::LARGER, false, 0, false, 0) ;
......@@ -254,4 +261,4 @@ bool rational_1d_fitter_cgal::fit_data(const data* d, int np, int nq, function*&
}
}
Q_EXPORT_PLUGIN2(rational_fitter_cgal, rational_1d_fitter_cgal)
Q_EXPORT_PLUGIN2(rational_fitter_cgal, rational_fitter_cgal)
......@@ -13,12 +13,15 @@
#include <core/fitter.h>
#include <core/args.h>
class rational_1d_fitter_cgal : public QObject, public fitter
class rational_fitter_cgal : public QObject, public fitter
{
Q_OBJECT
Q_INTERFACES(fitter)
public: // methods
rational_fitter_cgal() ;
virtual ~rational_fitter_cgal() ;
// Fitting a data object
virtual bool fit_data(const data* d, function*& fit) ;
......
TEMPLATE = lib
CONFIG += plugin
CONFIG *= qt \
plugin \
debug
DESTDIR = ../build
INCLUDEPATH += ../rational_function ../rational_data ../.. /home/belcour/Sources/Eigen/include/eigen3
HEADERS = rational_1d_fitter_cgal.h
SOURCES = rational_1d_fitter_cgal.cpp
LIBS += -lCGAL -lboost_regex \
-L../rational_function -L../rational_data \
LIBS += -lCGAL -lboost_regex \
-L../build \
-lrational_function -lrational_data
QMAKE_CXXFLAGS += -std=c++11 -frounding-math
QMAKE_CXXFLAGS += -std=c++11 -frounding-math -fPIC
TEMPLATE = lib
CONFIG += plugin
CONFIG *= qt \
plugin
DESTDIR = ../build
INCLUDEPATH += ../..
HEADERS = rational_function.h
SOURCES = rational_function.cpp
LIBS += -lboost_regex
QMAKE_CXXFLAGS += -std=c++11 -frounding-math
QMAKE_CXXFLAGS += -std=c++11 -frounding-math -fPIC -rdynamic
......@@ -29,22 +29,30 @@ int main(int argc, char** argv)
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
QObject *plugin = loader.instance();
if (plugin != nullptr) {
std::cout << "Loading plugin " << fileName.toStdString() << std::endl ;
if (plugin != nullptr)
{
#ifdef DEBUG
std::cout << "<<DEBUG>> loading plugin " << fileName.toStdString() << std::endl ;
#endif
if(dynamic_cast<function*>(plugin) != nullptr)
{
std::cout << " -> it is a function" << std::endl ;
#ifdef DEBUG
std::cout << "<<DEBUG>> -> it is a function" << std::endl ;
#endif
functions.push_back(dynamic_cast<function*>(plugin)) ;
}
else if(dynamic_cast<data*>(plugin) != nullptr)
{
std::cout << " -> it is a data loader" << std::endl ;
#ifdef DEBUG
std::cout << "<<DEBUG>> -> it is a data loader" << std::endl ;
#endif
datas.push_back(dynamic_cast<data*>(plugin)) ;
}
else if(dynamic_cast<fitter*>(plugin) != nullptr)
{
std::cout << " -> it is a fitter" << std::endl ;
#ifdef DEBUG
std::cout << "<<DEBUG>> -> it is a fitter" << std::endl ;
#endif
fitters.push_back(dynamic_cast<fitter*>(plugin)) ;
}
......@@ -52,6 +60,14 @@ int main(int argc, char** argv)
}
arguments args(argc, argv) ;
if(! args.is_defined("input")) {
std::cerr << "<<ERROR>> the input filename is not defined" << std::endl ;
return 1 ;
}
if(! args.is_defined("output")) {
std::cerr << "<<ERROR>> the output filename is not defined" << std::endl ;
return 1 ;
}
if(fitters.size() > 0 && datas.size() > 0 && functions.size() > 0)
{
......@@ -59,12 +75,29 @@ int main(int argc, char** argv)
function* f = functions[0] ;
data* d = datas[0] ;
if(args.is_defined("min") && args.is_defined("max"))
{
d->load(args["input"], args.get_float("min", 0.0f), args.get_float("max", 1.0f));
}
else if(args.is_defined("min") && !args.is_defined("max"))
{
d->load(args["input"], args.get_float("min", 0.0f), std::numeric_limits<double>::max());
}
else if(args.is_defined("min") && !args.is_defined("max"))
{
d->load(args["input"], -std::numeric_limits<double>::max(), args.get_float("min", 0.0f));
}
else
{
d->load(args["input"]);
}
bool is_fitted = fitters[0]->fit_data(d, f) ;
// Display the result
if(is_fitted)
{
std::cout << f << std::endl ;
// std::cout << *f << std::endl ;
//*
std::ofstream file(args["output"], std::ios_base::trunc);
......
......@@ -5,6 +5,7 @@ INCLUDEPATH += ../../ ../../libs/rational_1d /home/belcour/Sources/Eigen/include
SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++11 -frounding-math
QMAKE_CXXFLAGS += -std=c++11 -frounding-math -fPIC
QMAKE_LFLAGS += -Wl,-rpath="."
LIBS += -lCGAL -lboost_regex
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