g2o
Loading...
Searching...
No Matches
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"
32#include "g2o/core/solver.h"
33#include "g2o/stuff/logger.h"
34#include "linear_solver_dense.h"
35
36using namespace std;
37
38namespace g2o {
39namespace {
40template <int p, int l>
41std::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
49static 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
82
84
87 "gn_dense", "Gauss-Newton: Dense solver (variable blocksize)",
88 "Dense", false, Eigen::Dynamic, Eigen::Dynamic)));
90 gn_dense3_2,
92 "gn_dense3_2", "Gauss-Newton: Dense solver (fixed blocksize)", "Dense",
93 true, 3, 2)));
95 gn_dense6_3,
97 "gn_dense6_3", "Gauss-Newton: Dense solver (fixed blocksize)", "Dense",
98 true, 6, 3)));
100 gn_dense7_3,
102 "gn_dense7_3", "Gauss-Newton: Dense solver (fixed blocksize)", "Dense",
103 true, 7, 3)));
106 "lm_dense", "Levenberg: Dense solver (variable blocksize)",
107 "Dense", false, -1, -1)));
110 "lm_dense3_2", "Levenberg: Dense solver (fixed blocksize)",
111 "Dense", true, 3, 2)));
114 "lm_dense6_3", "Levenberg: Dense solver (fixed blocksize)",
115 "Dense", true, 6, 3)));
118 "lm_dense7_3", "Levenberg: Dense solver (fixed blocksize)",
119 "Dense", true, 7, 3)));
120
121} // namespace g2o
base for allocating an optimization algorithm
const OptimizationAlgorithmProperty & property() const
return the properties of the solver
virtual OptimizationAlgorithm * construct()
allocate a solver operating on optimizer, re-implement for your creator
DenseSolverCreator(const OptimizationAlgorithmProperty &p)
Implementation of the Gauss Newton Algorithm.
Implementation of the Levenberg Algorithm.
Generic interface for a non-linear solver operating on a graph.
#define G2O_DEBUG(...)
Definition logger.h:90
static OptimizationAlgorithm * createSolver(const std::string &solverName)
Definition jet.h:876
#define G2O_REGISTER_OPTIMIZATION_LIBRARY(libraryname)
#define G2O_REGISTER_OPTIMIZATION_ALGORITHM(optimizername, instance)