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

波变换

开发平台:

Matlab

  1. function dw2darro(option,win_dw2dtool,in3,in4)
  2. %DW2DARRO Discrete wavelet 2-D arrows.
  3. %   DW2DARRO(OPTION,WIN_DW2DTOOL,IN3,IN4)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  5. %   Last Revision: 17-May-1999.
  6. %   Copyright 1995-2002 The MathWorks, Inc.
  7. %   $Revision: 1.13 $
  8. % Subfunction(s): WAVARROW.
  9. %----------------
  10. % Tag property of objects.
  11. %-------------------------
  12. tag_axearrow  = 'Axe_Arrow';
  13. tag_axeimgini = 'Axe_ImgIni';
  14. tag_axeimgvis = 'Axe_ImgVis';
  15. tag_axeimgsel = 'Axe_ImgSel';
  16. tag_axeimgdec = 'Axe_ImgDec';
  17. tag_axeimgsyn = 'Axe_ImgSyn';
  18. tag_arrow     = 'Wave_Arrow';
  19. % Miscellaneous values.
  20. %----------------------
  21. [dum,dum,BoxTitleSel_Col] = wtbutils('colors','dw2d');
  22. axe_handles = findobj(get(win_dw2dtool,'Children'),'flat','type','axes');
  23. arrow_hdls  = findobj(axe_handles,'tag',tag_arrow);
  24. switch option
  25.     case 'ini_arrow'
  26.         fontsize = wmachdep('fontsize','normal',20);
  27.         axe_arrow = axes(...
  28.                          'Parent',win_dw2dtool,    ...
  29.                          'Position',[0 0 1 1],     ...
  30.                          'Xlim',[0 1],'Ylim',[0 1],...
  31.                          'NextPlot','Add',         ...
  32.                          'DrawMode','Normal',      ...
  33.                          'Visible','off',          ...
  34.                          'Tag',tag_axearrow        ...
  35.                          );
  36.         axes(axe_arrow);
  37.         ar0 = wavarrow('ini',axe_arrow,2,'w');
  38.         set(ar0,'Userdata','a0');
  39.         ar1 = wavarrow('ini',axe_arrow,2,'w');
  40.         set(ar1,'Userdata','a1');
  41.         commonProp = {...
  42.                       'Parent',axe_arrow,             ...
  43.                       'Units','normalized',           ...
  44.                       'Visible','off',                ...
  45.                       'HorizontalAlignment','center', ...
  46.                       'FontSize',fontsize,            ...
  47.                       'FontWeight','bold',            ...
  48.                       'Color',wtbutils('colors','arrow'),  ...
  49.                       'tag',tag_arrow                 ...
  50.                       };
  51.         locProp = {commonProp{:},'string','dwt','Userdata','t0'};
  52.         t0  = text(locProp{:});
  53.         ar2 = wavarrow('ini',axe_arrow,2,BoxTitleSel_Col);
  54.         set(ar2,'Userdata','a2');
  55.         ar3 = wavarrow('ini',axe_arrow,2,'w');
  56.         set(ar3,'Userdata','a3');
  57.         locProp = {commonProp{:},'string','idwt','Userdata','t31'};
  58.         t31     = text(locProp{:});
  59.         locProp = {commonProp{:},'string','','Userdata','t32'};
  60.         t32     = text(locProp{:});
  61.     case 'vis_arrow'
  62.         % in3 = 'on' or 'off'
  63.         % in4 optional (return_deno or return_comp)
  64.         %------------------------------------------             
  65.         txt = get(findobj(arrow_hdls,'Userdata','t0'),'String');
  66.         if strcmp(txt,'dwt')
  67.             ar = findobj(arrow_hdls,'Userdata','a1');
  68.         else
  69.             ar = findobj(arrow_hdls,'Userdata','a0');
  70.         end
  71.         arrow_hdls = arrow_hdls(find(arrow_hdls~=ar));
  72.         if nargin==4
  73.             txt = findobj(arrow_hdls,'Userdata','t32');
  74.             set(txt,'String',in4);
  75.         end             
  76.         set(arrow_hdls,'Visible',in3);
  77.     case 'clean'
  78.         % in3 = 'on' or 'off'
  79.         %------------------------------------------             
  80.         txt = get(findobj(arrow_hdls,'Userdata','t0'),'String');
  81.         if strcmp(txt,'dwt')
  82.             ar = findobj(arrow_hdls,'Userdata','a1');
  83.         else
  84.             ar = findobj(arrow_hdls,'Userdata','a0');
  85.         end
  86.         arrow_hdls = arrow_hdls(find(arrow_hdls~=ar));
  87.         txt = findobj(arrow_hdls,'Userdata','t32');
  88.         set(txt,'String','');
  89.         set(arrow_hdls,'Visible',in3);
  90.     case 'set_arrow'
  91.         % in3 calling option
  92.         %-------------------
  93.         Axe_ImgIni = findobj(axe_handles,'flat','Tag',tag_axeimgini);
  94.         Axe_ImgSel = findobj(axe_handles,'flat','Tag',tag_axeimgsel);
  95.         Axe_ImgVis = findobj(axe_handles,'flat','Tag',tag_axeimgvis);
  96.         Axe_ImgSyn = findobj(axe_handles,'flat','Tag',tag_axeimgsyn);
  97.         ar0 = findobj(arrow_hdls,'Userdata','a0');
  98.         ar1 = findobj(arrow_hdls,'Userdata','a1');
  99.         ar2 = findobj(arrow_hdls,'Userdata','a2');
  100.         ar3 = findobj(arrow_hdls,'Userdata','a3');
  101.         t0  = findobj(arrow_hdls,'Userdata','t0');
  102.         t31 = findobj(arrow_hdls,'Userdata','t31');
  103.         t32 = findobj(arrow_hdls,'Userdata','t32');
  104.         pini = get(Axe_ImgIni,'Position');
  105.         psel = get(Axe_ImgSel,'Position');
  106.         pvis = get(Axe_ImgVis,'Position');
  107.         psyn = get(Axe_ImgSyn,'Position');
  108.         [bdx,bdy] = wfigutil('prop_size',win_dw2dtool,15,15);
  109.         mul = 1/6;
  110.         xini = pini(1)+pini(3);
  111.         yini = pini(2);
  112.         xsel = psel(1)-bdx;
  113.         ysel = psel(2)+psel(4)+bdy;
  114.         dx = xsel-xini;
  115.         dy = yini-ysel;
  116.         pt1 = [xini+mul*dx yini-mul*dy];
  117.         pt2 = [xsel-mul*dx ysel+mul*dy];
  118.         wavarrow('set',ar0,pt1,pt2,0.6,2,'w','off');
  119.         wavarrow('set',ar1,pt2,pt1,0.6,2,'w','off');
  120.         if strcmp(in3,'load_cfs')
  121.             ar00 = ar1;
  122.             txt = 'idwt';
  123.         else
  124.             ar00 = ar0;
  125.             txt = 'dwt';
  126.         end 
  127.         set(t0,'Position',[xini+dx/2 yini-dy/2],'String',txt);
  128.         xvis = pvis(1)+pvis(3)/2;
  129.         yvis = pvis(2);
  130.         ysel = psel(2)+psel(4)+bdy+bdy/2;
  131.         dy   = yvis-ysel;
  132.         wavarrow('set',ar2,[xvis ysel+mul*dy],[xvis yvis-mul*dy], ...
  133.                                 0.6,2,BoxTitleSel_Col,'off');
  134.         xsyn = psyn(1)+psyn(3);
  135.         ysyn = psyn(2)+psyn(4)/2;
  136.         dx   = xsel-xsyn;
  137.         wavarrow('set',ar3,[xsel-mul*dx ysyn],[xsyn+mul*dx ysyn], ...
  138.                                 0.6,2,'w','off');
  139.         set(t31,'Position',[xsel-dx/2 ysyn+0.02],'String','idwt');
  140.         set(t32,'Position',[xsel-dx/2 ysyn-0.02],'String','');
  141.         set([ar00 ar2 ar3 t0 t31],'Visible','on');
  142.     case 'del_arrow'
  143.         delete(arrow_hdls)
  144.     otherwise
  145.         errargt(mfilename,'Unknown Option','msg');
  146.         error('*');
  147. end
  148. %=================================================================%
  149. function out1 = wavarrow(option,in2,in3,in4,in5,in6,in7,in8)
  150. %WAVARROW Draw arrows and texts for dw2dtool.
  151. %   out1 = wavarrow(option,in2,in3,in4,in5,in6,in7,in8)
  152. tag_arrow = 'Wave_Arrow';
  153. opt     = option(1:3);
  154. switch opt
  155.     case 'ini'
  156.       axe     = in2;
  157.       width   = in3;
  158.       color   = in4;
  159.       axes(axe);
  160.       out1 = line(...
  161.               'Parent',axe,...
  162.               'Xdata',[0 0],'Ydata',[1 1],...
  163.               'LineWidth',width,'Color',color,...
  164.               'Visible','off','tag',tag_arrow);
  165.     case 'cre'
  166.       axe     = in2;
  167.       start   = in3;
  168.       stop    = in4;
  169.       scale   = in5;
  170.       width   = in6;
  171.       color   = in7;
  172.       if nargin<8 , vis = 'on'; else , vis = in8; end
  173.       if isempty(find(stop-start)) , return; end
  174.       axes(axe);
  175.       xdif = stop(1) - start(1);
  176.       ydif = stop(2) - start(2);
  177.       if      xdif~=0 , theta = atan(ydif/xdif);
  178.       elseif  ydif>0  , theta = pi/2;
  179.       elseif  ydif<0  , theta = -pi/2;
  180.       end
  181.       if(xdif>=0) , scale = -scale; end
  182.       xx = [  start(1), stop(1),                                 ...
  183.               (stop(1)+0.02*scale*cos(theta+pi/6)),NaN,stop(1),  ...
  184.               (stop(1)+0.02*scale*cos(theta-pi/6))]';
  185.       yy = [  start(2), stop(2),                                 ...
  186.               (stop(2)+0.02*scale*sin(theta+pi/6)),NaN,stop(2),  ...
  187.               (stop(2)+0.02*scale*sin(theta-pi/6))]';
  188.       out1 = line(...
  189.               'Parent',axe,...
  190.               'Xdata',xx,'Ydata',yy,...
  191.               'LineWidth',width,'Color',color,...
  192.               'Visible',vis,'tag',tag_arrow);
  193.     case 'set'
  194.       arrow   = in2;
  195.       start   = in3;
  196.       stop    = in4;
  197.       scale   = in5;
  198.       width   = in6;
  199.       color   = in7;
  200.       if nargin<8 , vis = 'on'; else , vis = in8; end
  201.       if isempty(find(stop-start)) , return; end
  202.       axes(get(arrow,'Parent'));
  203.       xdif = stop(1) - start(1);
  204.       ydif = stop(2) - start(2);
  205.       if      xdif~=0 , theta = atan(ydif/xdif);
  206.       elseif  ydif>0  , theta = pi/2;
  207.       elseif  ydif<0  , theta = -pi/2;
  208.       end
  209.       if(xdif>=0) , scale = -scale; end
  210.       xx = [  start(1), stop(1),                                      ...
  211.               (stop(1)+0.02*scale*cos(theta+pi/6)),NaN,stop(1),       ...
  212.               (stop(1)+0.02*scale*cos(theta-pi/6))]';
  213.       yy = [  start(2), stop(2),                                      ...
  214.               (stop(2)+0.02*scale*sin(theta+pi/6)),NaN,stop(2),       ...
  215.               (stop(2)+0.02*scale*sin(theta-pi/6))]';
  216.       set(arrow,'Xdata',xx,'Ydata',yy,'LineWidth',width,'Color',color,...
  217.                               'Visible',vis,'tag',tag_arrow);
  218.     case 'vis' , set(in2,'Visible',in3);
  219.     case 'wid' , set(in2,'LineWidth',in3);
  220.     case 'col' , set(in2,'Color',in3);
  221.     otherwise
  222.         errargt(mfilename,'Unknown Option','msg');
  223.         error('*');
  224. end
  225. %=================================================================%