base_vertex.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 BASE_VERTEX_H
00018 #define BASE_VERTEX_H
00019 
00020 #include "optimizable_graph.h"
00021 #include "creators.h"
00022 #include "g2o/stuff/macros.h"
00023 
00024 #include <Eigen/Core>
00025 #include <Eigen/Dense>
00026 #include <Eigen/Cholesky>
00027 #include <stack>
00028 
00029 namespace g2o {
00030 
00031   using namespace Eigen;
00032 
00033 
00044   template <int D, typename T>
00045   class BaseVertex : public OptimizableGraph::Vertex {
00046     public:
00047     typedef T EstimateType;
00048     typedef std::stack
00049     <
00050        EstimateType, 
00051        std::deque <EstimateType,  Eigen::aligned_allocator<EstimateType> > 
00052     >  BackupStackType;
00053 
00055     static const int Dimension = D;
00056 
00057     typedef Map
00058     <
00059        Matrix<double, D, D>,
00060        Matrix<double, D, D>::Flags & AlignedBit ? Aligned : Unaligned
00061     >  HessianBlockType;
00062 
00063   public:
00064     BaseVertex();
00065 
00066     virtual const double& hessian(int i, int j) const
00067     {
00068        assert(i<D && j<D);
00069        return _hessian(i,j);
00070     }
00071 
00072     virtual double& hessian(int i, int j)
00073     {
00074        assert(i<D && j<D);
00075        return _hessian(i,j);
00076     }
00077 
00078     virtual double hessianDeterminant() const {return _hessian.determinant();}
00079 
00080     virtual double* hessianData() {return const_cast<double*>(_hessian.data());}
00081 
00082     virtual void mapHessianMemory(double* d);
00083 
00084     virtual int copyB(double* b_) const
00085     {
00086        memcpy(b_, _b.data(), Dimension * sizeof(double));
00087        return Dimension; 
00088     }
00089 
00090     virtual const double& b(int i) const 
00091     {
00092        assert(i < D);
00093        return _b(i);
00094     }
00095 
00096     virtual double& b(int i) 
00097     {
00098        assert(i < D);
00099        return _b(i);
00100     }
00101 
00102     virtual double* bData() { return _b.data();}
00103 
00104     virtual void clearQuadraticForm();
00105 
00108     virtual double solveDirect(double lambda=0);
00109 
00111     // virtual double estimate(int i) const 
00112     // {assert(i<InternalDimension); return _estimate[i]; }
00113 
00115     Matrix<double, D, 1>& b() { return _b;}
00116     const Matrix<double, D, 1>& b() const { return _b;}
00117 
00119     HessianBlockType& A() { return _hessian;}
00120     const HessianBlockType& A() const { return _hessian;}
00121 
00122     virtual void push() { _backup.push(_estimate);}
00123 
00124     virtual void pop() 
00125     {
00126        assert(!_backup.empty());
00127        _estimate = _backup.top();
00128        _backup.pop();
00129     }
00130 
00131     virtual void discardTop()
00132     {
00133        assert(!_backup.empty());
00134        _backup.pop();
00135     }
00136 
00137     virtual int stackSize() const {return _backup.size();}
00138 
00140     const EstimateType& estimate() const { return _estimate;}
00141     EstimateType& estimate() { return _estimate;}
00143     void setEstimate(const EstimateType& et) { _estimate = et;}
00144 
00145     virtual void setUncertainty(double* c);
00146     virtual double* uncertaintyData() { return _uncertainty.data();}
00148     const Matrix<double, D, D>& uncertainty() const { return _uncertainty;}
00150     void setUncertainty(const Matrix<double, D, D>& uncertainty)
00151        { _uncertainty = uncertainty;}
00152 
00153   protected:
00154     HessianBlockType _hessian;
00155     Matrix<double, D, 1> _b;
00156     EstimateType _estimate;
00157     BackupStackType _backup;
00158     Matrix<double, D, D> _uncertainty;
00159   public:
00160     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00161 };
00162 
00163 #include "base_vertex.hpp"
00164 
00165 } // end namespace g2o
00166 
00167 
00168 #endif


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