main.cpp 3.31 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
#include <core/args.h>
#include <core/data.h>
Laurent Belcour's avatar
core    
Laurent Belcour committed
11
#include <core/vertical_segment.h>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#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
30
		std::cout << "Usage: brdf2data --input brdf.file --output data.file [--data exporter.so --data-file data.file]" << std::endl ;
31
32
33
34
35
36
37
38
39
40
41
42
43
		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 ;
44
45
46
47
48
49
50
51
52
53
54
		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 ;
	}
55
	if(! args.is_defined("data") && ! args.is_defined("data-file")) {
56
57
58
		std::cerr << "<<ERROR>> the data exporter is not defined" << std::endl ;
		return 1 ;
	}
Laurent Belcour's avatar
Merging    
Laurent Belcour committed
59
60
	
	// Get the associated data object and load the file is any
61
	data* d = NULL ;
Laurent Belcour's avatar
Merging    
Laurent Belcour committed
62
63
64
65
66
	d = plugins_manager::get_data(args["data"]) ;
	if(args.is_defined("data-file"))
	{
		d->load(args["data-file"]);
	}
67

Laurent Belcour's avatar
core    
Laurent Belcour committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    // Get the output object. In the case where it is not a VS file, we use
    // the load object.
    data* d_out = NULL;
    if(dynamic_cast<vertical_segment*>(d) == NULL)
    {
        d_out = d;
    }
    else
    {
        d_out = new vertical_segment();
        d_out->setDimX(d->dimX());
        d_out->setDimY(d->dimY());
        d_out->setParametrization(d->input_parametrization());
    }

Laurent Belcour's avatar
Merging    
Laurent Belcour committed
83
	// Get the function file
84
	function* f = NULL;
85
	f = plugins_manager::get_function(args["input"]);
86
87
88
89
	if(f == NULL)
	{
		return 1;
	}
90
91
92

	if(d != NULL && f != NULL)
	{
Laurent Belcour's avatar
Laurent Belcour committed
93
		vec temp(f->dimX());
94
95
96
97
		for(int i=0; i<d->size(); ++i)
		{
			// Copy the input vector
			vec x = d->get(i);
Laurent Belcour's avatar
Laurent Belcour committed
98
99
100
			params::convert(&x[0], d->parametrization(), f->parametrization(), &temp[0]);

			vec y = f->value(temp);
101
102
103
104
105
106

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

Laurent Belcour's avatar
core    
Laurent Belcour committed
107
            d_out->set(x);
108
109
		}	

Laurent Belcour's avatar
core    
Laurent Belcour committed
110
        d_out->save(args["output"]);
111
112
113
114
115
116
117
118
	}	
	else
	{
		std::cerr << "<<ERROR>> cannot import function or export data" << std::endl ;
	}

	return 0 ;
}