g2o
Loading...
Searching...
No Matches
edge_se2_twopointsxy.cpp
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
28
29#include <cassert>
30
31#ifdef G2O_HAVE_OPENGL
34#endif
35
36namespace g2o {
37
41
43 VertexSE2* pose = static_cast<VertexSE2*>(_vertices[0]);
44 VertexPointXY* xy1 = static_cast<VertexPointXY*>(_vertices[1]);
45 VertexPointXY* xy2 = static_cast<VertexPointXY*>(_vertices[2]);
46
47 Vector2 m1 = pose->estimate().inverse() * xy1->estimate();
48 Vector2 m2 = pose->estimate().inverse() * xy2->estimate();
49
50 _error[0] = m1[0] - _measurement[0];
51 _error[1] = m1[1] - _measurement[1];
52 _error[2] = m2[0] - _measurement[2];
53 _error[3] = m2[1] - _measurement[3];
54}
55
56bool EdgeSE2TwoPointsXY::read(std::istream& is) {
57 is >> _measurement[0] >> _measurement[1] >> _measurement[2] >>
58 _measurement[3];
59 is >> information()(0, 0) >> information()(0, 1) >> information()(0, 2) >>
60 information()(0, 3) >> information()(1, 1) >> information()(1, 2) >>
61 information()(1, 3) >> information()(2, 2) >> information()(2, 3) >>
62 information()(3, 3);
63 information()(1, 0) = information()(0, 1);
64 information()(2, 0) = information()(0, 2);
65 information()(2, 1) = information()(1, 2);
66 information()(3, 0) = information()(0, 3);
67 information()(3, 1) = information()(1, 3);
68 information()(3, 2) = information()(2, 3);
69 return true;
70}
71
72bool EdgeSE2TwoPointsXY::write(std::ostream& os) const {
73 os << measurement()[0] << " " << measurement()[1] << " " << measurement()[2]
74 << " " << measurement()[3] << " ";
75 os << information()(0, 0) << " " << information()(0, 1) << " "
76 << information()(0, 2) << " " << information()(0, 3) << " "
77 << information()(1, 1) << " " << information()(1, 2) << " "
78 << information()(1, 3) << " " << information()(2, 2) << " "
79 << information()(2, 3) << " " << information()(3, 3);
80 return os.good();
81}
82
84 const OptimizableGraph::VertexSet& fixed,
85 OptimizableGraph::Vertex* toEstimate) {
86 (void)toEstimate;
87
88 assert(initialEstimatePossible(fixed, toEstimate) &&
89 "Bad vertices specified");
90
91 VertexSE2* pose = static_cast<VertexSE2*>(_vertices[0]);
92 VertexPointXY* v1 = static_cast<VertexPointXY*>(_vertices[1]);
93 VertexPointXY* v2 = static_cast<VertexPointXY*>(_vertices[2]);
94
95 bool estimatev1 = true;
96 bool estimatev2 = true;
97
98 for (std::set<HyperGraph::Vertex*>::iterator it = fixed.begin();
99 it != fixed.end(); ++it) {
100 if (v1->id() == (*it)->id()) {
101 estimatev1 = false;
102 } else if (v2->id() == (*it)->id()) {
103 estimatev2 = false;
104 }
105 }
106
107 if (estimatev1) {
108 Vector2 submeas(_measurement[0], _measurement[1]);
109 v1->setEstimate(pose->estimate() * submeas);
110 }
111
112 if (estimatev2) {
113 Vector2 submeas(_measurement[2], _measurement[3]);
114 v2->setEstimate(pose->estimate() * submeas);
115 }
116}
117
119 const OptimizableGraph::VertexSet& fixed,
120 OptimizableGraph::Vertex* toEstimate) {
121 (void)toEstimate;
122
123 for (std::set<HyperGraph::Vertex*>::iterator it = fixed.begin();
124 it != fixed.end(); ++it) {
125 if (_vertices[0]->id() == (*it)->id()) {
126 return 1.0;
127 }
128 }
129 return -1.0;
130}
131
133 VertexSE2* pose = static_cast<VertexSE2*>(_vertices[0]);
134 VertexPointXY* xy1 = static_cast<VertexPointXY*>(_vertices[1]);
135 VertexPointXY* xy2 = static_cast<VertexPointXY*>(_vertices[2]);
136
137 Vector2 m1 = pose->estimate().inverse() * xy1->estimate();
138 Vector2 m2 = pose->estimate().inverse() * xy2->estimate();
139
140 _measurement[0] = m1[0];
141 _measurement[1] = m1[1];
142 _measurement[2] = m2[0];
143 _measurement[3] = m2[1];
144 return true;
145}
146
147} // end namespace g2o
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition base_edge.h:119
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
Definition base_edge.h:107
Measurement _measurement
the measurement of the edge
Definition base_edge.h:146
ErrorVector _error
Definition base_edge.h:149
base class to represent an edge connecting an arbitrary number of nodes
const EstimateType & estimate() const
return the current estimate of the vertex
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
virtual void initialEstimate(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
virtual bool write(std::ostream &os) const
write the vertex to a stream
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
virtual double initialEstimatePossible(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
VertexContainer _vertices
int id() const
returns the id
std::set< Vertex * > VertexSet
A general case Vertex for optimization.
SE2 inverse() const
invert :-)
Definition se2.h:83
2D pose Vertex, (x,y,theta)
Definition vertex_se2.h:41
VectorN< 4 > Vector4
Definition eigen_types.h:52
VectorN< 2 > Vector2
Definition eigen_types.h:50