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)
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
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))
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))
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()
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
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))
def shape(self): stroker = QPainterPathStroker() stroker.setWidth(4) stroker.setCapStyle(Qt.RoundCap) return stroker.createStroke(self.path)
def shape(self): ps = QPainterPathStroker() path = QPainterPath() self.draw_shape(path) ps.setWidth(self.pen_width) return ps.createStroke(path)
def shape(self) -> "QPainterPath": path_stroker = QPainterPathStroker() path_stroker.setWidth(self.width + self.clickable_margin) return path_stroker.createStroke(self.path())