00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "linear_solver_cholmod.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_CHOLMOD(s, p, l, blockorder) \
00026 if (1) { \
00027 std::cerr << "# Using CHOLMOD poseDim " << p << " landMarkDim " << l << " blockordering " << blockorder << std::endl; \
00028 LinearSolverCholmod < DIM_TO_SOLVER(p, l)::PoseMatrixType >* linearSolver = new LinearSolverCholmod<DIM_TO_SOLVER(p, l)::PoseMatrixType>(); \
00029 linearSolver->setBlockOrdering(blockorder); \
00030 s = new DIM_TO_SOLVER(p, l)(opt, linearSolver); \
00031 } else (void)0
00032
00033 namespace g2o {
00034
00035 static Solver* createSolver(SparseOptimizer* opt, const std::string& solverName)
00036 {
00037 g2o::Solver* s = 0;
00038
00039 if (solverName == "var_cholmod") {
00040 ALLOC_CHOLMOD(s, -1, -1, false);
00041 }
00042 else if (solverName == "fix3_2_cholmod") {
00043 ALLOC_CHOLMOD(s, 3, 2, true);
00044 }
00045 else if (solverName == "fix6_3_cholmod") {
00046 ALLOC_CHOLMOD(s, 6, 3, true);
00047 }
00048 else if (solverName == "fix7_3_cholmod") {
00049 ALLOC_CHOLMOD(s, 7, 3, true);
00050 }
00051 else if (solverName == "fix3_2_cholmod_scalar") {
00052 ALLOC_CHOLMOD(s, 3, 2, false);
00053 }
00054 else if (solverName == "fix6_3_cholmod_scalar") {
00055 ALLOC_CHOLMOD(s, 6, 3, false);
00056 }
00057 else if (solverName == "fix7_3_cholmod_scalar") {
00058 ALLOC_CHOLMOD(s, 7, 3, false);
00059 }
00060
00061 return s;
00062 }
00063
00064 class CholmodSolverCreator : public AbstractSolverCreator
00065 {
00066 public:
00067 CholmodSolverCreator(const SolverProperty& p) : AbstractSolverCreator(p) {}
00068 virtual Solver* construct(SparseOptimizer* optimizer)
00069 {
00070 return createSolver(optimizer, property().name);
00071 }
00072 };
00073
00074 void __attribute__ ((constructor)) init_solver_cholmod()
00075 {
00076 SolverFactory* factory = SolverFactory::instance();
00077 factory->registerSolver(new CholmodSolverCreator(SolverProperty("var_cholmod", "Cholesky solver using CHOLMOD (variable blocksize)", "CHOLMOD", false, -1, -1)));
00078 factory->registerSolver(new CholmodSolverCreator(SolverProperty("fix3_2_cholmod", "Cholesky solver using CHOLMOD (fixed blocksize)", "CHOLMOD", true, 3, 2)));
00079 factory->registerSolver(new CholmodSolverCreator(SolverProperty("fix6_3_cholmod", "Cholesky solver using CHOLMOD (fixed blocksize)", "CHOLMOD", true, 6, 3)));
00080 factory->registerSolver(new CholmodSolverCreator(SolverProperty("fix7_3_cholmod", "Cholesky solver using CHOLMOD (fixed blocksize)", "CHOLMOD", true, 7, 3)));
00081 factory->registerSolver(new CholmodSolverCreator(SolverProperty("fix3_2_cholmod_scalar", "Cholesky solver using CHOLMOD (fixed blocksize, scalar ordering)", "CHOLMOD", true, 3, 2)));
00082 factory->registerSolver(new CholmodSolverCreator(SolverProperty("fix6_3_cholmod_scalar", "Cholesky solver using CHOLMOD (fixed blocksize, scalar ordering)", "CHOLMOD", true, 6, 3)));
00083 factory->registerSolver(new CholmodSolverCreator(SolverProperty("fix7_3_cholmod_scalar", "Cholesky solver using CHOLMOD (fixed blocksize, scalar ordering)", "CHOLMOD", true, 7, 3)));
00084 }
00085
00086 }