rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
plot_vertex_data.m
1 function p = plot_vertex_data(grid,data,params)
2 %function p = plot_vertex_data(grid,data[, params])
3 % plot method for vertex data on a 2D polygonal grid.
4 %
5 % For example a `P1` functions routine can be used for triangular and
6 % rectangular grids. A patch plot is performed as default. In case of
7 % rectangular elements, no true bilinear interpolation is performed, but the
8 % patch is divided into triangles.
9 %
10 % Parameters:
11 % data: a vector of length 'grid.nvertices' with nodewise scalar values.
12 % params: optional structure holding fields controlling the plot output.
13 %
14 % Return values:
15 % p: This is the list of handles to the graphics primitives
16 %
17 % optional fields of params:
18 % shrink_factor : if this flag is given, the elements are plotted shrinked
19 % axis_equal : if this flag is set, set axis to equal scale
20 % no_lines : if this flag is set, no lines are drawn
21 % show_colorbar : if this flag is set, a colorbar is drawn (default 1)
22 % colorbar_location : string specifying the position of the
23 % colorbar, e.g. 'South','EastOutside' (default), etc.
24 % clim : if this 2-vector is set, the colorbar is set to
25 % these values
26 
27 % Bernard Haasdonk 9.5.2007
28 
29 if nargin<3
30  params = [];
31 end;
32 
33 if ~(isfield(params,'shrink_factor'))
34  params.shrink_factor = 1.0;
35 end;
36 
37 if ~(isfield(params,'axis_equal'))
38  params.axis_equal = 0;
39 end;
40 
41 if ~(isfield(params,'no_lines'))
42  params.no_lines = 0;
43 end;
44 
45 if ~(isfield(params,'show_colorbar'))
46  params.show_colorbar = 1;
47 end;
48 
49 if ~(isfield(params,'colorbar_location'))
50  params.colorbar_location = 'EastOutside';
51 end;
52 
53 if (length(data)~=grid.nvertices)
54  error('length of data does not match number of elements!');
55 end;
56 
57 nneigh = grid.nneigh;
58 
59 % compute vertex coordinates and scale
60 XX = grid.X(grid.VI(:));
61 XX = reshape(XX,size(grid.VI)); % nelements*nneigh matrix
62 YY = grid.Y(grid.VI(:));
63 YY = reshape(YY,size(grid.VI)); % nelements*nneigh matrix
64 
65 CXX = repmat(grid.CX(:),1,nneigh);
66 CYY = repmat(grid.CY(:),1,nneigh);
67 
68 % scale coordinates
69 XX = (XX - CXX) *params.shrink_factor + CXX;
70 YY = (YY - CYY) *params.shrink_factor + CYY;
71 
72 %set patch colors
73 CC = data(grid.VI(:));
74 CC = reshape(CC,size(grid.VI)); % nelements*nneigh matrix
75 
76 if isfield(params, 'plot_mode') && isequal(params.plot_mode, '3d')
77  p = patch(XX',YY',CC',CC');
78  if isfield(params, 'view')
79  view(params.view);
80  else
81  view(3);
82  end
83 else
84  p = patch(XX',YY',CC');
85 end
86 
87 c = jet(256);
88 colormap(c);
89 
90 if params.axis_equal
91  axis equal;
92  axis tight;
93 end;
94 
95 if params.no_lines
96  set(p,'linestyle','none');
97 end;
98 
99 if params.show_colorbar
100  if isfield(params,'clim')
101  set(gca,'Clim',params.clim)
102  end;
103  colorbar(params.colorbar_location);
104 end;
105