-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHeart_GUI.m
More file actions
600 lines (582 loc) · 23.7 KB
/
Heart_GUI.m
File metadata and controls
600 lines (582 loc) · 23.7 KB
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
% Copyright 2025 Weiwei Ai, University of Auckland.
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%%
function Heart_GUI(mdl,modelName,filename,savepath,raw_excel,raw_probes)
% EGMs have a funny output - check root cause for order
close all
global nodes_name
nodes_name = raw_excel(:,1:2);
global probes_name
probes_name = raw_probes(:,1);
timescale = evalin('base','timescale');
%% GUI
global ConfigGUI
% initialization
ConfigGUI.path_plot=[];
ConfigGUI.cells=[];
ConfigGUI.Node_pos=[];
%% Link to the model
ConfigGUI.modelName=modelName;
ConfigGUI.mdl = mdl;
ConfigGUI.savepath=savepath;
load_system(ConfigGUI.mdl);
open_system(ConfigGUI.mdl);
%% Save some of the models original info that this UI may change (and needs to change back again when the simulation stops)
ConfigGUI.originalStopTime = get_param(ConfigGUI.modelName,'Stoptime');
ConfigGUI.originalMode = get_param(ConfigGUI.modelName,'SimulationMode');
if strcmp(timescale,'s')
ConfigGUI.simtime=2;
else
ConfigGUI.simtime=2000;
end
%% Get the display
pos = get(0, 'screensize'); %get the screensize
W=pos(3);
H=pos(4);
x0=50;
y0=50;
WIDTH=W-50-x0;
HEIGHT=H-100-y0;
%[left bottom width height],the most outer frame
ConfigGUI.Handle=figure('Units', 'Pixels', 'Position', [x0 y0 WIDTH HEIGHT],...
'Resize','off','Name','UoA CIEDs Closed-loop Validation Platform V1.0','NumberTitle','Off',...
'WindowButtonDownFcn',@button_down,'Tag','GUI');
% Cardiac conduction system topology axes
ConfigGUI.TOP_axe=subplot(6,2,[1,3,5,7,9,11],'Parent',ConfigGUI.Handle,...
'Unit','normalized','OuterPosition',[0 0 1*HEIGHT/WIDTH 1],...
'Xlim',[40 180],'Ylim',[20 160],...
'NextPlot','add','Box','on');
axis(ConfigGUI.TOP_axe,'manual');
xlabel(ConfigGUI.TOP_axe,'x');
ylabel(ConfigGUI.TOP_axe,'y');
title(ConfigGUI.TOP_axe,'Cardiac Conduction System');
grid(ConfigGUI.TOP_axe,'on');
colormap(ConfigGUI.TOP_axe,hot);
% Place the Nodes and Probes
ConfigGUI.node_pos=scatter(ConfigGUI.TOP_axe,[],[],100,'filled','LineWidth',2,'Marker','o','CData',[0 0 0]); % black
ConfigGUI.probe_pos=scatter(ConfigGUI.TOP_axe,[],[],'LineWidth',1.5,'Marker','d','CData',[0 0 0]);
cbar = colorbar;
cbar.Label.String = 'Membrane Potential, Shifted (mV)';
% Place the Wavefronts
ConfigGUI.wave_posdi=scatter(ConfigGUI.TOP_axe,[],[],50,'LineWidth',1.5,'Marker','v','CData',[1 0 0]);
ConfigGUI.wave_posdj=scatter(ConfigGUI.TOP_axe,[],[],50,'LineWidth',1.5,'Marker','d','CData',[1 0 0]);
ConfigGUI.wave_posri=scatter(ConfigGUI.TOP_axe,[],[],50,'LineWidth',1.5,'Marker','v','CData',[0 0 1]);
ConfigGUI.wave_posrj=scatter(ConfigGUI.TOP_axe,[],[],50,'LineWidth',1.5,'Marker','d','CData',[0 0 1]);
% EGM and events display axes
ConfigGUI.AEGM=subplot(6,2,2,'Parent',ConfigGUI.Handle,'NextPlot','add','Box','on');
ylabel(ConfigGUI.AEGM,'AEGM');
p = get(ConfigGUI.AEGM,'position');
p(3)=p(3)*1.2;
%set(ConfigGUI.AEGM,'Ylim',[-7 7]);
ConfigGUI.VEGM=subplot(6,2,4,'Parent',ConfigGUI.Handle,'NextPlot','add','Box','on');
ylabel(ConfigGUI.VEGM,'VEGM');
p = get(ConfigGUI.VEGM,'position');
p(3)=p(3)*1.2;
%set(ConfigGUI.VEGM,'Ylim',[-20 20]);
ConfigGUI.GET=subplot(6,2,6,'Parent',ConfigGUI.Handle,'NextPlot','add','Box','on');
ylabel(ConfigGUI.GET,'Aget/Vget');
p = get(ConfigGUI.GET,'position');
p(3)=p(3)*1.2;
%set(ConfigGUI.GET,'Ylim',[-1.5 1.5]);
ConfigGUI.P=subplot(6,2,8,'Parent',ConfigGUI.Handle,'NextPlot','add','Box','on');
ylabel(ConfigGUI.P,'AP/VP');
p = get(ConfigGUI.P,'position');
p(3)=p(3)*1.2;
%set(ConfigGUI.P,'Ylim',[-1.5 1.5]);
ConfigGUI.S=subplot(6,2,10,'Parent',ConfigGUI.Handle,'NextPlot','add','Box','on');
ylabel(ConfigGUI.S,'AS/VS');
p = get(ConfigGUI.S,'position');
p(3)=p(3)*1.2;
%set(ConfigGUI.S,'Ylim',[-1.5 1.5]);
ConfigGUI.R=subplot(6,2,12,'Parent',ConfigGUI.Handle,'NextPlot','add','Box','on');
ylabel(ConfigGUI.R,'AR/VR');
xlabel(ConfigGUI.R,sprintf('Time (%s)',timescale));
p = get(ConfigGUI.R,'position');
p(3)=p(3)*1.2;
%set(ConfigGUI.R,'Ylim',[-1.5 1.5]);
grid(ConfigGUI.AEGM,'on');
grid(ConfigGUI.VEGM,'on');
grid(ConfigGUI.GET,'on');
grid(ConfigGUI.P,'on');
grid(ConfigGUI.S,'on');
grid(ConfigGUI.R,'on');
% Draw initial lines of the EGM and events
ConfigGUI.aegm=animatedline('LineWidth',1.5,'Color',[0 0 0],'Parent',ConfigGUI.AEGM);
ConfigGUI.vegm=animatedline('LineWidth',1.5,'Color',[0 0 0],'Parent',ConfigGUI.VEGM,'MaximumNumPoints',4000);
ConfigGUI.aget=animatedline('LineWidth',1.5,'Color',[0 0 0],'Parent',ConfigGUI.GET,'MaximumNumPoints',4000);
ConfigGUI.vget=animatedline('LineWidth',1.5,'Color',[0 0 0],'Parent',ConfigGUI.GET,'MaximumNumPoints',1000);
ConfigGUI.ap=animatedline('LineWidth',1.5,'Color',[0 0 0],'Parent',ConfigGUI.P,'MaximumNumPoints',4000);
ConfigGUI.vp=animatedline('LineWidth',1.5,'Color',[0 0 0],'Parent',ConfigGUI.P,'MaximumNumPoints',4000);
ConfigGUI.as=animatedline('LineWidth',1.5,'Color',[0 0 0],'Parent',ConfigGUI.S,'MaximumNumPoints',4000);
ConfigGUI.vs=animatedline('LineWidth',1.5,'Color',[0 0 0],'Parent',ConfigGUI.S,'MaximumNumPoints',4000);
ConfigGUI.ar=animatedline('LineWidth',1.5,'Color',[0 0 0],'Parent',ConfigGUI.R,'MaximumNumPoints',4000);
ConfigGUI.vr=animatedline('LineWidth',1.5,'Color',[0 0 0],'Parent',ConfigGUI.R,'MaximumNumPoints',4000);
% Current position
ConfigGUI.setp=scatter(ConfigGUI.TOP_axe,[],[],'LineWidth',1.5,'Marker','o','CData',[1 0 0]);
ConfigGUI.getp = uicontrol('Parent',ConfigGUI.Handle,...
'Style','text',...
'Units','normalized',...
'Position',[0.15 0.96 0.1 0.03],...
'BackgroundColor',[1 1 1],...
'String','(x,y)',...
'HorizontalAlignment','left',...
'HandleVisibility','callback',...
'Tag','getp');
% Create a panel for operations
ConfigGUI.hop = uipanel('Parent',ConfigGUI.Handle,...
'Units','normalized',...
'Position',[0.01 0.4 0.04 0.15],...
'Title','Operations',...
'BackgroundColor',get(ConfigGUI.Handle,'Color'),...
'HandleVisibility','callback',...
'Tag','tunePanel');
strings = {'Start','Pause','Stop',int2str(ConfigGUI.simtime)};
positions = [0.6 0.4 0.2 0];
tags = {'startpb','pausepb','stoppb','simtime'};
callbacks = {@localStartPressed, @localPausePressed, @localStopPressed,@localSetTime};
enabled ={'on','off','off','on'};
style={'pushbutton','pushbutton','pushbutton','edit'};
for idx = 1:length(strings)
uicontrol('Parent',ConfigGUI.hop,...
'Style',style{idx},...
'Units','normalized',...
'Position',[0.05 positions(idx) 0.9 0.2],...
'BackgroundColor',get(ConfigGUI.Handle,'Color'),...
'String',strings{idx},...
'Enable',enabled{idx},...
'Callback',callbacks{idx},...
'HandleVisibility','callback',...
'Tag',tags{idx});
end
% Create a panel for playback
ConfigGUI.hplay = uipanel('Parent',ConfigGUI.Handle,...
'Units','normalized',...
'Position',[0.01 0.1 0.04 0.15],...
'Title','Playback',...
'BackgroundColor',get(ConfigGUI.Handle,'Color'),...
'HandleVisibility','callback',...
'Tag','tunePanel');
strings = {'Load','Start','Pause','0',int2str(ConfigGUI.simtime)};
positions = [0.8 0.6 0.4 0.2 0];
style={'pushbutton','pushbutton','pushbutton','edit','edit'};
tags = {'loadpb','playstart','playpause','playst','played'};
callbacks = {@localLoadplay,@localPlaystart,@localPlaypause, @localStartset, @localEndset};
enabled ={'on','off','off','on','on'};
for idx = 1:length(strings)
uicontrol('Parent',ConfigGUI.hplay,...
'Style',style{idx},...
'Units','normalized',...
'Position',[0.05 positions(idx) 0.9 0.2],...
'BackgroundColor',get(ConfigGUI.Handle,'Color'),...
'String',strings{idx},...
'Enable',enabled{idx},...
'Callback',callbacks{idx},...
'HandleVisibility','callback',...
'Tag',tags{idx});
end
%Load the default model
load_model(filename);
% Specify the number of output of each node and path
ConfigGUI.EachNode=5; % Number of outputs of each node
ConfigGUI.EachPath=8; % Number of outputs of each path
% Store ConfigGUI to Userdata and communicate with the Simulink model
set_param(sprintf('%s/S-Function',ConfigGUI.modelName),'UserData',ConfigGUI);
%waitfor(ConfigGUI.Handle);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Function for Load model
function load_model(modelcfg)
global ConfigGUI
%[fname,fpath] = uigetfile('*.mat', 'Load VHM Model');
dim=load(modelcfg);
[ConfigGUI.NumNodes,~]=size(dim.Node); % Number of nodes
[ConfigGUI.NumPaths,~]=size(dim.Path); % Number of paths
ConfigGUI.Node_pos=dim.Node_pos;
% Display the nodes and probes; Store the node and probe positions
if ~isempty(ConfigGUI.Node_pos)
colormap(ConfigGUI.TOP_axe,hot);
c=zeros(size(ConfigGUI.Node_pos,1),3);
set(ConfigGUI.node_pos,'XData',ConfigGUI.Node_pos(:,1),'YData',ConfigGUI.Node_pos(:,2),'CData',c);%'ZData',ConfigGUI.Node_pos(:,3),'CData',c);
for n=1:length(ConfigGUI.Node_pos(:,1))
text(ConfigGUI.TOP_axe,ConfigGUI.Node_pos(n,1),ConfigGUI.Node_pos(n,2)+2,int2str(n),'Color','blue','FontSize',12);
end
else
error('The node position is empty.');
exit;
end
if ~isempty(dim.Probe_pos)
set(ConfigGUI.probe_pos,'XData',dim.Probe_pos(:,1),'YData',dim.Probe_pos(:,2));%,'ZData',dim.Probe_pos(:,3));
else
error('The Probe position is empty.');
exit;
end
% Draw the paths
% IMPORTANT HERE: DETERMINE HOW TO MAKE THE PATHS 3D IF NEEDED AT ALL
% add dim.Node_pos(dim.Path(n,3),1) and dim.Node_pos(dim.Path(n,3),2) to
% the x and y respectively
for n=1:size(dim.Path,1)
ConfigGUI.path_plot(n)=line([dim.Node_pos(dim.Path(n,1),1),dim.Node_pos(dim.Path(n,2),1)],[dim.Node_pos(dim.Path(n,1),2),dim.Node_pos(dim.Path(n,2),2)],'LineWidth',1.5,'Color',[0 0 0],'Parent',ConfigGUI.TOP_axe);
end
% Create the legend
legend([ConfigGUI.node_pos,ConfigGUI.probe_pos,ConfigGUI.wave_posdi,ConfigGUI.wave_posdj,ConfigGUI.wave_posri,ConfigGUI.wave_posrj],...
{'Node','Probe','Depolarisation (->)','Depolarisation (<-)','Repolarisation (->)','Repolarisation (<-)'});
% Reset wavefronts to (0,0)
x0=zeros(1,size(dim.Path,1));
y0=x0;
%z0=x0;
set(ConfigGUI.wave_posdi,'XData',x0,'YData',y0);%'ZData',z0);
set(ConfigGUI.wave_posdj,'XData',x0,'YData',y0);%'ZData',z0);
set(ConfigGUI.wave_posri,'XData',x0,'YData',y0);%'ZData',z0);
set(ConfigGUI.wave_posrj,'XData',x0,'YData',y0);%'ZData',z0);
% Reset
set(ConfigGUI.setp,'XData',0,'YData',0);%'ZData',z0);
LineHandles={ConfigGUI.aegm,ConfigGUI.vegm, ConfigGUI.aget,ConfigGUI.vget,ConfigGUI.ap,ConfigGUI.vp,ConfigGUI.as,ConfigGUI.vs,ConfigGUI.ar,ConfigGUI.vr};
for i=1:10
thisLineHandle = LineHandles{i};
clearpoints(thisLineHandle);
end
I = imread('heartoutline.jpg');
x = [20 180];
y = [28 192];
I = flipdim(I, 1);
h= image(ConfigGUI.TOP_axe,x,y,I);
uistack(h,'bottom')
hold on;
set_param(sprintf('%s/S-Function',ConfigGUI.modelName),'UserData',ConfigGUI);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callback Function for Start button
function localStartPressed(hObject,eventdata) %#ok
global ConfigGUI
% toggle the buttons
% Turn off the Start button
h = findobj(ConfigGUI.hop,'Tag','startpb');
set(h,'Enable','off');
% Turn on the Pause button
h = findobj(ConfigGUI.hop,'Tag','pausepb');
set(h,'Enable','on');
% Turn on the Stop button
h = findobj(ConfigGUI.hop,'Tag','stoppb');
set(h,'Enable','on');
% Set up the simulation time
localSetTime(ConfigGUI.simtime);
% Perform a different operation
% set the stop time
set_param(ConfigGUI.modelName,'StopTime',ConfigGUI.simtime);
% set the simulation mode to Accelerator
set_param(ConfigGUI.modelName,'SimulationMode','accelerator');
% Initialize the figure
LineHandles={ConfigGUI.aegm,ConfigGUI.vegm,ConfigGUI.aget,ConfigGUI.vget,ConfigGUI.ap,ConfigGUI.vp,ConfigGUI.as,ConfigGUI.vs,ConfigGUI.ar,ConfigGUI.vr};
for i=1:10
thisLineHandle = LineHandles{i};
clearpoints(thisLineHandle);
end
c=zeros(size(ConfigGUI.Node_pos,1),3);
set(ConfigGUI.node_pos,'XData',ConfigGUI.Node_pos(:,1),'YData',ConfigGUI.Node_pos(:,2),'CData',c);%'ZData',ConfigGUI.Node_pos(:,3),'CData',c);
set(ConfigGUI.wave_posdi,'XData',0,'YData',0);%'ZData',z0);
set(ConfigGUI.wave_posdj,'XData',0,'YData',0);%'ZData',z0);
set(ConfigGUI.wave_posri,'XData',0,'YData',0);%'ZData',z0);
set(ConfigGUI.wave_posrj,'XData',0,'YData',0);%'ZData',z0);
drawnow update;
% Run the model
set_param(ConfigGUI.modelName,'SimulationCommand','start');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callback Function for Pause button
function localPausePressed(hObject,eventdata) %#ok
global ConfigGUI
% Get the simulation status and perform a different operation
switch get_param(ConfigGUI.modelName,'SimulationStatus')
% If paused, continue
case 'paused'
set_param(ConfigGUI.modelName,'SimulationCommand','continue');
h = findobj(ConfigGUI.hop,'Tag','pausepb');
set(h,'String','Pause');
% If running, pause
case 'running'
set_param(ConfigGUI.modelName,'SimulationCommand','pause');
h = findobj(ConfigGUI.hop,'Tag','pausepb');
set(h,'String','Continue');
otherwise
% shouldn't be able to get in here
errordlg('Selection Error',...
'Neither pause nor continue was attempted.', 'modal');
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callback Function for Stop button
function localStopPressed(hObject,eventdata)
global ConfigGUI
% toggle the buttons
% Turn on the Start button
h = findobj(ConfigGUI.hop,'Tag','startpb');
set(h,'Enable','on');
% Turn off the Pause button
h = findobj(ConfigGUI.hop,'Tag','pausepb');
set(h,'String','Pause','Enable','off');
% Turn off the Stop button
h = findobj(ConfigGUI.hop,'Tag','stoppb');
set(h,'Enable','off');
% Perform a different operation
% stop the model
set_param(ConfigGUI.modelName,'SimulationCommand','stop');
% set model properties back to their original values
set_param(ConfigGUI.modelName,'Stoptime',ConfigGUI.originalStopTime);
set_param(ConfigGUI.modelName,'SimulationMode',ConfigGUI.originalMode);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callback Function for simulation time edit box
function localSetTime(hObject,eventdata) %#ok
global ConfigGUI
% Check that a valid value has been entered
h = findobj(ConfigGUI.hop,'Tag','simtime');
str = get(h,'String');
newValue = str2double(str);
% Do the change if it's valid
if ~isnan(newValue)
% store the new value
ConfigGUI.simtime = str;
else
% throw up an error dialog
estr = sprintf('%s is an invalid time value.',str);
errordlg(estr,'Time setup Error','modal');
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callback Function for start time edit box
function localStartset(hObject,eventdata) %#ok
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callback Function for start time edit box
function localEndset(hObject,eventdata) %#ok
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callback Function for Load button
function localLoadplay(hObject,eventdata)%#ok
global ConfigGUI
% Initialize the figure
LineHandles={ConfigGUI.aegm,ConfigGUI.vegm, ConfigGUI.aget,ConfigGUI.vget,ConfigGUI.ap,ConfigGUI.vp,ConfigGUI.as,ConfigGUI.vs,ConfigGUI.ar,ConfigGUI.vr};
for i=1:10
thisLineHandle = LineHandles{i};
clearpoints(thisLineHandle);
end
c=zeros(size(ConfigGUI.Node_pos,1),3);
colormap(ConfigGUI.TOP_axe,hot);
set(ConfigGUI.node_pos,'XData',ConfigGUI.Node_pos(:,1),'YData',ConfigGUI.Node_pos(:,2),'CData',c);%'ZData',ConfigGUI.Node_pos(:,3),'CData',c);
set(ConfigGUI.wave_posdi,'XData',0,'YData',0);%'ZData',0);
set(ConfigGUI.wave_posdj,'XData',0,'YData',0);%'ZData',0);
set(ConfigGUI.wave_posri,'XData',0,'YData',0);%'ZData',0);
set(ConfigGUI.wave_posrj,'XData',0,'YData',0);%'ZData',0);
drawnow update;
h = findobj(ConfigGUI.hplay,'Tag','loadpb');
switch get(h,'String')
case 'Load'
disp('Loading happening')
set(h,'String','Stop');
[fname,fpath] = uigetfile('*.mat', 'Load VHM Model');
dim=load([fpath fname]);
ConfigGUI.cells=dim.cells;
h = findobj(ConfigGUI.hplay,'Tag','playstart');
set(h,'Enable','on'); % Ready to start
h = findobj(ConfigGUI.hplay,'Tag','playst');
set(h,'Enable','on');
case 'Stop'
set(h,'String','Load');
h1 = findobj(ConfigGUI.hplay,'Tag','playst');
set(h1,'Enable','off','String','0');
h = findobj(ConfigGUI.hplay,'Tag','playstart');
set(h,'String','Start','Enable','on');
h = findobj(ConfigGUI.hplay,'Tag','playpause');
if strcmp(get(h,'Enable'),'off')
set(h1,'Enable','on','String','0');
else
set(h,'Enable','off');
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localPlaystart(hObject,eventdata)%#ok
global ConfigGUI
h = findobj(ConfigGUI.hplay,'Tag','loadpb');
set(h,'String','Stop');
h2 = findobj(ConfigGUI.hplay,'Tag','playpause');
set(h2,'Enable','on');
h = findobj(ConfigGUI.hplay,'Tag','playstart');
set(h,'Enable','off');
h1 = findobj(ConfigGUI.hplay,'Tag','played');
str = get(h1,'String');
end_time = find(abs(ConfigGUI.cells(1,:)-str2double(str)) < eps);
h1 = findobj(ConfigGUI.hplay,'Tag','playst');
set(h1,'Enable','on');
if strcmp(get(h,'String'),'Start')
% Initialize the figure when playback starts.
LineHandles={ConfigGUI.aegm,ConfigGUI.vegm,ConfigGUI.aget,ConfigGUI.vget,ConfigGUI.ap,ConfigGUI.vp,ConfigGUI.as,ConfigGUI.vs,ConfigGUI.ar,ConfigGUI.vr};
for i=1:10
thisLineHandle = LineHandles{i};
clearpoints(thisLineHandle);
end
c=zeros(size(ConfigGUI.Node_pos,1),3);
set(ConfigGUI.node_pos,'XData',ConfigGUI.Node_pos(:,1),'YData',ConfigGUI.Node_pos(:,2),'CData',c);%'ZData',ConfigGUI.Node_pos(:,3),'CData',c);
set(ConfigGUI.wave_posdi,'XData',0,'YData',0);%'ZData',0);
set(ConfigGUI.wave_posdj,'XData',0,'YData',0);%'ZData',0);
set(ConfigGUI.wave_posri,'XData',0,'YData',0);%'ZData',0);
set(ConfigGUI.wave_posrj,'XData',0,'YData',0);%'ZData',0);
drawnow update;
end
while (1)
pause(0.05);
wait = get(h1,'Enable');
if strcmp(wait,'on')
str = get(h1,'String');
start_time =find(abs(ConfigGUI.cells(1,:)-str2double(str)) < eps);
if start_time<end_time
playback(start_time); % Update display
start_time=start_time+1;
str=int2str(start_time);
set(h1,'String',str); % Update time
else
set(h1,'Enable','on');
set(h,'String','Start','Enable','on');
set(h2,'Enable','off');
h = findobj(ConfigGUI.hplay,'Tag','loadpb');
set(h,'String','Load');
break;
end
else
set(h1,'Enable','on');
set(h,'Enable','on');
break;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localPlaypause(hObject,eventdata)%#ok
global ConfigGUI
h = findobj(ConfigGUI.hplay,'Tag','playpause');
h1 = findobj(ConfigGUI.hplay,'Tag','playst');
set(h1,'Enable','off');
set(h,'Enable','off');
h = findobj(ConfigGUI.hplay,'Tag','playstart');
set(h,'Enable','on','String','Continue');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function playback(n)
global ConfigGUI
Config=ConfigGUI;
t=Config.cells(1,n);
u=Config.cells(2:end,n);
% Update node status
% Update the color of nodes according to the value of v;
ed=(ConfigGUI.NumNodes-1)*ConfigGUI.EachNode;
%Config.node_pos=scatter(Config.TOP_axe,u(4:EachNode:ed+4),u(5:EachNode:ed+5),70,u(2:EachNode:ed+2),'filled','LineWidth',2,'Marker','o');
c=u(2:ConfigGUI.EachNode:ed+2);
set(Config.node_pos,'XData',Config.Node_pos(:,1),'YData',Config.Node_pos(:,2),'CData',c);%'ZData',ConfigGUI.Node_pos(:,3),'CData',c);
% Update wavefront
st=ConfigGUI.NumNodes*ConfigGUI.EachNode;
ed=(ConfigGUI.NumPaths-1)*ConfigGUI.EachPath+ConfigGUI.NumNodes*ConfigGUI.EachNode;
xd1=u(st+1:ConfigGUI.EachPath:ed+1);
yd1=u(st+2:ConfigGUI.EachPath:ed+2);
xd2=u(st+3:ConfigGUI.EachPath:ed+3);
yd2=u(st+4:ConfigGUI.EachPath:ed+4);
xr1=u(st+5:ConfigGUI.EachPath:ed+5);
yr1=u(st+6:ConfigGUI.EachPath:ed+6);
xr2=u(st+7:ConfigGUI.EachPath:ed+7);
yr2=u(st+8:ConfigGUI.EachPath:ed+8);
set(Config.wave_posdi,'XData',xd1,'YData',yd1);%'ZData',zd1); %%% IMPORTANT HERE: WILL NEED TO DETERMINE HOW 3D PATH TRAVERSAL IS PLOTTED
set(Config.wave_posdj,'XData',xd2,'YData',yd2);%'ZData',zd2);
set(Config.wave_posri,'XData',xr1,'YData',yr1);%'ZData',zr1);
set(Config.wave_posrj,'XData',xr2,'YData',yr2);%'ZData',zr2);
drawnow limitrate;
% Update egms
st=ConfigGUI.NumPaths*ConfigGUI.EachPath+ConfigGUI.NumNodes*ConfigGUI.EachNode;
% Get the handle to the line that currently needs updating
LineHandles={Config.aegm,Config.vegm};
LineAxes={Config.AEGM,Config.VEGM};
stoptime = evalin('base','stoptime');
sTime = t;
for i=1:2
thisLineHandle = LineHandles{i};
% Get the simulation time and the block data
data = u(st+i);
newXLim = [max(0,sTime-stoptime) max(stoptime,sTime)];
set(LineAxes{i},'Xlim',newXLim);
addpoints(thisLineHandle,sTime,data);
drawnow limitrate;
end
% Update events
st=st+2;
% Get the handle to the line that currently needs updating
LineHandles={Config.aget,Config.vget,Config.ap,Config.vp,Config.as,Config.vs,Config.ar,Config.vr};
LineAxes={Config.GET,Config.P,Config.S,Config.R};
for i=1:4
thisLineHandle = LineHandles{i*2-1};
% Get the simulation time and the block data
data1 = u(st+i*2-1);
data2=-u(st+i*2);
newXLim = [max(0,sTime-stoptime) max(stoptime,sTime)];
set(LineAxes{i},'Xlim',newXLim);
addpoints(thisLineHandle,sTime,data1);
thisLineHandle = LineHandles{i*2};
addpoints(thisLineHandle,sTime,data2);
drawnow limitrate;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callback Function for click
function button_down(hObject,eventdata) %#ok
% IMPORTANT HERE: DETERMINE HOW A MOUSE CLICK IS INTERPRETED FOR A 3D GRAPH
global ConfigGUI
global nodes_name
global probes_name
cursorPoint = get(ConfigGUI.TOP_axe, 'CurrentPoint');
curX = cursorPoint(1,1);
curY = cursorPoint(1,2);
xoffset = 5;
yoffset = 5;
xLimits = get(ConfigGUI.TOP_axe, 'xlim');
yLimits = get(ConfigGUI.TOP_axe, 'ylim');
if (curX > min(xLimits) && curX < max(xLimits) && curY > min(yLimits) && curY < max(yLimits))
set(ConfigGUI.getp,'String',sprintf('(%.2f,%.2f)',curX,curY));
set(ConfigGUI.setp,'XData',curX,'YData',curY);
% Determine which is the closest Node/Probe
[~,dist1] = dsearchn([curX,curY],ConfigGUI.Node_pos);
[~,dist2] = dsearchn([curX,curY],[ConfigGUI.probe_pos.XData.',ConfigGUI.probe_pos.YData.']);
[m1,ind1]=min(dist1);
[m2,ind2]=min(dist2);
if m1 < m2
str = append('Node: ',int2str(ind1),' = ', nodes_name(ind1+1,1));
if strcmp('N',nodes_name(ind1+1,2))
str = [str,'Cell Type: N'];
back_color = [1 1 .3];
elseif strcmp('NM',nodes_name(ind1+1,2))
str = [str,'Cell Type: NM'];
back_color = [1 .8 .4];
elseif strcmp('M',nodes_name(ind1+1,2))
str = [str,'Cell Type: M'];
back_color = [1 .8 .8];
end
else
str = append('Probe: ',int2str(ind2),' = ', probes_name(ind2+1));
back_color = [.75 .75 .75];
end
% Display information for the node
delete(findobj('tag','mytooltip'))
text(curX+xoffset,curY+yoffset,str,...
'backgroundcolor',back_color,'tag','mytooltip','edgecolor',[0 0 0],...
'hittest','off')
drawnow update;
else
set(ConfigGUI.getp,'String',sprintf('(Outside)'));
end
end