Apollo 11.0
自动驾驶开放平台
apollo::perception::lidar::FloodFill类 参考

#include <flood_fill.h>

apollo::perception::lidar::FloodFill 的协作图:

Public 成员函数

 FloodFill ()=default
 
 FloodFill (float grid_radius, float cell_size)
 
void GetSegments (base::PointFCloudConstPtr cloud, std::vector< std::vector< int > > *segments_indices, std::vector< int > *num_cells_per_segment)
 Get the segments
 
int Pos (float x, float y) const
 Get row and col position
 
bool Pos2d (float x, float y, int *irow, int *jcol) const
 Get row and col position
 
void BuildGrid (base::PointFCloudConstPtr cloud)
 Build grid based on point cloud
 
void SetGridRadius (float grid_radius)
 Set the grid radius
 
void SetCellSize (float cell_size)
 Set the cell size
 
int GetNumRows () const
 Get the number of rows
 
int GetNumCols () const
 Get the number of cols
 
int GetNumCells () const
 Get the number of cells
 
const std::vector< int > & GetPointIdxInGrid () const
 Get the indices of point cloud
 

详细描述

在文件 flood_fill.h 第 28 行定义.

构造及析构函数说明

◆ FloodFill() [1/2]

apollo::perception::lidar::FloodFill::FloodFill ( )
default

◆ FloodFill() [2/2]

apollo::perception::lidar::FloodFill::FloodFill ( float  grid_radius,
float  cell_size 
)
inline

在文件 flood_fill.h 第 31 行定义.

31: _grid_radius(grid_radius), _cell_size(cell_size) {}

成员函数说明

◆ BuildGrid()

void apollo::perception::lidar::FloodFill::BuildGrid ( base::PointFCloudConstPtr  cloud)

Build grid based on point cloud

参数
cloud

在文件 flood_fill.cc 第 55 行定义.

55 {
56 CHECK_GT(_grid_radius, 0.0);
57 CHECK_GT(_cell_size, 0.0);
58 // .1 calculate grid size
59 // max_grid_size = 2.f *_grid_radius /_cell_size;
60 _num_points = static_cast<int>(cloud->size());
61 const double min_grid_radius = _grid_radius / 10.0;
62 float min_x = static_cast<float>(-min_grid_radius);
63 float min_y = static_cast<float>(-min_grid_radius);
64 float max_x = static_cast<float>(min_grid_radius);
65 float max_y = static_cast<float>(min_grid_radius);
66
67 for (size_t i = 0; i < cloud->size(); ++i) {
68 auto pt = (*cloud)[i];
69 max_x = std::max(max_x, pt.x);
70 min_x = std::min(min_x, pt.x);
71 max_y = std::max(max_y, pt.y);
72 min_y = std::min(min_y, pt.y);
73 }
74 CHECK_LE(min_x, max_x);
75 CHECK_LE(min_y, max_y);
76 // .2 move origin to the left bottom corner
77 const float lower_x = std::max(min_x, -_grid_radius);
78 const float lower_y = std::max(min_y, -_grid_radius);
79 const float upper_x = std::min(max_x, _grid_radius);
80 const float upper_y = std::min(max_y, _grid_radius);
81 _offset_x = -lower_x;
82 _offset_y = -lower_y;
83 _grid_num_rows = static_cast<int>(ceil((upper_y - lower_y) / _cell_size)) + 1;
84 _grid_num_cols = static_cast<int>(ceil((upper_x - lower_x) / _cell_size)) + 1;
85 CHECK_GT(_grid_num_rows, 0);
86 CHECK_GT(_grid_num_cols, 0);
87 _grid_size = _grid_num_rows * _grid_num_cols;
88 // .3 locate points into grid
89 _point_cloud_grid_idx.assign(_num_points, -1);
90 _label.assign(_grid_size, kEmptyGridLabel);
91 for (int i = 0; i < _num_points; ++i) {
92 const int idx = Pos((*cloud)[i].x, (*cloud)[i].y);
93 if (idx >= 0) {
94 _point_cloud_grid_idx[i] = idx;
95 _label[idx] = kNonEmptyGridLabel;
96 }
97 }
98}
int Pos(float x, float y) const
Get row and col position
Definition flood_fill.cc:31

◆ GetNumCells()

int apollo::perception::lidar::FloodFill::GetNumCells ( ) const
inline

