def compute_circle_arc_polygon(self,
                                   x0,
                                   y0,
                                   radius,
                                   phi_begin,
                                   arc_length,
                                   steps=32):
        polygon = QPolygonF()

        x0_t, y0_t = self.convert_position(x0, y0)
        polygon.append(QPointF(x0_t, y0_t))

        begin = phi_begin
        end = arc_length + phi_begin
        step = (begin - end) / steps

        angle = float(begin)

        for i in range(steps):
            x = x0 + radius * numpy.cos(angle)
            y = y0 + radius * numpy.sin(angle)

            x_t, y_t = self.convert_position(x, y)

            polygon.append(QPointF(x_t, y_t))

            angle += step

        return polygon
예제 #2
0
    def _generate_indicators(self, **kwargs):  # pylint: disable=unused-argument
        """
        Paint arrow indicators of selected instructions and labels.
        """
        scene = self.scene()
        for item in self._map_indicator_items:
            scene.removeItem(item)
        self._map_indicator_items.clear()

        for addr in list(self.disasm_view.infodock.selected_insns) + list(
                self.disasm_view.infodock.selected_labels):
            pos = self._get_pos_from_addr(addr)
            if pos is None:
                continue

            pos -= 1  # this is the top-left x coordinate of our arrow body (the rectangle)

            pen = QPen(Qt.yellow)
            brush = QBrush(Qt.yellow)
            item = QGraphicsRectItem(QRectF(pos, 0, 2, 10), parent=self)
            item.setPen(pen)
            item.setBrush(brush)
            item.setZValue(self.ZVALUE_INDICATOR)
            self._map_indicator_items.append(item)

            triangle = QPolygonF()
            triangle.append(QPointF(pos - 1, 10))
            triangle.append(QPointF(pos + 3, 10))
            triangle.append(QPointF(pos + 1, 12))
            triangle.append(QPointF(pos - 1, 10))
            item = QGraphicsPolygonItem(triangle, parent=self)
            item.setPen(pen)
            item.setBrush(brush)
            item.setZValue(self.ZVALUE_INDICATOR)
            self._map_indicator_items.append(item)
예제 #3
0
    def _paint_insn_indicators(self):

        scene = self.view.scene()  # type: QGraphicsScene
        for item in self._insn_indicators:
            scene.removeItem(item)
        self._insn_indicators.clear()

        for selected_insn_addr in self.disasm_view.infodock.selected_insns:
            pos = self._get_pos_from_addr(selected_insn_addr)
            if pos is None:
                continue

            pos -= 1  # this is the top-left x coordinate of our arrow body (the rectangle)

            pen = QPen(Qt.yellow)
            brush = QBrush(Qt.yellow)
            rect = QRectF(pos, 0, 2, 5)
            # rectangle
            item = scene.addRect(rect, pen, brush)
            self._insn_indicators.append(item)
            # triangle
            triangle = QPolygonF()
            triangle.append(QPointF(pos - 1, 5))
            triangle.append(QPointF(pos + 3, 5))
            triangle.append(QPointF(pos + 1, 7))
            triangle.append(QPointF(pos - 1, 5))
            item = scene.addPolygon(triangle, pen, brush)
            self._insn_indicators.append(item)
예제 #4
0
 def createPoly(self, n, r, s):
     polygon = QPolygonF()
     w = 360/n                                                       # angle per step
     for i in range(n):                                              # add the points of polygon
         t = w*i + s
         x = r*math.cos(math.radians(t))
         y = r*math.sin(math.radians(t))
         polygon.append(QtCore.QPointF(self.w/2 +x, self.h/2 + y))
예제 #5
0
 def getFrozenQuad(self):
     """
     Returns the starting quad for the current type of transformation
     @return:
     @rtype: QPolygonF
     """
     poly = QPolygonF()
     for role in ['topLeft', 'topRight', 'bottomRight', 'bottomLeft']:
         poly.append(self.btnDict[role].posRelImg_frozen)
     return poly
예제 #6
0
 def getSourceQuad(self):
     """
     Returns the starting quad for the transformation in progress
     @return:
     @rtype: QPolygonF
     """
     poly = QPolygonF()
     for role in ['topLeft', 'topRight', 'bottomRight', 'bottomLeft']:
         poly.append(self.btnDict[role].posRelImg_ori)
     return poly
예제 #7
0
 def getTargetQuad(self):
     """
     Returns the current quad, as defined by the 4 buttons.
     Coordinates are relative to the full size image
     @return:
     @rtype: QPolygonF
     """
     poly = QPolygonF()
     for role in ['topLeft', 'topRight', 'bottomRight', 'bottomLeft']:
         poly.append(self.btnDict[role].posRelImg)
     return poly
예제 #8
0
 def getNewWindow(cls, targetImage=None, axeSize=500, layer=None, parent=None, curveType='quadric'):
     newWindow = graphicsToneForm(targetImage=targetImage, axeSize=axeSize, layer=layer, parent=parent, curveType=curveType)
     newWindow.setWindowTitle(layer.name)
     # init marker
     triangle = QPolygonF()
     s = 10
     triangle.append(QPointF(-s, s))
     triangle.append(QPointF(0, 0))
     triangle.append(QPointF(s, s))
     newWindow.inputMarker = QGraphicsPolygonItem(triangle)
     newWindow.scene().addItem(newWindow.inputMarker)
     newWindow.inputMarker.setBrush(QBrush(Qt.white))
     return newWindow
예제 #9
0
    def testsquareToQuad(self):
        q1 = QPolygonF()
        q1.append(QPointF(10.0, 10.0))
        q1.append(QPointF(20.0, 10.0))
        q1.append(QPointF(10.0, -10.0))
        q1.append(QPointF(20.0, -10.0))

        t1 = QTransform()
        r1 = QTransform.squareToQuad(q1, t1)
        r2 = QTransform.squareToQuad(q1)

        self.assertTrue(r1)
        self.assertTrue(r2)

        self.assertEqual(t1, r2)
예제 #10
0
class StarRating(object):
    """ Handle the actual painting of the stars themselves. """
    def __init__(self, starCount=1, maxStarCount=5):
        self.starCount = starCount
        self.maxStarCount = maxStarCount

        # Create the star shape we'll be drawing.
        self.starPolygon = QPolygonF()
        self.starPolygon.append(QPointF(1.0, 0.5))
        for i in range(1, 5):
            self.starPolygon.append(
                QPointF(0.5 + 0.5 * cos(0.8 * i * pi),
                        0.5 + 0.5 * sin(0.8 * i * pi)))

        # Create the diamond shape we'll show in the editor
        self.diamondPolygon = QPolygonF()
        diamondPoints = [
            QPointF(0.4, 0.5),
            QPointF(0.5, 0.4),
            QPointF(0.6, 0.5),
            QPointF(0.5, 0.6),
            QPointF(0.4, 0.5)
        ]
        for point in diamondPoints:
            self.diamondPolygon.append(point)

    def sizeHint(self):
        """ Tell the caller how big we are. """
        return PAINTING_SCALE_FACTOR * QSize(self.maxStarCount, 1)

    def paint(self, painter, rect, palette, isEditable=False):
        """ Paint the stars (and/or diamonds if we're in editing mode). """
        painter.save()

        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setPen(Qt.NoPen)

        if isEditable:
            painter.setBrush(palette.highlight())
        else:
            painter.setBrush(palette.windowText())

        yOffset = (rect.height() - PAINTING_SCALE_FACTOR) / 2
        painter.translate(rect.x(), rect.y() + yOffset)
        painter.scale(PAINTING_SCALE_FACTOR, PAINTING_SCALE_FACTOR)

        for i in range(self.maxStarCount):
            if i < self.starCount:
                painter.drawPolygon(self.starPolygon, Qt.WindingFill)
            elif isEditable:
                painter.drawPolygon(self.diamondPolygon, Qt.WindingFill)
            painter.translate(1.0, 0.0)

        painter.restore()
