Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
alta
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alta
alta
Commits
df821dba
Commit
df821dba
authored
Aug 23, 2013
by
Laurent Belcour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding save header and load header for functions
parent
4923d85e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
145 additions
and
87 deletions
+145
-87
sources/core/args.h
sources/core/args.h
+53
-0
sources/core/function.h
sources/core/function.h
+51
-2
sources/core/plugins_manager.cpp
sources/core/plugins_manager.cpp
+2
-34
sources/plugins/nonlinear_fresnel_schlick/function.cpp
sources/plugins/nonlinear_fresnel_schlick/function.cpp
+28
-24
sources/plugins/nonlinear_fresnel_schlick/function.h
sources/plugins/nonlinear_fresnel_schlick/function.h
+11
-27
No files found.
sources/core/args.h
View file @
df821dba
#pragma once
#include <string>
#include <sstream>
#include <map>
#include <cstdlib>
#include <iostream>
...
...
@@ -223,6 +224,58 @@ class arguments
return
res
;
}
//! \brief get the reconstructed command line arguments (without
//! the executable name
std
::
string
get_cmd
()
const
{
std
::
string
cmd
;
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
it
=
_map
.
begin
();
for
(;
it
!=
_map
.
end
();
it
++
)
{
cmd
.
append
(
it
->
first
);
cmd
.
append
(
" "
);
cmd
.
append
(
it
->
second
);
}
return
cmd
;
}
//! \brief Create an argument object from a string describing a command
//! line.
static
arguments
create_arguments
(
const
std
::
string
&
n
)
{
std
::
vector
<
std
::
string
>
cmd_vec
;
std
::
stringstream
stream
(
n
);
#ifdef DEBUG_ARGS
std
::
cout
<<
"<<DEBUG>> create argument vector: ["
;
#endif
while
(
stream
.
good
())
{
std
::
string
temp
;
stream
>>
temp
;
#ifdef DEBUG_ARGS
std
::
cout
<<
temp
<<
", "
;
#endif
cmd_vec
.
push_back
(
temp
);
}
#ifdef DEBUG_ARGS
std
::
cout
<<
"]"
<<
std
::
endl
;
#endif
int
argc
=
cmd_vec
.
size
();
char
*
argv
[
argc
];
for
(
int
i
=
0
;
i
<
argc
;
++
i
)
{
argv
[
i
]
=
&
cmd_vec
[
i
][
0
];
}
arguments
current_args
(
argc
,
argv
);
return
current_args
;
}
private:
// data
std
::
map
<
std
::
string
,
std
::
string
>
_map
;
...
...
sources/core/function.h
View file @
df821dba
...
...
@@ -69,7 +69,7 @@ class function : public parametrized
}
else
{
save
(
filename
)
;
save
_alta
(
filename
,
args
)
;
}
}
...
...
@@ -104,7 +104,7 @@ class function : public parametrized
protected:
// function
//! \brief Standard saving function.
virtual
void
save
(
const
std
::
string
&
filename
)
const
virtual
void
save
_alta
(
const
std
::
string
&
filename
,
const
arguments
&
args
)
const
{
NOT_IMPLEMENTED
();
}
...
...
@@ -156,6 +156,55 @@ class function : public parametrized
NOT_IMPLEMENTED
();
}
//! \brief parse the header of the file and return the corresponding
//! arguments and associate stream
void
load_header
(
const
std
::
string
&
filename
,
arguments
&
args
,
std
::
ifstream
&
file
)
{
file
.
open
(
filename
.
c_str
())
;
if
(
!
file
.
is_open
())
{
std
::
cerr
<<
"<<ERROR>> unable to open file
\"
"
<<
filename
<<
"
\"
"
<<
std
::
endl
;
throw
;
}
while
(
file
.
peek
()
==
'#'
)
{
std
::
string
line
;
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
(
5
,
std
::
string
::
npos
));
}
}
}
void
save_header
(
const
std
::
string
&
filename
,
arguments
&
args
,
std
::
ofstream
&
file
)
{
file
.
open
(
filename
.
c_str
())
;
if
(
!
file
.
is_open
())
{
std
::
cerr
<<
"<<ERROR>> unable to open file
\"
"
<<
filename
<<
"
\"
"
<<
std
::
endl
;
throw
;
}
file
<<
"#CMD "
<<
args
.
get_cmd
()
<<
std
::
endl
;
file
<<
"#DIM "
<<
_nX
<<
" "
<<
_nY
<<
std
::
endl
;
file
<<
"#PARAM_IN "
<<
params
::
get_name
(
input_parametrization
())
<<
std
::
endl
;
//file << "#PARAM_OUT " << params::get_name(output_parametrization()) << std::endl;
file
<<
std
::
endl
;
}
public:
// methods
//! \brief L2 norm to data.
...
...
sources/core/plugins_manager.cpp
View file @
df821dba
...
...
@@ -194,38 +194,6 @@ fitter* plugins_manager::get_fitter()
#endif
}
arguments
create_arguments
(
const
std
::
string
&
n
)
{
std
::
vector
<
std
::
string
>
cmd_vec
;
std
::
stringstream
stream
(
n
);
#ifdef DEBUG_ARGS
std
::
cout
<<
"<<DEBUG>> create argument vector: ["
;
#endif
while
(
stream
.
good
())
{
std
::
string
temp
;
stream
>>
temp
;
#ifdef DEBUG_ARGS
std
::
cout
<<
temp
<<
", "
;
#endif
cmd_vec
.
push_back
(
temp
);
}
#ifdef DEBUG_ARGS
std
::
cout
<<
"]"
<<
std
::
endl
;
#endif
int
argc
=
cmd_vec
.
size
();
char
*
argv
[
argc
];
for
(
int
i
=
0
;
i
<
argc
;
++
i
)
{
argv
[
i
]
=
&
cmd_vec
[
i
][
0
];
}
arguments
current_args
(
argc
,
argv
);
return
current_args
;
}
//! 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
)
...
...
@@ -259,7 +227,7 @@ function* plugins_manager::get_function(const arguments& args)
std
::
string
n
(
"--func "
);
n
.
append
(
args_vec
[
0
]);
func
=
get_function
(
create_arguments
(
n
));
func
=
get_function
(
arguments
::
create_arguments
(
n
));
//! return the compound class
...
...
@@ -317,7 +285,7 @@ function* plugins_manager::get_function(const arguments& args)
}
}
fresnel
*
func_fres
=
dynamic_cast
<
fresnel
*>
(
get_function
(
create_arguments
(
n
)));
fresnel
*
func_fres
=
dynamic_cast
<
fresnel
*>
(
get_function
(
arguments
::
create_arguments
(
n
)));
func_fres
->
setBase
(
nl_func
);
func
=
dynamic_cast
<
function
*>
(
func_fres
);
}
...
...
sources/plugins/nonlinear_fresnel_schlick/function.cpp
View file @
df821dba
...
...
@@ -14,12 +14,14 @@ ALTA_DLL_EXPORT function* provide_function()
return
new
schlick
();
}
//
Overload the function operator
v
ec
schlick
::
operator
()(
const
vec
&
x
)
const
//
! Load function specific files
v
oid
schlick
::
load
(
const
std
::
string
&
filename
)
{
return
value
(
x
);
std
::
cerr
<<
"Cannot load a Schlick file."
<<
std
::
endl
;
throw
;
}
vec
schlick
::
value
(
const
vec
&
x
)
const
vec
schlick
::
fresnelValue
(
const
vec
&
x
)
const
{
vec
res
(
_nY
);
for
(
int
i
=
0
;
i
<
_nY
;
++
i
)
...
...
@@ -30,37 +32,39 @@ vec schlick::value(const vec& x) const
return
res
;
}
//! Load function specific files
void
schlick
::
load
(
const
std
::
string
&
filename
)
{
std
::
cerr
<<
"Cannot load a Schlick file."
<<
std
::
endl
;
throw
;
}
//! Number of parameters to this non-linear function
int
schlick
::
nbParameters
()
const
//! \brief Number of parameters to this non-linear function
int
schlick
::
nbFresnelParameters
()
const
{
return
0
;
return
dimY
()
;
}
//! Get the vector of parameters for the function
vec
schlick
::
p
arameters
()
const
//!
\brief
Get the vector of parameters for the function
vec
schlick
::
getFresnelP
arameters
()
const
{
vec
r
(
0
);
return
r
;
vec
p
(
1
);
p
[
0
]
=
R
;
return
p
;
}
//! Update the vector of parameters for the function
void
schlick
::
setParameters
(
const
vec
&
p
)
//!
\brief
Update the vector of parameters for the function
void
schlick
::
set
Fresnel
Parameters
(
const
vec
&
p
)
{
R
=
p
[
0
];
}
//!
Obtain the derivatives of the function with respect to the
//!
\brief Obtain the derivatives of the function with respect to the
//! parameters.
vec
schlick
::
p
arametersJacobian
(
const
vec
&
x
)
const
vec
schlick
::
getFresnelP
arametersJacobian
(
const
vec
&
x
)
const
{
vec
r
(
0
);
return
r
;
const
int
nY
=
dimY
();
vec
jac
(
nY
);
for
(
int
i
=
0
;
i
<
nY
;
++
i
)
{
jac
[
i
]
=
1.0
-
pow
(
1.0
-
clamp
(
x
[
0
],
0.0
,
1.0
),
5.0
);
}
return
jac
;
}
...
...
sources/plugins/nonlinear_fresnel_schlick/function.h
View file @
df821dba
...
...
@@ -12,51 +12,35 @@
#include <core/common.h>
class
schlick
:
public
nonlinear_function
class
schlick
:
public
fresnel
{
public:
// methods
// Overload the function operator
virtual
vec
operator
()(
const
vec
&
x
)
const
;
virtual
vec
value
(
const
vec
&
x
)
const
;
//! \brief Boostrap the function by defining the diffuse term
virtual
void
bootstrap
(
const
data
*
d
,
const
arguments
&
args
);
//! \brief Load function specific files
virtual
void
load
(
const
std
::
string
&
filename
)
;
protected:
// methods
virtual
vec
fresnelValue
(
const
vec
&
x
)
const
;
//! \brief Number of parameters to this non-linear function
virtual
int
nbParameters
()
const
;
virtual
int
nb
Fresnel
Parameters
()
const
;
//! \brief Get the vector of parameters for the function
virtual
vec
p
arameters
()
const
;
virtual
vec
getFresnelP
arameters
()
const
;
//! \brief Update the vector of parameters for the function
virtual
void
setParameters
(
const
vec
&
p
)
;
virtual
void
set
Fresnel
Parameters
(
const
vec
&
p
)
;
//! \brief Obtain the derivatives of the function with respect to the
//! parameters.
virtual
vec
parametersJacobian
(
const
vec
&
x
)
const
;
//! \brief Provide the dimension of the input space of the function
inline
virtual
int
dimX
()
const
{
return
1
;
}
inline
virtual
int
dimY
()
const
{
return
1
;
}
//! \brief Provide the parametrization of the input space of the function.
//! For this one, we fix that the parametrization is in THETAD_PHID
virtual
params
::
input
parametrization
()
const
;
virtual
void
setParametrization
(
params
::
input
new_param
);
protected:
// methods
virtual
vec
getFresnelParametersJacobian
(
const
vec
&
x
)
const
;
private:
// data
...
...
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