g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
solvers
dense
solver_dense.cpp
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, H. Strasdat, W. Burgard
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
7
// met:
8
//
9
// * Redistributions of source code must retain the above copyright notice,
10
// this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above copyright
12
// notice, this list of conditions and the following disclaimer in the
13
// documentation and/or other materials provided with the distribution.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
#include "g2o/config.h"
28
#include "
g2o/core/block_solver.h
"
29
#include "
g2o/core/optimization_algorithm_factory.h
"
30
#include "
g2o/core/optimization_algorithm_gauss_newton.h
"
31
#include "
g2o/core/optimization_algorithm_levenberg.h
"
32
#include "
g2o/core/solver.h
"
33
#include "
g2o/stuff/logger.h
"
34
#include "
linear_solver_dense.h
"
35
36
using namespace
std
;
37
38
namespace
g2o
{
39
namespace
{
40
template
<
int
p,
int
l>
41
std::unique_ptr<g2o::Solver> AllocateSolver() {
42
G2O_DEBUG
(
"Using DENSE poseDim {} landMarkDim {}"
, p, l);
43
return
std::make_unique<BlockSolverPL<p, l>>(
44
std::make_unique<
45
LinearSolverDense<typename BlockSolverPL<p, l>::PoseMatrixType
>>());
46
}
47
}
// namespace
48
49
static
OptimizationAlgorithm
*
createSolver
(
const
std::string& fullSolverName) {
50
static
const
std::map<std::string,
51
std::function<std::unique_ptr<g2o::Solver>()>>
52
solver_factories{
53
{
"dense"
, &AllocateSolver<-1, -1>},
54
{
"dense3_2"
, &AllocateSolver<3, 2>},
55
{
"dense6_3"
, &AllocateSolver<6, 3>},
56
{
"dense7_3"
, &AllocateSolver<7, 3>},
57
};
58
59
string
solverName = fullSolverName.substr(3);
60
auto
solverf = solver_factories.find(solverName);
61
if
(solverf == solver_factories.end())
return
nullptr
;
62
63
string
methodName = fullSolverName.substr(0, 2);
64
65
if
(methodName ==
"gn"
) {
66
return
new
OptimizationAlgorithmGaussNewton
(solverf->second());
67
}
else
if
(methodName ==
"lm"
) {
68
return
new
OptimizationAlgorithmLevenberg
(solverf->second());
69
}
70
71
return
nullptr
;
72
}
73
74
class
DenseSolverCreator
:
public
AbstractOptimizationAlgorithmCreator
{
75
public
:
76
explicit
DenseSolverCreator
(
const
OptimizationAlgorithmProperty
& p)
77
:
AbstractOptimizationAlgorithmCreator
(p) {}
78
virtual
OptimizationAlgorithm
*
construct
() {
79
return
createSolver
(
property
().name);
80
}
81
};
82
83
G2O_REGISTER_OPTIMIZATION_LIBRARY
(dense);
84
85
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
86
gn_dense,
new
DenseSolverCreator
(
OptimizationAlgorithmProperty
(
87
"gn_dense"
,
"Gauss-Newton: Dense solver (variable blocksize)"
,
88
"Dense"
,
false
, Eigen::Dynamic, Eigen::Dynamic)));
89
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
90
gn_dense3_2,
91
new
DenseSolverCreator
(
OptimizationAlgorithmProperty
(
92
"gn_dense3_2"
,
"Gauss-Newton: Dense solver (fixed blocksize)"
,
"Dense"
,
93
true
, 3, 2)));
94
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
95
gn_dense6_3,
96
new
DenseSolverCreator
(
OptimizationAlgorithmProperty
(
97
"gn_dense6_3"
,
"Gauss-Newton: Dense solver (fixed blocksize)"
,
"Dense"
,
98
true
, 6, 3)));
99
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
100
gn_dense7_3,
101
new
DenseSolverCreator
(
OptimizationAlgorithmProperty
(
102
"gn_dense7_3"
,
"Gauss-Newton: Dense solver (fixed blocksize)"
,
"Dense"
,
103
true
, 7, 3)));
104
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
105
lm_dense,
new
DenseSolverCreator
(
OptimizationAlgorithmProperty
(
106
"lm_dense"
,
"Levenberg: Dense solver (variable blocksize)"
,
107
"Dense"
,
false
, -1, -1)));
108
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
109
lm_dense3_2,
new
DenseSolverCreator
(
OptimizationAlgorithmProperty
(
110
"lm_dense3_2"
,
"Levenberg: Dense solver (fixed blocksize)"
,
111
"Dense"
,
true
, 3, 2)));
112
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
113
lm_dense6_3,
new
DenseSolverCreator
(
OptimizationAlgorithmProperty
(
114
"lm_dense6_3"
,
"Levenberg: Dense solver (fixed blocksize)"
,
115
"Dense"
,
true
, 6, 3)));
116
G2O_REGISTER_OPTIMIZATION_ALGORITHM
(
117
lm_dense7_3,
new
DenseSolverCreator
(
OptimizationAlgorithmProperty
(
118
"lm_dense7_3"
,
"Levenberg: Dense solver (fixed blocksize)"
,
119
"Dense"
,
true
, 7, 3)));
120
121
}
// namespace g2o
block_solver.h
g2o::AbstractOptimizationAlgorithmCreator::property
const OptimizationAlgorithmProperty & property() const
return the properties of the solver
Definition
optimization_algorithm_factory.h:60
g2o::AbstractOptimizationAlgorithmCreator::AbstractOptimizationAlgorithmCreator
AbstractOptimizationAlgorithmCreator(const OptimizationAlgorithmProperty &p)
Definition
optimization_algorithm_factory.cpp:39
g2o::DenseSolverCreator
Definition
solver_dense.cpp:74
g2o::DenseSolverCreator::construct
virtual OptimizationAlgorithm * construct()
allocate a solver operating on optimizer, re-implement for your creator
Definition
solver_dense.cpp:78
g2o::DenseSolverCreator::DenseSolverCreator
DenseSolverCreator(const OptimizationAlgorithmProperty &p)
Definition
solver_dense.cpp:76
g2o::LinearSolverDense
linear solver using dense cholesky decomposition
Definition
linear_solver_dense.h:46
g2o::OptimizationAlgorithmGaussNewton
Implementation of the Gauss Newton Algorithm.
Definition
optimization_algorithm_gauss_newton.h:41
g2o::OptimizationAlgorithmLevenberg
Implementation of the Levenberg Algorithm.
Definition
optimization_algorithm_levenberg.h:41
g2o::OptimizationAlgorithm
Generic interface for a non-linear solver operating on a graph.
Definition
optimization_algorithm.h:46
linear_solver_dense.h
G2O_DEBUG
#define G2O_DEBUG(...)
logger.h
g2o
Definition
dl_wrapper.cpp:55
g2o::createSolver
static OptimizationAlgorithm * createSolver(const std::string &solverName)
Definition
graph_optimizer_sparse_incremental.cpp:471
std
Definition
jet.h:876
optimization_algorithm_factory.h
G2O_REGISTER_OPTIMIZATION_LIBRARY
#define G2O_REGISTER_OPTIMIZATION_LIBRARY(libraryname)
Definition
optimization_algorithm_factory.h:160
G2O_REGISTER_OPTIMIZATION_ALGORITHM
#define G2O_REGISTER_OPTIMIZATION_ALGORITHM(optimizername, instance)
Definition
optimization_algorithm_factory.h:181
optimization_algorithm_gauss_newton.h
optimization_algorithm_levenberg.h
solver.h
g2o::OptimizationAlgorithmProperty
describe the properties of a solver
Definition
optimization_algorithm_property.h:39
Generated on
for g2o by
1.17.0