Ejemplo n.º 1
0
 def __init__(self, size, fixedPoints=None, parentItem=None):
     """
     Inits a cubicSpline with an empty set of control points and
     an empty curve
     @param size: initial path size
     @type size: int
     @param parentItem:
     @type parentItem: object
     """
     self.curveChanged = baseSignal_No()  # TODO added 5/11/18 validate
     super().__init__()
     if fixedPoints is None:
         fixedPoints = []
     self.setParentItem(parentItem)
     qpp = QPainterPath()
     self.size = size
     # initial curve : diagonal
     qpp.lineTo(QPoint(size, -size))
     # stroke curve
     stroker = QPainterPathStroker()
     stroker.setWidth(self.strokeWidth)
     self.mboundingPath = stroker.createStroke(qpp)
     self.setPath(self.mboundingPath)
     self.clicked = False
     #self.selected = False
     self.setVisible(False)
     self.fixedPoints = fixedPoints
     # self.spline is the list of QPointF instances to plot (scene coordinates)
     self.spline = []
     # self.LUTXY is the 1D LUT : range 0..255 --> 0..255, type ndarray, dtype=int, size=256
     self.LUTXY = np.arange(256)
     self.channel = channelValues.RGB
     self.histImg = None
     # set item pen
     self.setPen(QPen(QBrush(self.brushColor), self.penWidth))
Ejemplo n.º 2
0
 def updatePath(self):
     axeSize = self.size
     yZero = self.yZero
     try:
         X = []
         for item in self.fixedPoints:
             X.extend([item.B.x() + item.x(), item.C.x() + item.x()])
         X = np.array(X)
         Y = np.array(
             [-(item.A.y() + item.y())
              for item in self.fixedPoints]) + yZero
         T = displacementSpline(X,
                                Y,
                                self.xCoords,
                                clippingInterval=[-self.scene().axeSize, 0],
                                period=self.period)
         self.spline = [
             QPointF(x, y + yZero) for x, y in zip(self.xCoords, -T)
         ]  # scene coord.
         # build path
         polygon = QPolygonF(self.spline)
         qpp = QPainterPath()
         qpp.addPolygon(polygon)
         # stroke path
         stroker = QPainterPathStroker()
         stroker.setWidth(self.strokeWidth)
         mboundingPath = stroker.createStroke(qpp)
         self.setPath(mboundingPath)
     except ValueError:
         pass
Ejemplo n.º 3
0
 def _draw_wire(self, painter, line):
     p = QPen(Qt.black, 8, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap)
     path = QPainterPath(line.p1())
     path.lineTo(line.p2())
     stroker = QPainterPathStroker(p)
     stroke = stroker.createStroke(path)
     painter.setPen(QPen(Qt.black, 2))
     painter.fillPath(stroke, Qt.white)
     painter.drawPath(stroke)
Ejemplo n.º 4
0
 def updatePath(self, calculate=True):
     """
     Calculates (if calculate=true) and displays the spline.
     Called by activePoint and activeTangent mouse event
     @param calculate:
     @type calculate: bool
     """
     # calculate the array of slopes
     d = [
         item.controlPoint - item.contactPoint
         for item in self.fixedTangents
     ]
     d1 = -np.array(list(map(lambda a: a.y(), d)))
     d2 = np.array(list(map(lambda a: a.x(), d)))
     d = d1 / d2
     # add boundary points if needed
     X = [item.x() for item in self.fixedPoints]
     Y = [item.y() for item in self.fixedPoints]
     X0, X1 = X[0], X[-1]
     Y0, Y1 = Y[0], Y[-1]
     t = (Y1 - Y0) / (X1 - X0)
     Y2 = Y0 - X0 * t
     Y3 = Y0 + (self.size - X0) * t
     d = d.tolist()
     if X[0] > 0.0:
         X.insert(0, 0.0)
         Y.insert(0, Y2)
         d.insert(0, t)
     if X[-1] < self.size:
         X.append(self.size)
         Y.append(Y3)
         d.append(t)
     d = np.array(d)
     try:
         if calculate:
             T = interpolationQuadSpline(
                 np.array(X) / self.size, -np.array(Y) / self.size,
                 d) * self.size
             self.spline = [
                 QPointF(x, y)
                 for x, y in zip(np.arange(256) * (self.size / 255.0), -T)
             ]
         for P in self.spline:
             if P.x() < X0:
                 P.setY(Y0)
             elif P.x() > X1:
                 P.setY(Y1)
         polygon = QPolygonF(self.spline)
         qpp = QPainterPath()
         qpp.addPolygon(polygon)
         # stroke path
         stroker = QPainterPathStroker()
         stroker.setWidth(self.strokeWidth)
         mboundingPath = stroker.createStroke(qpp)
         self.setPath(mboundingPath)
     except Exception as e:
         print(str(e))
