# Copyright 2017 The Tangram Developers. See the AUTHORS file at the
# top-level directory of this distribution and at
# https://github.com/renatoGarcia/tangram/blob/master/AUTHORS.
#
# This file is part of Tangram.
#
# Tangram 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.
#
# Tangram 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 Tangram in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.

import tangram as tg
import numpy as np


def test_mosaic(img_data):
    reg = np.zeros(shape=img_data.shape[:2], dtype=np.uint8)
    reg[:50, :50] = 1
    reg[:50, 50:100] = 2
    mosaic1 = tg.layer.Mosaic.from_integer_masks(reg,
                                                 labels={1: 'piece_1a', 2: 'piece_2a'})
    mosaic2 = tg.layer.Mosaic.from_integer_masks(reg,
                                                 labels={1: 'piece_1b', 2: 'piece_2b'})
    mw = tg.widget.MainWindow(
        tg.widget.ImageViewer(
            tg.Pixmap(img_data, layers=[mosaic1, mosaic2])
        )
    )

    tg.layer.bind_mosaics([mosaic1, mosaic2], [{'piece_1a', 'piece_1b'},
                                               {'piece_2a', 'piece_2b'}])
