27 using namespace gtsam;
29 int main(
const int argc,
const char* argv[]) {
40 std::tie(graph, initial) =
readG2o(g2oFile, is3D);
43 auto priorModel = noiseModel::Diagonal::Variances(
44 (
Vector(6) << 1
e-6, 1
e-6, 1
e-6, 1
e-4, 1
e-4, 1
e-4).finished());
46 for (
const auto key : initial->keys()) {
47 std::cout <<
"Adding prior to g2o file " << std::endl;
49 graph->addPrior(firstKey,
Pose3(), priorModel);
53 std::cout <<
"Optimizing the factor graph" << std::endl;
58 std::cout <<
"Optimization complete" << std::endl;
60 std::cout <<
"initial error=" << graph->error(*initial) << std::endl;
61 std::cout <<
"final error=" << graph->error(result) << std::endl;
64 result.
print(
"result");
67 std::cout <<
"Writing results to file: " << outputFile << std::endl;
70 std::tie(graphNoKernel, initial2) =
readG2o(g2oFile);
71 writeG2o(*graphNoKernel, result, outputFile);
72 std::cout <<
"done! " << std::endl;
const gtsam::Symbol key('X', 0)
void writeG2o(const NonlinearFactorGraph &graph, const Values &estimate, const std::string &filename)
This function writes a g2o file from NonlinearFactorGraph and a Values structure. ...
Matrix marginalCovariance(Key variable) const
virtual const Values & optimize()
std::map< Key, ValueType > extract(const std::function< bool(Key)> &filterFcn=&_truePredicate< Key >) const
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)
static const Pose3 pose(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5))
std::shared_ptr< This > shared_ptr
A class for computing marginals in a NonlinearFactorGraph.
int main(const int argc, const char *argv[])
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
utility functions for loading datasets
std::uint64_t Key
Integer nonlinear key type.
Marginals marginals(graph, result)