grid_map(五):grid_map函数定义、类型定义学习

一、grid_map_cv函数介绍

1.1 grid_map::GridMapCvConverter::initializeFromImage

        功能:从图像初始化生成栅格地图

        函数简介:

static bool grid_map::GridMapCvConverter::initializeFromImage 	( 	const cv::Mat &  	image,
		const double  	resolution,
		grid_map::GridMap &  	gridMap,
		const grid_map::Position &  	position 
	) 	

Initializes the geometry of a grid map from an image. This changes the geometry of the map and deletes all contents of the layers!

Parameters:
    [in]	image	the image.
    [in]	resolution	the desired resolution of the grid map [m/cell]. 栅格地图需要的分辨率
    [out]	gridMap	the grid map to be initialized. 需要初始化的栅格地图
    [in]	optional)	position the position of the grid map. 
                        --栅格地图的位置-地图的原点的原点在栅格地图对应坐标系中的位置
                        --地图的原点为地图的左下角
                        --注:栅格地图右向为x轴正向,上为y轴正向

Returns:
    true if successful, false otherwise. 

        其中grid_map::Position类型定义如下:

typedef Eigen::Vector2d Position;

        函数定义:

static bool initializeFromImage(const cv::Mat& image, const double resolution,
                                 grid_map::GridMap& gridMap, const grid_map::Position& position)
  {
    const double lengthX = resolution * image.rows;
    const double lengthY = resolution * image.cols;
    Length length(lengthX, lengthY);
    gridMap.setGeometry(length, resolution, position);
    return true;
  }

1.2 grid_map::GridMap::setGeometry

        设置栅格地图在指定坐标系下的位置

void grid_map::GridMap::setGeometry 	( 	const Length &  	length,
		const double  	resolution,
		const Position &  	position = Position::Zero() 
	) 	

Set the geometry of the grid map. Clears all the data. 
设置栅格地图的几何位置,并清除数据

Parameters:
    length	the side lengths in x, and y-direction of the grid map [m].
            --x、y方向的长度
    resolution	the cell size in [m/cell].
                --分辨率
    position	the 2d position of the grid map in the grid map frame [m]. 
                --栅格地图在栅格地图坐标系中的位置

1.3 grid_map::GridMapCvConverter::addLayerFromImage

        利用图像数据给栅格地图添加图层

#添加图层的数据类型,及通道数
template<typename Type_ , int NChannels_>
static bool grid_map::GridMapCvConverter::addLayerFromImage 	( 	const cv::Mat &  	image,
		const std::string &  	layer,
		grid_map::GridMap &  	gridMap,
		const float  	lowerValue = 0.0, //默认值
		const float  	upperValue = 1.0, //默认值
		const double  	alphaThreshold = 0.5  //默认值
	) 		[inline, static]

Adds a layer with data from image. 从图像中添加一个有数据的层

Parameters:
    [in]	image	the image to be added. If it is a color image (bgr or bgra encoding), it will be transformed in a grayscale image. 需要被添加的图像,其中彩色图会转为灰度图
    [in]	layer	the layer that is filled with the image data. 需要添加图像数据的图层
    [out]	gridMap	the grid map to be populated. 被填充的栅格地图
    [in]	optional)	lowerValue value of the layer corresponding to black image pixels.
                        --图层一个栅格中值的最低值-对应图像的黑色像素
    [in]	optional)	upperValue value of the layer corresponding to white image pixels.
                        --图层一个栅格中值的最大值-对应图像的白色像素
                        --图层一个栅格中值的范围应该在[lowerValue,upperValue]之间
    [in]	optional)	alphaThreshold the threshold ([0.0, 1.0]) for the alpha value at which cells in the grid map are marked as empty.
                        --栅格地图某一栅格标记为空时的阈值(这么小的值,应该不是图像像素,是转化后的栅格地图值),改阈值范围为0~1

Returns:
    true if successful, false otherwise. 

1.4 grid_map::GridMap::get

        返回图层数据,后续操作可能会改变图层数据

Matrix & grid_map::GridMap::get 	( 	const std::string &  	layer	) 	

Returns the grid map data for a layer as non-const. Use this method with care!
--返回栅格地图图层数据作为一个非常量,使用这种方法需要注意(是会改变图层数据吗?)

Parameters:
    layer	the name of the layer to be returned. --图层名称

Returns:
    grid map data.  栅格地图格式数据

