sparse_block_matrix.h
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 #ifndef __SPARSE_BLOCK_MATRIX__
00018 #define __SPARSE_BLOCK_MATRIX__
00019 
00020 #include <map>
00021 #include <vector>
00022 #include <fstream>
00023 #include <iostream>
00024 #include <iomanip>
00025 #include <Eigen/Core>
00026 
00027 #include "matrix_structure.h"
00028 #include "g2o/config.h"
00029 
00030 namespace g2o {
00031   using namespace Eigen;
00048 template <class MatrixType = MatrixXd >
00049 class SparseBlockMatrix {
00050 
00051   public:
00053     typedef MatrixType SparseMatrixBlock;
00054 
00056     inline int cols() const 
00057        {return _colBlockIndices.size() ? _colBlockIndices.back() : 0;}
00059     inline int rows() const 
00060        {return _rowBlockIndices.size() ? _rowBlockIndices.back() : 0;}
00061 
00062     typedef std::map<int, SparseMatrixBlock*> IntBlockMap;
00063 
00078     SparseBlockMatrix
00079        (const int * rbi, const int* cbi, int rb, int cb, bool hasStorage=true);
00080 
00081     SparseBlockMatrix();
00082 
00083     ~SparseBlockMatrix();
00084 
00085     
00090     void clear(bool dealloc=false) ;
00091 
00096     SparseMatrixBlock* block(int r, int c, bool alloc=false);
00097 
00099     const SparseMatrixBlock* block(int r, int c) const;
00100 
00102     inline int rowsOfBlock(int r) const 
00103     { 
00104        return r
00105           ? _rowBlockIndices[r] - _rowBlockIndices[r-1]
00106           : _rowBlockIndices[0] ; 
00107     }
00108 
00110     inline int colsOfBlock(int c) const 
00111     {
00112        return c
00113           ? _colBlockIndices[c] - _colBlockIndices[c-1]
00114           : _colBlockIndices[0];
00115     }
00116 
00118     inline int rowBaseOfBlock(int r) const 
00119        { return r ? _rowBlockIndices[r-1] : 0 ; }
00120 
00122     inline int colBaseOfBlock(int c) const
00123        { return c ? _colBlockIndices[c-1] : 0 ; }
00124 
00126     size_t nonZeros() const; 
00128     size_t nonZeroBlocks() const; 
00129 
00131     SparseBlockMatrix* clone() const ;
00132 
00141     SparseBlockMatrix* slice
00142        (int rmin, int rmax, int cmin, int cmax, bool alloc=true) const;
00143 
00148     template <class MatrixTransposedType>
00149     bool transpose(SparseBlockMatrix<MatrixTransposedType>*& dest) const;
00150 
00152     bool add(SparseBlockMatrix<MatrixType>*& dest) const ;
00153 
00155     template <class MatrixResultType, class MatrixFactorType>
00156     bool multiply
00157     (
00158        SparseBlockMatrix<MatrixResultType> *& dest,
00159        const SparseBlockMatrix<MatrixFactorType>* M
00160     ) const;
00161 
00163     void multiply(double*& dest, const double* src) const;
00164 
00166     void rightMultiply(double*& dest, const double* src) const;
00167 
00169     void scale( double a);
00170 
00175     bool symmPermutation
00176     (
00177        SparseBlockMatrix<MatrixType>*& dest,
00178        const int* pinv, bool onlyUpper=false
00179     ) const;
00180 
00182     int fillCCS(int* Cp, int* Ci, double* Cx, bool upperTriangle = false) const;
00183 
00189     int fillCCS(double* Cx, bool upperTriangle = false) const;
00190 
00192     void fillBlockStructure(MatrixStructure& ms) const;
00193 
00195     const std::vector<IntBlockMap>& blockCols() const { return _blockCols;}
00196     std::vector<IntBlockMap>& blockCols() { return _blockCols;}
00197 
00199     const std::vector<int>& rowBlockIndices() const { return _rowBlockIndices;}
00200     std::vector<int>& rowBlockIndices() { return _rowBlockIndices;}
00201 
00203     const std::vector<int>& colBlockIndices() const { return _colBlockIndices;}
00204     std::vector<int>& colBlockIndices() { return _colBlockIndices;}
00205 
00211     bool writeOctave(const char* filename, bool upperTriangle = true) const;
00212 
00213   protected:
00215     std::vector<int> _rowBlockIndices;
00216 
00218     std::vector<int> _colBlockIndices;
00219 
00225     std::vector <IntBlockMap> _blockCols;
00226 
00227     bool _hasStorage;
00228 };
00229 
00230 template < class  MatrixType >
00231 std::ostream& operator<<
00232    (std::ostream&, const SparseBlockMatrix<MatrixType>& m);
00233 
00234   typedef SparseBlockMatrix<MatrixXd> SparseBlockMatrixXd;   
00235 
00236 } //end namespace
00237 
00238 #include "sparse_block_matrix.hpp"
00239 
00240 #endif


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