solver.cpp
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
00003 // 
00004 // g2o is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as published
00006 // by the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // g2o is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "solver.h"
00018 
00019 #include <cstring>
00020 #include <algorithm>
00021 
00022 namespace g2o {
00023 
00024 Solver::Solver(SparseOptimizer* optimizer) :
00025   _optimizer(optimizer), _x(0), _b(0), _xSize(0), _maxXSize(0),
00026   _isLevenberg(false), _additionalVectorSpace(0)
00027 {
00028 }
00029 
00030 Solver::~Solver()
00031 {
00032   delete[] _x;
00033   delete[] _b;
00034 }
00035 
00036 void Solver::resizeVector(size_t sx)
00037 {
00038   size_t oldSize = _xSize;
00039   _xSize = sx;
00040   sx += _additionalVectorSpace; // allocate some additional space if requested
00041   if (_maxXSize < sx) {
00042     _maxXSize = 2*sx;
00043     delete[] _x;
00044     _x = new double[_maxXSize];
00045 #ifndef NDEBUG
00046     memset(_x, 0, _maxXSize * sizeof(double));
00047 #endif
00048     if (_b) { // backup the former b, might still be needed for online processing
00049       memcpy(_x, _b, oldSize * sizeof(double));
00050       delete[] _b;
00051       _b = new double[_maxXSize];
00052       std::swap(_b, _x);
00053     } else {
00054       _b = new double[_maxXSize];
00055 #ifndef NDEBUG
00056       memset(_b, 0, _maxXSize * sizeof(double));
00057 #endif
00058     }
00059   }
00060 }
00061 
00062 void Solver::setOptimizer(SparseOptimizer* optimizer)
00063 {
00064   _optimizer = optimizer;
00065 }
00066 
00067 void Solver::setLevenberg(bool levenberg)
00068 {
00069   _isLevenberg = levenberg;
00070 }
00071 
00072 void Solver::setAdditionalVectorSpace(size_t s)
00073 {
00074   _additionalVectorSpace = s;
00075 }
00076 
00077 } // end namespace


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:42