Skip to content

Commit

Permalink
Massive optimization using mesh instead of plot
Browse files Browse the repository at this point in the history
mesh is alot faster than plotting for large scatters.
  • Loading branch information
grinsted committed Jul 10, 2014
1 parent cef4b42 commit bba1e05
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 5 additions & 5 deletions demoengabreen.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@
axis equal xy off tight
hold on
Vn=sqrt(sum(V(:,1:2).^2,2));
keep=signal2noise>2&C(:,1)>.8;
keep=signal2noise>2&C(:,1)>.7;
scatter(xyzA(keep,1),xyzA(keep,2),100,Vn(keep),'.')
quiver(xyzA(keep,1),xyzA(keep,2),V(keep,1)./Vn(keep),V(keep,2)./Vn(keep),.2,'k')
caxis([0 1])
colormap jet
hcb=colorbar('southoutside')
hcb=colorbar('southoutside');
if ~verLessThan('matlab', '8.4.0')
set(hcb,'limits',caxis) %workaround for a bug in Matlab 2014b preview
set(hcb,'limits',caxis); %workaround for a bug in Matlab 2014b preview
end
plot(camA.xyz(1),camA.xyz(2),'r+')
title('Velocity in metres per day')
Expand Down Expand Up @@ -248,9 +248,9 @@

caxis([0 1])
colormap jet
hcb=colorbar('southoutside')
hcb=colorbar('southoutside');
if ~verLessThan('matlab', '8.4.0')
set(hcb,'limits',caxis) %workaround for a bug in Matlab 2014b preview
set(hcb,'limits',caxis); %workaround for a bug in Matlab 2014b preview
end

plot(camA.xyz(1),camA.xyz(2),'r+')
Expand Down
18 changes: 14 additions & 4 deletions templatematch.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,15 @@
hax=axes('pos',[0 0.01 0.5 0.95]);
showimg(A);
text(0.5,1,showprogress{1},'units','normalized','vert','bottom','fontname','courier','horiz','center')
plot(points(:,1),points(:,2),'b+','markersize',2)
%plot(points(:,1),points(:,2),'b+','markersize',2)
cc=zeros(2,size(points,1));
hscatterA=mesh(points(:,[1 1])',points(:,[2 2])',zeros(2,size(points,1)),'mesh','column','marker','.','markersize',5,'cdata',cc); %bizarrely much faster than scatter
colormap jet
caxis([0 1])
hax(2)=axes('pos',[0.5 0.01 0.5 0.95]);
showimg(B); hold on
hscatterB=mesh(points(:,[1 1])'+dxyo(1),points(:,[2 2])'+dxyo(2),zeros(2,size(points,1)),'mesh','column','marker','.','markersize',5,'cdata',cc); %bizarrely much faster than scatter
caxis([0 1])
htext=text(1,1,'','units','normalized','vert','bottom','fontname','courier','horiz','right');
text(0.5,1,showprogress{end},'units','normalized','vert','bottom','fontname','courier','horiz','center')
linkaxes(hax,'xy');
Expand Down Expand Up @@ -191,13 +197,17 @@
%TODO
else
%fprintf('xy:%4.0f,%4.0f dxy:%4.1f,%4.1f C:%3.0f,%3.0f\n',points(ii,:),dxy(ii,:),round(Cout(ii,:)*100));
color=[1 min(nanmax(Cout(ii,1)-Cout(ii,2),0),1) 0];
plot(hax(1),p(1),p(2),'+','color',color,'markersize',2)
plot(hax(2),p(1)+dxy(ii,1),p(2)+dxy(ii,2),'+','color',color,'markersize',2)
%color=[1 min(nanmax(Cout(ii,1)-Cout(ii,2),0),1) 0];
% plot(hax(1),p(1),p(2),'+','color',color,'markersize',2)
% plot(hax(2),p(1)+dxy(ii,1),p(2)+dxy(ii,2),'+','color',color,'markersize',2)
cc(:,ii)=min(nanmax(Cout(ii,1)-Cout(ii,2),0),1);
set(htext,'string',sprintf('%+5.1f %+5.1f ',dxy(ii,1),dxy(ii,2)))%,'units','normalized','vert','top')
set(hprogress,'position',[0 0 ii/Np 0.01])
set(fh,'name',sprintf('Templatematch %3.0f%%',ii*100/Np));
if (cputime-lastdraw)>.3||(cputime<lastdraw)
set(hscatterA,'cdata',cc);
posB=points+dxy;
set(hscatterB,'cdata',cc,'xdata',posB(:,[1 1])','ydata',posB(:,[2 2])');
drawnow
lastdraw=cputime;
end
Expand Down

0 comments on commit bba1e05

Please sign in to comment.