Commit 9e94b16e authored by Laurent Belcour's avatar Laurent Belcour
Browse files

Need a refactor before going into the plugin fashion

parent de6d0847
#pragma once #pragma once
#include <string> #include <string>
#include <pair> #include <utility>
template<class X, class Y> class data class data
{ {
public: // methods public: // methods
// Load data from a file // Load data from a file
virtual void load(const std::string& filename) = 0 ; virtual void load(const std::string& filename) = 0 ;
virtual void load(const std::string& filename, X min, X max) = 0 ; virtual void load(const std::string& filename, double min, double max) = 0 ;
// Acces to data // Acces to data
virtual bool get(int i, X& x, Y& y) const = 0 ; virtual bool get(int i, double& x, double& y, double& t) const = 0 ;
virtual const std::pair<X, Y>& operator[](int i) const = 0 ; virtual const std::vector<double>& operator[](int i) const = 0 ;
// Get data size // Get data size
virtual int size() const = 0 ; virtual int size() const = 0 ;
// Get min and max input parameters // Get min and max input parameters
virtual X min() const = 0 ; virtual double min() const = 0 ;
virtual X max() const = 0 ; virtual double max() const = 0 ;
} ; } ;
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Fitting interface for generic fitting algorithms * Fitting interface for generic fitting algorithms
* *
*/ */
template<class X, class Y> class fitter class fitter
{ {
public: public:
...@@ -15,6 +15,6 @@ template<class X, class Y> class fitter ...@@ -15,6 +15,6 @@ template<class X, class Y> class fitter
// underling function class. Return the best // underling function class. Return the best
// fit (along with fitting information ?) // fit (along with fitting information ?)
// //
virtual bool fit_data(const data<X, Y>& d, function<X, Y>& f) = 0 ; virtual bool fit_data(const data* d, function* f) = 0 ;
} ; } ;
#pragma once #pragma once
template<class X, class Y> class function : public std::function<X(Y)> #include <functional>
#include <string>
class function : public std::function<double(double)>
{ {
public: // methods public: // methods
// Overload the function operator // Overload the function operator
virtual Y operator()(float X) const = 0 ; virtual double operator()(double x) const = 0 ;
// IO function to text files // IO function to text files
virtual void load(const std::string& filename) = 0 ; virtual void load(const std::string& filename) = 0 ;
......
...@@ -6,7 +6,12 @@ ...@@ -6,7 +6,12 @@
#include <string> #include <string>
#include <tuple> #include <tuple>
class rational_1d : public std::function<double(double)> // Interface
#include <core/function.h>
#include <core/data.h>
#include <core/fitter.h>
class rational_1d : public function
{ {
public: // methods public: // methods
...@@ -36,24 +41,24 @@ class rational_1d : public std::function<double(double)> ...@@ -36,24 +41,24 @@ class rational_1d : public std::function<double(double)>
std::vector<double> b ; std::vector<double> b ;
} ; } ;
class rational_1d_data // : public fitting_data class rational_1d_data : public data
{ {
public: // methods public: // methods
// Load data from a file // Load data from a file
void load(const std::string& filename) ; virtual void load(const std::string& filename) ;
void load(const std::string& filename, double min, double max) ; virtual void load(const std::string& filename, double min, double max) ;
// Acces to data // Acces to data
bool get(int i, double& x, double& yl, double& yu) const ; virtual bool get(int i, double& x, double& yl, double& yu) const ;
const std::vector<double>& operator[](int i) const ; virtual const std::vector<double>& operator[](int i) const ;
// Get data size // Get data size
int size() const ; virtual int size() const ;
// Get min and max input parameters // Get min and max input parameters
double min() const ; virtual double min() const ;
double max() const ; virtual double max() const ;
private: // data private: // data
...@@ -66,7 +71,7 @@ class rational_1d_data // : public fitting_data ...@@ -66,7 +71,7 @@ class rational_1d_data // : public fitting_data
double _min, _max ; double _min, _max ;
} ; } ;
class rational_1d_fitter // : public fitting_algorithm class rational_1d_fitter //: public fitter
{ {
public: // methods public: // methods
......
...@@ -149,11 +149,7 @@ bool rational_1d_fitter_cgal::fit_data(const rational_1d_data& data, int np, int ...@@ -149,11 +149,7 @@ bool rational_1d_fitter_cgal::fit_data(const rational_1d_data& data, int np, int
#endif #endif
// solve the program, using ET as the exact type // solve the program, using ET as the exact type
//*
Solution s = CGAL::solve_quadratic_program(qp, ET()) ; Solution s = CGAL::solve_quadratic_program(qp, ET()) ;
/*/
Solution s = CGAL::solve_nonnegative_quadratic_program(qp, ET());
//*/
bool solves_qp = s.solves_quadratic_program(qp) ; bool solves_qp = s.solves_quadratic_program(qp) ;
for(int i=0; i<np+nq; ++i) for(int i=0; i<np+nq; ++i)
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <tuple> #include <tuple>
// Personal include // Personal include
//#include <fitting_algorithm.h>
#include "rational_1d_fitter.h" #include "rational_1d_fitter.h"
......
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