예제 #11
0
    def testquadToQuad(self):
        q1 = QPolygonF()
        q1.append(QPointF(10.0, 10.0))
        q1.append(QPointF(20.0, 10.0))
        q1.append(QPointF(10.0, -10.0))
        q1.append(QPointF(20.0, -10.0))

        q2 = QPolygonF()
        q2.append(QPointF(20.0, 20.0))
        q2.append(QPointF(30.0, 20.0))
        q2.append(QPointF(20.0, -20.0))
        q2.append(QPointF(30.0, -20.0))

        t1 = QTransform()
        r1 = QTransform.quadToQuad(q1, q2, t1)
        r2 = QTransform.quadToQuad(q1, q2)

        self.assertTrue(r1)
        self.assertTrue(r2)

        self.assertEqual(t1, r2)
예제 #12
0
class StarRating(object):
    """ Handle the actual painting of the stars themselves. """

    def __init__(self, starCount=1, maxStarCount=5):
        self.starCount = starCount
        self.maxStarCount = maxStarCount

        # Create the star shape we'll be drawing.
        self.starPolygon = QPolygonF()
        self.starPolygon.append(QPointF(1.0, 0.5))
        for i in range(1, 5):
            self.starPolygon.append(QPointF(0.5 + 0.5 * cos(0.8 * i * pi),
                                    0.5 + 0.5 * sin(0.8 * i * pi)))

        # Create the diamond shape we'll show in the editor
        self.diamondPolygon = QPolygonF()
        diamondPoints = [QPointF(0.4, 0.5), QPointF(0.5, 0.4),
                         QPointF(0.6, 0.5), QPointF(0.5, 0.6),
                         QPointF(0.4, 0.5)]
        for point in diamondPoints:
            self.diamondPolygon.append(point)

    def sizeHint(self):
        """ Tell the caller how big we are. """
        return PAINTING_SCALE_FACTOR * QSize(self.maxStarCount, 1)

    def paint(self, painter, rect, palette, isEditable=False):
        """ Paint the stars (and/or diamonds if we're in editing mode). """
        painter.save()

        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setPen(Qt.NoPen)

        if isEditable:
            painter.setBrush(palette.highlight())
        else:
            painter.setBrush(palette.windowText())

        yOffset = (rect.height() - PAINTING_SCALE_FACTOR) / 2
        painter.translate(rect.x(), rect.y() + yOffset)
        painter.scale(PAINTING_SCALE_FACTOR, PAINTING_SCALE_FACTOR)

        for i in range(self.maxStarCount):
            if i < self.starCount:
                painter.drawPolygon(self.starPolygon, Qt.WindingFill)
            elif isEditable:
                painter.drawPolygon(self.diamondPolygon, Qt.WindingFill)
            painter.translate(1.0, 0.0)

        painter.restore()
예제 #13
0
 def drawChannelHistogram(painter, hist, bin_edges, color):
     # Draw histogram for a single channel.
     # param painter: QPainter
     # param hist: histogram to draw
     # smooth the histogram (first and last bins excepted) for a better visualization of clipping.
     # hist = np.concatenate(([hist[0]], SavitzkyGolayFilter.filter(hist[1:-1]), [hist[-1]]))
     # To emphasize significant values we clip the first bin to max height of the others
     M = max(hist[1: ])  # max(hist)  # max(hist[1:-1])
     imgH = size.height()
     # drawing  trapezia instead of rectangles to quickly "smooth" the histogram
     # the rightmost trapezium is not drawn
     poly = QPolygonF()
     poly.append(QPointF(range[0], imgH))  # bottom left point
     for i, y in enumerate(hist):
         try:
             h = imgH * y / M
             if np.isnan(h):
                 raise ValueError
         except (ValueError, ArithmeticError, FloatingPointError, ZeroDivisionError):
             # don't draw the histogram for this channel if M is too small
             return
         poly.append(QPointF((bin_edges[i] - range[0]) * scale, max(imgH - h, 0)))
         # clipping indicators
         if i == 0 or i == len(hist)-1:
             left = bin_edges[0 if i == 0 else -1] * scale
             left = left - (20 if i > 0 else 0)  # shift the indicator at right
             percent = hist[i] * (bin_edges[i+1]-bin_edges[i])
             if percent > clipping_threshold:
                 # set the color of the indicator according to percent value
                 nonlocal gPercent
                 gPercent = min(gPercent, np.clip((0.05 - percent) / 0.03, 0, 1))
                 painter.fillRect(left, 0, 10, 10, QColor(255, 255*gPercent, 0))
     # draw the filled polygon
     poly.append(QPointF(poly.constLast().x(), imgH))  # bottom right point
     path = QPainterPath()
     path.addPolygon(poly)
     path.closeSubpath()
     painter.setPen(Qt.NoPen)
     painter.fillPath(path, QBrush(color))
예제 #14
0
파일: viewer.py 프로젝트: aldanstar/SCIPH
 def add_Polygon(self, arr, xoffset=0, yoffset=0):
     polygon = QPolygonF()
     for p in arr:
         x,y=p[0]
         polygon.append(QPointF(x+xoffset,y+yoffset))
     self.imgArea.scene.addPolygon(polygon, pen=QPen(Qt.blue, 3))
예제 #15
0
    def _create_line_indicator(self, addr, item_map, color=Qt.yellow, show_frontier=False, z=None, z_frontier=None):
        """
        Generate a cursor at a given address.
        """
        pos_x = self._get_pos_from_addr(addr)
        if pos_x is None:
            return

        pen = QPen(color)
        brush = QBrush(color)
        height = self.height

        tri_width = 7
        tri_height = 4

        pos_x = int(pos_x - tri_width / 2)  # Center drawing
        center = pos_x + int(tri_width / 2)
        pos_y = 0
        frontier_width = int(0.15 * max(self.width, self.height))

        if show_frontier:
            # Draw frontier gradients
            r = QRectF(center - frontier_width, pos_y, frontier_width, height)
            bg = QLinearGradient(r.topLeft(), r.topRight())
            color = Qt.red
            top_color = QColor(color)
            top_color.setAlpha(0)
            bg.setColorAt(0, top_color)
            bottom_color = QColor(color)
            bottom_color.setAlpha(180)
            bg.setColorAt(1, bottom_color)

            i = QGraphicsRectItem(r, parent=self)
            i.setPen(Qt.NoPen)
            i.setBrush(bg)
            if z_frontier is not None:
                i.setZValue(z_frontier)
            item_map.append(i)

            r = QRectF(center, pos_y, frontier_width, height)
            bg = QLinearGradient(r.topLeft(), r.topRight())
            color = Qt.blue
            top_color = QColor(color)
            bg.setColorAt(0, top_color)
            bottom_color = QColor(color)
            bottom_color.setAlpha(0)
            bg.setColorAt(1, bottom_color)

            i = QGraphicsRectItem(r, parent=self)
            i.setPen(Qt.NoPen)
            i.setBrush(bg)
            if z_frontier is not None:
                i.setZValue(z_frontier)
            item_map.append(i)

        # Draw line
        i = QGraphicsLineItem(center, 0, center, height, parent=self)
        i.setPen(pen)
        if z is not None:
            i.setZValue(z)
        item_map.append(i)

        # Draw top and bottom triangles
        t = QPolygonF()
        t.append(QPointF(pos_x, pos_y))
        t.append(QPointF(pos_x + tri_width - 1, pos_y))
        t.append(QPointF(center, pos_y + tri_height - 1))
        t.append(QPointF(pos_x, pos_y))

        pos_y += height - 1
        b = QPolygonF()
        b.append(QPointF(pos_x, pos_y))
        b.append(QPointF(center, pos_y - tri_height + 1))
        b.append(QPointF(pos_x + tri_width - 1, pos_y))
        b.append(QPointF(pos_x, pos_y))

        for i in [QGraphicsPolygonItem(t, parent=self),
                  QGraphicsPolygonItem(b, parent=self)]:
            i.setPen(pen)
            i.setBrush(brush)
            if z is not None:
                i.setZValue(z)
            item_map.append(i)
예제 #16
0
    def getObjectInteraction(self, persons, objects, interaction, d):

        # print("getObjectInteration")
        plt.close('all')

        polylines_object = []
        polylines_interacting = []

        for o in objects:
            obj = Object(o.x / 1000., o.z / 1000., o.angle, o.space)
            # print("OBJETO")
            ##para dibujarlo
            if d:
                plt.figure('ObjectSpace')
                rect = plt.Rectangle((obj.x - 0.25, obj.y - 0.25),
                                     0.5,
                                     0.5,
                                     fill=False)

                plt.gca().add_patch(rect)
                x_aux = obj.x + 0.25 * cos(pi / 2 - obj.th)
                y_aux = obj.y + 0.25 * sin(pi / 2 - obj.th)
                heading = plt.Line2D((obj.x, x_aux), (obj.y, y_aux),
                                     lw=1,
                                     color='k')
                plt.gca().add_line(heading)

            w = 1.0
            # print (obj.x,obj.y)
            ##para calcular el rectangulo
            s = QRectF(QPointF(0, 0), QSizeF(w, obj.sp))

            # if (d):
            #     plt.plot (s.bottomLeft().x(),s.bottomLeft().y(),"go")
            #     plt.plot(s.bottomRight().x(), s.bottomRight().y(), "ro")
            #     plt.plot(s.topRight().x(), s.topRight().y(), "yo")
            #     plt.plot(s.topLeft().x(), s.topLeft().y(), "bo")

            space = QPolygonF()
            space.append(s.topLeft())
            space.append(s.topRight())
            space.append(
                QPointF(s.bottomRight().x() + obj.sp / 4,
                        s.bottomRight().y()))
            space.append(
                QPointF(s.bottomLeft().x() - obj.sp / 4,
                        s.bottomLeft().y()))

            t = QTransform()
            t.translate(-w / 2, 0)
            space = t.map(space)
            t = QTransform()
            t.rotateRadians(-obj.th)
            space = t.map(space)

            t = QTransform()
            t.translate(obj.x, obj.y)
            space = t.map(space)

            # points = []
            # for x in xrange(space.count()-1):
            #     point = space.value(x)
            #     print ("valor", point)
            #     points.append([point.x(),point.y()])
            #     plt.plot(point.x(),point.y(),"go")

            polyline = []

            for x in range(space.count()):
                point = space.value(x)
                if (d):
                    plt.plot(point.x(), point.y(), "go")

                p = SNGPoint2D()
                p.x = point.x()
                p.z = point.y()
                polyline.append([p.x, p.z])

            polylines_object.append(polyline)

            for p in persons:
                pn = Person(p.x, p.z, p.angle)
                # print("PERSONA", persons.index(p)+1)
                if d:
                    body = plt.Circle((pn.x, pn.y), radius=0.3, fill=False)
                    plt.gca().add_patch(body)

                    x_aux = pn.x + 0.30 * cos(pi / 2 - pn.th)
                    y_aux = pn.y + 0.30 * sin(pi / 2 - pn.th)
                    heading = plt.Line2D((pn.x, x_aux), (pn.y, y_aux),
                                         lw=1,
                                         color='k')
                    plt.gca().add_line(heading)
                    plt.axis('equal')

                ##CHECKING THE ORIENTATION
                print("obj.angle", obj.th, "person.angle", pn.th)
                a = abs(obj.th - abs(pn.th - math.pi))
                if a < math.radians(45):
                    checkangle = True
                else:
                    checkangle = False

                ##CHECKING IF THE PERSON IS INSIDE THE POLYGON
                if space.containsPoint(QPointF(pn.x, pn.y),
                                       Qt.OddEvenFill):  # and checkangle:
                    print("DENTROOOOO Y MIRANDO")
                    if not polyline in polylines_interacting:
                        polylines_interacting.append(polyline)

        if d:
            for ps in polylines_interacting:
                #  plt.figure()
                for p in ps:
                    plt.plot(p.x, p.z, "ro")
                    plt.axis('equal')
                    plt.xlabel('X')
                    plt.ylabel('Y')
            plt.show()
        plt.show()

        if (interaction):
            return polylines_interacting
        else:
            return polylines_object
