g2o
Loading...
Searching...
No Matches
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
34using namespace std;
35
36namespace g2o {
37
39 : _maxNumVertices(-1), _maxDimension(-1) {}
40
42
44 if (_maxNumVertices <= 0 || _maxDimension <= 0) return false;
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
55 for (auto& wp : _workspace) wp.setZero();
56}
57
59 if (reset) {
60 _maxNumVertices = -1;
61 _maxDimension = -1;
62 }
63 updateSize(e_);
64}
65
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()) {
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
84void 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
98void 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
const VertexContainer & vertices() const
const EdgeSet & edges() const
void updateSize(const HyperGraph::Edge *e, bool reset)
WorkspaceVector _workspace
the memory pre-allocated for computing the Jacobians
int dimension() const
returns the dimensions of the error function
A general case Vertex for optimization.
int dimension() const
dimension of the estimated state belonging to this node
Definition jet.h:876