g2o
base_edge.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, H. Strasdat, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #ifndef G2O_BASE_EDGE_H
28 #define G2O_BASE_EDGE_H
29 
30 #include <iostream>
31 #include <limits>
32 
33 #include <Eigen/Core>
34 
35 #include "optimizable_graph.h"
36 
37 namespace g2o {
38 
39  template <int D, typename E>
41  {
42  public:
43 
44  static const int Dimension = D;
45  typedef E Measurement;
46  typedef Eigen::Matrix<double, D, 1, Eigen::ColMajor> ErrorVector;
47  typedef Eigen::Matrix<double, D, D, Eigen::ColMajor> InformationType;
48 
50  {
51  _dimension = D;
52  }
53 
54  virtual ~BaseEdge() {}
55 
56  virtual double chi2() const
57  {
58  return _error.dot(information()*_error);
59  }
60 
61  virtual const double* errorData() const { return _error.data();}
62  virtual double* errorData() { return _error.data();}
63  const ErrorVector& error() const { return _error;}
64  ErrorVector& error() { return _error;}
65 
67  EIGEN_STRONG_INLINE const InformationType& information() const { return _information;}
68  EIGEN_STRONG_INLINE InformationType& information() { return _information;}
69  EIGEN_STRONG_INLINE void setInformation(const InformationType& information) { _information = information;}
70 
71  virtual const double* informationData() const { return _information.data();}
72  virtual double* informationData() { return _information.data();}
73 
75  EIGEN_STRONG_INLINE const Measurement& measurement() const { return _measurement;}
76  virtual void setMeasurement(const Measurement& m) { _measurement = m;}
77 
78  virtual int rank() const {return _dimension;}
79 
81  {
82  std::cerr << "inititialEstimate() is not implemented, please give implementation in your derived class" << std::endl;
83  }
84 
85  protected:
86 
87  Measurement _measurement;
88  InformationType _information;
89  ErrorVector _error;
90 
94  InformationType robustInformation(const Vector3D& rho)
95  {
96  InformationType result = rho[1] * _information;
97  //ErrorVector weightedErrror = _information * _error;
98  //result.noalias() += 2 * rho[2] * (weightedErrror * weightedErrror.transpose());
99  return result;
100  }
101 
102  public:
103  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
104  };
105 
106 
107  template<typename E>
108  class BaseEdge<-1,E> : public OptimizableGraph::Edge
109  {
110  public:
111 
112  static const int Dimension = -1;
113  typedef E Measurement;
114  typedef Eigen::Matrix<double, Eigen::Dynamic, 1, Eigen::ColMajor> ErrorVector;
115  typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> InformationType;
116 
118 
119  }
120 
121  virtual ~BaseEdge() {}
122 
123  virtual double chi2() const
124  {
125  return _error.dot(information()*_error);
126  }
127 
128  virtual const double* errorData() const { return _error.data();}
129  virtual double* errorData() { return _error.data();}
130  const ErrorVector& error() const { return _error;}
131  ErrorVector& error() { return _error;}
132 
134  const InformationType& information() const { return _information;}
135  InformationType& information() { return _information;}
136  void setInformation(const InformationType& information) { _information = information;}
137 
138  virtual const double* informationData() const { return _information.data();}
139  virtual double* informationData() { return _information.data();}
140 
142  const Measurement& measurement() const { return _measurement;}
143  virtual void setMeasurement(const Measurement& m) { _measurement = m;}
144 
145  virtual int rank() const {return _dimension;}
146 
148  {
149  std::cerr << "inititialEstimate() is not implemented, please give implementation in your derived class" << std::endl;
150  }
151 
152  protected:
153 
154  Measurement _measurement;
155  InformationType _information;
156  ErrorVector _error;
157 
161  InformationType robustInformation(const Vector3D& rho)
162  {
163  InformationType result = rho[1] * _information;
164  //ErrorVector weightedErrror = _information * _error;
165  //result.noalias() += 2 * rho[2] * (weightedErrror * weightedErrror.transpose());
166  return result;
167  }
168 
169  public:
170  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
171  };
172 
173 
174 } // end namespace g2o
175 
176 #endif
InformationType robustInformation(const Vector3D &rho)
Definition: base_edge.h:161
Eigen::Matrix< double, Eigen::Dynamic, 1, Eigen::ColMajor > ErrorVector
Definition: base_edge.h:114
ErrorVector _error
Definition: base_edge.h:89
Eigen::Matrix< double, 3, 1, Eigen::ColMajor > Vector3D
Definition: eigen_types.h:46
void setInformation(const InformationType &information)
Definition: base_edge.h:136
virtual double chi2() const
computes the chi2 based on the cached error value, only valid after computeError has been called...
Definition: base_edge.h:123
Measurement _measurement
Definition: base_edge.h:87
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
virtual double chi2() const
computes the chi2 based on the cached error value, only valid after computeError has been called...
Definition: base_edge.h:56
const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:142
Eigen::Matrix< double, D, D, Eigen::ColMajor > InformationType
Definition: base_edge.h:47
InformationType _information
Definition: base_edge.h:88
virtual void setMeasurement(const Measurement &m)
Definition: base_edge.h:76
const ErrorVector & error() const
Definition: base_edge.h:130
InformationType _information
Definition: base_edge.h:155
virtual double * informationData()
Definition: base_edge.h:72
Eigen::Matrix< double, D, 1, Eigen::ColMajor > ErrorVector
Definition: base_edge.h:46
virtual ~BaseEdge()
Definition: base_edge.h:54
virtual double * errorData()
Definition: base_edge.h:129
const InformationType & information() const
information matrix of the constraint
Definition: base_edge.h:134
virtual void initialEstimate(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
Definition: base_edge.h:80
ErrorVector & error()
Definition: base_edge.h:131
virtual void setMeasurement(const Measurement &m)
Definition: base_edge.h:143
virtual void initialEstimate(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
Definition: base_edge.h:147
const ErrorVector & error() const
Definition: base_edge.h:63
EIGEN_STRONG_INLINE void setInformation(const InformationType &information)
Definition: base_edge.h:69
virtual int rank() const
Definition: base_edge.h:78
InformationType & information()
Definition: base_edge.h:135
EIGEN_STRONG_INLINE InformationType & information()
Definition: base_edge.h:68
A general case Vertex for optimization.
virtual const double * informationData() const
returns the memory of the information matrix, usable for example with a Eigen::Map<MatrixXD> ...
Definition: base_edge.h:71
virtual const double * errorData() const
returns the error vector cached after calling the computeError;
Definition: base_edge.h:61
virtual double * informationData()
Definition: base_edge.h:139
virtual const double * errorData() const
returns the error vector cached after calling the computeError;
Definition: base_edge.h:128
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
Definition: base_edge.h:67
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > InformationType
Definition: base_edge.h:115
virtual const double * informationData() const
returns the memory of the information matrix, usable for example with a Eigen::Map<MatrixXD> ...
Definition: base_edge.h:138
ErrorVector & error()
Definition: base_edge.h:64
InformationType robustInformation(const Vector3D &rho)
Definition: base_edge.h:94
virtual double * errorData()
Definition: base_edge.h:62
virtual int rank() const
Definition: base_edge.h:145
static const int Dimension
Definition: base_edge.h:44
Measurement _measurement
Definition: base_edge.h:154
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:75
ErrorVector _error
Definition: base_edge.h:156