Python PyQt5.QtGui.QPolygonF() Examples

The following are code examples for showing how to use PyQt5.QtGui.QPolygonF(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, geometry=QtGui.QPolygonF(),
         brush=QtGui.QBrush(QtCore.Qt.NoBrush),
         pen=QtGui.QPen(QtCore.Qt.NoPen)):
        """
        Initialize the polygon.
        :type geometry: T <= QRectF|QtGui.QPolygonF|QPainterPath
        :type brush: QBrush
        :type pen: QPen
        """
        self._geometry = geometry
        self._brush = brush
        self._pen = pen

    #############################################
    #   INTERFACE
    ################################# 
Example 2
Project: phidl   Author: amccaugh   File: quickplotter.py    MIT License 6 votes vote down vote up
def add_polygons(self, polygons, color = '#A8F22A', alpha = 1):
        qcolor = QColor()
        qcolor.setNamedColor(color)
        qcolor.setAlphaF(alpha)
        for points in polygons:
            qpoly = QPolygonF( [QPointF(p[0], p[1]) for p in points] )
            scene_poly = self.scene.addPolygon(qpoly)
            scene_poly.setBrush(qcolor)
            scene_poly.setPen(self.pen)
            self.scene_polys.append(scene_poly)
            # Update custom bounding box
            sr = scene_poly.sceneBoundingRect()
            if len(self.scene_polys) == 1:
                self.scene_xmin = sr.left()
                self.scene_xmax = sr.right()
                self.scene_ymin = sr.top()
                self.scene_ymax = sr.bottom()
            else:
                self.scene_xmin = min(self.scene_xmin, sr.left())
                self.scene_xmax = max(self.scene_xmax, sr.right())
                self.scene_ymin = min(self.scene_ymin, sr.top())
                self.scene_ymax = max(self.scene_ymax, sr.bottom()) 
Example 3
Project: echolocation   Author: hgross   File: radar.py    MIT License 6 votes vote down vote up
def _add_latest_input_line(self, angle):
        """Adds a line to the graphic scene that visualizes a scanned angle"""
        mx, my = self._get_middle()
        angle_rad = deg2rad(angle)
        angle_1_rad = deg2rad(angle - self.measurement_angle/2.0)
        angle_2_rad = deg2rad(angle + self.measurement_angle/2.0)
        length = max(self.width(), self.height())

        start_point = (mx, my)
        p1 = (mx + length * math.cos(angle_1_rad), my + length * math.sin(angle_1_rad))
        p2 = (mx + length * math.cos(angle_2_rad), my + length * math.sin(angle_2_rad))

        gradient_start_point, gradient_end_point = (mx, my), (mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad))
        gradient = QLinearGradient(*gradient_start_point, *gradient_end_point)
        gradient.setColorAt(0, Qt.transparent)
        gradient.setColorAt(0.8, Qt.red)
        gradient.setColorAt(1, Qt.darkRed)

        triangle = QPolygonF()
        triangle.append(QPointF(*start_point))
        triangle.append(QPointF(*p1))
        triangle.append(QPointF(*p2))
        triangle.append(QPointF(*start_point))

        self.scene.addPolygon(triangle, pen=QPen(Qt.transparent), brush=QBrush(gradient)) 
Example 4
Project: PyRHEED   Author: yux1991   File: canvas.py    MIT License 6 votes vote down vote up
def draw_rect(self,start,end,width,EnablePlot = True):
        self.clear_canvas()
        rect = QtGui.QPolygonF()
        if QtGui.QGuiApplication.queryKeyboardModifiers().__eq__(QtCore.Qt.ShiftModifier):
            if end.x() == start.x():
                slope = 10
            else:
                slope = (end.y()-start.y())/(end.x()-start.x())
            if slope > np.tan(np.pi/3):
                end.setX(start.x())
            elif slope < np.tan(np.pi/6):
                end.setY(start.y())
            else:
                end.setY(end.x()-start.x()+start.y())
        p1,p2,p3,p4 = self.get_rectangle_position(start,end,width)
        rect.append(p1)
        rect.append(p2)
        rect.append(p3)
        rect.append(p4)
        self._rectItem = self._scene.addPolygon(rect,QtGui.QPen(QtCore.Qt.yellow,1))
        self._rectItem.show()
        self.canvasObject = "rectangle"
        self.saveStart,self.saveEnd,self.saveWidth = start,end,width
        if EnablePlot:
            self.PLOT_INTEGRAL.emit(self.saveStart,self.saveEnd,self.saveWidth) 
Example 5
Project: BUAAAIHomeWork   Author: potato-cat   File: small_arrow.py    GNU General Public License v3.0 6 votes vote down vote up
def paint(self, painter, option, widget):
        path = QPainterPath()
        l_arrow = self.end - self.start
        path.moveTo(self.start)
        path.lineTo(self.end)

        length = math.sqrt(l_arrow.x() ** 2 + l_arrow.y() ** 2)
        sita = math.atan2(l_arrow.y(), l_arrow.x())
        p1 = self.end - QPointF(SMALL_ARROW_WIDTH * math.cos(sita),
                                SMALL_ARROW_WIDTH * math.sin(sita))
        p2 = p1 - QPointF(-(SMALL_ARROW_WIDTH / 2) * math.sin(sita),
                          (SMALL_ARROW_WIDTH / 2) * math.cos(sita))
        p3 = p1 + QPointF(-SMALL_ARROW_WIDTH / 2 * math.sin(sita),
                          SMALL_ARROW_WIDTH / 2 * math.cos(sita))
        path.addPolygon(QPolygonF([p2, p3, self.end, p2]))
        # path = path.simplified()
        painter.setPen(QPen(self.color, 2))
        painter.setBrush(self.color)
        painter.drawPath(path)
        painter.setPen(Qt.red)
        painter.drawPoint(p1) 
Example 6
Project: BUAAAIHomeWork   Author: potato-cat   File: big_arrow.py    GNU General Public License v3.0 6 votes vote down vote up
def paint(self, painter, option, widget):
        path = QPainterPath()
        l_arrow = self.end - self.start
        length = math.sqrt(l_arrow.x() ** 2 + l_arrow.y() ** 2)
        sita = math.atan2(l_arrow.y(), l_arrow.x())
        p1 = self.start + QPointF(-(BIG_ARROW_WIDTH / 2) * math.sin(sita),
                                  (BIG_ARROW_WIDTH / 2) * math.cos(sita))
        p2 = self.start - QPointF(-(BIG_ARROW_WIDTH / 2) * math.sin(sita),
                                  (BIG_ARROW_WIDTH / 2) * math.cos(sita))
        p3 = p2 + QPointF((length - BIG_ARROW_WIDTH) * math.cos(sita),
                          (length - BIG_ARROW_WIDTH) * math.sin(sita))
        p4 = p3 - QPointF(-BIG_ARROW_WIDTH / 2 * math.sin(sita),
                          BIG_ARROW_WIDTH / 2 * math.cos(sita))
        p5 = self.end
        p7 = p1 + QPointF((length - BIG_ARROW_WIDTH) * math.cos(sita),
                          (length - BIG_ARROW_WIDTH) * math.sin(sita))
        p6 = p7 + QPointF(-BIG_ARROW_WIDTH / 2 * math.sin(sita),
                          BIG_ARROW_WIDTH / 2 * math.cos(sita))
        path.addPolygon(QPolygonF([p1, p2, p3, p4, p5, p6, p7, p1]))
        # path = path.simplified()
        painter.setPen(Qt.black)
        painter.setBrush(Qt.yellow)
        painter.drawPath(path) 
