From 5ab0cef017768990f3672632f160fcfc1119b9cc Mon Sep 17 00:00:00 2001 From: Etienne Dumur Date: Mon, 12 Oct 2020 12:45:13 +0200 Subject: [PATCH] Solve artifacts issues Add a parameter "antialiasing". Remove profiler Add pyqtgraph mkPen --- examples/PColorMeshItem.py | 8 +++++--- pyqtgraph/graphicsItems/PColorMeshItem.py | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/examples/PColorMeshItem.py b/examples/PColorMeshItem.py index 7820030c..29e89db5 100644 --- a/examples/PColorMeshItem.py +++ b/examples/PColorMeshItem.py @@ -44,9 +44,11 @@ y.sort(axis=0) z = np.exp(-(x*xn)**2/1000)[:-1,:-1] ## Create image item -edgecolors = None +edgecolors = None +antialiasing = False # edgecolors = {'color':'w', 'width':2} # May be uncommened to see edgecolor effect -pcmi = pg.PColorMeshItem(edgecolors=edgecolors) +# antialiasing = True # May be uncommened to see antialiasing effect +pcmi = pg.PColorMeshItem(edgecolors=edgecolors, antialiasing=antialiasing) view.addItem(pcmi) @@ -72,7 +74,7 @@ def updateData(): new_z) i += wave_speed - QtCore.QTimer.singleShot(1000/fps, updateData) + QtCore.QTimer.singleShot(1000//fps, updateData) updateData() diff --git a/pyqtgraph/graphicsItems/PColorMeshItem.py b/pyqtgraph/graphicsItems/PColorMeshItem.py index 9ca21102..b45560a7 100644 --- a/pyqtgraph/graphicsItems/PColorMeshItem.py +++ b/pyqtgraph/graphicsItems/PColorMeshItem.py @@ -61,6 +61,9 @@ class PColorMeshItem(GraphicsObject): The dict may contains any arguments accepted by :func:`mkColor() . Example: mkPen(color='w', width=2) + antialiasing : bool , default False + Whether to draw edgelines with antialiasing. + Note that if edgecolors is None, antialiasing is always False. """ GraphicsObject.__init__(self) @@ -72,6 +75,11 @@ class PColorMeshItem(GraphicsObject): self.edgecolors = kwargs['edgecolors'] else: self.edgecolors = None + + if 'antialiasing' in kwargs.keys(): + self.antialiasing = kwargs['antialiasing'] + else: + self.antialiasing = False if 'cmap' in kwargs.keys(): if kwargs['cmap'] in Gradients.keys(): @@ -163,16 +171,16 @@ class PColorMeshItem(GraphicsObject): if np.any(self.x != args[0]) or np.any(self.y != args[1]): shapeChanged = True - profile = debug.Profiler() - self.qpicture = QtGui.QPicture() p = QtGui.QPainter(self.qpicture) - # We set the pen of all polygons once if self.edgecolors is None: - p.setPen(QtGui.QColor(0, 0, 0, 0)) + p.setPen(fn.mkPen(QtGui.QColor(0, 0, 0, 0))) else: p.setPen(fn.mkPen(self.edgecolors)) + if self.antialiasing: + p.setRenderHint(QtGui.QPainter.Antialiasing) + ## Prepare colormap # First we get the LookupTable @@ -190,9 +198,8 @@ class PColorMeshItem(GraphicsObject): for yi in range(self.z.shape[1]): # Set the color of the polygon first - # print(xi, yi, norm[xi][yi]) c = lut[norm[xi][yi]] - p.setBrush(QtGui.QColor(c[0], c[1], c[2])) + p.setBrush(fn.mkBrush(QtGui.QColor(c[0], c[1], c[2]))) polygon = QtGui.QPolygonF( [QtCore.QPointF(self.x[xi][yi], self.y[xi][yi]), @@ -208,18 +215,16 @@ class PColorMeshItem(GraphicsObject): p.end() self.update() + self.prepareGeometryChange() if shapeChanged: self.informViewBoundsChanged() - self.prepareGeometryChange() def paint(self, p, *args): - profile = debug.Profiler() if self.z is None: return - profile('p.drawPicture') p.drawPicture(0, 0, self.qpicture)