Apollo  6.0
Open source self driving car software
spp_cluster_list.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 <string>
19 #include <vector>
20 
21 #include "cyber/common/macros.h"
24 
25 namespace apollo {
26 namespace perception {
27 namespace lidar {
28 
30  public:
31  SppClusterList() { clusters_.reserve(kDefaultReserveSize); }
32  // @brief: initialize cluster list
33  // @param [in]: size
34  // @param [in]: sensor_name
35  void Init(size_t size, const std::string& sensor_name = "velodyne64");
36  // @brief: reset cluster list
37  inline void Reset() { clusters_.clear(); }
38  // @brief: resize cluster list
39  // @param [in]: size
40  void resize(size_t size);
41  // @brief: add an 3d point sample
42  // @param [in]: cluster id
43  // @param [in]: 3d point
44  // @param [in]: point height above ground
45  // @param [in]: point id
46  void AddPointSample(size_t cluster_id, const base::PointF& point,
47  float height, uint32_t point_id);
48  // @brief: get clusters data
49  // @return: clusters
50  inline std::vector<SppClusterPtr>& clusters() { return clusters_; }
51  // @brief: get clusters data, const version
52  // @return: clusters
53  inline const std::vector<SppClusterPtr>& clusters() const {
54  return clusters_;
55  }
56  // @brief: get clusters size
57  // @return: cluster size
58  inline size_t size() const { return clusters_.size(); }
59  // @brief: get cluster pointer
60  // @return: cluster pointer
61  inline SppClusterPtr& operator[](int id) { return clusters_[id]; }
62  // @brief: get cluster pointer, const version
63  // @return: cluster pointer
64  inline const SppClusterPtr& operator[](int id) const { return clusters_[id]; }
65  // @brief: merge elements from another cluster list and clear it
66  // @param [in]: another cluster list
67  void Merge(SppClusterList* rhs);
68  // @brief: cut along height axis to split cluster
69  // @param [in]: max gap value in two connected component
70  // @param [in]: start cluster id
71  // @return: cut number in all clusters
72  size_t HeightCut(float max_gap, size_t start_id = 0);
73  // @brief: compute height and split clusters
74  // @param [in]: cluster id
75  // @param [in]: max gap value in two connected component
76  // @return: true if successfully split
77  bool ComputeHeightAndSplitCluster(size_t id, float max_gap);
78  // @brief: remove empty cluster from clusters
79  void RemoveEmptyClusters();
80  // @brief: remove cluster given id
81  void EraseCluster(size_t id);
82  // @brief: assign clusters from label image
84  clusters_ = rhs.GetClusters();
85  return *this;
86  }
87 
88  private:
89  static const size_t kDefaultReserveSize = 500;
90 
91  private:
92  std::vector<SppClusterPtr> clusters_;
93  std::string sensor_name_;
94  DISALLOW_COPY_AND_ASSIGN(SppClusterList);
95 };
96 
97 } // namespace lidar
98 } // namespace perception
99 } // namespace apollo
void AddPointSample(size_t cluster_id, const base::PointF &point, float height, uint32_t point_id)
const std::vector< SppClusterPtr > & clusters() const
Definition: spp_cluster_list.h:53
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
size_t HeightCut(float max_gap, size_t start_id=0)
size_t size() const
Definition: spp_cluster_list.h:58
Definition: point.h:28
SppClusterPtr & operator[](int id)
Definition: spp_cluster_list.h:61
Definition: spp_cluster_list.h:29
SppClusterList()
Definition: spp_cluster_list.h:31
const SppClusterPtr & operator[](int id) const
Definition: spp_cluster_list.h:64
void Init(size_t size, const std::string &sensor_name="velodyne64")
bool ComputeHeightAndSplitCluster(size_t id, float max_gap)
std::vector< SppClusterPtr > & clusters()
Definition: spp_cluster_list.h:50
Definition: spp_label_image.h:32
std::shared_ptr< SppCluster > SppClusterPtr
Definition: spp_cluster.h:131
void Reset()
Definition: spp_cluster_list.h:37
std::vector< SppClusterPtr > & GetClusters()
Definition: spp_label_image.h:86
SppClusterList & operator=(const SppLabelImage &rhs)
Definition: spp_cluster_list.h:83