Modify for loop into map in ScatterPlotItem.py

This commit is contained in:
Guillaume Poulin 2013-09-22 23:10:18 +08:00
parent 3a9258e35e
commit 26b84693a8

View File

@ -3,6 +3,7 @@ from pyqtgraph.Point import Point
import pyqtgraph.functions as fn import pyqtgraph.functions as fn
from .GraphicsItem import GraphicsItem from .GraphicsItem import GraphicsItem
from .GraphicsObject import GraphicsObject from .GraphicsObject import GraphicsObject
from itertools import starmap
import numpy as np import numpy as np
import scipy.stats import scipy.stats
import weakref import weakref
@ -149,7 +150,7 @@ class SymbolAtlas(object):
images.append(img) ## we only need this to prevent the images being garbage collected immediately images.append(img) ## we only need this to prevent the images being garbage collected immediately
arr = fn.imageToArray(img, copy=False, transpose=False) arr = fn.imageToArray(img, copy=False, transpose=False)
else: else:
(x,y,w,h) = self.symbolMap[key] (y,x,h,w) = self.symbolMap[key]
arr = self.atlasData[x:x+w, y:y+w] arr = self.atlasData[x:x+w, y:y+w]
rendered[key] = arr rendered[key] = arr
w = arr.shape[0] w = arr.shape[0]
@ -180,14 +181,14 @@ class SymbolAtlas(object):
x = 0 x = 0
rowheight = h rowheight = h
self.atlasRows.append([y, rowheight, 0]) self.atlasRows.append([y, rowheight, 0])
self.symbolMap[key][:] = x, y, w, h self.symbolMap[key][:] = y, x, h, w
x += w x += w
self.atlasRows[-1][2] = x self.atlasRows[-1][2] = x
height = y + rowheight height = y + rowheight
self.atlasData = np.zeros((width, height, 4), dtype=np.ubyte) self.atlasData = np.zeros((width, height, 4), dtype=np.ubyte)
for key in symbols: for key in symbols:
x, y, w, h = self.symbolMap[key] y, x, h, w = self.symbolMap[key]
self.atlasData[x:x+w, y:y+h] = rendered[key] self.atlasData[x:x+w, y:y+h] = rendered[key]
self.atlas = None self.atlas = None
self.atlasValid = True self.atlasValid = True
@ -694,12 +695,15 @@ class ScatterPlotItem(GraphicsObject):
self.fragments = [] self.fragments = []
pts = np.clip(pts, -2**30, 2**30) ## prevent Qt segmentation fault. pts = np.clip(pts, -2**30, 2**30) ## prevent Qt segmentation fault.
## Still won't be able to render correctly, though. ## Still won't be able to render correctly, though.
for i in xrange(len(self.data)): #for i in xrange(len(self.data)):
rec = self.data[i] # rec = self.data[i]
pos = QtCore.QPointF(pts[0,i], pts[1,i]) # pos = QtCore.QPointF(pts[0,i], pts[1,i])
x,y,w,h = rec['fragCoords'] # x,y,w,h = rec['fragCoords']
rect = QtCore.QRectF(y, x, h, w) # rect = QtCore.QRectF(y, x, h, w)
self.fragments.append(QtGui.QPainter.PixmapFragment.create(pos, rect)) # self.fragments.append(QtGui.QPainter.PixmapFragment.create(pos, rect))
rect = starmap(QtCore.QRectF, self.data['fragCoords'])
pos = map(QtCore.QPointF, pts[0,:], pts[1,:])
self.fragments = map(QtGui.QPainter.PixmapFragment.create, pos, rect)
def setExportMode(self, *args, **kwds): def setExportMode(self, *args, **kwds):
GraphicsObject.setExportMode(self, *args, **kwds) GraphicsObject.setExportMode(self, *args, **kwds)