frame_id_filtering_points_processor.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 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 #include "cartographer/io/frame_id_filtering_points_processor.h"
00018 
00019 #include "absl/memory/memory.h"
00020 #include "cartographer/common/lua_parameter_dictionary.h"
00021 #include "cartographer/io/points_batch.h"
00022 #include "glog/logging.h"
00023 
00024 namespace cartographer {
00025 namespace io {
00026 
00027 std::unique_ptr<FrameIdFilteringPointsProcessor>
00028 FrameIdFilteringPointsProcessor::FromDictionary(
00029     common::LuaParameterDictionary* dictionary, PointsProcessor* next) {
00030   std::vector<std::string> keep_frames, drop_frames;
00031   if (dictionary->HasKey("keep_frames")) {
00032     keep_frames =
00033         dictionary->GetDictionary("keep_frames")->GetArrayValuesAsStrings();
00034   }
00035   if (dictionary->HasKey("drop_frames")) {
00036     drop_frames =
00037         dictionary->GetDictionary("drop_frames")->GetArrayValuesAsStrings();
00038   }
00039   return absl::make_unique<FrameIdFilteringPointsProcessor>(
00040       absl::flat_hash_set<std::string>(keep_frames.begin(), keep_frames.end()),
00041       absl::flat_hash_set<std::string>(drop_frames.begin(), drop_frames.end()),
00042       next);
00043 }
00044 
00045 FrameIdFilteringPointsProcessor::FrameIdFilteringPointsProcessor(
00046     const absl::flat_hash_set<std::string>& keep_frame_ids,
00047     const absl::flat_hash_set<std::string>& drop_frame_ids,
00048     PointsProcessor* next)
00049     : keep_frame_ids_(keep_frame_ids),
00050       drop_frame_ids_(drop_frame_ids),
00051       next_(next) {
00052   CHECK_NE(keep_frame_ids.empty(), drop_frame_ids.empty())
00053       << "You have to specify exactly one of the `keep_frames` property or the "
00054       << "`drop_frames` property, but not both at the same time.";
00055 }
00056 
00057 void FrameIdFilteringPointsProcessor::Process(
00058     std::unique_ptr<PointsBatch> batch) {
00059   if ((!keep_frame_ids_.empty() && keep_frame_ids_.count(batch->frame_id)) ||
00060       (!drop_frame_ids_.empty() && !drop_frame_ids_.count(batch->frame_id))) {
00061     next_->Process(std::move(batch));
00062   }
00063 }
00064 
00065 PointsProcessor::FlushResult FrameIdFilteringPointsProcessor::Flush() {
00066   return next_->Flush();
00067 }
00068 
00069 }  // namespace io
00070 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35