Commit bccc682f authored by Laurent Belcour's avatar Laurent Belcour

Adding the loading of ALTA file from the plugin manager

parent 0791b93a
......@@ -81,7 +81,7 @@ ALTA library assumes that all functions are exported using the following convent
Example of a .function file for a single Lafortune lobe without any diffuse:
\verbatim
#ALTA_HEADER_START
#ALTA_HEADER_DATA
#CMD lafortune --nb_lobes 1 --isotrope
#DIM 2 1
#PARAM_IN ROMEIRO_TH_TD
......@@ -98,7 +98,7 @@ For multiple BRDFs lobes (when you want to add a diffuse for example), you need
specify it into the command line. The different parameters are outputed sequentially
into the file:
\verbatim
#ALTA_HEADER_START
#ALTA_HEADER_FUNC
#CMD [diffuse, lafortune --nb_lobes 1 --isotrope, phong --fresnel schlick]
#DIM 2 3
#PARAM_IN ROMEIRO_TH_TD
......
......@@ -194,6 +194,64 @@ fitter* plugins_manager::get_fitter()
#endif
}
//! \brief load a function from the ALTA input file.
function* plugins_manager::get_function(const std::string& filename)
{
std::ifstream file;
file.open(filename.c_str()) ;
if(!file.is_open())
{
std::cerr << "<<ERROR>> unable to open file \"" << filename << "\"" << std::endl ;
throw ;
}
// Parameters of the function object
int nX, nY;
arguments args;
// Test for the first line of the file. Should be a ALTA FUNC HEADER
std::string line ;
std::getline(file, line) ;
if(line != "#ALTA FUNC HEADER")
{
std::cerr << "<<ERROR>> this is not a function file" << std::endl;
}
// Parse the header for the function command line and the dimension
// of the function
while(line != "#ALTA HEADER END")
{
std::getline(file, line) ;
std::stringstream linestream(line) ;
linestream.ignore(1) ;
std::string comment ;
linestream >> comment ;
if(comment == std::string("DIM"))
{
linestream >> nX >> nY ;
}
else if(comment == std::string("CMD"))
{
args = arguments::create_arguments(line.substr(4, std::string::npos));
}
}
// Create the function from the command line
function* f = get_function(args);
f->setDimX(nX);
f->setDimY(nY);
// Load the function part from the file object
//f->load(file);
return f;
}
//! Get an instance of the function selected based on the name <em>n</em>.
//! Return NULL if no one exist.
function* plugins_manager::get_function(const arguments& args)
......@@ -219,18 +277,30 @@ function* plugins_manager::get_function(const arguments& args)
return NULL;
}
//! \todo create a <em>compound</em> class to store multiple
//! create a <em>compound</em> class to store multiple
//! functions in it.
compound_function* compound = new compound_function();
//! For each args_vec element, create a function object and add
//! it to the compound one.
std::string n("--func ");
n.append(args_vec[0]);
func = get_function(arguments::create_arguments(n));
//! return the compound class
for(int i=0; i<args_vec.size(); ++i)
{
std::string n("--func ");
n.append(args_vec[i]);
function* f = get_function(arguments::create_arguments(n));
if(dynamic_cast<nonlinear_function*>(f) == NULL)
{
std::cerr << "<<ERROR>> only non-linear function care compatible with a compound" << std::endl;
}
else
{
compound->push_back(dynamic_cast<nonlinear_function*>(f));
}
}
//! return the compound class
func = compound;
}
else
{
......
......@@ -46,7 +46,13 @@ class plugins_manager
#ifdef USING_STATIC
static
#endif
function* get_function(const arguments& args) ;
function* get_function(const arguments& args) ;
//! \brief load a function from the ALTA input file.
#ifdef USING_STATIC
static
#endif
function* get_function(const std::string& filename);
//! \brief get an instance of the data that is defined in the plugin with
//! filename n. Return null if no one exist.
......
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