www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+xregbdrygui/BdrySlice2.m

    classdef BdrySlice2 < xregbdrygui.AbstractBdrySlice
    %xregbdrygui.BdrySlice2 class
    %   xregbdrygui.BdrySlice2 extends xregbdrygui.AbstractBdrySlice.
    %
    %    xregbdrygui.BdrySlice2 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'
    %       MessageService - Property is of type 'handle'
    %       Options - Property is of type 'handle vector'
    %       Actions - Property is of type 'handle vector'
    %       UIContextMenu - Property is of type 'MATLAB array'
    %       InputFactors - Property is of type 'MATLAB array' (read only)
    %       NAxes - Property is of type 'int' (read only)
    %       Axes - Property is of type 'MATLAB array' (read only)
    %       hAxes - Property is of type 'MATLAB array' (read only)
    %       hPatch - Property is of type 'MATLAB array' (read only)
    %       hBlackDots - Property is of type 'MATLAB array' (read only)
    %       hRedRings - Property is of type 'MATLAB array' (read only)
    %       hValidationInside - Property is of type 'MATLAB array' (read only)
    %       hValidationOutside - Property is of type 'MATLAB array' (read only)
    %       hNoDisplayText - Property is of type 'MATLAB array' (read only)
    %       hSelectButton - Property is of type 'MATLAB array' (read only)
    %       hSliceTable - Property is of type 'handle' (read only)
    %
    %    xregbdrygui.BdrySlice2 methods:
    %       gettitle - Return a suitable title for a window
    
    % Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    methods  % constructor block
        function obj = BdrySlice2( varargin )
        % XREGBDRYGUI.BDRYSLICE2 class constructor
        
        % Call the inherited constructor
        obj@xregbdrygui.AbstractBdrySlice(varargin{ : }); % converted super class constructor call
        
        end  % BdrySlice2
        
    end  % constructor block
    
    methods  % public methods
        %----------------------------------------
        function s = gettitle(obj) %#ok<MANU>
        %GETTITLE Return a suitable title for a window
        %  GETTITLE(OBJ) returns a string that can be used as a title for the view.
        %
        %  Sub-classes should overload this.
        
        s = '2D Slice';
        
        end  % gettitle
        
    end  % public methods
    
    methods (Access=protected)
        %----------------------------------------
        function pDrawConstraint(obj)
        %PDRAWCONSTRAINT Draw the current constraint
        %  PDRAWCONSTRAINT(OBJ)
        %  See also XREGBDRYGUI.ABSTRACTBDRYSLICE.
        
        if ~obj.hasData,
            return
        end
        
        BMS = obj.MessageService;
        
        % Change the pointer to an hour-glass to make it clear to the user that
        % stuff is happening
        PR = xregGui.PointerRepository;
        ptrID = PR.stackSetPointer( obj.Parent, 'watch');
        
        % Get the current constraint for the message service
        con = BMS.getConstraint;
        
        cif = BMS.getInputFactors;
        
        if length( cif ) < obj.NAxes,
            obj.pTurnOffPlot;
        else
            obj.pTurnOnPlot;
            
            % Set the axis labels
            fn = getFullNames( cif );
            set( get( obj.hAxes, 'XLabel' ), 'String', fn(obj.Axes(1)) );
            set( get( obj.hAxes, 'YLabel' ), 'String', fn(obj.Axes(2)) );
            
            
            % Get the evaluation points from the slice table
            [vectors, grid] = getEvaluationPoints( obj );
            
            % Set the axis limits
            set( obj.hAxes, 'XLim', [min( vectors{1} ), max( vectors{1} )] );
            set( obj.hAxes, 'YLim', [min( vectors{2} ), max( vectors{2} )] );
            
            
            if isempty( con ),
                % No constraint: hide the patch
                set(obj.hPatch, 'Visible', 'off');
            else
                
                distance = constraintDistance( con, grid );
                
                newPatch = i_drawcontours( ...
                    obj.hAxes, vectors{:}, ...
                    reshape( distance, cellfun( 'length', vectors([2,1]) ).' ), ...
                    0 );
                
                if isempty( newPatch ),
                    set( obj.hPatch, 'Visible', 'off' );
                else
                    delete( obj.hPatch );
                    obj.hPatch = newPatch;
                    
                    
                    set( obj.hPatch, 'Visible', 'on' );
                    % put patch at back
                    ch = get(obj.hAxes,'Children');
                    set(obj.hAxes,'Children',[ch(~ismember(ch,newPatch));newPatch]);
                end
                
            end
            
        end
        
        % Return the mouse pointer back to what it was before
        PR.stackRemovePointer(obj.Parent, ptrID);
        
        % Draw the points
        obj.pDrawPoints;
        end  % pDrawConstraint
        
        %----------------------------------------
        function n = pNAxes(obj) %#ok<MANU>
        %PNAXES Number of axes for a slice view
        %  N = PNAXES(OBJ)
        %
        %  See also XREGBDRYGUI.ABSTRACTBDRYSLICE.
        
        n = 2;
        
        end  % pNAxes        
    end
    
end  % classdef

function p = i_drawcontours( axh, x, y, z, v )

if all( z(:) < 0 ),
    % All points are inside
    %      C = [level1 x1 x2 x3 ... level2 x2 x2 x3 ...;
    %           pairs1 y1 y2 y3 ... pairs2 y2 y2 y3 ...]
    C = [
        0 min( x ) min( x ) max( x ) max( x ) min( x )
        5 min( y ) max( y ) max( y ) min( y ) min( y )
        ];
else
    % Need to reorient Z for contours to get things pointing in the right
    % direction
    z = -z;
    
    [m, n] = size( z );
    
    ii = isfinite( z );
    if ~any( ii(:) ),
        p = [];
        return
    end
    
    % pading with a very large negative value is an easy way of getting the
    % caps from contours
    minz = min( z(ii) );
    maxz = max( z(ii) );
    pad = minz - 1e4*(maxz - minz);
    if ~isfinite( pad ),
        pad = -realmax;
    end
    z(~ii) = pad;
    
    
    z = [
        repmat( pad, 1, n + 2 );
        repmat( pad, m, 1 ), z,  repmat( pad, m, 1 );
        repmat( pad, 1, n + 2 );
        ];
    
    x = [2*x(1)-x(2), x, 2*x(end)-x(end-1)];
    y = [2*y(1)-y(2), y, 2*y(end)-y(end-1)];
    
    % find the contours
    C = contours( x, y, z, [v, v] );
end

% find patches from contours
p = xregcontours2patches( C, axh, ...
    'LineWidth', 2, ...
    'EdgeColor', 'k', ...
    'HitTest', 'off' );
end  % i_drawcontours