Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 }
00070 }