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

    classdef BdrySlice3 < xregbdrygui.AbstractBdrySlice
    %xregbdrygui.BdrySlice3 class
    %   xregbdrygui.BdrySlice3 extends xregbdrygui.AbstractBdrySlice.
    %
    %    xregbdrygui.BdrySlice3 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.BdrySlice3 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 = BdrySlice3( varargin )
        % XREGBDRYGUI.BDRYSLICE3 class constructor
        
        % Call the inherited constructor
        obj@xregbdrygui.AbstractBdrySlice(varargin{ : }); % converted super class constructor call
        
        end  % BdrySlice3
        
    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 = '3D Slice';
        end  % gettitle
        
    end  % public methods
    
    methods (Access=protected)
        %----------------------------------------
        function pDrawConstraint(obj)
        %PDRAWCONSTRAINT Draw the current constraint
        %  PDRAWCONSTRAINT(OBJ)
        
        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)) );
            set( get( obj.hAxes, 'ZLabel' ), 'String', fn(obj.Axes(3)) );
            
            % 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} )] );
            set( obj.hAxes, 'ZLim', [min( vectors{3} ), max( vectors{3} )] );
            
            if isempty( con ),
                % No constraint: hide the patch
                set(obj.hPatch, 'Visible', 'off');
            else
                
                distance = constraintDistance( con, grid );
                
                fv = i_drawcontours( ...
                    vectors{:}, ...
                    reshape( distance, cellfun( 'length', vectors([2,1,3]) ).' ), ...
                    0 );
                
                if isempty( fv ),
                    set( obj.hPatch, 'Visible', 'off' );
                else
                    set( obj.hPatch, ...
                        'Vertices', fv.vertices, ...
                        'Faces',    fv.faces, ...
                        'HitTest', 'Off' );
                    set( obj.hPatch, 'Visible', 'on' );
                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)
        
        n = 3;
        
        end  % pNAxes
        
        %----------------------------------------
        function pSetupAxes(obj, hAxes) %#ok<INUSL>
        %PSETUPAXES Setup the axes for the boundary slice view
        %  PSETUPAXES(OBJ, HAXES)
        
        set( hAxes, ...
            'View', [-37.5, 30],...
            'Box', 'on',...
            'View', [10, 25], ...
            'HitTest', 'on');
        mbcgraph.camlight(hAxes);
        mv_rotate3d( hAxes, 'On' );
        
        end  % pSetupAxes
    end
    
end  % classdef

function fv = i_drawcontours( x, y, z, d, v )

ii = isfinite( d );
if any( ii(:) ),
    % Remove any infinte elements from Z and replace them instead with
    % a very large number
    minz = min( d(ii) );
    maxz = max( d(ii) );
    pad = maxz + 1e4*(maxz - minz);
    if ~isfinite( pad ),
        pad = realmax;
    end
    d(~ii) = pad;
    
    % Isosurface constraint
    [fv1] = isosurface( x, y, z, -d, v );
    [fv2] = isocaps(    x, y, z, -d, v );
    
    fv.vertices = [fv1.vertices; fv2.vertices];
    fv.faces    = [fv1.faces;    fv2.faces + size( fv1.vertices, 1 )];
else
    fv = [];
end
end  % i_drawcontours