Example 7
Project: PyQtSamples   Author: Upcios   File: text_balloon.py    MIT License 6 votes vote down vote up
def paint( self, painter ):
        brush = QtGui.QBrush( QtGui.QColor( "#007430" ) )

        painter.setBrush( brush )
        painter.setPen( QtCore.Qt.NoPen )
        painter.setRenderHint( QtGui.QPainter.Antialiasing )

        painter.drawRoundedRect( 0, 0, self.boundingRect().width(), self.boundingRect().height() - 10, 10, 10 )

        if self.rightAligned:
            points = []
            points.append( QtCore.QPointF( self.boundingRect().width() - 10.0, self.boundingRect().height() - 10.0 ) )
            points.append( QtCore.QPointF( self.boundingRect().width() - 20.0, self.boundingRect().height() ) )
            points.append( QtCore.QPointF( self.boundingRect().width() - 30.0, self.boundingRect().height() - 10.0 ) )
            #needle = QtCore.Qt.QPolygon(points)
            painter.drawConvexPolygon( QtGui.QPolygonF(points) )
        else:
            points = []
            points.append( QtCore.QPointF( 10.0, self.boundingRect().height() - 10.0 ) )
            points.append( QtCore.QPointF( 20.0, self.boundingRect().height() ) )
            points.append( QtCore.QPointF( 30.0, self.boundingRect().height() - 10.0 ) )
            painter.drawConvexPolygon( QtGui.QPolygonF(points) ) 
Example 8
Project: GeoMop   Author: GeoMop   File: scene.py    GNU General Public License v3.0 6 votes vote down vote up
def update(self):
        def com_point(seg1, seg2):
            p0 = seg1.points[0]
            if (p0 is seg2.points[0]) or (p0 is seg2.points[1]):
                return p0
            p1 = seg1.points[1]
            if (p1 is seg2.points[0]) or (p1 is seg2.points[1]):
                return p1
            return None

        def pol_append(pol, seg1, seg2):
            p = com_point(seg1, seg2)
            pol.append(QtCore.QPointF(p.xy[0], p.xy[1]))

        pol = QtGui.QPolygonF()
        segs = self.polygon_data.segments
        pol_append(pol, segs[-1], segs[0])
        for i in range(len(self.polygon_data.segments) - 1):
            pol_append(pol, segs[i], segs[i+1])

        self.setPolygon(pol)
        self.region_brush = GsPolygon.brush_table(self.polygon_data.region.color)
        super().update() 
Example 9
Project: GeoMop   Author: GeoMop   File: diagram_structures.py    GNU General Public License v3.0 6 votes vote down vote up
def get_area_poly(self, layers, diagram_id):
        """Return init area as squads intersection"""
        quads = layers.get_diagram_quads(diagram_id)
        if len(quads)==0:
            return self.area.gtpolygon
        poly = None
        for quad in quads:
            new_poly = QtGui.QPolygonF([
                QtCore.QPointF(quad[0][0], -quad[0][1]), 
                QtCore.QPointF(quad[1][0], -quad[1][1]), 
                QtCore.QPointF(quad[2][0], -quad[2][1]), 
                QtCore.QPointF(quad[3][0], -quad[3][1]), 
                QtCore.QPointF(quad[0][0], -quad[0][1])])
            if poly is None:
                poly = new_poly
            else:
                poly = new_poly.intersected(poly)
        return poly 
Example 10
Project: GeoMop   Author: GeoMop   File: polygon_operation.py    GNU General Public License v3.0 6 votes vote down vote up
def _get_lines_and_qtpoly(self, diagram, polygon):
        """Return lines and qt polygon"""
        points = polygon.vertices()
        qtpolygon = QtGui.QPolygonF()
        lines = []        
        for i in range(0, len(points)):            
            qtpolygon.append(QtCore.QPointF(points[i].xy[0], -points[i].xy[1]))
            if i==0:
                line = diagram.find_line(points[-1].id, points[0].id)
            else:
                line = diagram.find_line(points[i-1].id, points[i].id)
            if line is None:
                raise Exception("Can't find polygon line in diagram")
            lines.append(line)
        qtpolygon.append(QtCore.QPointF(points[0].xy[0], -points[0].xy[1]))
        return lines, qtpolygon 
Example 11
Project: eddy   Author: danielepantaleone   File: common.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, geometry=QtGui.QPolygonF(),
         brush=QtGui.QBrush(QtCore.Qt.NoBrush),
         pen=QtGui.QPen(QtCore.Qt.NoPen)):
        """
        Initialize the polygon.
        :type geometry: T <= QRectF|QtGui.QPolygonF|QPainterPath
        :type brush: QBrush
        :type pen: QPen
        """
        self._geometry = geometry
        self._brush = brush
        self._pen = pen

    #############################################
    #   INTERFACE
    ################################# 
Example 12
Project: tierpsy-tracker   Author: ver228   File: MWTrackerViewer.py    MIT License 6 votes vote down vote up
def draw_food_contour(self, image):
        if self.food_coordinates is None or not self.ui.checkBox_showFood.isChecked():
            return

        painter = QPainter()
        painter.begin(image)

        penwidth = max(1, max(image.height(), image.width()) // 800)
        col = Qt.darkMagenta
        p = QPolygonF()
        for x,y in self.food_coordinates:
            p.append(QPointF(x,y))
            
        pen = QPen()
        pen.setWidth(penwidth)
        pen.setColor(col)
        painter.setPen(pen)

        painter.drawPolyline(p)
        painter.end() 
Example 13
Project: PyQt   Author: PyQt5   File: RewriteHandle.py    GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, event):
        # 绘制默认的样式
        super(SplitterHandle, self).paintEvent(event)
        # 绘制顶部扩展按钮
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setPen(Qt.red)
        # 画矩形
        painter.drawRect(0, 0, self.width(), 24)
        # 画三角形
        painter.setBrush(Qt.red)
        painter.drawPolygon(QPolygonF([
            QPointF(0, (24 - 8) / 2),
            QPointF(self.width() - 2, 24 / 2),
            QPointF(0, (24 + 8) / 2)
        ])) 
