예제 #1
0
    def testEverythingDirtyPropagation( self ):
        self.lsm.append(self.layer2)        
        tiling = Tiling((900,400), blockSize=100)
        tp = TileProvider(tiling, self.pump.stackedImageSources)
        try:
            tp.requestRefresh(QRectF(100,100,200,200))
            tp.join()
            tiles = tp.getTiles(QRectF(100,100,200,200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:,:,0:3] == self.CONSTANT))
                self.assertTrue(np.all(aimg[:,:,3] == 255))

            NEW_CONSTANT = self.CONSTANT+1
            self.ds2.constant = NEW_CONSTANT
            tp.requestRefresh(QRectF(100,100,200,200))
            tp.join()
            tiles = tp.getTiles(QRectF(100,100,200,200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:,:,0:3] == NEW_CONSTANT))
                self.assertTrue(np.all(aimg[:,:,3] == 255))
            
        finally:
            tp.notifyThreadsToStop()
            tp.joinThreads()
예제 #2
0
    def testEverythingDirtyPropagation(self):
        self.lsm.append(self.layer2)
        tiling = Tiling((900, 400), blockSize=100)
        tp = TileProvider(tiling, self.pump.stackedImageSources)
        try:
            tp.requestRefresh(QRectF(100, 100, 200, 200))
            tp.join()
            tiles = tp.getTiles(QRectF(100, 100, 200, 200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:, :, 0:3] == self.CONSTANT))
                self.assertTrue(np.all(aimg[:, :, 3] == 255))

            NEW_CONSTANT = self.CONSTANT + 1
            self.ds2.constant = NEW_CONSTANT
            tp.requestRefresh(QRectF(100, 100, 200, 200))
            tp.join()
            tiles = tp.getTiles(QRectF(100, 100, 200, 200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:, :, 0:3] == NEW_CONSTANT))
                self.assertTrue(np.all(aimg[:, :, 3] == 255))

        finally:
            tp.notifyThreadsToStop()
            tp.joinThreads()
예제 #3
0
    def testSetAllLayersInvisible( self ):
        tiling = Tiling((900,400), blockSize=100)
        tp = TileProvider(tiling, self.sims)
        try:
            tp.requestRefresh(QRectF(100,100,200,200))
            tp.join()
            tiles = tp.getTiles(QRectF(100,100,200,200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:,:,0:3] == self.GRAY3))
                self.assertTrue(np.all(aimg[:,:,3] == 255))

            self.layer1.visible = False
            self.layer2.visible = False
            self.layer3.visible = False
            tp.requestRefresh(QRectF(100,100,200,200))
            tp.join()
            tiles = tp.getTiles(QRectF(100,100,200,200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:,:,0:3] == 255)) # all white
                self.assertTrue(np.all(aimg[:,:,3] == 255))

            self.layer1.visible = False
            self.layer2.visible = True
            self.layer2.opacity = 1.0
            self.layer3.visible = False
            tp.requestRefresh(QRectF(100,100,200,200))
            tp.join()
            tiles = tp.getTiles(QRectF(100,100,200,200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:,:,0:3] == self.GRAY2))
                self.assertTrue(np.all(aimg[:,:,3] == 255))

        finally:
            tp.notifyThreadsToStop()
            tp.joinThreads()
예제 #4
0
    def testSetAllLayersInvisible(self):
        tiling = Tiling((900, 400), blockSize=100)
        tp = TileProvider(tiling, self.sims)
        try:
            tp.requestRefresh(QRectF(100, 100, 200, 200))
            tp.join()
            tiles = tp.getTiles(QRectF(100, 100, 200, 200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:, :, 0:3] == self.GRAY3))
                self.assertTrue(np.all(aimg[:, :, 3] == 255))

            self.layer1.visible = False
            self.layer2.visible = False
            self.layer3.visible = False
            tp.requestRefresh(QRectF(100, 100, 200, 200))
            tp.join()
            tiles = tp.getTiles(QRectF(100, 100, 200, 200))
            for tile in tiles:
                # If all tiles are invisible, then no tile is even rendered at all.
                assert tile.qimg is None

            self.layer1.visible = False
            self.layer2.visible = True
            self.layer2.opacity = 1.0
            self.layer3.visible = False
            tp.requestRefresh(QRectF(100, 100, 200, 200))
            tp.join()
            tiles = tp.getTiles(QRectF(100, 100, 200, 200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:, :, 0:3] == self.GRAY2))
                self.assertTrue(np.all(aimg[:, :, 3] == 255))

        finally:
            tp.notifyThreadsToStop()
            tp.joinThreads()
