rbmatlab 0.10.01
discfunc/common/plot_sequence.m
Go to the documentation of this file.
00001 function p = plot_sequence(varargin)
00002 %function p = plot_sequence(data,grid,params[,callbackfigure, cbhandle])
00003 % plotting a sequence of data slices on polygonal
00004 % 2d grid (constructed from params if empty) and providing a slider
00005 % for changing between the data
00006 % slices.
00007 %
00008 % A new figure is opened and the handle returned in p.  If further parameters
00009 % are set, the call is assumed to stem from a callback-function
00010 %
00011 % Every column of data is interpreted as one discrete function
00012 % dof vector forwarded to the params.plot() function.
00013 %
00014 % parameters:
00015 %  varargin: usually called with 3 arguments:
00016 %            @code plot_sequence(data, grid, params) @endcode
00017 %   - data - data vector to be plotted
00018 %   - grid - the underlying grid
00019 %   - params - plotting parameters
00020 %   .
00021 %            Alternatively, there can be 5 arguments:
00022 %            @code plot_sequence(data, grid, params, callbackfigure, cbhandle) @endcode
00023 %            This function is set as a callback function for the time slider
00024 %            uicontrol. The additional arguments are:
00025 %   - callbackfigure - handle to the figure
00026 %   - cbhandle       - handle to the object calling the callback function. This
00027 %                      is usually the time slider.
00028 %
00029 % return values:
00030 %  p : figure handle of plot
00031 %
00032 % required fields in params:
00033 %  - 'plot' -- pointer to the plot-function performing the plotting of a
00034 %              single slice, e.g.  plot_element_data(), plot_vertex_data(),
00035 %              fv_plot(), ldg_plot().
00036 %
00037 % optional field of params:
00038 %  - 'title' -- string indicating the title of the newly opened figure
00039 %  - 'clim'  -- 2-vector giving the range of the colormap. If this is set,
00040 %               identical range is used for all slices. Default is the min and
00041 %               max of all slices.
00042 %  - 'clim_tight' -- if this flag is set, the colorbar is set tightly to the
00043 %                    range of every single data slice. Clearly only one of
00044 %                    'clim' or 'clim_tight' should be set.
00045 %
00046 % see also the chosen 'params.plot_function' for its further params-options
00047 
00048 % Bernard Haasdonk 9.5.2007
00049 
00050 % open figure
00051 if nargin < 4 % no callback, open new figure
00052 
00053   %  keyboard;
00054   f = figure;
00055   di = 0.1;
00056   textwidth= 0.15;
00057   textheight = 0.05;
00058   txt = uicontrol(f,'Style','text','Units','normalized',...
00059                   'Position',[di,di,textwidth,textheight],...
00060                   'String','Slice 1','Tag','text1');
00061   slider = uicontrol(f,'Style','slider','Units','normalized',...
00062                      'Position',[di+textwidth+di, di ,1-3*di-textwidth,...
00063                     textheight],'Tag','slider1',...
00064                     'Callback','plot_sequence([],[],[],[],gcbf,gcbo)');  
00065   ax = axes('Units','normalized',...
00066             'Position',[di,2*di+textheight,1-2*di,1-3*di - textheight],...
00067             'Tag','axes1');
00068   %  cb = colorbar;
00069   ud = [];
00070   ud.data = varargin{1};
00071   ud.grid = varargin{2};
00072   ud.params = varargin{3};
00073 
00074   if isempty(ud.grid)
00075     ud.grid = construct_grid(ud.params);
00076   end;
00077 
00078   if isfield(ud.params,'title')
00079     set(f,'Name',ud.params.title);
00080   end;
00081 
00082   if ~isfield(ud.params,'clim_tight')
00083     ud.params.clim_tight = 0;
00084   end;
00085 
00086   if isfield(ud.params,'clim') && ud.params.clim_tight
00087     error('please only specify one of the parameters clim and clim_tight.');
00088   end;
00089 
00090   if ~isfield(ud.params,'clim') && ~ud.params.clim_tight
00091     ud.params.clim = [min(min(ud.data)), max(max(ud.data))];
00092     if ud.params.clim(1) == ud.params.clim(2)
00093       ud.params.clim = ud.params.clim + [-eps, +eps];
00094     end;
00095   end;
00096   set(f,'Userdata',ud);
00097 
00098   sl = findobj(f,'Tag','slider1');
00099   %set(sl,'min',0);
00100   %set(sl,'max',ud.params.nt);
00101   %set(sl,'sliderstep',[1/ud.params.nt,1]);
00102   set(sl,'min',1);
00103   if size(ud.data,2)>1
00104     set(sl,'max',size(ud.data,2));
00105     set(sl,'sliderstep',[1/(size(ud.data,2)-1),1]);
00106   else
00107     set(sl,'max',size(ud.data,2)+eps);
00108     set(sl,'visible','off');
00109     %  set(sl,'sliderstep',[0,0]);
00110   end;
00111   set(sl,'value',1);
00112   th = findobj(f,'Tag','text1');
00113   set(th,'String',('data slice 1') );
00114   replot(f,sl,1);
00115   %  set(f,'Resize','on');  
00116   p = f;
00117 end;
00118 
00119 if nargin >=4 % callback-function
00120   cbf = varargin{4};
00121   cbo = varargin{5};
00122   %  disp('performing callback call of plot_fv_data')
00123   th = findobj(gcbf,'Tag','text1');
00124   v = round(get(gcbo,'value'));
00125   set(gcbo,'value',v)
00126   set(th,'String',['data slice ',num2str(v)]);
00127   replot(gcbf,gcbo,v);
00128   p = gcbf;
00129 end;
00130 
00131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00132 function replot(fh,oh,v)
00133 ud = get(fh,'Userdata');
00134 
00135 d = ud.data(:,v);
00136 
00137 % if clim_tight, adapt color-range:
00138 if ud.params.clim_tight
00139   ud.params.clim = [min(min(d)), max(max(d))];
00140   if ud.params.clim(1) == ud.params.clim(2)
00141     ud.params.clim = ud.params.clim + [-eps, +eps];
00142   end;
00143 end;
00144 
00145 % delete old data:
00146 ax = findobj(fh,'Tag','axes1');
00147 cla(ax);
00148 
00149 ud.params.plot(ud.grid,d,ud.params);
00150 
00151 set(gca,'Clim',[ud.params.clim(1), ud.params.clim(2)]);
00152 
00153 
 All Classes Namespaces Files Functions Variables