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

波变换

开发平台:

Matlab

  1. function varargout = cbcolmap(option,fig,varargin);
  2. %CBCOLMAP Callbacks for colormap utilities.
  3. %   NBC = CBCOLMAP(OPTION,FIG,VARARGIN)
  4. %   option :
  5. %       'pal' : change the colormap.
  6. %       'bri' : change the brightness.
  7. %       'nbc' : change the number of colors.
  8. %       'set' : sets colormap.
  9. %   FIG = handle of the figure.
  10. %   HDL = handle(s) of used button(s). (IN3 or IN4)
  11. %   NBC = number of colors. (IN4 or IN5)
  12. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 01-May-98.
  13. %   Last Revision: 05-Feb-2003.
  14. %   Copyright 1995-2004 The MathWorks, Inc.
  15. %   $Revision: 1.6.4.2 $  $Date: 2004/03/15 22:39:44 $
  16. if isempty(find(wfindobj('figure')==fig)) , return; end
  17. % Default Values.
  18. %----------------
  19. maxmax_nbcolors = 448;
  20. min_nbcolors = 2;
  21. def_nbcolors = 128;
  22. min_bright   = -2;
  23. max_bright   = 2;
  24. def_bright   = 0;
  25. % Find Handles.
  26. %--------------
  27. [Pop_PAL,Sli_NBC,Edi_NBC,Pus_BRI_M,Pus_BRI_P] = utcolmap('handles',fig,'cell');
  28. switch option
  29.     case 'nbc'
  30.         e_or_s = varargin{1};
  31.         if ~ishandle(e_or_s)
  32.             if nargin==4
  33.                 NBC = cbcolmap('pal',fig,varargin{2});
  34.             else
  35.                 NBC = cbcolmap('pal',fig);
  36.             end
  37.             varargout{1} =  NBC;
  38.             return; 
  39.         end
  40.         max_sli = get(Sli_NBC,'Max');
  41.         st = get(e_or_s,'style');
  42.         if strcmp(st,'edit')
  43.             nbcol = wstr2num(get(e_or_s,'String'));
  44.             continu = 1;
  45.             if isempty(nbcol)
  46.                 continu = 0;
  47.             elseif (nbcol<min_nbcolors)
  48.                 continu = 0 ;
  49.             elseif nbcol>max_sli
  50.                 nbcol = max_sli;
  51.                 set(e_or_s,'String',sprintf('%.0f',nbcol));
  52.             end
  53.             if ~continu
  54.                 map = get(fig,'Colormap');
  55.                 nbcol = size(map,1);
  56.                 set(e_or_s,'String',sprintf('%.0f',nbcol));
  57.                 varargout{1} = nbcol;
  58.                 return;
  59.             end
  60.             if ~isempty(Sli_NBC) , set(Sli_NBC,'Value',nbcol); end
  61.         elseif strcmp(st,'slider')
  62.             nbcol = round(get(e_or_s,'Value'));
  63.             if ~isempty(Edi_NBC)
  64.                 set(Edi_NBC,'String',sprintf('%.0f',nbcol));
  65.             end
  66.         end
  67.         varargout{1} = cbcolmap('pal',fig,nbcol);
  68.     case 'pal'
  69.         map = get(fig,'Colormap');
  70.         if length(varargin)<1 , NBC = size(map,1); else NBC = varargin{1}; end
  71.         val  = get(Pop_PAL,'Value');
  72.         name = get(Pop_PAL,'String');
  73.         name = deblankl(name(val,:));   
  74.         if strcmp(name,'self')
  75.             map = get(Pop_PAL,'Userdata');
  76.             nbcol = size(map,1);
  77.             if ~isempty(Sli_NBC) , set(Sli_NBC,'Value',nbcol); end
  78.             if ~isempty(Edi_NBC)
  79.                 set(Edi_NBC,'String',sprintf('%.0f',nbcol));
  80.             end
  81.         elseif name(1:2)=='1-'
  82.             name = name(3:end);
  83.             map  = 1-feval(name,NBC);
  84.         else
  85.             map = feval(name,NBC);
  86.         end
  87.         set(fig,'Colormap',map);
  88.         varargout{1} = NBC;
  89.     case 'bri'
  90.         val = 0.5*varargin{1};
  91.         old_Vis = get(fig,'HandleVisibility');
  92.         set(fig,'HandleVisibility','on')
  93.         if ~isequal(get(0,'CurrentFigure'),fig) , figure(fig); end
  94.         brighten(val);
  95.         set(fig,'HandleVisibility',old_Vis)
  96.     case 'set'
  97.         nbarg = length(varargin);
  98.         if nbarg<1 , return; end
  99.         for k = 1:2:nbarg
  100.            argType = varargin{k};
  101.            argVal  = varargin{k+1};
  102.            switch argType
  103.              case 'pal'
  104.                  names = get(Pop_PAL,'String');
  105.                  NBC   = [];
  106.                  if iscell(argVal)
  107.                      namepal = argVal{1};
  108.                      if length(argVal)>1
  109.                          NBC = argVal{2};
  110.                          if length(argVal)==4
  111.                              % Adding the "self" colormap.
  112.                              %----------------------------
  113.                              % addNam = argVal{3}; For next versions.
  114.                              addNam = 'self'; 
  115.                              udMap  = argVal{4};                             
  116.                              if ~isempty(udMap)
  117.                                  ind = strmatch(addNam,names);
  118.                                  if isempty(ind)
  119.                                      names = strvcat(names,addNam);
  120.                                  end
  121.                              else
  122.                                  names = mextglob('get','Lst_ColorMap');
  123.                              end
  124.                              set(Pop_PAL,'String',names,'Userdata',udMap);
  125.                          end
  126.                      end
  127.                  else
  128.                      namepal = argVal;
  129.                  end
  130.                  % Setting the number of colors.
  131.                  %------------------------------
  132.                  max_sli = get(Sli_NBC,'Max');
  133.                  map     = get(fig,'Colormap');
  134.                  nb_col  = size(map,1);
  135.                  if isempty(NBC) | ~isnumeric(NBC)
  136.                      NBC = nb_col;
  137.                  elseif (NBC<min_nbcolors)
  138.                      NBC = nb_col;
  139.                  end
  140.                  if NBC>max_sli , NBC = max_sli; end
  141.                  % Setting the name of colormap.
  142.                  %------------------------------
  143.                  namepal = deblankl(namepal);
  144.                  if ~(isempty(namepal) | isequal(namepal,'same'))
  145.                      ind = 0;
  146.                      for k = 1:size(names,1)
  147.                          if strcmp(namepal,deblankl(names(k,:)))
  148.                              ind = k; break;
  149.                          end
  150.                      end
  151.                  else
  152.                      ind = get(Pop_PAL,'Value');
  153.                  end
  154.                  if ind
  155.                      set(Pop_PAL,'Value',ind);
  156.                      if ~isempty(Edi_NBC)
  157.                          set(Edi_NBC,'String',sprintf('%.0f',NBC));
  158.                      end
  159.                      if ~isempty(Sli_NBC) , set(Sli_NBC,'Value',NBC); end
  160.                      % NBC = cbcolmap('nbc',fig,Edi_NBC,NBC);
  161.                      cbcolmap('pal',fig,NBC);
  162.                  end
  163.                  if nargout>0 , varargout{1} = NBC; end
  164.            end
  165.         end
  166.     case 'get'
  167.         nbarg = length(varargin);
  168.         if nbarg<1 , return; end
  169.         varargout = {};
  170.         for k = 1:nbarg
  171.            outType = lower(varargin{k});
  172.            switch outType
  173.              case 'self_pal' , varargout{k} = get(Pop_PAL,'Userdata');
  174.              case 'pop_pal'  , varargout{k} = Pop_PAL;
  175.              case 'sli_nbc'  , varargout{k} = Sli_NBC;
  176.              case 'edi_nbc'  , varargout{k} = Edi_NBC;
  177.              case 'btn_bri'  , varargout{k} = [Pus_BRI_M,Pus_BRI_P];
  178.              case 'mapname'  , prop =  get(Pop_PAL,{'String','Value'});
  179.                                varargout{k} = prop{1}(prop{2},:);
  180.              case 'nbcolors' , varargout{k} = round(get(Sli_NBC,'Value'));
  181.            end
  182.         end
  183.     case 'enable'
  184.         set([Pop_PAL,Sli_NBC,Edi_NBC,Pus_BRI_M,Pus_BRI_P],'Enable',varargin{1});
  185.     case 'visible'
  186.         handles = utcolmap('handles',fig,'all');
  187.         handles = handles(ishandle(handles));
  188.         set(handles,'Visible',varargin{1});
  189.     otherwise
  190.         errargt(mfilename,'Unknown Option','msg');
  191.         error('*');
  192. end