class AlphaModulatedImageSourceTest(ImageSourcesTestBase):
    def setUp(self):
        super(AlphaModulatedImageSourceTest, self).setUp()
        self.raw = numpy.load(
            os.path.join(volumina._testing.__path__[0],
                         'lena.npy')).astype(numpy.uint32)
        self.ars = _ArraySource2d(self.raw)
        self.ims = AlphaModulatedImageSource(
            self.ars, AlphaModulatedLayer(self.ars, QColor(1, 2, 3)))

    def testRequest(self):
        imr = self.ims.request(QRect(0, 0, 512, 512))
        result = imr.wait()
        self.assertTrue(type(result) == QImage)

    def testSetDirty(self):
        def checkAllDirty(rect):
            self.assertTrue(rect.isEmpty())

        def checkDirtyRect(rect):
            self.assertEqual(rect.x(), 34)
            self.assertEqual(rect.y(), 12)
            self.assertEqual(rect.width(), 3)
            self.assertEqual(rect.height(), 22)

        # should mark everything dirty
        self.ims.isDirty.connect(checkAllDirty)
        self.ims.setDirty((slice(34, None), slice(12, 34)))
        self.ims.isDirty.disconnect(checkAllDirty)

        # dirty subrect
        self.ims.isDirty.connect(checkDirtyRect)
        self.ims.setDirty((slice(34, 37), slice(12, 34)))
        self.ims.isDirty.disconnect(checkDirtyRect)
Пример #2
0
class AlphaModulatedImageSourceTest( ImageSourcesTestBase ):
    def setUp( self ):
        super( AlphaModulatedImageSourceTest, self ).setUp()
        self.raw = numpy.load(os.path.join(volumina._testing.__path__[0], 'lena.npy')).astype( numpy.uint32 )
        self.ars = _ArraySource2d(self.raw)
        self.ims = AlphaModulatedImageSource( self.ars, AlphaModulatedLayer( self.ars, QColor(1,2,3) ))

    def testRequest( self ):
        imr = self.ims.request(QRect(0,0,512,512))
        result = imr.wait()
        self.assertTrue(type(result) == QImage)

    def testSetDirty( self ):
        def checkAllDirty( rect ):
            self.assertTrue( rect.isEmpty() )

        def checkDirtyRect( rect ):
            self.assertEqual( rect.x(), 34 )
            self.assertEqual( rect.y(), 12 )
            self.assertEqual( rect.width(), 3 )
            self.assertEqual( rect.height(), 22  )

        # should mark everything dirty
        self.ims.isDirty.connect( checkAllDirty )
        self.ims.setDirty((slice(34,None), slice(12,34)))
        self.ims.isDirty.disconnect( checkAllDirty )

        # dirty subrect
        self.ims.isDirty.connect( checkDirtyRect )
        self.ims.setDirty((slice(34,37), slice(12,34)))
        self.ims.isDirty.disconnect( checkDirtyRect )
