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.
|
|
|
|
|
|
|
|
============= ================================================================
|
|
|
|
**Arguments**
|
|
|
|
data A 2-dimensional ndarray.
|
|
|
|
level The cutoff value at which to draw the curve. If level is not specified,
|
|
|
|
the previous level is used.
|
|
|
|
============= ================================================================
|
|
|
|
"""
|
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-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-04-04 16:22:43 +00:00
|
|
|
if self.path is None:
|
|
|
|
return QtCore.QRectF()
|
2012-03-23 17:38:53 +00:00
|
|
|
return self.path.boundingRect()
|
|
|
|
|
2012-04-04 16:22:43 +00:00
|
|
|
def generatePath(self):
|
|
|
|
self.path = QtGui.QPainterPath()
|
|
|
|
if self.data is None:
|
|
|
|
return
|
|
|
|
lines = fn.isocurve(self.data, self.level)
|
|
|
|
for line in lines:
|
|
|
|
self.path.moveTo(*line[0])
|
|
|
|
self.path.lineTo(*line[1])
|
|
|
|
|
2012-03-23 17:38:53 +00:00
|
|
|
def paint(self, p, *args):
|
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)
|
|
|
|
|