diff --git a/cartographer_ros/cartographer_ros/assets_writer.cc b/cartographer_ros/cartographer_ros/assets_writer.cc index 66d5d6f..7367ef3 100644 --- a/cartographer_ros/cartographer_ros/assets_writer.cc +++ b/cartographer_ros/cartographer_ros/assets_writer.cc @@ -66,10 +66,8 @@ std::unique_ptr CreatePipelineBuilder( const std::vector& trajectories, const std::string file_prefix) { - const auto file_writer_factory = [file_prefix](const std::string& filename) { - return carto::common::make_unique(file_prefix + - filename); - }; + const auto file_writer_factory = + AssetsWriter::CreateFileWriterFactory(file_prefix); auto builder = carto::common::make_unique(); carto::io::RegisterBuiltInPointsProcessors(trajectories, file_writer_factory, @@ -168,6 +166,12 @@ AssetsWriter::AssetsWriter(const std::string& pose_graph_filename, CreatePipelineBuilder(all_trajectories_, file_prefix); } +void AssetsWriter::RegisterPointsProcessor( + const std::string& name, + cartographer::io::PointsProcessorPipelineBuilder::FactoryFunction factory) { + point_pipeline_builder_->Register(name, factory); +} + void AssetsWriter::Run(const std::string& configuration_directory, const std::string& configuration_basename, const std::string& urdf_filename, @@ -263,4 +267,13 @@ void AssetsWriter::Run(const std::string& configuration_directory, carto::io::PointsProcessor::FlushResult::kRestartStream); } +::cartographer::io::FileWriterFactory AssetsWriter::CreateFileWriterFactory( + const std::string& file_path) { + const auto file_writer_factory = [file_path](const std::string& filename) { + return carto::common::make_unique(file_path + + filename); + }; + return file_writer_factory; +} + } // namespace cartographer_ros diff --git a/cartographer_ros/cartographer_ros/assets_writer.h b/cartographer_ros/cartographer_ros/assets_writer.h index 13ef7cb..3c3bf80 100644 --- a/cartographer_ros/cartographer_ros/assets_writer.h +++ b/cartographer_ros/cartographer_ros/assets_writer.h @@ -33,12 +33,23 @@ class AssetsWriter { const std::vector& bag_filenames, const std::string& output_file_prefix); + // Registers a new PointsProcessor type uniquly identified by 'name' which + // will be created using 'factory'. + void RegisterPointsProcessor( + const std::string& name, + cartographer::io::PointsProcessorPipelineBuilder::FactoryFunction + factory); + // Configures a points processing pipeline and pushes the points from the // bag through the pipeline. void Run(const std::string& configuration_directory, const std::string& configuration_basename, const std::string& urdf_filename, bool use_bag_transforms); + // Creates a FileWriterFactory which creates a FileWriter for storing assets. + static ::cartographer::io::FileWriterFactory CreateFileWriterFactory( + const std::string& file_path); + private: std::vector bag_filenames_; std::vector<::cartographer::mapping::proto::Trajectory> all_trajectories_;