27 using namespace gtsam;
30 int main(
const int argc,
const char *argv[]) {
31 string kernelType =
"none";
32 int maxIterations = 100;
40 maxIterations = atoi(argv[3]);
50 if (kernelType.compare(
"none") == 0) {
51 std::tie(graph, initial) =
readG2o(g2oFile, is3D);
53 if (kernelType.compare(
"huber") == 0) {
54 std::cout <<
"Using robust kernel: huber " << std::endl;
55 std::tie(graph, initial) =
58 if (kernelType.compare(
"tukey") == 0) {
59 std::cout <<
"Using robust kernel: tukey " << std::endl;
60 std::tie(graph, initial) =
66 noiseModel::Diagonal::Variances(
Vector3(1
e-6, 1
e-6, 1
e-8));
67 graph->addPrior(0,
Pose2(), priorModel);
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 std::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 std::string &filename)
This function writes a g2o file from NonlinearFactorGraph and a Values structure. ...
virtual const Values & optimize()
NonlinearFactorGraph graph
static const SmartProjectionParams params
void print(const std::string &str="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
void setVerbosity(const std::string &src)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GraphAndValues readG2o(const std::string &g2oFile, const bool is3D, KernelFunctionType kernelFunctionType)
This function parses a g2o file and stores the measurements into a NonlinearFactorGraph and the initi...
GTSAM_EXPORT std::string findExampleDataFile(const std::string &name)
std::shared_ptr< This > shared_ptr
int main(const int argc, const char *argv[])
utility functions for loading datasets
size_t maxIterations
The maximum iterations to stop iterating (default 100)