linear_solver_dense.h
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 H. Strasdat
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 #ifndef LINEAR_SOLVER_DENSE_H
00018 #define LINEAR_SOLVER_DENSE_H
00019 
00020 #include "g2o/core/linear_solver.h"
00021 #include "g2o/core/batch_stats.h"
00022 
00023 #include <vector>
00024 #include <utility>
00025 #include<Eigen/Core>
00026 #include<Eigen/Cholesky>
00027 
00028 
00029 namespace g2o {
00030 
00034   template <typename MatrixType>
00035   class LinearSolverDense : public LinearSolver<MatrixType>
00036   {
00037     public:
00038       LinearSolverDense() :
00039       LinearSolver<MatrixType>(){}
00040 
00041       virtual ~LinearSolverDense(){}
00042 
00043       virtual bool init(){ return true;}
00044 
00045       bool solve(const SparseBlockMatrix<MatrixType>& A, double* x, double* b)
00046       {
00047         int n = A.cols();
00048         int m = A.cols();
00049 
00050         MatrixXd H(n,m);
00051         H.setZero();
00052 
00053         int c_idx = 0;
00054 
00055         for (size_t i = 0; i < A.blockCols().size(); ++i)
00056         {
00057           int c_size = A.colsOfBlock(i);
00058           int r_idx = 0;
00059 
00060           const typename SparseBlockMatrix<MatrixType>::IntBlockMap& col =
00061              A.blockCols()[i];
00062           if (col.size() > 0)
00063           {
00064             typename SparseBlockMatrix<MatrixType>::
00065                IntBlockMap::const_iterator it;
00066             for (it = col.begin(); it != col.end(); ++it)
00067             {
00068               // only the upper triangular block is needed
00069               if (it->first <= (int)i)
00070               {
00071                 int r_size = A.rowsOfBlock(it->first);
00072                 H.block(r_idx,c_idx,r_size,c_size) = *(it->second);
00073                 r_idx += r_size;
00074               }
00075             }
00076           }
00077           c_idx += c_size;
00078         }
00079 
00080         //std::cerr << H << std::endl;
00081 
00082         Eigen::Map<Eigen::VectorXd> xvec(x, m);
00083         const Eigen::Map<Eigen::VectorXd> bvec(b, n);
00084 
00085         xvec = H.ldlt().solve(Eigen::VectorXd(bvec));
00086 
00087         return true;
00088       }
00089 
00090     protected:
00091 
00092   };
00093 
00094 }// end namespace
00095 
00096 #endif
00097 


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