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

Fixing the dynamic loading thing

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