Example 14
Project: EGame   Author: digital-bauhaus   File: heal_potion.py    MIT License 6 votes vote down vote up
def draw_polygon(self, painter):
        color = QColor(self.color)
        painter.setPen(QColor(0, 0, 0))
        painter.setBrush(color)

        r = self.size/2

        polygon = QPolygonF()
        polygon.append(QPointF(self._position[0] + r, self._position[1] + r/2))
        polygon.append(QPointF(self._position[0]    , self._position[1] + r  ))
        polygon.append(QPointF(self._position[0] - r, self._position[1] + r/2))
        polygon.append(QPointF(self._position[0] - r, self._position[1] - r/2))
        polygon.append(QPointF(self._position[0]    , self._position[1] - r  ))
        polygon.append(QPointF(self._position[0] + r, self._position[1] - r/2))

        painter.drawPolygon(polygon) 
Example 15
Project: eddy   Author: obdasystems   File: geometry.py    GNU General Public License v3.0 5 votes vote down vote up
def createArea(p1, p2, degrees, size):
    """
    Creates an area between the given QPointF and according to the given angle and size.
    :type p1: QPointF
    :type p2: QPointF
    :type degrees: float
    :type size: int
    :rtype: QPolygonF
    """
    rad = math.radians(degrees)
    x = size / 2 * math.sin(rad)
    y = size / 2 * math.cos(rad)
    a = QtCore.QPointF(+x, +y)
    b = QtCore.QPointF(-x, -y)
    return QtGui.QPolygonF([p1 + a, p1 + b, p2 + b, p2 + a]) 
Example 16
Project: eddy   Author: obdasystems   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, **kwargs):
        """
        Initialize the edge.
        """
        super().__init__(**kwargs)
        self.tail = Polygon(QtGui.QPolygonF())

    #############################################
    #   INTERFACE
    ################################# 
