class PathAccumulator(pycam.PathProcessors.BasePathProcessor): def __init__(self, zigzag=False, reverse=False): super(PathAccumulator, self).__init__() self.curr_path = None self.zigzag = zigzag self.scanline = None self.reverse = reverse def append(self, point): if self.curr_path == None: self.curr_path = Path() if self.reverse: self.curr_path.insert(0, point) else: self.curr_path.append(point) def new_direction(self, direction): self.scanline = 0 def new_scanline(self): self.scanline += 1 if self.curr_path: print "ERROR: curr_path expected to be empty" self.curr_path = None def end_scanline(self): if self.curr_path: if self.zigzag and (self.scanline % 2 == 0): self.curr_path.reverse() simplify_toolpath(self.curr_path) if self.reverse: self.paths.insert(0, self.curr_path) else: self.paths.append(self.curr_path) self.curr_path = None
def append(self, point): curr_path = None if self.curr_path == None: curr_path = Path() self.curr_path = curr_path else: curr_path = self.curr_path self.curr_path = None curr_path.append(point) if self.curr_path == None: simplify_toolpath(curr_path) if self.reverse: curr_path.reverse() self.paths.insert(0, curr_path) else: self.paths.append(curr_path)
def append(self, point): curr_path = None if self.curr_path == None: curr_path = Path() self.curr_path = curr_path else: curr_path = self.curr_path self.curr_path = None curr_path.append(point) if self.curr_path == None: if (self.scanline % 2) == 0: self.curr_scanline.append(curr_path) else: curr_path.reverse() self.curr_scanline.insert(0, curr_path)
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 = []
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 = []