1 function p = plot(grid,params)
2 %
function p = plot(grid,params)
5 % A line plot is performed. Currently implementation
for more than 3D not
6 % implemented, as
this would be a line-mess
9 % p:
this is the list of handles to the graphics primitives
11 % optional fields of params:
13 % shrink_factor:
if this flag is given, the elements are plotted shrinked
14 % plot_level:
if this flag is nonzero, a level plot is performed
15 % level :
this integer must be specified in
case of level-plot
16 % plot_patch :
if this flag is set (only 2D and 3D) the plot is done
18 % axis_equal :
if this flag is set, set axis to equal scale
20 % Bernard Haasdonk 1.3.2007
26 if ~(isfield(params,
'shrink_factor'))
27 params.shrink_factor = 1.0;
30 if ~(isfield(params,
'plot_level'))
31 params.plot_level = 0;
34 if ~(isfield(params,
'level'))
38 if ~(isfield(params,
'plot_patch'))
39 params.plot_patch = 0;
42 if ~(isfield(params,
'axis_equal'))
43 params.axis_equal = 0;
46 if ~(isfield(params,
'color'))
47 params.color = [0,0,1];
50 if ~(isfield(params,
'LineStyle'))
51 params.LineStyle =
'-'
56 % determine elements to be plotted
57 if (params.plot_level)
58 ids = find(grid.level==params.level);
60 ids = find(grid.isleaf);
64 disp('no elements on current level or grid empty')
67 if ~params.plot_patch % i.e. line mode required
68 % generate list of local coordinates to be connected
69 % idea: plot n-1 d bottom cube, its shifted top version and the
72 % dim = 2 => [1 2; 3,4; 1 3; 2 4]
73 % dim = 3 => [1 2; 3,4; 1 3; 2 4, 5 6; 7,8; 5 7; 6 8; 1 5 ; 2 6 ;
77 % assume li is local coordinate li of lower n-1 d patch
78 li = [li; li + 2^(i-1)];
79 % now li is local coordinate li of lower and upper n-1 d patch
80 li = [li; (1:2^(i-1))' ,(1:2^(i-1))'+2^(i-1)];
82 else % generate patch-list in local coordinates
94 error('patch mode requires dim= 2 or 3!');
102 X = zeros(size(li,2),size(li,1));
103 Y = zeros(size(li,2),size(li,1));
105 Z = zeros(size(li,2),size(li,1));
110 % stupid plotting: loop over all elements. should be vectorized sometime
113 % collect globalcoordinates of points for element
114 ve = grid.vertexindex(nel,:);
115 co = grid.vertex(ve,:); % => co is nlocalpoints x dimension matrix
116 % midpoint of element as matrix
117 cog = repmat(mean(co),size(co,1),1);
119 co = (co - cog)*params.shrink_factor + cog;
121 % generate coordinate lists to be plotted
122 % X,Y,Z: 2 x nlines matrix
123 switch grid.dimension
125 % only x-coord varying
126 X(1,:) = co(li(:,1),1);
127 X(2,:) = co(li(:,2),1);
129 % x and y-coord varying
130 X = reshape(co(li',1),size(X));
131 Y = reshape(co(li',2),size(Y));
133 % x and y- and z-coord varying
134 X = reshape(co(li',1),size(X));
135 Y = reshape(co(li',2),size(Y));
136 Z = reshape(co(li',3),size(Z));
138 Xtotal = [Xtotal, X];
139 Ytotal = [Ytotal, Y];
140 Ztotal = [Ztotal, Z];
143 switch grid.dimension
145 p = line(Xtotal,Ytotal,'Color',params.color,'LineStyle',params.LineStyle);
148 p = patch(Xtotal,Ytotal,params.color);
150 p = line(Xtotal,Ytotal,'Color',params.color,'LineStyle',params.LineStyle);
154 p = patch(Xtotal,Ytotal,Ztotal,params.color);
156 p = line(Xtotal,Ytotal,Ztotal,'Color',params.color,'LineStyle',params.LineStyle);
160 disp('plot for dimension>3 not yet implemented!')
level
level(id) equals refinement level of element id
A hierarchical cubegrid of arbitrary dimension.