g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
examples
simple_optimize
simple_optimize.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 <iostream>
28
29
#include "
g2o/core/factory.h
"
30
#include "
g2o/core/optimization_algorithm_factory.h
"
31
#include "
g2o/core/sparse_optimizer.h
"
32
#include "
g2o/stuff/command_args.h
"
33
34
using namespace
std
;
35
using namespace
g2o
;
36
37
// we use the 2D and 3D SLAM types here
38
G2O_USE_TYPE_GROUP
(slam2d);
39
G2O_USE_TYPE_GROUP
(slam3d);
40
G2O_USE_OPTIMIZATION_LIBRARY
(eigen);
41
42
int
main
(
int
argc,
char
** argv) {
43
// Command line parsing
44
int
maxIterations;
45
string
outputFilename;
46
string
inputFilename;
47
CommandArgs
arg;
48
arg.
param
(
"i"
, maxIterations, 10,
49
"perform n iterations, if negative consider the gain"
);
50
arg.
param
(
"o"
, outputFilename,
""
,
"output final version of the graph"
);
51
arg.
paramLeftOver
(
"graph-input"
, inputFilename,
""
,
52
"graph file which will be processed"
);
53
arg.
parseArgs
(argc, argv);
54
55
// NOTE: We skip to fix a vertex here, either this is stored in the file
56
// itself or Levenberg will handle it.
57
58
// create the optimizer to load the data and carry out the optimization
59
SparseOptimizer
optimizer;
60
optimizer.
setVerbose
(
true
);
61
62
// allocate the solver
63
g2o::OptimizationAlgorithmProperty
solverProperty;
64
optimizer.
setAlgorithm
(
65
g2o::OptimizationAlgorithmFactory::instance
()->construct(
"lm_var"
,
66
solverProperty));
67
68
ifstream ifs(inputFilename.c_str());
69
if
(!ifs) {
70
cerr <<
"unable to open "
<< inputFilename << endl;
71
return
1;
72
}
73
optimizer.
load
(ifs);
74
optimizer.
initializeOptimization
();
75
optimizer.
optimize
(maxIterations);
76
77
if
(outputFilename.size() > 0) {
78
if
(outputFilename ==
"-"
) {
79
cerr <<
"saving to stdout"
;
80
optimizer.
save
(cout);
81
}
else
{
82
cerr <<
"saving "
<< outputFilename <<
" ... "
;
83
optimizer.
save
(outputFilename.c_str());
84
}
85
cerr <<
"done."
<< endl;
86
}
87
return
0;
88
}
g2o::CommandArgs
Command line parsing of argc and argv.
Definition
command_args.h:45
g2o::CommandArgs::parseArgs
bool parseArgs(int argc, char **argv, bool exitOnError=true)
Definition
command_args.cpp:106
g2o::CommandArgs::paramLeftOver
void paramLeftOver(const std::string &name, std::string &p, const std::string &defValue, const std::string &desc, bool optional=false)
Definition
command_args.cpp:331
g2o::CommandArgs::param
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
Definition
command_args.cpp:188
g2o::OptimizationAlgorithmFactory::instance
static OptimizationAlgorithmFactory * instance()
return the instance
Definition
optimization_algorithm_factory.cpp:46
g2o::SparseOptimizer
Definition
sparse_optimizer.h:42
g2o::SparseOptimizer::optimize
int optimize(int iterations, bool online=false)
Definition
sparse_optimizer.cpp:381
g2o::SparseOptimizer::setVerbose
void setVerbose(bool verbose)
Definition
sparse_optimizer.cpp:562
g2o::SparseOptimizer::initializeOptimization
virtual bool initializeOptimization(HyperGraph::EdgeSet &eset)
Definition
sparse_optimizer.cpp:277
g2o::SparseOptimizer::setAlgorithm
void setAlgorithm(OptimizationAlgorithm *algorithm)
Definition
sparse_optimizer.cpp:564
command_args.h
factory.h
G2O_USE_TYPE_GROUP
#define G2O_USE_TYPE_GROUP(typeGroupName)
Definition
factory.h:159
main
int main()
Definition
gicp_demo.cpp:44
g2o
Definition
dl_wrapper.cpp:55
std
Definition
jet.h:876
optimization_algorithm_factory.h
G2O_USE_OPTIMIZATION_LIBRARY
#define G2O_USE_OPTIMIZATION_LIBRARY(libraryname)
Definition
optimization_algorithm_factory.h:170
sparse_optimizer.h
g2o::OptimizableGraph::save
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
g2o::OptimizableGraph::load
virtual bool load(std::istream &is)
g2o::OptimizationAlgorithmProperty
describe the properties of a solver
Definition
optimization_algorithm_property.h:39
Generated on
for g2o by
1.17.0