Apollo 11.0
自动驾驶开放平台
spp_cluster.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 <algorithm>
19#include <memory>
20#include <numeric>
21#include <vector>
22
25
26namespace apollo {
27namespace perception {
28namespace lidar {
29
30enum class SppClassType {
31 OTHERS = 0,
32 SMALLMOT = 1,
33 BIGMOT = 2,
34 CYCLIST = 3,
35 PEDESTRIAN = 4,
36 CONE = 5,
37 MAX_TYPE = 6,
38};
39
40struct SppPoint {
41 float x = 0.f;
42 float y = 0.f;
43 float z = 0.f;
44 float h = 0.f;
45
46 SppPoint() = default;
47
48 SppPoint(const base::PointF& point, float height) {
49 x = point.x;
50 y = point.y;
51 z = point.z;
52 h = height;
53 }
54};
55
56struct SppCluster {
57 // 3d points and ids
58 std::vector<SppPoint> points;
59 std::vector<uint32_t> point_ids;
60 // 2d pixels
61 std::vector<uint32_t> pixels;
62 // class probabilities and type
63 std::vector<float> class_prob;
65 float yaw = 0.f;
66 float confidence = 1.f;
68 size_t points_in_roi = 0;
69
74 class_prob.reserve(static_cast<size_t>(SppClassType::MAX_TYPE));
75 }
76
77 inline void AddPointSample(const base::PointF& point, float height,
78 uint32_t point_id) {
79 points.push_back(SppPoint(point, height));
80 point_ids.push_back(point_id);
81 }
82
83 void SortPoint() {
84 std::vector<int> indices(points.size(), 0);
85 std::iota(indices.begin(), indices.end(), 0);
86 std::sort(indices.begin(), indices.end(),
87 [&](const int lhs, const int rhs) {
88 return points[lhs].z < points[rhs].z;
89 });
90 std::vector<SppPoint> points_target(points.size());
91 std::vector<uint32_t> point_ids_target(points.size());
92 for (size_t i = 0; i < points.size(); ++i) {
93 points_target[i] = points[indices[i]];
94 point_ids_target[i] = point_ids[indices[i]];
95 }
96 points.swap(points_target);
97 point_ids.swap(point_ids_target);
98 }
99
100 inline void clear() {
101 points.clear();
102 point_ids.clear();
103 pixels.clear();
104 class_prob.clear();
106 yaw = 0.f;
107 confidence = 1.f;
109 points_in_roi = 0;
110 }
111
112 inline void RemovePoints(const CloudMask& mask) {
113 size_t valid = 0;
114 for (size_t i = 0; i < point_ids.size(); ++i) {
115 if (mask[point_ids[i]]) {
116 if (valid != i) {
117 point_ids[valid] = point_ids[i];
118 points[valid] = points[i];
119 }
120 ++valid;
121 }
122 }
123 points.resize(valid);
124 point_ids.resize(valid);
125 }
126
127 static const size_t kDefaultReserveSize = 1000;
128 static constexpr float kDefaultTopZ = 50.f;
129};
130
131typedef std::shared_ptr<SppCluster> SppClusterPtr;
132typedef std::shared_ptr<const SppCluster> SppClusterConstPtr;
133
134} // namespace lidar
135} // namespace perception
136} // namespace apollo
std::shared_ptr< const SppCluster > SppClusterConstPtr
std::shared_ptr< SppCluster > SppClusterPtr
class register implement
Definition arena_queue.h:37
void AddPointSample(const base::PointF &point, float height, uint32_t point_id)
Definition spp_cluster.h:77
std::vector< uint32_t > point_ids
Definition spp_cluster.h:59
void RemovePoints(const CloudMask &mask)
std::vector< uint32_t > pixels
Definition spp_cluster.h:61
std::vector< SppPoint > points
Definition spp_cluster.h:58
static const size_t kDefaultReserveSize
static constexpr float kDefaultTopZ
SppPoint(const base::PointF &point, float height)
Definition spp_cluster.h:48