MCPcopy Create free account
hub / github.com/Image-Py/imagepy / PolygonRoi

Class PolygonRoi

imagepy/core/roi/polygonroi.py:32–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30 return polygonize([line.intersection(line)])
31
32class PolygonRoi(ROI):
33 dtype = 'polygon'
34 def __init__(self, body=None):
35 self.body = body if body!=None else []
36 self.dirty = body!=None
37 self.infoupdate = body!=None
38 self.box = [1000,1000,-1000,-1000]
39
40 def update(self): self.dirty = True
41
42 def addpoint(self, p):
43 self.buf[0].append(p)
44
45 def commit(self, buf, oper):
46 pgs = []
47 if len(buf[0])==0:return False
48 if buf[0][0]!=buf[0][-1]:
49 buf[0].append(buf[0][0])
50 if len(self.body)==0:
51 self.body.append(buf)
52 buf = [[],[]]
53 self.update, self.infoupdate = True, True
54 return True
55 for i in self.body:
56 pgs.extend(to_segment(i))
57 unin = cascaded_union(pgs)
58 cur = cascaded_union(list(to_segment(buf)))
59 if oper=='+':rst = unin.union(cur)
60 if oper=='-':rst = unin.difference(cur)
61 self.body = parse_mpoly(rst)
62 self.update, self.infoupdate = True, True
63
64 def snap(self, x, y, z, lim):
65 if not self.issimple():return None
66 cur, minl = None, 1e8
67 for i in self.body[0][0]:
68 d = (i[0]-x)**2+(i[1]-y)**2
69 if d < minl:cur,minl = i,d
70 if minl**0.5>lim:return None
71 return self.body[0][0], self.body[0][0].index(cur)
72
73 def pick(self, x, y, z, lim):
74 rst = self.snap(x, y, z, lim)
75 if rst!=None:return rst
76
77 pgs = []
78 for i in self.body:
79 pgs.extend(to_segment(i))
80 unin = cascaded_union(pgs)
81 if unin.contains(Point(x,y)):
82 return True
83 return None
84
85 def draged(self, ox, oy, nx, ny, nz, i):
86 self.update, self.infoupdate = True, True
87 if i==True:
88 for pg in self.body:
89 pg[0] = [(p[0]+(nx-ox), p[1]+(ny-oy)) for p in pg[0]]

Callers 4

topolygonMethod · 0.85
topolygonMethod · 0.85
s2r_polygonFunction · 0.85
s2r_polygonsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected