Daniel@0: function varargout=som_select(c_vect,plane_h,arg) Daniel@0: Daniel@0: %SOM_SELECT Manual selection of map units from a visualization. Daniel@0: % Daniel@0: % som_select(c_vect,[plane_h]) Daniel@0: % Daniel@0: % som_select(3) Daniel@0: % som_select(sM.labels(:,1)) Daniel@0: % Daniel@0: % Input arguments ([]'s are optional): Daniel@0: % c_vect (scalar) number of classes Daniel@0: % (vector) initial class identifiers Daniel@0: % (cell array) of strings, class names Daniel@0: % (matrix) size * x 3, the color of each class Daniel@0: % [plane_h] (scalar) handle of the plane (axes) to be marked. Daniel@0: % By default, the current axes is used (GCA). Daniel@0: % For the function to work, the plot in the Daniel@0: % axes must have been created with the Daniel@0: % SOM_CPLANE function (or SOM_SHOW). Daniel@0: % Daniel@0: % Launches a GUI which allows user to select nodes from plane by Daniel@0: % clicking them or by choosing a region (a polygon). Daniel@0: % Daniel@0: % Middle mouse button: selects (or clears selection of) a single node Daniel@0: % Left mouse button: lets user draw a polygon Daniel@0: % Right mouse button: selects (or clears selection of) the units Daniel@0: % inside the polygon Daniel@0: % Daniel@0: % From the GUI, the color (class) is selected as well as whether Daniel@0: % but buttons select or clear the selection from the units. The Daniel@0: % buttons on the bottom have the following actions: Daniel@0: % Daniel@0: % 'OK' Assigns the class identifiers to the 'ans' variable in Daniel@0: % workspace. The value is an array of class identifiers: Daniel@0: % strings (cellstr) if the c_vect was an array of Daniel@0: % strings, a vector otherwise. Daniel@0: % 'Clear' Removes marks from the plane. Daniel@0: % 'Close' Closes the application. Daniel@0: % Daniel@0: % See also SOM_SHOW, SOM_CPLANE. Daniel@0: Daniel@0: % Contributed to SOM Toolbox vs2, February 2nd, 2000 by Juha Parhankangas Daniel@0: % Copyright (c) by Juha Parhankangas Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Juha Parhankangas 050100, juuso 010200 Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% input arguments Daniel@0: Daniel@0: if nargin < 2, plane_h = gca; end Daniel@0: if(isempty(gcbo)), arg='start'; end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% action Daniel@0: Daniel@0: switch arg Daniel@0: case 'start' Daniel@0: patch_h=find_patch(plane_h); Daniel@0: lattice=getfield(size(get(patch_h,'XData')),{1}); Daniel@0: msize(1)=floor(getfield(get(plane_h,'YLim'),{2})); Daniel@0: msize(2)=floor(getfield(get(plane_h,'XLim'),{2})-0.5); Daniel@0: if lattice==6 Daniel@0: lattice='hexa'; Daniel@0: else Daniel@0: lattice='rect'; Daniel@0: end Daniel@0: Daniel@0: if any(strcmp(get(patch_h,'Tag'),{'planeBar','planePie'})) Daniel@0: tmp_dim=size(get(patch_h,'XData'),2)/prod(msize); Daniel@0: tmp_xdata=get(patch_h,'XData'); Daniel@0: tmp_x=tmp_xdata(:,(msize(1)*(msize(2)-1)+2)*tmp_dim); Daniel@0: if floor(tmp_x(1)) ~= round(tmp_x(1)) Daniel@0: lattice = 'hexa'; Daniel@0: else Daniel@0: lattice = 'rect'; Daniel@0: end Daniel@0: elseif strcmp(get(patch_h,'Tag'),'planePlot') Daniel@0: tmp_lines_h=get(gca,'Children'); Daniel@0: test_x=mean(get(tmp_lines_h(2),'XData')); Daniel@0: if round(test_x) ~= floor(test_x) Daniel@0: lattice = 'hexa'; Daniel@0: else Daniel@0: lattice = 'rect'; Daniel@0: end Daniel@0: form=0.5*vis_patch('hexa'); Daniel@0: l = size(form,1); Daniel@0: Daniel@0: nx = repmat(form(:,1),1,prod(msize)); Daniel@0: ny = repmat(form(:,2),1,prod(msize)); Daniel@0: Daniel@0: x=reshape(repmat(1:msize(2),l*msize(1),1),l,prod(msize)); Daniel@0: y=repmat(repmat(1:msize(1),l,1),1,msize(2)); Daniel@0: Daniel@0: if strcmp(lattice,'hexa') Daniel@0: t = find(~rem(y(1,:),2)); Daniel@0: x(:,t)=x(:,t)+.5; Daniel@0: end Daniel@0: x=x+nx; Daniel@0: y=y+ny; Daniel@0: Daniel@0: colors=reshape(ones(prod(msize),1)*[NaN NaN NaN],... Daniel@0: [1 prod(msize) 3]); Daniel@0: v=caxis; Daniel@0: patch_h=patch(x,y,colors,... Daniel@0: 'EdgeColor','none',... Daniel@0: 'ButtonDownFcn',... Daniel@0: 'som_select([],[],''click'')',... Daniel@0: 'Tag','planePlot'); Daniel@0: set([gca gcf],'ButtonDownFcn','som_select([],[],''click'')'); Daniel@0: caxis(v) Daniel@0: end Daniel@0: Daniel@0: c_colors = []; Daniel@0: if iscell(c_vect) Daniel@0: [c_vect,c_names,c_classes]=class2num(c_vect); Daniel@0: if length(c_classes)1), Daniel@0: c_colors = c_vect; Daniel@0: c_names = 1:size(c_vect,1); Daniel@0: c_vect = size(c_vect,1); Daniel@0: c_classes = zeros(prod(msize),1); Daniel@0: elseif length(c_vect)==prod(msize), Daniel@0: c_classes = c_vect; Daniel@0: u = unique(c_classes(isfinite(c_classes) & c_classes>0)); Daniel@0: c_names = u; Daniel@0: c_vect = length(u); Daniel@0: elseif length(c_vect)>1, Daniel@0: c_names = c_vect; Daniel@0: c_vect = length(c_vect); Daniel@0: c_classes = zeros(prod(msize),1); Daniel@0: elseif length(c_vect)==1, Daniel@0: c_names = 1:c_vect; Daniel@0: c_classes = zeros(prod(msize),1); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: udata.lattice=lattice; Daniel@0: udata.patch_h=patch_h; Daniel@0: udata.plane_h=plane_h; Daniel@0: udata.type=get(udata.patch_h,'Tag'); Daniel@0: udata.msize=msize; Daniel@0: set(patch_h,'UserData',udata); Daniel@0: if strcmp(udata.type,'planePlot') Daniel@0: set([gca gcf],'UserData',udata); Daniel@0: end Daniel@0: str=cat(2,'som_select([],[],''click'')'); Daniel@0: set(patch_h,'ButtonDownFcn',str); Daniel@0: Daniel@0: draw_colorselection(c_names,c_colors); Daniel@0: tmp_data=findobj(get(0,'Children'),'Tag','SELECT_GUI'); Daniel@0: tmp_data=get(tmp_data,'UserData'); Daniel@0: tmp_data.c_names=c_names; Daniel@0: tmp_data.mat=reshape(c_classes,msize); Daniel@0: tmp_data.patch_h=patch_h; Daniel@0: tmp_data.plane_h=plane_h; Daniel@0: tmp_data.type=get(udata.patch_h,'Tag'); Daniel@0: tmp_data.lattice=lattice; Daniel@0: tmp_data.coords=[]; Daniel@0: tmp_data.poly_h=[]; Daniel@0: tmp_data.msize=msize; Daniel@0: tmp_data.mode='select'; Daniel@0: set(tmp_data.fig_h,'UserData',tmp_data); Daniel@0: draw_classes; Daniel@0: Daniel@0: case 'click' Daniel@0: switch get(gcf,'SelectionType') Daniel@0: case 'open' Daniel@0: return; Daniel@0: case {'normal','alt'} Daniel@0: draw_poly; Daniel@0: case 'extend' Daniel@0: click; Daniel@0: end Daniel@0: case 'choose' Daniel@0: draw_colorselection(0,0,'choose'); Daniel@0: case 'close' Daniel@0: close_gui; Daniel@0: case 'clear' Daniel@0: clear_plane; Daniel@0: case 'rb' Daniel@0: rb_control; Daniel@0: case 'ret_mat' Daniel@0: gui=findobj(get(0,'Children'),'Tag','SELECT_GUI'); Daniel@0: gui=get(gui,'UserData'); Daniel@0: mat=reshape(gui.mat,prod(size(gui.mat)),1); Daniel@0: if ~isempty(gui.c_names) Daniel@0: if isnumeric(gui.c_names), tmp=zeros(length(mat),1); Daniel@0: else tmp=cell(length(mat),1); Daniel@0: end Daniel@0: for i=1:length(gui.c_names) Daniel@0: inds=find(mat==i); Daniel@0: tmp(inds)=gui.c_names(i); Daniel@0: end Daniel@0: mat=tmp; Daniel@0: end Daniel@0: varargout{1}=mat; Daniel@0: %gui.mat=zeros(size(gui.mat)); Daniel@0: %set(gui.fig_h,'UserData',gui); Daniel@0: %h=findobj(get(gui.plane_h,'Children'),'Tag','SEL_PATCH'); Daniel@0: %delete(h); Daniel@0: end Daniel@0: Daniel@0: return; Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% subfunctions Daniel@0: Daniel@0: function rb_control; Daniel@0: Daniel@0: h=findobj(get(gcf,'Children'),'Style','radiobutton'); Daniel@0: set(h,'Value',0); Daniel@0: set(gcbo,'Value',1); Daniel@0: Daniel@0: udata=get(gcf,'UserData'); Daniel@0: if strcmp(get(gcbo,'Tag'),'Radiobutton1') Daniel@0: udata.mode='select'; Daniel@0: else Daniel@0: udata.mode='clear'; Daniel@0: end Daniel@0: Daniel@0: set(gcf,'UserData',udata); Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function clear_plane Daniel@0: Daniel@0: h=findobj(get(0,'Children'),'Tag','SELECT_GUI'); Daniel@0: gui=get(h,'UserData'); Daniel@0: Daniel@0: if strcmp(get(gui.patch_h,'Tag'),'planePlot') Daniel@0: colors=reshape(get(gui.patch_h,'FaceVertexCData'),[prod(gui.msize) 3]); Daniel@0: colors(:,:)=NaN; Daniel@0: set(gui.patch_h,'FaceVertexCData',colors); Daniel@0: end Daniel@0: Daniel@0: h=findobj(get(gui.plane_h,'Children'),'Tag','SEL_PATCH'); Daniel@0: gui.mat=zeros(gui.msize); Daniel@0: set(gui.fig_h,'UserData',gui); Daniel@0: delete(h); Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function click Daniel@0: Daniel@0: udata=get(gcbo,'UserData'); Daniel@0: Daniel@0: udata=get(udata.patch_h,'UserData'); Daniel@0: coords=get(gca,'CurrentPoint'); Daniel@0: row=round(coords(1,2)); Daniel@0: if row > udata.msize(1), row = udata.msize(1); end Daniel@0: if row < 1, row = 1; end Daniel@0: if any(strcmp(udata.lattice,{'hexa','hexaU'})) & ~mod(row,2), Daniel@0: col=floor(coords(1,1))+0.5; Daniel@0: if col > udata.msize(2)+0.5, col=udata.msize(2)+0.5; end Daniel@0: else Daniel@0: col=round(coords(1,1)); Daniel@0: if col > udata.msize(2), col=udata.msize(2); end Daniel@0: end Daniel@0: if col < 1, col = 1; end Daniel@0: Daniel@0: if strcmp(udata.type,'planePlot') Daniel@0: Daniel@0: if ~mod(row,2) & strcmp(udata.lattice,'hexa'), col=round(col-0.5); end Daniel@0: Daniel@0: ind=sub2ind(udata.msize,row,col); Daniel@0: colors=reshape(get(udata.patch_h,'FaceVertexCData'),[prod(udata.msize) 3]); Daniel@0: gui=findobj(get(0,'Children'),'Tag','SELECT_GUI'); Daniel@0: gui=get(gui,'UserData'); Daniel@0: Daniel@0: if ~isempty(gui.curr_col) & all(~isnan(colors(ind,1,:))), Daniel@0: if ~strcmp(gui.mode,'clear') & ~all(gui.curr_col == colors(ind,:)) Daniel@0: colors(ind,:)=gui.curr_col; Daniel@0: gui.mat(row,col)=gui.class; Daniel@0: else Daniel@0: colors(ind,:)=[NaN NaN NaN]; Daniel@0: gui.mat(row,col)=0; Daniel@0: end Daniel@0: elseif strcmp(gui.mode,'clear') Daniel@0: colors(ind,:)=[NaN NaN NaN]; Daniel@0: gui.mat(row,col)=0; Daniel@0: elseif isempty(gui.curr_col) Daniel@0: return; Daniel@0: else Daniel@0: gui.mat(row,col)=gui.class; Daniel@0: colors(ind,:)=gui.curr_col; Daniel@0: end Daniel@0: set(udata.patch_h,'FaceVertexCData',colors); Daniel@0: set(gui.fig_h,'UserData',gui); Daniel@0: return; Daniel@0: end Daniel@0: Daniel@0: if any(strcmp(udata.type,{'planePie','planeBar'})) Daniel@0: [x,y]=pol2cart(0:0.1:2*pi,0.5); Daniel@0: coords=[x';0.5]*0.7; Daniel@0: coords(:,2)=[y';0]*0.7; Daniel@0: elseif strcmp(udata.lattice,'hexa'); Daniel@0: coords=0.7*vis_patch('hexa'); Daniel@0: else Daniel@0: coords=0.7*vis_patch('rect'); Daniel@0: end Daniel@0: coords(:,1)=coords(:,1)+col; Daniel@0: coords(:,2)=coords(:,2)+row; Daniel@0: if ~mod(row,2) & strcmp(udata.lattice,'hexa'), col=round(col-0.5); end Daniel@0: Daniel@0: hold on; Daniel@0: if gco == udata.patch_h Daniel@0: gui=findobj(get(0,'Children'),'Tag','SELECT_GUI'); Daniel@0: gui=get(gui,'UserData'); Daniel@0: if isnan(gui.curr_col) | strcmp(gui.mode,'clear'), return; end Daniel@0: h=fill(coords(:,1),coords(:,2),gui.curr_col); Daniel@0: str=cat(2,'som_select([],[],''click'')'); Daniel@0: set(h,'ButtonDownFcn',str,'Tag','SEL_PATCH'); Daniel@0: tmp.patch_h=udata.patch_h; Daniel@0: set(h,'UserData',tmp); Daniel@0: gui.mat(row,col)=gui.class; Daniel@0: set(gui.fig_h,'UserData',gui); Daniel@0: else Daniel@0: gui=findobj(get(0,'Children'),'Tag','SELECT_GUI'); Daniel@0: gui=get(gui,'UserData'); Daniel@0: if ~all(get(gcbo,'FaceColor') == gui.curr_col) & ~strcmp(gui.mode,'clear'), Daniel@0: if ~isnan(gui.curr_col), Daniel@0: set(gcbo,'FaceColor',gui.curr_col); Daniel@0: gui.mat(row,col) = gui.class; Daniel@0: end Daniel@0: else Daniel@0: gui.mat(row,col)=0; Daniel@0: delete(gco); Daniel@0: end Daniel@0: set(gui.fig_h,'UserData',gui); Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function draw_colorselection(varargin) Daniel@0: Daniel@0: if length(varargin)==2, Daniel@0: Daniel@0: if length(varargin{1})==1, Daniel@0: n = varargin{1}; Daniel@0: names = 1:n; Daniel@0: else Daniel@0: n = length(varargin{1}); Daniel@0: names = varargin{1}; Daniel@0: end Daniel@0: colors = varargin{2}; Daniel@0: Daniel@0: shape=[0.5 -0.5;0.5 0.5;1.5 0.5;1.5 -0.5]; Daniel@0: rep_x=repmat(shape(:,1),1,n); Daniel@0: rep_y=repmat(shape(:,2),1,n); Daniel@0: for i=0:getfield(size(rep_y,2))-1, rep_x(:,i+1)=rep_x(:,i+1)+i; end Daniel@0: if isempty(colors), colors=jet(n); end Daniel@0: data=som_select_gui; Daniel@0: data.colors=colors; Daniel@0: data.curr_col=NaN; Daniel@0: data.class=0; Daniel@0: set(0,'CurrentFigure',data.fig_h); Daniel@0: hold on; Daniel@0: tmp=fill(rep_x,rep_y,0.8); Daniel@0: for i=1:n Daniel@0: set(tmp(i),... Daniel@0: 'EdgeColor',[0 0 0],... Daniel@0: 'FaceColor',colors(i,:),... Daniel@0: 'ButtonDownFcn','som_select([],0,''choose'');'); Daniel@0: end Daniel@0: axis('equal'); Daniel@0: axis('on'); Daniel@0: set(gca,'XTick',1:n,'XTickLabel',names,'XAxisLocation','top'); Daniel@0: set(data.a_h,'YLim',[-0.5,0.5],... Daniel@0: 'XLim',[0.5 n+0.5],... Daniel@0: 'YTickLabel',''); Daniel@0: set(data.fig_h,'UserData',data); Daniel@0: Daniel@0: elseif strcmp(varargin{3},'choose') Daniel@0: Daniel@0: udata=get(gcf,'UserData'); Daniel@0: if strcmp(get(gcbo,'Selected'),'off') Daniel@0: old=findobj(get(gca,'Children'),'Type','patch'); Daniel@0: set(old,'Selected','off'); Daniel@0: set(gcbo,'Selected','on'); Daniel@0: udata.curr_col=udata.colors(round(mean(get(gcbo,'XData'))),:); Daniel@0: udata.class=mean(get(gcbo,'XData')); Daniel@0: else Daniel@0: set(gcbo,'Selected','off'); Daniel@0: udata.curr_col=NaN; Daniel@0: udata.class=0; Daniel@0: end Daniel@0: set(gcf,'UserData',udata); Daniel@0: Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function data=som_select_gui() Daniel@0: Daniel@0: Daniel@0: a = figure('Color',[0.8 0.8 0.8], ... Daniel@0: 'PaperType','a4letter', ... Daniel@0: 'Position',[586 584 560 210], ... Daniel@0: 'Tag','SELECT_GUI'); Daniel@0: Daniel@0: data.fig_h=a; Daniel@0: Daniel@0: b = axes('Parent',a, ... Daniel@0: 'Box','on', ... Daniel@0: 'CameraUpVector',[0 1 0], ... Daniel@0: 'Color',[1 1 1], ... Daniel@0: 'DataAspectRatioMode','manual', ... Daniel@0: 'PlotBoxAspectRatio',[20 1 2], ... Daniel@0: 'PlotBoxAspectRatioMode','manual', ... Daniel@0: 'Position',[0.13 0.11 0.775 0.815], ... Daniel@0: 'Tag','Axes1', ... Daniel@0: 'WarpToFill','off', ... Daniel@0: 'XColor',[0 0 0], ... Daniel@0: 'XLimMode','manual', ... Daniel@0: 'YColor',[0 0 0], ... Daniel@0: 'YLimMode','manual', ... Daniel@0: 'YTickLabelMode','manual', ... Daniel@0: 'ZColor',[0 0 0]); Daniel@0: Daniel@0: data.a_h=b; Daniel@0: Daniel@0: b = uicontrol('Parent',a, ... Daniel@0: 'Units','points', ... Daniel@0: 'BackgroundColor',[0.701961 0.701961 0.701961], ... Daniel@0: 'Callback','som_select([],[],''close'')', ... Daniel@0: 'FontWeight','demi', ... Daniel@0: 'Position',[150 12 50 20], ... Daniel@0: 'String','CLOSE', ... Daniel@0: 'Tag','Pushbutton1'); Daniel@0: Daniel@0: b = uicontrol('Parent',a, ... Daniel@0: 'Units','points', ... Daniel@0: 'BackgroundColor',[0.701961 0.701961 0.701961], ... Daniel@0: 'Callback','som_select([],0,''ret_mat'')',... Daniel@0: 'FontWeight','demi', ... Daniel@0: 'Position',[365 12 50 20], ... Daniel@0: 'String','OK', ... Daniel@0: 'Tag','Pushbutton2'); Daniel@0: Daniel@0: b = uicontrol('Parent',a, ... Daniel@0: 'Units','points', ... Daniel@0: 'BackgroundColor',[0.701961 0.701961 0.701961], ... Daniel@0: 'Callback','som_select([],0,''clear'')',... Daniel@0: 'FontWeight','demi', ... Daniel@0: 'Position',[257.5 12 50 20], ... Daniel@0: 'String','CLEAR', ... Daniel@0: 'Tag','Pushbutton3'); Daniel@0: Daniel@0: b = uicontrol('Parent',a, ... Daniel@0: 'Units','points', ... Daniel@0: 'Position',[50 27 17 16], ... Daniel@0: 'Callback','som_select([],[],''rb'')',... Daniel@0: 'Style','radiobutton', ... Daniel@0: 'Tag','Radiobutton1', ... Daniel@0: 'Value',1); Daniel@0: b = uicontrol('Parent',a, ... Daniel@0: 'Units','points', ... Daniel@0: 'BackgroundColor',[0.701961 0.701961 0.701961], ... Daniel@0: 'Callback','som_select([],[],''rb'')',... Daniel@0: 'Position',[50 7 17 16], ... Daniel@0: 'Style','radiobutton', ... Daniel@0: 'Tag','Radiobutton2'); Daniel@0: b = uicontrol('Parent',a, ... Daniel@0: 'Units','points', ... Daniel@0: 'BackgroundColor',[0.8 0.8 0.8], ... Daniel@0: 'FontSize',9, ... Daniel@0: 'FontWeight','demi', ... Daniel@0: 'HorizontalAlignment','left', ... Daniel@0: 'Position',[72 25 28 15], ... Daniel@0: 'String','Select', ... Daniel@0: 'Style','text', ... Daniel@0: 'Tag','StaticText1'); Daniel@0: b = uicontrol('Parent',a, ... Daniel@0: 'Units','points', ... Daniel@0: 'BackgroundColor',[0.8 0.8 0.8], ... Daniel@0: 'FontSize',9, ... Daniel@0: 'FontWeight','demi', ... Daniel@0: 'HorizontalAlignment','left', ... Daniel@0: 'Position',[72 7 25 13.6], ... Daniel@0: 'String','Clear', ... Daniel@0: 'Style','text', ... Daniel@0: 'Tag','StaticText2'); Daniel@0: Daniel@0: Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function close_gui Daniel@0: Daniel@0: udata=get(get(gcbo,'Parent'),'UserData'); Daniel@0: Daniel@0: if strcmp(udata.type,'planePlot'); Daniel@0: set(udata.plane_h,'ButtonDownFcn','','UserData',[]); Daniel@0: set(get(udata.plane_h,'Parent'),'ButtonDownFcn',''); Daniel@0: delete(udata.patch_h); Daniel@0: return; Daniel@0: end Daniel@0: Daniel@0: h=findobj(get(udata.plane_h,'Children'),'Tag','SEL_PATCH'); Daniel@0: set(udata.patch_h,'ButtonDownFcn','','UserData',[]); Daniel@0: delete(h); Daniel@0: close(udata.fig_h); Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function draw_poly Daniel@0: Daniel@0: udata=get(findobj(get(0,'Children'),'Tag','SELECT_GUI'),'UserData'); Daniel@0: Daniel@0: if isempty(udata.coords) & strcmp(get(gcf,'SelectionType'),'alt') Daniel@0: return; Daniel@0: end Daniel@0: Daniel@0: coords(1,1) = getfield(get(gca,'CurrentPoint'),{3}); Daniel@0: coords(1,2) = getfield(get(gca,'CurrentPoint'),{1}); Daniel@0: udata.coords = cat(1,udata.coords,coords); Daniel@0: delete(udata.poly_h); Daniel@0: subplot(udata.plane_h); Daniel@0: Daniel@0: hold on; Daniel@0: switch get(gcf,'SelectionType'); Daniel@0: case 'normal' Daniel@0: udata.poly_h=plot(udata.coords(:,2),udata.coords(:,1),'black',... Daniel@0: 'ButtonDownFcn','som_select([],[],''click'')',... Daniel@0: 'LineWidth',2); Daniel@0: set(udata.fig_h,'UserData',udata); Daniel@0: case 'alt' Daniel@0: udata.coords=cat(1,udata.coords,udata.coords(1,:)); Daniel@0: udata.poly_h=plot(udata.coords(:,2),udata.coords(:,1),'black',... Daniel@0: 'LineWidth',2); Daniel@0: delete(udata.poly_h); Daniel@0: if ~isnan(udata.curr_col) Daniel@0: tmp=sort(repmat((1:udata.msize(1))',udata.msize(2),1)); Daniel@0: tmp(:,2)=repmat((1:udata.msize(2))',udata.msize(1),1); Daniel@0: tmp2=tmp; Daniel@0: if strcmp(udata.type,'planePlot') Daniel@0: in=find(inpolygon(tmp(:,2),tmp(:,1),... Daniel@0: udata.coords(:,2),udata.coords(:,1))); Daniel@0: row=tmp2(in,1); Daniel@0: col=tmp2(in,2); Daniel@0: in=sub2ind(udata.msize,row,col); Daniel@0: colors=reshape(get(udata.patch_h,'FaceVertexCData'),... Daniel@0: [prod(udata.msize) 3]); Daniel@0: if ~isnan(udata.curr_col) & ~strcmp(udata.mode,'clear') Daniel@0: colors(in,:)=ones(length(in),1)*udata.curr_col; Daniel@0: udata.mat(row,col)=udata.class; Daniel@0: elseif strcmp(udata.mode,'clear') Daniel@0: colors(in,:)=[NaN NaN NaN]; Daniel@0: udata.mat(row,col)=0; Daniel@0: end Daniel@0: udata.poly_h=[]; Daniel@0: udata.coords=[]; Daniel@0: set(udata.patch_h,'FaceVertexCData',colors); Daniel@0: set(udata.fig_h,'UserData',udata); Daniel@0: return; Daniel@0: end Daniel@0: if strcmp(udata.lattice,'hexa'); Daniel@0: t=find(~rem(tmp(:,1),2)); Daniel@0: tmp(t,2)=tmp(t,2)+0.5; Daniel@0: if any(strcmp(get(udata.patch_h,'Tag'),{'planeC','planeU'})) Daniel@0: p=0.7*vis_patch('hexa'); Daniel@0: else Daniel@0: [x,y]=pol2cart(0:0.1:2*pi,0.5); Daniel@0: p=[x';0.5]*0.7; Daniel@0: p(:,2)=[y';0]*0.7; Daniel@0: end Daniel@0: else Daniel@0: if any(strcmp(get(udata.patch_h,'Tag'),{'planeC','planeU'})) Daniel@0: p=0.7*vis_patch('rect'); Daniel@0: else Daniel@0: [x,y]=pol2cart(0:0.1:2*pi,0.5); Daniel@0: p=[x';0.5]*0.7; Daniel@0: p(:,2)=[y';0]*0.7; Daniel@0: end Daniel@0: end Daniel@0: in=find(inpolygon(tmp(:,2),tmp(:,1),udata.coords(:,2),udata.coords(:,1))); Daniel@0: set(udata.fig_h,'UserData',udata); Daniel@0: if strcmp(udata.mode,'select') Daniel@0: remove_selpatches; Daniel@0: udata=get(udata.fig_h,'UserData'); Daniel@0: for i=1:length(in) Daniel@0: udat.patch_h=udata.patch_h; Daniel@0: h=patch(p(:,1)+tmp(in(i),2),p(:,2)+tmp(in(i),1),... Daniel@0: udata.curr_col,... Daniel@0: 'EdgeColor','black',... Daniel@0: 'ButtonDownFcn','som_select([],[],''click'')', ... Daniel@0: 'Tag','SEL_PATCH',... Daniel@0: 'UserData',udat); Daniel@0: udata.mat(tmp2(in(i),1),tmp2(in(i),2))=udata.class; Daniel@0: end Daniel@0: else Daniel@0: remove_selpatches; Daniel@0: udata=get(udata.fig_h,'UserData'); Daniel@0: %h=findobj(get(udata.plane_h,'Children'),'Tag','SEL_PATCH'); Daniel@0: %for i=1:length(h) Daniel@0: % if all(get(h(i),'FaceColor')==udata.curr_col) & ... Daniel@0: % inpolygon(mean(get(h(i),'XData')),mean(get(h(i),'YData')),... Daniel@0: % udata.coords(:,2),udata.coords(:,1)) Daniel@0: % coords=[floor(mean(get(h(i),'YData')))... Daniel@0: % floor(mean(get(h(i),'XData')))]; Daniel@0: % udata.mat(coords(1),coords(2))=0; Daniel@0: % delete(h(i)); Daniel@0: % end Daniel@0: %end Daniel@0: end Daniel@0: end Daniel@0: udata.poly_h=[]; Daniel@0: udata.coords=[]; Daniel@0: set(udata.fig_h,'UserData',udata); Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function remove_selpatches Daniel@0: Daniel@0: udata=get(findobj(get(0,'Children'),'Tag','SELECT_GUI'),'UserData'); Daniel@0: h=findobj(get(udata.plane_h,'Children'),'Tag','SEL_PATCH'); Daniel@0: for i=1:length(h) Daniel@0: if inpolygon(mean(get(h(i),'XData')),mean(get(h(i),'YData')),... Daniel@0: udata.coords(:,2),udata.coords(:,1)); Daniel@0: coords=[floor(mean(get(h(i),'YData')))... Daniel@0: floor(mean(get(h(i),'XData')))]; Daniel@0: udata.mat(coords(1),coords(2))=0; Daniel@0: delete(h(i)); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: set(udata.fig_h,'UserData',udata); Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function [n,names,classes]=class2num(class) Daniel@0: Daniel@0: names = {}; Daniel@0: classes = zeros(length(class),1); Daniel@0: for i=1:length(class) Daniel@0: if ~isempty(class{i}), Daniel@0: a = find(strcmp(class{i},names)); Daniel@0: if isempty(a), Daniel@0: names=cat(1,names,class(i)); Daniel@0: classes(i) = length(names); Daniel@0: else Daniel@0: classes(i) = a; Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: n=length(names); Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function h=find_patch(a_h) Daniel@0: Daniel@0: h=[]; Daniel@0: Daniel@0: tags={'planeC','planeU','planePie','planeBar','planePlot'}; Daniel@0: Daniel@0: for i=1:5 Daniel@0: if ~isempty(findobj(get(a_h,'Children'),'Tag',tags{i})) Daniel@0: h=findobj(get(gca,'Children'),'Tag',tags{i}); Daniel@0: if length(h) > 1 Daniel@0: h=h(1); Daniel@0: end Daniel@0: return; Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function draw_classes Daniel@0: Daniel@0: udata=get(findobj(get(0,'Children'),'Tag','SELECT_GUI'), ... Daniel@0: 'UserData'); Daniel@0: figure(get(udata.plane_h,'Parent')) Daniel@0: subplot(udata.plane_h); Daniel@0: Daniel@0: colors=zeros(prod(udata.msize),3)+NaN; Daniel@0: c_map=jet(length(udata.c_names)); Daniel@0: inds = find(udata.mat); Daniel@0: for i=1:length(inds), Daniel@0: colors(inds(i),:) = c_map(udata.mat(inds(i)),:); Daniel@0: end Daniel@0: Daniel@0: if strcmp(udata.type,'planePlot'), Daniel@0: Daniel@0: set(udata.patch_h,'FaceVertexCData',colors); Daniel@0: set(udata.fig_h,'UserData',udata); Daniel@0: Daniel@0: else Daniel@0: Daniel@0: hold on Daniel@0: co = som_vis_coords(udata.lattice,udata.msize); Daniel@0: if any(strcmp(get(udata.patch_h,'Tag'),{'planeC','planeU'})) Daniel@0: p=0.7*vis_patch(udata.lattice); Daniel@0: else Daniel@0: [x,y]=pol2cart(0:0.1:2*pi,0.5); Daniel@0: p=[x';0.5]*0.7; Daniel@0: p(:,2)=[y';0]*0.7; Daniel@0: end Daniel@0: for i=1:length(inds), Daniel@0: udat.patch_h=udata.patch_h; Daniel@0: h=patch(p(:,1)+co(inds(i),1),p(:,2)+co(inds(i),2),... Daniel@0: colors(inds(i),:),... Daniel@0: 'EdgeColor','black',... Daniel@0: 'ButtonDownFcn','som_select([],[],''click'')', ... Daniel@0: 'Tag','SEL_PATCH',... Daniel@0: 'UserData',udat); Daniel@0: end Daniel@0: Daniel@0: end Daniel@0: Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%