function modify_conn( path) load( '-mat', path, 'x','y','conn', 'N', 'rotim') % makes conn the right size % in case some tiles were added since last time conn(N, 6) = 0; figure(2) hold on % add / remove connections--------------------------------------------- title 'LEFT click = add connection, RIGHT click = remove connection, CENTER = exit / pause' disp( 'click on two tiles, then enter the direction of connection') disp( '[1] right' ) disp( '[2] lower right' ) disp( '[3] lower left' ) disp( '[4] left' ) disp( '[5] upper left' ) disp( '[6] upper right' ) disp( 'to zoom or pan, first pause, then adjust while paused') cont = 'y'; while cont ~= 'q' % get first point from user click [x1,y1,button] = ginput(1); n1 = findclosest(x,y, floor(x1), floor(y1)); plot(x(n1), y(n1),'go') % add connection if button == 1 % get second point from user click [x2,y2] = ginput(1); n2 = findclosest(x,y, floor(x2), floor(y2)); plot(x(n2),y(n2),'go') type = 7; while type < 0 | type > 6 type = input( 'choose connection type [1-6] 0 = cancel: '); if type < 0 | type > 6 disp ( 'try again!' ) end end if type ~= 0 % reverse the click order if type > 3 temp = n1; n1 = n2; n2 = temp; type = type - 3; end % store new connection % writes over old connection if user chooses to % writing over connections can lead to odd results cont = 'y'; if( conn(n1, type) ~= 0 | conn(n2, type+3) ~= 0 ) cont = input('overwrite current connection? [y/n]','s') end if cont == 'y' conn(n1, type) = n2; conn(n2, type+3) = n1; if type == 1 clr = 'y-'; elseif type == 2 clr = 'm-'; else clr = 'c-'; end plot( [x(n1),x(n2)],[y(n1), y(n2)],clr ) else disp( 'connection not overwritten') end end % remove connection elseif button == 3 type = 0; while type < 1 | type > 6 type = input( 'choose connection type [1-6]: '); if type < 1 | type > 6 disp ( 'try again!' ) end end n2 = conn(n1,type); if n2 == 0 disp( 'there was no connection to break') else conn(n1,type) = 0; if type < 4 conn(n2, type+3) = 0; else conn(n2, type-3) = 0; end plot( [x(n1),x(n2)],[y(n1), y(n2)],'r--' ) end % pause or exit else cont = input( '[p]ause [q]uit [r]eplot: ','s'); if cont == 'r' figure(1) imagesc(rotim) colormap gray plotconn( x,y,conn, N, 'b-*' ) hold on plot(x,y,'b*') elseif cont ~= 'q' pause; end end end % fill in isolated missing connections again conn = fillinconn(conn, N,x,y, true); hold off save( path, 'conn', '-mat', '-append');