main.cpp 1.72 KB
Newer Older
1
#include <rational_1d_fitter_cgal.h>
2
#include <rational_1d_fitter_eigen.h>
3 4 5 6 7

#include <vector>
#include <iostream>
#include <fstream>

8 9
#include <core/args.h>

10 11
int main(int argc, char** argv)
{
12 13 14 15 16 17 18 19 20 21 22 23 24 25
	arguments args(argc, argv) ;
	if(args.is_defined("help")) {
		std::cout << argv[0] << " --np <int> --nq <int> --input <filename> --output <filename>" << std::endl ;
		return 0 ;
	}

	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 ;
	}
26

27
	// Load the data
28
	rational_1d_data data ;
29 30 31 32 33 34 35 36 37 38
	if(args.is_defined("min") && args.is_defined("max"))
	{
		data.load(args["input"], args.get_float("min", 0.0f), args.get_float("max", 1.0f));
	}
	else
	{
		data.load(args["input"]);
	}

	// Fitting call
39 40 41
	rational_1d_fitter* fitter ;
	if(args.is_defined("algorithm") && args["algorithm"] == std::string("eigen"))
	{
42
		std::cout << "<<INFO>> using Eigen method" << std::endl ;
43 44 45 46
		fitter = new rational_1d_fitter_eigen() ;
	}
	else
	{
47
		std::cout << "<<INFO>> using CGAL method" << std::endl ;
48 49 50
		fitter = new rational_1d_fitter_cgal() ;
	}
	
51
	rational_1d r ;
52
	bool is_fitted = fitter->fit_data(data, args.get_int("np", 10), args.get_int("nq", 10), r) ;
53

54 55 56 57
	// Display the result
	if(is_fitted)
	{
		std::cout << r << std::endl ;
58

59 60
		//*
		std::ofstream file(args["output"], std::ios_base::trunc);
61 62
		const double dt = (data.max() - data.min()) / 100.0f ;
		for(double x=data.min(); x<=data.max(); x+=dt)
63 64 65 66 67 68
		{
			file << x << "\t" << r(x) << std::endl ;
		}
		//*/
	}
	else
69
	{
70
		std::cout << "<<ERROR>> unable to fit the data" << std::endl ;
71
	}
72

73 74 75
	// Clean data
	delete fitter ;

76 77
	return 0 ;
}