00001 /* 00002 * Copyright 2016 The Cartographer Authors 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef CARTOGRAPHER_IO_POINTS_PROCESSOR_PIPELINE_BUILDER_H_ 00018 #define CARTOGRAPHER_IO_POINTS_PROCESSOR_PIPELINE_BUILDER_H_ 00019 00020 #include <string> 00021 #include <vector> 00022 00023 #include "absl/container/flat_hash_map.h" 00024 #include "cartographer/common/lua_parameter_dictionary.h" 00025 #include "cartographer/io/file_writer.h" 00026 #include "cartographer/io/points_processor.h" 00027 #include "cartographer/mapping/proto/trajectory.pb.h" 00028 00029 namespace cartographer { 00030 namespace io { 00031 00032 // Builder to create a points processor pipeline out of a Lua configuration. 00033 // You can register all built-in PointsProcessors using 00034 // 'RegisterBuiltInPointsProcessors'. Non-built-in PointsProcessors must define 00035 // a name and a factory method for building itself from a 00036 // LuaParameterDictionary. See the various built-in PointsProcessors for 00037 // examples. 00038 class PointsProcessorPipelineBuilder { 00039 public: 00040 using FactoryFunction = std::function<std::unique_ptr<PointsProcessor>( 00041 common::LuaParameterDictionary*, PointsProcessor* next)>; 00042 00043 PointsProcessorPipelineBuilder(); 00044 00045 PointsProcessorPipelineBuilder(const PointsProcessorPipelineBuilder&) = 00046 delete; 00047 PointsProcessorPipelineBuilder& operator=( 00048 const PointsProcessorPipelineBuilder&) = delete; 00049 00050 // Register a new PointsProcessor type uniquly identified by 'name' which will 00051 // be created using 'factory'. 00052 void Register(const std::string& name, FactoryFunction factory); 00053 00054 std::vector<std::unique_ptr<PointsProcessor>> CreatePipeline( 00055 common::LuaParameterDictionary* dictionary) const; 00056 00057 private: 00058 absl::flat_hash_map<std::string, FactoryFunction> factories_; 00059 }; 00060 00061 // Register all 'PointsProcessor' that ship with Cartographer with this 00062 // 'builder'. 00063 void RegisterBuiltInPointsProcessors( 00064 const std::vector<mapping::proto::Trajectory>& trajectories, 00065 const FileWriterFactory& file_writer_factory, 00066 PointsProcessorPipelineBuilder* builder); 00067 00068 } // namespace io 00069 } // namespace cartographer 00070 00071 #endif // CARTOGRAPHER_IO_POINTS_PROCESSOR_PIPELINE_BUILDER_H_