diff --git a/volumina/patchAccessor.py b/volumina/patchAccessor.py index edc5099ab..4d2a4d12d 100644 --- a/volumina/patchAccessor.py +++ b/volumina/patchAccessor.py @@ -94,22 +94,36 @@ def patchRectF(self, blockNum, overlap=0): return QRectF(QPointF(startx, starty), QPointF(endx, endy)) def getPatchesForRect(self, startx, starty, endx, endy): + """returns patchnumbers for patches that are intersecting with the normalized rectangle defined by upper left + corner (staĊ•tx/y) and lower right corner (endx/y) + """ + if endy < 0 or endx < 0: + # allowing no inverted start/end -positions, there should be no negative end-positions + return [] sx = int(numpy.floor(1.0 * startx / self._blockSize)) ex = int(numpy.ceil(1.0 * endx / self._blockSize)) sy = int(numpy.floor(1.0 * starty / self._blockSize)) ey = int(numpy.ceil(1.0 * endy / self._blockSize)) - # Clip to rect bounds - sx = max(sx, 0) - sy = max(sy, 0) + # Clip to rect to upper bounds ex = min(ex, self._cX) ey = min(ey, self._cY) - # always return at least one index - if sx==ex: - ex = ex + 1 - if sy==ey: - ey = ey + 1 + # return an index also, when start and end are equal + if sx == ex: + if ex >= self._cX: + sx = sx - 1 + else: + ex = ex + 1 + if sy == ey: + if ey >= self._cY: + sy = sy - 1 + else: + ey = ey + 1 + + # Clip to rect to lower bounds + sx = max(sx, 0) + sy = max(sy, 0) nums = [] for y in range(sy, ey): diff --git a/volumina/sliceSelectorHud.py b/volumina/sliceSelectorHud.py index 9b96ef488..e721c23fc 100644 --- a/volumina/sliceSelectorHud.py +++ b/volumina/sliceSelectorHud.py @@ -791,6 +791,7 @@ def setMouseCoords(self, x, y, z): coords = [int(val) for val in [x,y,z]] imgView = self.editor.posModel.activeView blockSize = self.editor.imageViews[imgView].scene()._tileProvider.tiling.blockSize + sliceShape = self.editor.imageViews[imgView].scene()._tileProvider.tiling.sliceShape labelSet = False del coords[imgView] @@ -802,14 +803,26 @@ def setMouseCoords(self, x, y, z): value = None layer_id = self.editor.imagepumps[imgView].stackedImageSources._layerToIms[layer] stack_id = self.editor.imageViews[imgView].scene()._tileProvider._current_stack_id - tile_id = self.editor.imageViews[imgView].scene()._tileProvider.tiling.intersected( - QRect(QPoint(x, y), QPoint(x, y)))[ - 0] # There will be just one tile, since we have just a single point + tile_ids = self.editor.imageViews[imgView].scene()._tileProvider.tiling.intersected( + QRect(QPoint(x, y), QPoint(x, y))) + if tile_ids: + tile_id = tile_ids[0] # There will be just one tile, since we have just a single point + else: + return + with self.editor.imageViews[imgView].scene()._tileProvider._cache: image = self.editor.imageViews[imgView].scene()._tileProvider._cache.layer(stack_id, layer_id, tile_id) if image is not None: - value = image.pixelColor(x % blockSize, y % blockSize) + x_r = x % blockSize + y_r = y % blockSize + + if x >= blockSize and x >= int(sliceShape[0]/blockSize) * blockSize: + x_r = x_r + blockSize + if y >= blockSize and y >= int(sliceShape[1]/blockSize) * blockSize: + y_r = y_r + blockSize + + value = image.pixelColor(x_r, y_r) lbl, foreground, background = layer.setValueWidget(value) diff --git a/volumina/tiling.py b/volumina/tiling.py index 034f891ef..a1c7161ee 100644 --- a/volumina/tiling.py +++ b/volumina/tiling.py @@ -200,7 +200,7 @@ def containsF(self, point): def intersected(self, sceneRect): if not sceneRect.isValid(): return list(range(len(self.tileRects))) - + sceneRect = sceneRect.normalized() # Patch accessor uses data coordinates rect = self.data2scene.inverted()[0].mapRect(sceneRect) patchNumbers = self._patchAccessor.getPatchesForRect(