27 using namespace gtsam;
30 int main(
const int argc,
const char *argv[]) {
31 string kernelType =
"none";
40 maxIterations = atoi(argv[3]);
50 if (kernelType.compare(
"none") == 0) {
51 boost::tie(graph, initial) =
readG2o(g2oFile, is3D);
53 if (kernelType.compare(
"huber") == 0) {
54 std::cout <<
"Using robust kernel: huber " << std::endl;
55 boost::tie(graph, initial) =
58 if (kernelType.compare(
"tukey") == 0) {
59 std::cout <<
"Using robust kernel: tukey " << std::endl;
60 boost::tie(graph, initial) =
66 noiseModel::Diagonal::Variances(
Vector3(1
e-6, 1
e-6, 1
e-8));
68 std::cout <<
"Adding prior on pose 0 " << std::endl;
74 std::cout <<
"User required to perform maximum " << params.
maxIterations 75 <<
" iterations " << std::endl;
78 std::cout <<
"Optimizing the factor graph" << std::endl;
81 std::cout <<
"Optimization complete" << std::endl;
83 std::cout <<
"initial error=" << graph->error(*initial) << std::endl;
84 std::cout <<
"final error=" << graph->error(result) << std::endl;
87 result.
print(
"result");
90 std::cout <<
"Writing results to file: " << outputFile << std::endl;
93 boost::tie(graphNoKernel, initial2) =
readG2o(g2oFile);
94 writeG2o(*graphNoKernel, result, outputFile);
95 std::cout <<
"done! " << std::endl;
void writeG2o(const NonlinearFactorGraph &graph, const Values &estimate, const string &filename)
This function writes a g2o file from NonlinearFactorGraph and a Values structure. ...
virtual const Values & optimize()
NonlinearFactorGraph graph
string findExampleDataFile(const string &name)
boost::shared_ptr< This > shared_ptr
void setVerbosity(const std::string &src)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static SmartStereoProjectionParams params
void print(const std::string &str="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
int main(const int argc, const char *argv[])
GraphAndValues readG2o(const string &g2oFile, const bool is3D, KernelFunctionType kernelFunctionType)
This function parses a g2o file and stores the measurements into a NonlinearFactorGraph and the initi...
utility functions for loading datasets
size_t maxIterations
The maximum iterations to stop iterating (default 100)