Commit 52fb76f9 authored by Laurent Belcour's avatar Laurent Belcour

Minor fixes

parent e63bac91
......@@ -5,6 +5,8 @@
#include <cstdlib>
#include <iostream>
#include "common.h"
class arguments
{
public: // functions
......@@ -69,14 +71,44 @@ class arguments
return atof(_map.at(key).c_str()) ;
else
return default_value ;
} ;
}
int get_int(const std::string& key, int default_value = 0) const
{
if(_map.count(key) > 0)
return atoi(_map.at(key).c_str()) ;
else
return default_value ;
} ;
}
vec get_vec(const std::string& key, float default_value) const
{
vec res;
if(_map.count(key) > 0)
{
std::string s = _map.at(key);
if(s[0] == '\[') // Is an array of type [a, b, c]
{
int i = 0;
size_t pos = 0;
while(pos != std::string::npos)
{
size_t ppos = s.find(",", pos);
if(ppos != std::string::npos)
{
std::cout << s.substr(pos, ppos) << std::endl ;
res[i] = atof(s.substr(pos, ppos).c_str());
pos = ppos+1;
++i;
}
}
return res;
}
}
float val = get_float(key, default_value);
res.push_back(default_value);
return res;
}
private: // data
......
......@@ -54,14 +54,7 @@ bool rational_fitter_cgal::fit_data(const data* dat, function* fit)
r->setDimY(d->dimY()) ;
r->setMin(d->min()) ;
r->setMax(d->max()) ;
/*
for(int i=0; i<20; ++i)
{
std::vector<int> deg = r->index2degree(i) ;
std::cout << deg[0] << ", " << deg[1] << std::endl ;
}
throw ;
*/
std::cout << "<<INFO>> np in [" << _min_np << ", " << _max_np
<< "] & nq in [" << _min_nq << ", " << _max_nq << "]" << std::endl ;
......@@ -331,7 +324,9 @@ bool rational_fitter_cgal::fit_data(const vertical_segment* d, int np, int nq, i
}
}
r->update(p, q) ;
std::cout << "<<INFO>> got solution " << *r << std::endl ;
#ifdef DEBUG
std::cout << "<<INFO>> got solution " << *r << std::endl ;
#endif
return true;
}
......
......@@ -167,11 +167,7 @@ bool rational_fitter_matlab::fit_data(const vertical_segment* d, int np, int nq,
double a1_norm = 0.0 ;
vec xi = d->get(i) ;
/* for(int k=0; k<d->dimX(); ++k)
{
xi[k] /= dmax[k] ;
}
*/
// A row of the constraint matrix has this
// form: [p_{0}(x_i), .., p_{np}(x_i), -f(x_i) q_{0}(x_i), .., -f(x_i) q_{nq}(x_i)]
// For the lower constraint and negated for
......@@ -234,7 +230,7 @@ bool rational_fitter_matlab::fit_data(const vertical_segment* d, int np, int nq,
delta = 1.0 ;
}
#ifndef DEBUG
#ifdef DEBUG
std::cout << "<<DEBUG>> delta factor: " << sigma_m << " / " << sigma_M << " = " << delta << std::endl ;
#endif
......
......@@ -51,18 +51,6 @@ bool rational_fitter_quadprog::fit_data(const data* dat, function* fit)
std::cout << "<<INFO>> np in [" << _min_np << ", " << _max_np
<< "] & nq in [" << _min_nq << ", " << _max_nq << "]" << std::endl ;
/*
for(int i=0; i<20; ++i)
{
std::vector<int> deg = r->index2degree(i) ;
std::cout << deg[0] << ", " << deg[1] << ", " << deg[2] << std::endl ;
}
throw ;
//*/
int temp_np = _min_np, temp_nq = _min_nq ;
while(temp_np <= _max_np || temp_nq <= _max_nq)
{
......@@ -171,11 +159,7 @@ bool rational_fitter_quadprog::fit_data(const vertical_segment* dat, int np, int
double a1_norm = 0.0 ;
vec xi = d->get(i) ;
/* for(int k=0; k<d->dimX(); ++k)
{
xi[k] /= dmax[k] ;
}
*/
// A row of the constraint matrix has this
// form: [p_{0}(x_i), .., p_{np}(x_i), -f(x_i) q_{0}(x_i), .., -f(x_i) q_{nq}(x_i)]
// For the lower constraint and negated for
......@@ -263,7 +247,7 @@ bool rational_fitter_quadprog::fit_data(const vertical_segment* dat, int np, int
}
#ifndef DEBUG
#ifdef DEBUG
std::cout << "<<DEBUG>> delta factor: " << sigma_m << " / " << sigma_M << " = " << delta << std::endl ;
#endif
for(int i=0; i<2*d->size(); ++i)
......@@ -310,8 +294,9 @@ bool rational_fitter_quadprog::fit_data(const vertical_segment* dat, int np, int
}
r->update(p, q);
#ifdef DEBUG
std::cout << "<<INFO>> got solution " << *r << std::endl ;
#endif
return norm > 0.0;
}
else
......
......@@ -8,6 +8,7 @@
#include <QtPlugin>
#include <QApplication>
#include <QDir>
#include <QTime>
#include <iostream>
#include <vector>
......@@ -56,11 +57,19 @@ int main(int argc, char** argv)
data* d = fit->provide_data() ;
d->load(args["input"], args);
QTime time ;
time.start() ;
bool is_fitted = fit->fit_data(d, f) ;
int msec = time.elapsed() ;
int sec = (msec / 1000) % 60 ;
int min = (msec / 60000) % 60 ;
int hour = (msec / 3600000) ;
// Display the result
if(is_fitted)
{
std::cout << "<<INFO>> total time: " << hour << "h " << min << "m " << sec << "s" << std::endl ;
/*
vec min, max ;
min.assign(2, args.get_float("min", 0.0f)) ;
......
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