Skip to content

Commit

Permalink
topoplot3d prevent crash when isolines out of data bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
dnacombo committed Mar 23, 2023
1 parent fcb6113 commit c740564
Showing 1 changed file with 48 additions and 47 deletions.
95 changes: 48 additions & 47 deletions plotting/ft_plot_topo3d.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,54 +175,55 @@ function ft_plot_topo3d(pos, val, varargin)
cntlevel = [cntlevel; ones(contour(cnt_indx).n,1) * isolines(cnt_indx)];
end

X = [intersect1(:,1) intersect2(:,1)]';
Y = [intersect1(:,2) intersect2(:,2)]';
C = [cntlevel(:) cntlevel(:)]';

if size(pos,2)>2
Z = [intersect1(:,3) intersect2(:,3)]';
else
Z = zeros(2, length(cntlevel));
end

switch contourstyle
case 'black'
% make black-white contours
hc = [];
for i=1:length(cntlevel)
if cntlevel(i)>0
linestyle = '-';
linewidth = 1;
elseif cntlevel(i)<0
linestyle = '--';
linewidth = 1;
else
linestyle = '-';
linewidth = 2;
end
h1 = patch('XData', X(:,i), 'Ydata', Y(:,i), ...
'ZData', Z(:,i), 'CData', C(:,i), ...
'facecolor','none','edgecolor','black', ...
'linestyle', linestyle, 'linewidth', linewidth, ...
'userdata',cntlevel(i));
hc = [hc; h1];
end

case 'color'
% make full-color contours
hc = [];
for i=1:length(cntlevel)
h1 = patch('XData', X(:,i), 'Ydata', Y(:,i), ...
'ZData', Z(:,i), 'CData', C(:,i), ...
'facecolor','none','edgecolor','flat',...
'userdata',cntlevel(i));
hc = [hc; h1];
if ~(isempty(intersect1) || isempty(intersect2))
X = [intersect1(:,1) intersect2(:,1)]';
Y = [intersect1(:,2) intersect2(:,2)]';
C = [cntlevel(:) cntlevel(:)]';

if size(pos,2)>2
Z = [intersect1(:,3) intersect2(:,3)]';
else
Z = zeros(2, length(cntlevel));
end

otherwise
ft_error('unsupported contourstyle');
end % switch contourstyle


switch contourstyle
case 'black'
% make black-white contours
hc = [];
for i=1:length(cntlevel)
if cntlevel(i)>0
linestyle = '-';
linewidth = 1;
elseif cntlevel(i)<0
linestyle = '--';
linewidth = 1;
else
linestyle = '-';
linewidth = 2;
end
h1 = patch('XData', X(:,i), 'Ydata', Y(:,i), ...
'ZData', Z(:,i), 'CData', C(:,i), ...
'facecolor','none','edgecolor','black', ...
'linestyle', linestyle, 'linewidth', linewidth, ...
'userdata',cntlevel(i));
hc = [hc; h1];
end

case 'color'
% make full-color contours
hc = [];
for i=1:length(cntlevel)
h1 = patch('XData', X(:,i), 'Ydata', Y(:,i), ...
'ZData', Z(:,i), 'CData', C(:,i), ...
'facecolor','none','edgecolor','flat',...
'userdata',cntlevel(i));
hc = [hc; h1];
end

otherwise
ft_error('unsupported contourstyle');
end % switch contourstyle
end
end % plot the contours

axis off
Expand Down

0 comments on commit c740564

Please sign in to comment.