Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
562daa01
Commit
562daa01
authored
Oct 29, 2012
by
Davis King
Browse files
Added remove_duplicate_edges().
parent
542d9920
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
32 deletions
+54
-32
dlib/manifold_regularization/graph_creation.h
dlib/manifold_regularization/graph_creation.h
+34
-32
dlib/manifold_regularization/graph_creation_abstract.h
dlib/manifold_regularization/graph_creation_abstract.h
+20
-0
No files found.
dlib/manifold_regularization/graph_creation.h
View file @
562daa01
...
@@ -14,6 +14,36 @@
...
@@ -14,6 +14,36 @@
namespace
dlib
namespace
dlib
{
{
// ----------------------------------------------------------------------------------------
template
<
typename
vector_type
>
void
remove_duplicate_edges
(
vector_type
&
pairs
)
{
if
(
pairs
.
size
()
>
0
)
{
// sort pairs so that we can avoid duplicates in the loop below
std
::
sort
(
pairs
.
begin
(),
pairs
.
end
(),
&
order_by_index
);
// now put edges into temp while avoiding duplicates
vector_type
temp
;
temp
.
reserve
(
pairs
.
size
());
temp
.
push_back
(
pairs
[
0
]);
for
(
unsigned
long
i
=
1
;
i
<
pairs
.
size
();
++
i
)
{
if
(
pairs
[
i
]
!=
pairs
[
i
-
1
])
{
temp
.
push_back
(
pairs
[
i
]);
}
}
temp
.
swap
(
pairs
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
namespace
impl
namespace
impl
...
@@ -104,23 +134,10 @@ namespace dlib
...
@@ -104,23 +134,10 @@ namespace dlib
// now put edges into out while avoiding duplicates
// now put edges into out while avoiding duplicates
if
(
edges
.
size
()
>
0
)
if
(
edges
.
size
()
>
0
)
{
{
// sort the edges so that duplicate edges will be adjacent
remove_duplicate_edges
(
edges
);
std
::
sort
(
edges
.
begin
(),
edges
.
end
(),
&
order_by_index
);
out
.
reserve
(
edges
.
size
());
out
.
push_back
(
edges
[
0
]);
for
(
unsigned
long
i
=
1
;
i
<
edges
.
size
();
++
i
)
{
if
(
edges
[
i
]
!=
edges
[
i
-
1
])
{
out
.
push_back
(
edges
[
i
]);
}
}
// now sort all the edges by distance and take the percent with the smallest distance
// now sort all the edges by distance and take the percent with the smallest distance
std
::
sort
(
out
.
begin
(),
out
.
end
(),
&
order_by_distance
);
std
::
sort
(
edges
.
begin
(),
edges
.
end
(),
&
order_by_distance
);
out
.
swap
(
edges
);
const
unsigned
long
out_size
=
std
::
min
<
unsigned
long
>
((
unsigned
long
)(
num
*
percent
),
edges
.
size
());
const
unsigned
long
out_size
=
std
::
min
<
unsigned
long
>
((
unsigned
long
)(
num
*
percent
),
edges
.
size
());
out
.
assign
(
edges
.
begin
(),
edges
.
begin
()
+
out_size
);
out
.
assign
(
edges
.
begin
(),
edges
.
begin
()
+
out_size
);
...
@@ -267,23 +284,8 @@ namespace dlib
...
@@ -267,23 +284,8 @@ namespace dlib
}
}
// now sort temp so that we can avoid duplicates in the final loop below
remove_duplicate_edges
(
temp
);
std
::
sort
(
temp
.
begin
(),
temp
.
end
(),
&
order_by_index
);
temp
.
swap
(
out
);
// now put edges into out while avoiding duplicates
if
(
temp
.
size
()
>
0
)
{
out
.
reserve
(
temp
.
size
());
out
.
push_back
(
temp
[
0
]);
for
(
unsigned
long
i
=
1
;
i
<
temp
.
size
();
++
i
)
{
if
(
temp
[
i
]
!=
temp
[
i
-
1
])
{
out
.
push_back
(
temp
[
i
]);
}
}
}
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
dlib/manifold_regularization/graph_creation_abstract.h
View file @
562daa01
...
@@ -240,6 +240,26 @@ namespace dlib
...
@@ -240,6 +240,26 @@ namespace dlib
- #pairs.size() == (1-percent)*pairs.size()
- #pairs.size() == (1-percent)*pairs.size()
!*/
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
vector_type
>
void
remove_duplicate_edges
(
vector_type
&
pairs
);
/*!
requires
- vector_type == a type with an interface compatible with std::vector and
it must in turn contain objects with an interface compatible with dlib::sample_pair
ensures
- Removes any duplicate edges from pairs. That is, for all elements of pairs,
A and B, such that A == B, only one of A or B will be in pairs after this
function terminates.
- #pairs.size() <= pairs.size()
- #pairs will be sorted according to order_by_index().
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment