solver_csparse.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_csparse.h"
00018 
00019 #include "g2o/core/block_solver.h"
00020 #include "g2o/core/solver.h"
00021 #include "g2o/core/solver_factory.h"
00022 #include "g2o/core/graph_optimizer_sparse.h"
00023 
00024 #include "g2o/stuff/macros.h"
00025 
00026 #define DIM_TO_SOLVER(p, l) BlockSolver< BlockSolverTraits<p, l> >
00027 
00028 #define ALLOC_CSPARSE(s, p, l, blockorder) \
00029   if (1) { \
00030     std::cerr << "# Using CSparse poseDim " << p << " landMarkDim " << l << " blockordering " << blockorder << std::endl; \
00031     LinearSolverCSparse< DIM_TO_SOLVER(p, l)::PoseMatrixType >* linearSolver = new LinearSolverCSparse<DIM_TO_SOLVER(p, l)::PoseMatrixType>(); \
00032     linearSolver->setBlockOrdering(blockorder); \
00033     s = new DIM_TO_SOLVER(p, l)(opt, linearSolver); \
00034   } else (void)0
00035 
00036 namespace g2o {
00037 
00041   static Solver* createSolver(SparseOptimizer* opt, const std::string& solverName)
00042   {
00043     g2o::Solver* s = 0;
00044 
00045     if (solverName == "var") {
00046       ALLOC_CSPARSE(s, -1, -1, false);
00047     }
00048     else if (solverName == "fix3_2") {
00049       ALLOC_CSPARSE(s, 3, 2, true);
00050     }
00051     else if (solverName == "fix6_3") {
00052       ALLOC_CSPARSE(s, 6, 3, true);
00053     }
00054     else if (solverName == "fix7_3") {
00055       ALLOC_CSPARSE(s, 7, 3, true);
00056     }
00057     else if (solverName == "fix3_2_scalar") {
00058       ALLOC_CSPARSE(s, 3, 2, false);
00059     }
00060     else if (solverName == "fix6_3_scalar") {
00061       ALLOC_CSPARSE(s, 6, 3, false);
00062     }
00063     else if (solverName == "fix7_3_scalar") {
00064       ALLOC_CSPARSE(s, 7, 3, false);
00065     }
00066 
00067     return s;
00068   }
00069 
00070   class CSparseSolverCreator : public AbstractSolverCreator
00071   {
00072     public:
00073       CSparseSolverCreator(const SolverProperty& p) : AbstractSolverCreator(p) {}
00074       virtual Solver* construct(SparseOptimizer* optimizer)
00075       {
00076         return createSolver(optimizer, property().name);
00077       }
00078   };
00079 
00080   void G2O_ATTRIBUTE_CONSTRUCTOR init_solver_csparse()
00081   {
00082     SolverFactory* factory = SolverFactory::instance();
00083     factory->registerSolver(new CSparseSolverCreator(SolverProperty("var", "Cholesky solver using CSparse (variable blocksize)", "CSparse", false, -1, -1)));
00084     factory->registerSolver(new CSparseSolverCreator(SolverProperty("fix3_2", "Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 3, 2)));
00085     factory->registerSolver(new CSparseSolverCreator(SolverProperty("fix6_3", "Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 6, 3)));
00086     factory->registerSolver(new CSparseSolverCreator(SolverProperty("fix7_3", "Cholesky solver using CSparse (fixed blocksize)", "CSparse", true, 7, 3)));
00087     factory->registerSolver(new CSparseSolverCreator(SolverProperty("fix3_2_scalar", "Cholesky solver using CSparse (fixed blocksize, scalar ordering)", "CSparse", true, 3, 2)));
00088     factory->registerSolver(new CSparseSolverCreator(SolverProperty("fix6_3_scalar", "Cholesky solver using CSparse (fixed blocksize, scalar ordering)", "CSparse", true, 6, 3)));
00089     factory->registerSolver(new CSparseSolverCreator(SolverProperty("fix7_3_scalar", "Cholesky solver using CSparse (fixed blocksize, scalar ordering)", "CSparse", true, 7, 3)));
00090   }
00091 
00092 } // end namespace


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