main.cpp 2.86 KB
Newer Older
1
2
3
4
5
6
7
8
/*! \package brdf2data
 *  \ingroup commands
 *  \brief
 *  This command allows to convert a \ref function object to a \ref data 
 *  object. And to save the \ref data object in a file specified by the
 *  \ref data plugin.
 *  \details
 */
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#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
29
		std::cout << "Usage: brdf2data --input brdf.file --output data.file [--data exporter.so --data-file data.file]" << std::endl ;
30
31
32
33
34
35
36
37
38
39
40
41
42
		std::cout << "Convert a function object to a data object."<< std::endl ;
		std::cout << std::endl;
		std::cout << "Mandatory arguments:" << std::endl;
		std::cout << "  --input     [filename]" << std::endl;
		std::cout << "  --output    [filename]" << std::endl;
		std::cout << std::endl;
		std::cout << "Optional arguments:" << std::endl;
		std::cout << "  --data      [filename] Name of the data plugin used to save the output" << std::endl ;
		std::cout << "                         data file. If no plugin is defined, the data file" << std::endl ;
		std::cout << "                         will be load using ALTA format but require an" << std::endl;
		std::cout << "                         ALTA file as template." << std::endl ;
		std::cout << "  --data-file [filename] ALTA data file used as a template if no data" << std::endl ;
		std::cout << "                         plugin is specified to export data." << std::endl ;
43
44
45
46
47
48
49
50
51
52
53
		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 ;
	}
54
	if(! args.is_defined("data") && ! args.is_defined("data-file")) {
55
56
57
		std::cerr << "<<ERROR>> the data exporter is not defined" << std::endl ;
		return 1 ;
	}
Laurent Belcour's avatar
Merging    
Laurent Belcour committed
58
59
	
	// Get the associated data object and load the file is any
60
	data* d = NULL ;
Laurent Belcour's avatar
Merging    
Laurent Belcour committed
61
62
63
64
65
	d = plugins_manager::get_data(args["data"]) ;
	if(args.is_defined("data-file"))
	{
		d->load(args["data-file"]);
	}
66

Laurent Belcour's avatar
Merging    
Laurent Belcour committed
67
	// Get the function file
68
	function* f = NULL;
69
	f = plugins_manager::get_function(args["input"]);
70
71
72
73
	if(f == NULL)
	{
		return 1;
	}
74
75
76

	if(d != NULL && f != NULL)
	{
Laurent Belcour's avatar
Laurent Belcour committed
77
		vec temp(f->dimX());
78
79
80
81
		for(int i=0; i<d->size(); ++i)
		{
			// Copy the input vector
			vec x = d->get(i);
Laurent Belcour's avatar
Laurent Belcour committed
82
83
84
			params::convert(&x[0], d->parametrization(), f->parametrization(), &temp[0]);

			vec y = f->value(temp);
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

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