g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
types
slam2d
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
27
#include "
edge_se2_twopointsxy.h
"
28
29
#include <cassert>
30
31
#ifdef G2O_HAVE_OPENGL
32
#include "
g2o/stuff/opengl_primitives.h
"
33
#include "
g2o/stuff/opengl_wrapper.h
"
34
#endif
35
36
namespace
g2o
{
37
38
EdgeSE2TwoPointsXY::EdgeSE2TwoPointsXY
() :
BaseVariableSizedEdge
<4,
Vector4
>() {
39
resize
(3);
40
}
41
42
void
EdgeSE2TwoPointsXY::computeError
() {
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
56
bool
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
72
bool
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
83
void
EdgeSE2TwoPointsXY::initialEstimate
(
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
118
double
EdgeSE2TwoPointsXY::initialEstimatePossible
(
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
132
bool
EdgeSE2TwoPointsXY::setMeasurementFromState
() {
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
g2o::BaseEdge< D, Vector4 >::measurement
EIGEN_STRONG_INLINE const Measurement & measurement() const
Definition
base_edge.h:119
g2o::BaseEdge< D, Vector4 >::information
EIGEN_STRONG_INLINE const InformationType & information() const
Definition
base_edge.h:107
g2o::BaseEdge< D, Vector4 >::_measurement
Measurement _measurement
Definition
base_edge.h:146
g2o::BaseEdge< D, Vector4 >::_error
ErrorVector _error
Definition
base_edge.h:149
g2o::BaseVariableSizedEdge< 4, Vector4 >::BaseVariableSizedEdge
BaseVariableSizedEdge()
Definition
base_variable_sized_edge.h:72
g2o::BaseVariableSizedEdge< 4, Vector4 >::resize
virtual void resize(size_t size)
Definition
base_variable_sized_edge.h:138
g2o::BaseVertex::estimate
const EstimateType & estimate() const
return the current estimate of the vertex
Definition
base_vertex.h:127
g2o::BaseVertex::setEstimate
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Definition
base_vertex.h:129
g2o::EdgeSE2TwoPointsXY::initialEstimate
virtual void initialEstimate(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
Definition
edge_se2_twopointsxy.cpp:83
g2o::EdgeSE2TwoPointsXY::setMeasurementFromState
virtual bool setMeasurementFromState()
Definition
edge_se2_twopointsxy.cpp:132
g2o::EdgeSE2TwoPointsXY::write
virtual bool write(std::ostream &os) const
write the vertex to a stream
Definition
edge_se2_twopointsxy.cpp:72
g2o::EdgeSE2TwoPointsXY::EdgeSE2TwoPointsXY
EdgeSE2TwoPointsXY()
Definition
edge_se2_twopointsxy.cpp:38
g2o::EdgeSE2TwoPointsXY::computeError
virtual void computeError()
Definition
edge_se2_twopointsxy.cpp:42
g2o::EdgeSE2TwoPointsXY::read
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Definition
edge_se2_twopointsxy.cpp:56
g2o::EdgeSE2TwoPointsXY::initialEstimatePossible
virtual double initialEstimatePossible(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
Definition
edge_se2_twopointsxy.cpp:118
g2o::HyperGraph::Edge::_vertices
VertexContainer _vertices
Definition
hyper_graph.h:221
g2o::HyperGraph::Vertex::id
int id() const
returns the id
Definition
hyper_graph.h:154
g2o::HyperGraph::VertexSet
std::set< Vertex * > VertexSet
Definition
hyper_graph.h:142
g2o::OptimizableGraph::Vertex
A general case Vertex for optimization.
Definition
optimizable_graph.h:108
g2o::SE2::inverse
SE2 inverse() const
invert :-)
Definition
se2.h:83
g2o::VertexPointXY
Definition
vertex_point_xy.h:39
g2o::VertexSE2
2D pose Vertex, (x,y,theta)
Definition
vertex_se2.h:41
edge_se2_twopointsxy.h
g2o
Definition
dl_wrapper.cpp:55
g2o::Vector4
VectorN< 4 > Vector4
Definition
eigen_types.h:52
g2o::Vector2
VectorN< 2 > Vector2
Definition
eigen_types.h:50
opengl_primitives.h
opengl_wrapper.h
Generated on
for g2o by
1.17.0