Convert pose graph 2D example to glog and gflags.
Change-Id: I0ed75a60718ef95199bb36f33d9eb99157d11d40
diff --git a/examples/slam/CMakeLists.txt b/examples/slam/CMakeLists.txt
index a5f12c4..c72aa16 100644
--- a/examples/slam/CMakeLists.txt
+++ b/examples/slam/CMakeLists.txt
@@ -30,7 +30,4 @@
include_directories(./)
add_subdirectory(pose_graph_2d)
-
-if (GFLAGS)
- add_subdirectory(pose_graph_3d)
-endif (GFLAGS)
\ No newline at end of file
+add_subdirectory(pose_graph_3d)
diff --git a/examples/slam/pose_graph_2d/CMakeLists.txt b/examples/slam/pose_graph_2d/CMakeLists.txt
index 5574ad1..d654e8c 100644
--- a/examples/slam/pose_graph_2d/CMakeLists.txt
+++ b/examples/slam/pose_graph_2d/CMakeLists.txt
@@ -28,11 +28,12 @@
#
# Author: vitus@google.com (Michael Vitus)
-add_executable(pose_graph_2d
- angle_local_parameterization.h
- normalize_angle.h
- pose_graph_2d.cc
- pose_graph_2d_error_term.h
- types.h)
-target_link_libraries(pose_graph_2d ceres)
-
+if (GFLAGS)
+ add_executable(pose_graph_2d
+ angle_local_parameterization.h
+ normalize_angle.h
+ pose_graph_2d.cc
+ pose_graph_2d_error_term.h
+ types.h)
+ target_link_libraries(pose_graph_2d ceres ${GFLAGS_LIBRARIES})
+endif (GFLAGS)
\ No newline at end of file
diff --git a/examples/slam/pose_graph_2d/pose_graph_2d.cc b/examples/slam/pose_graph_2d/pose_graph_2d.cc
index 969bdb5..b9374db 100644
--- a/examples/slam/pose_graph_2d/pose_graph_2d.cc
+++ b/examples/slam/pose_graph_2d/pose_graph_2d.cc
@@ -42,9 +42,13 @@
#include "angle_local_parameterization.h"
#include "ceres/ceres.h"
#include "common/read_g2o.h"
+#include "gflags/gflags.h"
+#include "glog/logging.h"
#include "pose_graph_2d_error_term.h"
#include "types.h"
+DEFINE_string(input, "", "The pose graph definition filename in g2o format.");
+
namespace ceres {
namespace examples {
@@ -56,7 +60,7 @@
CHECK(poses != NULL);
CHECK(problem != NULL);
if (constraints.empty()) {
- std::cout << "No constraints, no problem to optimize.\n";
+ LOG(INFO) << "No constraints, no problem to optimize.";
return;
}
@@ -148,37 +152,31 @@
} // namespace ceres
int main(int argc, char** argv) {
- if (argc != 2) {
- std::cerr << "Need to specify the filename to read as the first and only "
- << "argument.\n";
- return -1;
- }
+ google::InitGoogleLogging(argv[0]);
+ CERES_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
+
+ CHECK(FLAGS_input != "") << "Need to specify the filename to read.";
std::map<int, ceres::examples::Pose2d> poses;
std::vector<ceres::examples::Constraint2d> constraints;
- if (!ceres::examples::ReadG2oFile(argv[1], &poses, &constraints)) {
- return -1;
- }
+ CHECK(ceres::examples::ReadG2oFile(FLAGS_input, &poses, &constraints))
+ << "Error reading the file: " << FLAGS_input;
std::cout << "Number of poses: " << poses.size() << '\n';
std::cout << "Number of constraints: " << constraints.size() << '\n';
- if (!ceres::examples::OutputPoses("poses_original.txt", poses)) {
- return -1;
- }
+ CHECK(ceres::examples::OutputPoses("poses_original.txt", poses))
+ << "Error outputting to poses_original.txt";
ceres::Problem problem;
ceres::examples::BuildOptimizationProblem(constraints, &poses, &problem);
- if (!ceres::examples::SolveOptimizationProblem(&problem)) {
- std::cout << "The solve was not successful, exiting.\n";
- return -1;
- }
+ CHECK(ceres::examples::SolveOptimizationProblem(&problem))
+ << "The solve was not successful, exiting.";
- if (!ceres::examples::OutputPoses("poses_optimized.txt", poses)) {
- return -1;
- }
+ CHECK(ceres::examples::OutputPoses("poses_optimized.txt", poses))
+ << "Error outputting to poses_original.txt";
return 0;
}
diff --git a/examples/slam/pose_graph_3d/CMakeLists.txt b/examples/slam/pose_graph_3d/CMakeLists.txt
index 1be4e85..2c5fdc3 100644
--- a/examples/slam/pose_graph_3d/CMakeLists.txt
+++ b/examples/slam/pose_graph_3d/CMakeLists.txt
@@ -28,5 +28,7 @@
#
# Author: vitus@google.com (Michael Vitus)
-add_executable(pose_graph_3d pose_graph_3d.cc)
-target_link_libraries(pose_graph_3d ceres ${GFLAGS_LIBRARIES})
+if (GFLAGS)
+ add_executable(pose_graph_3d pose_graph_3d.cc)
+ target_link_libraries(pose_graph_3d ceres ${GFLAGS_LIBRARIES})
+endif (GFLAGS)
\ No newline at end of file
diff --git a/examples/slam/pose_graph_3d/pose_graph_3d.cc b/examples/slam/pose_graph_3d/pose_graph_3d.cc
index 191758d..dcc85af 100644
--- a/examples/slam/pose_graph_3d/pose_graph_3d.cc
+++ b/examples/slam/pose_graph_3d/pose_graph_3d.cc
@@ -39,8 +39,7 @@
#include "pose_graph_3d_error_term.h"
#include "types.h"
-DEFINE_string(input_filename, "",
- "The pose graph definition filename in g2o format.");
+DEFINE_string(input, "", "The pose graph definition filename in g2o format.");
namespace ceres {
namespace examples {
@@ -148,14 +147,13 @@
google::InitGoogleLogging(argv[0]);
CERES_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
- CHECK(FLAGS_input_filename != "") << "Need to specify the filename to read.";
+ CHECK(FLAGS_input != "") << "Need to specify the filename to read.";
ceres::examples::MapOfPoses poses;
ceres::examples::VectorOfConstraints constraints;
- CHECK(
- ceres::examples::ReadG2oFile(FLAGS_input_filename, &poses, &constraints))
- << "Error reading the file: " << FLAGS_input_filename;
+ CHECK(ceres::examples::ReadG2oFile(FLAGS_input, &poses, &constraints))
+ << "Error reading the file: " << FLAGS_input;
std::cout << "Number of poses: " << poses.size() << '\n';
std::cout << "Number of constraints: " << constraints.size() << '\n';