Get the number of cells

返回
int

在文件 flood_fill.h 第 105 行定义.

105 {
106 return _grid_size;
107 }

◆ GetNumCols()

int apollo::perception::lidar::FloodFill::GetNumCols ( ) const
inline

Get the number of cols

返回
int

在文件 flood_fill.h 第 97 行定义.

97 {
98 return _grid_num_cols;
99 }

◆ GetNumRows()

int apollo::perception::lidar::FloodFill::GetNumRows ( ) const
inline

Get the number of rows

返回
int

在文件 flood_fill.h 第 89 行定义.

89 {
90 return _grid_num_rows;
91 }

◆ GetPointIdxInGrid()

const std::vector< int > & apollo::perception::lidar::FloodFill::GetPointIdxInGrid ( ) const
inline

Get the indices of point cloud

返回
const std::vector<int>&

在文件 flood_fill.h 第 113 行定义.

113 {
114 return _point_cloud_grid_idx;
115 }

◆ GetSegments()

void apollo::perception::lidar::FloodFill::GetSegments ( base::PointFCloudConstPtr  cloud,
std::vector< std::vector< int > > *  segments_indices,
std::vector< int > *  num_cells_per_segment 
)

Get the segments

参数
cloud
segments_indices
num_cells_per_segment

在文件 flood_fill.cc 第 128 行定义.

131 {
132 CHECK_NOTNULL(segments_indices);
133 CHECK_NOTNULL(num_cells_per_segment);
134 // .1 build grid
135 BuildGrid(cloud);
136 // .2 get connected components
137 const int num_segments = GetConnectedComponents();
138 CHECK_GE(num_segments, 0);
139 // .3 write result
140 segments_indices->clear();
141 segments_indices->resize(num_segments);
142 num_cells_per_segment->clear();
143 num_cells_per_segment->resize(num_segments, 0);
144 for (int i = 0; i < _grid_size; ++i) {
145 if (_label[i] != kEmptyGridLabel) {
146 (*num_cells_per_segment)[_label[i]]++;
147 }
148 }
149 for (int i = 0; i < _num_points; ++i) {
150 const int idx = _point_cloud_grid_idx[i];
151 if (idx >= 0) {
152 (*segments_indices)[_label[idx]].push_back(i);
153 }
154 }
155}
void BuildGrid(base::PointFCloudConstPtr cloud)
Build grid based on point cloud
Definition flood_fill.cc:55

◆ Pos()

int apollo::perception::lidar::FloodFill::Pos ( float  x,
float  y 
) const

Get row and col position

参数
x
y
返回
int return -1 if failed, return position if success

在文件 flood_fill.cc 第 31 行定义.

31 {
32 const int irow = static_cast<int>((y + _offset_y) / _cell_size);
33 if (!IsValidRowIndex(irow)) {
34 return -1;
35 }
36 const int jcol = static_cast<int>((x + _offset_x) / _cell_size);
37 if (!IsValidColIndex(jcol)) {
38 return -1;
39 }
40 return irow * _grid_num_cols + jcol;
41}

◆ Pos2d()

bool apollo::perception::lidar::FloodFill::Pos2d ( float  x,
float  y,
int *  irow,
int *  jcol 
) const

Get row and col position

参数
x
y
irowrow position
jcolcol position
返回
true
false

在文件 flood_fill.cc 第 43 行定义.

43 {
44 *irow = static_cast<int>((y + _offset_y) / _cell_size);
45 if (!IsValidRowIndex(*irow)) {
46 return false;
47 }
48 *jcol = static_cast<int>((x + _offset_x) / _cell_size);
49 if (!IsValidColIndex(*jcol)) {
50 return false;
51 }
52 return true;
53}

◆ SetCellSize()

void apollo::perception::lidar::FloodFill::SetCellSize ( float  cell_size)
inline

Set the cell size

参数
cell_size

在文件 flood_fill.h 第 81 行定义.

81 {
82 _cell_size = cell_size;
83 }

◆ SetGridRadius()

void apollo::perception::lidar::FloodFill::SetGridRadius ( float  grid_radius)
inline

Set the grid radius

参数
grid_radius

在文件 flood_fill.h 第 73 行定义.

73 {
74 _grid_radius = grid_radius;
75 }

该类的文档由以下文件生成: