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 
34 #include "cartographer/mapping/proto/trajectory.pb.h"
35 
36 namespace cartographer {
37 namespace io {
38 
39 template <typename PointsProcessorType>
41  PointsProcessorPipelineBuilder* const builder) {
42  builder->Register(
43  PointsProcessorType::kConfigurationFileActionName,
44  [](common::LuaParameterDictionary* const dictionary,
45  PointsProcessor* const next) -> std::unique_ptr<PointsProcessor> {
46  return PointsProcessorType::FromDictionary(dictionary, next);
47  });
48 }
49 
50 template <typename PointsProcessorType>
52  const FileWriterFactory& file_writer_factory,
53  PointsProcessorPipelineBuilder* const builder) {
54  builder->Register(
55  PointsProcessorType::kConfigurationFileActionName,
56  [file_writer_factory](
57  common::LuaParameterDictionary* const dictionary,
58  PointsProcessor* const next) -> std::unique_ptr<PointsProcessor> {
59  return PointsProcessorType::FromDictionary(file_writer_factory,
60  dictionary, next);
61  });
62 }
63 
64 template <typename PointsProcessorType>
66  const std::vector<mapping::proto::Trajectory>& trajectories,
67  const FileWriterFactory& file_writer_factory,
68  PointsProcessorPipelineBuilder* const builder) {
69  builder->Register(
70  PointsProcessorType::kConfigurationFileActionName,
71  [&trajectories, file_writer_factory](
72  common::LuaParameterDictionary* const dictionary,
73  PointsProcessor* const next) -> std::unique_ptr<PointsProcessor> {
75  trajectories, file_writer_factory, dictionary, next);
76  });
77 }
78 
80  const std::vector<mapping::proto::Trajectory>& trajectories,
81  const FileWriterFactory& file_writer_factory,
83  RegisterPlainPointsProcessor<CountingPointsProcessor>(builder);
84  RegisterPlainPointsProcessor<FixedRatioSamplingPointsProcessor>(builder);
85  RegisterPlainPointsProcessor<FrameIdFilteringPointsProcessor>(builder);
86  RegisterPlainPointsProcessor<MinMaxRangeFiteringPointsProcessor>(builder);
87  RegisterPlainPointsProcessor<OutlierRemovingPointsProcessor>(builder);
88  RegisterPlainPointsProcessor<ColoringPointsProcessor>(builder);
89  RegisterPlainPointsProcessor<IntensityToColorPointsProcessor>(builder);
90  RegisterFileWritingPointsProcessor<PcdWritingPointsProcessor>(
91  file_writer_factory, builder);
92  RegisterFileWritingPointsProcessor<PlyWritingPointsProcessor>(
93  file_writer_factory, builder);
94  RegisterFileWritingPointsProcessor<XyzWriterPointsProcessor>(
95  file_writer_factory, builder);
96  RegisterFileWritingPointsProcessor<HybridGridPointsProcessor>(
97  file_writer_factory, builder);
98  RegisterFileWritingPointsProcessorWithTrajectories<XRayPointsProcessor>(
99  trajectories, file_writer_factory, builder);
101  ProbabilityGridPointsProcessor>(trajectories, file_writer_factory,
102  builder);
103 }
104 
105 void PointsProcessorPipelineBuilder::Register(const std::string& name,
106  FactoryFunction factory) {
107  CHECK(factories_.count(name) == 0) << "A points processor named '" << name
108  << "' has already been registered.";
109  factories_[name] = std::move(factory);
110 }
111 
113 
114 std::vector<std::unique_ptr<PointsProcessor>>
116  common::LuaParameterDictionary* const dictionary) const {
117  std::vector<std::unique_ptr<PointsProcessor>> pipeline;
118  // The last consumer in the pipeline must exist, so that the one created after
119  // it (and being before it in the pipeline) has a valid 'next' to point to.
120  // The last consumer will just drop all points.
121  pipeline.emplace_back(common::make_unique<NullPointsProcessor>());
122 
123  std::vector<std::unique_ptr<common::LuaParameterDictionary>> configurations =
124  dictionary->GetArrayValuesAsDictionaries();
125 
126  // We construct the pipeline starting at the back.
127  for (auto it = configurations.rbegin(); it != configurations.rend(); it++) {
128  const std::string action = (*it)->GetString("action");
129  auto factory_it = factories_.find(action);
130  CHECK(factory_it != factories_.end())
131  << "Unknown action '" << action
132  << "'. Did you register the correspoinding PointsProcessor?";
133  pipeline.push_back(factory_it->second(it->get(), pipeline.back().get()));
134  }
135  return pipeline;
136 }
137 
138 } // namespace io
139 } // namespace cartographer
std::function< std::unique_ptr< PointsProcessor >(common::LuaParameterDictionary *, PointsProcessor *next)> FactoryFunction
std::function< std::unique_ptr< FileWriter >(const std::string &filename)> FileWriterFactory
Definition: file_writer.h:66
void RegisterFileWritingPointsProcessor(const FileWriterFactory &file_writer_factory, PointsProcessorPipelineBuilder *const builder)
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
void Register(const std::string &name, FactoryFunction factory)
void RegisterPlainPointsProcessor(PointsProcessorPipelineBuilder *const builder)
transform::Rigid3d FromDictionary(common::LuaParameterDictionary *dictionary)
void RegisterFileWritingPointsProcessorWithTrajectories(const std::vector< mapping::proto::Trajectory > &trajectories, const FileWriterFactory &file_writer_factory, PointsProcessorPipelineBuilder *const builder)
void RegisterBuiltInPointsProcessors(const std::vector< mapping::proto::Trajectory > &trajectories, const FileWriterFactory &file_writer_factory, PointsProcessorPipelineBuilder *builder)


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58