Example 17
Project: eddy   Author: obdasystems   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 - QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 18
Project: eddy   Author: obdasystems   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def createTail(p1, angle, size):
        """
        Create the tail polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 + QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 + QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 19
Project: eddy   Author: obdasystems   File: input.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 4.0) * size, cos(rad + M_PI / 4.0) * size)
        p3 = p2 - QtCore.QPointF(sin(rad + 3.0 / 4.0 * M_PI) * size, cos(rad + 3.0 / 4.0 * M_PI) * size)
        p4 = p3 - QtCore.QPointF(sin(rad - 3.0 / 4.0 * M_PI) * size, cos(rad - 3.0 / 4.0 * M_PI) * size)
        return QtGui.QPolygonF([p1, p2, p3, p4]) 
Example 20
Project: eddy   Author: obdasystems   File: base.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, source, target=None, breakpoints=None, **kwargs):
        """
        Initialize the edge.
        :type source: AbstractNode
        :type target: AbstractNode
        :type breakpoints: list
        """
        super().__init__(**kwargs)

        self.source = source
        self.target = target

        self.anchors = {} # {AbstractNode: Polygon}
        self.breakpoints = breakpoints or [] # [QtCore.QPointF]
        self.handles = [] # [Polygon]
        self.head = Polygon(QtGui.QPolygonF())
        self.path = Polygon(QtGui.QPainterPath())
        self.selection = Polygon(QtGui.QPainterPath())

        self.mp_AnchorNode = None
        self.mp_AnchorNodePos = None
        self.mp_BreakPoint = None
        self.mp_BreakPointPos = None
        self.mp_Pos = None

        self.setAcceptHoverEvents(True)
        self.setCacheMode(AbstractItem.DeviceCoordinateCache)
        self.setFlag(AbstractItem.ItemIsSelectable, True)

    #############################################
    #   INTERFACE
    ################################# 
Example 21
Project: eddy   Author: obdasystems   File: membership.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 - QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 22
Project: eddy   Author: obdasystems   File: individual.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=60, height=60, brush=None, remaining_characters='individual', **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)

        w = max(width, 60)
        h = max(height, 60)
        brush = brush or IndividualNode.DefaultBrush
        pen = IndividualNode.DefaultPen

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(-(x / 2), +((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(-((x / (1 + math.sqrt(2))) / 2), +(y / 2)),
            QtCore.QPointF(+((x / (1 + math.sqrt(2))) / 2), +(y / 2)),
            QtCore.QPointF(+(x / 2), +((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(+(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(+((x / (1 + math.sqrt(2))) / 2), -(y / 2)),
            QtCore.QPointF(-((x / (1 + math.sqrt(2))) / 2), -(y / 2)),
            QtCore.QPointF(-(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
        ])

        self.background = Polygon(createPolygon(w + 8, h + 8))
        self.selection = Polygon(createPolygon(w + 8, h + 8))
        self.polygon = Polygon(createPolygon(w, h), brush, pen)

        self.remaining_characters = remaining_characters

        self.label = NodeLabel(template='individual', pos=self.center, parent=self, editable=True)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.updateNode()
        self.updateTextPos() 
Example 23
Project: eddy   Author: obdasystems   File: role.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=70, height=50, brush=None, remaining_characters='role', **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        
        w = max(width, 70)
        h = max(height, 50)
        brush = brush or RoleNode.DefaultBrush
        pen = RoleNode.DefaultPen

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-x / 2, 0),
            QtCore.QPointF(0, +y / 2),
            QtCore.QPointF(+x / 2, 0),
            QtCore.QPointF(0, -y / 2),
            QtCore.QPointF(-x / 2, 0)
        ])

        self.fpolygon = Polygon(QtGui.QPainterPath())
        self.ipolygon = Polygon(QtGui.QPainterPath())
        self.background = Polygon(createPolygon(w + 8, h + 8))
        self.selection = Polygon(createPolygon(w + 8, h + 8))
        self.polygon = Polygon(createPolygon(w, h), brush, pen)

        self.remaining_characters = remaining_characters

        self.label = NodeLabel(template='role', pos=self.center, parent=self, editable=True)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.updateNode()
        self.updateTextPos()

    #############################################
    #   INTERFACE
    ################################# 
Example 24
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def createPolygon(w, h):
        """
        Returns the initialized polygon according to the given width/height.
        :type w: int
        :type h: int
        :rtype: QtGui.QPolygonF
        """
        return QtGui.QPolygonF([
            QtCore.QPointF(-w / 2 + 10, -h / 2),
            QtCore.QPointF(+w / 2, -h / 2),
            QtCore.QPointF(+w / 2 - 10, +h / 2),
            QtCore.QPointF(-w / 2, +h / 2),
            QtCore.QPointF(-w / 2 + 10, -h / 2),
        ]) 
Example 25
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def createPolygonB(w, h):
        """
        Returns the initialized bottom-half polygon according to the given width/height.
        :type w: int
        :type h: int
        :rtype: QtGui.QPolygonF
        """
        return QtGui.QPolygonF([
            QtCore.QPointF(-w / 2 + 10 / 2, 0),
            QtCore.QPointF(+w / 2 - 10 / 2, 0),
            QtCore.QPointF(+w / 2 - 10, +h / 2),
            QtCore.QPointF(-w / 2, +h / 2),
            QtCore.QPointF(-w / 2 + 10 / 2, 0),
        ]) 
Example 26
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def geometryA(self):
        """
        Returns the geometry of the shape A of this node.
        :rtype: QtGui.QPolygonF
        """
        return self.polygonA.geometry() 
Example 27
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def geometryB(self):
        """
        Returns the geometry of the shape B of this node.
        :rtype: QtGui.QPolygonF
        """
        return self.polygonB.geometry() 
Example 28
Project: eddy   Author: obdasystems   File: operator.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=50, height=30, brush=None, **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-x / 2, 0),
            QtCore.QPointF(-x / 2 + 6, +y / 2),
            QtCore.QPointF(+x / 2 - 6, +y / 2),
            QtCore.QPointF(+x / 2, 0),
            QtCore.QPointF(+x / 2 - 6, -y / 2),
            QtCore.QPointF(-x / 2 + 6, -y / 2),
            QtCore.QPointF(-x / 2, 0),
        ])

        self.background = Polygon(createPolygon(58, 38))
        self.selection = Polygon(createPolygon(58, 38))
        self.polygon = Polygon(createPolygon(50, 30), brush or OperatorNode.DefaultBrush, OperatorNode.DefaultPen)

    #############################################
    #   INTERFACE
    ################################# 
Example 29
Project: eddy   Author: obdasystems   File: base.py    GNU General Public License v3.0 5 votes vote down vote up
def geometry(self):
        """
        Returns the geometry of the shape of this node.
        :rtype: QtGui.QPolygonF
        """
        return self.polygon.geometry() 
Example 30
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def geometry(self):
        """
        Returns the polygon geometry.
        :rtype: T <= QRectF | QPolygonF | QPainterPath
        """
        return self._geometry 
Example 31
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def setGeometry(self, geometry):
        """
        Set the shape polygon.
        :type geometry: T <= QRectF | QPolygonF | QPainterPath
        """
        self._geometry = geometry 
Example 32
Project: phidl   Author: amccaugh   File: quickplotter.py    MIT License 5 votes vote down vote up
def add_port(self, port, is_subport = False):
        if (port.width is None) or (port.width == 0):
            x,y = port.midpoint
            cs = 1 # cross size
            pn = QPointF(x, y+cs)
            ps = QPointF(x, y-cs)
            pe = QPointF(x+cs, y)
            pw = QPointF(x-cs, y)
            qline1 = self.scene.addLine(QLineF(pn, ps))
            qline2 = self.scene.addLine(QLineF(pw, pe))
            port_shapes = [qline1,qline2]
        else:
            point1, point2 = port.endpoints
            point1 = QPointF(point1[0], point1[1])
            point2 = QPointF(point2[0], point2[1])
            qline = self.scene.addLine(QLineF(point1, point2))
            arrow_points = np.array([[0,0],[10,0],[6,4],[6,2],[0,2]])/(40)*port.width
            arrow_qpoly = QPolygonF( [QPointF(p[0], p[1]) for p in arrow_points] )
            port_scene_poly = self.scene.addPolygon(arrow_qpoly)
            port_scene_poly.setRotation(port.orientation)
            port_scene_poly.moveBy(port.midpoint[0], port.midpoint[1])
            port_shapes = [qline,port_scene_poly]
        qtext = self.scene.addText(str(port.name), self.portfont)
        port_items = port_shapes + [qtext]
        rad = port.orientation*np.pi/180
        x,y = port.endpoints[0]*1/4 +  port.endpoints[1]*3/4 + np.array([np.cos(rad), np.sin(rad)])*port.width/8
#        x,y = port.midpoint[0], port.midpoint[1]
#        x,y  = x - qtext.boundingRect().width()/2, y - qtext.boundingRect().height()/2
        qtext.setPos(QPointF(x,y))
        qtext.setFlag(QGraphicsItem.ItemIgnoresTransformations)

        if not is_subport:
            [shape.setPen(self.portpen) for shape in port_shapes]
            qtext.setDefaultTextColor(self.portfontcolor)
            self.portitems += port_items
        else:
            [shape.setPen(self.subportpen) for shape in port_shapes]
            qtext.setDefaultTextColor(self.subportfontcolor)
            self.subportitems += port_items
#        self.portlabels.append(qtext) 
Example 33
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab2.py    MIT License 5 votes vote down vote up
def turn():
    global epi_x, epi_y, p1, p2, p3, p4, rect
    write_log()
    teta = math.radians(window.spin_deg.value())
    t_x = window.spin_turn_x.value()
    t_y = window.spin_turn_y.value()
    scene.clear()

    rect_t = QPolygonF(4)
    p1 = [t_x + (p1[0] - t_x) * math.cos(teta) + (p1[1] - t_y) * math.sin(teta),
          t_y - (p1[0] - t_x) * math.sin(teta) + (p1[1] - t_y) * math.cos(teta)]
    p2 = [t_x + (p2[0] - t_x) * math.cos(teta) + (p2[1] - t_y) * math.sin(teta),
          t_y - (p2[0] - t_x) * math.sin(teta) + (p2[1] - t_y) * math.cos(teta)]
    p3 = [t_x + (p3[0] - t_x) * math.cos(teta) + (p3[1] - t_y) * math.sin(teta),
          t_y - (p3[0] - t_x) * math.sin(teta) + (p3[1] - t_y) * math.cos(teta)]
    p4 = [t_x + (p4[0] - t_x) * math.cos(teta) + (p4[1] - t_y) * math.sin(teta),
          t_y - (p4[0] - t_x) * math.sin(teta) + (p4[1] - t_y) * math.cos(teta)]
    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    scene.addPolygon(rect, pen=p, brush=b)
    l = len(epi_x)
    for i in range(l):
        x1 = t_x + (epi_x[i] - t_x) * math.cos(teta) + (epi_y[i] - t_y) * math.sin(teta)
        y1 = t_y - (epi_x[i] - t_x) * math.sin(teta) + (epi_y[i] - t_y) * math.cos(teta)
        epi_x[i] = x1
        epi_y[i] = y1
        scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p) 
Example 34
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab9.py    MIT License 5 votes vote down vote up
def sutherland_hodgman(clip, pol, norm):
    # дублируем начальную вершину отсекателя в конец
    clip.append(clip[0])

    s = None
    f = None
    # цикл по вершинам отсекателя
    for i in range(len(clip) - 1):
        new = []  # новый массив вершин
        for j in range(len(pol)):    # цикл по вершинам многоугольника
            if j == 0:
                f = pol[j]
            else:
                t = is_intersection([s, pol[j]], [clip[i], clip[i + 1]], norm)
                if t:
                    new.append(t)

            s = pol[j]
            if is_visiable(s,  clip[i], clip[i + 1], norm):
                    new.append(s)

        if len(new) != 0:
            t = is_intersection([s, f], [clip[i], clip[i + 1]], norm)
            if t:
                new.append(t)

        pol = copy.deepcopy(new)

    if len(pol) == 0:
        return False
    else:
        return QPolygonF(pol) 
Example 35
Project: GeoMop   Author: GeoMop   File: diagram_structures.py    GNU General Public License v3.0 5 votes vote down vote up
def set_area(self, points):
        """Set rectangular arrea containing given points."""
        self.gtpolygon = QtGui.QPolygonF()
        self.xmin = points[0][0]
        self.xmax = points[0][0]
        self.ymin = -points[0][1]
        self.ymax = -points[0][1]
        for x, y in points:
            self.gtpolygon.append(QtCore.QPointF(x, -y))
            self.xmin = min(self.xmin, x)
            self.xmax = max(self.xmax, x)
            self.ymin = min(self.ymin, -y)
            self.ymax = max(self.ymax, -y)
        self.gtpolygon.append(QtCore.QPointF(points[0][0], -points[0][1])) 
Example 36
Project: GeoMop   Author: GeoMop   File: polygon_operation.py    GNU General Public License v3.0 5 votes vote down vote up
def _add_to_painter_path(cls, path, wire):
        vtxs = cls._get_wire_oriented_vertices(wire)
        point_list = [QtCore.QPointF(vtxx, -vtxy) for vtxx, vtxy in vtxs]
        sub_poly = QtGui.QPolygonF(point_list)
        path.addPolygon(sub_poly) 
Example 37
Project: GeoMop   Author: GeoMop   File: grid.py    GNU General Public License v3.0 5 votes vote down vote up
def set_quad(self, quad, nuv):
        """Set quad"""
        self.quad = quad
        polygon = QtGui.QPolygonF()
        for point in quad:
            polygon.append(QtCore.QPointF(point[0], -point[1]))
        polygon.append(QtCore.QPointF(quad[0][0], -quad[0][1]))
        self.u, self.v  = nuv
        self.setPolygon(polygon)
        self.update() 
Example 38
Project: GeoMop   Author: GeoMop   File: init_area.py    GNU General Public License v3.0 5 votes vote down vote up
def reload(self):
        """Reload new init area"""
        bbox = cfg.diagram.get_diagram_all_rect(cfg.diagram.rect, cfg.layers, cfg.diagrams.index(cfg.diagram))
        poly = QtGui.QPolygonF(bbox)
        self.setPolygon(poly)
        cfg.diagram.area.gtpolygon = poly 
Example 39
Project: eddy   Author: danielepantaleone   File: geometry.py    GNU General Public License v3.0 5 votes vote down vote up
def createArea(p1, p2, degrees, size):
    """
    Creates an area between the given QPointF and according to the given angle and size.
    :type p1: QPointF
    :type p2: QPointF
    :type degrees: float
    :type size: int
    :rtype: QPolygonF
    """
    rad = math.radians(degrees)
    x = size / 2 * math.sin(rad)
    y = size / 2 * math.cos(rad)
    a = QtCore.QPointF(+x, +y)
    b = QtCore.QPointF(-x, -y)
    return QtGui.QPolygonF([p1 + a, p1 + b, p2 + b, p2 + a]) 
Example 40
Project: eddy   Author: danielepantaleone   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, **kwargs):
        """
        Initialize the edge.
        """
        super().__init__(**kwargs)
        self.tail = Polygon(QtGui.QPolygonF())

    #############################################
    #   INTERFACE
    ################################# 
Example 41
Project: eddy   Author: danielepantaleone   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 - QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 42
Project: eddy   Author: danielepantaleone   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def createTail(p1, angle, size):
        """
        Create the tail polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 + QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 + QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 43
