예제 #1
0
    def setUp( self ):
        self.GRAY1 = 60
        self.ds1 = ConstantSource( self.GRAY1 )

        self.GRAY2 = 120
        self.ds2 = ConstantSource( self.GRAY2 )

        self.GRAY3 = 190
        self.ds3 = ConstantSource( self.GRAY3 )

        self.layer1 = GrayscaleLayer( self.ds1, normalize = False )
        self.layer1.visible = False
        self.layer1.opacity = 0.1
        self.ims1 = GrayscaleImageSource( self.ds1, self.layer1 )
        self.layer2 = GrayscaleLayer( self.ds2, normalize = False )
        self.layer2.visible = True
        self.layer2.opacity = 0.3
        self.ims2 = GrayscaleImageSource( self.ds2, self.layer2 )
        self.layer3 = GrayscaleLayer( self.ds3, normalize = False )
        self.layer3.visible = True
        self.layer3.opacity = 1.0
        self.ims3 = GrayscaleImageSource( self.ds3, self.layer3 )

        lsm = LayerStackModel()
        lsm.append(self.layer1)
        lsm.append(self.layer2)
        lsm.append(self.layer3)
        self.lsm = lsm
        sims = StackedImageSources( lsm )
        sims.register( self.layer1, self.ims1 )
        sims.register( self.layer2, self.ims2 )
        sims.register( self.layer3, self.ims3 )
        self.sims = sims
예제 #2
0
    def testAddingAndRemovingLayers( self ):
        lsm = LayerStackModel()
        sims = StackedImageSources( lsm )
        ims_view = sims.viewImageSources()
        self.assertEqual(len(lsm), 0)
        self.assertEqual(len(sims), 0)
        self.assertEqual(len(ims_view), 0)

        lsm.append(self.layer1)
        lsm.append(self.layer2)
        sims.register(self.layer1, self.ims1)
        sims.register(self.layer2, self.ims2)
        self.assertEqual(sims.isRegistered(self.layer1), True)
        self.assertEqual(sims.isRegistered(self.layer2), True)
        self.assertEqual(len(lsm), 2)
        self.assertEqual(len(sims), 2)
        self.assertEqual(len(ims_view), 2)
        self.assertEqual(ims_view[0], self.ims2)
        self.assertEqual(ims_view[1], self.ims1)

        lsm.append(self.layer3)
        self.assertEqual(len(lsm), 3)
        self.assertEqual(len(sims), 2)
        self.assertEqual(len(ims_view), 2)
        self.assertEqual(ims_view[0], self.ims2)
        self.assertEqual(ims_view[1], self.ims1)
        self.assertEqual(sims.isRegistered(self.layer1), True)
        self.assertEqual(sims.isRegistered(self.layer2), True)

        lsm.selectRow(1) # layer2
        lsm.deleteSelected()
        self.assertEqual(len(lsm), 2)
        self.assertEqual(len(sims), 1)
        self.assertEqual(len(ims_view), 1)
        self.assertEqual(ims_view[0], self.ims1)
        self.assertEqual(sims.isRegistered(self.layer1), True)
        self.assertEqual(sims.isRegistered(self.layer2), False)

        lsm.selectRow(0) # layer3
        lsm.deleteSelected()
        self.assertEqual(len(lsm), 1)
        self.assertEqual(len(sims), 1)
        self.assertEqual(len(ims_view), 1)
        self.assertEqual(ims_view[0], self.ims1)
        self.assertEqual(sims.isRegistered(self.layer1), True)
        self.assertEqual(sims.isRegistered(self.layer2), False)

        sims.deregister(self.layer1)
        self.assertEqual(len(lsm), 1)
        self.assertEqual(len(sims), 0)
        self.assertEqual(len(ims_view), 0)
        self.assertEqual(sims.isRegistered(self.layer1), False)
        self.assertEqual(sims.isRegistered(self.layer2), False)
예제 #3
0
    def testAddingAndRemovingLayers(self):
        lsm = LayerStackModel()
        sims = StackedImageSources(lsm)
        ims_view = sims.viewImageSources()
        self.assertEqual(len(lsm), 0)
        self.assertEqual(len(sims), 0)
        self.assertEqual(len(ims_view), 0)

        lsm.append(self.layer1)
        lsm.append(self.layer2)
        sims.register(self.layer1, self.ims1)
        sims.register(self.layer2, self.ims2)
        self.assertEqual(sims.isRegistered(self.layer1), True)
        self.assertEqual(sims.isRegistered(self.layer2), True)
        self.assertEqual(len(lsm), 2)
        self.assertEqual(len(sims), 2)
        self.assertEqual(len(ims_view), 2)
        self.assertEqual(ims_view[0], self.ims2)
        self.assertEqual(ims_view[1], self.ims1)

        lsm.append(self.layer3)
        self.assertEqual(len(lsm), 3)
        self.assertEqual(len(sims), 2)
        self.assertEqual(len(ims_view), 2)
        self.assertEqual(ims_view[0], self.ims2)
        self.assertEqual(ims_view[1], self.ims1)
        self.assertEqual(sims.isRegistered(self.layer1), True)
        self.assertEqual(sims.isRegistered(self.layer2), True)

        lsm.selectRow(1)  # layer2
        lsm.deleteSelected()
        self.assertEqual(len(lsm), 2)
        self.assertEqual(len(sims), 1)
        self.assertEqual(len(ims_view), 1)
        self.assertEqual(ims_view[0], self.ims1)
        self.assertEqual(sims.isRegistered(self.layer1), True)
        self.assertEqual(sims.isRegistered(self.layer2), False)

        lsm.selectRow(0)  # layer3
        lsm.deleteSelected()
        self.assertEqual(len(lsm), 1)
        self.assertEqual(len(sims), 1)
        self.assertEqual(len(ims_view), 1)
        self.assertEqual(ims_view[0], self.ims1)
        self.assertEqual(sims.isRegistered(self.layer1), True)
        self.assertEqual(sims.isRegistered(self.layer2), False)

        sims.deregister(self.layer1)
        self.assertEqual(len(lsm), 1)
        self.assertEqual(len(sims), 0)
        self.assertEqual(len(ims_view), 0)
        self.assertEqual(sims.isRegistered(self.layer1), False)
        self.assertEqual(sims.isRegistered(self.layer2), False)
예제 #4
0
    class ImageScene2D_LazyTest(ut.TestCase):
        def setUp(self):
            self.layerstack = LayerStackModel()
            self.sims = StackedImageSources(self.layerstack)

            self.g = Graph()
            self.op = OpLazy(self.g)
            self.ds = LazyflowSource(self.op.Output)

            self.ss = SliceSource(self.ds, projectionAlongTZC)

            self.layer = GrayscaleLayer(self.ds, normalize=False)
            self.layerstack.append(self.layer)
            self.ims = imsfac.createImageSource(self.layer, [self.ss])
            self.sims.register(self.layer, self.ims)

            self.scene = ImageScene2D(PositionModel(), (0, 0, 0), preemptive_fetch_number=0)
            self.scene.setCacheSize(1)

            self.scene.stackedImageSources = self.sims
            self.scene.dataShape = (30, 30)

        def renderScene(self, s, exportFilename=None, joinRendering=True):
            img = QImage(30, 30, QImage.Format_ARGB32_Premultiplied)
            img.fill(Qt.white)
            p = QPainter(img)

            s.render(p)  # trigger a rendering of the whole scene
            if joinRendering:
                # wait for all the data to arrive
                s.joinRenderingAllTiles(viewport_only=False)  # There is no viewport!
                # finally, render everything
                s.render(p)
            p.end()

            if exportFilename is not None:
                img.save(exportFilename)
            return byte_view(img)

        def testLazy(self):
            for i in range(3):
                self.op.setConstant(i)
                aimg = self.renderScene(self.scene, "/tmp/a_%03d.png" % i)
                assert numpy.all(aimg[:, :, 0] == i), "!= %d, [0,0,0]=%d" % (i, aimg[0, 0, 0])

                self.op.setConstant(42)
                self.op.setDelay(1)
                aimg = self.renderScene(self.scene, joinRendering=False, exportFilename="/tmp/x_%03d.png" % i)
                # this should be "i", not 255 (the default background for the imagescene)
                assert numpy.all(aimg[:, :, 0] == i), "!= %d, [0,0,0]=%d" % (i, aimg[0, 0, 0])

                # Now give the scene time to update before we change it again...
                self.scene.joinRenderingAllTiles(viewport_only=False)
