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
e5a96d3a
Commit
e5a96d3a
authored
Sep 05, 2013
by
Laurent Belcour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing the command line argument class to handle vector of strings
parent
fb08e7eb
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
67 deletions
+101
-67
sources/core/args.h
sources/core/args.h
+43
-36
sources/core/common.h
sources/core/common.h
+2
-0
sources/core/plugins_manager.cpp
sources/core/plugins_manager.cpp
+17
-17
sources/plugins/nonlinear_fitter_ceres/fitter.cpp
sources/plugins/nonlinear_fitter_ceres/fitter.cpp
+12
-8
sources/plugins/nonlinear_fresnel_schlick/function.cpp
sources/plugins/nonlinear_fresnel_schlick/function.cpp
+1
-1
sources/plugins/nonlinear_levenberg_eigen/fitter.cpp
sources/plugins/nonlinear_levenberg_eigen/fitter.cpp
+26
-5
No files found.
sources/core/args.h
View file @
e5a96d3a
...
...
@@ -26,52 +26,59 @@ class arguments
{
}
arguments
(
int
argc
,
char
**
const
argv
)
{
for
(
int
i
=
0
;
i
<
argc
;
++
i
)
{
std
::
string
temp
(
argv
[
i
])
;
std
::
string
key
,
data
;
{
for
(
int
i
=
0
;
i
<
argc
;
++
i
)
{
std
::
string
temp
(
argv
[
i
])
;
std
::
string
key
,
data
;
if
(
temp
.
compare
(
0
,
2
,
"--"
)
==
0
)
{
key
=
temp
.
substr
(
2
,
temp
.
size
()
-
2
)
;
if
(
temp
.
compare
(
0
,
2
,
"--"
)
==
0
)
{
//#define DEBUG_ARGS
key
=
temp
.
substr
(
2
,
temp
.
size
()
-
2
)
;
#ifdef DEBUG_ARGS
std
::
cout
<<
"<<DEBUG>> ("
<<
i
<<
")"
<<
key
<<
" -> [ "
;
std
::
cout
<<
"<<DEBUG>> ("
<<
i
<<
")"
<<
key
<<
" -> [ "
;
#endif
int
k
=
i
+
1
;
int
j
=
k
;
while
(
j
<
argc
)
{
if
(
++
i
<
argc
)
{
std
::
string
next
(
argv
[
j
])
;
if
(
next
[
0
]
==
'['
||
next
[
next
.
size
()
-
1
]
==
']'
||
next
.
compare
(
0
,
2
,
"--"
)
!=
0
)
{
if
(
j
!=
k
)
{
data
.
append
(
" "
);
std
::
string
next
(
argv
[
i
])
;
if
(
next
[
0
]
==
'['
&&
next
[
next
.
size
()
-
1
]
!=
']'
)
{
data
.
append
(
next
);
++
i
;
while
(
i
<
argc
&&
next
[
next
.
size
()
-
1
]
!=
']'
)
{
next
=
argv
[
i
]
;
data
.
append
(
" "
);
#ifdef DEBUG_ARGS
std
::
cout
<<
" "
;
std
::
cout
<<
" "
;
#endif
}
data
.
append
(
next
);
data
.
append
(
next
);
#ifdef DEBUG_ARGS
std
::
cout
<<
"("
<<
j
<<
")"
<<
next
;
std
::
cout
<<
"("
<<
i
<<
")"
<<
next
;
#endif
}
else
{
break
;
}
++
j
;
++
i
;
}
++
i
;
}
--
i
;
}
else
{
#ifdef DEBUG_ARGS
std
::
cout
<<
"]"
<<
std
::
endl
;
std
::
cout
<<
next
;
#endif
}
_map
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
key
,
data
))
;
}
}
data
.
append
(
next
);
}
}
#ifdef DEBUG_ARGS
std
::
cout
<<
"]"
<<
std
::
endl
;
#endif
}
_map
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
key
,
data
))
;
}
}
~
arguments
()
{
}
...
...
sources/core/common.h
View file @
e5a96d3a
...
...
@@ -235,6 +235,8 @@ double dot(const vec& a, const vec& b);
vec
product
(
const
vec
&
a
,
const
vec
&
b
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
vec
&
v
);
//! \brief locate the first index of value v in vector vec. Complexity in
//! O(n) is the worst case.
template
<
typename
T
>
int
is_in
(
std
::
vector
<
T
>
ve
,
T
v
)
...
...
sources/core/plugins_manager.cpp
View file @
e5a96d3a
...
...
@@ -282,23 +282,23 @@ function* plugins_manager::get_function(const arguments& args)
//! 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.
for
(
unsigned
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
));
}
}
//! For each args_vec element, create a function object and add
//! it to the compound one.
for
(
unsigned
int
i
=
0
;
i
<
args_vec
.
size
();
++
i
)
{
std
::
string
n
(
"--func "
);
n
.
append
(
args_vec
[
i
]);
arguments
temp_args
=
arguments
::
create_arguments
(
n
);
function
*
f
=
get_function
(
temp_args
);
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
;
...
...
sources/plugins/nonlinear_fitter_ceres/fitter.cpp
View file @
e5a96d3a
...
...
@@ -148,14 +148,18 @@ bool nonlinear_fitter_ceres::fit_data(const data* d, function* fit, const argume
}
// Solves the NL problem
ceres
::
Solver
::
Summary
summary
;
ceres
::
Solve
(
options
,
&
problem
,
&
summary
);
std
::
cout
<<
summary
.
BriefReport
()
<<
std
::
endl
;
std
::
cout
<<
"<<INFO>> found parameters: "
<<
p
<<
std
::
endl
;
nf
->
setParameters
(
p
);
return
true
;
// Solves the NL problem
ceres
::
Solver
::
Summary
summary
;
ceres
::
Solve
(
options
,
&
problem
,
&
summary
);
#ifdef DEBUG
std
::
cout
<<
summary
.
BriefReport
()
<<
std
::
endl
;
#endif
std
::
cout
<<
"<<INFO>> found parameters: "
<<
p
<<
std
::
endl
;
nf
->
setParameters
(
p
);
return
true
;
}
void
nonlinear_fitter_ceres
::
set_parameters
(
const
arguments
&
args
)
...
...
sources/plugins/nonlinear_fresnel_schlick/function.cpp
View file @
e5a96d3a
...
...
@@ -127,5 +127,5 @@ vec schlick::getFresnelParametersJacobian(const vec& x) const
void
schlick
::
fresnelBootstrap
(
const
data
*
d
,
const
arguments
&
args
)
{
R
=
0.
1
;
R
=
0.
5
;
}
sources/plugins/nonlinear_levenberg_eigen/fitter.cpp
View file @
e5a96d3a
...
...
@@ -22,8 +22,8 @@ ALTA_DLL_EXPORT fitter* provide_fitter()
struct
EigenFunctor
:
Eigen
::
DenseFunctor
<
double
>
{
EigenFunctor
(
nonlinear_function
*
f
,
const
data
*
d
)
:
DenseFunctor
<
double
>
(
f
->
nbParameters
(),
d
->
dimY
()
*
d
->
size
()),
_f
(
f
),
_d
(
d
)
EigenFunctor
(
nonlinear_function
*
f
,
const
data
*
d
,
bool
use_cosine
)
:
DenseFunctor
<
double
>
(
f
->
nbParameters
(),
d
->
dimY
()
*
d
->
size
()),
_f
(
f
),
_d
(
d
),
_cosine
(
use_cosine
)
{
#ifndef DEBUG
std
::
cout
<<
"<<DEBUG>> constructing an EigenFunctor for n="
<<
inputs
()
<<
" parameters and m="
<<
values
()
<<
" points"
<<
std
::
endl
;
...
...
@@ -45,12 +45,21 @@ struct EigenFunctor: Eigen::DenseFunctor<double>
{
vec
_x
=
_d
->
get
(
s
);
// Compute the cosine factor. Only update the constant if the flag
// is set in the object.
double
cos
=
1.0
;
if
(
_cosine
)
{
double
cart
[
6
];
params
::
convert
(
&
_x
[
0
],
_d
->
input_parametrization
(),
params
::
CARTESIAN
,
cart
);
cos
=
cart
[
5
];
}
vec
_di
=
vec
(
_f
->
dimY
());
for
(
int
i
=
0
;
i
<
_f
->
dimY
();
++
i
)
_di
[
i
]
=
_x
[
_f
->
dimX
()
+
i
];
// Should add the resulting vector completely
vec
_y
=
_di
-
(
*
_f
)(
_x
);
vec
_y
=
_di
-
cos
*
(
*
_f
)(
_x
);
for
(
int
i
=
0
;
i
<
_f
->
dimY
();
++
i
)
y
(
i
*
_d
->
size
()
+
s
)
=
_y
[
i
];
...
...
@@ -75,6 +84,15 @@ struct EigenFunctor: Eigen::DenseFunctor<double>
// Get the position
vec
xi
=
_d
->
get
(
s
);
// Compute the cosine factor. Only update the constant if the flag
// is set in the object.
double
cos
=
1.0
;
if
(
_cosine
)
{
double
cart
[
6
];
params
::
convert
(
&
xi
[
0
],
_d
->
input_parametrization
(),
params
::
CARTESIAN
,
cart
);
cos
=
cart
[
5
];
}
// Get the associated jacobian
vec
_jac
=
_f
->
parametersJacobian
(
xi
);
...
...
@@ -88,7 +106,7 @@ struct EigenFunctor: Eigen::DenseFunctor<double>
// vector row
for
(
int
i
=
0
;
i
<
_f
->
dimY
();
++
i
)
{
fjac
(
i
*
_d
->
size
()
+
s
,
j
)
=
-
_jac
[
i
*
_f
->
nbParameters
()
+
j
];
fjac
(
i
*
_d
->
size
()
+
s
,
j
)
=
-
cos
*
_jac
[
i
*
_f
->
nbParameters
()
+
j
];
#ifdef DEBUG
temp
(
i
,
j
)
=
_jac
[
i
*
_f
->
nbParameters
()
+
j
];
#endif
...
...
@@ -108,6 +126,9 @@ struct EigenFunctor: Eigen::DenseFunctor<double>
nonlinear_function
*
_f
;
const
data
*
_d
;
// Flags
bool
_cosine
;
};
nonlinear_fitter_eigen
::
nonlinear_fitter_eigen
()
...
...
@@ -153,7 +174,7 @@ bool nonlinear_fitter_eigen::fit_data(const data* d, function* fit, const argume
x
[
i
]
=
nf_x
[
i
];
}
EigenFunctor
functor
(
nf
,
d
);
EigenFunctor
functor
(
nf
,
d
,
args
.
is_defined
(
"fit-with-cosine"
)
);
Eigen
::
LevenbergMarquardt
<
EigenFunctor
>
lm
(
functor
);
info
=
lm
.
minimize
(
x
);
...
...
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