📄 grabit.m
字号:
handles = guidata(obj);if ~isempty(handles.I) k = lower(get(obj, 'CurrentKey')); switch k case 'a' % zoom in xl = get(handles.ImageAxis, 'xlim'); xrng = diff(xl); yl = get(handles.ImageAxis, 'ylim'); yrng = diff(yl); % prevent zooming in too much. % set the limit to 64x zoom. if xrng >= size(handles.I, 2)/64*2 % animate zoom for id = 0:0.2:1 set(handles.ImageAxis, ... 'xlim', xl + id * xrng / 4 * [1, -1], ... 'ylim', yl + id * yrng / 4 * [1, -1]); drawnow; end end case 'z' % zoom out xl = get(handles.ImageAxis, 'xlim'); xrng = diff(xl); yl = get(handles.ImageAxis, 'ylim'); yrng = diff(yl); % animate zoom for id = 0:0.2:1 set(handles.ImageAxis, ... 'xlim', xl + id * xrng / 2 * [-1, 1], ... 'ylim', yl + id * yrng / 2 * [-1, 1]); drawnow; end case 'space' % reset view resetViewFcn(handles.ResetViewBtn); case {'backspace', 'delete'} switch handles.state case 'grab' if ~handles.isPanning if isempty(handles.ImDat) return; else handles.ImDat(end, :) = []; handles.TrueDat(end, :) = []; end set(handles.PreviewLine, ... 'xdata', handles.TrueDat(:, 1), ... 'ydata', handles.TrueDat(:, 2)); set(handles.ImageLine, ... 'xdata', handles.ImDat(:, 1), ... 'ydata', handles.ImDat(:, 2)); set(handles.GrabPointsBtn, 'string', sprintf('Grabbing Points (%d)', size(handles.ImDat, 1))); guidata(obj, handles); end end case {'return', 'enter'} switch handles.state case 'grab' grabPointsFcn(handles.GrabPointsBtn); end endend%--------------------------------------------------------------------------%--------------------------------------------------------------------------% resetViewFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function resetViewFcn(varargin)% this function resets the viewobj = varargin{1};handles = guidata(obj);if ~isempty(handles.I) xl = get(handles.ImageAxis, 'xlim'); yl = get(handles.ImageAxis, 'ylim'); xd = (handles.ImLimits(1, :) - xl) / 10; yd = (handles.ImLimits(2, :) - yl) / 10; % animate zoom for id = 0:10 set(handles.ImageAxis, ... 'xlim', xl + id * xd, ... 'ylim', yl + id * yd); drawnow; endend% take focus awayloseFocusFcn(handles)%--------------------------------------------------------------------------%--------------------------------------------------------------------------% loseFocusFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function loseFocusFcn(handles)% attempt to take focus away by setting the ENABLE property to off and then% back to the original settingsettings = get([handles.LoadImageBtn, ... handles.ResetViewBtn, ... handles.VariableList, ... handles.SaveAs, ... handles.Rename, ... handles.Delete], ... 'enable');set([handles.LoadImageBtn, ... handles.ResetViewBtn, ... handles.VariableList, ... handles.SaveAs, ... handles.Rename, ... handles.Delete], ... 'enable', 'off');drawnow;set([handles.LoadImageBtn, ... handles.ResetViewBtn, ... handles.VariableList, ... handles.SaveAs, ... handles.Rename, ... handles.Delete], ... {'enable'}, settings);%--------------------------------------------------------------------------%--------------------------------------------------------------------------% winBtnDownFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function winBtnDownFcn(varargin)% this function is called when the mouse click initiatesobj = varargin{1};handles = guidata(obj);if strcmpi(get(handles.timer, 'Running'), 'on') || isempty(handles.I) return;endhandles.CurrentPointAxes = get(handles.ImageAxis, 'CurrentPoint');handles.CurrentPointFig = get(handles.GrabitGUI, 'CurrentPoint');switch get(handles.GrabitGUI, 'SelectionType') case 'normal' set(handles.CoordinateEdit, 'visible', 'off'); id = find(isnan(handles.CalibPts)); if ~isempty(id) set(handles.CalibPtsH(id(1),:), 'xdata', NaN, 'ydata', NaN); end % first call winBtnMotionPauseFcn to prevent immediate click-n-drag set(handles.GrabitGUI, ... 'WindowButtonMotionFcn', ... {@winBtnMotionPauseFcn, handles, handles.CurrentPointAxes(1,1:2), clock}); case 'alt' set(handles.CoordinateEdit, 'visible', 'off'); id = find(isnan(handles.CalibPts)); if ~isempty(id) set(handles.CalibPtsH(id(1),:), 'xdata', NaN, 'ydata', NaN); end xl = get(handles.ImageAxis, 'XLim');midX = (xl(1)+xl(2))/2; yl = get(handles.ImageAxis, 'YLim');midY = (yl(1)+yl(2))/2; figPos = get(handles.GrabitGUI, 'Position'); handles.curTitle = get(get(handles.ImageAxis, 'title'), 'string'); set(handles.GrabitGUI, ... 'Pointer', 'custom', ... 'PointerShapeCData' , handles.zoomInOutPointer, ... 'PointerShapeHotSpot' , handles.zoomInOutPointerHotSpot, ... 'WindowButtonMotionFcn' , {@zoomMotionFcn, handles, ... get(handles.GrabitGUI, 'CurrentPoint'), ... figPos(4), ... size(handles.I, 2), ... midX, ... midY, ... diff(xl)/2, ... diff(yl)/2}); set(get(handles.ImageAxis, 'title'), 'string', 'Zooming...'); endguidata(obj, handles);%--------------------------------------------------------------------------%--------------------------------------------------------------------------% zoomMotionFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function zoomMotionFcn(varargin)% this performs the click-n-drag zooming function. The pointer location% relative to the initial point determines the amount of zoom (in or out).[obj, handles, initPt, figHt, horizPx, midX, ... midY, rngXhalf, rngYhalf] = splitvar(varargin([1, 3:end]));pt = get(obj, 'CurrentPoint');% get relative pointer location (y-coord only).% power law allows for the inverse to work:% C^(x) * C^(-x) = 1% Choose C to get "appropriate" zoom factorr = 30 ^ ((initPt(2) - pt(2)) / figHt);% make sure it doesn't zoom in too much.% the limit is based on the size of the original image.% set limit to 64x zoom.if r < horizPx/64/rngXhalf/2 % stop zoom set(get(handles.ImageAxis, 'title'), 'string', 'Max Zoom Reached'); set(obj, ... 'Pointer' , 'arrow', ... 'WindowButtonMotionFcn' , '');else set(handles.ImageAxis, ... 'XLim', [midX - r * rngXhalf, midX + r * rngXhalf], ... 'YLim', [midY - r * rngYhalf, midY + r * rngYhalf]);end%--------------------------------------------------------------------------%--------------------------------------------------------------------------% winBtnMotionPauseFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function winBtnMotionPauseFcn(varargin)% this prevents click-n-drag from happening for X seconds. This is useful% because users may move the mouse as they are clicking.[obj, handles, xy, c] = splitvar(varargin([1, 3:end]));if etime(clock, c) > .15 % waits .15 seconds before dragging occurs set(obj, ... 'Pointer' , 'custom', ... 'PointerShapeCData' , handles.closedHandPointer, ... 'PointerShapeHotSpot' , handles.closedHandPointerHotSpot); set(obj, 'WindowButtonMotionFcn', {@winBtnMotionFcn, handles.ImageAxis, xy}); handles.curTitle = get(get(handles.ImageAxis, 'title'), 'string'); set(get(handles.ImageAxis, 'title'), 'string', 'Panning...'); handles.isPanning = true; guidata(obj, handles);end%--------------------------------------------------------------------------%--------------------------------------------------------------------------% winBtnMotionFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function winBtnMotionFcn(varargin)% this function is called when click-n-drag (panning) is happening[axH, xy] = splitvar(varargin(3:4));pt = get(axH, 'CurrentPoint');set(axH, ... 'xlim', get(axH, 'xlim')+(xy(1)-pt(1,1)), ... 'ylim', get(axH, 'ylim')+(xy(2)-pt(1,2)));%--------------------------------------------------------------------------%--------------------------------------------------------------------------% winBtnUpFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function winBtnUpFcn(varargin)% this is called when the mouse button is released. It initiates the button% down timer object (see btnUpTimerFcn). This timer waits for 0.2 seconds% before any action is taken. This is in order to detect a double click. If% a double click is detected, the single click action is NOT executed.obj = varargin{1};handles = guidata(obj);if ~isempty(handles.I) % there is an image displayed switch get(obj, 'SelectionType') case 'normal' if strcmpi(get(handles.timer, 'Running'), 'off') % start the timer which waits some time to see if double-clicking % occurs start(handles.timer); set(obj, ... 'Pointer' , handles.curPointer, ... 'PointerShapeCData' , handles.curPointerData.CData, ... 'PointerShapeHotSpot' , handles.curPointerData.HotSpot, ... 'WindowButtonMotionFcn' , {@pointerFcn, handles, handles.curPointer}); set(get(handles.ImageAxis, 'title'), 'string', handles.curTitle); end case 'alt' set(obj, ... 'Pointer' , handles.curPointer, ...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -