g2o
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 "linear_solver_dense.h"
28 
29 #include "g2o/config.h"
30 #include "g2o/core/block_solver.h"
31 #include "g2o/core/solver.h"
33 
36 
37 #define DIM_TO_SOLVER(p, l) BlockSolver< BlockSolverTraits<p, l> >
38 
39 #define ALLOC_DENSE(s, p, l) \
40  if (1) { \
41  std::cerr << "# Using DENSE poseDim " << p << " landMarkDim " << l << std::endl; \
42  DIM_TO_SOLVER(p, l)::LinearSolverType* linearSolver = new LinearSolverDense<DIM_TO_SOLVER(p, l)::PoseMatrixType>(); \
43  s = new DIM_TO_SOLVER(p, l)(linearSolver); \
44  } else (void)0
45 
46 using namespace std;
47 
48 namespace g2o {
49 
50  static OptimizationAlgorithm* createSolver(const std::string& fullSolverName)
51  {
52  g2o::Solver* s = 0;
53 
54  string methodName = fullSolverName.substr(0, 2);
55  string solverName = fullSolverName.substr(3);
56 
57  if (solverName == "dense") {
58  ALLOC_DENSE(s, -1, -1);
59  }
60  else if (solverName == "dense3_2") {
61  ALLOC_DENSE(s, 3, 2);
62  }
63  else if (solverName == "dense6_3") {
64  ALLOC_DENSE(s, 6, 3);
65  }
66  else if (solverName == "dense7_3") {
67  ALLOC_DENSE(s, 7, 3);
68  }
69 
70  OptimizationAlgorithm* snl = 0;
71  if (methodName == "gn") {
73  }
74  else if (methodName == "lm") {
75  snl = new OptimizationAlgorithmLevenberg(s);
76  }
77 
78  return snl;
79  }
80 
82  {
83  public:
86  {
87  return createSolver(property().name);
88  }
89  };
90 
92 
93  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_dense, new DenseSolverCreator(OptimizationAlgorithmProperty("gn_dense", "Gauss-Newton: Dense solver (variable blocksize)", "Dense", false, Eigen::Dynamic, Eigen::Dynamic)));
94  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_dense3_2, new DenseSolverCreator(OptimizationAlgorithmProperty("gn_dense3_2", "Gauss-Newton: Dense solver (fixed blocksize)", "Dense", true, 3, 2)));
95  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_dense6_3, new DenseSolverCreator(OptimizationAlgorithmProperty("gn_dense6_3", "Gauss-Newton: Dense solver (fixed blocksize)", "Dense", true, 6, 3)));
96  G2O_REGISTER_OPTIMIZATION_ALGORITHM(gn_dense7_3, new DenseSolverCreator(OptimizationAlgorithmProperty("gn_dense7_3", "Gauss-Newton: Dense solver (fixed blocksize)", "Dense", true, 7, 3)));
97  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_dense, new DenseSolverCreator(OptimizationAlgorithmProperty("lm_dense", "Levenberg: Dense solver (variable blocksize)", "Dense", false, -1, -1)));
98  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_dense3_2, new DenseSolverCreator(OptimizationAlgorithmProperty("lm_dense3_2", "Levenberg: Dense solver (fixed blocksize)", "Dense", true, 3, 2)));
99  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_dense6_3, new DenseSolverCreator(OptimizationAlgorithmProperty("lm_dense6_3", "Levenberg: Dense solver (fixed blocksize)", "Dense", true, 6, 3)));
100  G2O_REGISTER_OPTIMIZATION_ALGORITHM(lm_dense7_3, new DenseSolverCreator(OptimizationAlgorithmProperty("lm_dense7_3", "Levenberg: Dense solver (fixed blocksize)", "Dense", true, 7, 3)));
101 
102 } // end namespace
DenseSolverCreator(const OptimizationAlgorithmProperty &p)
#define G2O_REGISTER_OPTIMIZATION_ALGORITHM(optimizername, instance)
describe the properties of a solver
#define G2O_REGISTER_OPTIMIZATION_LIBRARY(libraryname)
Implementation of the Levenberg Algorithm.
static OptimizationAlgorithm * createSolver(const std::string &fullSolverName)
Implementation of the Gauss Newton Algorithm.
base for allocating an optimization algorithm
Generic interface for a sparse solver operating on a graph which solves one iteration of the lineariz...
Definition: solver.h:44
virtual OptimizationAlgorithm * construct()
allocate a solver operating on optimizer, re-implement for your creator
Generic interface for a non-linear solver operating on a graph.
#define ALLOC_DENSE(s, p, l)