Project: eddy   Author: danielepantaleone   File: input.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 4.0) * size, cos(rad + M_PI / 4.0) * size)
        p3 = p2 - QtCore.QPointF(sin(rad + 3.0 / 4.0 * M_PI) * size, cos(rad + 3.0 / 4.0 * M_PI) * size)
        p4 = p3 - QtCore.QPointF(sin(rad - 3.0 / 4.0 * M_PI) * size, cos(rad - 3.0 / 4.0 * M_PI) * size)
        return QtGui.QPolygonF([p1, p2, p3, p4]) 
Example 44
Project: eddy   Author: danielepantaleone   File: base.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, source, target=None, breakpoints=None, **kwargs):
        """
        Initialize the edge.
        :type source: AbstractNode
        :type target: AbstractNode
        :type breakpoints: list
        """
        super().__init__(**kwargs)

        self.source = source
        self.target = target

        self.anchors = {} # {AbstractNode: Polygon}
        self.breakpoints = breakpoints or [] # [QtCore.QPointF]
        self.handles = [] # [Polygon]
        self.head = Polygon(QtGui.QPolygonF())
        self.path = Polygon(QtGui.QPainterPath())
        self.selection = Polygon(QtGui.QPainterPath())

        self.mp_AnchorNode = None
        self.mp_AnchorNodePos = None
        self.mp_BreakPoint = None
        self.mp_BreakPointPos = None
        self.mp_Pos = None

        self.setAcceptHoverEvents(True)
        self.setCacheMode(AbstractItem.DeviceCoordinateCache)
        self.setFlag(AbstractItem.ItemIsSelectable, True)

    #############################################
    #   INTERFACE
    ################################# 
