rbmatlab 0.10.01
|
00001 function p = plot_discfunc(df,params) 00002 %function p = plot_discfunc(df,params) 00003 % 00004 % function plotting a single scalar discrete function on triangular grid 00005 % A patch plot is performed as default using speified number of 00006 % subsamplings of the triangles. Each patch is plotted linearly 00007 % interpolated (hence only showing true values in subsampling nodes.) 00008 % On each triangle-edge, subsamp_level points are inserted. 00009 % 00010 % p is the list of handles to the graphics primitives 00011 % 00012 % grid must provide the fields 00013 % X,Y,VI,CX,CY,nelements,nvertices and nneigh; 00014 % 00015 % df must specify the discfunc-information: 00016 % params.dimrange, params.pdeg 00017 % evaluate: pointer to local evaluation routine to be called as 00018 % evaluate(df,1:nel,locs(i,:),grid,params); 00019 % 00020 % optional fields of params: 00021 % shrink_factor : if this flag is given, the elements are plotted shrinked 00022 % axis_equal : if this flag is set, set axis to equal scale 00023 % no_lines : if this flag is set, no lines are drawn 00024 % show_colorbar : if this flag is set, a colorbar is drawn (default 1) 00025 % colorbar_location : string specifying the position of the 00026 % colorbar, e.g. 'South','EastOutside' (default), etc. 00027 % clim : if this 2-vector is set, the colorbar is set to 00028 % these values 00029 % subsampling_level : number of intervals per edge 00030 00031 % Bernard Haasdonk 2.2.2009 00032 00033 if df.dimrange>1 00034 error(['plotting of vectorial functions only via extraction of ',... 00035 ' scalar components!']) 00036 end; 00037 00038 if nargin<2 00039 params = []; 00040 end; 00041 00042 %if ~(isfield(params,'shrink_factor')) 00043 % params.shrink_factor = 1.0; 00044 %end; 00045 00046 if ~(isfield(params,'axis_equal')) 00047 params.axis_equal = 0; 00048 end; 00049 00050 if ~(isfield(params,'no_lines')) 00051 params.no_lines = 1; 00052 end; 00053 00054 if ~(isfield(params,'show_colorbar')) 00055 params.show_colorbar = 1; 00056 end; 00057 00058 if ~(isfield(params,'colorbar_location')) 00059 params.colorbar_location = 'EastOutside'; 00060 end; 00061 00062 if ~(isfield(params,'subsampling_level')) 00063 params.subsampling_level = df.pdeg; 00064 end; 00065 00066 %nneigh = grid.nneigh; 00067 00068 % compute vertex coordinates and scale 00069 %XX = grid.X(grid.VI(:)); 00070 %XX = reshape(XX,size(grid.VI)); % nelements*nneigh matrix 00071 %YY = grid.Y(grid.VI(:)); 00072 %YY = reshape(YY,size(grid.VI)); % nelements*nneigh matrix 00073 00074 %CXX = repmat(grid.CX(:),1,nneigh); 00075 %CYY = repmat(grid.CY(:),1,nneigh); 00076 00077 % scale coordinates 00078 %XX = (XX - CXX) *params.shrink_factor + CXX; 00079 %YY = (YY - CYY) *params.shrink_factor + CYY; 00080 00081 %set patch colors 00082 %CC = data(grid.VI(:)); 00083 00084 % evaluate discrete function 00085 00086 XX_total = zeros(0,size(df.grid.VI,2)); 00087 YY_total = zeros(0,size(df.grid.VI,2)); 00088 CC_total = zeros(0,size(df.grid.VI,2)); 00089 00090 XX = df.grid.X(df.grid.VI(:)); 00091 XX = reshape(XX,size(df.grid.VI)); % nelements*nneigh matrix 00092 YY = df.grid.Y(df.grid.VI(:)); 00093 YY = reshape(YY,size(df.grid.VI)); % nelements*nneigh matrix 00094 nel = df.grid.nelements; 00095 step = 1/(params.subsampling_level+1); 00096 00097 % outer subsampling triangles: 00098 %keyboard; 00099 for i1 = 1:(params.subsampling_level+1); 00100 for i2 = 1:(params.subsampling_level+2 - i1); 00101 00102 % list of local evaluation points: 00103 % i-th row is i-th point of the subsamp-triangle 00104 locs = [ 1-(i1+i2-2) * step, (i2-1)*step; ... 00105 1-(i1+i2-1) * step, i2 * step; ... 00106 1-(i1+i2-1) * step, (i2-1) * step ]; 00107 % for coordinate computation: 00108 lincombweights = [locs(:,2), 1 - locs(:,1)-locs(:,2),locs(:,1)]; 00109 % for local evaluating of function 00110 locs = [1 - locs(:,1)-locs(:,2),locs]; 00111 00112 %XX_part = zeros(size(grid.VI)); 00113 %YY_part = zeros(size(grid.VI)); 00114 CC_part = zeros(size(df.grid.VI)); 00115 for i=1:3 00116 CC_part(:,i) = evaluate(df,1:nel,locs(i,:)); 00117 end; 00118 XX_part = XX * lincombweights'; 00119 YY_part = YY * lincombweights'; 00120 00121 XX_total = [XX_total; XX_part]; 00122 YY_total = [YY_total; YY_part]; 00123 CC_total = [CC_total; CC_part]; 00124 00125 end; 00126 end; 00127 00128 % inner subsampling triangles: 00129 for i1 = 1:(params.subsampling_level); 00130 for i2 = 1:(params.subsampling_level + 1 - i1); 00131 00132 % list of local evaluation points: 00133 % i-th column is i-th point of the subsamp-triangle 00134 locs = [ 1-(i1+i2-1) * step,(i2-1)*step; ... 00135 1-(i1+i2-1) * step, i2 * step; ... 00136 1-(i1+i2) * step , i2 * step ]; 00137 lincombweights = [locs(:,2), 1 - locs(:,1)-locs(:,2),locs(:,1)]; 00138 locs = [1 - locs(:,1)-locs(:,2),locs]; 00139 00140 %XX_part = zeros(size(grid.VI)); 00141 %YY_part = zeros(size(grid.VI)); 00142 CC_part = zeros(size(df.grid.VI)); 00143 for i=1:3 00144 CC_part(:,i) = evaluate(df,1:nel,locs(i,:)); 00145 end; 00146 XX_part = XX * lincombweights'; 00147 YY_part = YY * lincombweights'; 00148 00149 XX_total = [XX_total; XX_part]; 00150 YY_total = [YY_total; YY_part]; 00151 CC_total = [CC_total; CC_part]; 00152 00153 end; 00154 end; 00155 00156 %different options with different results ??? 00157 %figure, 00158 p = patch(XX_total',YY_total',CC_total'); 00159 %figure, 00160 %p = patch(XX_total(1:10,:)',YY_total(1:10,:)',CC_total(1:10,:)'); 00161 %hold on; 00162 %%p = patch(XX_total(11:end,:)',YY_total(11:end,:)',CC_total(11:end,:)'); 00163 %keyboard; 00164 00165 if params.axis_equal 00166 axis equal; 00167 axis tight; 00168 end; 00169 00170 if params.no_lines 00171 set(p,'linestyle','none'); 00172 end; 00173 00174 %keyboard; 00175 00176 if params.show_colorbar 00177 if isfield(params,'clim') 00178 set(gca,'Clim',params.clim) 00179 end; 00180 colorbar(params.colorbar_location); 00181 end; 00182 hold on; 00183 00184 if ~params.no_lines 00185 p2 = plot(df.grid); 00186 set(p2,'Color','k') 00187 p = [p(:);p2]; 00188 end; 00189 00190 %| \docupdate