def _replot_polygon(self, poly): pts = [(pi.x, pi.y) for pi in poly.points] pts = sort_clockwise(pts, pts) # pts = pts + pts[:1] pts = array(pts) scale = 1000 pts *= scale use_convex_hull = False find_min = poly.find_min npoints, lens, theta = raster( pts, step=poly.scan_size, offset=-poly.offset if poly.use_outline else 0, use_convex_hull=use_convex_hull, find_min=find_min, theta=poly.theta) poly._set_theta(theta) # poly.trait_set(theta=theta) g = self.graph g.clear() g.plotcontainer.padding = 5 g.new_plot( padding=[60, 30, 30, 50], # bounds=[400, 400], # resizable='h', xtitle='X (microns)', ytitle='Y (microns)') g.new_plot( padding=[50, 30, 30, 30], xtitle='Theta (degrees)', ytitle='Num. Scan Lines', # bounds=[400, 100], # resizable='h' ) if find_min: ts, ls = zip(*lens) g.new_series(ts, ls, plotid=1) # plot original pts = vstack((pts, pts[:1])) xs, ys = pts.T self.graph.new_series(xs, ys, plotid=0) self.graph.set_x_limits(min(xs), max(xs), pad='0.1') self.graph.set_y_limits(min(ys), max(ys), pad='0.1') for ps in npoints: for i in range(0, len(ps), 2): p1, p2 = ps[i], ps[i + 1] g.new_series((p1[0], p2[0]), (p1[1], p2[1]), color='black', plotid=0) if poly.use_outline: from pychron.core.geometry.polygon_offset import polygon_offset opoly = polygon_offset(pts, -1 * poly.offset) opoly = array(opoly) xs, ys, _ = opoly.T self.graph.new_series(xs, ys, plotid=0)
def _raster(self, points, velocity, step=500, scale=1000, find_min=False, start_callback=None, end_callback=None, verbose=False): from pychron.core.geometry.scan_line import raster lines = raster(points, step=step, find_min=find_min) # initialize variables cnt = 0 direction = 1 flip = False lasing = False sc = self.stage_controller if verbose: self.info('start raster') # print lines # loop thru each scan line # for yi, xs in lines[::skip]: for yi, xs in lines: if direction == -1: xs = list(reversed(xs)) # convert odd numbers lists to even n = len(xs) if n % 2 != 0: xs = sorted(list(set(xs))) # traverse each x-intersection pair n = len(xs) for i in range(0, n, 2): if len(xs) <= 1: continue x1, x2, yy = xs[i] / scale, xs[i + 1] / scale, yi / scale if abs(x1 - x2) > 1e-10: if not lasing: if verbose: self.info('fast to {} {},{}'.format(cnt, x1, yy)) self.linear_move(x1, yy, mode='absolute', set_stage=False, block=True) if start_callback is not None: start_callback() lasing = True else: if verbose: self.info('slow to {} {},{}'.format(cnt, x1, yy)) sc.timer = sc.timer_factory() self.linear_move(x1, yy, mode='absolute', set_stage=False, velocity=velocity) if verbose: self.info('move to {}a {},{}'.format(cnt, x2, yy)) # if n > 2 and not i * 2 >= n: # line this scan line has more then 1 segment turn off laser at end of segment if i + 2 < n and not xs[i + 1] == xs[i + 2]: self.linear_move(x2, yy, velocity=velocity, mode='absolute', set_stage=False, block=True) self.info('wait for move complete') if end_callback is not None: end_callback() lasing = False else: self.linear_move(x2, yy, velocity=velocity, mode='absolute', set_stage=False, ) cnt += 1 flip = True else: flip = False if flip: direction *= -1 sc.block() if verbose: self.info('end raster')
def _replot_polygon(self, poly): pts = [(pi.x, pi.y) for pi in poly.points] pts = sort_clockwise(pts, pts) # pts = pts + pts[:1] pts = array(pts) scale = 1000 pts *= scale use_convex_hull = False find_min = poly.find_min npoints, lens, theta = raster(pts, step=poly.scan_size, offset=-poly.offset if poly.use_outline else 0, use_convex_hull=use_convex_hull, find_min=find_min, theta=poly.theta ) poly._set_theta(theta) # poly.trait_set(theta=theta) g = self.graph g.clear() g.plotcontainer.padding = 5 g.new_plot(padding=[60, 30, 30, 50], # bounds=[400, 400], # resizable='h', xtitle='X (microns)', ytitle='Y (microns)') g.new_plot(padding=[50, 30, 30, 30], xtitle='Theta (degrees)', ytitle='Num. Scan Lines', # bounds=[400, 100], # resizable='h' ) if find_min: ts, ls = zip(*lens) g.new_series(ts, ls, plotid=1) # plot original pts = vstack((pts, pts[:1])) xs, ys = pts.T self.graph.new_series(xs, ys, plotid=0) self.graph.set_x_limits(min(xs), max(xs), pad='0.1') self.graph.set_y_limits(min(ys), max(ys), pad='0.1') for ps in npoints: for i in range(0, len(ps), 2): p1, p2 = ps[i], ps[i + 1] g.new_series((p1[0], p2[0]), (p1[1], p2[1]), color='black', plotid=0) if poly.use_outline: from pychron.core.geometry.polygon_offset import polygon_offset opoly = polygon_offset(pts, -1 * poly.offset) opoly = array(opoly) xs, ys, _ = opoly.T self.graph.new_series(xs, ys, plotid=0)