g2o
edge_se2_lotsofxy.cpp
Go to the documentation of this file.
1 #include "edge_se2_lotsofxy.h"
2 
3 #ifdef G2O_HAVE_OPENGL
6 #endif
7 
8 namespace g2o{
9 
11  resize(0);
12  }
13 
15  VertexSE2 * pose = static_cast<VertexSE2 *> (_vertices[0]);
16 
17  for(unsigned int i=0; i<_observedPoints; i++){
18  VertexPointXY * xy = static_cast<VertexPointXY *> (_vertices[1+i]);
19  Vector2D m = pose->estimate().inverse() * xy->estimate();
20 
21  unsigned int index = 2*i;
22  _error[index] = m[0] - _measurement[index];
23  _error[index+1] = m[1] - _measurement[index+1];
24  }
25  }
26 
27  bool EdgeSE2LotsOfXY::read(std::istream& is){
28  is >> _observedPoints;
29  setSize(_observedPoints + 1);
30 
31  // read the measurements
32  for(unsigned int i=0; i<_observedPoints; i++){
33  unsigned int index = 2*i;
34  is >> _measurement[index] >> _measurement[index+1];
35  }
36 
37  // read the information matrix
38  for(unsigned int i=0; i<_observedPoints*2; i++){
39  // fill the "upper triangle" part of the matrix
40  for(unsigned int j=i; j<_observedPoints*2; j++){
41  is >> information()(i,j);
42  }
43 
44  // fill the lower triangle part
45  for(unsigned int j=0; j<i; j++){
46  information()(i,j) = information()(j,i);
47  }
48 
49  }
50 
51  return true;
52  }
53 
54  bool EdgeSE2LotsOfXY::write(std::ostream& os) const{
55  // write number of observed points
56  os << "|| " << _observedPoints;
57 
58  // write measurements
59  for(unsigned int i=0; i<_observedPoints; i++){
60  unsigned int index = 2*i;
61  os << " " << _measurement[index] << " " << _measurement[index+1];
62  }
63 
64  // write information matrix
65  for(unsigned int i=0; i<_observedPoints*2; i++){
66  for(unsigned int j=i; j<_observedPoints*2; j++){
67  os << " " << information()(i,j);
68  }
69  }
70 
71  return os.good();
72  }
73 
74 
76  const VertexSE2* vi = static_cast<const VertexSE2*>(_vertices[0]);
77  const double& x1 = vi->estimate().translation()[0];
78  const double& y1 = vi->estimate().translation()[1];
79  const double& th1 = vi->estimate().rotation().angle();
80 
81  double ct = cos(th1) ;
82  double st = sin(th1) ;
83 
84  MatrixXD Ji;
85  unsigned int rows = 2*(_vertices.size()-1);
86  Ji.resize(rows, 3);
87  Ji.fill(0);
88 
89  Matrix2D poseRot; // inverse of the rotation matrix associated to the pose
90  poseRot << ct , st ,
91  -st , ct ;
92 
93  Matrix2D minusPoseRot = -poseRot;
94 
95 
96  for(unsigned int i=1; i<_vertices.size(); i++){
98 
99  const double& x2 = point->estimate()[0];
100  const double& y2 = point->estimate()[1];
101 
102  unsigned int index = 2*(i-1);
103 
104  Ji.block<2,2>(index,0) = minusPoseRot;
105 
106  Ji(index,2) = ct * (y2-y1) + st * (x1 - x2);
107  Ji(index+1,2) = st * (y1-y2) + ct * (x1 - x2);
108 
109 
110  MatrixXD Jj;
111  Jj.resize(rows, 2);
112  Jj.fill(0);
113  Jj.block<2,2>(index, 0) = poseRot;
114 
115  _jacobianOplus[i] = Jj;
116  }
117  _jacobianOplus[0] = Ji;
118  }
119 
120 
122  (void) toEstimate;
123 
124  assert(initialEstimatePossible(fixed, toEstimate) && "Bad vertices specified");
125 
126  VertexSE2 * pose = static_cast<VertexSE2 *>(_vertices[0]);
127 
128 #ifdef _MSC_VER
129  std::vector<bool> estimate_this(_observedPoints, true);
130 #else
131  bool estimate_this[_observedPoints];
132  for(unsigned int i=0; i<_observedPoints; i++){
133  estimate_this[i] = true;
134  }
135 #endif
136 
137  for(std::set<HyperGraph::Vertex*>::iterator it=fixed.begin(); it!=fixed.end(); it++){
138  for(unsigned int i=1; i<_vertices.size(); i++){
139  VertexPointXY * vert = static_cast<VertexPointXY *>(_vertices[i]);
140  if(vert->id() == (*it)->id()) estimate_this[i-1] = false;
141  }
142  }
143 
144  for(unsigned int i=1; i<_vertices.size(); i++){
145  if(estimate_this[i-1]){
146  unsigned int index = 2*(i-1);
147  Vector2D submeas(_measurement[index], _measurement[index+1]);
148  VertexPointXY * vert = static_cast<VertexPointXY *>(_vertices[i]);
149  vert->setEstimate(pose->estimate() * submeas);
150  }
151  }
152  }
153 
154 
156  (void) toEstimate;
157 
158  for(std::set<HyperGraph::Vertex *>::iterator it=fixed.begin(); it!=fixed.end(); it++){
159  if(_vertices[0]->id() == (*it)->id()){
160  return 1.0;
161  }
162  }
163 
164  return -1.0;
165  }
166 
167 
169  VertexSE2 * pose = static_cast<VertexSE2 *> (_vertices[0]);
170 
171  for(unsigned int i=0; i<_observedPoints; i++){
172  VertexPointXY * xy = static_cast<VertexPointXY *> (_vertices[1+i]);
173  Vector2D m = pose->estimate().inverse() * xy->estimate();
174 
175  unsigned int index = 2*i;
176  _measurement[index] = m[0];
177  _measurement[index+1] = m[1];
178  }
179 
180  return true;
181  }
182 
183 } // end namespace g2o
Eigen::Matrix< double, 2, 1, Eigen::ColMajor > Vector2D
Definition: eigen_types.h:45
int id() const
returns the id
Definition: hyper_graph.h:148
virtual void initialEstimate(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
Eigen::Matrix< double, 2, 2, Eigen::ColMajor > Matrix2D
Definition: eigen_types.h:60
2D pose Vertex, (x,y,theta)
Definition: vertex_se2.h:41
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
virtual bool setMeasurementFromState()
virtual void linearizeOplus()
void setSize(int vertices)
const Eigen::Rotation2Dd & rotation() const
rotational component
Definition: se2.h:58
virtual void computeError()
virtual bool write(std::ostream &os) const
write the vertex to a stream
base class to represent an edge connecting an arbitrary number of nodes
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.
Eigen::Matrix< double, Eigen::Dynamic, 1, Eigen::ColMajor > VectorXD
Definition: eigen_types.h:48
virtual double initialEstimatePossible(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
virtual void resize(size_t size)
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
Definition: base_edge.h:67
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
SE2 inverse() const
invert :-)
Definition: se2.h:82
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixXD
Definition: eigen_types.h:63
const Vector2D & translation() const
translational component
Definition: se2.h:54
unsigned int _observedPoints
std::vector< JacobianType, Eigen::aligned_allocator< JacobianType > > _jacobianOplus
jacobians of the edge (w.r.t. oplus)
VertexContainer _vertices
Definition: hyper_graph.h:202