wolffd@0
|
1 function varargout=som_select(c_vect,plane_h,arg)
|
wolffd@0
|
2
|
wolffd@0
|
3 %SOM_SELECT Manual selection of map units from a visualization.
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % som_select(c_vect,[plane_h])
|
wolffd@0
|
6 %
|
wolffd@0
|
7 % som_select(3)
|
wolffd@0
|
8 % som_select(sM.labels(:,1))
|
wolffd@0
|
9 %
|
wolffd@0
|
10 % Input arguments ([]'s are optional):
|
wolffd@0
|
11 % c_vect (scalar) number of classes
|
wolffd@0
|
12 % (vector) initial class identifiers
|
wolffd@0
|
13 % (cell array) of strings, class names
|
wolffd@0
|
14 % (matrix) size * x 3, the color of each class
|
wolffd@0
|
15 % [plane_h] (scalar) handle of the plane (axes) to be marked.
|
wolffd@0
|
16 % By default, the current axes is used (GCA).
|
wolffd@0
|
17 % For the function to work, the plot in the
|
wolffd@0
|
18 % axes must have been created with the
|
wolffd@0
|
19 % SOM_CPLANE function (or SOM_SHOW).
|
wolffd@0
|
20 %
|
wolffd@0
|
21 % Launches a GUI which allows user to select nodes from plane by
|
wolffd@0
|
22 % clicking them or by choosing a region (a polygon).
|
wolffd@0
|
23 %
|
wolffd@0
|
24 % Middle mouse button: selects (or clears selection of) a single node
|
wolffd@0
|
25 % Left mouse button: lets user draw a polygon
|
wolffd@0
|
26 % Right mouse button: selects (or clears selection of) the units
|
wolffd@0
|
27 % inside the polygon
|
wolffd@0
|
28 %
|
wolffd@0
|
29 % From the GUI, the color (class) is selected as well as whether
|
wolffd@0
|
30 % but buttons select or clear the selection from the units. The
|
wolffd@0
|
31 % buttons on the bottom have the following actions:
|
wolffd@0
|
32 %
|
wolffd@0
|
33 % 'OK' Assigns the class identifiers to the 'ans' variable in
|
wolffd@0
|
34 % workspace. The value is an array of class identifiers:
|
wolffd@0
|
35 % strings (cellstr) if the c_vect was an array of
|
wolffd@0
|
36 % strings, a vector otherwise.
|
wolffd@0
|
37 % 'Clear' Removes marks from the plane.
|
wolffd@0
|
38 % 'Close' Closes the application.
|
wolffd@0
|
39 %
|
wolffd@0
|
40 % See also SOM_SHOW, SOM_CPLANE.
|
wolffd@0
|
41
|
wolffd@0
|
42 % Contributed to SOM Toolbox vs2, February 2nd, 2000 by Juha Parhankangas
|
wolffd@0
|
43 % Copyright (c) by Juha Parhankangas
|
wolffd@0
|
44 % http://www.cis.hut.fi/projects/somtoolbox/
|
wolffd@0
|
45
|
wolffd@0
|
46 % Juha Parhankangas 050100, juuso 010200
|
wolffd@0
|
47
|
wolffd@0
|
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
49 %% input arguments
|
wolffd@0
|
50
|
wolffd@0
|
51 if nargin < 2, plane_h = gca; end
|
wolffd@0
|
52 if(isempty(gcbo)), arg='start'; end
|
wolffd@0
|
53
|
wolffd@0
|
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
55 %% action
|
wolffd@0
|
56
|
wolffd@0
|
57 switch arg
|
wolffd@0
|
58 case 'start'
|
wolffd@0
|
59 patch_h=find_patch(plane_h);
|
wolffd@0
|
60 lattice=getfield(size(get(patch_h,'XData')),{1});
|
wolffd@0
|
61 msize(1)=floor(getfield(get(plane_h,'YLim'),{2}));
|
wolffd@0
|
62 msize(2)=floor(getfield(get(plane_h,'XLim'),{2})-0.5);
|
wolffd@0
|
63 if lattice==6
|
wolffd@0
|
64 lattice='hexa';
|
wolffd@0
|
65 else
|
wolffd@0
|
66 lattice='rect';
|
wolffd@0
|
67 end
|
wolffd@0
|
68
|
wolffd@0
|
69 if any(strcmp(get(patch_h,'Tag'),{'planeBar','planePie'}))
|
wolffd@0
|
70 tmp_dim=size(get(patch_h,'XData'),2)/prod(msize);
|
wolffd@0
|
71 tmp_xdata=get(patch_h,'XData');
|
wolffd@0
|
72 tmp_x=tmp_xdata(:,(msize(1)*(msize(2)-1)+2)*tmp_dim);
|
wolffd@0
|
73 if floor(tmp_x(1)) ~= round(tmp_x(1))
|
wolffd@0
|
74 lattice = 'hexa';
|
wolffd@0
|
75 else
|
wolffd@0
|
76 lattice = 'rect';
|
wolffd@0
|
77 end
|
wolffd@0
|
78 elseif strcmp(get(patch_h,'Tag'),'planePlot')
|
wolffd@0
|
79 tmp_lines_h=get(gca,'Children');
|
wolffd@0
|
80 test_x=mean(get(tmp_lines_h(2),'XData'));
|
wolffd@0
|
81 if round(test_x) ~= floor(test_x)
|
wolffd@0
|
82 lattice = 'hexa';
|
wolffd@0
|
83 else
|
wolffd@0
|
84 lattice = 'rect';
|
wolffd@0
|
85 end
|
wolffd@0
|
86 form=0.5*vis_patch('hexa');
|
wolffd@0
|
87 l = size(form,1);
|
wolffd@0
|
88
|
wolffd@0
|
89 nx = repmat(form(:,1),1,prod(msize));
|
wolffd@0
|
90 ny = repmat(form(:,2),1,prod(msize));
|
wolffd@0
|
91
|
wolffd@0
|
92 x=reshape(repmat(1:msize(2),l*msize(1),1),l,prod(msize));
|
wolffd@0
|
93 y=repmat(repmat(1:msize(1),l,1),1,msize(2));
|
wolffd@0
|
94
|
wolffd@0
|
95 if strcmp(lattice,'hexa')
|
wolffd@0
|
96 t = find(~rem(y(1,:),2));
|
wolffd@0
|
97 x(:,t)=x(:,t)+.5;
|
wolffd@0
|
98 end
|
wolffd@0
|
99 x=x+nx;
|
wolffd@0
|
100 y=y+ny;
|
wolffd@0
|
101
|
wolffd@0
|
102 colors=reshape(ones(prod(msize),1)*[NaN NaN NaN],...
|
wolffd@0
|
103 [1 prod(msize) 3]);
|
wolffd@0
|
104 v=caxis;
|
wolffd@0
|
105 patch_h=patch(x,y,colors,...
|
wolffd@0
|
106 'EdgeColor','none',...
|
wolffd@0
|
107 'ButtonDownFcn',...
|
wolffd@0
|
108 'som_select([],[],''click'')',...
|
wolffd@0
|
109 'Tag','planePlot');
|
wolffd@0
|
110 set([gca gcf],'ButtonDownFcn','som_select([],[],''click'')');
|
wolffd@0
|
111 caxis(v)
|
wolffd@0
|
112 end
|
wolffd@0
|
113
|
wolffd@0
|
114 c_colors = [];
|
wolffd@0
|
115 if iscell(c_vect)
|
wolffd@0
|
116 [c_vect,c_names,c_classes]=class2num(c_vect);
|
wolffd@0
|
117 if length(c_classes)<prod(msize),
|
wolffd@0
|
118 c_classes = zeros(prod(msize),1);
|
wolffd@0
|
119 end
|
wolffd@0
|
120 else
|
wolffd@0
|
121 if all(size(c_vect)>1),
|
wolffd@0
|
122 c_colors = c_vect;
|
wolffd@0
|
123 c_names = 1:size(c_vect,1);
|
wolffd@0
|
124 c_vect = size(c_vect,1);
|
wolffd@0
|
125 c_classes = zeros(prod(msize),1);
|
wolffd@0
|
126 elseif length(c_vect)==prod(msize),
|
wolffd@0
|
127 c_classes = c_vect;
|
wolffd@0
|
128 u = unique(c_classes(isfinite(c_classes) & c_classes>0));
|
wolffd@0
|
129 c_names = u;
|
wolffd@0
|
130 c_vect = length(u);
|
wolffd@0
|
131 elseif length(c_vect)>1,
|
wolffd@0
|
132 c_names = c_vect;
|
wolffd@0
|
133 c_vect = length(c_vect);
|
wolffd@0
|
134 c_classes = zeros(prod(msize),1);
|
wolffd@0
|
135 elseif length(c_vect)==1,
|
wolffd@0
|
136 c_names = 1:c_vect;
|
wolffd@0
|
137 c_classes = zeros(prod(msize),1);
|
wolffd@0
|
138 end
|
wolffd@0
|
139 end
|
wolffd@0
|
140
|
wolffd@0
|
141 udata.lattice=lattice;
|
wolffd@0
|
142 udata.patch_h=patch_h;
|
wolffd@0
|
143 udata.plane_h=plane_h;
|
wolffd@0
|
144 udata.type=get(udata.patch_h,'Tag');
|
wolffd@0
|
145 udata.msize=msize;
|
wolffd@0
|
146 set(patch_h,'UserData',udata);
|
wolffd@0
|
147 if strcmp(udata.type,'planePlot')
|
wolffd@0
|
148 set([gca gcf],'UserData',udata);
|
wolffd@0
|
149 end
|
wolffd@0
|
150 str=cat(2,'som_select([],[],''click'')');
|
wolffd@0
|
151 set(patch_h,'ButtonDownFcn',str);
|
wolffd@0
|
152
|
wolffd@0
|
153 draw_colorselection(c_names,c_colors);
|
wolffd@0
|
154 tmp_data=findobj(get(0,'Children'),'Tag','SELECT_GUI');
|
wolffd@0
|
155 tmp_data=get(tmp_data,'UserData');
|
wolffd@0
|
156 tmp_data.c_names=c_names;
|
wolffd@0
|
157 tmp_data.mat=reshape(c_classes,msize);
|
wolffd@0
|
158 tmp_data.patch_h=patch_h;
|
wolffd@0
|
159 tmp_data.plane_h=plane_h;
|
wolffd@0
|
160 tmp_data.type=get(udata.patch_h,'Tag');
|
wolffd@0
|
161 tmp_data.lattice=lattice;
|
wolffd@0
|
162 tmp_data.coords=[];
|
wolffd@0
|
163 tmp_data.poly_h=[];
|
wolffd@0
|
164 tmp_data.msize=msize;
|
wolffd@0
|
165 tmp_data.mode='select';
|
wolffd@0
|
166 set(tmp_data.fig_h,'UserData',tmp_data);
|
wolffd@0
|
167 draw_classes;
|
wolffd@0
|
168
|
wolffd@0
|
169 case 'click'
|
wolffd@0
|
170 switch get(gcf,'SelectionType')
|
wolffd@0
|
171 case 'open'
|
wolffd@0
|
172 return;
|
wolffd@0
|
173 case {'normal','alt'}
|
wolffd@0
|
174 draw_poly;
|
wolffd@0
|
175 case 'extend'
|
wolffd@0
|
176 click;
|
wolffd@0
|
177 end
|
wolffd@0
|
178 case 'choose'
|
wolffd@0
|
179 draw_colorselection(0,0,'choose');
|
wolffd@0
|
180 case 'close'
|
wolffd@0
|
181 close_gui;
|
wolffd@0
|
182 case 'clear'
|
wolffd@0
|
183 clear_plane;
|
wolffd@0
|
184 case 'rb'
|
wolffd@0
|
185 rb_control;
|
wolffd@0
|
186 case 'ret_mat'
|
wolffd@0
|
187 gui=findobj(get(0,'Children'),'Tag','SELECT_GUI');
|
wolffd@0
|
188 gui=get(gui,'UserData');
|
wolffd@0
|
189 mat=reshape(gui.mat,prod(size(gui.mat)),1);
|
wolffd@0
|
190 if ~isempty(gui.c_names)
|
wolffd@0
|
191 if isnumeric(gui.c_names), tmp=zeros(length(mat),1);
|
wolffd@0
|
192 else tmp=cell(length(mat),1);
|
wolffd@0
|
193 end
|
wolffd@0
|
194 for i=1:length(gui.c_names)
|
wolffd@0
|
195 inds=find(mat==i);
|
wolffd@0
|
196 tmp(inds)=gui.c_names(i);
|
wolffd@0
|
197 end
|
wolffd@0
|
198 mat=tmp;
|
wolffd@0
|
199 end
|
wolffd@0
|
200 varargout{1}=mat;
|
wolffd@0
|
201 %gui.mat=zeros(size(gui.mat));
|
wolffd@0
|
202 %set(gui.fig_h,'UserData',gui);
|
wolffd@0
|
203 %h=findobj(get(gui.plane_h,'Children'),'Tag','SEL_PATCH');
|
wolffd@0
|
204 %delete(h);
|
wolffd@0
|
205 end
|
wolffd@0
|
206
|
wolffd@0
|
207 return;
|
wolffd@0
|
208
|
wolffd@0
|
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
210 %% subfunctions
|
wolffd@0
|
211
|
wolffd@0
|
212 function rb_control;
|
wolffd@0
|
213
|
wolffd@0
|
214 h=findobj(get(gcf,'Children'),'Style','radiobutton');
|
wolffd@0
|
215 set(h,'Value',0);
|
wolffd@0
|
216 set(gcbo,'Value',1);
|
wolffd@0
|
217
|
wolffd@0
|
218 udata=get(gcf,'UserData');
|
wolffd@0
|
219 if strcmp(get(gcbo,'Tag'),'Radiobutton1')
|
wolffd@0
|
220 udata.mode='select';
|
wolffd@0
|
221 else
|
wolffd@0
|
222 udata.mode='clear';
|
wolffd@0
|
223 end
|
wolffd@0
|
224
|
wolffd@0
|
225 set(gcf,'UserData',udata);
|
wolffd@0
|
226
|
wolffd@0
|
227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
228
|
wolffd@0
|
229 function clear_plane
|
wolffd@0
|
230
|
wolffd@0
|
231 h=findobj(get(0,'Children'),'Tag','SELECT_GUI');
|
wolffd@0
|
232 gui=get(h,'UserData');
|
wolffd@0
|
233
|
wolffd@0
|
234 if strcmp(get(gui.patch_h,'Tag'),'planePlot')
|
wolffd@0
|
235 colors=reshape(get(gui.patch_h,'FaceVertexCData'),[prod(gui.msize) 3]);
|
wolffd@0
|
236 colors(:,:)=NaN;
|
wolffd@0
|
237 set(gui.patch_h,'FaceVertexCData',colors);
|
wolffd@0
|
238 end
|
wolffd@0
|
239
|
wolffd@0
|
240 h=findobj(get(gui.plane_h,'Children'),'Tag','SEL_PATCH');
|
wolffd@0
|
241 gui.mat=zeros(gui.msize);
|
wolffd@0
|
242 set(gui.fig_h,'UserData',gui);
|
wolffd@0
|
243 delete(h);
|
wolffd@0
|
244
|
wolffd@0
|
245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
246
|
wolffd@0
|
247 function click
|
wolffd@0
|
248
|
wolffd@0
|
249 udata=get(gcbo,'UserData');
|
wolffd@0
|
250
|
wolffd@0
|
251 udata=get(udata.patch_h,'UserData');
|
wolffd@0
|
252 coords=get(gca,'CurrentPoint');
|
wolffd@0
|
253 row=round(coords(1,2));
|
wolffd@0
|
254 if row > udata.msize(1), row = udata.msize(1); end
|
wolffd@0
|
255 if row < 1, row = 1; end
|
wolffd@0
|
256 if any(strcmp(udata.lattice,{'hexa','hexaU'})) & ~mod(row,2),
|
wolffd@0
|
257 col=floor(coords(1,1))+0.5;
|
wolffd@0
|
258 if col > udata.msize(2)+0.5, col=udata.msize(2)+0.5; end
|
wolffd@0
|
259 else
|
wolffd@0
|
260 col=round(coords(1,1));
|
wolffd@0
|
261 if col > udata.msize(2), col=udata.msize(2); end
|
wolffd@0
|
262 end
|
wolffd@0
|
263 if col < 1, col = 1; end
|
wolffd@0
|
264
|
wolffd@0
|
265 if strcmp(udata.type,'planePlot')
|
wolffd@0
|
266
|
wolffd@0
|
267 if ~mod(row,2) & strcmp(udata.lattice,'hexa'), col=round(col-0.5); end
|
wolffd@0
|
268
|
wolffd@0
|
269 ind=sub2ind(udata.msize,row,col);
|
wolffd@0
|
270 colors=reshape(get(udata.patch_h,'FaceVertexCData'),[prod(udata.msize) 3]);
|
wolffd@0
|
271 gui=findobj(get(0,'Children'),'Tag','SELECT_GUI');
|
wolffd@0
|
272 gui=get(gui,'UserData');
|
wolffd@0
|
273
|
wolffd@0
|
274 if ~isempty(gui.curr_col) & all(~isnan(colors(ind,1,:))),
|
wolffd@0
|
275 if ~strcmp(gui.mode,'clear') & ~all(gui.curr_col == colors(ind,:))
|
wolffd@0
|
276 colors(ind,:)=gui.curr_col;
|
wolffd@0
|
277 gui.mat(row,col)=gui.class;
|
wolffd@0
|
278 else
|
wolffd@0
|
279 colors(ind,:)=[NaN NaN NaN];
|
wolffd@0
|
280 gui.mat(row,col)=0;
|
wolffd@0
|
281 end
|
wolffd@0
|
282 elseif strcmp(gui.mode,'clear')
|
wolffd@0
|
283 colors(ind,:)=[NaN NaN NaN];
|
wolffd@0
|
284 gui.mat(row,col)=0;
|
wolffd@0
|
285 elseif isempty(gui.curr_col)
|
wolffd@0
|
286 return;
|
wolffd@0
|
287 else
|
wolffd@0
|
288 gui.mat(row,col)=gui.class;
|
wolffd@0
|
289 colors(ind,:)=gui.curr_col;
|
wolffd@0
|
290 end
|
wolffd@0
|
291 set(udata.patch_h,'FaceVertexCData',colors);
|
wolffd@0
|
292 set(gui.fig_h,'UserData',gui);
|
wolffd@0
|
293 return;
|
wolffd@0
|
294 end
|
wolffd@0
|
295
|
wolffd@0
|
296 if any(strcmp(udata.type,{'planePie','planeBar'}))
|
wolffd@0
|
297 [x,y]=pol2cart(0:0.1:2*pi,0.5);
|
wolffd@0
|
298 coords=[x';0.5]*0.7;
|
wolffd@0
|
299 coords(:,2)=[y';0]*0.7;
|
wolffd@0
|
300 elseif strcmp(udata.lattice,'hexa');
|
wolffd@0
|
301 coords=0.7*vis_patch('hexa');
|
wolffd@0
|
302 else
|
wolffd@0
|
303 coords=0.7*vis_patch('rect');
|
wolffd@0
|
304 end
|
wolffd@0
|
305 coords(:,1)=coords(:,1)+col;
|
wolffd@0
|
306 coords(:,2)=coords(:,2)+row;
|
wolffd@0
|
307 if ~mod(row,2) & strcmp(udata.lattice,'hexa'), col=round(col-0.5); end
|
wolffd@0
|
308
|
wolffd@0
|
309 hold on;
|
wolffd@0
|
310 if gco == udata.patch_h
|
wolffd@0
|
311 gui=findobj(get(0,'Children'),'Tag','SELECT_GUI');
|
wolffd@0
|
312 gui=get(gui,'UserData');
|
wolffd@0
|
313 if isnan(gui.curr_col) | strcmp(gui.mode,'clear'), return; end
|
wolffd@0
|
314 h=fill(coords(:,1),coords(:,2),gui.curr_col);
|
wolffd@0
|
315 str=cat(2,'som_select([],[],''click'')');
|
wolffd@0
|
316 set(h,'ButtonDownFcn',str,'Tag','SEL_PATCH');
|
wolffd@0
|
317 tmp.patch_h=udata.patch_h;
|
wolffd@0
|
318 set(h,'UserData',tmp);
|
wolffd@0
|
319 gui.mat(row,col)=gui.class;
|
wolffd@0
|
320 set(gui.fig_h,'UserData',gui);
|
wolffd@0
|
321 else
|
wolffd@0
|
322 gui=findobj(get(0,'Children'),'Tag','SELECT_GUI');
|
wolffd@0
|
323 gui=get(gui,'UserData');
|
wolffd@0
|
324 if ~all(get(gcbo,'FaceColor') == gui.curr_col) & ~strcmp(gui.mode,'clear'),
|
wolffd@0
|
325 if ~isnan(gui.curr_col),
|
wolffd@0
|
326 set(gcbo,'FaceColor',gui.curr_col);
|
wolffd@0
|
327 gui.mat(row,col) = gui.class;
|
wolffd@0
|
328 end
|
wolffd@0
|
329 else
|
wolffd@0
|
330 gui.mat(row,col)=0;
|
wolffd@0
|
331 delete(gco);
|
wolffd@0
|
332 end
|
wolffd@0
|
333 set(gui.fig_h,'UserData',gui);
|
wolffd@0
|
334 end
|
wolffd@0
|
335
|
wolffd@0
|
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
337
|
wolffd@0
|
338 function draw_colorselection(varargin)
|
wolffd@0
|
339
|
wolffd@0
|
340 if length(varargin)==2,
|
wolffd@0
|
341
|
wolffd@0
|
342 if length(varargin{1})==1,
|
wolffd@0
|
343 n = varargin{1};
|
wolffd@0
|
344 names = 1:n;
|
wolffd@0
|
345 else
|
wolffd@0
|
346 n = length(varargin{1});
|
wolffd@0
|
347 names = varargin{1};
|
wolffd@0
|
348 end
|
wolffd@0
|
349 colors = varargin{2};
|
wolffd@0
|
350
|
wolffd@0
|
351 shape=[0.5 -0.5;0.5 0.5;1.5 0.5;1.5 -0.5];
|
wolffd@0
|
352 rep_x=repmat(shape(:,1),1,n);
|
wolffd@0
|
353 rep_y=repmat(shape(:,2),1,n);
|
wolffd@0
|
354 for i=0:getfield(size(rep_y,2))-1, rep_x(:,i+1)=rep_x(:,i+1)+i; end
|
wolffd@0
|
355 if isempty(colors), colors=jet(n); end
|
wolffd@0
|
356 data=som_select_gui;
|
wolffd@0
|
357 data.colors=colors;
|
wolffd@0
|
358 data.curr_col=NaN;
|
wolffd@0
|
359 data.class=0;
|
wolffd@0
|
360 set(0,'CurrentFigure',data.fig_h);
|
wolffd@0
|
361 hold on;
|
wolffd@0
|
362 tmp=fill(rep_x,rep_y,0.8);
|
wolffd@0
|
363 for i=1:n
|
wolffd@0
|
364 set(tmp(i),...
|
wolffd@0
|
365 'EdgeColor',[0 0 0],...
|
wolffd@0
|
366 'FaceColor',colors(i,:),...
|
wolffd@0
|
367 'ButtonDownFcn','som_select([],0,''choose'');');
|
wolffd@0
|
368 end
|
wolffd@0
|
369 axis('equal');
|
wolffd@0
|
370 axis('on');
|
wolffd@0
|
371 set(gca,'XTick',1:n,'XTickLabel',names,'XAxisLocation','top');
|
wolffd@0
|
372 set(data.a_h,'YLim',[-0.5,0.5],...
|
wolffd@0
|
373 'XLim',[0.5 n+0.5],...
|
wolffd@0
|
374 'YTickLabel','');
|
wolffd@0
|
375 set(data.fig_h,'UserData',data);
|
wolffd@0
|
376
|
wolffd@0
|
377 elseif strcmp(varargin{3},'choose')
|
wolffd@0
|
378
|
wolffd@0
|
379 udata=get(gcf,'UserData');
|
wolffd@0
|
380 if strcmp(get(gcbo,'Selected'),'off')
|
wolffd@0
|
381 old=findobj(get(gca,'Children'),'Type','patch');
|
wolffd@0
|
382 set(old,'Selected','off');
|
wolffd@0
|
383 set(gcbo,'Selected','on');
|
wolffd@0
|
384 udata.curr_col=udata.colors(round(mean(get(gcbo,'XData'))),:);
|
wolffd@0
|
385 udata.class=mean(get(gcbo,'XData'));
|
wolffd@0
|
386 else
|
wolffd@0
|
387 set(gcbo,'Selected','off');
|
wolffd@0
|
388 udata.curr_col=NaN;
|
wolffd@0
|
389 udata.class=0;
|
wolffd@0
|
390 end
|
wolffd@0
|
391 set(gcf,'UserData',udata);
|
wolffd@0
|
392
|
wolffd@0
|
393 end
|
wolffd@0
|
394
|
wolffd@0
|
395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
396
|
wolffd@0
|
397 function data=som_select_gui()
|
wolffd@0
|
398
|
wolffd@0
|
399
|
wolffd@0
|
400 a = figure('Color',[0.8 0.8 0.8], ...
|
wolffd@0
|
401 'PaperType','a4letter', ...
|
wolffd@0
|
402 'Position',[586 584 560 210], ...
|
wolffd@0
|
403 'Tag','SELECT_GUI');
|
wolffd@0
|
404
|
wolffd@0
|
405 data.fig_h=a;
|
wolffd@0
|
406
|
wolffd@0
|
407 b = axes('Parent',a, ...
|
wolffd@0
|
408 'Box','on', ...
|
wolffd@0
|
409 'CameraUpVector',[0 1 0], ...
|
wolffd@0
|
410 'Color',[1 1 1], ...
|
wolffd@0
|
411 'DataAspectRatioMode','manual', ...
|
wolffd@0
|
412 'PlotBoxAspectRatio',[20 1 2], ...
|
wolffd@0
|
413 'PlotBoxAspectRatioMode','manual', ...
|
wolffd@0
|
414 'Position',[0.13 0.11 0.775 0.815], ...
|
wolffd@0
|
415 'Tag','Axes1', ...
|
wolffd@0
|
416 'WarpToFill','off', ...
|
wolffd@0
|
417 'XColor',[0 0 0], ...
|
wolffd@0
|
418 'XLimMode','manual', ...
|
wolffd@0
|
419 'YColor',[0 0 0], ...
|
wolffd@0
|
420 'YLimMode','manual', ...
|
wolffd@0
|
421 'YTickLabelMode','manual', ...
|
wolffd@0
|
422 'ZColor',[0 0 0]);
|
wolffd@0
|
423
|
wolffd@0
|
424 data.a_h=b;
|
wolffd@0
|
425
|
wolffd@0
|
426 b = uicontrol('Parent',a, ...
|
wolffd@0
|
427 'Units','points', ...
|
wolffd@0
|
428 'BackgroundColor',[0.701961 0.701961 0.701961], ...
|
wolffd@0
|
429 'Callback','som_select([],[],''close'')', ...
|
wolffd@0
|
430 'FontWeight','demi', ...
|
wolffd@0
|
431 'Position',[150 12 50 20], ...
|
wolffd@0
|
432 'String','CLOSE', ...
|
wolffd@0
|
433 'Tag','Pushbutton1');
|
wolffd@0
|
434
|
wolffd@0
|
435 b = uicontrol('Parent',a, ...
|
wolffd@0
|
436 'Units','points', ...
|
wolffd@0
|
437 'BackgroundColor',[0.701961 0.701961 0.701961], ...
|
wolffd@0
|
438 'Callback','som_select([],0,''ret_mat'')',...
|
wolffd@0
|
439 'FontWeight','demi', ...
|
wolffd@0
|
440 'Position',[365 12 50 20], ...
|
wolffd@0
|
441 'String','OK', ...
|
wolffd@0
|
442 'Tag','Pushbutton2');
|
wolffd@0
|
443
|
wolffd@0
|
444 b = uicontrol('Parent',a, ...
|
wolffd@0
|
445 'Units','points', ...
|
wolffd@0
|
446 'BackgroundColor',[0.701961 0.701961 0.701961], ...
|
wolffd@0
|
447 'Callback','som_select([],0,''clear'')',...
|
wolffd@0
|
448 'FontWeight','demi', ...
|
wolffd@0
|
449 'Position',[257.5 12 50 20], ...
|
wolffd@0
|
450 'String','CLEAR', ...
|
wolffd@0
|
451 'Tag','Pushbutton3');
|
wolffd@0
|
452
|
wolffd@0
|
453 b = uicontrol('Parent',a, ...
|
wolffd@0
|
454 'Units','points', ...
|
wolffd@0
|
455 'Position',[50 27 17 16], ...
|
wolffd@0
|
456 'Callback','som_select([],[],''rb'')',...
|
wolffd@0
|
457 'Style','radiobutton', ...
|
wolffd@0
|
458 'Tag','Radiobutton1', ...
|
wolffd@0
|
459 'Value',1);
|
wolffd@0
|
460 b = uicontrol('Parent',a, ...
|
wolffd@0
|
461 'Units','points', ...
|
wolffd@0
|
462 'BackgroundColor',[0.701961 0.701961 0.701961], ...
|
wolffd@0
|
463 'Callback','som_select([],[],''rb'')',...
|
wolffd@0
|
464 'Position',[50 7 17 16], ...
|
wolffd@0
|
465 'Style','radiobutton', ...
|
wolffd@0
|
466 'Tag','Radiobutton2');
|
wolffd@0
|
467 b = uicontrol('Parent',a, ...
|
wolffd@0
|
468 'Units','points', ...
|
wolffd@0
|
469 'BackgroundColor',[0.8 0.8 0.8], ...
|
wolffd@0
|
470 'FontSize',9, ...
|
wolffd@0
|
471 'FontWeight','demi', ...
|
wolffd@0
|
472 'HorizontalAlignment','left', ...
|
wolffd@0
|
473 'Position',[72 25 28 15], ...
|
wolffd@0
|
474 'String','Select', ...
|
wolffd@0
|
475 'Style','text', ...
|
wolffd@0
|
476 'Tag','StaticText1');
|
wolffd@0
|
477 b = uicontrol('Parent',a, ...
|
wolffd@0
|
478 'Units','points', ...
|
wolffd@0
|
479 'BackgroundColor',[0.8 0.8 0.8], ...
|
wolffd@0
|
480 'FontSize',9, ...
|
wolffd@0
|
481 'FontWeight','demi', ...
|
wolffd@0
|
482 'HorizontalAlignment','left', ...
|
wolffd@0
|
483 'Position',[72 7 25 13.6], ...
|
wolffd@0
|
484 'String','Clear', ...
|
wolffd@0
|
485 'Style','text', ...
|
wolffd@0
|
486 'Tag','StaticText2');
|
wolffd@0
|
487
|
wolffd@0
|
488
|
wolffd@0
|
489
|
wolffd@0
|
490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
491
|
wolffd@0
|
492 function close_gui
|
wolffd@0
|
493
|
wolffd@0
|
494 udata=get(get(gcbo,'Parent'),'UserData');
|
wolffd@0
|
495
|
wolffd@0
|
496 if strcmp(udata.type,'planePlot');
|
wolffd@0
|
497 set(udata.plane_h,'ButtonDownFcn','','UserData',[]);
|
wolffd@0
|
498 set(get(udata.plane_h,'Parent'),'ButtonDownFcn','');
|
wolffd@0
|
499 delete(udata.patch_h);
|
wolffd@0
|
500 return;
|
wolffd@0
|
501 end
|
wolffd@0
|
502
|
wolffd@0
|
503 h=findobj(get(udata.plane_h,'Children'),'Tag','SEL_PATCH');
|
wolffd@0
|
504 set(udata.patch_h,'ButtonDownFcn','','UserData',[]);
|
wolffd@0
|
505 delete(h);
|
wolffd@0
|
506 close(udata.fig_h);
|
wolffd@0
|
507
|
wolffd@0
|
508 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
509
|
wolffd@0
|
510 function draw_poly
|
wolffd@0
|
511
|
wolffd@0
|
512 udata=get(findobj(get(0,'Children'),'Tag','SELECT_GUI'),'UserData');
|
wolffd@0
|
513
|
wolffd@0
|
514 if isempty(udata.coords) & strcmp(get(gcf,'SelectionType'),'alt')
|
wolffd@0
|
515 return;
|
wolffd@0
|
516 end
|
wolffd@0
|
517
|
wolffd@0
|
518 coords(1,1) = getfield(get(gca,'CurrentPoint'),{3});
|
wolffd@0
|
519 coords(1,2) = getfield(get(gca,'CurrentPoint'),{1});
|
wolffd@0
|
520 udata.coords = cat(1,udata.coords,coords);
|
wolffd@0
|
521 delete(udata.poly_h);
|
wolffd@0
|
522 subplot(udata.plane_h);
|
wolffd@0
|
523
|
wolffd@0
|
524 hold on;
|
wolffd@0
|
525 switch get(gcf,'SelectionType');
|
wolffd@0
|
526 case 'normal'
|
wolffd@0
|
527 udata.poly_h=plot(udata.coords(:,2),udata.coords(:,1),'black',...
|
wolffd@0
|
528 'ButtonDownFcn','som_select([],[],''click'')',...
|
wolffd@0
|
529 'LineWidth',2);
|
wolffd@0
|
530 set(udata.fig_h,'UserData',udata);
|
wolffd@0
|
531 case 'alt'
|
wolffd@0
|
532 udata.coords=cat(1,udata.coords,udata.coords(1,:));
|
wolffd@0
|
533 udata.poly_h=plot(udata.coords(:,2),udata.coords(:,1),'black',...
|
wolffd@0
|
534 'LineWidth',2);
|
wolffd@0
|
535 delete(udata.poly_h);
|
wolffd@0
|
536 if ~isnan(udata.curr_col)
|
wolffd@0
|
537 tmp=sort(repmat((1:udata.msize(1))',udata.msize(2),1));
|
wolffd@0
|
538 tmp(:,2)=repmat((1:udata.msize(2))',udata.msize(1),1);
|
wolffd@0
|
539 tmp2=tmp;
|
wolffd@0
|
540 if strcmp(udata.type,'planePlot')
|
wolffd@0
|
541 in=find(inpolygon(tmp(:,2),tmp(:,1),...
|
wolffd@0
|
542 udata.coords(:,2),udata.coords(:,1)));
|
wolffd@0
|
543 row=tmp2(in,1);
|
wolffd@0
|
544 col=tmp2(in,2);
|
wolffd@0
|
545 in=sub2ind(udata.msize,row,col);
|
wolffd@0
|
546 colors=reshape(get(udata.patch_h,'FaceVertexCData'),...
|
wolffd@0
|
547 [prod(udata.msize) 3]);
|
wolffd@0
|
548 if ~isnan(udata.curr_col) & ~strcmp(udata.mode,'clear')
|
wolffd@0
|
549 colors(in,:)=ones(length(in),1)*udata.curr_col;
|
wolffd@0
|
550 udata.mat(row,col)=udata.class;
|
wolffd@0
|
551 elseif strcmp(udata.mode,'clear')
|
wolffd@0
|
552 colors(in,:)=[NaN NaN NaN];
|
wolffd@0
|
553 udata.mat(row,col)=0;
|
wolffd@0
|
554 end
|
wolffd@0
|
555 udata.poly_h=[];
|
wolffd@0
|
556 udata.coords=[];
|
wolffd@0
|
557 set(udata.patch_h,'FaceVertexCData',colors);
|
wolffd@0
|
558 set(udata.fig_h,'UserData',udata);
|
wolffd@0
|
559 return;
|
wolffd@0
|
560 end
|
wolffd@0
|
561 if strcmp(udata.lattice,'hexa');
|
wolffd@0
|
562 t=find(~rem(tmp(:,1),2));
|
wolffd@0
|
563 tmp(t,2)=tmp(t,2)+0.5;
|
wolffd@0
|
564 if any(strcmp(get(udata.patch_h,'Tag'),{'planeC','planeU'}))
|
wolffd@0
|
565 p=0.7*vis_patch('hexa');
|
wolffd@0
|
566 else
|
wolffd@0
|
567 [x,y]=pol2cart(0:0.1:2*pi,0.5);
|
wolffd@0
|
568 p=[x';0.5]*0.7;
|
wolffd@0
|
569 p(:,2)=[y';0]*0.7;
|
wolffd@0
|
570 end
|
wolffd@0
|
571 else
|
wolffd@0
|
572 if any(strcmp(get(udata.patch_h,'Tag'),{'planeC','planeU'}))
|
wolffd@0
|
573 p=0.7*vis_patch('rect');
|
wolffd@0
|
574 else
|
wolffd@0
|
575 [x,y]=pol2cart(0:0.1:2*pi,0.5);
|
wolffd@0
|
576 p=[x';0.5]*0.7;
|
wolffd@0
|
577 p(:,2)=[y';0]*0.7;
|
wolffd@0
|
578 end
|
wolffd@0
|
579 end
|
wolffd@0
|
580 in=find(inpolygon(tmp(:,2),tmp(:,1),udata.coords(:,2),udata.coords(:,1)));
|
wolffd@0
|
581 set(udata.fig_h,'UserData',udata);
|
wolffd@0
|
582 if strcmp(udata.mode,'select')
|
wolffd@0
|
583 remove_selpatches;
|
wolffd@0
|
584 udata=get(udata.fig_h,'UserData');
|
wolffd@0
|
585 for i=1:length(in)
|
wolffd@0
|
586 udat.patch_h=udata.patch_h;
|
wolffd@0
|
587 h=patch(p(:,1)+tmp(in(i),2),p(:,2)+tmp(in(i),1),...
|
wolffd@0
|
588 udata.curr_col,...
|
wolffd@0
|
589 'EdgeColor','black',...
|
wolffd@0
|
590 'ButtonDownFcn','som_select([],[],''click'')', ...
|
wolffd@0
|
591 'Tag','SEL_PATCH',...
|
wolffd@0
|
592 'UserData',udat);
|
wolffd@0
|
593 udata.mat(tmp2(in(i),1),tmp2(in(i),2))=udata.class;
|
wolffd@0
|
594 end
|
wolffd@0
|
595 else
|
wolffd@0
|
596 remove_selpatches;
|
wolffd@0
|
597 udata=get(udata.fig_h,'UserData');
|
wolffd@0
|
598 %h=findobj(get(udata.plane_h,'Children'),'Tag','SEL_PATCH');
|
wolffd@0
|
599 %for i=1:length(h)
|
wolffd@0
|
600 % if all(get(h(i),'FaceColor')==udata.curr_col) & ...
|
wolffd@0
|
601 % inpolygon(mean(get(h(i),'XData')),mean(get(h(i),'YData')),...
|
wolffd@0
|
602 % udata.coords(:,2),udata.coords(:,1))
|
wolffd@0
|
603 % coords=[floor(mean(get(h(i),'YData')))...
|
wolffd@0
|
604 % floor(mean(get(h(i),'XData')))];
|
wolffd@0
|
605 % udata.mat(coords(1),coords(2))=0;
|
wolffd@0
|
606 % delete(h(i));
|
wolffd@0
|
607 % end
|
wolffd@0
|
608 %end
|
wolffd@0
|
609 end
|
wolffd@0
|
610 end
|
wolffd@0
|
611 udata.poly_h=[];
|
wolffd@0
|
612 udata.coords=[];
|
wolffd@0
|
613 set(udata.fig_h,'UserData',udata);
|
wolffd@0
|
614 end
|
wolffd@0
|
615
|
wolffd@0
|
616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
617
|
wolffd@0
|
618 function remove_selpatches
|
wolffd@0
|
619
|
wolffd@0
|
620 udata=get(findobj(get(0,'Children'),'Tag','SELECT_GUI'),'UserData');
|
wolffd@0
|
621 h=findobj(get(udata.plane_h,'Children'),'Tag','SEL_PATCH');
|
wolffd@0
|
622 for i=1:length(h)
|
wolffd@0
|
623 if inpolygon(mean(get(h(i),'XData')),mean(get(h(i),'YData')),...
|
wolffd@0
|
624 udata.coords(:,2),udata.coords(:,1));
|
wolffd@0
|
625 coords=[floor(mean(get(h(i),'YData')))...
|
wolffd@0
|
626 floor(mean(get(h(i),'XData')))];
|
wolffd@0
|
627 udata.mat(coords(1),coords(2))=0;
|
wolffd@0
|
628 delete(h(i));
|
wolffd@0
|
629 end
|
wolffd@0
|
630 end
|
wolffd@0
|
631
|
wolffd@0
|
632 set(udata.fig_h,'UserData',udata);
|
wolffd@0
|
633
|
wolffd@0
|
634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
635
|
wolffd@0
|
636 function [n,names,classes]=class2num(class)
|
wolffd@0
|
637
|
wolffd@0
|
638 names = {};
|
wolffd@0
|
639 classes = zeros(length(class),1);
|
wolffd@0
|
640 for i=1:length(class)
|
wolffd@0
|
641 if ~isempty(class{i}),
|
wolffd@0
|
642 a = find(strcmp(class{i},names));
|
wolffd@0
|
643 if isempty(a),
|
wolffd@0
|
644 names=cat(1,names,class(i));
|
wolffd@0
|
645 classes(i) = length(names);
|
wolffd@0
|
646 else
|
wolffd@0
|
647 classes(i) = a;
|
wolffd@0
|
648 end
|
wolffd@0
|
649 end
|
wolffd@0
|
650 end
|
wolffd@0
|
651 n=length(names);
|
wolffd@0
|
652
|
wolffd@0
|
653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
654
|
wolffd@0
|
655 function h=find_patch(a_h)
|
wolffd@0
|
656
|
wolffd@0
|
657 h=[];
|
wolffd@0
|
658
|
wolffd@0
|
659 tags={'planeC','planeU','planePie','planeBar','planePlot'};
|
wolffd@0
|
660
|
wolffd@0
|
661 for i=1:5
|
wolffd@0
|
662 if ~isempty(findobj(get(a_h,'Children'),'Tag',tags{i}))
|
wolffd@0
|
663 h=findobj(get(gca,'Children'),'Tag',tags{i});
|
wolffd@0
|
664 if length(h) > 1
|
wolffd@0
|
665 h=h(1);
|
wolffd@0
|
666 end
|
wolffd@0
|
667 return;
|
wolffd@0
|
668 end
|
wolffd@0
|
669 end
|
wolffd@0
|
670
|
wolffd@0
|
671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
672
|
wolffd@0
|
673 function draw_classes
|
wolffd@0
|
674
|
wolffd@0
|
675 udata=get(findobj(get(0,'Children'),'Tag','SELECT_GUI'), ...
|
wolffd@0
|
676 'UserData');
|
wolffd@0
|
677 figure(get(udata.plane_h,'Parent'))
|
wolffd@0
|
678 subplot(udata.plane_h);
|
wolffd@0
|
679
|
wolffd@0
|
680 colors=zeros(prod(udata.msize),3)+NaN;
|
wolffd@0
|
681 c_map=jet(length(udata.c_names));
|
wolffd@0
|
682 inds = find(udata.mat);
|
wolffd@0
|
683 for i=1:length(inds),
|
wolffd@0
|
684 colors(inds(i),:) = c_map(udata.mat(inds(i)),:);
|
wolffd@0
|
685 end
|
wolffd@0
|
686
|
wolffd@0
|
687 if strcmp(udata.type,'planePlot'),
|
wolffd@0
|
688
|
wolffd@0
|
689 set(udata.patch_h,'FaceVertexCData',colors);
|
wolffd@0
|
690 set(udata.fig_h,'UserData',udata);
|
wolffd@0
|
691
|
wolffd@0
|
692 else
|
wolffd@0
|
693
|
wolffd@0
|
694 hold on
|
wolffd@0
|
695 co = som_vis_coords(udata.lattice,udata.msize);
|
wolffd@0
|
696 if any(strcmp(get(udata.patch_h,'Tag'),{'planeC','planeU'}))
|
wolffd@0
|
697 p=0.7*vis_patch(udata.lattice);
|
wolffd@0
|
698 else
|
wolffd@0
|
699 [x,y]=pol2cart(0:0.1:2*pi,0.5);
|
wolffd@0
|
700 p=[x';0.5]*0.7;
|
wolffd@0
|
701 p(:,2)=[y';0]*0.7;
|
wolffd@0
|
702 end
|
wolffd@0
|
703 for i=1:length(inds),
|
wolffd@0
|
704 udat.patch_h=udata.patch_h;
|
wolffd@0
|
705 h=patch(p(:,1)+co(inds(i),1),p(:,2)+co(inds(i),2),...
|
wolffd@0
|
706 colors(inds(i),:),...
|
wolffd@0
|
707 'EdgeColor','black',...
|
wolffd@0
|
708 'ButtonDownFcn','som_select([],[],''click'')', ...
|
wolffd@0
|
709 'Tag','SEL_PATCH',...
|
wolffd@0
|
710 'UserData',udat);
|
wolffd@0
|
711 end
|
wolffd@0
|
712
|
wolffd@0
|
713 end
|
wolffd@0
|
714
|
wolffd@0
|
715
|
wolffd@0
|
716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|