Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

main.cpp 1.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <core/args.h>
#include <core/data.h>
#include <core/params.h>
#include <core/function.h>
#include <core/fitter.h>
#include <core/plugins_manager.h>

#include <iostream>
#include <vector>
#include <iostream>
#include <fstream>
#include <limits>
#include <cstdlib>
#include <cmath>

int main(int argc, char** argv)
{
	arguments args(argc, argv) ;

	if(args.is_defined("help")) {
Laurent Belcour's avatar
Merging  
Laurent Belcour committed
21 22
		std::cout << "Usage: brdf2data --input brdf.file --output data.file [--data exporter.so --data-file data.file]" << std::endl ;
		std::cout << " - input, output are mandatory parameters, you need to either specify a data exporter or a data file" << std::endl ;
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
		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 ;
	}
	if(! args.is_defined("data")) {
		std::cerr << "<<ERROR>> the data exporter is not defined" << std::endl ;
		return 1 ;
	}
Laurent Belcour's avatar
Merging  
Laurent Belcour committed
38 39
	
	// Get the associated data object and load the file is any
40
	data* d = NULL ;
Laurent Belcour's avatar
Merging  
Laurent Belcour committed
41 42 43 44 45
	d = plugins_manager::get_data(args["data"]) ;
	if(args.is_defined("data-file"))
	{
		d->load(args["data-file"]);
	}
46

Laurent Belcour's avatar
Merging  
Laurent Belcour committed
47
	// Get the function file
48
	function* f = NULL;
49
	f = plugins_manager::get_function(args["input"]);
50 51 52 53
	if(f == NULL)
	{
		return 1;
	}
54 55 56

	if(d != NULL && f != NULL)
	{
Laurent Belcour's avatar
Laurent Belcour committed
57
		vec temp(f->dimX());
58 59 60 61
		for(int i=0; i<d->size(); ++i)
		{
			// Copy the input vector
			vec x = d->get(i);
Laurent Belcour's avatar
Laurent Belcour committed
62 63 64
			params::convert(&x[0], d->parametrization(), f->parametrization(), &temp[0]);

			vec y = f->value(temp);
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

			for(int j=0; j<d->dimY(); ++j)
			{
				x[d->dimX() + j] = y[j];
			}

			d->set(x);
		}	

		d->save(args["output"]);
	}	
	else
	{
		std::cerr << "<<ERROR>> cannot import function or export data" << std::endl ;
	}

	return 0 ;
}