예제 #5
0
    def testRegisterAndDeregister( self ):
        lsm = LayerStackModel()
        sims = StackedImageSources( lsm )
        self.assertEqual( len(lsm), 0 )
        self.assertEqual( len(sims), 0 )

        lsm.append(self.layer1)
        lsm.append(self.layer2)
        lsm.append(self.layer3)
        self.assertEqual( lsm.layerIndex(self.layer1), 2 )
        self.assertEqual( lsm.layerIndex(self.layer2), 1 )
        self.assertEqual( lsm.layerIndex(self.layer3), 0 )
        self.assertEqual( len(lsm), 3 )
        self.assertEqual( len(sims), 0 )

        self.assertFalse(sims.isRegistered(self.layer2))
        sims.register( self.layer2, self.ims2 )
        self.assertTrue(sims.isRegistered(self.layer2))
        self.assertEqual( len(sims), 1 )
        self.assertEqual( sims.getImageSource(0), self.ims2 )

        sims.register( self.layer1, self.ims1 )
        sims.register( self.layer3, self.ims3 )
        sims.deregister( self.layer2 )
        self.assertTrue( sims.isRegistered( self.layer1 ))
        self.assertFalse( sims.isRegistered( self.layer2 ))
        self.assertTrue( sims.isRegistered( self.layer3 ))
        self.assertEqual( len(lsm), 3 )
        self.assertEqual( len(sims), 2 )
        self.assertEqual( sims.getImageSource(0), self.ims3 )    
        self.assertEqual( sims.getImageSource(1), self.ims1 )

        for i,v in enumerate(sims):
            if i == 0:
                self.assertEqual(len(v), 3)
                self.assertEqual(v[0], self.layer3.visible) 
                self.assertEqual(v[1], self.layer3.opacity)
                self.assertEqual(v[2], self.ims3)  
            elif i == 1:
                self.assertEqual(len(v), 3)
                self.assertEqual(v[0], self.layer1.visible) 
                self.assertEqual(v[1], self.layer1.opacity)
                self.assertEqual(v[2], self.ims1)
            else:
                raise Exception("unexpected index")

        sims.deregister( self.layer1 )
        sims.deregister( self.layer3 )
        self.assertEqual( len(lsm), 3 )
        self.assertEqual( len(sims), 0 )

        lsm.clear()
