2012-03-23 17:38:53 +00:00
|
|
|
|
|
|
|
|
2012-05-11 22:05:41 +00:00
|
|
|
from .GraphicsObject import *
|
2012-03-23 17:38:53 +00:00
|
|
|
import pyqtgraph.functions as fn
|
2012-04-04 16:22:43 +00:00
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
2012-03-23 17:38:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class IsocurveItem(GraphicsObject):
|
|
|
|
"""
|
2012-04-25 17:12:40 +00:00
|
|
|
**Bases:** :class:`GraphicsObject <pyqtgraph.GraphicsObject>`
|
2012-03-23 17:38:53 +00:00
|
|
|
|
2012-04-25 17:12:40 +00:00
|
|
|
Item displaying an isocurve of a 2D array.To align this item correctly with an
|
|
|
|
ImageItem,call isocurve.setParentItem(image)
|
2012-03-23 17:38:53 +00:00
|
|
|
"""
|
|
|
|
|
2012-04-25 17:12:40 +00:00
|
|
|
|
2012-04-04 16:22:43 +00:00
|
|
|
def __init__(self, data=None, level=0, pen='w'):
|
2012-04-25 17:12:40 +00:00
|
|
|
"""
|
|
|
|
Create a new isocurve item.
|
|
|
|
|
|
|
|
============= ===============================================================
|
|
|
|
**Arguments**
|
|
|
|
data A 2-dimensional ndarray. Can be initialized as None, and set
|
|
|
|
later using :func:`setData <pyqtgraph.IsocurveItem.setData>`
|
|
|
|
level The cutoff value at which to draw the isocurve.
|
|
|
|
pen The color of the curve item. Can be anything valid for
|
|
|
|
:func:`mkPen <pyqtgraph.mkPen>`
|
|
|
|
============= ===============================================================
|
|
|
|
"""
|
2012-03-23 17:38:53 +00:00
|
|
|
GraphicsObject.__init__(self)
|
2012-04-25 17:12:40 +00:00
|
|
|
|
|
|
|
self.level = level
|
2012-04-04 16:22:43 +00:00
|
|
|
self.data = None
|
|
|
|
self.path = None
|
2012-03-23 17:38:53 +00:00
|
|
|
self.setPen(pen)
|
2012-04-25 17:12:40 +00:00
|
|
|
self.setData(data, level)
|
|
|
|
|
2012-03-23 17:38:53 +00:00
|
|
|
|
2012-04-25 17:12:40 +00:00
|
|
|
|
|
|
|
#if data is not None and level is not None:
|
|
|
|
#self.updateLines(data, level)
|
|
|
|
|
2012-04-04 16:22:43 +00:00
|
|
|
|
|
|
|
def setData(self, data, level=None):
|
2012-04-25 17:12:40 +00:00
|
|
|
"""
|
|
|
|
Set the data/image to draw isocurves for.
|
|
|
|
|
2012-12-22 21:51:25 +00:00
|
|
|
============= ========================================================================
|
2012-04-25 17:12:40 +00:00
|
|
|
**Arguments**
|
|
|
|
data A 2-dimensional ndarray.
|
|
|
|
level The cutoff value at which to draw the curve. If level is not specified,
|
2012-12-22 21:51:25 +00:00
|
|
|
the previously set level is used.
|
|
|
|
============= ========================================================================
|
2012-04-25 17:12:40 +00:00
|
|
|
"""
|
2012-04-04 16:22:43 +00:00
|
|
|
if level is None:
|
|
|
|
level = self.level
|
|
|
|
self.level = level
|
|
|
|
self.data = data
|
|
|
|
self.path = None
|
|
|
|
self.prepareGeometryChange()
|
|
|
|
self.update()
|
|
|
|
|
2012-04-25 17:12:40 +00:00
|
|
|
|
2012-04-04 16:22:43 +00:00
|
|
|
def setLevel(self, level):
|
2012-04-25 17:12:40 +00:00
|
|
|
"""Set the level at which the isocurve is drawn."""
|
2012-04-04 16:22:43 +00:00
|
|
|
self.level = level
|
|
|
|
self.path = None
|
|
|
|
self.update()
|
|
|
|
|
2012-04-25 17:12:40 +00:00
|
|
|
|
2012-03-23 17:38:53 +00:00
|
|
|
def setPen(self, *args, **kwargs):
|
2012-04-25 17:12:40 +00:00
|
|
|
"""Set the pen used to draw the isocurve. Arguments can be any that are valid
|
|
|
|
for :func:`mkPen <pyqtgraph.mkPen>`"""
|
2012-03-23 17:38:53 +00:00
|
|
|
self.pen = fn.mkPen(*args, **kwargs)
|
|
|
|
self.update()
|
|
|
|
|
2012-12-22 21:51:25 +00:00
|
|
|
def setBrush(self, *args, **kwargs):
|
|
|
|
"""Set the brush used to draw the isocurve. Arguments can be any that are valid
|
|
|
|
for :func:`mkBrush <pyqtgraph.mkBrush>`"""
|
|
|
|
self.brush = fn.mkBrush(*args, **kwargs)
|
|
|
|
self.update()
|
|
|
|
|
2012-04-25 17:12:40 +00:00
|
|
|
|
|
|
|
def updateLines(self, data, level):
|
|
|
|
##print "data:", data
|
|
|
|
##print "level", level
|
|
|
|
#lines = fn.isocurve(data, level)
|
|
|
|
##print len(lines)
|
|
|
|
#self.path = QtGui.QPainterPath()
|
|
|
|
#for line in lines:
|
|
|
|
#self.path.moveTo(*line[0])
|
|
|
|
#self.path.lineTo(*line[1])
|
|
|
|
#self.update()
|
|
|
|
self.setData(data, level)
|
|
|
|
|
2012-03-23 17:38:53 +00:00
|
|
|
def boundingRect(self):
|
2012-12-22 21:51:25 +00:00
|
|
|
if self.data is None:
|
2012-04-04 16:22:43 +00:00
|
|
|
return QtCore.QRectF()
|
2012-12-22 21:51:25 +00:00
|
|
|
if self.path is None:
|
|
|
|
self.generatePath()
|
2012-03-23 17:38:53 +00:00
|
|
|
return self.path.boundingRect()
|
|
|
|
|
2012-04-04 16:22:43 +00:00
|
|
|
def generatePath(self):
|
|
|
|
if self.data is None:
|
2012-12-22 21:51:25 +00:00
|
|
|
self.path = None
|
2012-04-04 16:22:43 +00:00
|
|
|
return
|
2012-12-22 21:51:25 +00:00
|
|
|
lines = fn.isocurve(self.data, self.level, connected=True, extendToEdge=True)
|
|
|
|
self.path = QtGui.QPainterPath()
|
2012-04-04 16:22:43 +00:00
|
|
|
for line in lines:
|
|
|
|
self.path.moveTo(*line[0])
|
2012-12-22 21:51:25 +00:00
|
|
|
for p in line[1:]:
|
|
|
|
self.path.lineTo(*p)
|
2012-04-04 16:22:43 +00:00
|
|
|
|
2012-03-23 17:38:53 +00:00
|
|
|
def paint(self, p, *args):
|
2012-12-22 21:51:25 +00:00
|
|
|
if self.data is None:
|
|
|
|
return
|
2012-04-04 16:22:43 +00:00
|
|
|
if self.path is None:
|
|
|
|
self.generatePath()
|
2012-03-23 17:38:53 +00:00
|
|
|
p.setPen(self.pen)
|
|
|
|
p.drawPath(self.path)
|
2012-12-22 21:51:25 +00:00
|
|
|
|