comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_select.m @ 0:e9a9cd732c1e tip

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