Add a --output_file_prefix option to the asset writer. (#537)

It defaults to using the first bag name, i.e. the files end up next to the input file which is more ergonomic than having them end up in $HOME/.ros.
master
Holger Rapp 2017-10-13 15:36:11 +02:00 committed by GitHub
parent 6a3dc04510
commit 8539e1a601
2 changed files with 15 additions and 5 deletions

View File

@ -63,6 +63,10 @@ DEFINE_string(pose_graph_filename, "",
"Proto stream file containing the pose graph."); "Proto stream file containing the pose graph.");
DEFINE_bool(use_bag_transforms, true, DEFINE_bool(use_bag_transforms, true,
"Whether to read and use the transforms from the bag."); "Whether to read and use the transforms from the bag.");
DEFINE_string(output_file_prefix, "",
"Will be prefixed to all output file names and can be used to "
"define the output directory. If empty, the first bag filename "
"will be used.");
namespace cartographer_ros { namespace cartographer_ros {
namespace { namespace {
@ -114,7 +118,8 @@ std::unique_ptr<carto::io::PointsBatch> HandleMessage(
void Run(const string& pose_graph_filename, void Run(const string& pose_graph_filename,
const std::vector<string>& bag_filenames, const std::vector<string>& bag_filenames,
const string& configuration_directory, const string& configuration_directory,
const string& configuration_basename, const string& urdf_filename) { const string& configuration_basename, const string& urdf_filename,
const string& output_file_prefix) {
auto file_resolver = auto file_resolver =
carto::common::make_unique<carto::common::ConfigurationFileResolver>( carto::common::make_unique<carto::common::ConfigurationFileResolver>(
std::vector<string>{configuration_directory}); std::vector<string>{configuration_directory});
@ -133,8 +138,12 @@ void Run(const string& pose_graph_filename,
"trajectory in the same order as the correponding trajectories in the " "trajectory in the same order as the correponding trajectories in the "
"pose graph proto."; "pose graph proto.";
const auto file_writer_factory = [](const string& filename) { const string file_prefix = !output_file_prefix.empty()
return carto::common::make_unique<carto::io::StreamFileWriter>(filename); ? output_file_prefix
: bag_filenames.front() + "_";
const auto file_writer_factory = [file_prefix](const string& filename) {
return carto::common::make_unique<carto::io::StreamFileWriter>(file_prefix +
filename);
}; };
// This vector must outlive the pipeline. // This vector must outlive the pipeline.
@ -253,5 +262,5 @@ int main(int argc, char** argv) {
FLAGS_pose_graph_filename, FLAGS_pose_graph_filename,
cartographer_ros::SplitString(FLAGS_bag_filenames, ','), cartographer_ros::SplitString(FLAGS_bag_filenames, ','),
FLAGS_configuration_directory, FLAGS_configuration_basename, FLAGS_configuration_directory, FLAGS_configuration_basename,
FLAGS_urdf_filename); FLAGS_urdf_filename, FLAGS_output_file_prefix);
} }

View File

@ -70,7 +70,8 @@ Now we run the assets writer with the `sample configuration file`_ for the 3D ba
bag_filenames:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag \ bag_filenames:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag \
pose_graph_filename:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag.pbstream pose_graph_filename:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag.pbstream
At the time of writing, the generated assets end up in ``~/.ros``. All output files are prefixed by ``--output_file_prefix`` which defaults to the filename of the first bag.
For the last example, if you specify ``points.ply`` in the pipeline configuration file, this will translate to ``${HOME}/Downloads/b3-2016-04-05-14-14-00.bag_points.ply``.
Configuration Configuration
------------- -------------