Skip to content

Commit

Permalink
Guess output format in g2o CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerKuemmerle committed Aug 24, 2024
1 parent 0b21e74 commit c0f51d9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions g2o/apps/g2o_cli/g2o.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
#include "g2o/core/estimate_propagator.h"
#include "g2o/core/factory.h"
#include "g2o/core/hyper_dijkstra.h"
#include "g2o/core/io/io_format.h"
#include "g2o/core/optimization_algorithm.h"
#include "g2o/core/optimization_algorithm_factory.h"
#include "g2o/core/robust_kernel.h"
#include "g2o/core/robust_kernel_factory.h"
#include "g2o/core/sparse_optimizer.h"
#include "g2o/core/sparse_optimizer_terminate_action.h"
#include "g2o/stuff/command_args.h"
#include "g2o/stuff/filesys_tools.h"
#include "g2o/stuff/logger.h"
#include "g2o/stuff/macros.h"
#include "g2o/stuff/timeutil.h"
Expand Down Expand Up @@ -691,8 +693,15 @@ int main(int argc, char** argv) {
cerr << "saving to stdout";
optimizer.save(cout);
} else {
cerr << "saving " << outputfilename << " ... ";
optimizer.save(outputfilename.c_str());
const std::string file_extension = g2o::getFileExtension(outputfilename);
g2o::io::Format output_format = g2o::io::Format::kG2O;
if (!file_extension.empty()) {
output_format = g2o::io::formatForFileExtension(file_extension)
.value_or(output_format);
}
cerr << "saving " << outputfilename << " in "
<< g2o::io::to_string(output_format) << " ... ";
optimizer.save(outputfilename.c_str(), output_format);
}
cerr << "done.\n";
}
Expand Down

0 comments on commit c0f51d9

Please sign in to comment.