Apollo
11.0
自动驾驶开放平台
segment_graph.h
浏览该文件的文档.
1
/******************************************************************************
2
* Copyright 2019 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
Copyright (C) 2006 Pedro Felzenszwalb
18
19
This program is free software; you can redistribute it and/or modify
20
it under the terms of the GNU General Public License as published by
21
the Free Software Foundation; either version 2 of the License, or
22
(at your option) any later version.
23
24
This program is distributed in the hope that it will be useful,
25
but WITHOUT ANY WARRANTY; without even the implied warranty of
26
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
GNU General Public License for more details.
28
29
You should have received a copy of the GNU General Public License
30
along with this program; if not, write to the Free Software
31
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
*/
33
34
#pragma once
35
#include <algorithm>
36
#include <cmath>
37
38
#include "
modules/perception/lidar_segmentation/segmentor/ncut_segmentation/common/graph_felzenszwalb/disjoint_set.h
"
39
40
namespace
apollo
{
41
namespace
perception {
42
namespace
lidar {
43
44
// threshold function
45
#define THRESHOLD(size, c) (c / size)
46
47
typedef
struct
{
48
float
w
;
49
int
a
;
50
int
b
;
51
}
edge
;
52
53
bool
operator<
(
const
edge
&a,
const
edge
&b) {
54
return
a.
w
< b.
w
;
55
}
56
66
Universe
*
segment_graph
(
int
num_vertices,
int
num_edges,
edge
*edges,
float
c) {
67
// sort edges by weight
68
std::sort(edges, edges + num_edges);
69
70
// make a disjoint-set forest
71
Universe
*u =
new
Universe
(num_vertices);
72
73
// init thresholds
74
float
*
threshold
=
new
float
[num_vertices];
75
for
(
int
i = 0; i < num_vertices; i++) {
76
threshold
[i] =
THRESHOLD
(1, c);
77
}
78
79
// for each edge, in non-decreasing weight order...
80
for
(
int
i = 0; i < num_edges; i++) {
81
edge
*pedge = &edges[i];
82
83
// components connected by this edge
84
int
a = u->
find
(pedge->
a
);
85
int
b = u->
find
(pedge->
b
);
86
if
(a != b) {
87
if
((pedge->
w
<=
threshold
[a]) && (pedge->
w
<=
threshold
[b])) {
88
u->
join
(a, b);
89
a = u->
find
(a);
90
threshold
[a] = pedge->
w
+
THRESHOLD
(u->
size
(a), c);
91
}
92
}
93
}
94
95
// free up
96
delete
threshold
;
97
return
u;
98
}
99
100
}
// namespace lidar
101
}
// namespace perception
102
}
// namespace apollo
apollo::perception::lidar::Universe
Definition
disjoint_set.h:49
apollo::perception::lidar::Universe::find
int find(int x)
Find parent of x
Definition
disjoint_set.h:104
apollo::perception::lidar::Universe::join
void join(int x, int y)
Join set x and set y
Definition
disjoint_set.h:113
apollo::perception::lidar::Universe::size
int size(int x) const
Get size of set x
Definition
disjoint_set.h:73
disjoint_set.h
apollo::perception::lidar::segment_graph
Universe * segment_graph(int num_vertices, int num_edges, edge *edges, float c)
Segment a graph
Definition
segment_graph.h:66
apollo::perception::lidar::threshold
Image< uchar > * threshold(Image< T > *src, int t)
Threshold image
Definition
imutil.h:79
apollo::perception::lidar::operator<
bool operator<(const edge &a, const edge &b)
Definition
segment_graph.h:53
apollo
class register implement
Definition
arena_queue.h:37
THRESHOLD
#define THRESHOLD(size, c)
Definition
segment_graph.h:45
apollo::perception::lidar::edge
Definition
segment_graph.h:47
apollo::perception::lidar::edge::b
int b
Definition
segment_graph.h:50
apollo::perception::lidar::edge::w
float w
Definition
segment_graph.h:48
apollo::perception::lidar::edge::a
int a
Definition
segment_graph.h:49
modules
perception
lidar_segmentation
segmentor
ncut_segmentation
common
graph_felzenszwalb
segment_graph.h