Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "linear_solver_pcg.h"
00018
00019 #include "g2o/core/block_solver.h"
00020 #include "g2o/core/solver.h"
00021 #include "g2o/core/solver_factory.h"
00022
00023 #define DIM_TO_SOLVER(p, l) BlockSolver< BlockSolverTraits<p, l> >
00024
00025 #define ALLOC_PCG(s, p, l) \
00026 if (1) { \
00027 std::cerr << "# Using PCG poseDim " << p << " landMarkDim " << l << std::endl; \
00028 DIM_TO_SOLVER(p, l)::LinearSolverType* linearSolver = new LinearSolverPCG<DIM_TO_SOLVER(p, l)::PoseMatrixType>(); \
00029 s = new DIM_TO_SOLVER(p, l)(opt, linearSolver); \
00030 } else (void)0
00031
00032 namespace g2o {
00033
00034 static Solver* createSolver(SparseOptimizer* opt, const std::string& solverName)
00035 {
00036 g2o::Solver* s = 0;
00037
00038 if (solverName == "pcg") {
00039 ALLOC_PCG(s, -1, -1);
00040 }
00041 else if (solverName == "pcg3_2") {
00042 ALLOC_PCG(s, 3, 2);
00043 }
00044 else if (solverName == "pcg6_3") {
00045 ALLOC_PCG(s, 6, 3);
00046 }
00047 else if (solverName == "pcg7_3") {
00048 ALLOC_PCG(s, 7, 3);
00049 }
00050
00051 return s;
00052 }
00053
00054 class PCGSolverCreator : public AbstractSolverCreator
00055 {
00056 public:
00057 PCGSolverCreator(const SolverProperty& p) : AbstractSolverCreator(p) {}
00058 virtual Solver* construct(SparseOptimizer* optimizer)
00059 {
00060 return createSolver(optimizer, property().name);
00061 }
00062 };
00063
00064 void __attribute__ ((constructor)) init_solver_csparse()
00065 {
00066 SolverFactory* factory = SolverFactory::instance();
00067 factory->registerSolver(new PCGSolverCreator(SolverProperty("pcg", "PCG solver using block-Jacobi pre-conditioner (variable blocksize)", "PCG", false, -1, -1)));
00068 factory->registerSolver(new PCGSolverCreator(SolverProperty("pcg3_2", "PCG solver using block-Jacobi pre-conditioner (fixed blocksize)", "PCG", true, 3, 2)));
00069 factory->registerSolver(new PCGSolverCreator(SolverProperty("pcg6_3", "PCG solver using block-Jacobi pre-conditioner (fixed blocksize)", "PCG", true, 6, 3)));
00070 factory->registerSolver(new PCGSolverCreator(SolverProperty("pcg7_3", "PCG solver using block-Jacobi pre-conditioner (fixed blocksize)", "PCG", true, 7, 3)));
00071 }
00072
00073 }