Apollo  6.0
Open source self driving car software
ground_struct.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 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 <vector>
19 
20 #include "Eigen/Dense"
21 
22 namespace apollo {
23 namespace perception {
24 namespace lidar {
25 
26 struct GroundNode {
27  Eigen::Vector4f params;
28  float confidence = 0.f;
29 };
30 
31 class GroundGrid {
32  public:
33  GroundGrid() = default;
34  ~GroundGrid() = default;
35  GroundGrid(const GroundGrid& rhs) { *this = rhs; }
37  rows_ = rhs.rows_;
38  cols_ = rhs.cols_;
39  size_ = rhs.size_;
40  if (data_.size() != rhs.data_.size()) {
41  data_.resize(rhs.data_.size());
42  }
43  memcpy(data_.data(), rhs.data_.data(), sizeof(GroundNode) * size_);
44  nodes_.resize(rows_);
45  for (int32_t i = 0; i < rows_; ++i) {
46  nodes_[i] = data_.data() + i * cols_;
47  }
48  return *this;
49  }
50  // @brief: initialize ground grid
51  // @param [in]: rows and cols of grid
52  void Init(int32_t rows, int32_t cols) {
53  data_.clear();
54  nodes_.clear();
55  rows_ = rows;
56  cols_ = cols;
57  size_ = rows_ * cols_;
58  data_.resize(size_);
59  nodes_.resize(rows_);
60  for (int i = 0; i < rows_; ++i) {
61  nodes_[i] = data_.data() + i * cols_;
62  }
63  Reset();
64  }
65  // @brief: reset grid
66  void Reset() { memset(data_.data(), 0, sizeof(GroundNode) * data_.size()); }
67  // @brief: whether a coordinate is in grid
68  // @param [in]: row id r, col id c
69  // @return: status
70  bool IsInGrid(int32_t r, int32_t c) {
71  return (r >= 0 && r < rows_ && c >= 0 && c < cols_);
72  }
73  // @brief: row pointer accessor
74  // @param [in]: row id
75  // @return: row pointer
76  GroundNode* operator[](int32_t r) { return nodes_[r]; }
77  // @brief: row pointer accessor(const version)
78  // @param [in]: row id
79  // @return: row pointer
80  const GroundNode* operator[](int32_t r) const { return nodes_[r]; }
81  // @brief: data pointer accessor
82  // @return: data pointer
83  GroundNode* DataPtr() { return data_.data(); }
84  // @brief: data pointer accessor(const version)
85  // @return: data pointer
86  const GroundNode* DataPtr() const { return data_.data(); }
87  // @brief: grid rows accessor
88  // @return: rows
89  int32_t rows() const { return rows_; }
90  // @brief: grid cols accessor
91  // @return: cols
92  int32_t cols() const { return cols_; }
93  // @brief: grid size assessor
94  // @return: size
95  int32_t size() const { return size_; }
96 
97  protected:
98  std::vector<GroundNode> data_;
99  std::vector<GroundNode*> nodes_;
100  int32_t rows_ = 0;
101  int32_t cols_ = 0;
102  int32_t size_ = 0;
103 };
104 
105 } // namespace lidar
106 } // namespace perception
107 } // namespace apollo
GroundNode * operator[](int32_t r)
Definition: ground_struct.h:76
int32_t size() const
Definition: ground_struct.h:95
GroundGrid(const GroundGrid &rhs)
Definition: ground_struct.h:35
int32_t cols_
Definition: ground_struct.h:101
bool IsInGrid(int32_t r, int32_t c)
Definition: ground_struct.h:70
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
float confidence
Definition: ground_struct.h:28
int32_t rows() const
Definition: ground_struct.h:89
void Reset()
Definition: ground_struct.h:66
const GroundNode * operator[](int32_t r) const
Definition: ground_struct.h:80
const GroundNode * DataPtr() const
Definition: ground_struct.h:86
Definition: ground_struct.h:26
int32_t size_
Definition: ground_struct.h:102
Definition: ground_struct.h:31
GroundGrid & operator=(const GroundGrid &rhs)
Definition: ground_struct.h:36
GroundNode * DataPtr()
Definition: ground_struct.h:83
Eigen::Vector4f params
Definition: ground_struct.h:27
void Init(int32_t rows, int32_t cols)
Definition: ground_struct.h:52
int32_t cols() const
Definition: ground_struct.h:92
int32_t rows_
Definition: ground_struct.h:100
std::vector< GroundNode > data_
Definition: ground_struct.h:98
std::vector< GroundNode * > nodes_
Definition: ground_struct.h:99