diff --git a/script/local.py b/script/local.py index f9a6529..c84c79e 100755 --- a/script/local.py +++ b/script/local.py @@ -183,4 +183,105 @@ add_device(Sinusoid("center_y"), True) center_x.setPolling(100) center_y.setPolling(100) +if not get_context().isLocalMode(): + try: + run("camtool") + add_device(CamTool("image_stats", prefix = "SINEG01-DSCR190:", latch = True, camera = "SINEG01-DSCR190", gauss = False), True) + except: + pass + + +#Convex hull plots +def clear_convex_hull_plot(title): + plots = get_plots(title = title) + if len(plots)>0: + plots[0].clear() + +def add_convex_hull_plot(title, x,y, name=None, clear = False, x_range = None, y_range = None): + plots = get_plots(title = title) + p = None + if len(plots)==0: + p = plot(None,name=name, title = title)[0] + if x_range is not None: + p.getAxis(p.AxisId.X).setRange(x_range[0], x_range[1]) + if y_range is not None: + p.getAxis(p.AxisId.Y).setRange(y_range[0], y_range[1]) + p.setLegendVisible(True) + else: + p = plots[0] + if clear: + p.clear() + p.addSeries(LinePlotSeries(name)) + s = p.getSeries(name) + s.setLinesVisible(False) + s.setPointSize(3) + s.setData(to_array(x,'d') , to_array(y,'d')) + + #Convex Hull + #In the first time the plot shows, it takes some time for the color to be assigned + timeout = 0 + while s.color is None and timeout<1000: + time.sleep(0.001) + timeout = timeout + 1 + hull = LinePlotSeries(name + "Hull", s.color) + p.addSeries(hull) + #Bounding box + #x1,x2,y1,y2 = min(x), max(x), min(y), max(y) + #(hx,hy) = ([x1,x2, x2, x1, x1], [y1, y1, y2, y2, y1]) + (hx,hy) = convex_hull(x=x, y=y) + hx.append(hx[0]); hy.append(hy[0]) + hull.setLineWidth(2) + hull.setData(to_array(hx,'d') , to_array(hy,'d')) + hull.setColor(s.color) + return [hx,hy]if not get_context().isLocalMode(): + try: + run("camtool") + add_device(CamTool("image_stats", prefix = "SINEG01-DSCR190:", latch = True, camera = "SINEG01-DSCR190", gauss = False), True) + except: + pass + + +#Convex hull plots +def clear_convex_hull_plot(title): + plots = get_plots(title = title) + if len(plots)>0: + plots[0].clear() + +def add_convex_hull_plot(title, x,y, name=None, clear = False, x_range = None, y_range = None): + plots = get_plots(title = title) + p = None + if len(plots)==0: + p = plot(None,name=name, title = title)[0] + if x_range is not None: + p.getAxis(p.AxisId.X).setRange(x_range[0], x_range[1]) + if y_range is not None: + p.getAxis(p.AxisId.Y).setRange(y_range[0], y_range[1]) + p.setLegendVisible(True) + else: + p = plots[0] + if clear: + p.clear() + p.addSeries(LinePlotSeries(name)) + s = p.getSeries(name) + s.setLinesVisible(False) + s.setPointSize(3) + s.setData(to_array(x,'d') , to_array(y,'d')) + + #Convex Hull + #In the first time the plot shows, it takes some time for the color to be assigned + timeout = 0 + while s.color is None and timeout<1000: + time.sleep(0.001) + timeout = timeout + 1 + hull = LinePlotSeries(name + "Hull", s.color) + p.addSeries(hull) + #Bounding box + #x1,x2,y1,y2 = min(x), max(x), min(y), max(y) + #(hx,hy) = ([x1,x2, x2, x1, x1], [y1, y1, y2, y2, y1]) + (hx,hy) = convex_hull(x=x, y=y) + hx.append(hx[0]); hy.append(hy[0]) + hull.setLineWidth(2) + hull.setData(to_array(hx,'d') , to_array(hy,'d')) + hull.setColor(s.color) + return [hx,hy]