Exceptions:
    std::out_of_range	if no map layer with name `layer` is present. 
                        --没有该图层时会输出

1.5 const Matrix & grid_map::GridMap::get

        返回图层数据,应该不会改变图层的数据

const Matrix & grid_map::GridMap::get 	( 	const std::string &  	layer	) 	const

Returns the grid map data for a layer as matrix.

Parameters:
    layer	the name of the layer to be returned.

Returns:
    grid map data as matrix. 

Exceptions:
    std::out_of_range	if no map layer with name `layer` is present. 

1.6 grid_map::GridMapRosConverter::toOccupancyGrid

        转换栅格地图指定图层为ros栅格地图数据类型

void grid_map::GridMapRosConverter::toOccupancyGrid 	( 	const grid_map::GridMap &  	gridMap,
		const std::string &  	layer,
		float  	dataMin,
		float  	dataMax,
		nav_msgs::OccupancyGrid &  	occupancyGrid 
	) 		[static]

Parameters:
    [in]	gridMap	the grid map object.
    [in]	layer	the layer that is transformed to the occupancy cell data.
    [in]	dataMin	the minimum value of the grid map data (used to normalize the cell data in [min, max]).
    [in]	dataMax	the maximum value of the grid map data (used to normalize the cell data in [min, max]).
    [out]	occupancyGrid	the message to be populated. 被填充的栅格地图的消息名

1.7 grid_map::GridMap::setTimestamp 

        设置栅格地图的时间戳

void grid_map::GridMap::setTimestamp 	( 	const Time  	timestamp	) 	

Set the timestamp of the grid map.
----设置栅格地图的时间戳(单位:纳秒)

Parameters:
    timestamp	the timestamp to set (in nanoseconds). 

        示例:

global_map.setTimestamp(ros::Time::now().toNSec());

二 grid_map类型定义

2.1  grid_map::Index

        定义为:

typedef Eigen::Array2i Index;

         参考下面,可以为两个int型的元组

template<typename Type >
using 	Eigen::Array2X = Array< Type, 2, Dynamic >

附录:

grid_map_cv官方文档介绍:grid_map_cv: File List 

        进入该网页不能够进行搜索查询,但可以在谷歌以“grid_map::xxx::xx”格式进行搜索

@meng

  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
要将 `data2` 作为 Echarts 折线图的数据源,并使用 `data1` 中的中文名称作为图例显示,可以按照以下步骤进行操作: 1. 安装 Echarts: ```bash npm install echarts --save ``` 2. 在 Vue 的模板中,使用 `echarts` 组件来显示折线图: ```html <template> <div> <div ref="chart" style="width: 600px; height: 400px;"></div> </div> </template> ``` 3. 在 Vue 的 JavaScript 代码中,引入 `echarts` 并定义折线图的配置和数据: ```javascript <script> import echarts from 'echarts'; export default { mounted() { this.initChart(); }, methods: { initChart() { const chart = echarts.init(this.$refs.chart); const xAxisData = data2.map(item => item.time); const seriesData = []; for (let i = 1; i < data1.length; i++) { const fieldName = data1[i].field; const series = { name: data1[i].name, type: 'line', data: data2.map(item => item[fieldName]) }; seriesData.push(series); } const option = { legend: { data: data1.slice(1).map(item => item.name) }, xAxis: { type: 'category', data: xAxisData }, yAxis: { type: 'value' }, series: seriesData }; chart.setOption(option); } } }; </script> ``` 在上述代码中,我们首先引入 `echarts` 库,并在 `mounted` 钩子函数中调用 `initChart` 方法来初始化折线图。 在 `initChart` 方法中,我们首先通过 `map` 方法提取出 `data2` 中的时间作为 X 轴数据,然后遍历 `data1` 中的每个属性(除了时间),构建折线图的数据系列。每个属性对应一个数据系列,其中 `name` 为属性的中文名称,`type` 设置为 `'line'` 表示折线图,`data` 使用 `map` 方法提取出 `data2` 中对应属性的值作为 Y 轴数据。 最后,我们定义了折线图的配置 `option`,其中设置了图例的数据为 `data1` 中除了时间之外的属性名称,并设置了 X 轴和 Y 轴的数据。 确保你已经引入了 Echarts 库,并将上述代码放置在正确的位置,就可以使用 `data2` 作为折线图的数据源,并使用 `data1` 中的中文名称作为图例显示了。根据数据的不同属性,折线图将会显示相应的曲线。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值