Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
alta
alta
Commits
7f863e66
Commit
7f863e66
authored
Aug 22, 2013
by
Laurent Belcour
Browse files
Adding the parsing of the function input to allow for vector functions.
parent
35018597
Changes
7
Hide whitespace changes
Inline
Side-by-side
sources/core/args.h
View file @
7f863e66
...
...
@@ -25,13 +25,11 @@ class arguments
{
}
arguments
(
int
argc
,
char
**
const
argv
)
{
std
::
string
key
;
std
::
string
data
;
{
for
(
int
i
=
0
;
i
<
argc
;
++
i
)
{
std
::
string
temp
(
argv
[
i
])
;
std
::
string
data
;
std
::
string
temp
(
argv
[
i
])
;
std
::
string
key
,
data
;
if
(
temp
.
compare
(
0
,
2
,
"--"
)
==
0
)
{
...
...
@@ -70,6 +68,23 @@ class arguments
return
false
;
}
}
//! \brief is the data at the given key in a vector format?
//! No matter the type of the data, this function will test is the
//! mapped string is of type "[ .... ]".
//! It returns false if there is no associated entry.
bool
is_vec
(
const
std
::
string
&
key
)
const
{
if
(
_map
.
count
(
key
)
>
0
)
{
return
_map
.
find
(
key
)
->
second
[
0
]
==
'['
;
}
else
{
return
false
;
}
}
//! \brief access the element stored value
std
::
string
operator
[](
const
std
::
string
&
key
)
const
{
...
...
@@ -131,13 +146,14 @@ class arguments
if
(
ppos
!=
std
::
string
::
npos
)
{
res
[
i
]
=
atof
(
s
.
substr
(
pos
,
ppos
).
c_str
());
res
[
i
]
=
atof
(
s
.
substr
(
pos
,
ppos
-
pos
).
c_str
());
pos
=
ppos
+
1
;
++
i
;
}
else
{
res
[
i
]
=
atof
(
s
.
substr
(
pos
,
ppos
-
1
).
c_str
());
std
::
string
temp
=
s
.
substr
(
pos
,
std
::
string
::
npos
);
res
[
i
]
=
atof
(
temp
.
substr
(
0
,
temp
.
size
()
-
1
).
c_str
());
pos
=
ppos
;
++
i
;
}
...
...
@@ -154,6 +170,39 @@ class arguments
return
res
;
}
std
::
vector
<
std
::
string
>
get_vec
(
const
std
::
string
&
key
)
const
{
std
::
vector
<
std
::
string
>
res
;
if
(
_map
.
count
(
key
)
>
0
)
{
std
::
string
s
=
_map
.
find
(
key
)
->
second
;
std
::
cout
<<
s
<<
std
::
endl
;
if
(
s
[
0
]
==
'['
)
// Is an array of type [a, b, c]
{
int
i
=
0
;
size_t
pos
=
1
;
while
(
pos
!=
std
::
string
::
npos
)
{
size_t
ppos
=
s
.
find
(
','
,
pos
);
if
(
ppos
!=
std
::
string
::
npos
)
{
res
.
push_back
(
s
.
substr
(
pos
,
ppos
-
pos
));
pos
=
ppos
+
1
;
}
else
{
std
::
string
temp
=
s
.
substr
(
pos
,
std
::
string
::
npos
);
res
.
push_back
(
temp
.
substr
(
0
,
temp
.
size
()
-
1
));
pos
=
ppos
;
}
}
}
}
return
res
;
}
private:
// data
std
::
map
<
std
::
string
,
std
::
string
>
_map
;
...
...
sources/core/plugins_manager.cpp
View file @
7f863e66
...
...
@@ -194,13 +194,11 @@ fitter* plugins_manager::get_fitter()
#endif
}
// Get instances of the function, the data and the
// fitter, select one based on the name. Return null
// if no one exist.
//
function
*
plugins_manager
::
get_function
(
const
std
::
string
&
n
)
//! 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
)
{
if
(
n
.
empty
(
))
if
(
!
args
.
is_defined
(
"func"
))
{
#ifdef DEBUG
std
::
cout
<<
"<<DEBUG>> no function plugin specified, returning a rational function"
<<
std
::
endl
;
...
...
@@ -208,46 +206,64 @@ function* plugins_manager::get_function(const std::string& n)
return
new
rational_function
();
}
#ifdef USING_STATIC
/*
std::string file;
if(n[0] == '.')
{
file = n.substr(1, n.size()-1);
}
else
{
file = n;
}
QString path = QDir::currentPath() + QString(file.c_str()) ;
FunctionPrototype myFunction = open_library<FunctionPrototype>(path.toStdString(), "provide_function");
*/
FunctionPrototype
myFunction
=
open_library
<
FunctionPrototype
>
(
n
,
"provide_function"
);
if
(
myFunction
!=
NULL
)
if
(
args
.
is_vec
(
"func"
))
{
#ifdef DEBUG
std
::
cout
<<
"<<DEBUG>> using function provider in file
\"
"
<<
n
<<
"
\"
"
<<
std
::
endl
;
#endif
return
myFunction
();
std
::
vector
<
std
::
string
>
args_vec
=
args
.
get_vec
(
"func"
);
// Treating the case []
if
(
args_vec
.
size
()
==
0
)
{
return
NULL
;
}
//! \todo create a <em>compound</em> class to store multiple
//! functions in it.
//! For each args_vec element, create a function object and add
//! it to the compound one.
std
::
string
n
=
args_vec
[
0
];
std
::
vector
<
std
::
string
>
cmd_vec
;
cmd_vec
.
push_back
(
"--func"
);
std
::
stringstream
stream
(
n
);
while
(
stream
.
good
())
{
std
::
string
temp
;
stream
>>
temp
;
cmd_vec
.
push_back
(
temp
);
}
int
argc
=
cmd_vec
.
size
();
char
*
argv
[
argc
];
for
(
int
i
=
0
;
i
<
argc
;
++
i
)
{
argv
[
i
]
=
&
cmd_vec
[
i
][
0
];
}
const
arguments
current_args
(
argc
,
argv
);
return
get_function
(
current_args
);
//! return the compound class
}
else
{
std
::
cerr
<<
"<<ERROR>> no function provider found in file
\"
"
<<
n
<<
"
\"
"
<<
std
::
endl
;
return
new
rational_function
()
;
}
#else
if
(
_functions
.
count
(
n
)
==
0
)
{
return
new
rational_function
()
;
}
else
{
return
_functions
.
find
(
n
)
->
second
;
}
std
::
string
filename
=
args
[
"func"
];
FunctionPrototype
myFunction
=
open_library
<
FunctionPrototype
>
(
filename
,
"provide_function"
);
if
(
myFunction
!=
NULL
)
{
#ifdef DEBUG
std
::
cout
<<
"<<DEBUG>> using function provider in file
\"
"
<<
filename
<<
"
\"
"
<<
std
::
endl
;
#endif
return
myFunction
();
}
else
{
std
::
cerr
<<
"<<ERROR>> no function provider found in file
\"
"
<<
filename
<<
"
\"
"
<<
std
::
endl
;
return
new
rational_function
()
;
}
}
}
data
*
plugins_manager
::
get_data
(
const
std
::
string
&
n
)
{
...
...
@@ -259,22 +275,6 @@ data* plugins_manager::get_data(const std::string& n)
return
new
vertical_segment
();
}
#ifdef USING_STATIC
/*
std::string file;
if(n[0] == '.')
{
file = n.substr(1, n.size()-1);
}
else
{
file = n;
}
QString path = QDir::currentPath() + QString(file.c_str()) ;
DataPrototype myData = open_library<DataPrototype>(path.toStdString(), "provide_data");
*/
DataPrototype
myData
=
open_library
<
DataPrototype
>
(
n
,
"provide_data"
);
if
(
myData
!=
NULL
)
{
...
...
@@ -288,17 +288,6 @@ data* plugins_manager::get_data(const std::string& n)
std
::
cerr
<<
"<<ERROR>> no data provider found in file
\"
"
<<
n
<<
"
\"
"
<<
std
::
endl
;
return
new
vertical_segment
()
;
}
#else
if
(
_functions
.
count
(
n
)
==
0
)
{
return
new
vertical_segment
()
;
}
else
{
return
_datas
.
find
(
n
)
->
second
;
}
#endif
}
fitter
*
plugins_manager
::
get_fitter
(
const
std
::
string
&
n
)
{
...
...
@@ -310,23 +299,7 @@ fitter* plugins_manager::get_fitter(const std::string& n)
return
NULL
;
}
#ifdef USING_STATIC
/*
std::string file;
if(n[0] == '.')
{
file = n.substr(1, n.size()-1);
}
else
{
file = n;
}
QString path = QDir::currentPath() + QString(file.c_str()) ;
FitterPrototype myFitter = open_library<FitterPrototype>(path.toStdString(), "provide_fitter");
*/
FitterPrototype
myFitter
=
open_library
<
FitterPrototype
>
(
n
,
"provide_fitter"
);
FitterPrototype
myFitter
=
open_library
<
FitterPrototype
>
(
n
,
"provide_fitter"
);
if
(
myFitter
!=
NULL
)
{
#ifdef DEBUG
...
...
@@ -339,20 +312,8 @@ fitter* plugins_manager::get_fitter(const std::string& n)
std
::
cerr
<<
"<<ERROR>> no fitter provider found in file
\"
"
<<
n
<<
"
\"
"
<<
std
::
endl
;
return
NULL
;
}
#else
if
(
_fitters
.
count
(
n
)
==
0
)
{
return
NULL
;
}
else
{
#ifdef DEBUG
std
::
cout
<<
"<<DEBUG>> using
\"
"
<<
n
<<
"
\"
"
<<
std
::
endl
;
#endif
return
_fitters
.
find
(
n
)
->
second
;
}
#endif
}
void
plugins_manager
::
check_compatibility
(
data
*&
d
,
function
*&
f
,
const
arguments
&
args
)
{
...
...
sources/core/plugins_manager.h
View file @
7f863e66
#pragma once
#pragma once
#include <map>
#include <string>
#include "args.h"
#include "function.h"
#include "data.h"
#include "fitter.h"
...
...
@@ -45,7 +46,7 @@ class plugins_manager
#ifdef USING_STATIC
static
#endif
function
*
get_function
(
const
std
::
string
&
n
)
;
function
*
get_function
(
const
arguments
&
args
)
;
//! \brief get an instance of the data that is defined in the plugin with
//! filename n. Return null if no one exist.
...
...
sources/softs/brdf2data/main.cpp
View file @
7f863e66
...
...
@@ -51,7 +51,7 @@ int main(int argc, char** argv)
d
=
manager
.
get_data
(
args
[
"data"
])
;
function
*
f
=
NULL
;
f
=
manager
.
get_function
(
args
[
"func"
]
);
f
=
manager
.
get_function
(
args
);
f
->
load
(
args
[
"input"
]);
// Modify function or data to provide coherent
...
...
sources/softs/brdf2gnuplot/main.cpp
View file @
7f863e66
...
...
@@ -34,16 +34,7 @@ int main(int argc, char** argv)
return
1
;
}
function
*
f
=
NULL
;
if
(
args
.
is_defined
(
"func"
))
{
std
::
cout
<<
"<<INFO>> Using plugin function
\"
"
<<
args
[
"func"
]
<<
"
\"
"
<<
std
::
endl
;
f
=
manager
.
get_function
(
args
[
"func"
])
;
}
else
{
f
=
manager
.
get_function
()
;
}
function
*
f
=
manager
.
get_function
(
args
)
;
data
*
d
=
NULL
;
if
(
args
.
is_defined
(
"data"
))
...
...
@@ -72,7 +63,7 @@ int main(int argc, char** argv)
// Create output file
std
::
ofstream
file
(
args
[
"output"
].
c_str
(),
std
::
ios_base
::
trunc
);
if
(
d
!=
NULL
)
if
(
d
!=
NULL
)
{
for
(
int
i
=
0
;
i
<
d
->
size
();
++
i
)
{
...
...
sources/softs/data2brdf/main.cpp
View file @
7f863e66
...
...
@@ -47,10 +47,17 @@ int main(int argc, char** argv)
// if(fitters.size() > 0 && datas.size() > 0 && functions.size() > 0)
{
fit
->
set_parameters
(
args
)
;
function
*
f
=
plugins_manager
::
get_function
(
args
[
"func"
]);
function
*
f
=
plugins_manager
::
get_function
(
args
);
data
*
d
=
plugins_manager
::
get_data
(
args
[
"data"
]);
d
->
load
(
args
[
"input"
],
args
);
if
(
f
==
NULL
||
d
==
NULL
)
{
std
::
cerr
<<
"<<ERROR>> no function or data object correctly defined"
<<
std
::
endl
;
return
1
;
}
// Check the compatibility between the data and the function
plugins_manager
::
check_compatibility
(
d
,
f
,
args
);
...
...
sources/softs/data2moments/main.cpp
View file @
7f863e66
...
...
@@ -84,7 +84,7 @@ int main(int argc, char** argv)
for
(
int
i
=
0
;
i
<
d
->
dimY
();
++
i
)
{
double
val
=
x
[
i
]
*
cos
(
in_angle
[
2
]);
double
val
=
x
[
i
]
*
cos
(
in_angle
[
2
]);
rawm0
[
i
]
+=
val
;
rawm1
[
i
]
+=
theta_out
*
val
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment