Esempio n. 1
0
    def removePoints(self, listp):
        print("Remove Points")
        print("--------------------------------------------------------")
        print("Entran", len(listp), "polilineas")
        #######################################################################
        poligon_list = []

        for poliline in listp:
            qp = QPolygonF()
            for p in poliline:
                qp.append(QPointF(p.x, p.z))
            poligon_list.append(qp)

        print("Hay ", len(poligon_list), "poligonos")
        resulting_list = recursiP(poligon_list)
        polylines = []

        for element in resulting_list:
            polyline = []
            for pnt in element:
                punto = SNGPoint2D()
                punto.x = pnt.x()
                punto.z = pnt.y()
                polyline.append(punto)
            polylines.append(polyline)

        print("Salen", len(polylines), "polilineas")
        print("--------------------------------------------------------")
        return polylines
Esempio n. 2
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.assert_(r2)

        self.assertEqual(t1, r2)
Esempio n. 3
0
    def setUp(self):
        #Acquire resources
        super(QColorOnSetBrush, self).setUp()

        self.scene = QGraphicsScene()
        poly = QPolygonF()
        self.item = self.scene.addPolygon(poly)
        self.color = QColor('black')
Esempio n. 4
0
    def beforeTest(self):
        points = [QPointF(0, 0), QPointF(100, 100), QPointF(0, 100)]
        pol = self.scene.addPolygon(QPolygonF(points))
        self.assert_(isinstance(pol, QGraphicsPolygonItem))
        self.wrp = weakref.ref(pol, pol_del)

        #refcount need be 3 because one ref for QGraphicsScene, and one to rect obj
        self.assertEqual(sys.getrefcount(pol), 3)
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)
Esempio n. 7
0
 def shape(self):
     bound = QPainterPath()
     rotMatrix = QTransform().rotate(self.angle)
     poly = QPolygonF([
         QPointF(0, 0),
         QPointF(self.w, 0),
         QPointF(self.w, self.h),
         QPointF(0, self.h),
     ])
     poly = rotMatrix.map(poly)
     bound.addPolygon(poly)
     return bound
Esempio n. 8
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.assert_(r2)

        self.assertEqual(t1, r2)
Esempio n. 9
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()
Esempio n. 10
0
    def italic_block(self, start, width, h):
        slope = 0.3

        # The QPoint below are ordered this way :
        #   1__2
        #  /  /
        # 4__3

        pts = []
        pts.append(QPointF(start + h*slope,2))
        pts.append(QPointF(start + h*slope + width,2))
        pts.append(QPointF(start + 1 + width,h-1))
        pts.append(QPointF(start + 1,h-1))
        pts.append(pts[0]) # Closes the path

        qpp = QPainterPath()
        qpp.addPolygon(QPolygonF(pts))
        return qpp
Esempio n. 11
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()
Esempio n. 12
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.assert_(r2)

        self.assertEqual(t1, r2)
Esempio n. 13
0
    def _makeArrow( self, ra, rb, both_ways=True):

        ca = QPointF( ra.x() + float(ra.width()) / 2.0, ra.y() + float(ra.height()) / 2.0)
        cb = QPointF( rb.x() + rb.width() / 2.0, rb.y() + rb.height() / 2.0)

        dx = cb.x() - ca.x()
        dy = cb.y() - ca.y()
        d = dist(dx,dy)


        a = math.atan2(float(dy),float(dx)) # The result is between -pi and pi

        # ra_rad = dist(ra.width() / 2, ra.height() / 2)
        # rb_rad = dist(rb.width() / 2, rb.height() / 2)

        x,y = squircle(ra.width() / 2, ra.height() / 2, to_squircle_angle(ra.width() / 2, ra.height() / 2,a))
        ra_rad = dist(x,y) + 10
        # painter.drawLine(ca,QPoint(ca.x() + x, ca.y() + y))

        na = a
        if a < 0:
            na += math.pi
        else:
            na -= math.pi

        x,y = squircle(float(rb.width()) / 2.0, float(rb.height()) / 2.0, to_squircle_angle(float(rb.width()) / 2.0, float(rb.height()) / 2.0,na))
        rb_rad = dist(x,y)+10

        # ra_rad = rb_rad = 0


        # painter.drawLine(ca,cb)
        # painter.drawRect(ra)
        # painter.setPen(Qt.GlobalColor.red)
        # painter.drawRect(rb)
        # painter.setPen(Qt.GlobalColor.black)

        # for t in range(100):
        #     ang = 6.28/100.0*float(t)
        #     x,y = squircle( 200,50,ang)
        #     painter.drawPoint(300 + x,100 + y)

        qp = QPolygonF()
        h = 5

        v = []
        v.append(QPointF(ra_rad,0))

        if not both_ways:
            v.append(QPointF(ra_rad,-h/2))
        else:
            v.append(QPointF(ra_rad + 2*h,-2*h))
            v.append(QPointF(ra_rad + 2*h,-h/2))


        v.append(QPointF(d - rb_rad - 2*h,-h/2))
        v.append(QPointF(d - rb_rad - 2*h,-2*h))
        v.append(QPointF(d - rb_rad, 0))
        v.append(QPointF(d - rb_rad - 2*h,+2*h))
        v.append(QPointF(d - rb_rad - 2*h,+h/2))

        if not both_ways:
            v.append(QPointF(ra_rad,+h/2))
        else:
            v.append(QPointF(ra_rad + 2*h,+h/2))
            v.append(QPointF(ra_rad + 2*h,+2*h))

        v.append(QPointF(ra_rad,0))

        p = QPolygonF(v)
        item = QGraphicsPolygonItem(p)
        item.translate(ca.x(),ca.y())
        item.rotate(math.degrees(a))
        return item
