Commit de98c728 authored by Mike Cichonski's avatar Mike Cichonski
Browse files

optimized efficiency of the vised plot in MATLAB 2014 and later versions

parent b265dcb3
......@@ -220,7 +220,13 @@ MAXEVENTSTRING = 10;
DEFAULT_AXES_POSITION = [0.0964286 0.15 0.842 0.75-(MAXEVENTSTRING-5)/100];
% dimensions of main EEG axes
ORIGINAL_POSITION = [50 50 800 500];
persistent ax0;
persistent ax1;
persistent etime;
persistent eelec;
persistent evalue;
if nargin < 1
help ve_eegplot
return
......@@ -437,11 +443,11 @@ if ~isstr(data) % If NOT a 'noui' call or a callback from uicontrols
clf;
% Background axis
% ---------------
% ---------------
ax0 = axes('tag','backeeg','parent',figh,...
'Position',DEFAULT_AXES_POSITION,...
'Box','off','xgrid','off', 'xaxislocation', 'top');
% Drawing axis
% ---------------
YLabels = num2str((1:g.chans)'); % Use numbers as default
......@@ -461,7 +467,7 @@ if ~isstr(data) % If NOT a 'noui' call or a callback from uicontrols
'Color','none',...
'XColor',DEFAULT_AXIS_COLOR,...
'YColor',DEFAULT_AXIS_COLOR);
if isstr(g.eloc_file) | isstruct(g.eloc_file) % Read in electrode names
if isstruct(g.eloc_file) & length(g.eloc_file) > size(data,1)
g.eloc_file(end) = []; % common reference channel location
......@@ -553,15 +559,15 @@ if ~isstr(data) % If NOT a 'noui' call or a callback from uicontrols
'Position',posbut(4,:), ...
'Tag','Pushbutton4',...
'string','>>',...
'Callback',['global in_callback;', ...
'if isempty(in_callback);in_callback=1;', ...
' try ve_eegplot(''drawp'',4);', ...
' clear global in_callback;', ...
' catch error_struct;', ...
' clear global in_callback;', ...
' throw(error_struct);', ...
' end;', ...
'else;return;end;']);
'Callback',['global in_callback;', ...
'if isempty(in_callback);in_callback=1;', ...
' try ve_eegplot(''drawp'',4);', ...
' clear global in_callback;', ...
' catch error_struct;', ...
' clear global in_callback;', ...
' throw(error_struct);', ...
' end;', ...
'else;return;end;']);
% Text edit fields: ESpacing
......@@ -1083,8 +1089,16 @@ u(22) = uicontrol('Parent',figh, ...
h = findobj(gcf, 'tag', 'eegslider');
set(h, 'backgroundcolor', BUTTON_COLOR);
set(figh, 'visible', 'on');
if isempty(etime);
etime = findobj('tag','Etime','parent',figh);
end;
if isempty(eelec);
eelec = findobj('tag','Eelec','parent',figh);
end;
if isempty(evalue);
evalue = findobj('tag','Evalue','parent',figh);
end;
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% End Main Function
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -1104,9 +1118,6 @@ else
if strcmp(get(figh,'tag'),'dialog')
figh = get(figh,'UserData');
end
ax0 = findobj('tag','backeeg','parent',figh); % axes handle
ax1 = findobj('tag','eegaxis','parent',figh); % axes handle
g = get(figh,'UserData');
data = get(ax1,'UserData');
ESpacing = findobj('tag','ESpacing','parent',figh); % ui handle
......@@ -1178,8 +1189,8 @@ else
end;
if strcmpi(g.plotdata2, 'off')
axes(ax1)
obj_2_clear = findobj(ax1,'tag','text');
cla(obj_2_clear); % clear all except text
obj_2_clear = findobj('-regexp','tag','text_*','-or','-regexp','tag','marker_*');
cla(obj_2_clear); % clear all except text and markers
end;
oldspacing = g.spacing;
......@@ -1194,13 +1205,14 @@ else
%% HANDLE MARKING ...
%calculate x ifinterval for channel tags...
%calculate x ifinterval for channel tags...
figdim=axis;
tag_x_int=figdim(2)*g.inter_tag_int;
% plot channels whose order is < 0.
manual_mark_ind=find(strcmp('manual',{g.chan_marks_struct.label}));
mark_inds=find([g.chan_marks_struct.order]<0);
n_mark_inds=length(mark_inds);
tot_marks = length(g.chan_marks_struct);
for fi=1:n_mark_inds;
chan_inds=find(g.chan_marks_struct(mark_inds(fi)).flags);
tmp_color=g.chan_marks_struct(mark_inds(fi)).line_color;
......@@ -1211,22 +1223,22 @@ else
tmp_color=[.7 .7 .7];
end
end
plot_p1 = 1+tag_x_int*mark_inds(n_mark_inds-(fi-1));
plot_p2 = (g.chans-(chan_inds-1))*g.spacing;
plot_colour = g.chan_marks_struct(mark_inds(fi)).tag_color;
for ci=1:length(chan_inds);
plot_p1 = 1+tag_x_int*(tot_marks-(mark_inds(fi)-1));
plot_p2 = (g.chans-(chan_inds-1))*g.spacing;
plot_colour = g.chan_marks_struct(mark_inds(fi)).tag_color;
for ci=1:length(chan_inds);
%plot tick...
plot(plot_p1, plot_p2(ci),'<', ...
'MarkerEdgeColor', plot_colour, ...
'MarkerFaceColor', plot_colour, ...
'MarkerSize', 8,'tag',['marker_' num2str(chan_inds(ci))]);
%plot data
'MarkerSize', 8,'tag',['marker_' num2str(chan_inds(ci)) '_' g.chan_marks_struct(mark_inds(fi)).label]);
%change line color
if fi==manual_mark_ind || ~g.chan_marks_struct(manual_mark_ind).flags(chan_inds(ci));
tmp_offset=(g.chans-(chan_inds(ci)-1))*g.spacing-(meandata(chan_inds(ci)));
line(1:length(low_high_range), ...
data(chan_inds(ci),low_high_range) + tmp_offset, zlowhigh, ...
'color', tmp_color, 'clipping','on','tag',['line_' num2str(chan_inds(ci))]);
end
tmp_offset=(g.chans-(chan_inds(ci)-1))*g.spacing-(meandata(chan_inds(ci)));
line(1:length(low_high_range), ...
data(chan_inds(ci),low_high_range) + tmp_offset, zlowhigh, ...
'color', tmp_color, 'clipping','on','tag',['line_' num2str(chan_inds(ci))]);
end
end
end
......@@ -1263,9 +1275,9 @@ else
'CData',cdat, ...
'LineStyle','none','tag',['mark_' g.time_marks_struct(tmi).label]);
alpha(sh,g.marks_col_alpha);
if p1==0;
if isempty(findobj('tag',['text_' g.time_marks_struct(tmi).label]));
text(figdim(2),ylims(1)+inter_time_mark_offset*tmi+(time_marks_offset(i))-(inter_time_mark_offset*length(g.time_marks_struct)), ...
g.time_marks_struct(tmi).label,'color',g.time_marks_struct(tmi).color,'interpreter','none','tag','text');
g.time_marks_struct(tmi).label,'color',g.time_marks_struct(tmi).color,'interpreter','none','tag',['text_' g.time_marks_struct(tmi).label]);
end
end
end
......@@ -1280,18 +1292,25 @@ else
end
end
for ci=1:length(chan_inds);
tmp_offset=(g.chans-(chan_inds(ci)-1))*g.spacing-(meandata(chan_inds(ci)));
line(1:length(lowlim:highlim),data(chan_inds(ci),lowlim:highlim) + tmp_offset, ones(1,length(lowlim:highlim))*100, ...
'color', tmp_color, 'clipping','on','tag',['line_' num2str(chan_inds(ci))]);
%change line color
if fi==manual_mark_ind || ~g.chan_marks_struct(manual_mark_ind).flags(chan_inds(ci));
tmp_offset=(g.chans-(chan_inds(ci)-1))*g.spacing-(meandata(chan_inds(ci)));
line(1:length(low_high_range), ...
data(chan_inds(ci),low_high_range) + tmp_offset, zlowhigh, ...
'color', tmp_color, 'clipping','on','tag',['line_' num2str(chan_inds(ci))]);
end
end
% plot channels whose order is > 0.
mark_inds = find([g.chan_marks_struct.order]>0);
manual_mark_ind = strcmp('manual',{g.chan_marks_struct.label});
n_mark_inds=length(mark_inds);
tot_marks = length(g.chan_marks_struct);
for fi=1:length(mark_inds);
chan_inds = [];
chan_inds = find(g.chan_marks_struct(mark_inds(fi)).flags);
tmp_color = g.chan_marks_struct(mark_inds(fi)).line_color;
plot_p1 = 1+tag_x_int*(tot_marks-(mark_inds(fi)-1));
if strcmp(g.plotdata2, 'on')
if length(g.color) == 2
tmp_color = g.color{2};
......@@ -1301,10 +1320,10 @@ else
end
for ci=1:length(chan_inds);
%plot tick...
plot(1+tag_x_int*mark_inds(fi),(g.chans-(chan_inds(ci)-1))*g.spacing,'<', ...
plot(plot_p1,(g.chans-(chan_inds(ci)-1))*g.spacing,'<', ...
'MarkerEdgeColor', g.chan_marks_struct(mark_inds(fi)).tag_color, ...
'MarkerFaceColor', g.chan_marks_struct(mark_inds(fi)).tag_color, ...
'MarkerSize',8,'tag',['marker_' num2str(chan_inds(ci))]);
'MarkerSize',8,'tag',['marker_' num2str(chan_inds(ci)) '_' g.chan_marks_struct(mark_inds(fi)).label]);
%plot data
if ~g.chan_marks_struct(manual_mark_ind).flags(chan_inds(ci))
tmp_offset=(g.chans-(chan_inds(ci)-1))*g.spacing-(meandata(chan_inds(ci)));
......@@ -1368,9 +1387,6 @@ else
case 'drawb' % Draw background ******************************************************
% Redraw EEG and change position
ax0 = findobj('tag','backeeg','parent',gcf); % axes handle
ax1 = findobj('tag','eegaxis','parent',gcf); % axes handle
g = get(gcf,'UserData'); % Data (Note: this could also be global)
% Plot data and update axes
......@@ -1575,7 +1591,6 @@ else
case 'draws'
% Redraw EEG and change scale
ax1 = findobj('tag','eegaxis','parent',gcf); % axes handle
g = get(gcf,'UserData');
data = get(ax1, 'userdata');
ESpacing = findobj('tag','ESpacing','parent',gcf); % ui handle
......@@ -1726,7 +1741,6 @@ else
end;
eyeaxes = findobj('tag','eyeaxes','parent',figh);
ax1 = findobj('tag','eegaxis','parent',gcf); % axes handle
YLim = get(ax1, 'ylim');
ESpacing = findobj('tag','ESpacing','parent',figh);
......@@ -1756,6 +1770,7 @@ else
set(eyeaxes, 'tag', 'eyeaxes');
case 'noui'
dbstop in ve_eegplot.m at 1774;
if ~isempty(varargin)
ve_eegplot( varargin{:} ); fig = gcf;
else
......@@ -1779,12 +1794,10 @@ else
case 'zoom' % if zoom
fig = varargin{1};
ax1 = findobj('tag','eegaxis','parent',fig);
ax2 = findobj('tag','backeeg','parent',fig);
tmpxlim = get(ax1, 'xlim');
tmpylim = get(ax1, 'ylim');
tmpxlim2 = get(ax2, 'xlim');
set(ax2, 'xlim', get(ax1, 'xlim'));
tmpxlim2 = get(ax0, 'xlim');
set(ax0, 'xlim', get(ax1, 'xlim'));
g = get(fig,'UserData');
% deal with abscissa
......@@ -1879,9 +1892,8 @@ else
case 'defmotioncom'
fig = varargin{1};
g = get(fig,'UserData');
ax1 = findobj('tag','backeeg','parent',fig);
tmppos = get(ax1, 'currentpoint');
tmppos = get(ax0, 'currentpoint');
if g.trialstag ~= -1,
lowlim = round(g.time*g.trialstag+1);
......@@ -1893,12 +1905,7 @@ else
set(fig,'UserData', g);
ve_eegplot('drawb');
else
hh = findobj('tag','Etime','parent',fig);
if g.trialstag ~= -1,
set(hh, 'string', num2str(mod(tmppos(1)+lowlim-1,g.trialstag)/g.trialstag*(g.limits(2)-g.limits(1)) + g.limits(1)));
else set(hh, 'string', num2str((tmppos(1)+lowlim-1)/g.srate)); % put g.time in the box
end;
ax1 = findobj('tag','eegaxis','parent',fig);
etime = findobj('tag','Etime','parent',fig);
tmppos = get(ax1, 'currentpoint');
xlims=get(ax1,'XLim');
ylims=get(ax1,'YLim');
......@@ -1919,26 +1926,30 @@ else
set(eph,'enable','off');drawnow;set(eph,'enable','on');
on_data_ax=1;
end
end
if (tmppos(1,1)<xlims(1)||tmppos(1,1)>xlims(2))|| ...
(tmppos(1,2)<ylims(1)||tmppos(1,2)>ylims(2))
if ~isempty(on_data_ax);clear global on_data_ax;end
end
tmpelec = round(tmppos(1,2) / g.spacing);
tmpelec = min(max(double(tmpelec), 1),g.chans);
labls = get(ax1, 'YtickLabel');
hh = findobj('tag','Eelec','parent',fig); % put electrode in the box
if ~g.envelope
set(hh, 'string', labls(tmpelec+1,:));
else
set(hh, 'string', ' ');
end
hh = findobj('tag','Evalue','parent',fig);
if ~g.envelope
eegplotdata = get(ax1, 'userdata');
set(hh, 'string', num2str(eegplotdata(g.chans+1-tmpelec, min(g.frames,max(1,double(round(tmppos(1)+lowlim))))))); % put value in the box
else
set(hh,'string',' ');
if g.trialstag ~= -1,
set(etime, 'string', num2str(mod(tmppos(1)+lowlim-1,g.trialstag)/g.trialstag*(g.limits(2)-g.limits(1)) + g.limits(1)));
else set(etime, 'string', num2str((tmppos(1)+lowlim-1)/g.srate)); % put g.time in the box
end;
if (tmppos(1,1)<xlims(1)||tmppos(1,1)>xlims(2))|| ...
(tmppos(1,2)<ylims(1)||tmppos(1,2)>ylims(2))
if ~isempty(on_data_ax);clear global on_data_ax;end
end
tmpelec = round(tmppos(1,2) / g.spacing);
tmpelec = min(max(double(tmpelec), 1),g.chans);
labls = get(ax1, 'YtickLabel');
eelec = findobj('tag','Eelec','parent',fig); % put electrode in the box
if ~g.envelope
set(eelec, 'string', labls(tmpelec+1,:));
else
set(eelec, 'string', ' ');
end
evalue = findobj('tag','Evalue','parent',fig);
if ~g.envelope
eegplotdata = get(ax1, 'userdata');
set(evalue, 'string', num2str(eegplotdata(g.chans+1-tmpelec, min(g.frames,max(1,double(round(tmppos(1)+lowlim))))))); % put value in the box
else
set(evalue,'string',' ');
end
end
end;
......@@ -1950,9 +1961,8 @@ else
if ~isstruct(g.eloc_file) || ~isfield(g.eloc_file, 'theta') || isempty( [ g.eloc_file.theta ])
return;
end;
ax1 = findobj('tag','backeeg','parent',fig);
tmppos = get(ax1, 'currentpoint');
ax1 = findobj('tag','eegaxis','parent',fig); % axes handle
tmppos = get(ax0, 'currentpoint');
% plot vertical line
yl = ylim;
plot([ tmppos tmppos ], yl, 'color', [0.8 0.8 0.8]);
......@@ -1982,7 +1992,6 @@ else
case 'defupcom'
fig = varargin{1};
g = get(fig,'UserData');
ax1 = findobj('tag','backeeg','parent',fig);
g.incallback = 0;
set(fig,'UserData', g); % early save in case of bug in the following
if strcmp(g.mocap,'on'), g.winrej = g.winrej(end,:);end; % nima
......@@ -2026,8 +2035,7 @@ else
fig = varargin{1};
g = get(fig,'UserData');
ax1 = findobj('tag','backeeg','parent',fig);
tmppos = get(ax1, 'currentpoint');
tmppos = get(ax0, 'currentpoint');
if strcmp(get(fig, 'SelectionType'),'normal');
g = get(fig,'UserData'); % get data of backgroung image {g.trialstag g.winrej incallback}
if g.incallback ~= 1 % interception of nestest calls
......@@ -2045,8 +2053,7 @@ else
if any(Allwin) % remove the mark or select electrode if necessary
lowlim = find(Allwin==1);
if g.setelectrode % select electrode
ax2 = findobj('tag','eegaxis','parent',fig);
tmppos = get(ax2, 'currentpoint');
tmppos = get(ax1, 'currentpoint');
tmpelec = g.chans + 1 - round(tmppos(1,2) / g.spacing);
tmpelec = min(max(tmpelec, 1), g.chans);
g.winrej(lowlim,tmpelec+5) = ~g.winrej(lowlim,tmpelec+5); % set the electrode
......@@ -2072,7 +2079,7 @@ else
end;
end;
set(fig,'UserData', g);
%ve_eegplot('drawp', 0); % redraw background
ve_eegplot('drawb', 0); % redraw background
end;
end;
end;
......
......@@ -237,7 +237,7 @@ if ~isempty(g.add_winrej_mark) || ~isempty(g.add_page_mark) || ~isempty(g.rm_win
end
set(gcf, 'userdata', udf);
if (isfield(g,'awm') && strcmp(g.awm,'manual')); % || (isfield(g,'rwm') && strcmp(g.rwm,'manual'));
if (isfield(g,'awm') && strcmp(g.awm,'manual')) || (isfield(g,'rwm') && strcmp(g.rwm,'manual'));
figh = gcf; % figure handle
if strcmp(get(figh,'tag'),'dialog')
......@@ -273,8 +273,8 @@ if ~isempty(g.add_winrej_mark) || ~isempty(g.add_page_mark) || ~isempty(g.rm_win
end;
set(figh, 'userdata', udf);
lowlim = round(udf.time*multiplier+1)
highlim = round(min((udf.time+udf.winlength)*multiplier+2,udf.frames))
lowlim = round(udf.time*multiplier+1);
highlim = round(min((udf.time+udf.winlength)*multiplier+2,udf.frames));
low_high_range = lowlim:highlim;
zlowhigh = zeros(1,length(low_high_range));
......@@ -300,15 +300,14 @@ if ~isempty(g.add_winrej_mark) || ~isempty(g.add_page_mark) || ~isempty(g.rm_win
cdat=tmp_cdat;
for i=1:length(time_marks_offset)
if isfield(g,'awm');
sh=surf(1:size(cflags,2), ...
[ylims(1)+inter_time_mark_offset*1+(time_marks_offset(i))-(inter_time_mark_offset*length(udf.time_marks_struct)), ...
ylims(1)+inter_time_mark_offset*1+(time_marks_offset(i))+inter_time_mark_offset-(inter_time_mark_offset*length(udf.time_marks_struct))], ...
cflags, ...
'CData',cdat, ...
'LineStyle','none','tag',['mark_' udf.time_marks_struct(1).label]);
alpha(sh,udf.marks_col_alpha);
end
delete (findobj('tag','mark_manual'));
sh=surf(1:size(cflags,2), ...
[ylims(1)+inter_time_mark_offset*1+(time_marks_offset(i))-(inter_time_mark_offset*length(udf.time_marks_struct)), ...
ylims(1)+inter_time_mark_offset*1+(time_marks_offset(i))+inter_time_mark_offset-(inter_time_mark_offset*length(udf.time_marks_struct))], ...
cflags, ...
'CData',cdat, ...
'LineStyle','none','tag',['mark_' udf.time_marks_struct(1).label]);
alpha(sh,udf.marks_col_alpha);
end
return
end
......
......@@ -114,7 +114,7 @@ properties = [ ...
...
...
PropertyGridField('srate', vised_config.srate, ...
'Type', PropertyType('char','row'), ...
'Type', PropertyType('denserealdouble','matrix'), ...
'Category', 'eegplot options', ...
'DisplayName', 'sampling rate [srate]', ...
'Description', ['Sampling rate in Hz {default|0: 256 Hz}. ' ...
......
......@@ -63,7 +63,6 @@ com = ''; % this initialization ensure that the function will return something
% if the user press the cancel button
% display help if not enough arguments
% ------------------------------------
udf=get(gcf, 'userdata');
uda=get(gca,'userdata');
......@@ -183,6 +182,8 @@ if nargin < 5
%else
% g.eloc_file(g.eventedit.ChanIndex).badchan=0;
%end
mark_inds=find([udf.chan_marks_struct.order]);
n_mark_inds=length(mark_inds);
mark_ind=find(strcmp(g.quick_chanflag,{udf.chan_marks_struct.label}));
%calculate x ifinterval for channel tags...
figdim=axis;
......@@ -192,18 +193,18 @@ if nargin < 5
plot_p2 = (udf.chans-(chan_inds-1))*udf.spacing;
if udf.chan_marks_struct(mark_ind).flags(g.eventedit.ChanIndex)==0;
udf.chan_marks_struct(mark_ind).flags(g.eventedit.ChanIndex)=1;
plot_p1 = 1+tag_x_int*mark_inds(n_mark_inds-(mark_ind-1));
%replot tick...
delete(findobj(gcf,'tag',['marker_' num2str(g.eventedit.ChanIndex)]));
plot(plot_p1, plot_p2(chan_inds(g.eventedit.ChanIndex)),'<', ...
'MarkerEdgeColor', udf.chan_marks_struct(mark_ind).tag_color, ...
'MarkerFaceColor', udf.chan_marks_struct(mark_ind).tag_color, ...
'MarkerSize', 8,'tag',['marker_' num2str(g.eventedit.ChanIndex)]);
'MarkerSize', 8,'tag',['marker_' num2str(g.eventedit.ChanIndex) '_' g.quick_chanflag]);
%change line color
set(findobj(gcf,'tag',['line_' num2str(g.eventedit.ChanIndex)]), ...
'Color',udf.chan_marks_struct(mark_ind).line_color);
else
udf.chan_marks_struct(mark_ind).flags(g.eventedit.ChanIndex)=0;
non_manual_ind = find(~strcmp(g.quick_chanflag,{udf.chan_marks_struct.label}));
non_manual_ind = find(~strcmp('manual',{udf.chan_marks_struct.label}));
for mi=non_manual_ind(1):non_manual_ind(end);
if ismember(g.eventedit.ChanIndex,find(sum([udf.chan_marks_struct.flags],2)==0));
tmp_color=udf.color{:};
......@@ -220,11 +221,7 @@ if nargin < 5
end
if udf.chan_marks_struct(mi).flags(g.eventedit.ChanIndex)==1;
%replot tick...
delete(findobj(gcf,'tag',['marker_' num2str(g.eventedit.ChanIndex)]));
plot(1+tag_x_int*mi,(udf.chans-(g.eventedit.ChanIndex-1))*udf.spacing,'<', ...
'MarkerEdgeColor', udf.chan_marks_struct(mi).tag_color, ...
'MarkerFaceColor', udf.chan_marks_struct(mi).tag_color, ...
'MarkerSize', 8,'tag',['marker_' num2str(g.eventedit.ChanIndex)]);
delete(findobj(gcf,'tag',['marker_' num2str(g.eventedit.ChanIndex) '_' g.quick_chanflag]));
set(findobj(gcf,'tag',['line_' num2str(g.eventedit.ChanIndex)]), ...
'Color',udf.chan_marks_struct(mi).line_color);
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment