-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpolateSurface.m
67 lines (49 loc) · 1.41 KB
/
interpolateSurface.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function interpolateSurface(positions,values,mode,minLimit,maxLimit)
if (~exist('mode','var'))
mode=1
end
if (~exist('minLimit','var'))
minLimit=min(values);
end
if (~exist('maxLimit','var'))
maxLimit=max(values);
end
if(maxLimit == minLimit)
maxLimit = 1.1*minLimit;
end
[xi yi zi] = computeSurface(positions,values);
if mode==1
surf(xi,yi,zi);
elseif mode==2
% colormap(gray);
pcolor(xi,yi,zi);
colorbar;
%caxis([minLimit maxLimit]);
%hc = colorbar;
%set(hc,'YLim',[minLimit maxLimit]);
%caxis(hc,[minLimit maxLimit]);
elseif mode==3
[tmp,h] = contour(xi,yi,zi,[.1:.1:1]);
set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2);
text_handle = clabel(tmp,h);
set(text_handle,'BackgroundColor',[1 1 .6],'Edgecolor',[.7 .7 .7])
elseif mode==4
[cs,h] = contour(xi,yi,zi);
clabel(cs,h,'fontsize',15);%,'labelspacing',72);
end
function [xi yi zi] = computeSurface(positions, values)
num_nodes = size(positions,1);
x = positions(:,1);
y = positions(:,2);
z = values;
maxx = max(positions(:,1));
minx = min(positions(:,1));
maxy = max(positions(:,2));
miny = min(positions(:,2));
grid_size = 30;
[xi yi] = meshgrid(minx:(maxx-minx)/grid_size:maxx,miny:(maxy-miny)/grid_size:maxy);
%zin = griddata(x,y,z,xi,yi,'nearest');
zi = griddata(x,y,z,xi,yi,'cubic');
% zi = griddata(x,y,z,xi,yi,'nearest');
%wrongs = find(isnan(zi));
%zi(wrongs) = zin(wrongs);