Apollo  6.0
Open source self driving car software
flood_fill.h
Go to the documentation of this file.
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 
24 namespace apollo {
25 namespace perception {
26 namespace lidar {
27 
28 class FloodFill {
29  public:
30  FloodFill() = default;
31  FloodFill(float grid_radius, float cell_size)
32  : _grid_radius(grid_radius), _cell_size(cell_size) {}
34  std::vector<std::vector<int>>* segments_indices,
35  std::vector<int>* num_cells_per_segment);
36  // The grids at the boundary are valid.
37  int Pos(float x, float y) const;
38  bool Pos2d(float x, float y, int* irow, int* jcol) const;
40  void SetGridRadius(float grid_radius) { _grid_radius = grid_radius; }
41  void SetCellSize(float cell_size) { _cell_size = cell_size; }
42  int GetNumRows() const { return _grid_num_rows; }
43  int GetNumCols() const { return _grid_num_cols; }
44  int GetNumCells() const { return _grid_size; }
45  const std::vector<int>& GetPointIdxInGrid() const {
46  return _point_cloud_grid_idx;
47  }
48 
49  private:
50  bool IsValidRowIndex(int i) const { return (i >= 0 && i < _grid_num_rows); }
51  bool IsValidColIndex(int j) const { return (j >= 0 && j < _grid_num_cols); }
52  int GetConnectedComponents();
53  void DfsColoring(int i, int j, int curr_component);
54  float _grid_radius = 0.0;
55  float _cell_size = 0.0;
56  float _offset_x = 0.0;
57  float _offset_y = 0.0;
58  int _grid_num_rows = 0;
59  int _grid_num_cols = 0;
60  int _grid_size = 0;
61  int _num_points = 0;
62  std::vector<int> _point_cloud_grid_idx;
63  std::vector<int> _label;
64 };
65 } // namespace lidar
66 } // namespace perception
67 } // namespace apollo
void BuildGrid(base::PointFCloudConstPtr cloud)
bool Pos2d(float x, float y, int *irow, int *jcol) const
int Pos(float x, float y) const
int GetNumCols() const
Definition: flood_fill.h:43
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
int GetNumCells() const
Definition: flood_fill.h:44
std::shared_ptr< const PointFCloud > PointFCloudConstPtr
Definition: point_cloud.h:483
const std::vector< int > & GetPointIdxInGrid() const
Definition: flood_fill.h:45
FloodFill(float grid_radius, float cell_size)
Definition: flood_fill.h:31
void SetGridRadius(float grid_radius)
Definition: flood_fill.h:40
int GetNumRows() const
Definition: flood_fill.h:42
void GetSegments(base::PointFCloudConstPtr cloud, std::vector< std::vector< int >> *segments_indices, std::vector< int > *num_cells_per_segment)
Definition: flood_fill.h:28
void SetCellSize(float cell_size)
Definition: flood_fill.h:41