Ejemplo n.º 5
0
    def shape(self) -> QPainterPath:
        """
		Stroke the shape of the line.

		:return: the arrow path
		:rtype: QPainterPathStroker
		"""
        path = self.buildPath()

        stroker = QPainterPathStroker()
        stroker.setWidth(10)

        return stroker.createStroke(path).simplified()
    def shape(self):
        """
		Stroke the shape of the line.
		
		:return: the arrow path
		:rtype: QPainterPathStroker
		"""
        path, buffer, buffer2 = self.buildPath(self._x1, self._x2, self._y1,
                                               self._y2)

        stroker = QPainterPathStroker()
        stroker.setWidth(50)

        return stroker.createStroke(path).simplified()
Ejemplo n.º 7
0
    def _draw_wire(self, painter, line, ghost):
        p = QPen(Qt.black, 8, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap)
        path = QPainterPath(line.p1())
        path.lineTo(line.p2())
        stroker = QPainterPathStroker(p)
        stroke = stroker.createStroke(path)

        fill_color = QColor(255, 255, 255)
        outline_color = QColor(0, 0, 0)

        if ghost:
            fill_color.setAlphaF(0.5)
            outline_color.setAlphaF(0.5)

        painter.setPen(QPen(outline_color, 2))
        painter.fillPath(stroke, fill_color)
        painter.drawPath(stroke)
Ejemplo n.º 8
0
    def _draw_wires(self, painter):
        path = QPainterPath()

        for wire in self.wires:
            path.moveTo(wire.p1())
            path.lineTo(wire.p2())

        p = QPen(Qt.black, 8, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap)

        stroker = QPainterPathStroker(p)
        stroke = stroker.createStroke(path).simplified()

        fill_color = QColor(255, 255, 255)
        outline_color = QColor(0, 0, 0)

        painter.setPen(QPen(outline_color, 2))
        painter.fillPath(stroke, fill_color)
        painter.drawPath(stroke)
Ejemplo n.º 9
0
 def updatePath(self):
     """
     Update and display the spline. Should be called after
     each control point or tangent modification : see
     activePoint and activeTangent mouse event handlers
     """
     # add ending control points, if needed,
     # to get full range 0..self.size
     X = [item.x() for item in self.fixedPoints]
     Y = [item.y() for item in self.fixedPoints]
     X0, X1 = X[0], X[-1]
     Y0, Y1 = Y[0], Y[-1]
     Y2 = Y0 - X0 * (Y1 - Y0) / (X1 - X0)
     Y3 = Y0 + (self.size - X0) * (Y1 - Y0) / (X1 - X0)
     if X[0] > 0.0:
         X.insert(0, 0.0)
         Y.insert(0, Y2)
     if X[-1] < self.size:
         X.append(self.size)
         Y.append(Y3)
     # interpolate
     try:
         # interpolationCubSpline raises an exception if two points have identical x-coordinates
         self.spline = interpolationCubSpline(
             np.array(X),
             np.array(Y),
             clippingInterval=[-self.scene().axeSize, 0])
         # set the curve constant outside ]X0..X1[
         for P in self.spline:
             if P.x() < X0:
                 P.setY(Y0)
             elif P.x() > X1:
                 P.setY(Y1)
         # build path
         polygon = QPolygonF(self.spline)
         qpp = QPainterPath()
         qpp.addPolygon(polygon)
         # stroke path
         stroker = QPainterPathStroker()
         stroker.setWidth(self.strokeWidth)
         mboundingPath = stroker.createStroke(qpp)
         self.setPath(mboundingPath)
     except ValueError:
         pass
Ejemplo n.º 10
0
 def __init__(self,
              size,
              fixedPoints=None,
              baseCurve=None,
              parentItem=None):
     """
     Init an interactive spline with an empty set of control points and
     an empty curve
     @param size: initial path size
     @type size: int
     @param fixedPoints:
     @type fixedPoints:
     @param baseCurve: starting (initial) curve
     @type baseCurve: 2-uple of QPoint
     @param parentItem:
     @type parentItem: object
     """
     self.curveChanged = baseSignal_No()
     super().__init__(parent=parentItem)
     if fixedPoints is None:
         fixedPoints = []
     self.size = size
     # default initial curve : diagonal
     if baseCurve is None:
         baseCurve = (QPoint(0, 0), QPoint(size, -size))
     qpp = QPainterPath()
     qpp.moveTo(baseCurve[0])
     qpp.lineTo(baseCurve[1])
     # stroke curve
     stroker = QPainterPathStroker()
     stroker.setWidth(self.strokeWidth)
     self.mboundingPath = stroker.createStroke(qpp)
     self.setPath(self.mboundingPath)
     self.clicked = False
     self.setVisible(False)
     self.fixedPoints = fixedPoints
     self.__spline = []
     # self.LUTXY is the 1D LUT : range 0..255 --> 0..255, type ndarray, dtype=int, size=256
     self.LUTXY = np.arange(256)
     self.channel = channelValues.RGB
     self.histImg = None
     # set item pen
     self.setPen(QPen(QBrush(self.brushColor), self.penWidth))
Ejemplo n.º 11
0
def _make_wire_item(x1, y1, x2, y2):
    path = QPainterPath()

    path.moveTo(x1, y1)
    path.lineTo(x2, y2)

    path_item = QGraphicsPathItem(path)

    stroker = QPainterPathStroker(QPen(Qt.black, 5, c=Qt.RoundCap))
    stroke_path = stroker.createStroke(path)
    stroke_item = QGraphicsPathItem(stroke_path)

    path_item.setPen(QPen(Qt.white, 5, c=Qt.RoundCap))
    stroke_item.setPen(QPen(Qt.black, 1.5, c=Qt.RoundCap))

    group = QGraphicsItemGroup()
    group.addToGroup(path_item)
    group.addToGroup(stroke_item)

    group.setFlag(QGraphicsItem.ItemIsSelectable)

    return group
Ejemplo n.º 12
0
 def shape(self):
     stroker = QPainterPathStroker()
     stroker.setWidth(4)
     stroker.setCapStyle(Qt.RoundCap)
     return stroker.createStroke(self.path)
Ejemplo n.º 13
0
 def shape(self):
     ps = QPainterPathStroker()
     path = QPainterPath()
     self.draw_shape(path)
     ps.setWidth(self.pen_width)
     return ps.createStroke(path)
 def shape(self) -> QPainterPath:
     stroker = QPainterPathStroker()
     stroker.setWidth(10)
     stroker.setJoinStyle(Qt.MiterJoin)
     stroker.setCapStyle(Qt.RoundCap)
     stroker.setDashPattern(Qt.DashLine)
     return stroker.createStroke(self.__path)
Ejemplo n.º 15
0
 def shape(self) -> "QPainterPath":
     path_stroker = QPainterPathStroker()
     path_stroker.setWidth(self.width + self.clickable_margin)
     return path_stroker.createStroke(self.path())