Esempio n. 1
0
class SideRoi:
    support: List[QRectF]
    polygon: QPolygonF

    def __init__(self):
        self.support = list()
        self.polygon = QPolygonF()

    def in_support(self, point: QPointF) -> bool:
        for s in self.support:
            if s.contains(point):
                return True

        return False

    def contains(self, point: QPointF) -> bool:
        return (self.polygon.size() >= 3) and \
            self.polygon.containsPoint(point, Qt.OddEvenFill)

    def to_dict(self):
        o = dict()
        o['support'] = list()

        for s in self.support:
            r = dict()
            r['x'] = s.x()
            r['y'] = s.y()
            r['width'] = s.width()
            r['height'] = s.height()
            o['support'].append(r)

        o['polygon'] = list()
        for point in self.polygon:
            p = dict()
            p['x'] = point.x()
            p['y'] = point.y()
            o['polygon'].append(p)

        return o

    def from_dict(self, o: dict):
        self.support = list()
        self.polygon = QPolygonF()

        for r in o['support']:
            x = r['x']
            y = r['y']
            w = r['width']
            h = r['height']
            s = QRectF(x, y, w, h)
            self.support.append(s)

        for p in o['polygon']:
            x = p['x']
            y = p['y']
            point = QPointF(x, y)
            self.polygon.append(point)

        return self
Esempio n. 2
0
 def countInArea(self, area: QPolygonF):
     new_count = []
     for cell in self.__cells.values():
         if area.containsPoint(cell.center(),
                               Qt.OddEvenFill) and not cell.isCounted():
             cell.count(self.countId)
             new_count.append(cell)
     return new_count