g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
types
slam3d
edge_se3_lotsofxyz.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_se3_lotsofxyz.h
"
28
29
#include <cassert>
30
31
namespace
g2o
{
32
33
EdgeSE3LotsOfXYZ::EdgeSE3LotsOfXYZ
()
34
:
BaseVariableSizedEdge
<-1,
VectorX
>(),
_observedPoints
(0) {
35
resize
(0);
36
}
37
38
bool
EdgeSE3LotsOfXYZ::setMeasurementFromState
() {
39
VertexSE3
* pose =
static_cast<
VertexSE3
*
>
(
_vertices
[0]);
40
41
Eigen::Transform<double, 3, 1> poseinv = pose->
estimate
().inverse();
42
43
for
(
unsigned
int
i = 0; i <
_observedPoints
; i++) {
44
VertexPointXYZ
* xyz =
static_cast<
VertexPointXYZ
*
>
(
_vertices
[1 + i]);
45
// const Vector3 &pt = xyz->estimate();
46
Vector3
m = poseinv * xyz->
estimate
();
47
48
unsigned
int
index = 3 * i;
49
_measurement
[index] = m[0];
50
_measurement
[index + 1] = m[1];
51
_measurement
[index + 2] = m[2];
52
}
53
return
true
;
54
}
55
56
void
EdgeSE3LotsOfXYZ::computeError
() {
57
VertexSE3
* pose =
static_cast<
VertexSE3
*
>
(
_vertices
[0]);
58
59
for
(
unsigned
int
i = 0; i <
_observedPoints
; i++) {
60
VertexPointXYZ
* xyz =
static_cast<
VertexPointXYZ
*
>
(
_vertices
[1 + i]);
61
Vector3
m = pose->
estimate
().inverse() * xyz->
estimate
();
62
63
unsigned
int
index = 3 * i;
64
_error
[index] = m[0] -
_measurement
[index];
65
_error
[index + 1] = m[1] -
_measurement
[index + 1];
66
_error
[index + 2] = m[2] -
_measurement
[index + 2];
67
}
68
}
69
70
void
EdgeSE3LotsOfXYZ::linearizeOplus
() {
71
g2o::VertexSE3
* pose = (
g2o::VertexSE3
*)(
_vertices
[0]);
72
73
// initialize Ji matrix
74
MatrixX
Ji;
75
unsigned
int
rows = 3 * (
_vertices
.size() - 1);
76
Ji.resize(rows, 6);
77
Ji.fill(0);
78
79
Matrix3
poseRot = pose->
estimate
().inverse().rotation();
80
81
for
(
unsigned
int
i = 1; i <
_vertices
.size(); i++) {
82
g2o::VertexPointXYZ
* point = (
g2o::VertexPointXYZ
*)(
_vertices
[i]);
83
Vector3
Zcam = pose->
estimate
().inverse() * point->
estimate
();
84
85
unsigned
int
index = 3 * (i - 1);
86
87
// Ji.block<3,3>(index,0) = -poseRot;
88
Ji.block<3, 3>(index, 0) = -Matrix3::Identity();
89
90
Ji(index, 3) = -0.0;
91
Ji(index, 4) = -2 * Zcam(2);
92
Ji(index, 5) = 2 * Zcam(1);
93
94
Ji(index + 1, 3) = 2 * Zcam(2);
95
Ji(index + 1, 4) = -0.0;
96
Ji(index + 1, 5) = -2 * Zcam(0);
97
98
Ji(index + 2, 3) = -2 * Zcam(1);
99
Ji(index + 2, 4) = 2 * Zcam(0);
100
Ji(index + 2, 5) = -0.0;
101
102
MatrixX
Jj;
103
Jj.resize(rows, 3);
104
Jj.fill(0);
105
Jj.block<3, 3>(index, 0) = poseRot;
106
107
_jacobianOplus
[i] = Jj;
108
}
109
110
_jacobianOplus
[0] = Ji;
111
}
112
113
bool
EdgeSE3LotsOfXYZ::read
(std::istream& is) {
114
is >>
_observedPoints
;
115
116
setSize
(
_observedPoints
+ 1);
117
118
// read the measurements
119
for
(
unsigned
int
i = 0; i <
_observedPoints
; i++) {
120
unsigned
int
index = 3 * i;
121
is >>
_measurement
[index] >>
_measurement
[index + 1] >>
122
_measurement
[index + 2];
123
}
124
125
// read the information matrix
126
for
(
unsigned
int
i = 0; i <
_observedPoints
* 3; i++) {
127
// fill the "upper triangle" part of the matrix
128
for
(
unsigned
int
j = i; j <
_observedPoints
* 3; j++) {
129
is >>
information
()(i, j);
130
}
131
132
// fill the lower triangle part
133
for
(
unsigned
int
j = 0; j < i; j++) {
134
information
()(i, j) =
information
()(j, i);
135
}
136
}
137
return
true
;
138
}
139
140
bool
EdgeSE3LotsOfXYZ::write
(std::ostream& os)
const
{
141
// write number of observed points
142
os <<
"|| "
<<
_observedPoints
;
143
144
// write measurements
145
for
(
unsigned
int
i = 0; i <
_observedPoints
; i++) {
146
unsigned
int
index = 3 * i;
147
os <<
" "
<<
_measurement
[index] <<
" "
<<
_measurement
[index + 1] <<
" "
148
<<
_measurement
[index + 2];
149
}
150
151
// write information matrix
152
for
(
unsigned
int
i = 0; i <
_observedPoints
* 3; i++) {
153
for
(
unsigned
int
j = i; j <
_observedPoints
* 3; j++) {
154
os <<
" "
<<
information
()(i, j);
155
}
156
}
157
return
os.good();
158
}
159
160
void
EdgeSE3LotsOfXYZ::initialEstimate
(
const
OptimizableGraph::VertexSet
& fixed,
161
OptimizableGraph::Vertex
* toEstimate) {
162
(void)toEstimate;
163
164
assert(
initialEstimatePossible
(fixed, toEstimate) &&
165
"Bad vertices specified"
);
166
167
VertexSE3
* pose =
static_cast<
VertexSE3
*
>
(
_vertices
[0]);
168
169
#ifdef _MSC_VER
170
std::vector<bool> estimate_this(
_observedPoints
,
true
);
171
#else
172
bool
estimate_this[
_observedPoints
];
173
for
(
unsigned
int
i = 0; i <
_observedPoints
; i++) {
174
estimate_this[i] =
true
;
175
}
176
#endif
177
178
for
(std::set<HyperGraph::Vertex*>::iterator it = fixed.begin();
179
it != fixed.end(); ++it) {
180
for
(
unsigned
int
i = 1; i <
_vertices
.size(); i++) {
181
VertexPointXYZ
* vert =
static_cast<
VertexPointXYZ
*
>
(
_vertices
[i]);
182
if
(vert->
id
() == (*it)->id()) estimate_this[i - 1] =
false
;
183
}
184
}
185
186
for
(
unsigned
int
i = 1; i <
_vertices
.size(); i++) {
187
if
(estimate_this[i - 1]) {
188
unsigned
int
index = 3 * (i - 1);
189
Vector3
submeas(
_measurement
[index],
_measurement
[index + 1],
190
_measurement
[index + 2]);
191
VertexPointXYZ
* vert =
static_cast<
VertexPointXYZ
*
>
(
_vertices
[i]);
192
vert->
setEstimate
(pose->
estimate
() * submeas);
193
}
194
}
195
}
196
197
double
EdgeSE3LotsOfXYZ::initialEstimatePossible
(
198
const
OptimizableGraph::VertexSet
& fixed,
199
OptimizableGraph::Vertex
* toEstimate) {
200
(void)toEstimate;
201
202
for
(std::set<HyperGraph::Vertex*>::iterator it = fixed.begin();
203
it != fixed.end(); ++it) {
204
if
(
_vertices
[0]->
id
() == (*it)->id()) {
205
return
1.0;
206
}
207
}
208
209
return
-1.0;
210
}
211
212
}
// namespace g2o
g2o::BaseEdge< D, VectorX >::information
EIGEN_STRONG_INLINE const InformationType & information() const
Definition
base_edge.h:107
g2o::BaseEdge< D, VectorX >::_measurement
Measurement _measurement
Definition
base_edge.h:146
g2o::BaseEdge< D, VectorX >::_error
ErrorVector _error
Definition
base_edge.h:149
g2o::BaseVariableSizedEdge<-1, VectorX >::BaseVariableSizedEdge
BaseVariableSizedEdge()
Definition
base_variable_sized_edge.h:72
g2o::BaseVariableSizedEdge<-1, VectorX >::resize
virtual void resize(size_t size)
Definition
base_variable_sized_edge.h:138
g2o::BaseVariableSizedEdge<-1, VectorX >::_jacobianOplus
std::vector< JacobianType > _jacobianOplus
Definition
base_variable_sized_edge.h:101
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::EdgeSE3LotsOfXYZ::initialEstimate
virtual void initialEstimate(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
Definition
edge_se3_lotsofxyz.cpp:160
g2o::EdgeSE3LotsOfXYZ::EdgeSE3LotsOfXYZ
EdgeSE3LotsOfXYZ()
Definition
edge_se3_lotsofxyz.cpp:33
g2o::EdgeSE3LotsOfXYZ::write
virtual bool write(std::ostream &os) const
write the vertex to a stream
Definition
edge_se3_lotsofxyz.cpp:140
g2o::EdgeSE3LotsOfXYZ::initialEstimatePossible
virtual double initialEstimatePossible(const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
Definition
edge_se3_lotsofxyz.cpp:197
g2o::EdgeSE3LotsOfXYZ::computeError
virtual void computeError()
Definition
edge_se3_lotsofxyz.cpp:56
g2o::EdgeSE3LotsOfXYZ::setSize
void setSize(int vertices)
Definition
edge_se3_lotsofxyz.h:47
g2o::EdgeSE3LotsOfXYZ::read
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Definition
edge_se3_lotsofxyz.cpp:113
g2o::EdgeSE3LotsOfXYZ::linearizeOplus
virtual void linearizeOplus()
Definition
edge_se3_lotsofxyz.cpp:70
g2o::EdgeSE3LotsOfXYZ::setMeasurementFromState
virtual bool setMeasurementFromState()
Definition
edge_se3_lotsofxyz.cpp:38
g2o::EdgeSE3LotsOfXYZ::_observedPoints
unsigned int _observedPoints
Definition
edge_se3_lotsofxyz.h:41
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::VertexPointXYZ
Vertex for a tracked point in space.
Definition
vertex_pointxyz.h:38
g2o::VertexSE3
3D pose Vertex, represented as an Isometry3
Definition
vertex_se3.h:50
edge_se3_lotsofxyz.h
g2o
Definition
dl_wrapper.cpp:55
g2o::Matrix3
MatrixN< 3 > Matrix3
Definition
eigen_types.h:72
g2o::Vector3
VectorN< 3 > Vector3
Definition
eigen_types.h:51
g2o::VectorX
VectorN< Eigen::Dynamic > VectorX
Definition
eigen_types.h:55
g2o::MatrixX
MatrixN< Eigen::Dynamic > MatrixX
Definition
eigen_types.h:74
Generated on
for g2o by
1.17.0