g2o
edge_se2_pointxy_offset.cpp
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, 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 #include "parameter_se2_offset.h"
29 #include <iostream>
30 
31 namespace g2o {
32  using namespace std;
33 
34 
35  // point to camera projection, monocular
37  information().setIdentity();
38  cache = 0;
39  offsetParam = 0;
42  }
43 
45  ParameterVector pv(1);
46  pv[0]=offsetParam;
47  resolveCache(cache, (OptimizableGraph::Vertex*)_vertices[0],"CACHE_SE2_OFFSET",pv);
48  return cache != 0;
49  }
50 
51 
52  bool EdgeSE2PointXYOffset::read(std::istream& is) {
53  int pId;
54  is >> pId;
55  setParameterId(0, pId);
56  // measured keypoint
57  Vector2D meas;
58  for (int i=0; i<2; i++) is >> meas[i];
59  setMeasurement(meas);
60  // information matrix is the identity for features, could be changed to allow arbitrary covariances
61  if (is.bad()) {
62  return false;
63  }
64  for ( int i=0; i<information().rows() && is.good(); i++)
65  for (int j=i; j<information().cols() && is.good(); j++){
66  is >> information()(i,j);
67  if (i!=j)
68  information()(j,i)=information()(i,j);
69  }
70  if (is.bad()) {
71  // we overwrite the information matrix
72  information().setIdentity();
73  }
74  return true;
75  }
76 
77  bool EdgeSE2PointXYOffset::write(std::ostream& os) const {
78  cerr <<"W";
79  os << offsetParam->id() << " ";
80  for (int i=0; i<2; i++) os << measurement()[i] << " ";
81  for (int i=0; i<information().rows(); i++)
82  for (int j=i; j<information().cols(); j++) {
83  os << information()(i,j) << " ";
84  }
85  return os.good();
86  }
87 
88 
90  // from cam to point (track)
91  // VertexSE2 *rob = static_cast<VertexSE2*>(_vertices[0]);
92  VertexPointXY *point = static_cast<VertexPointXY*>(_vertices[1]);
93 
94  Vector2D perr = cache->w2lMatrix() * point->estimate();
95 
96  // error, which is backwards from the normal observed - calculated
97  // _measurement is the measured projection
98  _error = perr - _measurement;
99  // std::cout << _error << std::endl << std::endl;
100  }
101 
103  VertexSE2 *rob = static_cast<VertexSE2*>(_vertices[0]);
104  VertexPointXY *point = static_cast<VertexPointXY*>(_vertices[1]);
105  _jacobianOplusXi.block<2,2>(0,0) = - cache->RpInverseRInverseMatrix();
106  _jacobianOplusXi.block<2,1>(0,2) = cache->RpInverseRInversePrimeMatrix()*(point->estimate()-rob->estimate().translation());
108  }
109 
110 
112  VertexPointXY *point = static_cast<VertexPointXY*>(_vertices[1]);
113 
114  const Vector2D &pt = point->estimate();
115 
116  Vector2D perr = cache->w2lMatrix() * pt;
117  _measurement = perr;
118  return true;
119  }
120 
121 
123  {
124  (void) from;
125  assert(from.size() == 1 && from.count(_vertices[0]) == 1 && "Can not initialize VertexDepthCam position by VertexTrackXY");
126 
127  VertexSE2 *cam = dynamic_cast<VertexSE2*>(_vertices[0]);
128  VertexPointXY *point = dynamic_cast<VertexPointXY*>(_vertices[1]);
129  // SE2OffsetCache* vcache = (SE2OffsetCache* ) cam->getCache(_cacheIds[0]);
130  // if (! vcache){
131  // cerr << "fatal error in retrieving cache" << endl;
132  // }
133  // SE2OffsetParameters* params=vcache->params;
135  point->setEstimate(cam->estimate() * (offsetParam->offsetMatrix() * p));
136  }
137 
138 }
Eigen::Matrix< double, 2, 1, Eigen::ColMajor > Vector2D
Definition: eigen_types.h:45
const Isometry2D & w2lMatrix() const
bool installParameter(ParameterType *&p, size_t argNo, int paramId=-1)
virtual void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
const Isometry2D & offsetMatrix() const
rotation of the offset as 2x2 rotation matrix
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
2D pose Vertex, (x,y,theta)
Definition: vertex_se2.h:41
bool setParameterId(int argNum, int paramId)
void resolveCache(CacheType *&cache, OptimizableGraph::Vertex *, const std::string &_type, const ParameterVector &parameters)
Definition: cache.h:122
std::vector< Parameter * > ParameterVector
Definition: parameter.h:52
int id() const
Definition: parameter.h:45
ParameterSE2Offset * offsetParam
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Definition: base_vertex.h:101
A general case Vertex for optimization.
void resizeParameters(size_t newSize)
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
Definition: base_edge.h:67
virtual void setMeasurement(const Vector2D &m)
virtual bool write(std::ostream &os) const
write the vertex to a stream
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
const Matrix2D RpInverseRInversePrimeMatrix() const
const Vector2D & translation() const
translational component
Definition: se2.h:54
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
const Matrix2D RpInverseRInverseMatrix() const
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:75
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EdgeSE2PointXYOffset()
VertexContainer _vertices
Definition: hyper_graph.h:202