Apollo 11.0
自动驾驶开放平台
cloud_mask.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
21
22namespace apollo {
23namespace perception {
24namespace lidar {
25
26class CloudMask {
27 public:
28 CloudMask() = default;
29 ~CloudMask() = default;
30
31 // @brief: set mask size and initial value
32 // @param [in]: size, mask size
33 // @param [in]: value, initial value
34 inline void Set(size_t size, int init_value) {
35 mask_.assign(size, init_value);
36 }
37
38 // @brief: fill mask with given value
39 // @param [in]: value
40 inline void Fill(int value) { std::fill(mask_.begin(), mask_.end(), value); }
41
42 // @brief: get mask data
43 // @return: mask data
44 inline const std::vector<int>& mask() const { return mask_; }
45
46 // @brief: overloading [] to get mask element
47 // @param [in]: id
48 // @return: mask element, at id
49 inline int& operator[](int id) { return mask_[id]; }
50
51 // @brief: overloading [] to get mask element, const version
52 // @param [in]: id
53 // @return: mask element, at id
54 inline const int& operator[](int id) const { return mask_[id]; }
55
56 // @brief: get size of mask data
57 // @return: size
58 inline size_t size() const { return mask_.size(); }
59
60 // @brief: clear mask data
61 inline void clear() { mask_.clear(); }
62
63 // @brief: get valid (positive) indices count
64 // @return: count
65 size_t ValidIndicesCount() const;
66
67 // @brief: get valid (positive) indices count
68 // @param [in]: indices
69 // @return: count
70 template <typename IntegerType>
71 size_t ValidIndicesCount(const std::vector<IntegerType>& indices) const;
72
73 // @brief: get valid (positive) point cloud from mask
74 // @param [in]: source point cloud
75 // @param [out]: target point cloud with valid points
76 void GetValidCloud(
78 base::AttributePointCloud<base::PointF>* target_cloud) const;
79
80 // @brief; get valid indices from mask
81 // @param [in]: indices vector
83
84 // @brief: flip the mask data, positive to zero and zero to one
85 // @brief: note, flip twice is not guaranteed to recover the original mask
86 void Flip();
87
88 // @brief: add point indices, base::PointIndices version
89 // @param [in]: indices
90 // @param [in]: value
91 void AddIndices(const base::PointIndices& indices, int value = 1);
92
93 // @brief: add point indices, std::vector<IntegerType> version
94 // @param [in]: indices
95 // @param [in]: value
96 template <typename IntegerType>
97 void AddIndices(const std::vector<IntegerType>& indices, int value = 1);
98
99 // @brief: add point indices of indices
100 // @param [in]: indices
101 // @param [in]: indices of indices (first param)
102 // @param [in]: value
103 void AddIndicesOfIndices(const base::PointIndices& indices,
104 const base::PointIndices& indices_of_indices,
105 int value = 1);
106
107 // @brief: remove point indices, base::PointIndices version
108 // @param [in]: indices
109 void RemoveIndices(const base::PointIndices& indices);
110
111 // @brief: remove point indices, std::vector<IntegerType> version
112 // @param [in]: indices
113 template <typename IntegerType>
114 void RemoveIndices(const std::vector<IntegerType>& indices);
115
116 // @brief: remove point indices of indices
117 // @param [in]: indices
118 // @param [in]: indices of indices (first param)
119 void RemoveIndicesOfIndices(const base::PointIndices& indices,
120 const base::PointIndices& indices_of_indices);
121
122 // @brief: get and store valid (positive) value to another mask
123 // @param [out]: target mask
124 void GetValidMask(CloudMask* rhs) const;
125
126 // @brief: reset source value in mask to target value
127 // @param [in]: source value
128 // @param [in]: target value
129 void ResetValue(int source_value, int target_value);
130
131 std::vector<int> GetValidIndices();
132
133 private:
134 // @brief mask data
135 std::vector<int> mask_;
136
137 // @brief point indices buffer
138 mutable std::vector<int> indices_;
139};
140
141template <typename IntegerType>
142void CloudMask::AddIndices(const std::vector<IntegerType>& indices, int value) {
143 for (auto& id : indices) {
144 mask_[id] = value;
145 }
146}
147
148template <typename IntegerType>
149void CloudMask::RemoveIndices(const std::vector<IntegerType>& indices) {
150 for (auto& id : indices) {
151 mask_[id] = 0;
152 }
153}
154
155template <typename IntegerType>
157 const std::vector<IntegerType>& indices) const {
158 size_t count = 0;
159 for (const auto& id : indices) {
160 if (mask_[id]) {
161 ++count;
162 }
163 }
164 return count;
165}
166
167} // namespace lidar
168} // namespace perception
169} // namespace apollo
void RemoveIndices(const base::PointIndices &indices)
Definition cloud_mask.cc:78
void ResetValue(int source_value, int target_value)
void AddIndices(const base::PointIndices &indices, int value=1)
Definition cloud_mask.cc:66
const int & operator[](int id) const
Definition cloud_mask.h:54
void GetValidCloud(const base::AttributePointCloud< base::PointF > &source_cloud, base::AttributePointCloud< base::PointF > *target_cloud) const
Definition cloud_mask.cc:35
std::vector< int > GetValidIndices()
void AddIndicesOfIndices(const base::PointIndices &indices, const base::PointIndices &indices_of_indices, int value=1)
Definition cloud_mask.cc:70
const std::vector< int > & mask() const
Definition cloud_mask.h:44
void Set(size_t size, int init_value)
Definition cloud_mask.h:34
void RemoveIndicesOfIndices(const base::PointIndices &indices, const base::PointIndices &indices_of_indices)
Definition cloud_mask.cc:82
void GetValidMask(CloudMask *rhs) const
Definition cloud_mask.cc:90
class register implement
Definition arena_queue.h:37