points_processor_pipeline_builder.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
32 #include "cartographer/mapping/proto/trajectory.pb.h"
33 
34 namespace cartographer {
35 namespace io {
36 
37 template <typename PointsProcessorType>
39  PointsProcessorPipelineBuilder* const builder) {
40  builder->Register(
41  PointsProcessorType::kConfigurationFileActionName,
42  [](common::LuaParameterDictionary* const dictionary,
43  PointsProcessor* const next) -> std::unique_ptr<PointsProcessor> {
44  return PointsProcessorType::FromDictionary(dictionary, next);
45  });
46 }
47 
48 template <typename PointsProcessorType>
50  FileWriterFactory file_writer_factory,
51  PointsProcessorPipelineBuilder* const builder) {
52  builder->Register(
53  PointsProcessorType::kConfigurationFileActionName,
54  [file_writer_factory](
55  common::LuaParameterDictionary* const dictionary,
56  PointsProcessor* const next) -> std::unique_ptr<PointsProcessor> {
57  return PointsProcessorType::FromDictionary(file_writer_factory,
58  dictionary, next);
59  });
60 }
61 
63  const mapping::proto::Trajectory& trajectory,
64  FileWriterFactory file_writer_factory,
66  RegisterPlainPointsProcessor<CountingPointsProcessor>(builder);
67  RegisterPlainPointsProcessor<FixedRatioSamplingPointsProcessor>(builder);
68  RegisterPlainPointsProcessor<MinMaxRangeFiteringPointsProcessor>(builder);
69  RegisterPlainPointsProcessor<OutlierRemovingPointsProcessor>(builder);
70  RegisterPlainPointsProcessor<ColoringPointsProcessor>(builder);
71  RegisterPlainPointsProcessor<IntensityToColorPointsProcessor>(builder);
72  RegisterFileWritingPointsProcessor<PcdWritingPointsProcessor>(
73  file_writer_factory, builder);
74  RegisterFileWritingPointsProcessor<PlyWritingPointsProcessor>(
75  file_writer_factory, builder);
76  RegisterFileWritingPointsProcessor<XyzWriterPointsProcessor>(
77  file_writer_factory, builder);
78  RegisterFileWritingPointsProcessor<HybridGridPointsProcessor>(
79  file_writer_factory, builder);
80 
81  // X-Ray is an odd ball since it requires the trajectory to figure out the
82  // different building levels we walked on to separate the images.
83  builder->Register(
85  [&trajectory, file_writer_factory](
86  common::LuaParameterDictionary* const dictionary,
87  PointsProcessor* const next) -> std::unique_ptr<PointsProcessor> {
89  trajectory, file_writer_factory, dictionary, next);
90  });
91 }
92 
93 void PointsProcessorPipelineBuilder::Register(const std::string& name,
94  FactoryFunction factory) {
95  CHECK(factories_.count(name) == 0) << "A points processor named '" << name
96  << "' has already been registered.";
97  factories_[name] = factory;
98 }
99 
101 
102 std::vector<std::unique_ptr<PointsProcessor>>
104  common::LuaParameterDictionary* const dictionary) const {
105  std::vector<std::unique_ptr<PointsProcessor>> pipeline;
106  // The last consumer in the pipeline must exist, so that the one created after
107  // it (and being before it in the pipeline) has a valid 'next' to point to.
108  // The last consumer will just drop all points.
109  pipeline.emplace_back(common::make_unique<NullPointsProcessor>());
110 
111  std::vector<std::unique_ptr<common::LuaParameterDictionary>> configurations =
112  dictionary->GetArrayValuesAsDictionaries();
113 
114  // We construct the pipeline starting at the back.
115  for (auto it = configurations.rbegin(); it != configurations.rend(); it++) {
116  const string action = (*it)->GetString("action");
117  auto factory_it = factories_.find(action);
118  CHECK(factory_it != factories_.end())
119  << "Unknown action '" << action
120  << "'. Did you register the correspoinding PointsProcessor?";
121  pipeline.push_back(factory_it->second(it->get(), pipeline.back().get()));
122  }
123  return pipeline;
124 }
125 
126 } // namespace io
127 } // namespace cartographer
std::function< std::unique_ptr< PointsProcessor >(common::LuaParameterDictionary *, PointsProcessor *next)> FactoryFunction
void RegisterBuiltInPointsProcessors(const mapping::proto::Trajectory &trajectory, FileWriterFactory file_writer_factory, PointsProcessorPipelineBuilder *builder)
std::function< std::unique_ptr< FileWriter >(const string &filename)> FileWriterFactory
Definition: file_writer.h:63
std::vector< std::unique_ptr< LuaParameterDictionary > > GetArrayValuesAsDictionaries()
std::unordered_map< std::string, FactoryFunction > factories_
std::vector< std::unique_ptr< PointsProcessor > > CreatePipeline(common::LuaParameterDictionary *dictionary) const
static std::unique_ptr< XRayPointsProcessor > FromDictionary(const mapping::proto::Trajectory &trajectory, FileWriterFactory file_writer_factory, common::LuaParameterDictionary *dictionary, PointsProcessor *next)
void Register(const std::string &name, FactoryFunction factory)
void RegisterPlainPointsProcessor(PointsProcessorPipelineBuilder *const builder)
transform::Rigid3d FromDictionary(common::LuaParameterDictionary *dictionary)
static constexpr const char * kConfigurationFileActionName
void RegisterFileWritingPointsProcessor(FileWriterFactory file_writer_factory, PointsProcessorPipelineBuilder *const builder)


cartographer
Author(s):
autogenerated on Wed Jun 5 2019 21:57:58