Page MenuHomec4science

test_flood_fill.py
No OneTemporary

File Metadata

Created
Fri, May 17, 05:04

test_flood_fill.py

#!/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