www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+xregbdrygui/BdryPairwiseGraph.m
classdef BdryPairwiseGraph < mbcgui.widget.BasicContainer %xregbdrygui.BdryPairwiseGraph class % xregbdrygui.BdryPairwiseGraph extends mbcgui.widget.BasicContainer % % xregbdrygui.BdryPairwiseGraph properties: % Parent - Property is of type 'MATLAB array' % Position - Property is of type 'rect' % Enable - Property is of type 'on/off' % Visible - Property is of type 'on/off' % UserData - Property is of type 'MATLAB array' % Tag - Property is of type 'string' % DataShowing - Property is of type 'bool' % BoundaryPointsVisible - Property is of type 'on/off' % ValidationPointsVisible - Property is of type 'on/off' % XIndex - Property is of type 'int' (read only) % YIndex - Property is of type 'int' (read only) % % xregbdrygui.BdryPairwiseGraph methods: % addListener - Add a listner % Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (AbortSet, SetObservable) %DATASHOWING Property is of type 'bool' DataShowing = true; %BOUNDARYPOINTSVISIBLE Property is of type 'on/off' BoundaryPointsVisible = 'off'; %VALIDATIONPOINTSVISIBLE Property is of type 'on/off' ValidationPointsVisible = 'off'; end properties (Access=protected, AbortSet) %HAXES Property is of type 'MATLAB array' hAxes = []; %HPATCH Property is of type 'MATLAB array' hPatch = []; %HHIGHLIGHT Property is of type 'MATLAB array' hHighlight = []; %HBLACKDOTS Property is of type 'MATLAB array' hBlackDots = []; %HVALIDATIONINSIDE Property is of type 'MATLAB array' hValidationInside = []; %HVALIDATIONOUTSIDE Property is of type 'MATLAB array' hValidationOutside = []; %HREDRINGS Property is of type 'MATLAB array' hRedRings = []; %HHIGHLIGHTLINE Property is of type 'MATLAB array' hHighlightLine = []; end properties (Access=protected, AbortSet, SetObservable) %HLISTENERS Property is of type 'handle vector' hListeners = []; end properties (SetAccess=protected, AbortSet) %XINDEX Property is of type 'int' (read only) XIndex %YINDEX Property is of type 'int' (read only) YIndex end events SelectHighlight end % events methods % constructor block function obj = BdryPairwiseGraph( varargin ) % XREGBDRYGUI.BDRYPAIRWISEGRAPH class constructor % Call the inherited constructor obj@mbcgui.widget.BasicContainer(varargin{ : }); % converted super class constructor call % Generate GUI primitives and link together into a layout obj.ContentHandle= mbcgui.widget.AxesContainer(... 'Parent', obj.Parent, ... 'Visible', 'off', ... 'Border', [15, 10, 15, 10] ); obj.hAxes = obj.ContentHandle.AxesHandle; set(obj.hAxes,... 'Box','on',... 'XGrid','on',... 'YGrid','on',... 'XTickLabel', '',... 'YTickLabel', '',... 'Units','pixels',... 'Layer','top',... 'Tag', 'BdryPairwiseAxis', ... 'ButtonDownFcn', @(s, e) obj.pStartHighlight ); xlabel( obj.hAxes, '', 'Interpreter', 'none' ); ylabel( obj.hAxes, '', 'Interpreter', 'none' ); zlabel( obj.hAxes, '', 'Interpreter', 'none' ); obj.hPatch = patch( ... 'Parent',obj.hAxes, ... 'Faces', [], ... 'Vertices', [], ... 'HitTest', 'off' ); obj.hHighlight = patch( ... 'Parent',obj.hAxes, ... 'Faces', [], ... 'Vertices', [], ... 'HitTest', 'off' ); obj.hBlackDots = line( ... 'Parent',obj.hAxes, ... 'LineStyle', 'none', ... 'Marker', '.', ... 'MarkerEdgeColor', 'k', ... 'MarkerFaceColor', 'k', ... 'MarkerSize', 15, ... 'XData', [], ... 'YData', [], ... 'ZData', [], ... 'HitTest', 'off' ); obj.hValidationInside = line( ... 'Parent',obj.hAxes, ... 'LineStyle', 'none', ... 'Marker', '^', ... 'MarkerFaceColor', [50, 200, 50]/255, ... 'MarkerSize', 6, ... 'XData', [], ... 'YData', [], ... 'ZData', [], ... 'HitTest', 'off', ... 'Visible', obj.ValidationPointsVisible, ... 'Tag', ''); obj.hValidationOutside = line( ... 'Parent',obj.hAxes, ... 'LineStyle', 'none', ... 'Marker', '^', ... 'MarkerFaceColor', [200, 50, 50]/255, ... 'MarkerSize', 6, ... 'XData', [], ... 'YData', [], ... 'ZData', [], ... 'HitTest', 'off', ... 'Visible', obj.ValidationPointsVisible, ... 'Tag', ''); obj.hRedRings = line(... 'Parent',obj.hAxes, ... 'LineStyle', 'none', ... 'LineWidth', 2, ... 'Marker', 'o', ... 'MarkerEdgeColor', 'r', ... 'MarkerFaceColor', 'none', ... 'MarkerSize', 10, ... 'XData', [], ... 'YData', [], ... 'ZData', [], ... 'HitTest', 'off', ... 'Visible', obj.BoundaryPointsVisible); obj.hHighlightLine = line(... 'Parent',obj.hAxes, ... 'Color', 'r', ... 'LineStyle', '-', ... 'LineWidth', 2, ... 'Marker', 'None', ... 'XData', [], ... 'YData', [], ... 'ZData', [], ... 'HitTest', 'off' ); mbcgui.hgclassesutil.setNotPickable([obj.hHighlightLine obj.hRedRings obj.hValidationOutside obj.hValidationInside obj.hBlackDots obj.hPatch]); obj.hListeners = [ event.proplistener( obj, obj.findprop( 'DataShowing' ), 'PostSet', @(s, e) obj.setVisible ) event.proplistener( obj, obj.findprop( 'BoundaryPointsVisible' ), 'PostSet', @(s, e) obj.pPostSetBoundaryPointsVisible ) event.proplistener( obj, obj.findprop( 'ValidationPointsVisible' ), 'PostSet', @(s, e) obj.pPostSetValidationPointsVisible ) ]; end % BdryPairwiseGraph end % constructor block methods % public methods %---------------------------------------- function addListener(obj, hListener) %ADDLISTENER Add a listner % ADDLISTENER(OBJ, HLISTENER) obj.hListeners = [ obj.hListeners hListener ]; end % addListener %---------------------------------------- function setTableData(obj, R, C, data) %SETTABLEDATA Scrolling table interface function. % SETTABLEDATA(OBJ, R, C, DATA) % There is nothing to show above the main diagonal obj.DataShowing = C <= R; if obj.DataShowing, % Each graphical object's data is placed at a different Z value so that % everything layers correctly: MAIN_FACE = 0; HIGHLIGHT_FACE = 1; HIGHLIGHT_HOLE = 2; MAIN_HOLE = 3; DATA_PTS = 4; BOUNDARY_PTS = 5; HIGHLIGHT_LINE = 6; % Note: this value is also used in pFinishHighlight cif = data.MessageService.getInputFactors; set(obj.hAxes ,'XLim', [cif(C).Min, cif(C).Max], 'YLim', [cif(R+1).Min, cif(R+1).Max]); tagName = sprintf('BdryPairwiseR%dC%d', R, C); % Main patch. The holes are lifted to leave levels for the highlight % patches and holes if isgraphics(obj.hPatch) delete( obj.hPatch ); end obj.hPatch = xregcontours2patches( ... data.getMainContours( R, C ), ... obj.hAxes, ... 'FaceLevel', MAIN_FACE, ... 'HoleLevel', MAIN_HOLE, ... 'LineWidth', 2, ... 'FaceColor', [0.5, 0.5, 1], ... % light blue 'EdgeColor', 'k', ... 'HitTest', 'off' ); xd = data.getBlackDotXData( R, C ); yd = data.getBlackDotYData( R, C ); set( obj.hBlackDots, ... 'XData', xd, ... 'YData', yd, ... 'ZData', repmat(DATA_PTS, size(xd))); obj.BoundaryPointsVisible = data.MessageService.BoundaryPointHighlight; xd = data.getRedRingXData( R, C ); yd = data.getRedRingYData( R, C ); set( obj.hRedRings, ... 'XData', xd, ... 'YData', yd, ... 'ZData', repmat(BOUNDARY_PTS, size(xd))); % validation data % made up of dots (data inside) and crosses (data outside) obj.ValidationPointsVisible = data.MessageService.ValidationPointHighlight; [xInside, xOutside] = data.getValidationXData( R, C ); [yInside, yOutside] = data.getValidationYData( R, C ); set( obj.hValidationInside, ... 'XData', xInside, ... 'YData', yInside, ... 'ZData', repmat(DATA_PTS, size(xInside)), ... 'Tag', [tagName, 'ValidationInside']); set( obj.hValidationOutside, ... 'XData', xOutside, ... 'YData', yOutside, ... 'ZData', repmat(DATA_PTS, size(xOutside)), ... 'Tag', [tagName, 'ValidationOutside']); % Highlight patch if isgraphics(obj.hHighlight) delete( obj.hHighlight ); end obj.hHighlight = xregcontours2patches( ... data.getHighlightContours( R, C ), ... obj.hAxes, ... 'FaceLevel', HIGHLIGHT_FACE, ... 'HoleLevel', HIGHLIGHT_HOLE, ... 'LineWidth', 2, ... 'FaceColor', [1, 1, 0], ... % yellow 'HoleColor', [0.5 0.5 1], ... % Same color as main patch 'EdgeColor', 'k', ... 'HitTest', 'off' ); xd = data.getHighlightLineXData( R, C ); yd = data.getHighlightLineYData( R, C ); set( obj.hHighlightLine, ... 'XData', xd, ... 'YData', yd, ... 'ZData', repmat(HIGHLIGHT_LINE, size(xd))); obj.XIndex = C; obj.YIndex = R; end end % setTableData end % public methods methods (Access=protected) %---------------------------------------- function pFinishHighlight(obj, point1) %PFINISHHIGHLIGHT Finishes the "select highlight region" process % PFINISHHIGHLIGHT(OBJ) point2 = get( obj.hAxes, 'CurrentPoint' ); rectangle = [point1(1,1:2); point2(1,1:2)]; set( obj.hHighlightLine, ... 'XData', rectangle([1,1,2,2,1],1), ... 'YData', rectangle([1,2,2,1,1],2), ... 'ZData', [6 6 6 6 6]); drawnow % Send event data = struct( ... 'XIndex', obj.XIndex, ... 'YIndex', obj.YIndex, ... 'Rectangle', rectangle, ... 'MinPoint', min( rectangle, [], 1 ), ... 'MaxPoint', max( rectangle, [], 1 ) ); eventData = xregEventData( data ); obj.notify( 'SelectHighlight', eventData ); end % pFinishHighlight %---------------------------------------- function pPostSetBoundaryPointsVisible(obj, ~,~) %PPOSTSETBOUNDARYPOINTSVISIBLE Set visbibilty of the boundary point line. % PPOSTSETBOUNDARYPOINTSVISIBLE(OBJ, EVT) set(obj.hRedRings, 'Visible', obj.BoundaryPointsVisible); end % pPostSetBoundaryPointsVisible %---------------------------------------- function pPostSetValidationPointsVisible(obj, ~,~) %PPOSTSETVALIDATIONPOINTSVISIBLE Set visibilty of the validation points. % PPOSTSETVALIDATIONPOINTSVISIBLE(OBJ, EVT) set(obj.hValidationInside, 'Visible', obj.ValidationPointsVisible); set(obj.hValidationOutside, 'Visible', obj.ValidationPointsVisible); end % pPostSetValidationPointsVisible %---------------------------------------- function pStartHighlight(obj) %PSTARTHIGHLIGHT Starts the "select highligh region" process % PSTARTHIGHLIGHT(OBJ) % Get the point where the user first clicks hFig = ancestor(obj.Parent,'figure'); pt = get( hFig, 'CurrentPoint' ); point1 = get( obj.hAxes, 'CurrentPoint' ); % Use a "rubberband box" to show the user where they're selecting % draw the rubber band box rbbox([pt(1) pt(2) 0 0 ]); obj.pFinishHighlight( point1 ) end % pStartHighlight function setVisible(obj, vis) %setVisible Ensure that the visibility of widget is correctly set. % setVisible(OBJ, vis) if nargin==1 vis = obj.Visible; end if obj.DataShowing set(obj.ContentHandle, 'Visible', vis); else set(obj.ContentHandle, 'Visible', 'off'); end end end end % classdef