Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F86314826
test_flood_fill.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Oct 5, 18:45
Size
2 KB
Mime Type
text/x-python
Expires
Mon, Oct 7, 18:45 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21266584
Attached To
rTAMAAS tamaas
test_flood_fill.py
View Options
#!/usr/bin/env python
# coding: utf-8
# -----------------------------------------------------------------------------
# @author Lucas Frérot <lucas.frerot@epfl.ch>
#
# @section LICENSE
#
# Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de
# Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
# Solides)
#
# Tamaas is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
from
__future__
import
print_function
,
division
import
tamaas
as
tm
import
numpy
as
np
def
test_flood_fill
():
tm
.
initialize
()
field
=
np
.
zeros
((
18
,
18
))
# Cluster of permeter 18 area 13
field
[
2
:
4
,
3
:
6
]
=
1.
field
[
4
,
4
:
6
]
=
1.
field
[
5
,
5
]
=
1.
field
[
3
:
5
,
6
:
8
]
=
1.
# Cluster of perimeter 8 area 4
field
[
14
:
16
,
3
:
5
]
=
1.
# Cluster of perimeter 20 area 11
field
[
9
:
11
,
8
:
11
]
=
1.
field
[
7
:
9
,
9
]
=
1.
field
[
10
,
11
:
14
]
=
1.
# Cluster of perimeter 18 area 9
field
[
3
:
5
,
14
:
16
]
=
1.
field
[
5
:
10
,
15
]
=
1.
bool_field
=
np
.
zeros_like
(
field
,
np
.
bool
)
bool_field
[
field
>
0
]
=
True
clusters
=
tm
.
FloodFill
.
getClusters
(
bool_field
,
False
)
# Dummy class for clusters
class
dummy
:
def
__init__
(
self
,
area
,
perimeter
):
self
.
area
=
area
self
.
perimeter
=
perimeter
# Solution
ref
=
[
dummy
(
13
,
18
),
dummy
(
9
,
18
),
dummy
(
11
,
20
),
dummy
(
4
,
8
)]
for
x
,
y
in
zip
(
clusters
,
ref
):
assert
x
.
getArea
()
==
y
.
area
tm
.
finalize
()
Event Timeline
Log In to Comment