def testSetAllLayersInvisible( self ): tiling = Tiling((900,400), blockSize=100) tp = TileProvider(tiling, self.sims) tp.requestRefresh(QRectF(100,100,200,200)) tp.waitForTiles() 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.waitForTiles() 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.waitForTiles() 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))
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()
def setCacheSize(self, cache_size): if cache_size != self._tileProvider._cache_size: self._tileProvider = TileProvider(self._tiling, self._stackedImageSources, cache_size=cache_size) self._tileProvider.sceneRectChanged.connect( self.invalidateViewports)
def reset(self): """Reset rotations, tiling, etc. Called when first initialized and when the underlying data changes. """ DEFAULT_TILE_WIDTH = 512 self.resetAxes(finish=False) tileWidth = self.tileWidth if self.tileWidth is None: tileWidth = DEFAULT_TILE_WIDTH self._tiling = Tiling(self._dataShape, self.data2scene, name=self.name, blockSize=tileWidth) self._tileProvider = TileProvider(self._tiling, self._stackedImageSources) self._tileProvider.sceneRectChanged.connect(self.invalidateViewports) if self._dirtyIndicator: self.removeItem(self._dirtyIndicator) del self._dirtyIndicator self._dirtyIndicator = DirtyIndicator(self._tiling) self.addItem(self._dirtyIndicator) self._dirtyIndicator.setVisible(False)
def reset(self): """Reset rotations, tiling, etc. Called when first initialized and when the underlying data changes. """ self.resetAxes(finish=False) self._tiling = Tiling(self._dataShape, self.data2scene, name=self.name) self._brushingLayer = TiledImageLayer(self._tiling) self._tileProvider = TileProvider(self._tiling, self._stackedImageSources) self._tileProvider.sceneRectChanged.connect(self.invalidateViewports) if self._dirtyIndicator: self.removeItem(self._dirtyIndicator) del self._dirtyIndicator self._dirtyIndicator = DirtyIndicator(self._tiling) self.addItem(self._dirtyIndicator)
def testOutOfViewDirtyPropagation( self ): self.lsm.append(self.layer1) tiling = Tiling((900,400), blockSize=100) tp = TileProvider(tiling, self.pump.stackedImageSources) # Navigate down to the second z-slice self.pump.syncedSliceSources.through = [0,1,0] tp.requestRefresh(QRectF(100,100,200,200)) tp.waitForTiles() # 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.waitForTiles() # 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.waitForTiles() 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.waitForTiles() # 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))