g2o
edge_se2_twopointsxy.cpp
Go to the documentation of this file.
1 #include "edge_se2_twopointsxy.h"
2 
3 #ifdef G2O_HAVE_OPENGL
6 #endif
7 
8 
9 namespace g2o{
10 
12  resize(3);
13  }
14 
16  VertexSE2 * pose = static_cast<VertexSE2 *> (_vertices[0]);
17  VertexPointXY * xy1 = static_cast<VertexPointXY *> (_vertices[1]);
18  VertexPointXY * xy2 = static_cast<VertexPointXY *> (_vertices[2]);
19 
20 
21  Vector2D m1 = pose->estimate().inverse() * xy1->estimate();
22  Vector2D m2 = pose->estimate().inverse() * xy2->estimate();
23 
24  _error[0] = m1[0] - _measurement[0];
25  _error[1] = m1[1] - _measurement[1];
26  _error[2] = m2[0] - _measurement[2];
27  _error[3] = m2[1] - _measurement[3];
28  }
29 
30  bool EdgeSE2TwoPointsXY::read(std::istream& is){
31  is >> _measurement[0] >> _measurement[1] >> _measurement[2] >> _measurement[3];
32  is >> information()(0,0) >> information()(0,1) >> information()(0,2) >> information()(0,3) >> information()(1,1) >> information()(1,2) >> information()(1,3) >> information()(2,2) >> information()(2,3) >> information()(3,3);
33  information()(1,0) = information()(0,1);
34  information()(2,0) = information()(0,2);
35  information()(2,1) = information()(1,2);
36  information()(3,0) = information()(0,3);
37  information()(3,1) = information()(1,3);
38  information()(3,2) = information()(2,3);
39  return true;
40  }
41 
42  bool EdgeSE2TwoPointsXY::write(std::ostream& os) const{
43  os << measurement()[0] << " " << measurement()[1] << " " << measurement()[2] << " " << measurement()[3] << " ";
44  os << information()(0,0) << " " << information()(0,1) << " " << information()(0,2) << " " << information()(0,3) << " " << information()(1,1) << " " << information()(1,2) << " " << information()(1,3) << " " << information()(2,2) << " " << information()(2,3) << " " << information()(3,3);
45  return os.good();
46  }
47 
48 
50  (void) toEstimate;
51 
52  assert(initialEstimatePossible(fixed, toEstimate) && "Bad vertices specified");
53 
54  VertexSE2 * pose = static_cast<VertexSE2 *>(_vertices[0]);
55  VertexPointXY * v1 = static_cast<VertexPointXY *>(_vertices[1]);
56  VertexPointXY * v2 = static_cast<VertexPointXY *>(_vertices[2]);
57 
58  bool estimatev1 = true;
59  bool estimatev2 = true;
60 
61  for(std::set<HyperGraph::Vertex*>::iterator it=fixed.begin(); it!=fixed.end(); it++){
62  if(v1->id() == (*it)->id()){
63  estimatev1 = false;
64  }
65  else if(v2->id() == (*it)->id()){
66  estimatev2 = false;
67  }
68  }
69 
70  if(estimatev1){
71  Vector2D submeas(_measurement[0], _measurement[1]);
72  v1->setEstimate(pose->estimate() * submeas);
73  }
74 
75  if(estimatev2){
76  Vector2D submeas(_measurement[2], _measurement[3]);
77  v2->setEstimate(pose->estimate() * submeas);
78  }
79  }
80 
81 
83  (void) toEstimate;
84 
85  for(std::set<HyperGraph::Vertex *>::iterator it=fixed.begin(); it!=fixed.end(); it++){
86  if(_vertices[0]->id() == (*it)->id()){
87  return 1.0;
88  }
89  }
90  return -1.0;
91  }
92 
93 
95  VertexSE2 * pose = static_cast<VertexSE2 *> (_vertices[0]);
96  VertexPointXY * xy1 = static_cast<VertexPointXY *> (_vertices[1]);
97  VertexPointXY * xy2 = static_cast<VertexPointXY *> (_vertices[2]);
98 
99 
100  Vector2D m1 = pose->estimate().inverse() * xy1->estimate();
101  Vector2D m2 = pose->estimate().inverse() * xy2->estimate();
102 
103  _measurement[0] = m1[0];
104  _measurement[1] = m1[1];
105  _measurement[2] = m2[0];
106  _measurement[3] = m2[1];
107  return true;
108  }
109 
110 } // 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
Eigen::Matrix< double, 4, 1, Eigen::ColMajor > Vector4D
Definition: eigen_types.h:47
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
2D pose Vertex, (x,y,theta)
Definition: vertex_se2.h:41
virtual void initialEstimate(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
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
virtual double initialEstimatePossible(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
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.
virtual void resize(size_t size)
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
Definition: base_edge.h:67
virtual bool setMeasurementFromState()
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
SE2 inverse() const
invert :-)
Definition: se2.h:82
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:75
VertexContainer _vertices
Definition: hyper_graph.h:202