fixed_ratio_sampler.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 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/common/fixed_ratio_sampler.h"
00018 
00019 #include "glog/logging.h"
00020 
00021 namespace cartographer {
00022 namespace common {
00023 
00024 FixedRatioSampler::FixedRatioSampler(const double ratio) : ratio_(ratio) {
00025   CHECK_GE(ratio, 0.);
00026   LOG_IF(WARNING, ratio == 0.) << "FixedRatioSampler is dropping all data.";
00027   CHECK_LE(ratio, 1.);
00028 }
00029 
00030 FixedRatioSampler::~FixedRatioSampler() {}
00031 
00032 bool FixedRatioSampler::Pulse() {
00033   ++num_pulses_;
00034   if (static_cast<double>(num_samples_) / num_pulses_ < ratio_) {
00035     ++num_samples_;
00036     return true;
00037   }
00038   return false;
00039 }
00040 
00041 std::string FixedRatioSampler::DebugString() {
00042   return std::to_string(num_samples_) + " (" +
00043          std::to_string(100. * num_samples_ / num_pulses_) + "%)";
00044 }
00045 
00046 }  // namespace common
00047 }  // namespace cartographer


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