Esempio n. 14
0
 def testPolygon(self):
     #QGraphicsScene.addPolygon
     points = [QPointF(0, 0), QPointF(100, 100), QPointF(0, 100)]
     item = self.scene.addPolygon(QPolygonF(points))
     self.assertTrue(isinstance(item, QGraphicsPolygonItem))
Esempio n. 15
0
    def paint(self, painter, option, index):
        # NODE_REFERENCE ---------------------------------------------------
        if index.column() == NODE_REFERENCE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            if option.state & QStyle.State_Selected:
                bg_color = palette.highlight().color()
            else:
                bg_color = Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint
            value = float(index.model().data(index))
            if value == 0.0:
                painter.setPen(
                    Qt.black
                    if option.state & QStyle.State_Selected
                    else Qt.darkGray
                )
                painter.setBrush(Qt.NoBrush)
                mid_size = 3.0
            else:
                painter.setPen(Qt.darkCyan)
                painter.setBrush(Qt.cyan)
                mid_size = 4.0

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            losange = QPolygonF()
            losange.append(QPointF(h_center, v_center - mid_size))
            losange.append(QPointF(h_center - mid_size, v_center))
            losange.append(QPointF(h_center, v_center + mid_size))
            losange.append(QPointF(h_center + mid_size, v_center))

            painter.drawPolygon(losange)

            # restore painter
            painter.restore()

        # FILE_STATE -------------------------------------------------------
        elif index.column() == FILE_STATE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint circle
            value = index.model().data(index)

            pen_color = [
                Qt.darkRed,
                Qt.black if option.state & QStyle.State_Selected else Qt.gray,
                Qt.darkGreen][value + 1]
            brush_color = [Qt.red, Qt.NoBrush, Qt.green][value + 1]

            painter.setPen(pen_color)
            painter.setBrush(brush_color)

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            center = QPointF(h_center, v_center)

            painter.drawEllipse(center, 3.0, 3.0)

            # restore painter
            painter.restore()

        # NODE_NAME --------------------------------------------------------
        elif index.column() == NODE_NAME:
            text = index.model().data(index, Qt.DisplayRole)
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            if MTTSettings.value('vizWrongNameState') \
                    and not MTTSettings.value('showWrongNameState'):
                file_name = os.path.splitext(os.path.basename(
                    index.model().data(
                        index.sibling(index.row(), NODE_FILE),
                        Qt.DisplayRole
                    )
                ))[0]
                if not re.split('[0-9]*$', text.rsplit(':')[-1])[0] == \
                        re.split('[0-9]*$', file_name)[0]:
                    bg_color = QBrush(
                        Qt.red
                        if option.state & QStyle.State_Selected
                        else Qt.darkRed,
                        Qt.Dense4Pattern
                    )

            if not MTTSettings.value('showNamespaceState'):
                splits = text.split(':')
                text = splits[len(splits) > 1]

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            rect = option.rect
            rect.setX(4)
            QApplication.style().drawItemText(
                painter, rect, Qt.AlignLeft | Qt.AlignVCenter,
                palette, True, text
            )
            painter.restore()

        # NODE_FILE ------------------------------------------------------------
        elif index.column() == NODE_FILE:
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            text = index.model().data(index, Qt.DisplayRole)
            if MTTSettings.value('vizExternalState'):
                if not text.startswith(self.ws_path):
                    bg_color = QBrush(
                        '#ef7900'
                        if option.state & QStyle.State_Selected
                        else '#b05100',
                        Qt.Dense4Pattern)

            if MTTSettings.value('vizWrongPathState'):
                if not re.match(MTTSettings.PATH_PATTERN, text):
                    bg_color = QBrush(
                        Qt.red
                        if option.state & QStyle.State_Selected
                        else Qt.darkRed,
                        Qt.Dense4Pattern)

            if MTTSettings.value('showBasenameState'):
                text = os.path.basename(text)
            elif not MTTSettings.value('showRealAttributeValue'):
                if not text.startswith('\\'):
                    text = os.path.normpath(cmds.workspace(projectPath=text))

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            QApplication.style().drawItemText(
                painter, option.rect, Qt.AlignLeft | Qt.AlignVCenter,
                palette, True, text)
            painter.restore()
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
Esempio n. 16
0
    def paint(self, painter, option, index):
        # NODE_REFERENCE ---------------------------------------------------
        if index.column() == NODE_REFERENCE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            if option.state & QStyle.State_Selected:
                bg_color = palette.highlight().color()
            else:
                bg_color = Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint
            value = float(index.model().data(index))
            if value == 0.0:
                painter.setPen(Qt.black if option.state
                               & QStyle.State_Selected else Qt.darkGray)
                painter.setBrush(Qt.NoBrush)
                mid_size = 3.0
            else:
                painter.setPen(Qt.darkCyan)
                painter.setBrush(Qt.cyan)
                mid_size = 4.0

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            losange = QPolygonF()
            losange.append(QPointF(h_center, v_center - mid_size))
            losange.append(QPointF(h_center - mid_size, v_center))
            losange.append(QPointF(h_center, v_center + mid_size))
            losange.append(QPointF(h_center + mid_size, v_center))

            painter.drawPolygon(losange)

            # restore painter
            painter.restore()

        # FILE_STATE -------------------------------------------------------
        elif index.column() == FILE_STATE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint circle
            value = index.model().data(index)

            pen_color = [
                Qt.darkRed,
                Qt.black if option.state & QStyle.State_Selected else Qt.gray,
                Qt.darkGreen
            ][value + 1]
            brush_color = [Qt.red, Qt.NoBrush, Qt.green][value + 1]

            painter.setPen(pen_color)
            painter.setBrush(brush_color)

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            center = QPointF(h_center, v_center)

            painter.drawEllipse(center, 3.0, 3.0)

            # restore painter
            painter.restore()

        # NODE_NAME --------------------------------------------------------
        elif index.column() == NODE_NAME:
            text = index.model().data(index, Qt.DisplayRole)
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            if MTTSettings.value('vizWrongNameState') \
                    and not MTTSettings.value('showWrongNameState'):
                file_name = os.path.splitext(
                    os.path.basename(index.model().data(
                        index.sibling(index.row(), NODE_FILE),
                        Qt.DisplayRole)))[0]
                if not re.split('[0-9]*$', text.rsplit(':')[-1])[0] == \
                        re.split('[0-9]*$', file_name)[0]:
                    bg_color = QBrush(
                        Qt.red if option.state
                        & QStyle.State_Selected else Qt.darkRed,
                        Qt.Dense4Pattern)

            if not MTTSettings.value('showNamespaceState'):
                splits = text.split(':')
                text = splits[len(splits) > 1]

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            rect = option.rect
            rect.setX(4)
            QApplication.style().drawItemText(painter, rect,
                                              Qt.AlignLeft | Qt.AlignVCenter,
                                              palette, True, text)
            painter.restore()

        # NODE_FILE ------------------------------------------------------------
        elif index.column() == NODE_FILE:
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            text = index.model().data(index, Qt.DisplayRole)
            if MTTSettings.value('vizExternalState'):
                if not text.startswith(self.ws_path):
                    bg_color = QBrush(
                        '#ef7900' if option.state
                        & QStyle.State_Selected else '#b05100',
                        Qt.Dense4Pattern)

            if MTTSettings.value('vizWrongPathState'):
                if not re.match(MTTSettings.PATH_PATTERN, text):
                    bg_color = QBrush(
                        Qt.red if option.state
                        & QStyle.State_Selected else Qt.darkRed,
                        Qt.Dense4Pattern)

            if MTTSettings.value('showBasenameState'):
                text = os.path.basename(text)
            elif not MTTSettings.value('showRealAttributeValue'):
                if not text.startswith('\\'):
                    text = os.path.normpath(cmds.workspace(projectPath=text))

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            QApplication.style().drawItemText(painter, option.rect,
                                              Qt.AlignLeft | Qt.AlignVCenter,
                                              palette, True, text)
            painter.restore()
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
Esempio n. 17
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.assert_(r2)

        self.assertEqual(t1, r2)
