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