cartographer源码分析(6)-common-histogram.h
来源:互联网 发布:ubuntu安装系统工具包 编辑:程序博客网 时间:2024/06/06 00:05
源码可在https://github.com/learnmoreonce/SLAM 下载
文件:common/histogram.h#ifndef CARTOGRAPHER_COMMON_HISTOGRAM_H_#define CARTOGRAPHER_COMMON_HISTOGRAM_H_#include <map>#include <string>#include <vector>#include "cartographer/common/port.h"namespace cartographer {namespace common {/*Histogram直方图类,提供2个操作:1,Add()添加元素2,ToString(buckets )以字符串的形式输出buckets个直方图信息,bin大小是篮子个数.Histogram只有一个数据成员,用vector<float>表示*/class Histogram { public: void Add(float value); //添加value,可乱序 string ToString(int buckets) const;//分为几块 private: std::vector<float> values_;};} // namespace common} // namespace cartographer#endif // CARTOGRAPHER_COMMON_HISTOGRAM_H_/*测试:若bin为2:[2,1,2,4,5,5]:Count: 6 Min: 1.000000 Max: 5.000000 Mean: 3.166667[1.000000, 3.000000) ########## Count: 3 (50.000000%) Total: 3 (50.000000%)[3.000000, 5.000000] ########## Count: 3 (50.000000%) Total: 6 (100.000000%)若bin为3:[2,1,2,4,5,5,6,7,8]:Count: 10 Min: 1.000000 Max: 8.000000 Mean: 4.500000[1.000000, 3.333333) ###### Count: 3 (30.000000%) Total: 3 (30.000000%)[3.333333, 5.666667) ######## Count: 4 (40.000000%) Total: 7 (70.000000%)[5.666667, 8.000000] ###### Count: 3 (30.000000%) Total: 10 (100.000000%)*/
测试代码histogram_le_test:#include "cartographer/common/math.h"#include "cartographer/common/histogram.h"#include "gtest/gtest.h"namespace cartographer {namespace common {namespace {TEST(Hist, toString) { Histogram hist; hist.Add(2); hist.Add(1); hist.Add(2); hist.Add(4); hist.Add(5); hist.Add(5); hist.Add(5); hist.Add(6); hist.Add(7); hist.Add(8); std::cout<<hist.ToString(3)<<std::endl;}输出信息:Count: 10 Min: 1.000000 Max: 8.000000 Mean: 4.500000[1.000000, 3.333333) ###### Count: 3 (30.000000%) Total: 3 (30.000000%)[3.333333, 5.666667) ######## Count: 4 (40.000000%) Total: 7 (70.000000%)[5.666667, 8.000000] ###### Count: 3 (30.000000%) Total: 10 (100.000000%)
本文发于:
* http://www.jianshu.com/u/9e38d2febec1
* https://zhuanlan.zhihu.com/learnmoreonce
* http://blog.csdn.net/learnmoreonce
* slam源码分析微信公众号:slamcode
阅读全文
0 0
- cartographer源码分析(6)-common-histogram.h
- cartographer源码分析(3)-common-port.h
- cartographer源码分析(4)-common-time.h
- cartographer源码分析(5)-common-rate_time.h
- cartographer源码分析(7)-common-math.h
- cartographer源码分析(8)-common-make_unique.h
- cartographer源码分析(5)-common-fixed_ratio_sampler.h
- cartographer源码分析(9)-common-mutex.h
- cartographer源码分析(10)-common-thread_pool.h
- cartographer源码分析(11)-common-blocking_queue.h
- cartographer源码分析(13)-transform-rigid_transform.h
- cartographer源码分析(14)-transform-transform.h
- cartographer源码分析(15)-transform-transform_interpolation_buffer.h
- cartographer源码分析(17)-sensor-point_cloud.h
- cartographer源码分析(19)-sensor-range_data.h
- cartographer源码分析(20)-sensor-data.h
- cartographer源码分析(21)-sensor-ordered_multi_queue.h
- cartographer源码分析(22)-sensor-collator.h
- Eclipse快捷键及使用技巧
- Android 手机短信验证
- SVM-kernel(1)
- CountDownLatch使用说明
- Handler 机制深入理解(Handler、Looper、MessageQueue)
- cartographer源码分析(6)-common-histogram.h
- 编码规范(变量、结构篇)
- enote笔记语言(4)(ver0.4)——“5w1h2k”分析法
- Django中MVC与MVT设计模式的区别系列之一
- .out文件转bin文件
- Web前端案例_QQ登录界面实现
- springboot +mina配置
- Unity使用Git的行尾设置
- Java中重载和重写的区别