Apollo 11.0
自动驾驶开放平台
graph_segmentor.h
浏览该文件的文档.
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
24namespace apollo {
25namespace perception {
26namespace algorithm {
27
28// @brief: graph edge definition
29struct 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 algorithm
69} // namespace perception
70} // namespace apollo
void Init(const float initial_threshold)
void SegmentGraph(const int num_vertices, const int num_edges, Edge *edges, bool need_sort=true)
class register implement
Definition arena_queue.h:37
bool operator<(const Edge &other) const