-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFM2app.m
1604 lines (1162 loc) · 52.1 KB
/
FM2app.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
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = FM2app(varargin)
% FM2APP MATLAB code for FM2app.fig
% FM2APP, by itself, creates a new FM2APP or raises the existing
% singleton*.
%
% H = FM2APP returns the handle to a new FM2APP or the handle to
% the existing singleton*.
%
% FM2APP('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FM2APP.M with the given input arguments.
%
% FM2APP('Property','Value',...) creates a new FM2APP or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before FM2app_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to FM2app_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help FM2app
% Last Modified by GUIDE v2.5 20-Sep-2014 16:58:33
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Common part
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @FM2app_OpeningFcn, ...
'gui_OutputFcn', @FM2app_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before FM2app is made visible.
function FM2app_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to FM2app (see VARARGIN)
handles.cuenta = 0;
handles.trayectory = 0; %trayectoria que se guarga
handles.trayectoryl = 0; %trayectoria cargada
handles.cuental = 0;
handles.demosl = 0;
% Choose default command line output for FM2app
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes FM2app wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% Setting initial values.
if isempty(regexp(path,['algorithms' pathsep], 'once'))
addpath([pwd, '/algorithms']); % path algorithms
end
if isempty(regexp(path,['fm2tools' pathsep], 'once'))
addpath([pwd, '/fm2tools']); % tool scripts
end
%% Descomentar esto o quitar los if.
if isempty(regexp(path,['guitools' pathsep], 'once'))
addpath([pwd, '/guitools']); % tool scripts
end
if isempty(regexp(path,['thirdparty' pathsep], 'once'))
addpath([pwd, '/thirdparty']); % tool scripts
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(handles.fml_uipanel, 'Visible', 'Off');
set(handles.fm2_uipanel, 'Visible', 'Off');
set(handles.fm2f_uipanel,'Visible','Off');
% --- Outputs from this function are returned to the command line.
function varargout = FM2app_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Topbar Menu Callbacks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --------------------------------------------------------------------
function algorithms_menu_Callback(hObject, eventdata, handles)
% hObject handle to algorithms_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function fm2_menu_Callback(hObject, eventdata, handles)
% hObject handle to fm2_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.fm2_uipanel, 'Visible', 'On');
set(handles.fml_uipanel, 'Visible', 'Off');
set(handles.fm2f_uipanel,'Visible','Off');
% --------------------------------------------------------------------
function fml_menu_Callback(hObject, eventdata, handles)
% hObject handle to fml_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.fml_uipanel, 'Visible', 'On');
set(handles.fm2_uipanel,'Visible','Off');
set(handles.fm2f_uipanel,'Visible','Off');
% --------------------------------------------------------------------
function fm2f_menu_Callback(hObject, eventdata, handles)
% hObject handle to fm2f_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.fml_uipanel, 'Visible', 'Off');
set(handles.fm2_uipanel,'Visible','Off');
set(handles.fm2f_uipanel,'Visible','On');
% --------------------------------------------------------------------
function about_menu_Callback(hObject, eventdata, handles)
% hObject handle to about_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str = sprintf('FM2app - Fast Marching Square\nVersion: 1.0 - 05/10/2014\n\nAuthor: Javier V. Gómez\njvgomez@ing.uc3m.es\nwww.javiervgomez.com\nhttp://roboticslab.uc3m.es/\nCarlos III University of Madrid \nand \nDavid Palomo Perez\n100276596@alumnos.uc3m.es\nCarlos III University of Madrid');
msgbox(str,'About FM2app', 'help');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Fast Marching Square GUI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function fm2sat_box_Callback(hObject, eventdata, handles)
% hObject handle to fm2sat_box (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of fm2sat_box as text
% str2double(get(hObject,'String')) returns contents of fm2sat_box as a double
sat = str2double(get(hObject, 'String'));
sat = checkLimits(sat,0,1, 'saturation');
handles.fm2sat = sat;
guidata(hObject,handles);
set(hObject, 'String', sat);
set(handles.fm2sat_slider, 'Value', sat);
fm2updateF; %se actualiza el mapa al valor nuevo.
% --- Executes during object creation, after setting all properties.
function fm2sat_box_CreateFcn(hObject, eventdata, handles)
% hObject handle to fm2sat_box (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject,'Value', 1);
set(hObject,'String', 1);
handles.fm2sat = 1;
guidata(hObject,handles);
% --- Executes on slider movement.
function fm2sat_slider_Callback(hObject, eventdata, handles)
% hObject handle to fm2sat_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
sat = get(hObject, 'Value'); % IMPROVE: there should be a better way to round to 2 decimals.
sat = str2double(sprintf('%.2f', sat)); % To only show 2 decimals.;
set(handles.fm2sat_box, 'String', sat);
handles.fm2sat = sat;
guidata(hObject,handles);
fm2updateF;
% --- Executes during object creation, after setting all properties.
function fm2sat_slider_CreateFcn(hObject, eventdata, handles)
% hObject handle to fm2sat_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set(hObject,'Value', 1);
% --- Executes on button press in fm2loaddata_pushbutton.
function fm2loaddata_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to fm2loaddata_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.fm2start_text, 'String', 'Start: ');
set(handles.fm2goal_text, 'String', 'Goal: ');
FM2app2;
fm2openGUI;
set(handles.hint_text1, 'String', 'Click over the environment map to select the FM2 start and goal points.');
% --- Executes on button press in fm2sg_pushbutton.
function fm2sg_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to fm2sg_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fm2map_axes
% Start point
point_ok = 0;
while point_ok == 0
figure(FM2app2);
axes(fm2map_axes);
[x,y] = ginput(1);
y = round(y);
x = round(x);
point_ok = 1;
if y < 0 || y > size(handles.fm2map,1) || x < 0 || x > size(handles.fm2map,2)
h = warndlg('Point out of map bounds, please select another point.',...
'Start point selection error','modal');
uiwait(h); % Prevents to run ginputax by clicking the OK button.
point_ok = 0;
elseif handles.fm2map(y,x) == 0
h = warndlg('Point in an obstacle, please select another point.',...
'Start point selection error','modal');
uiwait(h); % Prevents to run ginputax by clicking the OK button.
point_ok = 0;
end
end
handles.fm2start_point = [x; y];
str = sprintf('Start: [%d, %d]',x,y);
set(handles.fm2start_text, 'String', str);
axes(fm2map_axes);
cla;
imagesc(handles.fm2map);
colormap gray(256);
axis xy;
axis image;
axis off;
hold on;
title('Obstacles Map');
plot(x,y,'rx','MarkerSize', 15);
point_ok = 0;
while point_ok == 0
figure(FM2app2);
axes(fm2map_axes);
[x,y] = ginput(1);
y = round(y);
x = round(x);
point_ok = 1;
if y < 0 || y > size(handles.fm2map,1) || x < 0 || x > size(handles.fm2map,2)
h = warndlg('Point out of map bounds, please select another point.',...
'Start point selection error','modal');
uiwait(h); % Prevents to run ginputax by clicking the OK button.
point_ok = 0;
elseif handles.fm2map(y,x) == 0
h = warndlg('Point in an obstacle, please select another point.',...
'Start point selection error','modal');
uiwait(h); % Prevents to run ginputax by clicking the OK button.
point_ok = 0;
end
end
handles.fm2goal_point = [x; y];
str = sprintf('Goal: [%d, %d]',x,y);
set(handles.fm2goal_text, 'String', str);
axes(fm2map_axes);
plot(x,y,'k*','MarkerSize', 15);
hold on;
title('Obstacles Map');
hold off;
guidata(hObject,handles);
set(handles.fm2run_pushbutton, 'Enable', 'On');
set(handles.hint_text1, 'String', 'Now click on Compute FM2! to run the Fast Marching Square algorithm.');
% --- Executes on button press in fm2run_pushbutton.
function fm2run_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to fm2run_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% IMPROVEMENT : add option of additive drawing: if data not reloaded, select if
% the new FM2 run should detele the previous computed path.
global fm2F_axes
global fm2map_axes
global fm2vels_axes
sat = str2double(get(handles.fm2sat_box, 'String'));
map = handles.fm2map;
start = handles.fm2start_point;
goal = handles.fm2goal_point;
% FM2 template. The velocities map F is recomputed just to show how the
[F, T, path, vels, times] = FM2(map, sat, start, goal);
% Updating gui.
handles.fm2F = F;
handles.fm2path = path;
handles.fm2vels = vels;
handles.fm2times = times;
handles.fm2sat = sat;
guidata(hObject,handles);
figure(FM2app2); % activa la pantalla 2
str = sprintf('F (s): %f', times(1));
set(handles.fm2Ftime_text, 'String', str);
freezeColors(fm2F_axes);
fm2updateT;
axes(fm2map_axes);
colormap gray(256);
freezeColors;
hold on;
plot(path(1,:), path(2,:), 'b-', 'LineWidth', 5);
title('Obstacles Map');
axes(fm2vels_axes);
cla;
plot(vels(2,:), vels(1,:), 'b-', 'LineWidth', 2);
hold on;
plot(vels(2,1), vels(1,1), 'rx', 'MarkerSize', 15);
plot(vels(2,end), vels(1,end), 'k*', 'MarkerSize', 15);
ylim([0 1.05]);
title('Result');
hold off;
xlabel('Distance (m)')
ylabel('Speed (m/s)')
set(handles.hint_text1, 'String', 'You can see the results of the FM2 algorithm. Now use the Save button');
set(handles.fm2save_popupmenu, 'Enable', 'On');
set(handles.fm2save_pushbutton, 'Enable', 'On');
% --- Executes on selection change in fm2save_popupmenu.
function fm2save_popupmenu_Callback(hObject, eventdata, handles)
% hObject handle to fm2save_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns fm2save_popupmenu contents as cell array
% contents{get(hObject,'Value')} returns selected item from fm2save_popupmenu
% --- Executes during object creation, after setting all properties.
function fm2save_popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject handle to fm2save_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in fm2save_pushbutton.
function fm2save_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to fm2save_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fm2map_axes
global fm2F_axes
global fm2T_axes
global fm2vels_axes
what_to_save = get(handles.fm2save_popupmenu,'Value');
switch what_to_save
case 1
fm2map = handles.fm2map;
fm2sat = handles.fm2sat;
fm2F = handles.fm2F;
fm2T = handles.fm2T;
fm2path = handles.fm2path;
fm2vels = handles.fm2vels;
fm2times = handles.fm2times;
fm2start_point = handles.fm2start_point;
fm2goal_point = handles.fm2goal_point;
[filename, pathname] = uiputfile('output/fm2workspace.mat', 'Save FM2 workspace as');
save([pathname filename], 'fm2map', 'fm2sat', 'fm2F', 'fm2T', 'fm2path', 'fm2vels', 'fm2times', 'fm2start_point', 'fm2goal_point');
copyfile('guitools/README.txt', [pathname 'README.txt']);
otherwise
% TODO : include save as fig. Tried so hard already but unable to
% get a satisfactory solution.
[file, path, ~] = uiputfile({'*.eps','Encapsulated PostScript (*.eps)';'*.pdf','Portable Document Format (*.pdf)'}, 'Save figure as');
if file ~= 0
filetype = file(end-2:end);
switch what_to_save
case 2
axes_to_save = fm2map_axes;
case 3
axes_to_save = fm2F_axes;
case 4
axes_to_save = fm2T_axes;
case 5
axes_to_save = fm2vels_axes;
end
% TODO : does not save properly the figures.
%Runs the export_fig command with the path and file name, along with the
%filetype
export_fig(axes_to_save,[path,file],['-',filetype],'-painters');
export_fig(axes_to_save,[path,file],['-',filetype],'-painters');
%Message box
msgbox({'Done!';'';...
['The file ',file,'.',filetype,' can be found in:'];path},...
'Save Figure File','help','modal');
elseif isempty(file) == 0
msgbox('Not saved.','Save figure file','warn','modal');
end
end
% --- Executes on button press in fm2new_pushbutton.
function fm2new_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to fm2new_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
draw;
% Choose default command line output for FM2app
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Fast Marching Learning GUI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%nn%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in fmlloaddata_pushbutton.
function fmlloaddata_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to fmlloaddata_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% set(handles.fm2start_text, 'String', 'Start: ');
set(handles.fmlgoal_text, 'String', 'Goal: ');
FM2app2;
fmlopenGUI;
set(handles.fmloadtrajectory_pushbutton, 'Enable', 'On'); %habilita la posibilidad de cargar una trayectoria
set(handles.hint_text2, 'String', 'Click Load Trajectory or introduce nºdemos.');
function fmldemo_edit_Callback(hObject, eventdata, handles)
% hObject handle to fmldemo_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of fmldemo_edit as text
% str2double(get(hObject,'String')) returns contents of fmldemo_edit as a double
n = get(hObject, 'Value');
n = str2double(get(hObject,'String'));
set(handles.fmldemo_edit, 'String', n);
handles.fmln = n;%% demos
guidata(hObject,handles);
set(handles.fmlsat_slider, 'Enable', 'On');
set(handles.fmlsat_box, 'Enable', 'On');
set(handles.fmlsg_pushbutton, 'Enable', 'On');
set(handles.fmlaoi_slider, 'Enable', 'On');
set(handles.fmlaoi_box, 'Enable', 'On');
set(handles.hint_text2, 'String', 'Click now Introduce Demos.');
% --- Executes during object creation, after setting all properties.
function fmldemo_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to fmldemo_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function fmlsat_box_Callback(hObject, eventdata, handles)
% hObject handle to fmlsat_box (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of fmlsat_box as text
% str2double(get(hObject,'String')) returns contents of fmlsat_box as a double
sat = str2double(get(hObject, 'String'));
sat = checkLimits(sat,0.00,1, 'saturation');
handles.fmlsat = sat;
set(hObject, 'String', sat);
set(handles.fmlsat_slider, 'Value', sat);
fmLupdateF;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function fmlsat_box_CreateFcn(hObject, eventdata, handles)
% hObject handle to fmlsat_box (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject,'Value', 1);
set(hObject,'String', 1);
handles.fmlsat = 1;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function fmlsat_slider_CreateFcn(hObject, eventdata, handles)
% hObject handle to fmlsat_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function fmlsat_slider_Callback(hObject, eventdata, handles)
% hObject handle to fmlsat_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
sat = get(hObject, 'Value'); % IMPROVE: there should be a better way to round to 2 decimals.
sat = str2double(sprintf('%.2f', sat)); % To only show 2 decimals.;
set(handles.fmlsat_box, 'String', sat);
set(handles.fmlsat_slider,'Min',0.01)
handles.fmlsat = sat;
fmLupdateF;
guidata(hObject,handles);
% --- Executes on slider movement.
function fmlaoi_slider_Callback(hObject, eventdata, handles)
% hObject handle to fmlaoi_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
aoi = get(hObject, 'Value'); % IMPROVE: there should be a better way to round to 2 decimals.
aoi = str2double(sprintf('%d', round(aoi)));
set(handles.fmlaoi_box, 'String', aoi);
x = size(handles.fmlmap,1);
y = size(handles.fmlmap,2);
if x > y % Se el AOI sera el min del tamaño del mapa dividido entre dos.
Maxaoi = y/2;
elseif y > x
Maxaoi = x/2;
elseif x == y || y==x % Caso de que sea iguales
Maxaoi = x/2;
end
Maxaoi = fix(Maxaoi);
set(handles.fmlaoi_slider,'Min',10)
set(handles.fmlaoi_slider, 'Max', Maxaoi);
handles.maxaoi = Maxaoi;
handles.fmlaoi = aoi;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function fmlaoi_slider_CreateFcn(hObject, eventdata, handles)
% hObject handle to fmlaoi_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function fmlaoi_box_Callback(hObject, eventdata, handles)
% hObject handle to fmlaoi_box (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of fmlaoi_box as text
% str2double(get(hObject,'String')) returns contents of fmlaoi_box as a double
aoi = str2double(get(hObject, 'String'));
aoi = checkLimits(aoi,10,handles.maxaoi, 'aoi');
handles.fmlaoi = aoi;
set(hObject, 'String', aoi);
set(handles.fmlaoi_slider, 'Value', aoi);
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function fmlaoi_box_CreateFcn(hObject, eventdata, handles)
% hObject handle to fmlaoi_box (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject,'Value', 10);
set(hObject,'String', 10);
handles.fmlaoi = 10;
guidata(hObject,handles);
% --- Executes on button press in fmlsg_pushbutton.
function fmlsg_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to fmlsg_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fmLmap_axes
global fmLF_axes
n = handles.fmln; % numero de demostraciones
aoi_size = handles.fmlaoi; % valor de AOI
map = handles.fmlmap;
sat = handles.fmlsat;
p =[];
demos = cell(1,n);
handles.demos = cell(1,n);
handles.trajectory = cell(1,n); % Variable para almacenar trayectorias
handles.cuenta = cell(1,n) ; % Numero de puntos que conforman cada trayectoria
figure(FM2app2);
cla;
% Simulation of kinesthetic teaching.
for k=1:n
[dataset,cuenta] = kinesthetic_teaching (map', p);
p = [p dataset]; % This line is just to help plotting previous points.
cuenta = cuenta -1;
handles.cuenta{k} = cuenta; % save trajectory
demos{k} = dataset;
handles.demos{k} = dataset; %Se utiliza en el Recalculo del codigo
handles.trajectory{k} = dataset; % almacena las trayectorias
end
figure(FM2app2);
% Executing the FML algorithm.
[F, T, end_point, dx, dy] = FML(map, demos, sat, aoi_size);
% Updating gui
handles.fmlT = T;
handles.fmlF = F;
handles.fmlsat = sat;
handles.fmlmap = map;
axes(fmLF_axes);
cla;
imagesc(F');
colormap gray(256);
axis xy;
axis image;
title('Velocities Map');
axis off;
guidata(hObject,handles);
% Getting some reproductions from the initial poitns of the demos.
for i = 1:n
start_point = demos{i}(:,1);
start_point_r = round(start_point);
path = compute_geodesic(handles.fmlT, start_point_r);
starts(:, i) = start_point;
paths{i} = path;
end
% Plotting results.
axes(fmLmap_axes)
cla;
imagesc(map);
colormap gray(256);
hold on;
axis xy;
title('Result Map');
handles.fmlmap = map;
box on;
h = streamslice(-dx,-dy); % Reproductions field with stream lines.
set(h,'color','b');
for i = 1:length(paths)
ff = plot(paths{i}(1,:),paths{i}(2,:),'b','LineWidth',3);
f = plot(starts(1,i),starts(2,i),'k.','markersize',30);
end
for i = 1:n
g = scatter(demos{i}(1,:),demos{i}(2,:),'.r');
end
plot(end_point(1),end_point(2),'k*','markersize',15,'linewidth',3);
set(gca,'xtick',[], 'ytick',[]);
hold off;
axis image;
guidata(hObject,handles);
set(handles.fmlsave_popupmenu, 'Enable', 'On');
set(handles.fmlsave_pushbutton, 'Enable', 'On');
set(handles.fmrecalculate_pushbutton, 'Enable', 'On');
set(handles.hint_text2, 'String', 'Click popupmenu,select axes and click Save.');
% --- Executes on selection change in fmlsave_popupmenu.
function fmlsave_popupmenu_Callback(hObject, eventdata, handles)
% hObject handle to fmlsave_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns fmlsave_popupmenu contents as cell array
% contents{get(hObject,'Value')} returns selected item from fmlsave_popupmenu
% --- Executes during object creation, after setting all properties.
function fmlsave_popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject handle to fmlsave_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in fmlsave_pushbutton.
function fmlsave_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to fmlsave_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fmLmap_axes
global fmLF_axes
global fmLres_axes
what_to_save = get(handles.fmlsave_popupmenu,'Value');
switch what_to_save
case 1
fmlmap = handles.fmlmap;
fmlsat = handles.fmlsat;
fmlf = handles.fmlF;
n = handles.fmln;
aoi = handles.fmlaoi;
demos = handles.demos;
[filename, pathname] = uiputfile('output/fmlworkspace.mat', 'Save FML workspace as');
save([pathname filename],'fmlmap', 'fmlf', 'fmlsat','n','aoi','demos');
copyfile('guitools/README.txt', [pathname 'README.txt']);
case 2 % guardamos la trayectoria para poder cargarla luego.
trajectory = handles.trajectory;
count = handles.cuenta;
demos = handles.demos;
[filename, pathname] = uiputfile('output/fmltrajectory.mat', 'Save FML workspace as');
save([pathname filename],'trajectory', 'count','demos');
copyfile('guitools/README.txt', [pathname 'README.txt']);
otherwise
% TODO : include save as fig. Tried so hard already but unable to
% get a satisfactory solution.
[file, path, ~] = uiputfile({'*.eps','Encapsulated PostScript (*.eps)';'*.pdf','Portable Document Format (*.pdf)'}, 'Save figure as');
if file ~= 0
filetype = file(end-2:end);
switch what_to_save
case 3
axes_to_save = fmLmap_axes;
case 4
axes_to_save = fmLF_axes;
case 5
axes_to_save = fmLres_axes;
end
% TODO : does not save properly the figures.
%Runs the export_fig command with the path and file name, along with the
%filetype
export_fig(axes_to_save,[path,file],['-',filetype], '-transparent','-painters'); %painters
export_fig(axes_to_save,[path,file],['-',filetype], '-transparent','-painters'); %painters
%Message box
msgbox({'Done!';'';...
['The file ',file,'.',filetype,' can be found in:'];path},...
'Save Figure File','help','modal');
elseif isempty(file) == 0
msgbox('Not saved.','Save figure file','warn','modal');
end
end
% --- Executes on button press in fmlnewmap_pushbutton.
function fmlnewmap_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to fmlnewmap_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
draw;
% Choose default command line output for FM2app
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in fmrecalculate_pushbutton.
function fmrecalculate_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to fmrecalculate_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fmLF_axes
global fmLmap_axes
n = handles.fmln;
aoi_size = handles.fmlaoi;
map = handles.fmlmap;
sat = handles.fmlsat;
demos = handles.demos;
figure(FM2app2);
% Executing the FML algorithm.
[F, T, end_point, dx, dy] = FML(map, demos, sat, aoi_size);
% Updating gui
handles.fmlT = T;
handles.fmlF = F;
handles.fmlsat = sat;