diff --git a/cartographer_ros/cartographer_ros/assets_writer_main.cc b/cartographer_ros/cartographer_ros/assets_writer_main.cc index 91bf114..bc3cc1b 100644 --- a/cartographer_ros/cartographer_ros/assets_writer_main.cc +++ b/cartographer_ros/cartographer_ros/assets_writer_main.cc @@ -63,6 +63,10 @@ DEFINE_string(pose_graph_filename, "", "Proto stream file containing the pose graph."); DEFINE_bool(use_bag_transforms, true, "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 { @@ -114,7 +118,8 @@ std::unique_ptr HandleMessage( void Run(const string& pose_graph_filename, const std::vector& bag_filenames, 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 = carto::common::make_unique( std::vector{configuration_directory}); @@ -133,8 +138,12 @@ void Run(const string& pose_graph_filename, "trajectory in the same order as the correponding trajectories in the " "pose graph proto."; - const auto file_writer_factory = [](const string& filename) { - return carto::common::make_unique(filename); + const string file_prefix = !output_file_prefix.empty() + ? output_file_prefix + : bag_filenames.front() + "_"; + const auto file_writer_factory = [file_prefix](const string& filename) { + return carto::common::make_unique(file_prefix + + filename); }; // This vector must outlive the pipeline. @@ -253,5 +262,5 @@ int main(int argc, char** argv) { FLAGS_pose_graph_filename, cartographer_ros::SplitString(FLAGS_bag_filenames, ','), FLAGS_configuration_directory, FLAGS_configuration_basename, - FLAGS_urdf_filename); + FLAGS_urdf_filename, FLAGS_output_file_prefix); } diff --git a/docs/source/assets_writer.rst b/docs/source/assets_writer.rst index 8c76eec..430c241 100644 --- a/docs/source/assets_writer.rst +++ b/docs/source/assets_writer.rst @@ -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 \ 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 -------------