Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
crossroads segmentation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jean-Marie Favreau
crossroads segmentation
Commits
34369a62
Commit
34369a62
authored
1 year ago
by
Jean-Marie Favreau
Browse files
Options
Downloads
Patches
Plain Diff
fill inner holes
parent
25d161fa
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
crseg/__init__.py
+1
-1
1 addition, 1 deletion
crseg/__init__.py
crseg/crossroad.py
+44
-4
44 additions, 4 deletions
crseg/crossroad.py
crseg/region.py
+14
-0
14 additions, 0 deletions
crseg/region.py
with
59 additions
and
5 deletions
crseg/__init__.py
+
1
−
1
View file @
34369a62
__version__
=
'
0.1.2
4
'
__version__
=
'
0.1.2
5
'
This diff is collapsed.
Click to expand it.
crseg/crossroad.py
+
44
−
4
View file @
34369a62
...
...
@@ -46,10 +46,6 @@ class Crossroad(r.Region):
return
"
id: %s, center: %s, #nodes: %s
"
%
(
self
.
id
,
self
.
center
,
len
(
self
.
nodes
))
def
get_geometric_center
(
self
):
bn
=
self
.
boundary_nodes
()
return
[
sum
([
self
.
G
.
nodes
[
i
][
"
x
"
]
for
i
in
bn
])
/
len
(
bn
),
sum
([
self
.
G
.
nodes
[
i
][
"
y
"
]
for
i
in
bn
])
/
len
(
bn
)]
def
get_center
(
self
):
return
self
.
center
...
...
@@ -512,6 +508,46 @@ class Crossroad(r.Region):
if
path
[
len
(
path
)
-
1
]
in
points
and
u
.
Util
.
length_with_shortcut
(
self
.
G
,
path
)
<
self
.
diameter
():
self
.
add_path
(
path
)
# return the connected component outside of the current region
# starting from p, and only if it stays inside the disc (center, radius)
# and to not reach another region.
# Otherwise, it returns None
def
compute_connected_component_if_inside
(
self
,
p
,
center
,
radius
):
result
=
[]
open
=
[
p
]
seen
=
[]
while
len
(
open
)
!=
0
:
pt
=
open
.
pop
()
seen
.
append
(
pt
)
for
nb
in
self
.
G
.
neighbors
(
pt
):
if
not
nb
in
seen
and
not
self
.
has_edge
((
pt
,
nb
)):
if
self
.
G
[
pt
][
nb
][
0
][
r
.
Region
.
label_region
]
==
-
1
:
nb_coord
=
(
self
.
G
.
nodes
[
nb
][
"
x
"
],
self
.
G
.
nodes
[
nb
][
"
y
"
])
if
u
.
Util
.
coords_distance
(
center
,
nb_coord
)
>=
radius
:
return
None
else
:
result
.
append
((
pt
,
nb
))
open
.
append
(
nb
)
else
:
return
None
return
result
def
add_inner_regions
(
self
):
center
=
self
.
get_geometric_center
()
radius
=
self
.
get_geometric_radius
()
bnodes
=
self
.
boundary_nodes
()
# for each boundary point, compute the connected component starting from it.
# if it stays inside the area, consider adding it to the intersection.
for
point
in
bnodes
:
component
=
self
.
compute_connected_component_if_inside
(
point
,
center
,
radius
)
if
component
!=
None
:
for
edge
in
component
:
self
.
add_edge
(
edge
)
# merge all given regions with the current one
def
merge
(
self
,
regions
):
# add nodes and edges from the other regions
...
...
@@ -544,6 +580,10 @@ class Crossroad(r.Region):
# add missing paths (inner paths and paths to boundaries)
def
add_missing_paths
(
self
,
scale
=
2
,
boundaries
=
True
):
# add inner regions
self
.
add_inner_regions
()
# add inner paths
self
.
add_direct_paths_between_nodes
(
self
.
nodes
)
...
...
This diff is collapsed.
Click to expand it.
crseg/region.py
+
14
−
0
View file @
34369a62
...
...
@@ -110,6 +110,20 @@ class Region:
nbEdgesInside
=
len
([
e
for
e
in
self
.
edges
if
e
[
0
]
==
n
or
e
[
1
]
==
n
])
return
nbnb
!=
nbEdgesInside
def
get_geometric_center
(
self
):
bn
=
self
.
boundary_nodes
()
return
[
sum
([
self
.
G
.
nodes
[
i
][
"
x
"
]
for
i
in
bn
])
/
len
(
bn
),
sum
([
self
.
G
.
nodes
[
i
][
"
y
"
]
for
i
in
bn
])
/
len
(
bn
)]
def
get_geometric_radius
(
self
):
center
=
self
.
get_geometric_center
()
result
=
0
for
node
in
self
.
nodes
:
d
=
u
.
Util
.
coords_distance
(
center
,
(
self
.
G
.
nodes
[
node
][
"
x
"
],
self
.
G
.
nodes
[
node
][
"
y
"
]))
if
d
>
result
:
result
=
d
return
result
def
centroid
(
self
):
return
u
.
Util
.
centroid
(
self
.
G
,
self
.
nodes
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment