frame_id_filtering_points_processor.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2017 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 
22 #include "glog/logging.h"
23 
24 namespace cartographer {
25 namespace io {
26 
27 std::unique_ptr<FrameIdFilteringPointsProcessor>
30  std::vector<std::string> keep_frames, drop_frames;
31  if (dictionary->HasKey("keep_frames")) {
32  keep_frames =
33  dictionary->GetDictionary("keep_frames")->GetArrayValuesAsStrings();
34  }
35  if (dictionary->HasKey("drop_frames")) {
36  drop_frames =
37  dictionary->GetDictionary("drop_frames")->GetArrayValuesAsStrings();
38  }
39  return common::make_unique<FrameIdFilteringPointsProcessor>(
40  std::unordered_set<std::string>(keep_frames.begin(), keep_frames.end()),
41  std::unordered_set<std::string>(drop_frames.begin(), drop_frames.end()),
42  next);
43 }
44 
46  const std::unordered_set<std::string>& keep_frame_ids,
47  const std::unordered_set<std::string>& drop_frame_ids,
48  PointsProcessor* next)
49  : keep_frame_ids_(keep_frame_ids),
50  drop_frame_ids_(drop_frame_ids),
51  next_(next) {
52  CHECK_NE(keep_frame_ids.empty(), drop_frame_ids.empty())
53  << "You have to specify exactly one of the `keep_frames` property or the "
54  << "`drop_frames` property, but not both at the same time.";
55 }
56 
58  std::unique_ptr<PointsBatch> batch) {
59  if ((!keep_frame_ids_.empty() && keep_frame_ids_.count(batch->frame_id)) ||
60  (!drop_frame_ids_.empty() && !drop_frame_ids_.count(batch->frame_id))) {
61  next_->Process(std::move(batch));
62  }
63 }
64 
66  return next_->Flush();
67 }
68 
69 } // namespace io
70 } // namespace cartographer
virtual void Process(std::unique_ptr< PointsBatch > points_batch)=0
virtual FlushResult Flush()=0
static std::unique_ptr< FrameIdFilteringPointsProcessor > FromDictionary(common::LuaParameterDictionary *dictionary, PointsProcessor *next)
FrameIdFilteringPointsProcessor(const std::unordered_set< std::string > &keep_frame_ids, const std::unordered_set< std::string > &drop_frame_ids, PointsProcessor *next)
std::unique_ptr< LuaParameterDictionary > GetDictionary(const std::string &key)
void Process(std::unique_ptr< PointsBatch > batch) override


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