예제 #6
0
    def testRegisterAndDeregister(self):
        lsm = LayerStackModel()
        sims = StackedImageSources(lsm)
        self.assertEqual(len(lsm), 0)
        self.assertEqual(len(sims), 0)

        lsm.append(self.layer1)
        lsm.append(self.layer2)
        lsm.append(self.layer3)
        self.assertEqual(lsm.layerIndex(self.layer1), 2)
        self.assertEqual(lsm.layerIndex(self.layer2), 1)
        self.assertEqual(lsm.layerIndex(self.layer3), 0)
        self.assertEqual(len(lsm), 3)
        self.assertEqual(len(sims), 0)

        self.assertFalse(sims.isRegistered(self.layer2))
        sims.register(self.layer2, self.ims2)
        self.assertTrue(sims.isRegistered(self.layer2))
        self.assertEqual(len(sims), 1)
        self.assertEqual(sims.getImageSource(0), self.ims2)

        sims.register(self.layer1, self.ims1)
        sims.register(self.layer3, self.ims3)
        sims.deregister(self.layer2)
        self.assertTrue(sims.isRegistered(self.layer1))
        self.assertFalse(sims.isRegistered(self.layer2))
        self.assertTrue(sims.isRegistered(self.layer3))
        self.assertEqual(len(lsm), 3)
        self.assertEqual(len(sims), 2)
        self.assertEqual(sims.getImageSource(0), self.ims3)
        self.assertEqual(sims.getImageSource(1), self.ims1)

        for i, v in enumerate(sims):
            if i == 0:
                self.assertEqual(len(v), 3)
                self.assertEqual(v[0], self.layer3.visible)
                self.assertEqual(v[1], self.layer3.opacity)
                self.assertEqual(v[2], self.ims3)
            elif i == 1:
                self.assertEqual(len(v), 3)
                self.assertEqual(v[0], self.layer1.visible)
                self.assertEqual(v[1], self.layer1.opacity)
                self.assertEqual(v[2], self.ims1)
            else:
                raise Exception("unexpected index")

        sims.deregister(self.layer1)
        sims.deregister(self.layer3)
        self.assertEqual(len(lsm), 3)
        self.assertEqual(len(sims), 0)

        lsm.clear()
예제 #7
0
class ImageScene2DTest( ut.TestCase ):
    def setUp( self ):
        self.app = QApplication([], False)

        self.layerstack = LayerStackModel()
        self.sims = StackedImageSources( self.layerstack )

        self.GRAY = 201
        self.ds = ConstantSource(self.GRAY)
        self.layer = GrayscaleLayer( self.ds )
        self.layerstack.append(self.layer)
        self.ims = imsfac.createImageSource( self.layer, [self.ds] )
        self.sims.register(self.layer, self.ims)
        
        self.scene = ImageScene2D(self.app) 
        self.scene.stackedImageSources = self.sims
        self.scene.sceneShape = (310,290)

    def renderScene( self, s):
        img = QImage(310,290,QImage.Format_ARGB32_Premultiplied)
        p = QPainter(img)
        s.render(p)
        s.joinRendering()
        s.render(p)
        p.end()
        return byte_view(img)

    def testBasicImageRenderingCapability( self ):
        import time
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:,:,0:3] == self.GRAY))
        self.assertTrue(np.all(aimg[:,:,3] == 255))

    @ut.skipIf(os.getenv('TRAVIS'), 'fails on TRAVIS CI due to unknown reasons')
    def testToggleVisibilityOfOneLayer( self ):
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:,:,0:3] == self.GRAY))
        self.assertTrue(np.all(aimg[:,:,3] == 255))

        self.layer.visible = False
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:,:,0:3] == 255)) # all white
        self.assertTrue(np.all(aimg[:,:,3] == 255))

        self.layer.visible = True
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:,:,0:3] == self.GRAY))
        self.assertTrue(np.all(aimg[:,:,3] == 255))
예제 #8
0
    def testFirstFullyOpaque( self ):
        lsm = LayerStackModel()
        sims = StackedImageSources( lsm )
        self.assertEqual(sims.firstFullyOpaque(), None)

        lsm.append(self.layer1)
        lsm.append(self.layer2)
        lsm.append(self.layer3)
        self.assertEqual( lsm.layerIndex(self.layer1), 2 )
        self.assertEqual( lsm.layerIndex(self.layer2), 1 )
        self.assertEqual( lsm.layerIndex(self.layer3), 0 )
        sims.register(self.layer1, self.ims1)
        sims.register(self.layer2, self.ims2)
        sims.register(self.layer3, self.ims3)
        self.assertEqual(sims.firstFullyOpaque(), 0)
        lsm.clear()

        sims = StackedImageSources( lsm )
        lsm.append(self.layer2)
        lsm.append(self.layer3)
        lsm.append(self.layer1)
        self.assertEqual( lsm.layerIndex(self.layer1), 0 )
        self.assertEqual( lsm.layerIndex(self.layer2), 2 )
        self.assertEqual( lsm.layerIndex(self.layer3), 1 )
        sims.register(self.layer1, self.ims1)
        sims.register(self.layer2, self.ims2)
        sims.register(self.layer3, self.ims3)
        self.assertEqual(sims.firstFullyOpaque(), 1)
        lsm.clear()

        sims = StackedImageSources( lsm )
        lsm.append(self.layer2)
        lsm.append(self.layer1)
        self.assertEqual( lsm.layerIndex(self.layer1), 0 )
        self.assertEqual( lsm.layerIndex(self.layer2), 1 )
        sims.register(self.layer1, self.ims1)
        sims.register(self.layer2, self.ims2)
        self.assertEqual(sims.firstFullyOpaque(), None)
        lsm.clear()
