Home > chronux_1_50 > spikesort > 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;
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             error(sprintf('UIlogmenu is undefined for objects of type %s.', get(h,'Type')));
0040     end
0041 else
0042     childs = get(gca, 'Children');
0043     img = findobj(childs, 'Type', 'image');
0044     if (~isempty(img)),
0045         h = img(1);  limits = 'CLim';
0046     elseif (~isempty(findobj(childs, 'Type', 'surface'))),
0047         h = gca;     limits = 'ZLim';
0048     elseif (~isempty(findobj(childs, 'Type', 'line'))),
0049         h = gca;     limits = 'YLim';
0050     else
0051         error('The current axes do not contain the appropriate objects.');
0052     end
0053 end
0054 
0055 %%%%%%%%%%%%%%%%%%%%%%%%% Create Context Menu %%%%%%%%%%%%%%%%%%%%%%%%
0056 logmenu = find_uimenu(h, 'logmenu', 'Log scaling', @CB_logmenu);
0057 
0058 %%%%%%%%%%%%%%%%%%%%%%%%%%%% Store UserData %%%%%%%%%%%%%%%%%%%%%%%%%%
0059 switch(limits)
0060     case {'YLim','ZLim'}
0061         userdata.axes     = h;
0062     case 'CLim',
0063         userdata.axes     = get(h, 'Parent');
0064         userdata.imageobj = h;
0065         userdata.backdata = log10(get(h, 'CData'));
0066             userdata.backdata(get(h,'CData') <= 0) = NaN;   % blank out imaginary/-INF values
0067         userdata.backlims = [min(userdata.backdata(:)), max(userdata.backdata(:))];  % default tight color scaling on log plot
0068 end
0069 userdata.limits = limits;
0070 set(logmenu, 'UserData', userdata);
0071 
0072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Cleanup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0073 if (nargout == 0), clear h;  end
0074 
0075 warning(state);

Generated on Mon 09-Oct-2006 00:54:52 by m2html © 2003