Home > chronux_2_00 > spikesort > utility > uitools > UIlogmenu.m

UIlogmenu

PURPOSE ^

UIlogmenu Adds a context menu for toggling logarithmic scaling.

SYNOPSIS ^

function h = UIlogmenu(h)

DESCRIPTION ^

UIlogmenu         Adds a context menu for toggling logarithmic scaling.
   UIlogmenu creates a context menu that allows the user to toggle
   logarithmic scaling for image, surface or line data, depending on the
   contents of the current axes.
  
   If the current axes contain an image, the context menu is associated
   with that object (or the topmost one if multiple images are present).
   Pixel intensities toggle between their values when UIlogmenu is called
   and the log (base 10) of those values (raw data values <= 0 result in
   NaNs).  The log data is precomputed when the menu is first added to an
   image to speed up subsequent switching.

   If no image is present but the axes contain surface objects, the
   context menu is associated with the axes.  The menu then toggles
   linear vs logarithmic scaling on the z-axis.

   If no image or surface objects are present but the axes contain line
   objects, the context menu is associated with the axes.  In this case,
   the menu toggles logarithmic scaling on the y-axis.

   UIlogmenu(HANDLE) associates the menu with the object specified by
   HANDLE. 

   H = UIlogmenu(...) returns a handle to the object (image or axes)
   associated with the new context menu.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function h = UIlogmenu(h)
0002 %UIlogmenu         Adds a context menu for toggling logarithmic scaling.
0003 %   UIlogmenu creates a context menu that allows the user to toggle
0004 %   logarithmic scaling for image, surface or line data, depending on the
0005 %   contents of the current axes.
0006 %
0007 %   If the current axes contain an image, the context menu is associated
0008 %   with that object (or the topmost one if multiple images are present).
0009 %   Pixel intensities toggle between their values when UIlogmenu is called
0010 %   and the log (base 10) of those values (raw data values <= 0 result in
0011 %   NaNs).  The log data is precomputed when the menu is first added to an
0012 %   image to speed up subsequent switching.
0013 %
0014 %   If no image is present but the axes contain surface objects, the
0015 %   context menu is associated with the axes.  The menu then toggles
0016 %   linear vs logarithmic scaling on the z-axis.
0017 %
0018 %   If no image or surface objects are present but the axes contain line
0019 %   objects, the context menu is associated with the axes.  In this case,
0020 %   the menu toggles logarithmic scaling on the y-axis.
0021 %
0022 %   UIlogmenu(HANDLE) associates the menu with the object specified by
0023 %   HANDLE.
0024 %
0025 %   H = UIlogmenu(...) returns a handle to the object (image or axes)
0026 %   associated with the new context menu.
0027 
0028 state = warning;  warning('off', 'Matlab:log:logOfZero');
0029 
0030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Setup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0031 if (nargin > 1)
0032     error('Invalid syntax.');
0033 elseif (nargin == 1)
0034     switch(get(h,'Type')),
0035         case 'image',    limits = 'CLim';
0036         case 'surface',  limits = 'ZLim';
0037         case 'line',     limits = 'YLim';
0038         otherwise, 
0039             errmsg = sprintf('UIlogmenu is undefined for objects of type %s.', get(h,'Type')); 
0040             error(errmsg);
0041     end
0042 else
0043     childs = get(gca, 'Children');
0044     img = findobj(childs, 'Type', 'image');
0045     if (~isempty(img)),
0046         h = img(1);  limits = 'CLim';
0047     elseif (~isempty(findobj(childs, 'Type', 'surface'))),
0048         h = gca;     limits = 'ZLim';
0049     elseif (~isempty(findobj(childs, 'Type', 'line'))),
0050         h = gca;     limits = 'YLim';
0051     else
0052         error('The current axes do not contain the appropriate objects.');
0053     end
0054 end
0055 
0056 %%%%%%%%%%%%%%%%%%%%%%%%% Create Context Menu %%%%%%%%%%%%%%%%%%%%%%%%
0057 logmenu = find_uimenu(h, 'logmenu', 'Log scaling', @CB_logmenu);
0058 
0059 %%%%%%%%%%%%%%%%%%%%%%%%%%%% Store UserData %%%%%%%%%%%%%%%%%%%%%%%%%%
0060 switch(limits)
0061     case {'YLim','ZLim'}
0062         userdata.axes     = h;
0063     case 'CLim',
0064         userdata.axes     = get(h, 'Parent');
0065         userdata.imageobj = h;
0066         userdata.backdata = log10(get(h, 'CData'));
0067             userdata.backdata(get(h,'CData') <= 0) = NaN;   % blank out imaginary/-INF values
0068         userdata.backlims = [min(userdata.backdata(:)), max(userdata.backdata(:))];  % default tight color scaling on log plot
0069 end
0070 userdata.limits = limits;
0071 set(logmenu, 'UserData', userdata);
0072 
0073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Cleanup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0074 if (nargout == 0), clear h;  end
0075 
0076 warning(state);

Generated on Fri 15-Aug-2008 11:35:42 by m2html © 2003