g2o
Loading...
Searching...
No Matches
g2o
core
jacobian_workspace.cpp
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, 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 "
jacobian_workspace.h
"
28
29
#include <cassert>
30
#include <cmath>
31
32
#include "
optimizable_graph.h
"
33
34
using namespace
std
;
35
36
namespace
g2o
{
37
38
JacobianWorkspace::JacobianWorkspace
()
39
: _maxNumVertices(-1), _maxDimension(-1) {}
40
41
JacobianWorkspace::~JacobianWorkspace
() {}
42
43
bool
JacobianWorkspace::allocate
() {
44
if
(
_maxNumVertices
<= 0 ||
_maxDimension
<= 0)
return
false
;
45
_workspace
.resize(
_maxNumVertices
);
46
for
(WorkspaceVector::iterator it =
_workspace
.begin();
47
it !=
_workspace
.end(); ++it) {
48
it->resize(
_maxDimension
);
49
it->setZero();
50
}
51
return
true
;
52
}
53
54
void
JacobianWorkspace::setZero
() {
55
for
(
auto
& wp :
_workspace
) wp.setZero();
56
}
57
58
void
JacobianWorkspace::updateSize
(
const
HyperGraph::Edge
* e_,
bool
reset) {
59
if
(reset) {
60
_maxNumVertices
= -1;
61
_maxDimension
= -1;
62
}
63
updateSize
(e_);
64
}
65
66
void
JacobianWorkspace::updateSize
(
const
HyperGraph::Edge
* e_) {
67
const
OptimizableGraph::Edge
* e =
68
static_cast<
const
OptimizableGraph::Edge
*
>
(e_);
69
int
errorDimension = e->
dimension
();
70
int
numVertices = e->
vertices
().size();
71
int
maxDimensionForEdge = -1;
72
73
for
(
const
auto
& vv : e->
vertices
()) {
74
const
OptimizableGraph::Vertex
* v =
75
static_cast<
const
OptimizableGraph::Vertex
*
>
(vv);
76
assert(v &&
"Edge has no vertex assigned"
);
77
maxDimensionForEdge =
78
max(v->
dimension
() * errorDimension, maxDimensionForEdge);
79
}
80
_maxNumVertices
= max(numVertices,
_maxNumVertices
);
81
_maxDimension
= max(maxDimensionForEdge,
_maxDimension
);
82
}
83
84
void
JacobianWorkspace::updateSize
(
const
OptimizableGraph
& graph,
bool
reset) {
85
if
(reset) {
86
_maxNumVertices
= -1;
87
_maxDimension
= -1;
88
}
89
90
for
(OptimizableGraph::EdgeSet::const_iterator it = graph.
edges
().begin();
91
it != graph.
edges
().end(); ++it) {
92
const
OptimizableGraph::Edge
* e =
93
static_cast<
const
OptimizableGraph::Edge
*
>
(*it);
94
updateSize
(e);
95
}
96
}
97
98
void
JacobianWorkspace::updateSize
(
int
numVertices,
int
dimension,
bool
reset) {
99
if
(reset) {
100
_maxNumVertices
= -1;
101
_maxDimension
= -1;
102
}
103
104
_maxNumVertices
= max(numVertices,
_maxNumVertices
);
105
_maxDimension
= max(dimension,
_maxDimension
);
106
}
107
108
}
// namespace g2o
g2o::HyperGraph::Edge
Definition
hyper_graph.h:172
g2o::HyperGraph::Edge::vertices
const VertexContainer & vertices() const
Definition
hyper_graph.h:186
g2o::HyperGraph::edges
const EdgeSet & edges() const
Definition
hyper_graph.h:253
g2o::JacobianWorkspace::~JacobianWorkspace
~JacobianWorkspace()
Definition
jacobian_workspace.cpp:41
g2o::JacobianWorkspace::_maxNumVertices
int _maxNumVertices
Definition
jacobian_workspace.h:104
g2o::JacobianWorkspace::JacobianWorkspace
JacobianWorkspace()
Definition
jacobian_workspace.cpp:38
g2o::JacobianWorkspace::updateSize
void updateSize(const HyperGraph::Edge *e, bool reset)
Definition
jacobian_workspace.cpp:58
g2o::JacobianWorkspace::allocate
bool allocate()
Definition
jacobian_workspace.cpp:43
g2o::JacobianWorkspace::_maxDimension
int _maxDimension
Definition
jacobian_workspace.h:106
g2o::JacobianWorkspace::setZero
void setZero()
Definition
jacobian_workspace.cpp:54
g2o::JacobianWorkspace::_workspace
WorkspaceVector _workspace
the memory pre-allocated for computing the Jacobians
Definition
jacobian_workspace.h:103
g2o::OptimizableGraph::Edge
Definition
optimizable_graph.h:417
g2o::OptimizableGraph::Edge::dimension
int dimension() const
returns the dimensions of the error function
Definition
optimizable_graph.h:518
g2o::OptimizableGraph::Vertex
A general case Vertex for optimization.
Definition
optimizable_graph.h:108
g2o::OptimizableGraph::Vertex::dimension
int dimension() const
dimension of the estimated state belonging to this node
Definition
optimizable_graph.h:348
jacobian_workspace.h
g2o
Definition
dl_wrapper.cpp:55
std
Definition
jet.h:876
optimizable_graph.h
g2o::OptimizableGraph
Definition
optimizable_graph.h:62
Generated on Tue Nov 11 2025 05:18:45 for g2o by
1.9.8