Cache the ring preview using the expected size to avoid resampling

This commit is contained in:
Valentin Valls 2019-05-16 18:35:38 +02:00
parent f8eb95c42a
commit 6e5a4b0d6b
1 changed files with 6 additions and 6 deletions

View File

@ -27,7 +27,7 @@ from __future__ import absolute_import
__authors__ = ["V. Valls"]
__license__ = "MIT"
__date__ = "10/05/2019"
__date__ = "16/05/2019"
import logging
import numpy
@ -55,6 +55,7 @@ class CalibrantPreview(qt.QFrame):
self.__calibrant = None
self.__waveLength = None
self.__pixmap = None
self.__cachedSize = None
self.setMinimumSize(qt.QSize(50, 20))
def setCalibrant(self, calibrant):
@ -124,17 +125,15 @@ class CalibrantPreview(qt.QFrame):
toolTip = u"<html><ul>%s</ul></html>" % toolTip
self.setToolTip(toolTip)
def __getPixmap(self):
if self.__pixmap is not None:
def __getPixmap(self, size=360):
if self.__pixmap is not None and self.__cachedSize == size:
return self.__pixmap
calibrant = self.__getConfiguredCalibrant()
if calibrant is None:
return None
tths = numpy.array(calibrant.get_2th())
tth_min, tth_max = 0, numpy.pi
size = 360
histo = numpy.histogram(tths, bins=size, range=(tth_min, tth_max))
agregation = histo[0].reshape(1, -1)
colormap = Colormap(name="reversed gray", vmin=agregation.min(), vmax=agregation.max())
@ -142,6 +141,7 @@ class CalibrantPreview(qt.QFrame):
qimage = imageutils.convertArrayToQImage(rgbImage)
qpixmap = qt.QPixmap.fromImage(qimage)
self.__pixmap = qpixmap
self.__cachedSize = size
return self.__pixmap
def paintEvent(self, event):
@ -160,9 +160,9 @@ class CalibrantPreview(qt.QFrame):
self)
# content
pixmap = self.__getPixmap()
pixmapRect = self.rect().adjusted(self._PIXMAP_OFFSET, self._PIXMAP_OFFSET,
-self._PIXMAP_OFFSET, -self._PIXMAP_OFFSET)
pixmap = self.__getPixmap(size=pixmapRect.width())
if pixmap is not None:
painter.drawPixmap(pixmapRect,
pixmap,