예제 #17
0
    def drawOneStep(self, step):
        """
        :type step: tuple
        """
        if step[0] == ACTION_RECT:
            self.graphics_scene.addRect(
                QRectF(QPointF(step[1], step[2]), QPointF(step[3], step[4])),
                step[5])
        elif step[0] == ACTION_ELLIPSE:
            self.graphics_scene.addEllipse(
                QRectF(QPointF(step[1], step[2]), QPointF(step[3], step[4])),
                step[5])
        elif step[0] == ACTION_ARROW:
            arrow = QPolygonF()

            linex = float(step[1] - step[3])
            liney = float(step[2] - step[4])
            line = sqrt(pow(linex, 2) + pow(liney, 2))

            # in case to divided by 0
            if line == 0:
                return

            sinAngel = liney / line
            cosAngel = linex / line

            # sideLength is the length of bottom side of the body of an arrow
            # arrowSize is the size of the head of an arrow, left and right
            # sides' size is arrowSize, and the bottom side's size is arrowSize / 2
            sideLength = step[5].width()
            arrowSize = 8
            bottomSize = arrowSize / 2

            tmpPoint = QPointF(step[3] + arrowSize * sideLength * cosAngel,
                               step[4] + arrowSize * sideLength * sinAngel)

            point1 = QPointF(step[1] + sideLength * sinAngel,
                             step[2] - sideLength * cosAngel)
            point2 = QPointF(step[1] - sideLength * sinAngel,
                             step[2] + sideLength * cosAngel)
            point3 = QPointF(tmpPoint.x() - sideLength * sinAngel,
                             tmpPoint.y() + sideLength * cosAngel)
            point4 = QPointF(tmpPoint.x() - bottomSize * sideLength * sinAngel,
                             tmpPoint.y() + bottomSize * sideLength * cosAngel)
            point5 = QPointF(step[3], step[4])
            point6 = QPointF(tmpPoint.x() + bottomSize * sideLength * sinAngel,
                             tmpPoint.y() - bottomSize * sideLength * cosAngel)
            point7 = QPointF(tmpPoint.x() + sideLength * sinAngel,
                             tmpPoint.y() - sideLength * cosAngel)

            arrow.append(point1)
            arrow.append(point2)
            arrow.append(point3)
            arrow.append(point4)
            arrow.append(point5)
            arrow.append(point6)
            arrow.append(point7)
            arrow.append(point1)

            self.graphics_scene.addPolygon(arrow, step[5], step[6])
        elif step[0] == ACTION_LINE:
            self.graphics_scene.addLine(
                QLineF(QPointF(step[1], step[2]), QPointF(step[3], step[4])),
                step[5])
        elif step[0] == ACTION_FREEPEN:
            self.graphics_scene.addPath(step[1], step[2])
        elif step[0] == ACTION_TEXT:
            textAdd = self.graphics_scene.addSimpleText(step[1], step[2])
            textAdd.setPos(step[3])
            textAdd.setBrush(QBrush(step[4]))
            self.textRect = textAdd.boundingRect()