예제 #5
0
    def testOutOfViewDirtyPropagation( self ):
        self.lsm.append(self.layer1)
        tiling = Tiling((900,400), blockSize=100)
        tp = TileProvider(tiling, self.pump.stackedImageSources)
        try:
            # Navigate down to the second z-slice
            self.pump.syncedSliceSources.through = [0,1,0]
            tp.requestRefresh(QRectF(100,100,200,200))
            tp.join()

            # Sanity check: Do we see the right data on the second slice? (should be all 1s)
            tiles = tp.getTiles(QRectF(100,100,200,200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:,:,0:3] == 1))
                self.assertTrue(np.all(aimg[:,:,3] == 255))

            # Navigate down to the third z-slice
            self.pump.syncedSliceSources.through = [0,2,0]
            tp.requestRefresh(QRectF(100,100,200,200))
            tp.join()

            # Sanity check: Do we see the right data on the third slice?(should be all 2s)
            tiles = tp.getTiles(QRectF(100,100,200,200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:,:,0:3] == 2))
                self.assertTrue(np.all(aimg[:,:,3] == 255))

            # Navigate back up to the second z-slice
            self.pump.syncedSliceSources.through = [0,1,0]
            tp.requestRefresh(QRectF(100,100,200,200))
            tp.join()
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:,:,0:3] == 1))
                self.assertTrue(np.all(aimg[:,:,3] == 255))

            # Change some of the data in the (out-of-view) third z-slice
            slicing = (slice(None), slice(100,300), slice(100,300), slice(2,3), slice(None))
            slicing = tuple(slicing)
            self.ds1._array[slicing] = 99
            self.ds1.setDirty( slicing )
            
            # Navigate back down to the third z-slice
            self.pump.syncedSliceSources.through = [0,2,0]
            tp.requestRefresh(QRectF(100,100,200,200))
            tp.join()

            # Even though the data was out-of-view when it was changed, it should still have new values.
            # If dirtiness wasn't propagated correctly, the cache's old values will be used.
            # (For example, this fails if you comment out the call to setDirty, above.)
            tiles = tp.getTiles(QRectF(100,100,200,200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                # Use any() because the tile borders may not be perfectly aligned with the data we changed.
                self.assertTrue(np.any(aimg[:,:,0:3] == 99))

        finally:
            tp.notifyThreadsToStop()
            tp.joinThreads()
예제 #6
0
    def testOutOfViewDirtyPropagation(self):
        self.lsm.append(self.layer1)
        tiling = Tiling((900, 400), blockSize=100)
        tp = TileProvider(tiling, self.pump.stackedImageSources)
        try:
            # Navigate down to the second z-slice
            self.pump.syncedSliceSources.through = [0, 1, 0]
            tp.requestRefresh(QRectF(100, 100, 200, 200))
            tp.join()

            # Sanity check: Do we see the right data on the second
            # slice? (should be all 1s)
            tiles = tp.getTiles(QRectF(100, 100, 200, 200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:, :, 0:3] == 1))
                self.assertTrue(np.all(aimg[:, :, 3] == 255))

            # Navigate down to the third z-slice
            self.pump.syncedSliceSources.through = [0, 2, 0]
            tp.requestRefresh(QRectF(100, 100, 200, 200))
            tp.join()

            # Sanity check: Do we see the right data on the third
            # slice?(should be all 2s)
            tiles = tp.getTiles(QRectF(100, 100, 200, 200))
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:, :, 0:3] == 2))
                self.assertTrue(np.all(aimg[:, :, 3] == 255))

            # Navigate back up to the second z-slice
            self.pump.syncedSliceSources.through = [0, 1, 0]
            tp.requestRefresh(QRectF(100, 100, 200, 200))
            tp.join()
            for tile in tiles:
                aimg = byte_view(tile.qimg)
                self.assertTrue(np.all(aimg[:, :, 0:3] == 1))
                self.assertTrue(np.all(aimg[:, :, 3] == 255))

            # Change some of the data in the (out-of-view) third z-slice
            slicing = (slice(None), slice(100, 300), slice(100, 300),
                       slice(2, 3), slice(None))
            slicing = tuple(slicing)
            self.ds1._array[slicing] = 99
            self.ds1.setDirty(slicing)

            # Navigate back down to the third z-slice
            self.pump.syncedSliceSources.through = [0, 2, 0]
            tp.requestRefresh(QRectF(100, 100, 200, 200))
            tp.join()

            # Even though the data was out-of-view when it was
            # changed, it should still have new values. If dirtiness
            # wasn't propagated correctly, the cache's old values will
            # be used. (For example, this fails if you comment out the
            # call to setDirty, above.)

            # Shrink accessed rect by 1 pixel on each side (Otherwise,
            # tiling overlap_draw causes getTiles() to return
            # surrounding tiles that we haven't actually touched in
            # this test)
            tiles = tp.getTiles(QRectF(101, 101, 198, 198))

            for tile in tiles:
                aimg = byte_view(tile.qimg)
                # Use any() because the tile borders may not be
                # perfectly aligned with the data we changed.
                self.assertTrue(np.any(aimg[:, :, 0:3] == 99))
        finally:
            tp.notifyThreadsToStop()
            tp.joinThreads()