⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bvqxprogress.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
字号:
function p = BVQXprogress(p, pval, ptxt, pstate, pmin, pmax)
% bvqxprogress  - show a progress bar
%
% FORMAT:       p = BVQXprogress([opts]);
%         or    [p] = BVQXprogress(p, pval, ptxt, pstate, pmin, pmax)
%         or    BVQXprogress(p, cmd, cmdarg);
%
% Input fields:
%
%       opts        1x1 struct with optional settings
%        .colors    2x3 RGB for bar colors
%
%       p           BVQXprogress object
%       pval        current progress value
%       ptxt        label (e.g. current progress step)
%       pstate      one of 'close', 'hidden', {'visible'}
%       pmin        minimum value, default: 0
%       pmax        maximum value, default: 1
%
%       cmd         either of
%                   'close' (use an empty 3rd arg)
%                   'setcaption'
%                   'setposition' (1x2 screen pixels)
%                   'setsize' (1x2 screen size)
%                   'settitle'
%                   'setvisible'
%       cmdarg      a valid argument for the command
%
% Note: to start using the class, create an empty progress object
%       which will have the state hidden
%
%       p = BVQXprogress;
%
%       then call the class method to change the object
%
%       [p] = BVQXprogress(p, ...);
%       BVQXprogress(p, 'settitle', 'Preparing GLM...');

% Version:  v0.7a
% Build:    7081610
% Date:     Aug-16 2007, 10:17 AM CEST
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% default constructor
if nargin < 1 || ...
    numel(p) ~= 1 || ...
   ~strcmpi(class(p), 'bvqxprogress')
    
    % but only called for empty argument list
    if nargin > 0 && ...
       ~isstruct(p)
        error( ...
            'BVQXprogress:BadCall', ...
            'Bad call to BVQXprogress.' ...
        );
    end
    if nargin > 0 && ...
        isstruct(p)
        opts = p;
    else
        opts = struct;
    end
    
    % get ROOT object properties
    rp = get(0);
    if ~any(rp.ScreenSize > 1)
        error( ...
            'BVQXprogress:NoScreen', ...
            'No GUI object available.' ...
        );
    end
    
    % generate figure object
    hFig = figure(...
        'CloseRequestFcn', 'false;', ...
        'IntegerHandle',   'off', ...
        'Menubar',         'none', ...
        'Name',            'BVQXtools progress...', ...
        'NumberTitle',     'off', ...
        'Toolbar',         'none', ...
        'Units',           'pixels', ...
        'Visible',         'off');
    set(hFig, 'Visible',   'off');
    set(hFig, 'Position', ...
        [rp.ScreenSize(3) / 2 - 240, rp.ScreenSize(4) / 2, 480, 36]);
    
    % configure progress bar objects
    numlines = 128;
	numcols  = fix((numlines + 1) / 2);
    iCap = 'Progress:';
    if isfield(opts, 'color') && ...
        isa(opts.color, 'double') && ...
        numel(size(opts.color)) == 2 && ...
        all(size(opts.color) == [2, 3]) && ...
       ~any(isnan(opts.color(:))) && ...
        all(opts.color(:) >= 0 & opts.color(:) <= 255)
        iCBG = opts.color(1, :);
        iCFG = opts.color(2, :);
        if any(opts.color(:) > 1)
            iCBG = iCBG ./ 255;
            iCFG = iCFG ./ 255;
        end
    else
        iCBG = [ 16,  32, 192] / 255;
        iCFG = [128, 192, 240] / 255;
    end

    % put together bar image
    imgpdata(numlines, 1, 3) = uint8(0);
    for colc = 1:numcols
        colb = (numcols - colc) / numcols;
        colf = colc / numcols;
        ridx = [colc (numlines + 1 - colc)];
        imgpdata(ridx, 1, 1) = ...
            uint8(fix(255 * (colb * iCBG(1) + colf * iCFG(1)) + 0.5));
        imgpdata(ridx, 1, 2) = ...
            uint8(fix(255 * (colb * iCBG(2) + colf * iCFG(2)) + 0.5));
        imgpdata(ridx, 1, 3) = ...
            uint8(fix(255 * (colb * iCBG(3) + colf * iCFG(3)) + 0.5));
    end

    % create first axes and add image
    AxProp = struct( ...
        'Parent',   hFig, ...
        'Color',    'none', ...
        'Units',    'normalized', ...
        'Position', [0.05, 0.15, 0.9, 0.7]);
    hBarAx = axes(AxProp);
    image(imgpdata, 'Parent', hBarAx);
    set(hBarAx, 'Visible', 'off');

    % create second axes for outline and caption
    hLabAx = axes(AxProp);
    line(...
        [0 1 1 0 0], [0 0 1 1 0], ...
        'Parent',    hLabAx, ...
        'EraseMode', 'none', ...
        'Color',     iCBG * 0.75, ...
        'Visible',   'on');

    CapProp = struct('Parent', hLabAx);
    CapProp.Units           = 'normalized';
    CapProp.Position        = [0.02 0.52];
    CapProp.HorizontalAlign = 'left';
    CapProp.VerticalAlign   = 'middle';
    CapProp.FontSize        = 11;
    CapProp.FontWeight      = 'demi';
    CapProp.FontUnits       = 'points';
    CapProp.Interpreter     = 'none';
    if prod(iCFG) < 0.125 && ...
        all(iCFG < 0.25)
        CapProp.Color       = [0.9325 0.9325 0.9325];
    else
        CapProp.Color       = iCBG * 0.125;
    end

    % generate text object
    hBarTxt = text(0.5, 0.5, iCap, CapProp);

    % get size, set Units back to original units and init progress
    set(hLabAx, 'Units', 'normalized', 'Visible', 'off');

    % fill class object
    p = struct;
    p.hFig = hFig;
    p.hBar = hBarAx;
    p.hLab = hBarTxt;
    p.pBar = get(p.hBar, 'Position');
    p.vCur = 0;
    p.vDst = 1;
    p.vMax = 1;
    p.vMin = 0;
    
    % create class object
    p = class(p, 'BVQXprogress');
    
    % set bar width
    p = BVQXprogress(p, p.vCur);
    
    % return
    return;
    
end

% empty call
if nargin == 1
    p = p.vCur;
    return;
end

% command call
if nargin > 2 && ...
    ischar(pval) && ...
    any(strcmpi(pval(:)', ...
        {'close', 'setcaption', ...
         'setposition', 'setsize', ...
         'settitle', 'setvisible'}))
    
    % what command ?
    switch (lower(pval(:)'))
        
        % close fig
        case {'close'}
            delete(p.hFig);
            
        % caption
        case {'setcaption'}
            try
                set(p.hLab, 'String', ptxt);
            catch
                % do nothing
            end
        
        % position
        case {'setposition'}
            try
                if numel(ptxt) ~= 4
                    fpos = get(p.hFig, 'Position');
                    set(p.hFig, 'Position', [ptxt(1:2), fpos(3:4)]);
                else
                    set(p.hFig, 'Position', ptxt);
                end
            catch
                % do nothing
            end
            
        % size
        case {'setsize'}
            try
                fpos = get(p.hFig, 'Position');
                if numel(ptxt) < 2
                    set(p.hFig, 'Position', [fpos(1:2), ptxt(1), fpos(4)]);
                else
                    set(p.hFig, 'Position', [fpos(1:2), ptxt(1:2)]);
                end
            catch
                % do nothing
            end
            
        % title
        case {'settitle'}
            try
                set(p.hFig, 'Name', ptxt);
            catch
                % do nothing
            end
            
        % visibility
        case {'setvisible'}
            try
                set(p.hFig, 'Visible', ptxt);
            catch
                % do nothing
            end
    end
    
    % return
    drawnow;
    return;
end

% objects must still exist
if ~ishandle(p.hFig) || ...
   ~ishandle(p.hBar) || ...
   ~ishandle(p.hLab)
    warning( ...
        'BVQXprogress:BadHandle', ...
        'Handle of figure, bar or text object disappeared.' ...
    );
    return;
end

% genuine call with initial settings?
if nargin > 1 && ...
    isa(pval, 'double') && ...
    numel(pval) == 1 && ...
   ~isinf(pval) && ...
   ~isnan(pval)

    % make sure value is OK
    pval = min(p.vMax, max(p.vMin, pval));
    p.vCur = pval;
    
    % set size
    pval = max(p.vMin + eps, pval);
    set(p.hBar, 'Position', ...
        [p.pBar(1:2), p.pBar(3) * (pval - p.vMin) / p.vDst, p.pBar(4)]);
    
    % anything else
    if nargin > 2 && ...
        ischar(ptxt) && ...
        ~isempty(ptxt)
        set(p.hLab, 'String', ptxt(:)');
    end
    if nargin > 3 && ...
        ischar(pstate) && ...
        any(strcmpi(pstate(:)', {'close', 'hidden', 'visible'}))
        switch (lower(pstate(:)'))
            case {'close'}
                BVQXprogress(p, 'close', []);
                return;
            case {'hidden'}
                set(p.hFig, 'Visible', 'off');
            case {'visible'}
                set(p.hFig, 'Visible', 'on');
        end
    end
    if nargin > 5 && ...
        isa(pmin, 'double') && ...
        numel(pmin) == 1 && ...
        ~isinf(pmin) && ...
        ~isnan(pmin) && ...
        isa(pmax, 'double') && ...
        numel(pmax) == 1 && ...
        ~isinf(pmax) && ...
        ~isnan(pmax) && ...
        pmax > pmin
        p.vMin = pmin;
        p.vMax = pmax;
        p.vDst = pmax - pmin;
        p.vCur = min(pmax, max(pmin, p.vCur));
        BVQXprogress(p, p.vCur);
    end
    
    % update screen
    drawnow;
    
    % set back
    if ~isempty(inputname(1))
        try
            assignin('caller', inputname(1), p);
        catch
            % do nothing
        end
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -