def set_path_from_coordinates(self, x, y):
     x_fwd = x
     x_rev = x_fwd[::-1]
     x = numpy.concatenate([x_fwd, x_rev])
     y_fwd = y
     y_rev = y_fwd[::-1]
     y = numpy.concatenate([y_fwd, y_rev])
     path = arrayToQPath(x, y)
     self.setPath(path)
def test_arrayToQPath(xs, ys, connect, expected):
    path = arrayToQPath(xs, ys, connect=connect)
    for i in range(path.elementCount()):
        with suppress(NameError):
            # nan elements add two line-segments, for simplicity of test config
            # we can ignore the second segment
            if (eq(element.x, np.nan) or eq(element.y, np.nan)):
                continue
        element = path.elementAt(i)
        assert eq(expected[i], (element.type, element.x, element.y))
 def set_path_from_coordinates(self, x, y):
     # TODO: Going back along the path to avoid creation of an area by the automatically closing path may not be the
     # best solution...
     x[:] = [i + 0.5 for i in x]
     y[:] = [i + 0.5 for i in y]
     x_fwd = x
     x_rev = x_fwd[::-1]
     x = numpy.concatenate([x_fwd, x_rev])
     y_fwd = y
     y_rev = y_fwd[::-1]
     y = numpy.concatenate([y_fwd, y_rev])
     path = arrayToQPath(x, y)
     self.setPath(path)
Beispiel #4
0
 def set_path_from_coordinates(self, x, y):
     # TODO: Going back along the path to avoid creation of an area by the automatically closing path may not be the
     # best solution...
     x[:] = [i + 0.5 for i in x]
     y[:] = [i + 0.5 for i in y]
     x_fwd = x
     x_rev = x_fwd[::-1]
     x = numpy.concatenate([x_fwd, x_rev])
     y_fwd = y
     y_rev = y_fwd[::-1]
     y = numpy.concatenate([y_fwd, y_rev])
     path = arrayToQPath(x, y)
     self.setPath(path)
Beispiel #5
0
 def generatePath(self, x, y):
     if self.opts['stepMode']:
         ## each value in the x/y arrays generates 2 points.
         x2 = np.empty((len(x),2), dtype=x.dtype)
         x2[:] = x[:,np.newaxis]
         if self.opts['fillLevel'] is None:
             x = x2.reshape(x2.size)[1:-1]
             y2 = np.empty((len(y),2), dtype=y.dtype)
             y2[:] = y[:,np.newaxis]
             y = y2.reshape(y2.size)
         else:
             ## If we have a fill level, add two extra points at either end
             x = x2.reshape(x2.size)
             y2 = np.empty((len(y)+2,2), dtype=y.dtype)
             y2[1:-1] = y[:,np.newaxis]
             y = y2.reshape(y2.size)[1:-1]
             y[0] = self.opts['fillLevel']
             y[-1] = self.opts['fillLevel']
     
     path = fn.arrayToQPath(x, y, connect='all')
     
     return path
                # print "MyPathItem right click event detected!"
                pen = QPen(QColor(255, 255, 0))
                pen.setWidth(5)
                self.setPen(pen)

app = QtGui.QApplication([])

v = Viewer()

xFwd = numpy.array([10, 20, 40, 80])
xRev = xFwd[::-1]
x = numpy.concatenate([xFwd, xRev])
yFwd = numpy.array([80, 90, 100, 110])
yRev = yFwd[::-1]
y = numpy.concatenate([yFwd, yRev])
path1 = arrayToQPath(x, y)

item1 = ClickablePathItem()
item1.setPath(path1)

# Create images
back = (numpy.ones((100, 200, 300)) * 0).astype(numpy.uint8)
back[0:60, 0:60, 0:60] = 255
back[40:80, 40:80, 40:80] = 120
back[40:100, 40:100, 0:40] = 80
back[0:45, 50:100, 0:100] = 200
ol = (numpy.zeros((100, 200, 300))).astype(numpy.uint8)
# ol[0:99, 0:99, 0:99] = 120
# ol[0:99, 120:140, 0:99] = 255
ol[:] = back
back.shape = (1,)+back.shape+(1,)
# #
# # s = (raw/64).astype(numpy.uint8)
#
#
# def onClick(layer, pos5D, pos):
#     print "here i am: ", pos5D, s[pos5D]
#
# l2 = v.addColorTableLayer(ol, clickFunctor=onClick, name="thresh")
# l2.colortableIsRandom = True
# l2.zeroIsTransparent = True
# l2.visible = True
#
# # v.addClickableSegmentationLayer(s, "click it", direct=True)

x = numpy.array([200, 200, 200, 200])
y = numpy.array([10, 100, 200, 300])
qpp = arrayToQPath(x, y)
painter = QtGui.QPainter()
painter.begin(v)
painter.fillRect(0, 0, 100, 100, Qt.Qt.red)
painter.setPen(
    QtGui.QPen(QtGui.QColor(0, 100, 100), 1, Qt.Qt.SolidLine, Qt.Qt.FlatCap,
               Qt.Qt.MiterJoin))
painter.setBrush(QtGui.QColor(122, 163, 39))
painter.drawPath(qpp)
painter.end()

v.setWindowTitle("streaming viewer")
v.showMaximized()
app.exec_()
Beispiel #8
0
# path1 = QPainterPath()
# path1.addRect(20, 20, 60, 60)
path2 = QPainterPath()
path2.moveTo(0, 0)
path2.cubicTo(99, 0, 50, 50, 99, 99)
path2.cubicTo(0, 99, 50, 50, 0, 0)

xFwd = numpy.array([10, 20, 40, 80])
xRev = xFwd[::-1]
x = numpy.concatenate([xFwd, xRev])
yFwd = numpy.array([80, 90, 100, 110])
yRev = yFwd[::-1]
y = numpy.concatenate([yFwd, yRev])
print x, y
path1 = arrayToQPath(x, y)
# path1 = QPainterPath()
# poly = QPolygonF()
# poly.append(QPointF(10, 80))
# poly.append(QPointF(20, 90))
# poly.append(QPointF(40, 100))
# poly.append(QPointF(80, 110))
# path1.addPolygon(poly)

item1 = MyPathItem()
item1.setPath(path1)
item1.setPen(QtGui.QPen(QColor(255, 255, 0)))
item1.setBrush(QBrush(Qt.TransparentMode))

# scene.addPath(path)