示例#1
0
    def convert_hor_path_list(self):
        if DEBUG_POLYGONEXTRACTOR2:
            print("converting hor paths")
        hor_path_list = []
        for s in self.hor_path_list:
            allsame = True
            miny = s.points[0][1]
            maxy = s.points[0][1]
            for p in s.points:
                if not p[0] == s.points[0][0]:
                    allsame = False
                if p[1] < miny:
                    miny = p[1]
                if p[1] > maxy:
                    maxy = p[1]
            if allsame:
                if DEBUG_POLYGONEXTRACTOR2:
                    print("all same !")
                s0 = Path()
                for p in s.points:
                    if p[1] == miny:
                        s0.append(p)
                hor_path_list.append(s0)
                s1 = Path()
                for p in s.points:
                    if p[1] == maxy:
                        s1.append(p)
                hor_path_list.append(s1)
                continue
            prev = s.points[-1]
            p_iter = CyclicIterator(s.points)
            p = s.points[0]
            next_p = next(p_iter)
            while not ((prev[0] >= p[0]) and (next_p[0] > p[0])):
                p = next_p
                next_p = next(p_iter)
            count = 0
            while count < len(s.points):
                s0 = Path()
                while next_p[0] >= p[0]:
                    s0.append(p)
                    p = next_p
                    next_p = next(p_iter)
                    count += 1
                s0.append(p)
                while (len(s0.points) > 1) \
                        and (s0.points[0][0] == s0.points[1][0]):
                    s0.points = s0.points[1:]
                while (len(s0.points) > 1) \
                        and (s0.points[-2][0] == s0.points[-1][0]):
                    s0.points = s0.points[0:-1]

                hor_path_list.append(s0)
                s1 = Path()
                while next_p[0] <= p[0]:
                    s1.append(p)
                    p = next_p
                    next_p = next(p_iter)
                    count += 1
                s1.append(p)
                s1.reverse()
                while (len(s1.points) > 1) \
                        and (s1.points[0][0] == s1.points[1][0]):
                    s1.points = s1.points[1:]
                while (len(s1.points) > 1) \
                        and (s1.points[-2][0] == s1.points[-1][0]):
                    s1.points = s1.points[:-1]
                hor_path_list.append(s1)
        hor_path_list.sort(key=lambda p: p.points[0][0])
        if DEBUG_POLYGONEXTRACTOR2:
            print("ver_hor_path_list = ", hor_path_list)
            for s in hor_path_list:
                print("s%d =" % s.id),
                for point in s.points:
                    print(point.id),
                print()
        self.ver_hor_path_list = hor_path_list

        self.act_hor_path_list = []
示例#2
0
    def convert_hor_path_list(self):
        if DEBUG_POLYGONEXTRACTOR2:
            print "converting hor paths"
        hor_path_list = []
        for s in self.hor_path_list:
            allsame = True
            miny = s.points[0].y
            maxy = s.points[0].y
            for p in s.points:
                if not p.x == s.points[0].x:
                    allsame = False
                if p.y < miny:
                    miny = p.y
                if p.y > maxy:
                    maxy = p.y
            if allsame:
                if DEBUG_POLYGONEXTRACTOR2:
                    print "all same !"
                s0 = Path()
                for p in s.points:
                    if p.y == miny:
                        s0.append(p)
                hor_path_list.append(s0)
                s1 = Path()
                for p in s.points:
                    if p.y == maxy:
                        s1.append(p)
                hor_path_list.append(s1)
                continue
            prev = s.points[-1]
            p_iter = CyclicIterator(s.points)
            p = s.points[0]
            next_p = p_iter.next()
            while not ((prev.x >= p.x) and (next_p.x > p.x)):
                p = next_p
                next_p = p_iter.next()
            count = 0
            while count < len(s.points):
                s0 = Path()
                while next_p.x >= p.x:
                    s0.append(p)
                    p = next_p
                    next_p = p_iter.next()
                    count += 1
                s0.append(p)
                while (len(s0.points) > 1) \
                        and (s0.points[0].x == s0.points[1].x):
                    s0.points = s0.points[1:]
                while (len(s0.points) > 1) \
                        and (s0.points[-2].x == s0.points[-1].x):
                    s0.points = s0.points[0:-1]

                hor_path_list.append(s0)
                s1 = Path()
                while next_p.x <= p.x:
                    s1.append(p)
                    p = next_p
                    next_p = p_iter.next()
                    count += 1
                s1.append(p)
                s1.reverse()
                while (len(s1.points) > 1) \
                        and (s1.points[0].x == s1.points[1].x):
                    s1.points = s1.points[1:]
                while (len(s1.points) > 1) \
                        and (s1.points[-2].x == s1.points[-1].x):
                    s1.points = s1.points[:-1]
                hor_path_list.append(s1)
        hor_path_list.sort(cmp=lambda a, b: cmp(a.points[0].x, b.points[0].x))
        if DEBUG_POLYGONEXTRACTOR2:
            print "ver_hor_path_list = ", hor_path_list
            for s in hor_path_list:
                print "s%d =" % s.id,
                for point in s.points:
                    print point.id,
                print
        self.ver_hor_path_list = hor_path_list

        self.act_hor_path_list = []
示例#3
0
    def convert_hor_path_list(self):
        if DEBUG_POLYGONEXTRACTOR2:
            print "converting hor paths"
        hor_path_list = []
        for s in self.hor_path_list:
            allsame = True
            miny = s.points[0].y
            maxy = s.points[0].y
            for p in s.points:
                if not p.x == s.points[0].x:
                    allsame = False
                if p.y < miny:
                    miny = p.y
                if p.y > maxy:
                    maxy = p.y
            if allsame:
                if DEBUG_POLYGONEXTRACTOR2:
                    print "all same !"
                s0 = Path()
                for p in s.points:
                    if p.y == miny:
                        s0.append(p)
                hor_path_list.append(s0)
                s1 = Path()
                for p in s.points:
                    if p.y == maxy:
                        s1.append(p)
                hor_path_list.append(s1)
                continue
            prev = s.points[-1]
            p_iter = CyclicIterator(s.points)
            p = s.points[0]
            next_p = p_iter.next()
            while not ((prev.x >= p.x) and (next_p.x > p.x)):
                p = next_p
                next_p = p_iter.next()
            count = 0
            while count < len(s.points):
                s0 = Path()
                while next_p.x >= p.x:
                    s0.append(p)
                    p = next_p
                    next_p = p_iter.next()
                    count += 1
                s0.append(p)
                while (len(s0.points) > 1) \
                        and (s0.points[0].x == s0.points[1].x):
                    s0.points = s0.points[1:]
                while (len(s0.points) > 1) \
                        and (s0.points[-2].x == s0.points[-1].x):
                    s0.points = s0.points[0:-1]

                hor_path_list.append(s0)
                s1 = Path()
                while next_p.x <= p.x:
                    s1.append(p)
                    p = next_p
                    next_p = p_iter.next()
                    count += 1
                s1.append(p)
                s1.reverse()
                while (len(s1.points) > 1) \
                        and (s1.points[0].x == s1.points[1].x):
                    s1.points = s1.points[1:]
                while (len(s1.points) > 1) \
                        and (s1.points[-2].x == s1.points[-1].x):
                    s1.points = s1.points[:-1]
                hor_path_list.append(s1)
        hor_path_list.sort(cmp=lambda a, b: cmp(a.points[0].x, b.points[0].x))
        if DEBUG_POLYGONEXTRACTOR2:
            print "ver_hor_path_list = ", hor_path_list
            for s in hor_path_list:
                print "s%d =" % s.id,
                for point in s.points:
                    print point.id,
                print
        self.ver_hor_path_list = hor_path_list

        self.act_hor_path_list = []