Example 45
Project: eddy   Author: danielepantaleone   File: membership.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 - QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 46
Project: eddy   Author: danielepantaleone   File: individual.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=60, height=60, brush=None, **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)

        w = max(width, 60)
        h = max(height, 60)
        brush = brush or IndividualNode.DefaultBrush
        pen = IndividualNode.DefaultPen

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(-(x / 2), +((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(-((x / (1 + math.sqrt(2))) / 2), +(y / 2)),
            QtCore.QPointF(+((x / (1 + math.sqrt(2))) / 2), +(y / 2)),
            QtCore.QPointF(+(x / 2), +((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(+(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(+((x / (1 + math.sqrt(2))) / 2), -(y / 2)),
            QtCore.QPointF(-((x / (1 + math.sqrt(2))) / 2), -(y / 2)),
            QtCore.QPointF(-(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
        ])

        self.background = Polygon(createPolygon(w + 8, h + 8))
        self.selection = Polygon(createPolygon(w + 8, h + 8))
        self.polygon = Polygon(createPolygon(w, h), brush, pen)
        self.label = NodeLabel(template='individual', pos=self.center, parent=self)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.updateNode()
        self.updateTextPos()

    #############################################
    #   PROPERTIES
    ################################# 
Example 47
Project: eddy   Author: danielepantaleone   File: role.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=70, height=50, brush=None, **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        
        w = max(width, 70)
        h = max(height, 50)
        brush = brush or RoleNode.DefaultBrush
        pen = RoleNode.DefaultPen

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-x / 2, 0),
            QtCore.QPointF(0, +y / 2),
            QtCore.QPointF(+x / 2, 0),
            QtCore.QPointF(0, -y / 2),
            QtCore.QPointF(-x / 2, 0)
        ])

        self.fpolygon = Polygon(QtGui.QPainterPath())
        self.ipolygon = Polygon(QtGui.QPainterPath())
        self.background = Polygon(createPolygon(w + 8, h + 8))
        self.selection = Polygon(createPolygon(w + 8, h + 8))
        self.polygon = Polygon(createPolygon(w, h), brush, pen)
        self.label = NodeLabel(template='role', pos=self.center, parent=self)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.updateNode()
        self.updateTextPos()

    #############################################
    #   INTERFACE
    ################################# 
Example 48
Project: eddy   Author: danielepantaleone   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def createPolygon(w, h):
        """
        Returns the initialized polygon according to the given width/height.
        :type w: int
        :type h: int
        :rtype: QtGui.QPolygonF
        """
        return QtGui.QPolygonF([
            QtCore.QPointF(-w / 2 + 10, -h / 2),
            QtCore.QPointF(+w / 2, -h / 2),
            QtCore.QPointF(+w / 2 - 10, +h / 2),
            QtCore.QPointF(-w / 2, +h / 2),
            QtCore.QPointF(-w / 2 + 10, -h / 2),
        ]) 
Example 49
Project: eddy   Author: danielepantaleone   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def createPolygonB(w, h):
        """
        Returns the initialized bottom-half polygon according to the given width/height.
        :type w: int
        :type h: int
        :rtype: QtGui.QPolygonF
        """
        return QtGui.QPolygonF([
            QtCore.QPointF(-w / 2 + 10 / 2, 0),
            QtCore.QPointF(+w / 2 - 10 / 2, 0),
            QtCore.QPointF(+w / 2 - 10, +h / 2),
            QtCore.QPointF(-w / 2, +h / 2),
            QtCore.QPointF(-w / 2 + 10 / 2, 0),
        ]) 
Example 50
Project: eddy   Author: danielepantaleone   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def geometryA(self):
        """
        Returns the geometry of the shape A of this node.
        :rtype: QtGui.QPolygonF
        """
        return self.polygonA.geometry() 
Example 51
Project: eddy   Author: danielepantaleone   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def geometryB(self):
        """
        Returns the geometry of the shape B of this node.
        :rtype: QtGui.QPolygonF
        """
        return self.polygonB.geometry() 
Example 52
Project: eddy   Author: danielepantaleone   File: operator.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=50, height=30, brush=None, **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-x / 2, 0),
            QtCore.QPointF(-x / 2 + 6, +y / 2),
            QtCore.QPointF(+x / 2 - 6, +y / 2),
            QtCore.QPointF(+x / 2, 0),
            QtCore.QPointF(+x / 2 - 6, -y / 2),
            QtCore.QPointF(-x / 2 + 6, -y / 2),
            QtCore.QPointF(-x / 2, 0),
        ])

        self.background = Polygon(createPolygon(58, 38))
        self.selection = Polygon(createPolygon(58, 38))
        self.polygon = Polygon(createPolygon(50, 30), brush or OperatorNode.DefaultBrush, OperatorNode.DefaultPen)

    #############################################
    #   INTERFACE
    ################################# 
Example 53
Project: eddy   Author: danielepantaleone   File: base.py    GNU General Public License v3.0 5 votes vote down vote up
def geometry(self):
        """
        Returns the geometry of the shape of this node.
        :rtype: QtGui.QPolygonF
        """
        return self.polygon.geometry() 
Example 54
Project: eddy   Author: danielepantaleone   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def geometry(self):
        """
        Returns the polygon geometry.
        :rtype: T <= QRectF | QPolygonF | QPainterPath
        """
        return self._geometry 
Example 55
Project: eddy   Author: danielepantaleone   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def setGeometry(self, geometry):
        """
        Set the shape polygon.
        :type geometry: T <= QRectF | QPolygonF | QPainterPath
        """
        self._geometry = geometry 
Example 56
Project: algorithmic-trading   Author: zhangarejiu   File: test_qt.py    MIT License 5 votes vote down vote up
def series_to_polyline(xdata, ydata):
    """Convert series data to QPolygon(F) polyline
    
    This code is derived from PythonQwt's function named 
    `qwt.plot_curve.series_to_polyline`"""
    size = len(xdata)
    polyline = QPolygonF(size)
    pointer = polyline.data()
    dtype, tinfo = np.float, np.finfo  # integers: = np.int, np.iinfo
    pointer.setsize(2*polyline.size()*tinfo(dtype).dtype.itemsize)
    memory = np.frombuffer(pointer, dtype)
    memory[:(size-1)*2+1:2] = xdata
    memory[1:(size-1)*2+2:2] = ydata
    return polyline 
Example 57
Project: AnnotationTool   Author: ElbitSystems   File: AnnotationToolGS.py    MIT License 5 votes vote down vote up
def add_contour(self, points, obj_id, class_name, final, color=None):
        """ draw contour for given object on scene """
        if not points:
            return

        # set appropriate color
        if not color:
            color = self.get_color(self.colormap[:, obj_id])

        # extract (x, y) couples from list of points
        points = list(zip(points[::2], points[1::2]))

        # create list of Qt.QPointF from (x, y) lists
        points = [QtCore.QPointF(*p) for p in points]

        # draw current polygon
        contour = AnnotationObject(QtGui.QPolygonF(points), self.pen, color, final)

        # insert the AnnotationObject to the scene
        self.addItem(contour)

        # set tool tip
        tooltip_text = 'Object ID: {0}, class: {1}'.format(obj_id, class_name)
        if not final:
            tooltip_text += ', prediction'
        contour.setToolTip(tooltip_text)

        # save object id and class of this contour
        self.contour2obj[contour] = (obj_id, class_name)
        self.obj2contour[obj_id] = contour

        return contour 
Example 58
Project: CvStudio   Author: haruiz   File: polygon_item.py    MIT License 5 votes vote down vote up
def addPoint(self,p):
        self.points.append(p)
        item=EditablePolygonPoint(len(self.points)-1)
        item.brush_color=self._brush_color
        item.pen_color=self._pen_color
        item.signals.moved.connect(self.point_moved_slot)
        item.signals.deleted.connect(self.point_deleted_slot)
        item.signals.doubleClicked.connect(self.point_double_clicked)
        self.scene().addItem(item)
        item.setPos(p)
        self.controls.append(item)
        self.setPolygon(QtGui.QPolygonF(self.points)) 
Example 59
Project: CvStudio   Author: haruiz   File: polygon_item.py    MIT License 5 votes vote down vote up
def insertPoint(self,index,p):
        self.points.insert(index, p)
        item=EditablePolygonPoint(index)
        item.brush_color=self._brush_color
        item.pen_color=self._pen_color
        item.signals.moved.connect(self.point_moved_slot)
        item.signals.deleted.connect(self.point_deleted_slot)
        item.signals.doubleClicked.connect(self.point_double_clicked)
        self.scene().addItem(item)
        item.setPos(p)
        self.controls.insert(index, item)
        self.setPolygon(QtGui.QPolygonF(self.points)) 
Example 60
Project: CvStudio   Author: haruiz   File: polygon_item.py    MIT License 5 votes vote down vote up
def point_moved_slot(self,item: EditablePolygonPoint,pos: QPointF):
        self.points[item.index]=self.mapFromScene(pos)
        self.setPolygon(QtGui.QPolygonF(self.points)) 
Example 61
Project: CvStudio   Author: haruiz   File: polygon_item.py    MIT License 5 votes vote down vote up
def point_deleted_slot(self,index: int):
        del self.points[index]
        del self.controls[index]
        self.setPolygon(QtGui.QPolygonF(self.points))
        self.update_indexes() 
Example 62
Project: CvStudio   Author: haruiz   File: polygon.py    MIT License 5 votes vote down vote up
def addPoint(self, p):
        self.m_points.append(p)
        self.setPolygon(QtGui.QPolygonF(self.m_points))
        item = GripItem(self, len(self.m_points) - 1)
        self.scene().addItem(item)
        self.m_items.append(item)
        item.setPos(p) 
Example 63
Project: CvStudio   Author: haruiz   File: polygon.py    MIT License 5 votes vote down vote up
def movePoint(self, i, p):
        if 0 <= i < len(self.m_points):
            self.m_points[i] = self.mapFromScene(p)
            self.setPolygon(QtGui.QPolygonF(self.m_points)) 
Example 64
Project: Detectron-PYTORCH   Author: CharlesShang   File: cityscapesViewer.py    Apache License 2.0 5 votes vote down vote up
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x, pt.y)
            poly.append(point)
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore 
Example 65
Project: pyVds1022   Author: albert-spruyt   File: gui.py    GNU General Public License v3.0 5 votes vote down vote up
def series_to_polyline(xdata, ydata,timebase):
    """Convert series data to QPolygon(F) polyline
    
    This code is derived from PythonQwt's function named 
    `qwt.plot_curve.series_to_polyline`"""
    size = len(xdata)
    polyline = QPolygonF(size)
    pointer = polyline.data()
    dtype, tinfo = np.float, np.finfo  # integers: = np.int, np.iinfo
    pointer.setsize(2*polyline.size()*tinfo(dtype).dtype.itemsize)
    memory = np.frombuffer(pointer, dtype)
    memory[:(size-1)*2+1:2] = np.array(xdata) / timebase
    memory[1:(size-1)*2+2:2] = ydata 
    return polyline 
Example 66
Project: Quantdom   Author: constverum   File: charts.py    Apache License 2.0 5 votes vote down vote up
def paint(self, p, *args):
        p.setRenderHint(p.Antialiasing)
        if isinstance(self.item, tuple):
            positive = self.item[0].opts
            negative = self.item[1].opts
            p.setPen(pg.mkPen(positive['pen']))
            p.setBrush(pg.mkBrush(positive['brush']))
            p.drawPolygon(
                QtGui.QPolygonF(
                    [
                        QtCore.QPointF(0, 0),
                        QtCore.QPointF(18, 0),
                        QtCore.QPointF(18, 18),
                    ]
                )
            )
            p.setPen(pg.mkPen(negative['pen']))
            p.setBrush(pg.mkBrush(negative['brush']))
            p.drawPolygon(
                QtGui.QPolygonF(
                    [
                        QtCore.QPointF(0, 0),
                        QtCore.QPointF(0, 18),
                        QtCore.QPointF(18, 18),
                    ]
                )
            )
        else:
            opts = self.item.opts
            p.setPen(pg.mkPen(opts['pen']))
            p.drawRect(0, 10, 18, 0.5) 
Example 67
Project: tierpsy-tracker   Author: ver228   File: TrackerViewerAux.py    MIT License 5 votes vote down vote up
def _drawSkel(self, worm_qimg, skel_dat, skel_colors = GOOD_SKEL_COLOURS):

        qPlg = {}
        for tt, dat in skel_dat.items():
            qPlg[tt] = QPolygonF()
            for p in dat:
                #do not add point if it is nan
                if p[0] == p[0]: 
                    qPlg[tt].append(QPointF(*p))


        if not qPlg or len(qPlg['skeleton']) == 0:
            return

        pen = QPen()
        pen.setWidth(1)

        painter = QPainter()
        painter.begin(worm_qimg)

        for k, pol_v in qPlg.items():
            color = skel_colors[k]
            pen.setColor(QColor(*color))
            painter.setPen(pen)
            painter.drawPolyline(pol_v)

        pen.setColor(Qt.black)
        painter.setBrush(Qt.white)
        painter.setPen(pen)

        radius = 3
        painter.drawEllipse(qPlg['skeleton'][0], radius, radius)
        painter.drawEllipse(QPointF(0,0), radius, radius)

        painter.end() 
Example 68
Project: tierpsy-tracker   Author: ver228   File: MWTrackerViewer.py    MIT License 5 votes vote down vote up
def draw_trajectories(self, painter, row_data, is_current_index):
        if self.traj_worm_index_grouped is None:
            return
        worm_index = int(row_data[self.worm_index_type])
        current_frame = row_data['frame_number']
        traj_data = self._h_get_trajectory(worm_index, current_frame)
        traj_data = traj_data.dropna(subset=['coord_x', 'coord_y'])

        x_v = traj_data['coord_x'].round()
        y_v = traj_data['coord_y'].round()
        points = [QPointF(*map(int, c)) for c in zip(x_v, y_v)]

        if self.ui.is_color_features.isChecked():

            vec_color = [self._h_assign_feat_color(x) for x in traj_data.index]
            
            pen = QPen()
            pen.setWidth(self.penwidth)
            for p1, p2, c in zip(points[1:], points[:-1], vec_color):
                pen.setColor(c)
                painter.setPen(pen)
                painter.drawLine(p1, p2)
        else:
            pol = QPolygonF()
            for p in points:
                pol.append(p)

            if not worm_index in self.traj_colors:
                self.traj_colors[worm_index] = QColor(*np.random.randint(50, 230, 3))
            col = self.traj_colors[worm_index]
            
            pen = QPen()
            pen.setWidth(self.penwidth)
            pen.setColor(col)
            painter.setPen(pen)
            painter.drawPolyline(pol) 
Example 69
Project: AnalogGaugeWidgetPyQt   Author: StefanHol   File: analoggaugewidget.py    Apache License 2.0 5 votes vote down vote up
def create_polygon_pie(self, outer_radius, inner_raduis, start, lenght):
        polygon_pie = QPolygonF()
        # start = self.scale_angle_start_value
        # start = 0
        # lenght = self.scale_angle_size
        # lenght = 180
        # inner_raduis = self.width()/4
        # print(start)
        n = 360     # angle steps size for full circle
        # changing n value will causes drawing issues
        w = 360 / n   # angle per step
        # create outer circle line from "start"-angle to "start + lenght"-angle
        x = 0
        y = 0

        # todo enable/disable bar graf here
        if not self.enable_barGraph:
            # float_value = ((lenght / (self.value_max - self.value_min)) * (self.value - self.value_min))
            lenght = int(round((lenght / (self.value_max - self.value_min)) * (self.value - self.value_min)))
            # print("f: %s, l: %s" %(float_value, lenght))
            pass

        # mymax = 0

        for i in range(lenght+1):                                              # add the points of polygon
            t = w * i + start - self.angle_offset
            x = outer_radius * math.cos(math.radians(t))
            y = outer_radius * math.sin(math.radians(t))
            polygon_pie.append(QPointF(x, y))
        # create inner circle line from "start + lenght"-angle to "start"-angle
        for i in range(lenght+1):                                              # add the points of polygon
            # print("2 " + str(i))
            t = w * (lenght - i) + start - self.angle_offset
            x = inner_raduis * math.cos(math.radians(t))
            y = inner_raduis * math.sin(math.radians(t))
            polygon_pie.append(QPointF(x, y))

        # close outer line
        polygon_pie.append(QPointF(x, y))
        return polygon_pie 
Example 70
Project: PyQt   Author: PyQt5   File: WorldMap.py    GNU General Public License v3.0 5 votes vote down vote up
def initMap(self):
        features = json.load(
            open("Data/world.json", encoding="utf8")).get("features")
        for feature in features:
            geometry = feature.get("geometry")
            if not geometry:
                continue
            _type = geometry.get("type")
            coordinates = geometry.get("coordinates")
            for coordinate in coordinates:
                if _type == "Polygon":
                    polygon = QPolygonF(
                        [QPointF(latitude, -longitude) for latitude, longitude in coordinate])
                    item = QGraphicsPolygonItem(polygon)
                    item.setPen(QPen(self.borderColor, 0))
                    item.setBrush(QBrush(self.backgroundColor))
                    item.setPos(0, 0)
                    self._scene.addItem(item)
                elif _type == "MultiPolygon":
                    for _coordinate in coordinate:
                        polygon = QPolygonF(
                            [QPointF(latitude, -longitude) for latitude, longitude in _coordinate])
                        item = QGraphicsPolygonItem(polygon)
                        item.setPen(QPen(self.borderColor, 0))
                        item.setBrush(QBrush(self.backgroundColor))
                        item.setPos(0, 0)
                        self._scene.addItem(item) 
Example 71
Project: EGame   Author: digital-bauhaus   File: corpse.py    MIT License 5 votes vote down vote up
def draw_polygon(self, painter):
        color = QColor(self.color)
        painter.setBrush(color)

        r = self.size/2

        polygon = QPolygonF()
        polygon.append(QPointF(self._position[0] + r, self._position[1] + r/2))
        polygon.append(QPointF(self._position[0], self._position[1] + r))
        polygon.append(QPointF(self._position[0] - r, self._position[1] + r/2))
        polygon.append(QPointF(self._position[0] - r, self._position[1] - r/2))
        polygon.append(QPointF(self._position[0], self._position[1] - r))
        polygon.append(QPointF(self._position[0] + r, self._position[1] - r/2))

        painter.drawPolygon(polygon) 
Example 72
Project: tierpsy-tracker   Author: ver228   File: TrackerViewerAux.py    MIT License 4 votes vote down vote up
def drawThreshMask(self, worm_img, worm_qimg, row_data, read_center=True):
        #in very old versions of the tracker I didn't save the area in trajectories table, 
        #let's assign a default value to deal with this cases
        if 'area' in row_data:
            min_blob_area = row_data['area'] / 2
        else:
            min_blob_area = 10
        
        c1, c2 = (row_data['coord_x'], row_data[
                  'coord_y']) if read_center else (-1, -1)

        worm_mask, worm_cnt, _ = getWormMask(worm_img, row_data['threshold'], strel_size=self.strel_size,
                                      roi_center_x=c1, roi_center_y=c2, min_blob_area=min_blob_area,
                                      is_light_background = self.is_light_background)

        
        worm_mask = QImage(
            worm_mask.data,
            worm_mask.shape[1],
            worm_mask.shape[0],
            worm_mask.strides[0],
            QImage.Format_Indexed8)
        worm_mask = worm_mask.convertToFormat(
            QImage.Format_RGB32, Qt.AutoColor)
        worm_mask = QPixmap.fromImage(worm_mask)

        worm_mask = worm_mask.createMaskFromColor(Qt.black)
        p = QPainter(worm_qimg)
        p.setPen(QColor(0, 204, 102))
        p.drawPixmap(worm_qimg.rect(), worm_mask, worm_mask.rect())
        
        if False:
            #test skeletonization
            skeleton, ske_len, cnt_side1, cnt_side2, cnt_widths, cnt_area = \
                getSkeleton(worm_cnt, np.zeros(0), 49)
            for cnt in skeleton, cnt_side1, cnt_side2:
                p.setPen(Qt.black)
                polyline = QPolygonF()
                for point in cnt:
                    polyline.append(QPointF(*point))
                p.drawPolyline(polyline)

        p.end()