rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
plot_sequence.m
Go to the documentation of this file.
1 function p = plot_sequence(varargin)
2 %function p = plot_sequence(data,grid,params[,callbackfigure, cbhandle])
3 % plotting a sequence of data slices on polygonal
4 % 2d grid (constructed from params if empty) and providing a slider
5 % for changing between the data
6 % slices.
7 %
8 % A new figure is opened and the handle returned in p. If further parameters
9 % are set, the call is assumed to stem from a callback-function
10 %
11 % Every column of data is interpreted as one discrete function
12 % dof vector forwarded to the params.plot() function.
13 %
14 % parameters:
15 % varargin: usually called with 3 arguments:
16 % @code plot_sequence(data, grid, params) @endcode
17 % - data - data vector to be plotted
18 % - grid - the underlying grid
19 % - params - plotting parameters
20 % .
21 % Alternatively, there can be 5 arguments:
22 % @code plot_sequence(data, grid, params, callbackfigure, cbhandle) @endcode
23 % This function is set as a callback function for the time slider
24 % uicontrol. The additional arguments are:
25 % - callbackfigure - handle to the figure
26 % - cbhandle - handle to the object calling the callback function. This
27 % is usually the time slider.
28 %
29 % return values:
30 % p : figure handle of plot
31 %
32 % required fields in params:
33 % - 'plot' -- pointer to the plot-function performing the plotting of a
34 % single slice, e.g. plot_element_data(), plot_vertex_data(),
35 % fv_plot(), ldg_plot().
36 %
37 % optional field of params:
38 % - 'title' -- string indicating the title of the newly opened figure
39 % - 'clim' -- 2-vector giving the range of the colormap. If this is set,
40 % identical range is used for all slices. Default is the min and
41 % max of all slices.
42 % - 'clim_tight' -- if this flag is set, the colorbar is set tightly to the
43 % range of every single data slice. Clearly only one of
44 % 'clim' or 'clim_tight' should be set.
45 %
46 % see also the chosen 'params.plot_function' for its further params-options
47 
48 % Bernard Haasdonk 9.5.2007
49 
50 % open figure
51 if nargin < 4 % no callback, open new figure
52 
53  % keyboard;
54  f = figure;
55  di = 0.1;
56  textwidth= 0.15;
57  textheight = 0.05;
58  txt = uicontrol(f,'Style','text','Units','normalized',...
59  'Position',[di,di,textwidth,textheight],...
60  'String','Slice 1','Tag','text1');
61  slider = uicontrol(f,'Style','slider','Units','normalized',...
62  'Position',[di+textwidth+di, di ,1-3*di-textwidth,...
63  textheight],'Tag','slider1',...
64  'Callback','plot_sequence([],[],[],[],gcbf,gcbo);');
65  ax = axes('Units','normalized',...
66  'Position',[di,2*di+textheight,1-2*di,1-3*di - textheight],...
67  'Tag','axes1');
68  % cb = colorbar;
69  ud = [];
70  ud.data = varargin{1};
71  ud.grid = varargin{2};
72  ud.params = varargin{3};
73 
74  if isempty(ud.grid)
75  ud.grid = construct_grid(ud.params);
76  end;
77 
78  if isfield(ud.params,'title')
79  set(f,'Name',ud.params.title);
80  end;
81 
82  if ~isfield(ud.params,'clim_tight')
83  ud.params.clim_tight = 0;
84  end;
85 
86  if isfield(ud.params,'clim') && ud.params.clim_tight
87  error('please only specify one of the parameters clim and clim_tight.');
88  end;
89 
90  if ~isfield(ud.params,'clim') && ~ud.params.clim_tight
91  ud.params.clim = [min(min(ud.data)), max(max(ud.data))];
92  if ud.params.clim(1) == ud.params.clim(2)
93  ud.params.clim = ud.params.clim + [-eps, +eps];
94  end;
95  end;
96  set(f,'Userdata',ud);
97 
98  sl = findobj(f,'Tag','slider1');
99  %set(sl,'min',0);
100  %set(sl,'max',ud.params.nt);
101  %set(sl,'sliderstep',[1/ud.params.nt,1]);
102  set(sl,'min',1);
103  if size(ud.data,2)>1
104  set(sl,'max',size(ud.data,2));
105  set(sl,'sliderstep',[1/(size(ud.data,2)-1),1]);
106  else
107  set(sl,'max',size(ud.data,2)+eps);
108  set(sl,'visible','off');
109  % set(sl,'sliderstep',[0,0]);
110  end;
111  set(sl,'value',1);
112  th = findobj(f,'Tag','text1');
113  set(th,'String',('data slice 1') );
114  replot(f,sl,1);
115  % set(f,'Resize','on');
116  p = f;
117 end;
118 
119 if nargin >=4 % callback-function
120  cbf = varargin{4};
121  cbo = varargin{5};
122  % disp('performing callback call of plot_fv_data')
123  th = findobj(gcbf,'Tag','text1');
124  v = round(get(gcbo,'value'));
125  set(gcbo,'value',v);
126  set(th,'String',['data slice ',num2str(v)]);
127  replot(gcbf,gcbo,v);
128  p = gcbf;
129 end;
130 
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 function replot(fh,oh,v)
133 ud = get(fh,'Userdata');
134 
135 d = ud.data(:,v);
136 
137 % if clim_tight, adapt color-range:
138 if ud.params.clim_tight
139  ud.params.clim = [min(min(d)), max(max(d))];
140  if ud.params.clim(1) == ud.params.clim(2)
141  ud.params.clim = ud.params.clim + [-eps, +eps];
142  end;
143 end;
144 
145 % delete old data:
146 ax = findobj(fh,'Tag','axes1');
147 cla(ax);
148 
149 ud.params.plot(ud.grid,d,ud.params);
150 
151 set(gca,'Clim',[ud.params.clim(1), ud.params.clim(2)]);
152 
153 
function p = plot_sequence(varargin)
plotting a sequence of data slices on polygonal 2d grid (constructed from params if empty) and provid...
Definition: plot_sequence.m:17