solver.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 "solver.h"
28 
29 #include <cstring>
30 #include <algorithm>
31 
32 namespace g2o {
33 
35  _optimizer(0), _x(0), _b(0), _xSize(0), _maxXSize(0),
36  _isLevenberg(false), _additionalVectorSpace(0)
37 {
38 }
39 
41 {
42  delete[] _x;
43  delete[] _b;
44 }
45 
46 void Solver::resizeVector(size_t sx)
47 {
48  size_t oldSize = _xSize;
49  _xSize = sx;
50  sx += _additionalVectorSpace; // allocate some additional space if requested
51  if (_maxXSize < sx) {
52  _maxXSize = 2*sx;
53  delete[] _x;
54  _x = new double[_maxXSize];
55 #ifndef NDEBUG
56  memset(_x, 0, _maxXSize * sizeof(double));
57 #endif
58  if (_b) { // backup the former b, might still be needed for online processing
59  memcpy(_x, _b, oldSize * sizeof(double));
60  delete[] _b;
61  _b = new double[_maxXSize];
62  std::swap(_b, _x);
63  } else {
64  _b = new double[_maxXSize];
65 #ifndef NDEBUG
66  memset(_b, 0, _maxXSize * sizeof(double));
67 #endif
68  }
69  }
70 }
71 
73 {
75 }
76 
78 {
80 }
81 
83 {
85 }
86 
87 } // end namespace
double * _b
Definition: solver.h:137
void setLevenberg(bool levenberg)
Definition: solver.cpp:77
SparseOptimizer * _optimizer
Definition: solver.h:135
size_t _xSize
Definition: solver.h:138
double * _x
Definition: solver.h:136
bool levenberg() const
the system is Levenberg-Marquardt
Definition: solver.h:109
void setAdditionalVectorSpace(size_t s)
Definition: solver.cpp:82
void setOptimizer(SparseOptimizer *optimizer)
Definition: solver.cpp:72
size_t _additionalVectorSpace
Definition: solver.h:140
void resizeVector(size_t sx)
Definition: solver.cpp:46
SparseOptimizer * optimizer() const
the optimizer (graph) on which the solver works
Definition: solver.h:105
bool _isLevenberg
the system we gonna solve is a Levenberg-Marquardt system
Definition: solver.h:139
virtual ~Solver()
Definition: solver.cpp:40
size_t _maxXSize
Definition: solver.h:138


orb_slam2_with_maps_odom
Author(s): teng zhang
autogenerated on Fri Sep 25 2020 03:24:47