solver_pcg.cpp
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
00003 // 
00004 // g2o is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as published
00006 // by the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // g2o is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
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 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:42