Beispiel #1
0
 def fun(self):
     #构造初始圆, 初始点
     d = 5.
     pt = self.lines[0].p1
     C = Circle(pt, d / 2.)
     pl = LineSet()
     pre = pt
     while (True):
         canvas = np.ones([500, 500, 3], np.uint8) * 255
         self.display(canvas)
         pl.display(canvas, (255, 0, 0))
         remove = []  #被删除点
         ans = []  #交点
         cv2.circle(canvas, utils.tuple_int(C.pt), int(C.r), (0, 255, 0))
         for l in self:  #遍历集合,查找相交点
             dict = l.intersect(C)
             if dict['state'] == -1:  #删除直线
                 remove.append(l)
             elif dict['state'] == 1:  #删除一半
                 p1 = dict['intersect'][0]
                 cv2.circle(canvas, utils.tuple_int(p1), 3, (0, 0, 255))
                 ans.append(p1)
                 for i in l:  #遍历当前直线的两个端点
                     if C.pointPosition(i) == 1:  #这个点在圆外
                         p2 = i
                 l.p1 = p1
                 l.p2 = p2  #绑定新的点
         # plt.imshow(canvas); plt.show() #显示
         pass
         for i in remove:
             self.lines.remove(i)
         if len(ans) > 2:  #找到中心点
             break
         mid = ans[0].midPoint(ans[1])
         wid = abs((ans[1] - ans[0]).dist())
         pl.addLine(pre, mid)
         pre = mid
         d = wid * 1.1
         C = Circle(mid, d / 2.)
         # 输出图片
     splited = self.split()
     print(len(splited))
     splited[0].display(canvas, (255, 255, 0))
     splited[1].display(canvas, (0, 255, 255))
     plt.imshow(canvas)
     plt.show()  # 显示
     return pl
Beispiel #2
0
 def display(self, window, offset, mag, mag_vec):
     """
         Get the true position of the particle on the screen,
         if it is inside it, draw it
     """
     real_pos = get_real_pos(self.pos, offset, mag, mag_vec)
     real_radius = self.radius * mag
     if inside_window(window, real_pos, real_radius):
         args = window, *tuple_int(real_pos), int(real_radius), self.color
         pygame.gfxdraw.aacircle(*args)
         pygame.gfxdraw.filled_circle(*args)
Beispiel #3
0
 def display_new_line(self, size, nlines):
     canvas = np.ones(size, np.uint8) * 255
     line = self.startL
     i = 0
     while True:
         # print(i);i+=1
         if not line: break
         color = (0, 0, 0)
         width = 1
         cv2.line(canvas, line.S, line.E, color, width)
         line = line.Next
         if line is self.startL:
             break
     for line in nlines:
         color = (255, 0, 0)
         width = 1
         cv2.line(canvas, utils.tuple_int(line.S), utils.tuple_int(line.E),
                  color, width)
     plt.imshow(canvas)
     plt.show()
Beispiel #4
0
def display_msp(msp, size):
    print(size)
    canvas = np.ones(size, np.uint8) * 255
    for polyline in msp:
        print('polyline: ' + str(polyline))
        pts = polyline.points()
        pre = None
        start = None
        for i, x in enumerate(pts):
            now = utils.tuple_int(x)
            if not i:
                pre = tuple(now)
                start = tuple(now)
                continue
            cv2.line(canvas, pre, now, (0, 0, 0))
            pre = tuple(now)
        cv2.line(canvas, pre, start, (0, 0, 0))
    plt.imshow(canvas)
    plt.show()
Beispiel #5
0
    def __init__(self, *args):
        if len(args) == 0:
            self.lines = []
            self.pts = []
        elif len(args) == 1:
            self.lines = []
            self.pts = []
            polyline = args[0]

            def line_append(p1, p2):
                if p1 != p2:
                    self.lines.append(Line(p1, p2))

            self.pts = pts = polyline.points()
            pre = origin = None
            for pt in pts:
                pt = utils.tuple_int(pt)
                if not pre is None:
                    line_append(pre, pt)
                else:
                    origin = pt
                pre = pt
            line_append(pre, origin)
Beispiel #6
0
 def display(self, canvas, color=(0, 0, 0), wid=1):
     for line in self:
         cv2.line(canvas, utils.tuple_int(line.p1),
                  utils.tuple_int(line.p2), color, wid)
Beispiel #7
0
 def display(self, canvas, color=(0, 255, 255), width=10):
     cv2.line(canvas, utils.tuple_int(self.p1), utils.tuple_int(self.p2),
              color, width)
Beispiel #8
0
def display_points(canvas, pts):
    for pt in pts:
        cv2.circle(canvas, utils.tuple_int(pt), 3, (255, 0, 0))