Esempio n. 18
0
def get_avgDist_minDist_maxDist_CP_single(persons, objects, objects_shapes, traj, polylinesI, polylinesP, polylinesS,
                                          polylinesAffNormal,
                                          polylinesAffLow, polylinesAffMed, polylinesAffHigh):
    dist_cperson = np.array([min([np.linalg.norm(x - person) for person in persons]) for x in traj])
    avgDist_cperson = np.average(dist_cperson)

    dist_cperson2 = np.array([min([np.linalg.norm(x - person) for x in traj]) for person in persons])

    minDist_cperson = np.min(dist_cperson)
    maxDist_cperson = np.max(dist_cperson)

    # To objects
    dist_center_object = np.array([min([np.linalg.norm(x - object) for object in objects]) for x in traj])

    avgDist_center_object = np.average(dist_center_object)
    minDist_center_object = np.min(dist_center_object)
    maxDist_center_object = np.max(dist_center_object)

    dist_shape_object_points = np.array(
        [[min(np.linalg.norm(x - point) for shape in objects_shapes for point in shape)] for x in traj])

    dist_shape_objects2 = np.array(
        [min([min([np.linalg.norm(x - point) for x in traj]) for point in shape]) for shape in objects_shapes])

    minDist_shape_obj = np.min(dist_shape_object_points)
    maxDist_shape_obj = np.max(dist_shape_object_points)
    avgDist_shape_obj = np.average(dist_shape_object_points)

    social_cperson = {'intimate': 0., 'personal': 0., 'social': 0., 'pub': 0.}
    social_affordance = {'normal': 0., 'low': 0., 'medium': 0., 'high': 0., 'free': 0.}

    polygonI = QPolygonF()
    polygonP = QPolygonF()
    polygonS = QPolygonF()

    polygonAffNormal = QPolygonF()
    polygonAffLow = QPolygonF()
    polygonAffMed = QPolygonF()
    polygonAffHigh = QPolygonF()

    for pI in polylinesI:
        for x in pI:
            polygonI.append(QPointF(x[0], x[1]))

    for pP in polylinesP:
        for x in pP:
            polygonP.append(QPointF(x[0], x[1]))

    for pS in polylinesS:
        for x in pS:
            polygonS.append(QPointF(x[0], x[1]))

    ## Object affordances
    for pN in polylinesAffNormal:
        for x in pN:
            polygonAffNormal.append(QPointF(x[0], x[1]))

    for pL in polylinesAffLow:
        for x in pL:
            polygonAffLow.append(QPointF(x[0], x[1]))

    for pM in polylinesAffMed:
        for x in pM:
            polygonAffMed.append(QPointF(x[0], x[1]))

    for pM in polylinesAffHigh:
        for x in pM:
            polygonAffHigh.append(QPointF(x[0], x[1]))

    for x in traj:
        if polygonI.containsPoint(QPointF(x[0], x[1]), Qt.OddEvenFill):
            social_cperson['intimate'] += 1.
        elif polygonP.containsPoint(QPointF(x[0], x[1]), Qt.OddEvenFill):
            social_cperson['personal'] += 1.
        elif polygonS.containsPoint(QPointF(x[0], x[1]), Qt.OddEvenFill):
            social_cperson['social'] += 1.
        else:
            social_cperson['pub'] += 1.

    social_cperson['intimate'] /= len(traj) / 100.
    social_cperson['personal'] /= len(traj) / 100.
    social_cperson['social'] /= len(traj) / 100.
    social_cperson['pub'] /= len(traj) / 100.

    for x in traj:
        if polygonAffNormal.containsPoint(QPointF(x[0], x[1]), Qt.OddEvenFill):
            social_affordance['normal'] += 1.
        elif polygonAffLow.containsPoint(QPointF(x[0], x[1]), Qt.OddEvenFill):
            social_affordance['low'] += 1.
        elif polygonAffMed.containsPoint(QPointF(x[0], x[1]), Qt.OddEvenFill):
            social_affordance['medium'] += 1.
        elif polygonAffHigh.containsPoint(QPointF(x[0], x[1]), Qt.OddEvenFill):
            social_affordance['high'] += 1.
        else:
            social_affordance['free'] += 1.

    social_affordance['normal'] /= len(traj) / 100.
    social_affordance['low'] /= len(traj) / 100.
    social_affordance['medium'] /= len(traj) / 100.
    social_affordance['high'] /= len(traj) / 100.
    social_affordance['free'] /= len(traj) / 100.

    return avgDist_cperson, minDist_cperson, maxDist_cperson, avgDist_shape_obj, minDist_shape_obj, maxDist_shape_obj, social_cperson, social_affordance, dist_cperson2, dist_shape_objects2
Esempio n. 19
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, o.z, 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 xrange(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)

            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
                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