utentpar.m
上传用户:haiyisale
上传日期:2013-01-09
资源大小:3246k
文件大小:13k
源码类别:

波变换

开发平台:

Matlab

  1. function varargout = utentpar(option,fig,varargin)
  2. %UTENTPAR Utilities for wavelet packets entropy.
  3. %   VARARGOUT = UTENTPAR(OPTION,FIG,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 13-May-98.
  5. %   Last Revision: 26-Dec-2001.
  6. %   Copyright 1995-2002 The MathWorks, Inc.
  7. %   $Revision: 1.9 $
  8. % Tag property of objects.
  9. %-------------------------
  10. tag_ent_par = 'Fra_EntPar';
  11. switch option
  12.     case 'create'
  13.         % Get Globals.
  14.         %--------------
  15.         [Def_Txt_Height,Def_Btn_Height,Def_Btn_Width,Pop_Min_Width, ...
  16.          X_Spacing,Y_Spacing,Def_FraBkColor,Def_EdiBkColor] = ...
  17.             mextglob('get',...
  18.                 'Def_Txt_Height','Def_Btn_Height','Def_Btn_Width', ...
  19.                 'Pop_Min_Width','X_Spacing','Y_Spacing', ...
  20.                 'Def_FraBkColor','Def_EdiBkColor');
  21.         % Positions utilities.
  22.         %---------------------
  23.         dx = X_Spacing; bdx = 3;
  24.         dy = Y_Spacing; bdy = 4;        
  25.         d_txt  = (Def_Btn_Height-Def_Txt_Height);
  26.         deltaY = (Def_Btn_Height+dy);
  27.         % Defaults.
  28.         %----------
  29.         xleft = Inf; xright  = Inf; xloc = Inf;
  30.         ytop  = Inf; ybottom = Inf; yloc = Inf;
  31.         bkColor = Def_FraBkColor;
  32.         enaVAL  = 'on';
  33.         ent_Nam = 'default';
  34.         ent_Par = 0;
  35.         % Parsing Inputs.
  36.         %----------------        
  37.         nbarg = nargin-2;
  38.         for k=1:2:nbarg
  39.             arg = lower(varargin{k});
  40.             switch arg
  41.               case 'left'    , xleft   = varargin{k+1};
  42.               case 'right'   , xright  = varargin{k+1};
  43.               case 'xloc'    , xloc    = varargin{k+1};
  44.               case 'bottom'  , ybottom = varargin{k+1};
  45.               case 'top'     , ytop    = varargin{k+1};
  46.               case 'yloc'    , yloc    = varargin{k+1};
  47.               case 'bkcolor' , bkColor = varargin{k+1};              
  48.               case 'enable'  , enaVAL  = varargin{k+1};
  49.               case 'nam' ,     ent_Nam = lower(deblankl(varargin{k+1}));
  50.               case 'par' ,     ent_Par = varargin{k+1};
  51.               case 'ent'
  52.                 ent_Nam = lower(deblankl(varargin{k+1}{1}));
  53.                 ent_Par = varargin{k+1}{2};
  54.             end 
  55.         end
  56.         str_numfig = num2mstr(fig);
  57.         old_units  = get(fig,'units');
  58.         fig_units  = 'pixels';
  59.         if ~isequal(old_units,fig_units), set(fig,'units',fig_units); end       
  60.         % Setting frame position.
  61.         %------------------------
  62.         w_fra   = wfigmngr('get',fig,'fra_width');
  63.         h_fra   = Def_Btn_Height+2*bdy;
  64.         xleft   = utposfra(xleft,xright,xloc,w_fra);
  65.         ybottom = utposfra(ybottom,ytop,yloc,h_fra);
  66.         pos_fr1 = [xleft,ybottom,w_fra,h_fra];
  67.         pos_fr2 = [xleft,ybottom-deltaY,w_fra,h_fra+deltaY];
  68.  
  69.         % Position property of objects.
  70.         %------------------------------
  71.         xleft = xleft+bdx;
  72.         ylow  = ybottom+h_fra-Def_Btn_Height-bdy;
  73.         pos_txt_ent = [xleft, ylow+d_txt/2, Def_Btn_Width, Def_Txt_Height];
  74.         xl          = pos_txt_ent(1)+pos_txt_ent(3);
  75.         pos_pop_ent = [xl, ylow, 2*Pop_Min_Width, Def_Btn_Height];
  76.         ylow        = ylow-deltaY;
  77.         pos_txt_par    = pos_txt_ent;
  78.         pos_txt_par(2) = ylow+d_txt/2;
  79.         xl             = pos_txt_par(1)+pos_txt_par(3);
  80.         pos_uic_ent    = [xl, ylow, 2*Pop_Min_Width, Def_Btn_Height];
  81.         % String property of objects.
  82.         %----------------------------
  83.         str_txt_ent = 'Entropy';
  84.         str_pop_ent = strvcat('shannon','threshold','norm', ...
  85.                               'log energy','sure','user');
  86.         str_txt_par = 'Ent. Param.';
  87.         str_uic_ent = '';
  88.         % Create objects.
  89.         %----------------
  90.         comFigProp = {'Parent',fig,'Unit',fig_units};
  91.         fra_ent = uicontrol(...
  92.                             comFigProp{:}, ...
  93.                             'Style','frame', ...
  94.                             'Position',pos_fr1, ...
  95.                             'Backgroundcolor',bkColor, ...
  96.                             'Tag',tag_ent_par ...
  97.                             );
  98.         txt_ent = uicontrol(...
  99.                             comFigProp{:},                  ...
  100.                             'Style','text',                 ...
  101.                             'HorizontalAlignment','left',   ...
  102.                             'Position',pos_txt_ent,         ...
  103.                             'String',str_txt_ent,           ...
  104.                             'Backgroundcolor',Def_FraBkColor...
  105.                             );
  106.         pop_ent = uicontrol(...
  107.                             comFigProp{:},          ...
  108.                             'Style','Popup',        ...
  109.                             'Position',pos_pop_ent, ...
  110.                             'String',str_pop_ent,   ...
  111.                             'Enable',enaVAL         ...
  112.                             );
  113.         txt_par = uicontrol(...
  114.                             comFigProp{:}, ...
  115.                             'Style','text',                 ...
  116.                             'Visible','off',                ...
  117.                             'HorizontalAlignment','left',   ...
  118.                             'Position',pos_txt_par,         ...
  119.                             'String',str_txt_par,           ...
  120.                             'Backgroundcolor',Def_FraBkColor...
  121.                             );
  122.         uic_ent = uicontrol(...
  123.                             comFigProp{:},          ...
  124.                             'Style','edit',         ...
  125.                             'Position',pos_uic_ent, ...
  126.                             'Visible','off',        ...
  127.                             'HorizontalAlignment','center', ...
  128.                             'String',str_uic_ent,   ...
  129.                             'Enable',enaVAL,        ...
  130.                             'Backgroundcolor',Def_EdiBkColor...
  131.                             );
  132.         % Store data.
  133.         %------------
  134.         pos_fig = get(fig,'Position');
  135.         nor_rat = [pos_fig(3) pos_fig(4) pos_fig(3) pos_fig(4)];
  136.         pos_fr1_Norm = pos_fr1./nor_rat;
  137.         pos_fr2_Norm = pos_fr2./nor_rat;
  138.         ud.handles   = [fra_ent,txt_ent,pop_ent,txt_par,uic_ent];
  139.         ud.positions = [pos_fr1 ; pos_fr2 ; pos_fr1_Norm ; pos_fr2_Norm];
  140.         set(fra_ent,'Userdata',ud);
  141.         if ~isequal(old_units,fig_units)
  142.             set([fig;ud.handles],'units',old_units);
  143.         end       
  144. % Add Context Sensitive Help (CSHelp).
  145. %-------------------------------------
  146. wfighelp('add_ContextMenu',fig,ud.handles,'WP_ENTROPY');
  147. %-------------------------------------
  148.         % Callbacks update.
  149.         %------------------
  150.         cba_pop_ent = [mfilename  '(''set'',' str_numfig ');'];
  151.         set(pop_ent,'Callback',cba_pop_ent);
  152.  
  153.         % Initialize entropy.
  154.         %-------------------       
  155.         if ~isequal(ent_Nam,'default')
  156.             utentpar('set',fig,'ent',{ent_Nam,ent_Par});
  157.         end
  158.         if nargout>0
  159.             varargout = {get(fra_ent,'Position') , [pos_fr1_Norm ; pos_fr2_Norm]};
  160.         end
  161.     case 'create_copy'
  162.         createArg = varargin{1};
  163.         [varargout{1},varargout{2}] = utentpar('create',fig,createArg{:});
  164.         [pop_ent,uic_ent] = utentpar('handles',fig,'act');
  165.         Def_FraBkColor = mextglob('get','Def_FraBkColor');
  166.         copyOpt = 1;
  167.         if copyOpt
  168.             prop = get(pop_ent,{'Value','String'});
  169.             newProp = {'Style','Edit','BackGroundColor',Def_FraBkColor, ...
  170.                        'Enable','Inactive', ...
  171.                        'String',prop{2}(prop{1},:)};
  172.             set(pop_ent,newProp{:});
  173.         else
  174.             inactCol = mextglob('get','Def_TxtBkColor');
  175.             set(pop_ent,'enable','inactive','ForeGroundColor',inactCol);
  176.         end
  177.         set(uic_ent,'enable','inactive','BackGroundColor',Def_FraBkColor);
  178.     case 'handles'
  179.         fra = findobj(get(fig,'Children'),'flat','style','frame',...
  180.                       'tag',tag_ent_par);
  181.         ud = get(fra,'Userdata');
  182.         varargout = num2cell(ud.handles);
  183.         % One more input to get "active" handles.
  184.         if length(varargin)>0 , varargout = varargout([3 5]); end
  185.     case {'toolPosition','position'}
  186.         fra = findobj(fig,'style','frame','tag',tag_ent_par);
  187.         varargout = get(fra,{'Position','Units'});
  188.     case 'set'
  189.         nbarg = length(varargin);
  190.         [fra_ent,txt_ent,pop_ent,txt_par,uic_ent] = utentpar('handles',fig);
  191.         if nbarg==0
  192.            tmp = get(pop_ent,{'String','Value'});
  193.            ent_Nam = lower(deblankl(tmp{1}(tmp{2},:)));
  194.            ent_Par = '';
  195.         end
  196.         for k = 1:2:nbarg
  197.            argType = varargin{k};
  198.            argVal  = varargin{k+1};
  199.            switch argType
  200.              case 'nam' , ent_Nam = lower(deblankl(argVal));
  201.              case 'par' , ent_Par = argVal;
  202.              case 'ent'
  203.                ent_Nam = lower(deblankl(argVal{1}));
  204.                ent_Par = argVal{2};
  205.            end
  206.         end
  207.         num = getNum(ent_Nam);
  208.         switch ent_Nam
  209.             case {'shannon','logenergy'}
  210.               vis     = 'off';
  211.               str_txt = 'Ent. Param.';
  212.               str_val = '';  
  213.             case {'threshold','sure'}
  214.               vis     = 'on';
  215.               str_txt = 'Threshold';
  216.               str_val = num2str(ent_Par);  
  217.             case 'norm'
  218.               vis     = 'on';
  219.               str_txt = 'Power';
  220.               str_val = num2str(ent_Par);  
  221.             case 'user'
  222.               vis     = 'on';
  223.               str_txt = 'Funct. Name';
  224.               str_val = ent_Par;  
  225.         end
  226.         old_vis = get(txt_par,'Visible');
  227.         if ~isequal(old_vis,vis)
  228.             ud = get(fra_ent,'Userdata');
  229.             positions = ud.positions;
  230.             units = get(fig,'units');
  231.             units = lower(units(1:3));
  232.             if isequal(units,'pix') , dPOS = 0; else , dPOS = 2; end 
  233.             switch vis
  234.               case 'off' , pos_fra = positions(1+dPOS,:);
  235.               case 'on'  , pos_fra = positions(2+dPOS,:);
  236.             end
  237.             set(fra_ent,'Position',pos_fra);
  238.         end
  239.         set(pop_ent,'Value',num);        
  240.         set(txt_par,'String',str_txt,'Visible',vis);
  241.         set(uic_ent,'String',str_val,'Visible',vis);
  242.     case 'get'
  243.         nbarg = length(varargin);
  244.         if nbarg<1 , return; end
  245.         [pop_ent,uic_ent] = utentpar('handles',fig,'act');
  246.         tmp = get(pop_ent,{'Style','String','Value'});
  247.         if isequal(tmp{1},'popupmenu')
  248.             ent_Nam = tmp{2}(tmp{3},:);
  249.         else
  250.             ent_Nam = tmp{2};
  251.         end
  252.         ent_Nam = lower(deblankl(ent_Nam));
  253.         ent_Par = deblankl(get(uic_ent,'String'));
  254.         switch ent_Nam
  255.           case {'shannon','logenergy'} , ent_Par = 0; err = 0;
  256.           case {'threshold','norm','sure'}
  257.             err = isempty(abs(ent_Par));
  258.             if ~err
  259.                  ent_Par = wstr2num(ent_Par);
  260.                  err = isempty(ent_Par);
  261.                  if ~err
  262.                     if isequal(ent_Nam,'norm')
  263.                         err = (ent_Par<1);
  264.                     else
  265.                         err = (ent_Par<=0);
  266.                     end
  267.                  end
  268.             end
  269.           case 'user'         
  270.             ok = exist(ent_Par);
  271.             if isempty(ok) | ~ismember(ok,[2 3 5 6])
  272.                 err = 2;
  273.             else
  274.                 err = 0;
  275.             end
  276.         end
  277.         varargout = {};
  278.         ind = 1;
  279.         for k = 1:nbarg
  280.            outType = varargin{k};
  281.            switch outType
  282.              case 'nam' , varargout{ind} = ent_Nam; ind = ind+1;
  283.              case 'par' , varargout{ind} = ent_Par; ind = ind+1;
  284.              case 'ent' 
  285.                varargout{ind} = ent_Nam; ind = ind+1;
  286.                varargout{ind} = ent_Par; ind = ind+1;
  287.              case 'txt'
  288.                 switch ent_Nam
  289.                    case {'shannon','logenergy'}
  290.                        varargout{ind} = '';
  291.                    case {'threshold','sure'}
  292.                        varargout{ind} = 'Threshold';
  293.                    case 'norm'
  294.                        varargout{ind} = 'Power';
  295.                    case 'user'
  296.                        varargout{ind} = 'Funct. Name';
  297.                 end
  298.                 ind = ind+1;
  299.            end
  300.         end
  301.         varargout{ind} = err; 
  302.     case 'enable'
  303.         [pop_ent,uic_ent] = utentpar('handles',fig,'act');
  304.         set([pop_ent,uic_ent],'enable',varargin{1});
  305.     case 'clean'
  306.         utentpar('set',fig,'nam','shannon');
  307.     otherwise
  308.         errargt(mfilename,'Unknown Option','msg');
  309.         error('*');
  310. end
  311. %--------------------------------
  312. function num = getNum(entNam)
  313. switch entNam
  314.   case 'shannon'  , num = 1;
  315.   case 'threshold', num = 2;
  316.   case 'norm'     , num = 3;
  317.   case 'logenergy', num = 4;
  318.   case 'sure'     , num = 5;
  319.   case 'user'     , num = 6;
  320. end
  321. %--------------------------------