예제 #9
0
    def testFirstFullyOpaque(self):
        lsm = LayerStackModel()
        sims = StackedImageSources(lsm)
        self.assertEqual(sims.firstFullyOpaque(), None)

        lsm.append(self.layer1)
        lsm.append(self.layer2)
        lsm.append(self.layer3)
        self.assertEqual(lsm.layerIndex(self.layer1), 2)
        self.assertEqual(lsm.layerIndex(self.layer2), 1)
        self.assertEqual(lsm.layerIndex(self.layer3), 0)
        sims.register(self.layer1, self.ims1)
        sims.register(self.layer2, self.ims2)
        sims.register(self.layer3, self.ims3)
        self.assertEqual(sims.firstFullyOpaque(), 0)
        lsm.clear()

        sims = StackedImageSources(lsm)
        lsm.append(self.layer2)
        lsm.append(self.layer3)
        lsm.append(self.layer1)
        self.assertEqual(lsm.layerIndex(self.layer1), 0)
        self.assertEqual(lsm.layerIndex(self.layer2), 2)
        self.assertEqual(lsm.layerIndex(self.layer3), 1)
        sims.register(self.layer1, self.ims1)
        sims.register(self.layer2, self.ims2)
        sims.register(self.layer3, self.ims3)
        self.assertEqual(sims.firstFullyOpaque(), 1)
        lsm.clear()

        sims = StackedImageSources(lsm)
        lsm.append(self.layer2)
        lsm.append(self.layer1)
        self.assertEqual(lsm.layerIndex(self.layer1), 0)
        self.assertEqual(lsm.layerIndex(self.layer2), 1)
        sims.register(self.layer1, self.ims1)
        sims.register(self.layer2, self.ims2)
        self.assertEqual(sims.firstFullyOpaque(), None)
        lsm.clear()
예제 #10
0
class ImageScene2D_RenderTest(ut.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.app = None
        if QApplication.instance():
            cls.app = QApplication.instance()
        else:
            cls.app = QApplication([], False)

    @classmethod
    def tearDownClass(cls):
        del cls.app

    def setUp(self):
        self.layerstack = LayerStackModel()
        self.sims = StackedImageSources(self.layerstack)

        self.GRAY = 201
        self.ds = ConstantSource(self.GRAY)
        self.layer = GrayscaleLayer(self.ds)
        self.layerstack.append(self.layer)
        self.ims = imsfac.createImageSource(self.layer, [self.ds])
        self.sims.register(self.layer, self.ims)

        self.scene = ImageScene2D(PositionModel(), (0, 3, 4),
                                  preemptive_fetch_number=0)

        self.scene.stackedImageSources = self.sims
        self.scene.dataShape = (310, 290)

    def tearDown(self):
        if self.scene._tileProvider:
            self.scene._tileProvider.notifyThreadsToStop()
            self.scene._tileProvider.joinThreads()

    def renderScene(self, s, exportFilename=None):
        img = QImage(310, 290, QImage.Format_ARGB32_Premultiplied)
        img.fill(0)
        p = QPainter(img)
        s.render(p)
        s.joinRendering()
        s.render(p)
        p.end()
        if exportFilename is not None:
            img.save(exportFilename)
        return byte_view(img)

    def testBasicImageRenderingCapability(self):
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:, :, 0:3] == self.GRAY))
        self.assertTrue(np.all(aimg[:, :, 3] == 255))

    def testToggleVisibilityOfOneLayer(self):
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:, :, 0:3] == self.GRAY))
        self.assertTrue(np.all(aimg[:, :, 3] == 255))

        self.layer.visible = False
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:, :, 0:3] == 0))  # all white
        self.assertTrue(np.all(aimg[:, :, 3] == 0))

        self.layer.visible = True
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:, :, 0:3] == self.GRAY))
        self.assertTrue(np.all(aimg[:, :, 3] == 255))
예제 #11
0
class ImageScene2D_RenderTest( ut.TestCase ):

    @classmethod
    def setUpClass(cls):
        cls.app = None
        if QApplication.instance():
            cls.app = QApplication.instance()
        else:
            cls.app = QApplication([], False)

    @classmethod
    def tearDownClass(cls):
        del cls.app

    def setUp( self ):
        self.layerstack = LayerStackModel()
        self.sims = StackedImageSources( self.layerstack )

        self.GRAY = 201
        self.ds = ConstantSource(self.GRAY)
        self.layer = GrayscaleLayer( self.ds )
        self.layerstack.append(self.layer)
        self.ims = imsfac.createImageSource( self.layer, [self.ds] )
        self.sims.register(self.layer, self.ims)

        self.scene = ImageScene2D(PositionModel(), (0,3,4), preemptive_fetch_number=0)

        self.scene.stackedImageSources = self.sims
        self.scene.dataShape = (310,290)

    def tearDown( self ):
        if self.scene._tileProvider:
            self.scene._tileProvider.notifyThreadsToStop()
            self.scene._tileProvider.joinThreads()

    def renderScene( self, s, exportFilename=None):
        img = QImage(310,290,QImage.Format_ARGB32_Premultiplied)
        p = QPainter(img)
        s.render(p)
        s.joinRendering()
        s.render(p)
        p.end()
        if exportFilename is not None:
            img.save(exportFilename)
        return byte_view(img)

    def testBasicImageRenderingCapability( self ):
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:,:,0:3] == self.GRAY))
        self.assertTrue(np.all(aimg[:,:,3] == 255))

    def testToggleVisibilityOfOneLayer( self ):
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:,:,0:3] == self.GRAY))
        self.assertTrue(np.all(aimg[:,:,3] == 255))

        self.layer.visible = False
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:,:,0:3] == 255)) # all white
        self.assertTrue(np.all(aimg[:,:,3] == 255))

        self.layer.visible = True
        aimg = self.renderScene(self.scene)
        self.assertTrue(np.all(aimg[:,:,0:3] == self.GRAY))
        self.assertTrue(np.all(aimg[:,:,3] == 255))
예제 #12
0
    class ImageScene2D_LazyTest(ut.TestCase):
        @classmethod
        def setUpClass(cls):
            cls.app = None
            if QApplication.instance():
                cls.app = QApplication.instance()
            else:
                cls.app = QApplication([], False)

        @classmethod
        def tearDownClass(cls):
            del cls.app

        def setUp(self):
            self.layerstack = LayerStackModel()
            self.sims = StackedImageSources(self.layerstack)

            self.g = Graph()
            self.op = OpLazy(self.g)
            self.ds = LazyflowSource(self.op.Output)

            self.ss = SliceSource(self.ds, projectionAlongTZC)

            self.layer = GrayscaleLayer(self.ds)
            self.layerstack.append(self.layer)
            self.ims = imsfac.createImageSource(self.layer, [self.ss])
            self.sims.register(self.layer, self.ims)

            self.scene = ImageScene2D(PositionModel(), (0, 0, 0),
                                      preemptive_fetch_number=0)
            self.scene.setCacheSize(1)

            self.scene.stackedImageSources = self.sims
            self.scene.dataShape = (30, 30)

        def tearDown(self):
            if self.scene._tileProvider:
                self.scene._tileProvider.notifyThreadsToStop()
                self.scene._tileProvider.joinThreads()

        def renderScene(self, s, exportFilename=None, joinRendering=True):
            img = QImage(30, 30, QImage.Format_ARGB32_Premultiplied)
            img.fill(Qt.white)
            p = QPainter(img)

            s.render(p)  #trigger a rendering of the whole scene
            if joinRendering:
                #wait for all the data to arrive
                s.joinRendering()
                #finally, render everything
                s.render(p)
            p.end()

            if exportFilename is not None:
                img.save(exportFilename)
            return byte_view(img)

        def testLazy(self):
            for i in range(3):
                self.op.setConstant(i)
                aimg = self.renderScene(self.scene, "/tmp/a_%03d.png" % i)
                assert numpy.all(
                    aimg[:, :,
                         0] == i), "!= %d, [0,0,0]=%d" % (i, aimg[0, 0, 0])

                self.op.setConstant(42)
                self.op.setDelay(1)
                aimg = self.renderScene(self.scene,
                                        joinRendering=False,
                                        exportFilename="/tmp/x_%03d.png" % i)
                #this should be "i", not 255 (the default background for the imagescene)
                assert numpy.all(
                    aimg[:, :,
                         0] == i), "!= %d, [0,0,0]=%d" % (i, aimg[0, 0, 0])
예제 #13
0
    class ImageScene2D_LazyTest( ut.TestCase ):

        @classmethod
        def setUpClass(cls):
            cls.app = None
            if QApplication.instance():
                cls.app = QApplication.instance()
            else:
                cls.app = QApplication([], False)

        @classmethod
        def tearDownClass(cls):
            del cls.app

        def setUp( self ):
            self.layerstack = LayerStackModel()
            self.sims = StackedImageSources( self.layerstack )

            self.g = Graph()
            self.op = OpLazy(self.g)
            self.ds = LazyflowSource( self.op.Output )

            self.ss = SliceSource( self.ds, projectionAlongTZC )

            self.layer = GrayscaleLayer(self.ds)
            self.layerstack.append(self.layer)
            self.ims = imsfac.createImageSource( self.layer, [self.ss] )
            self.sims.register(self.layer, self.ims)

            self.scene = ImageScene2D(PositionModel(), (0,0,0), preemptive_fetch_number=0)
            self.scene.setCacheSize(1)

            self.scene.stackedImageSources = self.sims
            self.scene.dataShape = (30,30)

        def tearDown( self ):
            if self.scene._tileProvider:
                self.scene._tileProvider.notifyThreadsToStop()
                self.scene._tileProvider.joinThreads()

        def renderScene( self, s, exportFilename=None, joinRendering=True):
            img = QImage(30,30,QImage.Format_ARGB32_Premultiplied)
            img.fill(Qt.white)
            p = QPainter(img)

            s.render(p) #trigger a rendering of the whole scene
            if joinRendering:
                #wait for all the data to arrive
                s.joinRendering()
                #finally, render everything
                s.render(p)
            p.end()

            if exportFilename is not None:
                img.save(exportFilename)
            return byte_view(img)

        def testLazy( self ):
            for i in range(3):
                self.op.setConstant(i)
                aimg = self.renderScene(self.scene, "/tmp/a_%03d.png" % i)
                assert numpy.all(aimg[:,:,0] == i), "!= %d, [0,0,0]=%d" % (i, aimg[0,0,0])

                self.op.setConstant(42)
                self.op.setDelay(1)
                aimg = self.renderScene(self.scene, joinRendering=False, exportFilename="/tmp/x_%03d.png" % i)
                #this should be "i", not 255 (the default background for the imagescene)
                assert numpy.all(aimg[:,:,0] == i), "!= %d, [0,0,0]=%d" % (i, aimg[0,0,0])