Apollo  6.0
Open source self driving car software
graph_segmentor.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 
17 #pragma once
18 
19 #include <algorithm>
20 #include <vector>
21 
23 
24 namespace apollo {
25 namespace perception {
26 namespace common {
27 
28 // @brief: graph edge definition
29 struct Edge {
30  float w = 0.0f;
31  int a = 0;
32  int b = 0;
33  // @brief: edge comparison
34  bool operator<(const Edge& other) const { return this->w < other.w; }
35 };
36 
38  public:
39  GraphSegmentor() = default;
40  ~GraphSegmentor() = default;
41 
42  // @brief: initialize thresholds
43  void Init(const float initial_threshold);
44 
45  // @brief: segment a graph, generating a disjoint-set forest
46  // representing the segmentation.
47  // @params[IN] num_vertices: number of vertices in graph.
48  // @params[IN] num_edges: number of edges in graph.
49  // @params[IN] edges: array of Edges.
50  // @params[OUT] need_sort: whether input edges needs to be sorted
51  void SegmentGraph(const int num_vertices, const int num_edges, Edge* edges,
52  bool need_sort = true);
53 
54  // @brief: return the disjoint-set forest as the segmentation result.
55  Universe* mutable_universe() { return &universe_; }
56 
57  const Universe& universe() { return universe_; }
58 
59  private:
60  static const size_t kMaxVerticesNum = 10000;
61  static const size_t kMaxThresholdsNum = 50000;
62  float initial_threshold_ = 0.f;
63  std::vector<float> thresholds_;
64  std::vector<float> thresholds_table_;
65  Universe universe_;
66 }; // class GraphSegmentor
67 
68 } // namespace common
69 } // namespace perception
70 } // namespace apollo
const Universe & universe()
Definition: graph_segmentor.h:57
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
int a
Definition: graph_segmentor.h:31
int b
Definition: graph_segmentor.h:32
Definition: graph_segmentor.h:29
Definition: graph_segmentor.h:37
bool operator<(const Edge &other) const
Definition: graph_segmentor.h:34
bool Init(const char *binary_name)
Definition: disjoint_set.h:28
float w
Definition: graph_segmentor.h:30
Universe * mutable_universe()
Definition: graph_segmentor.h:55