Пример #3
0
class AlphaModulatedImageSourceTest2(ImageSourcesTestBase):
    def setUp(self):
        super(AlphaModulatedImageSourceTest2, self).setUp()
        self.raw = numpy.load(
            os.path.join(volumina._testing.__path__[0],
                         "2d_cells_apoptotic_1channel.npy"))[0:512,
                                                             0:512].astype(
                                                                 numpy.uint32)

        self.raw = numpy.ma.masked_array(self.raw,
                                         mask=numpy.zeros(self.raw.shape,
                                                          dtype=bool),
                                         shrink=False)
        self.raw[:1, :] = numpy.ma.masked
        self.raw[-1:, :] = numpy.ma.masked
        self.raw[:, :1] = numpy.ma.masked
        self.raw[:, -1:] = numpy.ma.masked

        self.ars = _ArraySource2d(self.raw)
        self.ims = AlphaModulatedImageSource(
            self.ars, AlphaModulatedLayer(self.ars, QColor(1, 2, 3)))

    def testRequest(self):
        imr = self.ims.request(QRect(0, 0, 512, 512))
        result = imr.wait()
        self.assertTrue(type(result) == QImage)

        result_view = qimage2ndarray.byte_view(result)
        if sys.byteorder == "little":
            self.assertTrue((result_view[:1, :, 3] == 0).all())
            self.assertTrue((result_view[-1:, :, 3] == 0).all())
            self.assertTrue((result_view[:, :1, 3] == 0).all())
            self.assertTrue((result_view[:, -1:, 3] == 0).all())
        else:
            self.assertTrue((result_view[:1, :, 0] == 0).all())
            self.assertTrue((result_view[-1:, :, 0] == 0).all())
            self.assertTrue((result_view[:, :1, 0] == 0).all())
            self.assertTrue((result_view[:, -1:, 0] == 0).all())

    def testSetDirty(self):
        def checkAllDirty(rect):
            self.assertTrue(rect.isEmpty())

        def checkDirtyRect(rect):
            self.assertEqual(rect.x(), 34)
            self.assertEqual(rect.y(), 12)
            self.assertEqual(rect.width(), 3)
            self.assertEqual(rect.height(), 22)

        # should mark everything dirty
        self.ims.isDirty.connect(checkAllDirty)
        self.ims.setDirty((slice(34, None), slice(12, 34)))
        self.ims.isDirty.disconnect(checkAllDirty)

        # dirty subrect
        self.ims.isDirty.connect(checkDirtyRect)
        self.ims.setDirty((slice(34, 37), slice(12, 34)))
        self.ims.isDirty.disconnect(checkDirtyRect)
Пример #4
0
class AlphaModulatedImageSourceTest2( ImageSourcesTestBase ):
    def setUp( self ):
        super( AlphaModulatedImageSourceTest2, self ).setUp()
        self.raw = numpy.load(os.path.join(volumina._testing.__path__[0], 'lena.npy')).astype( numpy.uint32 )

        self.raw = numpy.ma.masked_array(self.raw, mask=numpy.zeros(self.raw.shape, dtype=bool), shrink=False)
        self.raw[:1, :] = numpy.ma.masked
        self.raw[-1:, :] = numpy.ma.masked
        self.raw[:, :1] = numpy.ma.masked
        self.raw[:, -1:] = numpy.ma.masked

        self.ars = _ArraySource2d(self.raw)
        self.ims = AlphaModulatedImageSource( self.ars, AlphaModulatedLayer( self.ars, QColor(1,2,3) ))

    def testRequest( self ):
        imr = self.ims.request(QRect(0,0,512,512))
        def check(result, codon):
            self.assertEqual(codon, "unique")
            self.assertTrue(type(result) == QImage)


            result_view = qimage2ndarray.byte_view(result)
            if sys.byteorder == "little":
                self.assertTrue((result_view[:1, :, 3] == 0).all())
                self.assertTrue((result_view[-1:, :, 3] == 0).all())
                self.assertTrue((result_view[:, :1, 3] == 0).all())
                self.assertTrue((result_view[:, -1:, 3] == 0).all())
            else:
                self.assertTrue((result_view[:1, :, 0] == 0).all())
                self.assertTrue((result_view[-1:, :, 0] == 0).all())
                self.assertTrue((result_view[:, :1, 0] == 0).all())
                self.assertTrue((result_view[:, -1:, 0] == 0).all())

        imr.notify(check, codon="unique")

    def testSetDirty( self ):
        def checkAllDirty( rect ):
            self.assertTrue( rect.isEmpty() )

        def checkDirtyRect( rect ):
            self.assertEqual( rect.x(), 34 )
            self.assertEqual( rect.y(), 12 )
            self.assertEqual( rect.width(), 3 )
            self.assertEqual( rect.height(), 22  )

        # should mark everything dirty
        self.ims.isDirty.connect( checkAllDirty )
        self.ims.setDirty((slice(34,None), slice(12,34)))
        self.ims.isDirty.disconnect( checkAllDirty )

        # dirty subrect
        self.ims.isDirty.connect( checkDirtyRect )
        self.ims.setDirty((slice(34,37), slice(12,34)))
        self.ims.isDirty.disconnect( checkDirtyRect )