Apollo 11.0
自动驾驶开放平台
ground_struct.h
浏览该文件的文档.
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
22namespace apollo {
23namespace perception {
24namespace lidar {
25
26struct GroundNode {
27 Eigen::Vector4f params;
28 float confidence = 0.f;
29
30 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
31};
32
34 public:
35 GroundGrid() = default;
36 ~GroundGrid() = default;
37 GroundGrid(const GroundGrid& rhs) { *this = rhs; }
39 rows_ = rhs.rows_;
40 cols_ = rhs.cols_;
41 size_ = rhs.size_;
42 if (data_.size() != rhs.data_.size()) {
43 data_.resize(rhs.data_.size());
44 }
45 memcpy(data_.data(), rhs.data_.data(), sizeof(GroundNode) * size_);
46 nodes_.resize(rows_);
47 for (int32_t i = 0; i < rows_; ++i) {
48 nodes_[i] = data_.data() + i * cols_;
49 }
50 return *this;
51 }
52 // @brief: initialize ground grid
53 // @param [in]: rows and cols of grid
54 void Init(int32_t rows, int32_t cols) {
55 data_.clear();
56 nodes_.clear();
57 rows_ = rows;
58 cols_ = cols;
59 size_ = rows_ * cols_;
60 data_.resize(size_);
61 nodes_.resize(rows_);
62 for (int i = 0; i < rows_; ++i) {
63 nodes_[i] = data_.data() + i * cols_;
64 }
65 Reset();
66 }
67 // @brief: reset grid
68 void Reset() { memset(data_.data(), 0, sizeof(GroundNode) * data_.size()); }
69 // @brief: whether a coordinate is in grid
70 // @param [in]: row id r, col id c
71 // @return: status
72 bool IsInGrid(int32_t r, int32_t c) {
73 return (r >= 0 && r < rows_ && c >= 0 && c < cols_);
74 }
75 // @brief: row pointer accessor
76 // @param [in]: row id
77 // @return: row pointer
78 GroundNode* operator[](int32_t r) { return nodes_[r]; }
79 // @brief: row pointer accessor(const version)
80 // @param [in]: row id
81 // @return: row pointer
82 const GroundNode* operator[](int32_t r) const { return nodes_[r]; }
83 // @brief: data pointer accessor
84 // @return: data pointer
85 GroundNode* DataPtr() { return data_.data(); }
86 // @brief: data pointer accessor(const version)
87 // @return: data pointer
88 const GroundNode* DataPtr() const { return data_.data(); }
89 // @brief: grid rows accessor
90 // @return: rows
91 int32_t rows() const { return rows_; }
92 // @brief: grid cols accessor
93 // @return: cols
94 int32_t cols() const { return cols_; }
95 // @brief: grid size assessor
96 // @return: size
97 int32_t size() const { return size_; }
98
99 protected:
100 std::vector<GroundNode> data_;
101 std::vector<GroundNode*> nodes_;
102 int32_t rows_ = 0;
103 int32_t cols_ = 0;
104 int32_t size_ = 0;
105};
106
107} // namespace lidar
108} // namespace perception
109} // namespace apollo
bool IsInGrid(int32_t r, int32_t c)
std::vector< GroundNode * > nodes_
GroundNode * operator[](int32_t r)
const GroundNode * DataPtr() const
std::vector< GroundNode > data_
GroundGrid & operator=(const GroundGrid &rhs)
void Init(int32_t rows, int32_t cols)
const GroundNode * operator[](int32_t r) const
class register implement
Definition arena_queue.h:37