Skip to content

Commit

Permalink
Fix fastScatterMesh.m, zbuffer wrongly defined which can cause errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggalibert committed Mar 27, 2017
1 parent 0a6353e commit 87866cf
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions Util/fastScatterMesh.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,17 @@

minClim = colLimits(1);
maxClim = colLimits(2);

% Posting by Boris Babic for the method. see http://www.mathworks.com/matlabcentral/newsreader/view_thread/22966
% as referenced in
% http://au.mathworks.com/matlabcentral/fileexchange/47205-fastscatter-m
% http://au.mathworks.com/matlabcentral/fileexchange/53580-fastscatterm

% index of valid data
ix=find(isfinite(cdata + xdata + ydata));

if isempty(ix) | numel(ix) < 2
hwin = [];
ix = find(isfinite(cdata + xdata + ydata));
if isempty(ix) || numel(ix) < 2
return;
end

if mod(length(ix),2)==1
ix(end+1)=ix(end);
if mod(length(ix), 2) == 1
ix(end+1) = ix(end);
end

ixLength = length(ix);

% normalize cdata
normData = (cdata(ix) - minClim) / ( maxClim - minClim );
[~, idx] = histc(normData, 0: 1/nColors : 1);
Expand All @@ -55,26 +46,26 @@

switch zType
case 'ascending',
zBuffer = linspace(0, 1, ixLength);
zBuffer = linspace(0, 1, nColors);
case 'descending',
zBuffer = linspace(1, 0, ixLength) ;
zBuffer = linspace(1, 0, nColors) ;
case 'triangle',
zBuffer = [linspace(0, 1, ixLength/2) linspace(1, 0, ixLength/2)];
zBuffer = [linspace(0, 1, nColors/2) linspace(1, 0, nColors/2)];
case 'vee',
zBuffer = [linspace(1, 0, ixLength/2) linspace(0, 1, ixLength/2)];
zBuffer = [linspace(1, 0, nColors/2) linspace(0, 1, nColors/2)];
case 'flat',
zBuffer = zeros(size(ix));
case 'parabolic'
jj = (0:ixLength-1)';
zBuffer = 1 - (2*jj/ixLength - 1).^2;
jj = (0:nColors-1)';
zBuffer = 1 - (2*jj/nColors - 1).^2;
case 'hamming'
thalf=pi/ixLength*((1-ixLength):2:0)'; % first half sample locations
thalf=pi/nColors*((1-nColors):2:0)'; % first half sample locations
hwin=.54+.46*cos(thalf); % first half window
zBuffer=[hwin; hwin(floor(ixLength/2):-1:1)]; % full window
zBuffer=[hwin; hwin(floor(nColors/2):-1:1)]; % full window
case 'hann'
thalf=pi/ixLength*((1-ixLength):2:0)'; % first half sample locations
thalf=pi/nColors*((1-nColors):2:0)'; % first half sample locations
hwin=.5+.5*cos(thalf); % first half window
zBuffer=[hwin; hwin(floor(ixLength/2):-1:1)]; % full window
zBuffer=[hwin; hwin(floor(nColors/2):-1:1)]; % full window
otherwise
warning('Unknown marker zbuffer method, using flat');
zBuffer = zeros(size(ix));
Expand Down

0 comments on commit 87866cf

Please sign in to comment.