Skip to content

Commit

Permalink
test_PolyLineROI now passes on non-AMD64 platforms
Browse files Browse the repository at this point in the history
The major source of the discrepancy of the images came from AntiAliasing
This commit adds an attribute to ROIs and Handles, ._antialias, which is
True by default, but anti-aliasing will be disabled when that attribute
is set to False. The ROIs and Handles used in the test suite are set to
have this attribute set to False, thus disabling the use of
anti-aliasing.

This change also required that I generate new baseline test images,
which are included in the commit.

Because of disabling anti-aliasing, the pxCount value for image
comparison checker are substantially lower.
  • Loading branch information
j9ac9k committed Apr 27, 2024
1 parent 91a900d commit 6aaad28
Show file tree
Hide file tree
Showing 50 changed files with 303 additions and 174 deletions.
54 changes: 38 additions & 16 deletions pyqtgraph/graphicsItems/ROI.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class ROI(GraphicsObject):
an option to remove the ROI. The ROI emits
sigRemoveRequested when this menu action is selected.
Default is False.
antialias (bool) If True, the ROI will render using AntiAliasing,
this is what is desired in almost all cases, the option is
added for testing purposes.
Default is True
================ ===========================================================
Expand Down Expand Up @@ -143,7 +147,7 @@ def __init__(self, pos, size=Point(1, 1), angle=0.0, invertible=False,
translateSnap=False, rotateSnap=False, parent=None, pen=None,
hoverPen=None, handlePen=None, handleHoverPen=None,
movable=True, rotatable=True, resizable=True, removable=False,
aspectLocked=False):
aspectLocked=False, antialias=True):
GraphicsObject.__init__(self, parent)
self.setAcceptedMouseButtons(QtCore.Qt.MouseButton.NoButton)
pos = Point(pos)
Expand All @@ -154,6 +158,7 @@ def __init__(self, pos, size=Point(1, 1), angle=0.0, invertible=False,
self.resizable = resizable
self.removable = removable
self.menu = None
self._antialias = antialias

self.freeHandleMoved = False ## keep track of whether free handles have moved since last change signal was emitted.
self.mouseHovering = False
Expand Down Expand Up @@ -611,7 +616,7 @@ def addHandle(self, info, index=None):
## If a Handle was not supplied, create it now
if 'item' not in info or info['item'] is None:
h = Handle(self.handleSize, typ=info['type'], pen=self.handlePen,
hoverPen=self.handleHoverPen, parent=self)
hoverPen=self.handleHoverPen, parent=self, antialias=self._antialias)
info['item'] = h
else:
h = info['item']
Expand Down Expand Up @@ -1067,8 +1072,10 @@ def boundingRect(self):
def paint(self, p, opt, widget):
# Note: don't use self.boundingRect here, because subclasses may need to redefine it.
r = QtCore.QRectF(0, 0, self.state['size'][0], self.state['size'][1]).normalized()

p.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing)
p.setRenderHint(
QtGui.QPainter.RenderHint.Antialiasing,
self._antialias
)
p.setPen(self.currentPen)
p.translate(r.left(), r.top())
p.scale(r.width(), r.height())
Expand Down Expand Up @@ -1335,7 +1342,7 @@ class Handle(UIGraphicsItem):
sigRemoveRequested = QtCore.Signal(object) # self

def __init__(self, radius, typ=None, pen=(200, 200, 220),
hoverPen=(255, 255, 0), parent=None, deletable=False):
hoverPen=(255, 255, 0), parent=None, deletable=False, antialias=True):
self.rois = []
self.radius = radius
self.typ = typ
Expand All @@ -1346,6 +1353,7 @@ def __init__(self, radius, typ=None, pen=(200, 200, 220),
self.sides, self.startAng = self.types[typ]
self.buildPath()
self._shape = None
self._antialias = antialias
self.menu = self.buildMenu()

UIGraphicsItem.__init__(self, parent=parent)
Expand Down Expand Up @@ -1477,9 +1485,11 @@ def buildPath(self):
self.path.closeSubpath()

def paint(self, p, opt, widget):
p.setRenderHints(p.RenderHint.Antialiasing, True)
p.setRenderHint(
p.RenderHint.Antialiasing,
self._antialias
)
p.setPen(self.currentPen)

p.drawPath(self.shape())

def shape(self):
Expand All @@ -1488,7 +1498,9 @@ def shape(self):
if s is None:
return self.path
self._shape = s
self.prepareGeometryChange() ## beware--this can cause the view to adjust, which would immediately invalidate the shape.
# beware--this can cause the view to adjust,
# which would immediately invalidate the shape.
self.prepareGeometryChange()
return self._shape

def boundingRect(self):
Expand Down Expand Up @@ -1839,12 +1851,14 @@ def _clearPath(self):

def paint(self, p, opt, widget):
r = self.boundingRect()
p.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing)

p.setRenderHint(
QtGui.QPainter.RenderHint.Antialiasing,
self._antialias
)
p.setPen(self.currentPen)

p.scale(r.width(), r.height())## workaround for GL bug
r = QtCore.QRectF(r.x()/r.width(), r.y()/r.height(), 1,1)

p.drawEllipse(r)

def getArrayRegion(self, arr, img=None, axes=(0, 1), returnMappedCoords=False, **kwds):
Expand Down Expand Up @@ -2017,7 +2031,7 @@ def setState(self, state):

def addSegment(self, h1, h2, index=None):
seg = _PolyLineSegment(handles=(h1, h2), pen=self.pen, hoverPen=self.hoverPen,
parent=self, movable=False)
parent=self, movable=False, antialias=self._antialias)
if index is None:
self.segments.append(seg)
else:
Expand Down Expand Up @@ -2162,7 +2176,10 @@ def setState(self, state):
self.movePoint(self.getHandles()[1], p2)

def paint(self, p, *args):
p.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing)
p.setRenderHint(
QtGui.QPainter.RenderHint.Antialiasing,
self._antialias
)
p.setPen(self.currentPen)
h1 = self.endpoints[0].pos()
h2 = self.endpoints[1].pos()
Expand Down Expand Up @@ -2278,9 +2295,11 @@ def shape(self):

def paint(self, p, *args):
radius = self.getState()['size'][1]
p.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing)
p.setRenderHint(
QtGui.QPainter.RenderHint.Antialiasing,
self._antialias
)
p.setPen(self.currentPen)

p.drawLine(Point(0, -radius), Point(0, radius))
p.drawLine(Point(-radius, 0), Point(radius, 0))

Expand Down Expand Up @@ -2337,7 +2356,10 @@ def __init__(self, pos, size, **args):

def paint(self, p, *args):
r = self.boundingRect()
p.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing)
p.setRenderHint(
QtGui.QPainter.RenderHint.Antialiasing,
self._antialias
)
p.scale(r.width(), r.height())
p.setPen(self.currentPen)
p.drawPolygon(self.poly)
Expand Down
Loading

0 comments on commit 6aaad28

Please sign in to comment.