Home > chronux_1_50 > spikesort > CB_colorshift.m

CB_colorshift

PURPOSE ^

CB_COLORSHIFT Callback for UIcolorshift.

SYNOPSIS ^

function CB_colorshift(handle, events)

DESCRIPTION ^

CB_COLORSHIFT     Callback for UIcolorshift.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function CB_colorshift(handle, events)
0002 %CB_COLORSHIFT     Callback for UIcolorshift.
0003 
0004 % Fields for UserData structure:
0005 %  fighdl - parent figure hndl    mouseroot - global coords initial click
0006 %  target - data axes hndl        climsinit - initial clim
0007 %  cimage - colorbar image hndl   limitSEL  - 1 = bottom limit, 2 = top
0008 %  mode   - 'H'oriz or 'V'ert     mouseSEL  - 1 = horiz (X), 2 = vert (Y)
0009 %  cbrhdl - colorbar axes hndl    limitstr  - 'XLim'=horiz, 'YLim'=vert
0010 %  cmap   - initial colormap      cmaplen - # rows in colormap
0011 %  datastr - 'XData'=horiz,'YData'=vert
0012 %  incr_per_pix - clim incr per pixel of mouse motion
0013 
0014 %  shft_per_pix - clim shift per pixel of mouse motion
0015 
0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Set Up Data %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0017 info = get(handle, 'UserData');
0018 
0019 info.mouseSEL = (info.mode == 'V') + 1;   % 1 for 'H' mode, 2 for 'V'
0020 if (info.mode == 'H'),  info.limitstr = 'XLim';  info.datastr = 'XData';
0021 else,                   info.limitstr = 'YLim';  info.datastr = 'YData';
0022 end
0023 
0024 info.climsinit = get(info.target,'CLim');   
0025 info.incr_per_pix = diff(info.climsinit)./200;
0026 
0027 info.cmap = get(info.fighdl, 'Colormap');
0028 info.cmaplen = size(info.cmap,1);
0029 info.shft_per_pix = info.cmaplen./256;
0030 
0031 
0032 % mouseclick in data units
0033 clickData = get(handle,'CurrentPoint');  clickData = clickData(1,info.mouseSEL);
0034 
0035 % mouseclick in figure units
0036 clickRoot = get(0, 'PointerLocation');   info.mouseinit = clickRoot(info.mouseSEL);
0037 
0038 %%%%%%%%%%%%%%%%%%%%%%%%%%%% Decide Action %%%%%%%%%%%%%%%%%%%%%%%%%%%
0039 dlims = get(handle, info.limitstr);              
0040 click = (clickData - dlims(1)) ./ (dlims(2)-dlims(1));  % data units -> normalized
0041 if (click >= 0.95),     mode = 'top';   info.limitSEL = 2;
0042 elseif (click <= 0.05), mode = 'bot';   info.limitSEL = 1;
0043 else                    mode = 'shf';
0044 end
0045 
0046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Track Mouse %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0047 oldMotionFcn   = get(info.fighdl, 'WindowButtonMotionFcn');
0048 oldButtonUpFcn = get(info.fighdl, 'WindowButtonUpFcn');
0049 set(info.fighdl, 'WindowButtonUpFcn', {@done_cbar});
0050 switch(mode),
0051     case {'top', 'bot'}
0052         set(info.fighdl, 'WindowButtonMotionFcn', {@scale_cbar, info});
0053     case 'shf',
0054         set(info.fighdl, 'WindowButtonMotionFcn', {@shift_cbar, info});
0055 end
0056 waitfor(info.fighdl, 'WindowButtonMotionFcn', '');
0057 
0058 set(info.fighdl, 'WindowButtonMotionFcn', oldMotionFcn);
0059 set(info.fighdl, 'WindowButtonUpFcn', oldButtonUpFcn);
0060 
0061 axes(info.target);  % R13 TMW bug on deletion if colorbar remains current axes
0062 if (info.mode == 'H')
0063     UIcolorshift('horiz', 'peer',info.target);   % refresh display
0064 else
0065     UIcolorshift('peer', info.target);  
0066 end
0067 % click = round((click-range(1)) ./ (range(2)-range(1)) .* 255);
0068 % shift = mod([-127:128] + click, 256) + 1;      % make shifted indices
0069 % cmap = colormap;
0070 % colormap(cmap(shift,:));  % then shift the map
0071 
0072 
0073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0074 %%%%%%%%%%%%%%%%%%%% Callbacks for the Callback %%%%%%%%%%%%%%%%%%%%%%
0075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0076 
0077 %%%%% Used to signal to cb_colorshift that tracking is over.
0078 function done_cbar(handle, event)
0079 set(handle, 'WindowButtonMotionFcn', '')
0080 
0081 %%%%% Rescale color limits
0082 function scale_cbar(handle, event, ud)
0083 mouse = get(0,'PointerLocation');
0084 ud.climsinit(ud.limitSEL) = ud.climsinit(ud.limitSEL) - (mouse(ud.mouseSEL)-ud.mouseinit)*ud.incr_per_pix;
0085 if (diff(ud.climsinit) > 0)
0086     set(ud.target, 'CLim', ud.climsinit);
0087     set(ud.cbrhdl, ud.limitstr, ud.climsinit);
0088     set(ud.cimage, ud.datastr, ud.climsinit);
0089 end
0090 
0091 %%%%% Shift color limits
0092 function shift_cbar(handle, event, ud)
0093 mouse = get(0,'PointerLocation');
0094 shift = round((mouse(ud.mouseSEL)-ud.mouseinit)*ud.shft_per_pix);
0095 cmap = ud.cmap;
0096 set(ud.fighdl, 'Colormap', cmap(circshift((1:ud.cmaplen)', shift), :));

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