def visit_leaf(self, boxIn, boxOut): X0 = boxIn | boxOut X = boxIn & boxOut # print(X0, boxIn, boxOut) vibes.drawBoxDiff(X0, boxIn, self.color_map["IN"]) vibes.drawBoxDiff(X0, boxOut, self.color_map["OUT"]) if not X.is_empty(): for i in range(X.size()): if X[i].diam() < 1e-8: X[i].inflate(0.05) vibes.drawBox(X[0][0], X[0][1], X[1][0], X[1][1], self.color_map["MAYBE"])
def SIVIA(X0, data, eps): stack = deque([IntervalVector(X0)]) lf = LargestFirst(eps/2.0) k = 0 rbox = [] while len(stack) > 0: X = stack.popleft() k = k+1 t = IBOOL(testR(X,data[0],float(data[1]),data[2])) if (t == IBOOL.IN): vibes.drawBox(X[0][0],X[0][1], X[1][0], X[1][1], '[r]' ) #rbox.append((X[0][0],X[0][1], X[1][0], X[1][1])) elif (t == IBOOL.OUT): # r = 1; vibes.drawBox(X[0][0],X[0][1], X[1][0], X[1][1], '[b]' ) elif (t == IBOOL.MAYBE): # r = 1; vibes.drawBox(X[0][0],X[0][1], X[1][0], X[1][1], '[orange]' ) elif (t != IBOOL.OUT and t != IBOOL.MAYBE): if (X.max_diam() > eps): (X1, X2) = lf.bisect(X) stack.append(X1) stack.append(X2) else : vibes.drawBox(X[0][0],X[0][1], X[1][0], X[1][1], '[y]' ) #vibes.drawBoxesUnion(rbox,'[r]') vibes.axisEqual()
def draw(self, color_in='#FF0000[#BB00FFAA]', color_out='b[#00AAFFAA]', color_maybe='[y]'): """Draw.""" X0 = self.xin | self.xout vibes.drawBoxDiff(X0, self.xin, siviaParams["color_in"]) vibes.drawBoxDiff(X0, self.xout, siviaParams["color_out"]) if (not self.isLeaf()): self.left.draw() self.right.draw() else: X = self.xin & self.xout vibes.drawBox(X[0][0], X[0][1], X[1][0], X[1][1], siviaParams["color_maybe"])
def drawBoxDiff(X0, X, color, use_patch=False, **kwargs): if X0 == X: return if not X.is_empty(): if use_patch is True: vibes.drawBoxDiff(X0, X, color, **kwargs) # vibes.drawBoxDiff([ X0[0].lb(), X0[0].ub(), X0[1].lb(), X0[1].ub()], # [X[0].lb(), X[0].ub(), X[1].lb(), X[1].ub()], color) else: for b in X0.diff(X): vibes.drawBox(b[0].lb(), b[0].ub(), b[1].lb(), b[1].ub(), color, **kwargs) else: vibes.drawBox(X0[0].lb(), X0[0].ub(), X0[1].lb(), X0[1].ub(), color, **kwargs)
def test_Paving3(self): P = IntervalVector(2, [-4, 4]) pdc = myPdc() A = Paving(P, YES) A.Sivia(pdc, op_And, 0.3) vibes.beginDrawing() vibes.newFigure("test3") # P = IntervalVector(2, [-4, -3.9]) A.visit(ToVibes(10)) vibes.drawBox(P[0][0], P[0][1], P[1][0], P[1][1], 'r') print(P) A.ctcOutside(P) print(P) vibes.drawBox(P[0][0], P[0][1], P[1][0], P[1][1], 'g')
def test_Paving3(self): P = IntervalVector(2, [-4, 4]) pdc = myPdc() A = Paving(P,YES); A.Sivia(pdc,op_And,0.3); vibes.beginDrawing() vibes.newFigure("test3") # P = IntervalVector(2, [-4, -3.9]) A.visit(ToVibes(10)) vibes.drawBox(P[0][0], P[0][1], P[1][0], P[1][1], 'r') print(P) A.ctcOutside(P) print(P) vibes.drawBox(P[0][0], P[0][1], P[1][0], P[1][1], 'g')
def __pySIVIA_sep(X0, sep, epsilon, color_in='k[r]', color_out='k[b]', color_maybe='k[y]', draw_boxes=True, save_result=True, **kwargs): stack = deque([IntervalVector(X0)]) res_y, res_in, res_out = [], [], [] lf = LargestFirst(epsilon / 2.0) k = 0 while len(stack) > 0: X = stack.popleft() k = k + 1 x_in, x_out = map(IntervalVector, (X, ) * 2) sep.separate(x_in, x_out) if (draw_boxes is True and vibes_available is True): drawBoxDiff(X, x_in, color_in, **kwargs) drawBoxDiff(X, x_out, color_out, **kwargs) if save_result is True: res_in += X.diff(x_in) res_out += X.diff(x_out) X = x_in & x_out if (X.is_empty()): continue if (X.max_diam() < epsilon): if draw_boxes is True: vibes.drawBox(X[0].lb(), X[0].ub(), X[1].lb(), X[1].ub(), color_maybe) res_y.append(X) elif (X.is_empty() is False): (X1, X2) = lf.bisect(X) stack.append(X1) stack.append(X2) print('number of separation %d / number of boxes %d' % (k, len(res_in) + len(res_out) + len(res_y))) return (res_in, res_out, res_y)
def __pySIVIA_ctc(X0, ctc, epsilon, color_out='k[b]', color_maybe='k[y]', draw_boxes=True, save_result=True, **kwargs): stack = deque([IntervalVector(X0)]) res_y, res_out = [], [] lf = LargestFirst(epsilon / 2.0) k = 0 while len(stack) > 0: k = k + 1 X = stack.popleft() X0 = IntervalVector(X) # X = __contract_and_extract(X, ctc, res_out, color_out) ctc.contract(X) if (draw_boxes is True and vibes_available is True): drawBoxDiff(X0, X, color_out, **kwargs) if save_result is True: res_out += X0.diff(X) if (X.is_empty()): continue if (X.max_diam() < epsilon): if draw_boxes is True: vibes.drawBox(X[0].lb(), X[0].ub(), X[1].lb(), X[1].ub(), color_maybe) if save_result is True: res_y.append(X) elif (X.is_empty() is False): (X1, X2) = lf.bisect(X) stack.append(X1) stack.append(X2) print('number of contraction %d / number of boxes %d' % (k, len(res_out) + len(res_y))) return (res_out, res_y)
def visit_leaf(self, box, status): framebox = box & self.frame # Associate a color to the box. # - YES (means "inside") is in green # - NO (means "outside") is in red # - MAYBE (means "boundary") is in blue. if status == YES: color = "r" elif status == NO: color = "b" else: color = "g" # Plot the box with Vibes vibes.drawBox(framebox[0].lb(), framebox[0].ub(), framebox[1].lb(), framebox[1].ub(), color)
def visit_leaf(self, box, status): framebox= box & self.frame; # Associate a color to the box. # - YES (means "inside") is in green # - NO (means "outside") is in red # - MAYBE (means "boundary") is in blue. if status == YES: color="r" elif status == NO: color="b" else : color="g" # Plot the box with Vibes vibes.drawBox(framebox[0].lb(), framebox[0].ub(), framebox[1].lb(), framebox[1].ub(), color);
def sivia(X): X0 = X vibes.drawBox(X[0][0], X[0][1], X[1][0], X[1][1], color='black[blue]', figure='sivia_easibex_vibes') X = Cout(X) vibes.drawBox(X[0][0], X[0][1], X[1][0], X[1][1], color='magenta[red]', figure='sivia_easibex_vibes') #X = Cin(X) #b=inside(X); #if b==[1 1]: vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='magenta[red]',figure='sivia_easibex_vibes') #elif b==[0 0]: vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='black[blue]',figure='sivia_easibex_vibes') #elif (i_Width(X)<0.1): vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='yellow[yellow]',figure='sivia_easibex_vibes') if (i_Width(X) < 0.25): vibes.drawBox(X[0][0], X[0][1], X[1][0], X[1][1], color='yellow[yellow]', figure='sivia_easibex_vibes') #if (i_decrease(X,X0)<0.1): vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='yellow[yellow]',figure='sivia_easibex_vibes') else: X1, X2 = i_Bisect(X) sivia(X1) sivia(X2)
def shapeGen(): x, y = yield (x,y) = yield vibes.drawArrow([x-1, y-1], [x+1, y+1], 0.6, 'k[k]') (x,y) = yield vibes.drawAUV(x,y,45,2, 'k[y]') (x,y) = yield vibes.drawBox(x-1,x+1,y-2,y+2, "[b]") (x,y) = yield vibes.drawBoxesUnion([[x-1,x,y-2,y], [x-0.5,x+1,y-0.5,y+2]], "[r]") (x,y) = yield vibes.drawCircle(x,y,1, "g[m]") (x,y) = yield vibes.drawEllipse(x,y,2,1,45, color="r[darkCyan]") (x,y) = yield vibes.drawLine([[x-0.5, y-1], [x+1, y+0.5]], "k") (x,y) = yield vibes.drawPie( (x-2, y-2), (1,2.5), [20,70] , "y[cyan]") (x,y) = yield vibes.drawPolygon([[x-1,y-1], [x, y+1], [ x+1, y-1]], "k[orange]") (x,y) = yield vibes.drawRing(x,y, 1,2, '[red]') # (x,y) = yield vibes.drawPie( (x, y), (1,2), [0,360] , "y[cyan]") (x,y) = yield vibes.drawVehicle( x, y, 20, 1, "[darkBlue]") (x,y) = yield vibes.drawPoint( x,y, 1, "[k]") (x,y) = yield vibes.drawText( x,y, "Text", 1)
def shapeGen(): x, y = yield (x, y) = yield vibes.drawArrow([x - 1, y - 1], [x + 1, y + 1], 0.6, 'k[k]') (x, y) = yield vibes.drawAUV(x, y, 45, 2, 'k[y]') (x, y) = yield vibes.drawBox(x - 1, x + 1, y - 2, y + 2, "[b]") (x, y) = yield vibes.drawBoxesUnion( [[x - 1, x, y - 2, y], [x - 0.5, x + 1, y - 0.5, y + 2]], "[r]") (x, y) = yield vibes.drawCircle(x, y, 1, "g[m]") (x, y) = yield vibes.drawEllipse(x, y, 2, 1, 45, color="r[darkCyan]") (x, y) = yield vibes.drawLine([[x - 0.5, y - 1], [x + 1, y + 0.5]], "k") (x, y) = yield vibes.drawPie((x - 2, y - 2), (1, 2.5), [20, 70], "y[cyan]") (x, y) = yield vibes.drawPolygon([[x - 1, y - 1], [x, y + 1], [x + 1, y - 1]], "k[orange]") (x, y) = yield vibes.drawRing(x, y, 1, 2, '[red]') # (x,y) = yield vibes.drawPie( (x, y), (1,2), [0,360] , "y[cyan]") (x, y) = yield vibes.drawVehicle(x, y, 20, 1, "[darkBlue]") (x, y) = yield vibes.drawPoint(x, y, 1, "[k]") (x, y) = yield vibes.drawText(x, y, "Text", 1)
def sivia(X): X0 = X vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='black[blue]',figure='sivia_easibex_vibes') X = Cout(X) vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='magenta[red]',figure='sivia_easibex_vibes') #X = Cin(X) #b=inside(X); #if b==[1 1]: vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='magenta[red]',figure='sivia_easibex_vibes') #elif b==[0 0]: vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='black[blue]',figure='sivia_easibex_vibes') #elif (i_Width(X)<0.1): vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='yellow[yellow]',figure='sivia_easibex_vibes') if (i_Width(X) < 0.25): vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='yellow[yellow]',figure='sivia_easibex_vibes') #if (i_decrease(X,X0)<0.1): vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='yellow[yellow]',figure='sivia_easibex_vibes') else: X1,X2 = i_Bisect(X) sivia(X1) sivia(X2)
# Read the image and extract the last layer img = misc.imread('./img.png')[:, :, 3] # normalize in order to have a binary image. img = img / np.max(img) if np.max(img) != 1: print("Error, img must be a binary image") # convert img into a unsigned int64 image type img = img.astype(np.uint64) # vertical flip to inverse the y axis img = np.flipud(img) # PixelMap2D constructor takes : # - a binary image in uint64 format. # - x position of the lower left pixel in world frame # - y position of the lower left pixel in world frame # - size of a pixel in the x direction (in meter) # - size of a pixel in the y direction (in meter) x_res = 12.0 / img.shape[0] y_res = 12.0 / img.shape[1] p = PixelMap2D(img, -4, -4, x_res, y_res) # Compute the intgral image (in place) p.compute_integral_image() # build the contractor ctc = CtcPixelMap(p) X0 = IntervalVector([[-1, 4], [0, 3]]) vibes.drawBox(X0[0][0], X0[0][1], X0[1][0], X0[1][1], "b") ctc.contract(X0) vibes.drawBox(X0[0][0], X0[0][1], X0[1][0], X0[1][1], "r")
def main(stdscr): # Clear screen stdscr.clear() stdscr.keypad(1) begin_x = 20; begin_y = 7 height = 5; width = 40 win = curses.newwin(height, width, begin_y, begin_x) stdscr.addstr(0,10,"Hit 'space' to quit") stdscr.refresh() cpt = 0 key = '' x = Interval(1,1.5) y = Interval(2,3) dth = Interval.HALF_PI.mid()/32. th = Interval(0).inflate(2*dth) Interval.__str__ = print2 fout = open("test.txt", "a") fout.write("#================ RUN ===============\n") while key != ord(' '): key = stdscr.getch() lower_key = chr(key).lower() if lower_key == 'z' : y += 0.5 if curses.ascii.isupper(key) else 0.1 elif lower_key == 's' : y -= 0.5 if curses.ascii.isupper(key) else 0.1 elif lower_key == 'd' : x += 0.5 if curses.ascii.isupper(key) else 0.1 elif lower_key == 'q' : x -= 0.5 if curses.ascii.isupper(key) else 0.1 elif lower_key == 'a': th += dth/8. if curses.ascii.isupper(key) else dth elif lower_key == 'e': th -= dth/8. if curses.ascii.isupper(key) else dth elif key == curses.KEY_NPAGE: th = th.lb() + (Interval(0,th.diam()-dth) | Interval(0)) elif key == curses.KEY_PPAGE: th = th.lb() + (Interval(0,th.diam()+dth) | Interval(0)) elif key == curses.KEY_RIGHT: x = x.lb() + (Interval(0,x.diam()+1) | Interval(0)) elif key == curses.KEY_LEFT: x = x.lb() + (Interval(0,x.diam()-1) | Interval(0)) elif key == curses.KEY_UP: y = y.lb() + (Interval(0,y.diam()+1) | Interval(0)) elif key == curses.KEY_DOWN: y = y.lb() + (Interval(0,y.diam()-1) | Interval(0)) # # # if curses.ascii.ascii(key) == "a": # # if key == curses.KEY_UP or key == 566: # y += 0.5 if key==566 else 0.1 # elif key == curses.KEY_DOWN or key == 525: # y -= 0.5 if key==525 else 0.1 # elif key == curses.KEY_RIGHT or key == 560: # x += 0.5 if key==560 else 0.1 # elif key == curses.KEY_LEFT or key == 545: # x -= 0.5 if key==545 else 0.1 # elif key == ord('a') or key == 1: # th += 0.1 if key==1 else 0.05 # elif key == ord('e') or key == 5: # th -= 0.1 if key==5 else 0.05 # # elif key == ord('A'): # th = th.lb() + (Interval(0,th.diam()-0.1) | Interval(0)) # elif key == ord('E'): # th = th.lb() + (Interval(0,th.diam()+0.1) | Interval(0)) # elif key == ord('z'): # x = x.lb() + (Interval(0,x.diam()+1) | Interval(0)) # elif key == ord('s'): # x = x.lb() + (Interval(0,x.diam()-1) | Interval(0)) # elif key == ord('d'): # y = y.lb() + (Interval(0,y.diam()+1) | Interval(0)) # elif key == ord('q'): # y = y.lb() + (Interval(0,y.diam()-1) | Interval(0)) elif key == ord('R'): x = Interval(1,1.5) y = Interval(2,3) th = Interval(0).inflate(1) xx,yy,thh = Catan2(x,y,Interval(th)) # print(event.Key, event.Ascii, th, thh) # print(x, y, th ) vibes.clearFigure() vibes.drawBox(x[0], x[1], y[0], y[1], 'r') vibes.drawPie((0,0), (1e-5,5), th*180./math.pi, "r") vibes.drawPie((0,0), (1e-5,5), thh*180./math.pi, "b") vibes.drawBox(xx[0], xx[1], yy[0], yy[1], 'b') # if key in actions: # x, y, th = actions[key]( x,y,th ) # fct = actions.get(key, lambda x,y,th:x,y,th) stdscr.clear() stdscr.addstr(1, 10, "Pressed %s %d"%(lower_key, key)) stdscr.addstr(1,25,str(curses.ascii.ctrl(key))) stdscr.addstr(1,40,str(curses.ascii.ascii(key))) stdscr.addstr(1,40,str(curses.ascii.alt(key))) stdscr.addstr(3, 20, "x : %s\t\t%s"%(x,xx)) stdscr.addstr(4, 20, "y : %s\t\t%s"%(y,yy)) stdscr.addstr(5, 20, "theta : %s\t\t%s"%(th, thh)) if key == ord("t"): fout.write("%s %s %s -> %s %s %s\n"%(x,y,th, xx, yy, thh)) stdscr.refresh() curses.endwin() fout.write("#===================== END ===============\n");
vibes.drawPie((0,0), (1e-5,5), thh*180./math.pi, "b") vibes.drawBox(xx[0], xx[1], yy[0], yy[1], 'b') # if key in actions: # x, y, th = actions[key]( x,y,th ) # fct = actions.get(key, lambda x,y,th:x,y,th) stdscr.clear() stdscr.addstr(1, 10, "Pressed %s %d"%(lower_key, key)) stdscr.addstr(1,25,str(curses.ascii.ctrl(key))) stdscr.addstr(1,40,str(curses.ascii.ascii(key))) stdscr.addstr(1,40,str(curses.ascii.alt(key))) stdscr.addstr(3, 20, "x : %s\t\t%s"%(x,xx)) stdscr.addstr(4, 20, "y : %s\t\t%s"%(y,yy)) stdscr.addstr(5, 20, "theta : %s\t\t%s"%(th, thh)) if key == ord("t"): fout.write("%s %s %s -> %s %s %s\n"%(x,y,th, xx, yy, thh)) stdscr.refresh() curses.endwin() fout.write("#===================== END ===============\n"); if __name__ == '__main__': vibes.beginDrawing() vibes.newFigure("Debut Catan2") vibes.setFigureSize(500,500) vibes.drawBox(-5,5,-5,5) vibes.axisAuto() wrapper(main)
#exmaple.py from vibes import vibes print(vibes.channel, vibes.current_fig) vibes.beginDrawing() vibes.newFigure("test") vibes.drawBox(0,1,4,6,color='[#FF12FFA0]', figure='test') vibes.drawText(12, 12, 'My Text', 0.1, 'b[r]') vibes.axisAuto() vibes.drawBox(0.5,2,4,7,color='[#00FFFF66]', figure='test') vibes.drawBox(-1,0,-4,-6,color='r', figure='test') vibes.drawLine([[0,0], [4,4]]) vibes.drawEllipse(3, 5, 1, 3, 45) vibes.drawEllipse(5, 5, 3, 3, 0, angles=[30,60], color='g') vibes.drawCircle(0, 0, 5) vibes.drawAUV(0,0, 2, 3, color='r[yellow]') vibes.drawPie([0,0], [3,4], [45, 90]) vibes.newGroup("Pie", figure="test", format='[cyan]') vibes.drawPie([0,0], [5,9], [-120, -40], group="Pie") # vibes.drawPie([0,0], [5,9], [-120, -40], "[b]") vibes.drawPie([5,2], [1,2], [160, 220]) #, 'g[y]') # vibes.clearGroup("Pie", figure="test")
X[0][1], X[1][0], X[1][1], color='yellow[yellow]', figure='sivia_easibex_vibes') #if (i_decrease(X,X0)<0.1): vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='yellow[yellow]',figure='sivia_easibex_vibes') else: X1, X2 = i_Bisect(X) sivia(X1) sivia(X2) # ---------------------- main ---------------------------- print(vibes.channel, vibes.current_fig) vibes.beginDrawing() vibes.newFigure("sivia_easibex_vibes") X = [[-4, 4], [-4, 4]] #X=[[-0.4,0.4],[-0.4,0.4]] vibes.drawBox(X[0][0], X[0][1], X[1][0], X[1][1], color='g[black]', figure='sivia_easibex_vibes') #X=[[0,0.4],[-0.4,0.4]] #vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='yellow[yellow]',figure='sivia_easibex_vibes') #X=[[-0.4,0],[-0.4,0.4]] #vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='magenta[red]',figure='sivia_easibex_vibes') sivia(X) vibes.endDrawing()
#------------------------------------------------------------------------ def sivia(X): X0 = X vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='black[blue]',figure='sivia_easibex_vibes') X = Cout(X) vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='magenta[red]',figure='sivia_easibex_vibes') #X = Cin(X) #b=inside(X); #if b==[1 1]: vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='magenta[red]',figure='sivia_easibex_vibes') #elif b==[0 0]: vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='black[blue]',figure='sivia_easibex_vibes') #elif (i_Width(X)<0.1): vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='yellow[yellow]',figure='sivia_easibex_vibes') if (i_Width(X) < 0.25): vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='yellow[yellow]',figure='sivia_easibex_vibes') #if (i_decrease(X,X0)<0.1): vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='yellow[yellow]',figure='sivia_easibex_vibes') else: X1,X2 = i_Bisect(X) sivia(X1) sivia(X2) # ---------------------- main ---------------------------- print(vibes.channel, vibes.current_fig) vibes.beginDrawing() vibes.newFigure("sivia_easibex_vibes") X=[[-4,4],[-4,4]] #X=[[-0.4,0.4],[-0.4,0.4]] vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='g[black]',figure='sivia_easibex_vibes') #X=[[0,0.4],[-0.4,0.4]] #vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='yellow[yellow]',figure='sivia_easibex_vibes') #X=[[-0.4,0],[-0.4,0.4]] #vibes.drawBox(X[0][0],X[0][1],X[1][0],X[1][1],color='magenta[red]',figure='sivia_easibex_vibes') sivia(X) vibes.endDrawing()
def SIVIA(X0, test, test3, test2, eps): stack = deque([IntervalVector(X0)]) lf = LargestFirst(eps/2.0) k = 0 boatBoxesNP = [] while len(stack) > 0: X = stack.popleft() k = k+1 t = test.test(X) t2 = test2.test(X) t3 = test3.test(X) # if (t == IBOOL.IN): # vibes.drawBox(X[0][0],X[0][1], X[1][0], X[1][1], '[g]' ) if (t==IBOOL.IN or t2 == IBOOL.IN or t3 == IBOOL.IN): i,j = test.toPixels(X[0].lb(),X[1].ub()) i1,j1 = test.toPixels(X[0].ub(),X[1].ub()) i2,j2 = test.toPixels(X[0].ub(),X[1].lb()) i3,j3 = test.toPixels(X[0].lb(),X[1].lb()) boatBoxesNP.append([[i,j],[i1,j1],[i2,j2],[i3,j3]]) if (t==IBOOL.IN): # Gascogne vibes.drawBox(X[0][0],X[0][1], X[1][0], X[1][1], '[g]' ) elif (t2 == IBOOL.IN): # Robots vibes.drawBox(X[0][0],X[0][1], X[1][0], X[1][1], '[r]' ) elif (t3 == IBOOL.IN): # Trail vibes.drawBox(X[0][0],X[0][1], X[1][0], X[1][1], '[r]' ) elif (t == IBOOL.OUT and t2 == IBOOL.OUT and t3 == IBOOL.OUT): vibes.drawBox(X[0][0],X[0][1], X[1][0], X[1][1], '[b]' ) elif (t2 == IBOOL.MAYBE): vibes.drawBox(X[0][0],X[0][1], X[1][0], X[1][1], '[orange]' ) else: try: if (X.max_diam() > eps): (X1, X2) = lf.bisect(X) stack.append(X1) stack.append(X2) else : vibes.drawBox(X[0][0],X[0][1], X[1][0], X[1][1], '[y]' ) except Exception: print(type(lf),lf) vibes.axisEqual() return boatBoxesNP
def newFigure(name): vibes.newFigure(name) vibes.setFigureProperties({'x':0, 'y':0, 'width':1024, 'height':500, 'viewbox':'equal'}) vibes.axisLimits(x_min-offset, x_max+offset, y_min-offset, y_max+offset) vibes.drawBox(x_min-offset, x_max+offset, y_min-offset, y_max+offset, "white[white]")
#exmaple.py from vibes import vibes print(vibes.channel, vibes.current_fig) vibes.beginDrawing() vibes.newFigure("test") vibes.drawBox(0, 1, 4, 6, color='[#FF12FFA0]', figure='test') vibes.drawText(12, 12, 'My Text', 0.1, 'b[r]') vibes.axisAuto() vibes.drawBox(0.5, 2, 4, 7, color='[#00FFFF66]', figure='test') vibes.drawBox(-1, 0, -4, -6, color='r', figure='test') vibes.drawLine([[0, 0], [4, 4]]) vibes.drawEllipse(3, 5, 1, 3, 45) vibes.drawEllipse(5, 5, 3, 3, 0, angles=[30, 60], color='g') vibes.drawCircle(0, 0, 5) vibes.drawAUV(0, 0, 2, 3, color='r[yellow]') vibes.drawPie([0, 0], [3, 4], [45, 90]) vibes.newGroup("Pie", figure="test", format='[cyan]') vibes.drawPie([0, 0], [5, 9], [-120, -40], group="Pie") # vibes.drawPie([0,0], [5,9], [-120, -40], "[b]") vibes.drawPie([5, 2], [1, 2], [160, 220]) #, 'g[y]') # vibes.clearGroup("Pie", figure="test") vibes.drawPie([0, 0], [1, 2], [160, 220]) #, 'g[y]')
# exmaple.py from vibes import vibes print(vibes.channel, vibes.current_fig) vibes.beginDrawing() vibes.newFigure("test") vibes.drawBox(0, 1, 4, 6, color="[#FF12FFA0]", figure="test") vibes.drawBox(0.5, 2, 4, 7, color="[#00FFFF66]", figure="test") vibes.drawBox(-1, 0, -4, -6, color="r", figure="test") vibes.drawLine([[0, 0], [4, 4]]) vibes.drawEllipse(3, 5, 1, 3, 45) vibes.drawEllipse(5, 5, 3, 3, 0, angles=[30, 60], color="g") vibes.drawCircle(0, 0, 5) vibes.drawAUV(0, 0, 2, 3, color="r[yellow]") vibes.drawPie([0, 0], [3, 4], [45, 90]) vibes.drawPie([0, 0], [5, 9], [-120, -40], "[b]") vibes.drawPie([0, 0], [1, 2], [160, 220], "g[y]") vibes.drawPie([5, 2], [1, 2], [160, 220], "g[y]") vibes.newFigure("test2") # vibes.drawBox(-1,0,-4,-6,color='[r]', figure='test2') # vibes.selectFigure("test")
# normalize in order to have a binary image. img = img/np.max(img) if np.max(img) != 1: print("Error, img must be a binary image") # convert img into a unsigned int64 image type img = img.astype(np.uint64) # vertical flip to inverse the y axis img = np.flipud(img) # PixelMap2D constructor takes : # - a binary image in uint64 format. # - x position of the lower left pixel in world frame # - y position of the lower left pixel in world frame # - size of a pixel in the x direction (in meter) # - size of a pixel in the y direction (in meter) x_res = 12.0 / img.shape[0] y_res = 12.0 / img.shape[1] p = PixelMap2D(img, -4, -4, x_res, y_res) # Compute the intgral image (in place) p.compute_integral_image() # build the contractor ctc = CtcPixelMap(p) X0 = IntervalVector([[-1, 4], [0, 3]]) vibes.drawBox(X0[0][0], X0[0][1], X0[1][0], X0[1][1], "b") ctc.contract(X0) vibes.drawBox(X0[0][0], X0[0][1], X0[1][0], X0[1][1], "r")
phi.set(interval, Interval(0, h / 2)) out.append(integrate_box(phi, v, theta, h / 2)) return union(out), out if __name__ == "__main__": h = 1 / 20 phi = Interval(-np.pi / 2, np.pi / 2) alpha = 0.01 deltat = 300 vibes.beginDrawing() vibes.newFigure("MagMap") vibes.setFigureProperties({ "x": 200, "y": 200, "width": 600, "height": 600 }) vibes.axisLimits(-h, deltat * h, -np.pi / 2, np.pi / 2) for k in range(deltat): v = Interval(1.0) theta = Interval(0.4 * np.sin(k / 20)) I, out = integrate(phi, alpha, v, theta, h) lb, ub = I.lb(), I.ub() vibes.drawBox(k * h, (k + 1) * h, lb, ub, "darkCyan[darkCyan]") phi = Interval(lb, ub)
def main(stdscr): # Clear screen stdscr.clear() stdscr.keypad(1) begin_x = 20 begin_y = 7 height = 5 width = 40 win = curses.newwin(height, width, begin_y, begin_x) stdscr.addstr(0, 10, "Hit 'space' to quit") stdscr.refresh() cpt = 0 key = '' x = Interval(1, 1.5) y = Interval(2, 3) dth = Interval.HALF_PI.mid() / 32. th = Interval(0).inflate(2 * dth) Interval.__str__ = print2 fout = open("test.txt", "a") fout.write("#================ RUN ===============\n") while key != ord(' '): key = stdscr.getch() lower_key = chr(key).lower() if lower_key == 'z': y += 0.5 if curses.ascii.isupper(key) else 0.1 elif lower_key == 's': y -= 0.5 if curses.ascii.isupper(key) else 0.1 elif lower_key == 'd': x += 0.5 if curses.ascii.isupper(key) else 0.1 elif lower_key == 'q': x -= 0.5 if curses.ascii.isupper(key) else 0.1 elif lower_key == 'a': th += dth / 8. if curses.ascii.isupper(key) else dth elif lower_key == 'e': th -= dth / 8. if curses.ascii.isupper(key) else dth elif key == curses.KEY_NPAGE: th = th.lb() + (Interval(0, th.diam() - dth) | Interval(0)) elif key == curses.KEY_PPAGE: th = th.lb() + (Interval(0, th.diam() + dth) | Interval(0)) elif key == curses.KEY_RIGHT: x = x.lb() + (Interval(0, x.diam() + 1) | Interval(0)) elif key == curses.KEY_LEFT: x = x.lb() + (Interval(0, x.diam() - 1) | Interval(0)) elif key == curses.KEY_UP: y = y.lb() + (Interval(0, y.diam() + 1) | Interval(0)) elif key == curses.KEY_DOWN: y = y.lb() + (Interval(0, y.diam() - 1) | Interval(0)) # # # if curses.ascii.ascii(key) == "a": # # if key == curses.KEY_UP or key == 566: # y += 0.5 if key==566 else 0.1 # elif key == curses.KEY_DOWN or key == 525: # y -= 0.5 if key==525 else 0.1 # elif key == curses.KEY_RIGHT or key == 560: # x += 0.5 if key==560 else 0.1 # elif key == curses.KEY_LEFT or key == 545: # x -= 0.5 if key==545 else 0.1 # elif key == ord('a') or key == 1: # th += 0.1 if key==1 else 0.05 # elif key == ord('e') or key == 5: # th -= 0.1 if key==5 else 0.05 # # elif key == ord('A'): # th = th.lb() + (Interval(0,th.diam()-0.1) | Interval(0)) # elif key == ord('E'): # th = th.lb() + (Interval(0,th.diam()+0.1) | Interval(0)) # elif key == ord('z'): # x = x.lb() + (Interval(0,x.diam()+1) | Interval(0)) # elif key == ord('s'): # x = x.lb() + (Interval(0,x.diam()-1) | Interval(0)) # elif key == ord('d'): # y = y.lb() + (Interval(0,y.diam()+1) | Interval(0)) # elif key == ord('q'): # y = y.lb() + (Interval(0,y.diam()-1) | Interval(0)) elif key == ord('R'): x = Interval(1, 1.5) y = Interval(2, 3) th = Interval(0).inflate(1) xx, yy, thh = Catan2(x, y, Interval(th)) # print(event.Key, event.Ascii, th, thh) # print(x, y, th ) vibes.clearFigure() vibes.drawBox(x[0], x[1], y[0], y[1], 'r') vibes.drawPie((0, 0), (1e-5, 5), th * 180. / math.pi, "r") vibes.drawPie((0, 0), (1e-5, 5), thh * 180. / math.pi, "b") vibes.drawBox(xx[0], xx[1], yy[0], yy[1], 'b') # if key in actions: # x, y, th = actions[key]( x,y,th ) # fct = actions.get(key, lambda x,y,th:x,y,th) stdscr.clear() stdscr.addstr(1, 10, "Pressed %s %d" % (lower_key, key)) stdscr.addstr(1, 25, str(curses.ascii.ctrl(key))) stdscr.addstr(1, 40, str(curses.ascii.ascii(key))) stdscr.addstr(1, 40, str(curses.ascii.alt(key))) stdscr.addstr(3, 20, "x : %s\t\t%s" % (x, xx)) stdscr.addstr(4, 20, "y : %s\t\t%s" % (y, yy)) stdscr.addstr(5, 20, "theta : %s\t\t%s" % (th, thh)) if key == ord("t"): fout.write("%s %s %s -> %s %s %s\n" % (x, y, th, xx, yy, thh)) stdscr.refresh() curses.endwin() fout.write("#===================== END ===============\n")
vibes.drawBox(xx[0], xx[1], yy[0], yy[1], 'b') # if key in actions: # x, y, th = actions[key]( x,y,th ) # fct = actions.get(key, lambda x,y,th:x,y,th) stdscr.clear() stdscr.addstr(1, 10, "Pressed %s %d" % (lower_key, key)) stdscr.addstr(1, 25, str(curses.ascii.ctrl(key))) stdscr.addstr(1, 40, str(curses.ascii.ascii(key))) stdscr.addstr(1, 40, str(curses.ascii.alt(key))) stdscr.addstr(3, 20, "x : %s\t\t%s" % (x, xx)) stdscr.addstr(4, 20, "y : %s\t\t%s" % (y, yy)) stdscr.addstr(5, 20, "theta : %s\t\t%s" % (th, thh)) if key == ord("t"): fout.write("%s %s %s -> %s %s %s\n" % (x, y, th, xx, yy, thh)) stdscr.refresh() curses.endwin() fout.write("#===================== END ===============\n") if __name__ == '__main__': vibes.beginDrawing() vibes.newFigure("Debut Catan2") vibes.setFigureSize(500, 500) vibes.drawBox(-5, 5, -5, 5) vibes.axisAuto() wrapper(main)