Apollo 11.0
自动驾驶开放平台
flood_fill.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16#pragma once
17
18#include <algorithm>
19#include <cstdlib>
20#include <vector>
21
23
24namespace apollo {
25namespace perception {
26namespace lidar {
27
28class FloodFill {
29public:
30 FloodFill() = default;
31 FloodFill(float grid_radius, float cell_size) : _grid_radius(grid_radius), _cell_size(cell_size) {}
39 void GetSegments(
41 std::vector<std::vector<int>>* segments_indices,
42 std::vector<int>* num_cells_per_segment);
50 int Pos(float x, float y) const;
61 bool Pos2d(float x, float y, int* irow, int* jcol) const;
73 void SetGridRadius(float grid_radius) {
74 _grid_radius = grid_radius;
75 }
81 void SetCellSize(float cell_size) {
82 _cell_size = cell_size;
83 }
89 int GetNumRows() const {
90 return _grid_num_rows;
91 }
97 int GetNumCols() const {
98 return _grid_num_cols;
99 }
105 int GetNumCells() const {
106 return _grid_size;
107 }
113 const std::vector<int>& GetPointIdxInGrid() const {
114 return _point_cloud_grid_idx;
115 }
116
117private:
118 bool IsValidRowIndex(int i) const {
119 return (i >= 0 && i < _grid_num_rows);
120 }
121 bool IsValidColIndex(int j) const {
122 return (j >= 0 && j < _grid_num_cols);
123 }
124 int GetConnectedComponents();
125 void DfsColoring(int i, int j, int curr_component);
126 float _grid_radius = 0.0;
127 float _cell_size = 0.0;
128 float _offset_x = 0.0;
129 float _offset_y = 0.0;
130 int _grid_num_rows = 0;
131 int _grid_num_cols = 0;
132 int _grid_size = 0;
133 int _num_points = 0;
134 std::vector<int> _point_cloud_grid_idx;
135 std::vector<int> _label;
136};
137} // namespace lidar
138} // namespace perception
139} // namespace apollo
int GetNumCells() const
Get the number of cells
Definition flood_fill.h:105
FloodFill(float grid_radius, float cell_size)
Definition flood_fill.h:31
void SetGridRadius(float grid_radius)
Set the grid radius
Definition flood_fill.h:73
const std::vector< int > & GetPointIdxInGrid() const
Get the indices of point cloud
Definition flood_fill.h:113
bool Pos2d(float x, float y, int *irow, int *jcol) const
Get row and col position
Definition flood_fill.cc:43
int Pos(float x, float y) const
Get row and col position
Definition flood_fill.cc:31
void SetCellSize(float cell_size)
Set the cell size
Definition flood_fill.h:81
int GetNumRows() const
Get the number of rows
Definition flood_fill.h:89
int GetNumCols() const
Get the number of cols
Definition flood_fill.h:97
void GetSegments(base::PointFCloudConstPtr cloud, std::vector< std::vector< int > > *segments_indices, std::vector< int > *num_cells_per_segment)
Get the segments
void BuildGrid(base::PointFCloudConstPtr cloud)
Build grid based on point cloud
Definition flood_fill.cc:55
std::shared_ptr< const PointFCloud > PointFCloudConstPtr
class register implement
Definition arena_queue.h:37