Commit 29f74558 authored by Robert's avatar Robert Committed by Robert Ohmacht

fixes bug occurring when fast clicking in particle paint mode

fixes bug occurring when painting particles outside of canvas
parent 62ed922c
......@@ -222,7 +222,13 @@ def getParticleImageFromFullimage(contour, fullimage):
contourCopy = deepcopy(contour)
xmin, xmax, ymin, ymax = getContourExtrema(contourCopy)
img = fullimage[ymin:ymax, xmin:xmax]
xmin_i = max(0, xmin)
ymin_i = max(0, ymin)
xmax_i = min(fullimage.shape[1], xmax)
ymax_i = min(fullimage.shape[0], ymax)
img = fullimage[ymin_i:ymax_i, xmin_i:xmax_i]
#img = fullimage[ymin:ymax, xmin:xmax]
img = img.copy()
mask = np.zeros(img.shape[:2])
......
......@@ -67,8 +67,10 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
def mousePressEvent(self, event):
pos = event.pos()
if type(pos) == QtCore.QPointF:
pos = QtCore.QPoint(xpos=int(round(pos.x())), ypos=int(round(pos.y())))
self.mousePos = self.viewparent.mapToScene(event.pos())
x = int(round(pos.x()))
y = int(round(pos.y()))
pos = QtCore.QPoint(x, y)
self.mousePos = self.viewparent.mapToScene(pos)
self.erasing = self.painting = False
if event.modifiers() == QtCore.Qt.ControlModifier:
self.painting = True
......@@ -76,7 +78,7 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
self.erasing = True
if self.painting or self.erasing:
drawPos = self.viewparent.mapToScene(event.pos()) - self.brect.topLeft()
drawPos = self.viewparent.mapToScene(pos) - self.brect.topLeft()
self.drawParticle(drawPos)
def mouseMoveEvent(self, event):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment