1function topo2(V,HDR,maplimits)
2% TOPO2 makes a 2-D topographic map
3%
4%  topo2(value,HDR [,limits]);
5%
6%
7%
8
9%	$Id$
10%	Copyright (C) 2007,2008 by Alois Schloegl <alois.schloegl@gmail.com>
11%       This is part of the BIOSIG-toolbox http://biosig.sf.net/
12%
13%    BioSig is free software: you can redistribute it and/or modify
14%    it under the terms of the GNU General Public License as published by
15%    the Free Software Foundation, either version 3 of the License, or
16%    (at your option) any later version.
17%
18%    BioSig is distributed in the hope that it will be useful,
19%    but WITHOUT ANY WARRANTY; without even the implied warranty of
20%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21%    GNU General Public License for more details.
22%
23%    You should have received a copy of the GNU General Public License
24%    along with BioSig.  If not, see <http://www.gnu.org/licenses/>.
25
26
27
28Label = [];
29if isstruct(HDR)
30	if isfield(HDR,'ELEC')
31		XYZ = HDR.ELEC.XYZ;
32		Label = HDR.Label;
33	elseif isfield(HDR,'XYZ')
34		XYZ = HDR.XYZ;
35	end;
36elseif isnumeric(HDR),
37	XYZ = HDR;
38end;
39size(XYZ),size(V),
40
41ix = find(all(~isnan(XYZ),2) & ~isnan(V(:)));
42
43R   = sqrt(sum(XYZ(ix,:).^2,2));
44th  = atan(XYZ(ix,2)./XYZ(ix,1)) + pi*(XYZ(ix,1)<0);
45rd  = acos(XYZ(ix,3)./R);
46th(isnan(th))=0;
47V = V(ix);
48Label = Label(ix);
49
50if nargin<3,
51	maplimits=[-1,1]*max(abs(V));
52%elseif isnumeric(maplimits)
53elseif ischar(maplimits)
54 	if strcmp(maplimits,'absmax');
55 		maplimits=[-1,1]*max(abs(V));
56	elseif strcmp(maplimits,'maxmin');
57		maplimits=[min(V),max(V)];
58	end;
59end;
60
61
62r   = max(rd)*1.05;
63x   = -rd.*sin(th-pi/2);
64y   = rd.*cos(th-pi/2);
65
66%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67%%%%%% interpolation         %%%%%%%%
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69GRID_SCALE = 67;
70xi = linspace(-r,+r,GRID_SCALE);
71yi = linspace(-r,+r,GRID_SCALE);
72
73[Xi,Yi,Zi] = griddata(x,y,V,xi',yi,'invdist'); % interpolate data
74
75Zi(Xi.^2 + Yi.^2 > r.^2) = NaN;
76
77%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78%%%%%% make topographic plot %%%%%%%%
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80
81%surf(Xi,Yi,Zi);
82caxis(maplimits);
83surface(Xi,Yi,zeros(size(Zi)),Zi,'EdgeColor','none','FaceColor','flat');
84hold on;
85%contour(Xi,Yi,Zi,6,'k');
86t = 0:.01:2*pi;
87plot(x,y,'k.',r*sin([-.1,0,.1]'),r*[cos([-.1,0,.1]')+[0,.1,0]'],'k-',r*sin(t),r*cos(t),'k-');
88%for k=1:length(V),text(x(k),y(k),Label{k}),end;
89set(gca,'visible','off','xlim',[-1,1]*r,'ylim',[-1,1.1]*r);
90hold off;
91
92
93