rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
plot_discfunc.m
1 function p = plot_discfunc(df,params)
2 %function p = plot_discfunc(df,params)
3 %
4 % function plotting a single scalar discrete function on triangular grid
5 % A patch plot is performed as default using speified number of
6 % subsamplings of the triangles. Each patch is plotted linearly
7 % interpolated (hence only showing true values in subsampling nodes.)
8 % On each triangle-edge, subsamp_level points are inserted.
9 %
10 % p is the list of handles to the graphics primitives
11 %
12 % grid must provide the fields
14 %
15 % df must specify the discfunc-information:
16 % params.dimrange, params.pdeg
17 % evaluate: pointer to local evaluation routine to be called as
18 % evaluate(df,1:nel,locs(i,:),grid,params);
19 %
20 % optional fields of params:
21 % shrink_factor : if this flag is given, the elements are plotted shrinked
22 % axis_equal : if this flag is set, set axis to equal scale
23 % no_lines : if this flag is set, no lines are drawn
24 % show_colorbar : if this flag is set, a colorbar is drawn (default 1)
25 % colorbar_location : string specifying the position of the
26 % colorbar, e.g. 'South','EastOutside' (default), etc.
27 % clim : if this 2-vector is set, the colorbar is set to
28 % these values
29 % subsampling_level : number of intervals per edge
30 % height_factor : scalar factor using for z-plot (default 0)
31 
32 % Bernard Haasdonk 2.2.2009
33 
34 if df.dimrange>1
35  error(['plotting of vectorial functions only via extraction of ',...
36  ' scalar components!'])
37 end;
38 
39 if nargin<2
40  params = [];
41 end;
42 
43 %if ~(isfield(params,'shrink_factor'))
44 % params.shrink_factor = 1.0;
45 %end;
46 
47 if ~(isfield(params,'axis_equal'))
48  params.axis_equal = 0;
49 end;
50 
51 if ~(isfield(params,'no_lines'))
52  params.no_lines = 1;
53 end;
54 
55 if ~(isfield(params,'show_colorbar'))
56  params.show_colorbar = 1;
57 end;
58 
59 if ~(isfield(params,'colorbar_location'))
60  params.colorbar_location = 'EastOutside';
61 end;
62 
63 if ~(isfield(params,'subsampling_level'))
64  params.subsampling_level = df.pdeg;
65 end;
66 
67 if ~(isfield(params,'height_factor'))
68  params.height_factor = 0;
69 end;
70 
71 if ~(isfield(params,'plot_flat_colored'))
72  params.plot_flat_colored = 0;
73 end;
74 
75 if ~(isfield(params,'flat_color'))
76  params.flat_color = [0.75,0.75,0.75]; % grey
77 end;
78 
79 %nneigh = grid.nneigh;
80 
81 % compute vertex coordinates and scale
82 %XX = grid.X(grid.VI(:));
83 %XX = reshape(XX,size(grid.VI)); % nelements*nneigh matrix
84 %YY = grid.Y(grid.VI(:));
85 %YY = reshape(YY,size(grid.VI)); % nelements*nneigh matrix
86 
87 %CXX = repmat(grid.CX(:),1,nneigh);
88 %CYY = repmat(grid.CY(:),1,nneigh);
89 
90 % scale coordinates
91 %XX = (XX - CXX) *params.shrink_factor + CXX;
92 %YY = (YY - CYY) *params.shrink_factor + CYY;
93 
94 %set patch colors
95 %CC = data(grid.VI(:));
96 
97 % evaluate discrete function
98 
99 XX_total = zeros(0,size(df.grid.VI,2));
100 YY_total = zeros(0,size(df.grid.VI,2));
101 CC_total = zeros(0,size(df.grid.VI,2));
102 
103 XX = df.grid.X(df.grid.VI(:));
104 XX = reshape(XX,size(df.grid.VI)); % nelements*nneigh matrix
105 YY = df.grid.Y(df.grid.VI(:));
106 YY = reshape(YY,size(df.grid.VI)); % nelements*nneigh matrix
107 nel = df.grid.nelements;
108 step = 1/(params.subsampling_level+1);
109 
110 % outer subsampling triangles:
111 %keyboard;
112 for i1 = 1:(params.subsampling_level+1);
113  for i2 = 1:(params.subsampling_level+2 - i1);
114 
115  % list of local evaluation points:
116  % i-th row is i-th point of the subsamp-triangle
117  locs = [ 1-(i1+i2-2) * step, (i2-1)*step; ...
118  1-(i1+i2-1) * step, i2 * step; ...
119  1-(i1+i2-1) * step, (i2-1) * step ];
120  % for coordinate computation:
121  lincombweights = [locs(:,2), 1 - locs(:,1)-locs(:,2),locs(:,1)];
122  % for local evaluating of function
123  locs = [1 - locs(:,1)-locs(:,2),locs];
124 
125  %XX_part = zeros(size(grid.VI));
126  %YY_part = zeros(size(grid.VI));
127  CC_part = zeros(size(df.grid.VI));
128  for i=1:3
129  CC_part(:,i) = evaluate(df,1:nel,locs(i,:));
130  end;
131  XX_part = XX * lincombweights';
132  YY_part = YY * lincombweights';
133 
134  XX_total = [XX_total; XX_part];
135  YY_total = [YY_total; YY_part];
136  CC_total = [CC_total; CC_part];
137 
138  end;
139 end;
140 
141 % inner subsampling triangles:
142 for i1 = 1:(params.subsampling_level);
143  for i2 = 1:(params.subsampling_level + 1 - i1);
144 
145  % list of local evaluation points:
146  % i-th column is i-th point of the subsamp-triangle
147  locs = [ 1-(i1+i2-1) * step,(i2-1)*step; ...
148  1-(i1+i2-1) * step, i2 * step; ...
149  1-(i1+i2) * step , i2 * step ];
150  lincombweights = [locs(:,2), 1 - locs(:,1)-locs(:,2),locs(:,1)];
151  locs = [1 - locs(:,1)-locs(:,2),locs];
152 
153  %XX_part = zeros(size(grid.VI));
154  %YY_part = zeros(size(grid.VI));
155  CC_part = zeros(size(df.grid.VI));
156  for i=1:3
157  CC_part(:,i) = evaluate(df,1:nel,locs(i,:));
158  end;
159  XX_part = XX * lincombweights';
160  YY_part = YY * lincombweights';
161 
162  XX_total = [XX_total; XX_part];
163  YY_total = [YY_total; YY_part];
164  CC_total = [CC_total; CC_part];
165 
166  end;
167 end;
168 
169 %different options with different results ???
170 %figure,
171 if ~params.plot_flat_colored
172  p = patch(XX_total',YY_total',params.height_factor*CC_total', ...
173  CC_total');
174 else
175  p = patch(XX_total',YY_total',params.height_factor*CC_total', ...
176  params.flat_color);
177 end;
178 
179 %figure,
180 %p = patch(XX_total(1:10,:)',YY_total(1:10,:)',CC_total(1:10,:)');
181 %hold on;
182 %%p = patch(XX_total(11:end,:)',YY_total(11:end,:)',CC_total(11:end,:)');
183 %keyboard;
184 
185 if params.axis_equal
186  axis equal;
187  axis tight;
188 end;
189 
190 if params.no_lines
191  set(p,'linestyle','none');
192 end;
193 
194 %keyboard;
195 
196 if params.show_colorbar
197  if isfield(params,'clim')
198  set(gca,'Clim',params.clim)
199  end;
200  colorbar(params.colorbar_location);
201 end;
202 hold on;
203 
204 if ~params.no_lines & (params.height_factor == 0)
205  p2 = plot(df.grid);
206  set(p2,'Color','k')
207  p = [p(:);p2];
208 end;
209 
210 %| \docupdate