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

波变换

开发平台:

Matlab

  1. function varargout = utcolmap(option,fig,varargin)
  2. %UTCOLMAP Wavelet colormap utilities.
  3. %   VARARGOUT = UTCOLMAP(OPTION,FIG,VARARGIN)
  4. %   option = 'create' or 'handles'
  5. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 01-May-98.
  6. %   Last Revision: 05-Feb-2003.
  7. %   Copyright 1995-2004 The MathWorks, Inc.
  8. %   $Revision: 1.6.4.2 $  $Date: 2004/03/15 22:42:05 $
  9. if isempty(find(wfindobj('figure')==fig)) , return; end
  10. % Tagged Objects.
  11. %----------------
  12. tag_col_par = 'Fra_ColPar';
  13. switch option
  14.     case {'Install_V3','Install_V3_CB','create'}
  15.         % Default Values.
  16.         %----------------
  17.         maxmax_nbcolors = 448;
  18.         min_nbcolors = 2;
  19.         def_nbcolors = 128;
  20.         min_bright   = -2;
  21.         max_bright   = 2;
  22.         def_bright   = 0;
  23.         % Defaults Inputs.
  24.         %----------------
  25.         xleft = Inf; xright  = Inf; xloc = Inf;
  26.         ytop  = Inf; ybottom = Inf; yloc = Inf;
  27.         ybottom = NaN;
  28.         bkColor = NaN;
  29.         briFlag = 1;
  30.         enaVAL  = 'off';
  31.         max_nbcolors = 256;
  32.         % Parsing Inputs.
  33.         %----------------        
  34.         nbarg = nargin-2;
  35.         for k=1:2:nbarg
  36.             arg = lower(varargin{k});
  37.             switch arg
  38.               case 'left'    , xleft   = varargin{k+1};
  39.               case 'right'   , xright  = varargin{k+1};
  40.               case 'xloc'    , xloc    = varargin{k+1};
  41.               case 'bottom'  , ybottom = varargin{k+1};
  42.               case 'top'     , ytop    = varargin{k+1};
  43.               case 'yloc'    , yloc    = varargin{k+1};
  44.               case 'bkcolor' , bkColor = varargin{k+1};              
  45.               case 'briflag' , briFlag = varargin{k+1};
  46.               case 'enable'  , enaVAL  = varargin{k+1};
  47.               case 'maxnbcol', max_nbcolors = varargin{k+1};
  48.             end
  49.         end
  50.         str_numfig = num2mstr(fig);
  51.         
  52.         switch option
  53.             case 'Install_V3'
  54.                 % Get Handles.
  55.                 %-------------
  56.                 handles = guihandles(fig);
  57.                 Fra_ColPar  = handles.Fra_ColPar;
  58.                 Txt_NBC = handles.Txt_NBC;
  59.                 Edi_NBC = handles.Edi_NBC;
  60.                 Sli_NBC = handles.Sli_NBC;
  61.                 Txt_PAL = handles.Txt_PAL;
  62.                 Pop_PAL = handles.Pop_PAL;
  63.                 try
  64.                     Txt_BRI   = handles.Txt_BRI; 
  65.                     Pus_BRI_M = handles.Pus_BRI_M;
  66.                     Pus_BRI_P = handles.Pus_BRI_P;
  67.                 catch
  68.                     briFlag = false;
  69.                 end
  70.                 if ~briFlag
  71.                     Txt_BRI = NaN;  Pus_BRI_M = NaN; Pus_BRI_P = NaN;
  72.                 end
  73.                 
  74.             case 'create'
  75.                 % Temporary change of units.
  76.                 %---------------------------
  77.                 old_units  = get(fig,'units');
  78.                 fig_units  = 'pixels';
  79.                 if ~isequal(old_units,fig_units), set(fig,'units',fig_units); end  
  80.                 
  81.                 % Get globals.
  82.                 %-------------
  83.                 [...
  84.                 Def_Txt_Height,Def_Btn_Height,Def_Btn_Width, ...
  85.                 X_Spacing,Y_Spacing,sliYProp,Lst_ColorMap,   ...
  86.                 Def_EdiBkColor,Def_FraBkColor] = ...
  87.                     mextglob('get',...
  88.                     'Def_Txt_Height','Def_Btn_Height','Def_Btn_Width',   ...
  89.                     'X_Spacing','Y_Spacing','Sli_YProp', ...
  90.                     'Lst_ColorMap','Def_EdiBkColor','Def_FraBkColor'  ...
  91.                     );
  92.                 
  93.                 % Positions utilities.
  94.                 %---------------------
  95.                 dx = X_Spacing; bdx = 3;
  96.                 dy = Y_Spacing; bdy = 4;        
  97.                 d_txt  = (Def_Btn_Height-Def_Txt_Height);
  98.                 deltaY = (Def_Btn_Height+0*dy);
  99.                 sli_hi = Def_Btn_Height*sliYProp;
  100.                 sli_dy = 0.5*Def_Btn_Height*(1-sliYProp);
  101.                 
  102.                 % Defaults Inputs.
  103.                 %----------------
  104.                 if isnan(ybottom)
  105.                     pos_close = wfigmngr('get',fig,'pos_close');
  106.                     if ~isempty(pos_close)
  107.                         ybottom = pos_close(2)+pos_close(4)+2*dy;
  108.                     end
  109.                 end
  110.                 if isnan(bkColor) , bkColor = mextglob('get','Def_FraBkColor'); end
  111.                 
  112.                 % Setting frame position.
  113.                 %------------------------                
  114.                 w_fra   = wfigmngr('get',fig,'fra_width');
  115.                 h_fra   = Def_Btn_Height+(1+briFlag)*deltaY+2*bdy;
  116.                 xleft   = utposfra(xleft,xright,xloc,w_fra);
  117.                 ybottom = utposfra(ybottom,ytop,yloc,h_fra);
  118.                 pos_fra = [xleft,ybottom,w_fra,h_fra];
  119.                 
  120.                 % String property of objects.
  121.                 %----------------------------
  122.                 str_txt_pal = 'Colormap';
  123.                 str_txt_nbc = 'Nb. Colors';
  124.                 str_pop_pal = Lst_ColorMap;
  125.                 str_edi_nbc = sprintf('%.0f',size(get(fig,'Colormap'),1));
  126.                 if briFlag , str_txt_bri = 'Brightness'; end
  127.                 
  128.                 % Position property of objects.
  129.                 %------------------------------
  130.                 xleft          = xleft+bdx;
  131.                 ylow           = ybottom+h_fra-Def_Btn_Height-bdy;               
  132.                 pos_txt_pal    = [xleft,ylow+d_txt/2,Def_Btn_Width,Def_Txt_Height];
  133.                 pos_pop_pal    = [xleft,ylow,Def_Btn_Width,Def_Btn_Height];
  134.                 pos_pop_pal(1) = pos_pop_pal(1)+pos_txt_pal(3);
  135.                 ylow           = ylow-deltaY;
  136.                 
  137.                 pos_txt_nbc    = pos_txt_pal;
  138.                 pos_txt_nbc(2) = pos_txt_nbc(2)-deltaY;
  139.                 xl             = pos_txt_nbc(1)+pos_txt_nbc(3);
  140.                 pos_sli_nbc    = [xl, ylow+sli_dy, Def_Btn_Width, sli_hi];
  141.                 xl             = pos_sli_nbc(1)+pos_sli_nbc(3)+dx;
  142.                 pos_edi_nbc    = [xl, ylow, Def_Btn_Width/2, Def_Btn_Height];
  143.                 if briFlag
  144.                     ylow           = ylow-deltaY;
  145.                     pos_txt_bri    = pos_txt_nbc;
  146.                     pos_txt_bri(2) = pos_txt_bri(2)-deltaY;
  147.                     xl             = pos_txt_bri(1)+pos_txt_bri(3);
  148.                     pos_p_M_bri    = [xl, ylow, Def_Btn_Width/2, Def_Btn_Height];
  149.                     xl             = xl+Def_Btn_Width/2;
  150.                     pos_p_P_bri    = [xl, ylow, Def_Btn_Width/2, Def_Btn_Height];
  151.                 end
  152.                 
  153.                 % Create objects.
  154.                 %----------------
  155.                 Fra_ColPar = uicontrol('Parent',fig, ...
  156.                     'Style','frame', ...
  157.                     'Unit',fig_units, ...
  158.                     'Position',pos_fra, ...
  159.                     'Backgroundcolor',bkColor, ...
  160.                     'tag',tag_col_par, ...
  161.                     'TooltipString','Colormap Settings' ...
  162.                     );
  163.                 
  164.                 Txt_PAL = uicontrol('Parent',fig,...
  165.                     'Style','Text',...
  166.                     'Unit',fig_units,...
  167.                     'Position',pos_txt_pal,...
  168.                     'HorizontalAlignment','left',...
  169.                     'Backgroundcolor',bkColor,...
  170.                     'String',str_txt_pal...
  171.                     );
  172.                 
  173.                 Pop_PAL = uicontrol('Parent',fig,...
  174.                     'Style','Popup',...
  175.                     'Unit',fig_units,...
  176.                     'Position',pos_pop_pal,...
  177.                     'String',str_pop_pal,...
  178.                     'Enable',enaVAL...
  179.                     );
  180.                 
  181.                 Txt_NBC = uicontrol('Parent',fig,...
  182.                     'Style','Text',...
  183.                     'Unit',fig_units,...
  184.                     'Position',pos_txt_nbc,...
  185.                     'HorizontalAlignment','left',...
  186.                     'Backgroundcolor',bkColor,...
  187.                     'String',str_txt_nbc...
  188.                     );
  189.                 
  190.                 Sli_NBC = uicontrol('Parent',fig,...
  191.                     'Style','Slider',...
  192.                     'Unit',fig_units,...
  193.                     'Position',pos_sli_nbc,...
  194.                     'Min',min_nbcolors,...
  195.                     'Max',max_nbcolors,...
  196.                     'Value',def_nbcolors,...
  197.                     'Enable',enaVAL...
  198.                     );
  199.                 
  200.                 Edi_NBC = uicontrol('Parent',fig,...
  201.                     'Style','Edit',...
  202.                     'Unit',fig_units,...
  203.                     'Backgroundcolor',Def_EdiBkColor,...
  204.                     'Position',pos_edi_nbc,...
  205.                     'String',str_edi_nbc,...
  206.                     'Enable',enaVAL ...
  207.                 );
  208.                               
  209.                 if briFlag
  210.                     Txt_BRI = uicontrol('Parent',fig,...
  211.                         'Style','Text',...
  212.                         'Unit',fig_units,...
  213.                         'Position',pos_txt_bri,...
  214.                         'HorizontalAlignment','left',...
  215.                         'Backgroundcolor',bkColor,...
  216.                         'String',str_txt_bri...
  217.                         );
  218.                     
  219.                     Pus_BRI_M = uicontrol('Parent',fig,...
  220.                         'Style','Pushbutton',...
  221.                         'String','-',...
  222.                         'Unit',fig_units,...
  223.                         'FontSize',12,...
  224.                         'FontWeight','bold',...
  225.                         'Position',pos_p_M_bri,...
  226.                         'Enable',enaVAL ...
  227.                     );
  228.                     
  229.                     Pus_BRI_P = uicontrol('Parent',fig,...
  230.                         'Style','Pushbutton',...
  231.                         'String','+',...
  232.                         'Unit',fig_units,...
  233.                         'FontSize',12,...
  234.                         'FontWeight','bold',...
  235.                         'Position',pos_p_P_bri,...
  236.                         'Enable',enaVAL ...
  237.                     );
  238.                 else
  239.                     Txt_BRI = NaN;  Pus_BRI_M = NaN; Pus_BRI_P = NaN;
  240.                 end
  241.                 if ~isequal(old_units,fig_units)
  242.                     set([fig;ud.handles],'units',old_units);
  243.                 end       
  244.                 drawnow;        
  245.         end
  246.         
  247.         % Callbacks update.
  248.         %------------------
  249.         switch option
  250.             case {'Install_V3'} ,
  251.             case {'Install_V3_CB','create'}
  252.                 cbaFileName = 'cbcolmap';
  253.                 cba_pop_pal = [cbaFileName '(''pal'',' str_numfig ');'];
  254.                 cba_edi_nbc = [cbaFileName '(''nbc'',' str_numfig ',' ...
  255.                         num2mstr([Edi_NBC]) ');'];
  256.                 cba_sli_nbc = [cbaFileName '(''nbc'',' str_numfig ',' ...
  257.                         num2mstr([Sli_NBC]) ');'];
  258.                 
  259.                 set(Pop_PAL,'Callback',cba_pop_pal);
  260.                 set(Edi_NBC,'Callback',cba_edi_nbc);
  261.                 set(Sli_NBC,'Callback',cba_sli_nbc);
  262.                 if briFlag
  263.                     cba_p_M_bri = [cbaFileName '(''bri'',' str_numfig ',-1);'];
  264.                     set(Pus_BRI_M,'Callback',cba_p_M_bri);
  265.                     cba_p_P_bri = [cbaFileName '(''bri'',' str_numfig ',+1);'];
  266.                     set(Pus_BRI_P,'Callback',cba_p_P_bri);
  267.                 end
  268.         end
  269.         
  270.         % Store Handles.
  271.         %----------------
  272.         ud.handles = [Fra_ColPar; ...
  273.                 Txt_PAL;Pop_PAL;Txt_NBC;Sli_NBC;Edi_NBC; ...
  274.                 Txt_BRI;Pus_BRI_M;Pus_BRI_P];
  275.         set(Fra_ColPar,'Userdata',ud);
  276.         
  277.         if nargout>0
  278.             varargout{1} = [Pop_PAL,Sli_NBC,Edi_NBC,Pus_BRI_M,Pus_BRI_P];
  279.             varargout{2} = [Fra_ColPar,Txt_PAL,Txt_NBC,Txt_BRI];
  280.         end
  281. % Add Context Sensitive Help (CSHelp).
  282. %-------------------------------------
  283. wfighelp('add_ContextMenu',fig,ud.handles,'UT_COLMAP');
  284. %-------------------------------------
  285.     case 'handles'
  286.         fra = findobj(fig,'Style','frame','tag',tag_col_par);
  287.         ud  = get(fra,'Userdata');
  288.         varargout{1} = ud.handles;
  289.         nbarg = length(varargin);
  290.         if nbarg>0
  291.            type = varargin{1};
  292.            switch type
  293.              case 'all'  ,
  294.              case 'act'  , varargout{1} = varargout{1}([3 5 6 8 9]);
  295.              case 'cell' ,
  296.                tmp = varargout{1}([3 5 6 8 9]);
  297.                ind = ~isnan(tmp);
  298.                varargout = {[];[];[];[];[]};
  299.                varargout(ind) = num2cell(tmp(ind));
  300.                return
  301.            end
  302.            if nbarg>1         
  303.                varargout{1} = varargout{1}(ishandle(varargout{1}));
  304.            end
  305.         end 
  306.     case 'position'
  307.         fra = findobj(fig,'style','frame','tag',tag_col_par);
  308.         varargout = get(fra,{'Position','Units'});
  309.     otherwise
  310.         errargt(mfilename,'Unknown Option','msg');
  311.         error('*');
  312. end