Apollo  6.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 <numeric>
21 #include <vector>
22 
25 
26 namespace apollo {
27 namespace perception {
28 namespace lidar {
29 
30 enum 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 
40 struct 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 
56 struct 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;
67  float top_z = kDefaultTopZ;
68  size_t points_in_roi = 0;
69 
71  points.reserve(kDefaultReserveSize);
72  point_ids.reserve(kDefaultReserveSize);
73  pixels.reserve(kDefaultReserveSize);
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();
105  type = SppClassType::OTHERS;
106  yaw = 0.f;
107  confidence = 1.f;
108  top_z = kDefaultTopZ;
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 
131 typedef std::shared_ptr<SppCluster> SppClusterPtr;
132 typedef std::shared_ptr<const SppCluster> SppClusterConstPtr;
133 
134 } // namespace lidar
135 } // namespace perception
136 } // namespace apollo
void RemovePoints(const CloudMask &mask)
Definition: spp_cluster.h:112
std::vector< float > class_prob
Definition: spp_cluster.h:63
SppCluster()
Definition: spp_cluster.h:70
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: point.h:28
void AddPointSample(const base::PointF &point, float height, uint32_t point_id)
Definition: spp_cluster.h:77
Definition: spp_cluster.h:56
SppClassType
Definition: spp_cluster.h:30
T x
Definition: point.h:29
void SortPoint()
Definition: spp_cluster.h:83
Definition: spp_cluster.h:40
SppPoint(const base::PointF &point, float height)
Definition: spp_cluster.h:48
Definition: cloud_mask.h:26
T z
Definition: point.h:31
std::shared_ptr< const SppCluster > SppClusterConstPtr
Definition: spp_cluster.h:132
void clear()
Definition: spp_cluster.h:100
std::shared_ptr< SppCluster > SppClusterPtr
Definition: spp_cluster.h:131
std::vector< uint32_t > pixels
Definition: spp_cluster.h:61
std::vector< uint32_t > point_ids
Definition: spp_cluster.h:59
T y
Definition: point.h:30
std::vector< SppPoint > points
Definition: spp_cluster.h:58