2012-03-23 17:38:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
from GraphicsObject import *
|
|
|
|
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):
|
|
|
|
"""
|
|
|
|
Item displaying an isocurve of a 2D array.
|
|
|
|
|
|
|
|
To align this item correctly with an ImageItem,
|
|
|
|
call isocurve.setParentItem(image)
|
|
|
|
"""
|
|
|
|
|
2012-04-04 16:22:43 +00:00
|
|
|
def __init__(self, data=None, level=0, pen='w'):
|
2012-03-23 17:38:53 +00:00
|
|
|
GraphicsObject.__init__(self)
|
2012-04-04 16:22:43 +00:00
|
|
|
self.level = 0
|
|
|
|
self.data = None
|
|
|
|
self.path = None
|
|
|
|
self.setData(data, level)
|
2012-03-23 17:38:53 +00:00
|
|
|
self.setPen(pen)
|
|
|
|
|
2012-04-04 16:22:43 +00:00
|
|
|
|
|
|
|
def setData(self, data, level=None):
|
|
|
|
if level is None:
|
|
|
|
level = self.level
|
|
|
|
self.level = level
|
|
|
|
self.data = data
|
|
|
|
self.path = None
|
|
|
|
self.prepareGeometryChange()
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
def setLevel(self, level):
|
|
|
|
self.level = level
|
|
|
|
self.path = None
|
|
|
|
self.update()
|
|
|
|
|
2012-03-23 17:38:53 +00:00
|
|
|
def setPen(self, *args, **kwargs):
|
|
|
|
self.pen = fn.mkPen(*args, **kwargs)
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
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)
|
|
|
|
|