1 function p = plot_discfunc(df,params)
2 %
function p = plot_discfunc(df,params)
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.
10 % p is the list of handles to the graphics primitives
12 % grid must provide the fields
13 % X,Y,VI,CX,CY,nelements,nvertices and nneigh;
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);
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
29 % subsampling_level : number of intervals per edge
30 % height_factor : scalar factor
using for z-plot (
default 0)
32 % Bernard Haasdonk 2.2.2009
35 error([
'plotting of vectorial functions only via extraction of ',...
36 ' scalar components!'])
43 %if ~(isfield(params,'shrink_factor'))
44 % params.shrink_factor = 1.0;
47 if ~(isfield(params,'axis_equal'))
48 params.axis_equal = 0;
51 if ~(isfield(params,'no_lines'))
55 if ~(isfield(params,'show_colorbar'))
56 params.show_colorbar = 1;
59 if ~(isfield(params,'colorbar_location'))
60 params.colorbar_location = 'EastOutside';
63 if ~(isfield(params,'subsampling_level'))
64 params.subsampling_level = df.pdeg;
67 if ~(isfield(params,'height_factor'))
68 params.height_factor = 0;
71 if ~(isfield(params,'plot_flat_colored'))
72 params.plot_flat_colored = 0;
75 if ~(isfield(params,'flat_color'))
76 params.flat_color = [0.75,0.75,0.75]; % grey
79 %nneigh = grid.nneigh;
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
87 %CXX = repmat(grid.CX(:),1,nneigh);
88 %CYY = repmat(grid.CY(:),1,nneigh);
91 %XX = (XX - CXX) *params.shrink_factor + CXX;
92 %YY = (YY - CYY) *params.shrink_factor + CYY;
95 %CC = data(grid.VI(:));
97 % evaluate discrete function
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));
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);
110 % outer subsampling triangles:
112 for i1 = 1:(params.subsampling_level+1);
113 for i2 = 1:(params.subsampling_level+2 - i1);
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];
125 %XX_part = zeros(size(grid.VI));
126 %YY_part = zeros(size(grid.VI));
127 CC_part = zeros(size(df.grid.VI));
129 CC_part(:,i) = evaluate(df,1:nel,locs(i,:));
131 XX_part = XX * lincombweights';
132 YY_part = YY * lincombweights';
134 XX_total = [XX_total; XX_part];
135 YY_total = [YY_total; YY_part];
136 CC_total = [CC_total; CC_part];
141 % inner subsampling triangles:
142 for i1 = 1:(params.subsampling_level);
143 for i2 = 1:(params.subsampling_level + 1 - i1);
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];
153 %XX_part = zeros(size(grid.VI));
154 %YY_part = zeros(size(grid.VI));
155 CC_part = zeros(size(df.grid.VI));
157 CC_part(:,i) = evaluate(df,1:nel,locs(i,:));
159 XX_part = XX * lincombweights';
160 YY_part = YY * lincombweights';
162 XX_total = [XX_total; XX_part];
163 YY_total = [YY_total; YY_part];
164 CC_total = [CC_total; CC_part];
169 % enables easy parametrized geometry transformation
170 if isfield(params, 'global_transformation')
172 XY_transformed = params.global_transformation([XX_total(:), YY_total(:)]);
174 XX_total = reshape(XY_transformed(:, 1), size(CC_total));
175 YY_total = reshape(XY_transformed(:, 2), size(CC_total));
178 %different options with different results ???
180 if ~params.plot_flat_colored
181 p = patch(XX_total',YY_total',params.height_factor*CC_total', ...
184 p = patch(XX_total',YY_total',params.height_factor*CC_total', ...
189 %p = patch(XX_total(1:10,:)',YY_total(1:10,:)',CC_total(1:10,:)');
191 %%p = patch(XX_total(11:end,:)',YY_total(11:end,:)',CC_total(11:end,:)');
203 set(p,'linestyle','none');
208 if params.show_colorbar
209 if isfield(params,'clim')
210 set(gca,'Clim',params.clim)
212 colorbar(params.colorbar_location);
216 if ~params.no_lines & (params.height_factor == 0)