Apollo 11.0
自动驾驶开放平台
spp_cluster_list.cc
浏览该文件的文档.
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 *****************************************************************************/
17
20
21namespace apollo {
22namespace perception {
23namespace lidar {
24
25void SppClusterList::Init(size_t size, const std::string& sensor_name) {
26 sensor_name_ = sensor_name;
27 clusters_.clear();
28 SppClusterPool::Instance(sensor_name_).BatchGet(size, &clusters_);
29}
30
31void SppClusterList::resize(size_t size) {
32 if (clusters_.size() < size) {
33 SppClusterPool::Instance(sensor_name_)
34 .BatchGet(size - clusters_.size(), &clusters_);
35 } else {
36 clusters_.resize(size);
37 }
38}
39
40void SppClusterList::AddPointSample(size_t cluster_id,
41 const base::PointF& point, float height,
42 uint32_t point_id) {
43 if (clusters_.size() <= cluster_id) {
44 resize(cluster_id + 1);
45 }
46 clusters_[cluster_id]->AddPointSample(point, height, point_id);
47}
48
50 clusters_.reserve(clusters_.size() + rhs->clusters_.size());
51 for (size_t i = 0; i < rhs->size(); ++i) {
52 clusters_.push_back((*rhs)[static_cast<int>(i)]);
53 }
54}
55
56size_t SppClusterList::HeightCut(float max_gap, size_t start_id) {
57 size_t size = clusters_.size();
58 size_t count = 0;
59 for (size_t i = start_id; i < size; ++i) {
60 if (clusters_[i]->points.size() > 0) {
61 if (ComputeHeightAndSplitCluster(i, max_gap)) {
62 ++count;
63 }
64 }
65 }
66 AINFO << "Split " << count << " clusters in 3d";
67 return count;
68}
69
70bool SppClusterList::ComputeHeightAndSplitCluster(size_t id, float max_gap) {
71 if (id >= clusters_.size()) {
72 return false;
73 }
74
75 clusters_[id]->SortPoint();
76 std::vector<SppPoint>& points = clusters_[id]->points;
77 std::vector<uint32_t>& indices = clusters_[id]->point_ids;
78
79 float gap = 0.f;
80 std::vector<size_t> split_indices(1, 0);
81 for (size_t i = 1; i < points.size(); ++i) {
82 if (points[i].h < 0) {
83 continue;
84 }
85 gap = points[i].z - points[i - 1].z;
86 if (gap > max_gap) {
87 split_indices.push_back(i);
88 }
89 }
90 size_t split_num = split_indices.size();
91 if (split_num > 0) {
92 size_t max_index = split_indices.size() - 1;
93 size_t length = points.size() - split_indices.back();
94 size_t max_length = length;
95 for (size_t i = 1; i < split_indices.size(); ++i) {
96 length = split_indices[i] - split_indices[i - 1];
97 if (length > max_length) {
98 max_length = length;
99 max_index = i - 1;
100 }
101 }
102 // the highest split is not stable
103 if (max_index != split_indices.size() - 1) {
104 size_t split_index = split_indices[max_index + 1];
105 points.resize(split_index);
106 indices.resize(split_index);
107 return true;
108 }
109 }
110 return false;
111}
112
114 size_t current = 0;
115 for (size_t i = 0; i < clusters_.size(); ++i) {
116 if (clusters_[i]->points.size() > 0) {
117 if (current != i) {
118 clusters_[current] = clusters_[i];
119 }
120 ++current;
121 }
122 }
123 clusters_.resize(current);
124}
125
127 if (clusters_.size() <= id) {
128 return;
129 }
130 clusters_[id] = clusters_.back();
131 clusters_.resize(clusters_.size() - 1);
132}
133
134} // namespace lidar
135} // namespace perception
136} // namespace apollo
void BatchGet(size_t num, std::vector< std::shared_ptr< ObjectType > > *data) override
static LightObjectPool & Instance(const std::string &sensor_name="velodyne64")
size_t HeightCut(float max_gap, size_t start_id=0)
void AddPointSample(size_t cluster_id, const base::PointF &point, float height, uint32_t point_id)
bool ComputeHeightAndSplitCluster(size_t id, float max_gap)
void Init(size_t size, const std::string &sensor_name="velodyne64")
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37