speedup
This commit is contained in:
parent
3a0d599d70
commit
3c5503039f
@ -49,7 +49,8 @@ def update():
|
|||||||
s = np.clip(dt*3., 0, 1)
|
s = np.clip(dt*3., 0, 1)
|
||||||
fps = fps * (1-s) + (1.0/dt) * s
|
fps = fps * (1-s) + (1.0/dt) * s
|
||||||
p.setTitle('%0.2f fps' % fps)
|
p.setTitle('%0.2f fps' % fps)
|
||||||
app.processEvents() ## force complete redraw for every plot
|
p.repaint()
|
||||||
|
#app.processEvents() ## force complete redraw for every plot
|
||||||
timer = QtCore.QTimer()
|
timer = QtCore.QTimer()
|
||||||
timer.timeout.connect(update)
|
timer.timeout.connect(update)
|
||||||
timer.start(0)
|
timer.start(0)
|
||||||
|
@ -105,21 +105,27 @@ class SymbolAtlas:
|
|||||||
self.atlas = None # atlas as QPixmap
|
self.atlas = None # atlas as QPixmap
|
||||||
self.atlasValid = False
|
self.atlasValid = False
|
||||||
|
|
||||||
def getSymbolCoords(self, symbol, size, pen, brush):
|
def getSymbolCoords(self, opts):
|
||||||
|
"""
|
||||||
|
Given a list of spot records, return an object representing the coordinates of that symbol within the atlas
|
||||||
|
"""
|
||||||
|
coords = np.empty(len(opts), dtype=object)
|
||||||
|
for i, rec in enumerate(opts):
|
||||||
|
symbol, size, pen, brush = rec['symbol'], rec['size'], rec['pen'], rec['brush']
|
||||||
|
pen = fn.mkPen(pen) if not isinstance(pen, QtGui.QPen) else pen
|
||||||
|
brush = fn.mkBrush(brush) if not isinstance(pen, QtGui.QBrush) else brush
|
||||||
key = (symbol, size, fn.colorTuple(pen.color()), pen.width(), pen.style(), fn.colorTuple(brush.color()))
|
key = (symbol, size, fn.colorTuple(pen.color()), pen.width(), pen.style(), fn.colorTuple(brush.color()))
|
||||||
if key not in self.symbolMap:
|
if key not in self.symbolMap:
|
||||||
newCoords = SymbolAtlas.SymbolCoords()
|
newCoords = SymbolAtlas.SymbolCoords()
|
||||||
self.symbolMap[key] = newCoords
|
self.symbolMap[key] = newCoords
|
||||||
self.invalidateAtlas()
|
self.atlasValid = False
|
||||||
#try:
|
#try:
|
||||||
#self.addToAtlas(key) ## squeeze this into the atlas if there is room
|
#self.addToAtlas(key) ## squeeze this into the atlas if there is room
|
||||||
#except:
|
#except:
|
||||||
#self.buildAtlas() ## otherwise, we need to rebuild
|
#self.buildAtlas() ## otherwise, we need to rebuild
|
||||||
|
|
||||||
return self.symbolMap[key]
|
coords[i] = self.symbolMap[key]
|
||||||
|
return coords
|
||||||
def invalidateAtlas(self):
|
|
||||||
self.atlasValid = False
|
|
||||||
|
|
||||||
def buildAtlas(self):
|
def buildAtlas(self):
|
||||||
# get rendered array for all symbols, keep track of avg/max width
|
# get rendered array for all symbols, keep track of avg/max width
|
||||||
@ -512,15 +518,26 @@ class ScatterPlotItem(GraphicsObject):
|
|||||||
dataSet = self.data
|
dataSet = self.data
|
||||||
self._maxSpotWidth = 0
|
self._maxSpotWidth = 0
|
||||||
self._maxSpotPxWidth = 0
|
self._maxSpotPxWidth = 0
|
||||||
if self.opts['pxMode']:
|
invalidate = False
|
||||||
for rec in dataSet:
|
|
||||||
if rec['fragCoords'] is None:
|
|
||||||
|
|
||||||
|
|
||||||
rec['fragCoords'] = self.fragmentAtlas.getSymbolCoords(*self.getSpotOpts(rec))
|
|
||||||
self.measureSpotSizes(dataSet)
|
self.measureSpotSizes(dataSet)
|
||||||
|
if self.opts['pxMode']:
|
||||||
|
mask = np.equal(dataSet['fragCoords'], None)
|
||||||
|
if np.any(mask):
|
||||||
|
invalidate = True
|
||||||
|
opts = self.getSpotOpts(dataSet[mask])
|
||||||
|
coords = self.fragmentAtlas.getSymbolCoords(opts)
|
||||||
|
dataSet['fragCoords'][mask] = coords
|
||||||
|
|
||||||
def getSpotOpts(self, rec):
|
#for rec in dataSet:
|
||||||
|
#if rec['fragCoords'] is None:
|
||||||
|
#invalidate = True
|
||||||
|
#rec['fragCoords'] = self.fragmentAtlas.getSymbolCoords(*self.getSpotOpts(rec))
|
||||||
|
if invalidate:
|
||||||
|
self.invalidate()
|
||||||
|
|
||||||
|
def getSpotOpts(self, recs):
|
||||||
|
if recs.ndim == 0:
|
||||||
|
rec = recs
|
||||||
symbol = rec['symbol']
|
symbol = rec['symbol']
|
||||||
if symbol is None:
|
if symbol is None:
|
||||||
symbol = self.opts['symbol']
|
symbol = self.opts['symbol']
|
||||||
@ -534,6 +551,14 @@ class ScatterPlotItem(GraphicsObject):
|
|||||||
if brush is None:
|
if brush is None:
|
||||||
brush = self.opts['brush']
|
brush = self.opts['brush']
|
||||||
return (symbol, size, fn.mkPen(pen), fn.mkBrush(brush))
|
return (symbol, size, fn.mkPen(pen), fn.mkBrush(brush))
|
||||||
|
else:
|
||||||
|
recs = recs.copy()
|
||||||
|
recs['symbol'][np.equal(recs['symbol'], None)] = self.opts['symbol']
|
||||||
|
recs['size'][np.equal(recs['size'], -1)] = self.opts['size']
|
||||||
|
recs['pen'][np.equal(recs['pen'], None)] = fn.mkPen(self.opts['pen'])
|
||||||
|
recs['brush'][np.equal(recs['brush'], None)] = fn.mkBrush(self.opts['brush'])
|
||||||
|
return recs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def measureSpotSizes(self, dataSet):
|
def measureSpotSizes(self, dataSet):
|
||||||
@ -642,7 +667,6 @@ class ScatterPlotItem(GraphicsObject):
|
|||||||
def paint(self, p, *args):
|
def paint(self, p, *args):
|
||||||
#p.setPen(fn.mkPen('r'))
|
#p.setPen(fn.mkPen('r'))
|
||||||
#p.drawRect(self.boundingRect())
|
#p.drawRect(self.boundingRect())
|
||||||
|
|
||||||
if self.opts['pxMode']:
|
if self.opts['pxMode']:
|
||||||
atlas = self.fragmentAtlas.getAtlas()
|
atlas = self.fragmentAtlas.getAtlas()
|
||||||
#arr = fn.imageToArray(atlas.toImage(), copy=True)
|
#arr = fn.imageToArray(atlas.toImage(), copy=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user