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