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

波变换

开发平台:

Matlab

  1. function out1 = plottree(in1,in2);
  2. %PLOTTREE Plot tree.
  3. %   PLOTTREE(T) plots the tree structure T (see MAKETREE).
  4. %
  5. %   See also MAKETREE, WPDEC, WPDEC2.
  6. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  7. %   Last Revision: 02-Aug-2000.
  8. %   Copyright 1995-2002 The MathWorks, Inc.
  9. % $Revision: 1.14 $
  10. % Check arguments.
  11. if errargn(mfilename,nargin,[1:2],nargout,[0 1]), error('*'); end
  12. % Miscelleanous Values.
  13. %----------------------
  14. [line_color,txt_color] = wtbutils('colors','tree');
  15. % Tag property of objects.
  16. %-------------------------
  17. tag_axe_t_lin = 'Axe_TreeLines';
  18. % MemBloc1 of stored values.
  19. %---------------------------
  20. n_stored_val = 'Plottree';
  21. ind_tree     = 1;
  22. ind_hdls_txt = 2;
  23. ind_hdls_lin = 3;
  24. ind_type_txt = 4;
  25. nb1_stored   = 4;
  26. if ~ischar(in1)
  27.     Ts  = in1;
  28.     clear in1
  29.     order = wtreemgr('order',Ts);
  30.     depth = wtreemgr('depth',Ts);
  31.     all   = wtreemgr('allnodes',Ts);
  32.     NB    = (order^(depth+1)-1)/(order-1);
  33.     table_node = -ones(1,NB);
  34.     table_node(all+1) = all;
  35.     [xnpos,ynpos] = xynodpos(table_node,order,depth);
  36.     option = 'create';
  37. else
  38.     option = in1;
  39. end
  40. switch option
  41.     case 'create'
  42.         menu_bar =  get(0,'DefaultFigureMenuBar');
  43.         fig_tree = colordef('new','none');
  44.         set(fig_tree,'visible', 'on',      ...
  45.                      'menubar',menu_bar,   ...
  46.                      'Units','normalized', ...
  47.                      'Interruptible','On'  ...
  48.                      );
  49.         str_numf = int2str(fig_tree);
  50.         m_lab    = uimenu(fig_tree,'Label','Node Label  ');
  51.         uimenu(m_lab,...
  52.                  'Label','Depth_Position  ',                       ...
  53.                  'Callback',[mfilename '(''depo'',' str_numf ');'] ...
  54.                  );
  55.         uimenu(m_lab,...
  56.                  'Label','Index   ',                                 ...
  57.                  'Callback', [mfilename '(''index'',' str_numf ');'] ...
  58.                  );
  59.         pos_axe_tree = [0.05 0.05 0.9 0.9];
  60.         axe_tree_lin = axes(...
  61.                         'Parent',fig_tree,              ...
  62.                         'Visible','off',                ...
  63.                         'XLim',[-0.5,0.5],              ...
  64.                         'YDir','reverse',               ...
  65.                         'YLim',[0 1],                   ...
  66.                         'Units','normalized',           ...
  67.                         'Position',pos_axe_tree,        ...
  68.                         'XTicklabelMode','manual',      ...
  69.                         'YTicklabelMode','manual',      ...
  70.                         'XTicklabel',[],'YTicklabel',[],...
  71.                         'XTick',[],'YTick',[],          ...
  72.                         'Box','On',                     ...
  73.                         'Tag',tag_axe_t_lin             ...
  74.                         );
  75.         wmemtool('ini',fig_tree,n_stored_val,nb1_stored);
  76.         hdls_lin = zeros(1,NB);
  77.         hdls_txt = zeros(1,NB);
  78.         axes(axe_tree_lin)
  79.         i_fath  = 1;
  80.         i_child = i_fath+[1:order];
  81.         for d=1:depth
  82.             for p=0:order^(d-1)-1
  83.                 if table_node(i_child(1)) ~= -1
  84.                     for k=1:order
  85.                         ic = i_child(k);
  86.                         hdls_lin(ic) = line(...
  87.                                         'Parent',axe_tree_lin,...
  88.                                         'XData',[xnpos(i_fath) xnpos(ic)],...
  89.                                         'YData',ynpos(d,:),...
  90.                                         'Color',line_color);
  91.                     end
  92.                 end
  93.                 i_child = i_child+order;
  94.                 i_fath  = i_fath+1;
  95.             end
  96.         end
  97.         hdls_txt(1) = text(...
  98.                         'Parent',axe_tree_lin,          ...
  99.                         'String', '(0,0)',              ...
  100.                         'FontWeight','bold',            ...
  101.                         'Position',[0 0.1 0],           ...
  102.                         'Color',txt_color,              ...
  103.                         'HorizontalAlignment','center', ...
  104.                         'VerticalAlignment','middle',   ...
  105.                         'Clipping','on',                ...
  106.                         'UserData',table_node(1)        ...
  107.                         );
  108.         i_fath         = 1;
  109.         i_child = i_fath+[1:order];
  110.         for d=1:depth
  111.             d_str = int2str(d);
  112.             for p=0:order:order^d-1
  113.                 if table_node(i_child(1)) ~= -1
  114.                     p_child = p+[0:order-1];
  115.                     for k=1:order
  116.                         ic = i_child(k);
  117.                         p_str = int2str(p_child(k));
  118.                         hdls_txt(ic) = text(...
  119.                                         'Parent',axe_tree_lin,...
  120.                                         'String',['(' d_str ',' p_str ')'],...
  121.                                         'FontWeight','bold',...
  122.                                         'Position',[xnpos(ic) ynpos(d,2) 0],...
  123.                                         'Color',txt_color,...
  124.                                         'HorizontalAlignment','center',...
  125.                                         'VerticalAlignment','middle',...
  126.                                         'Clipping','on',...
  127.                                         'Userdata',table_node(ic)...
  128.                                         );
  129.                     end
  130.                 end
  131.                 i_child = i_child+order;
  132.             end
  133.         end
  134.         wmemtool('wmb',fig_tree,n_stored_val, ...
  135.                        ind_tree,Ts,         ...
  136.                        ind_hdls_txt,hdls_txt, ...
  137.                        ind_hdls_lin,hdls_lin, ...
  138.                        ind_type_txt,'p'       ...
  139.                        );
  140.     case 'depo'
  141.         fig_tree = in2;
  142.         type_txt = wmemtool('rmb',fig_tree,n_stored_val,ind_type_txt);
  143.         if type_txt=='p', return; end
  144.         [Ts,hdls_txt] = wmemtool('rmb',fig_tree,n_stored_val,...
  145.                                          ind_tree,ind_hdls_txt);
  146.         order = wtreemgr('order',Ts);
  147.         depth = wtreemgr('depth',Ts);
  148.         set(hdls_txt(1),'String','(0,0)')
  149.         n = 2;
  150.         for d=1:depth
  151.             nd_str = int2str(d);
  152.             for b=0:order:order^d-1
  153.                 if hdls_txt(n) ~= 0
  154.                     for i=0:order-1
  155.                         set(hdls_txt(n+i),'String',...
  156.                           ['(' nd_str ',' int2str(b+i) ')']);
  157.                     end
  158.                 end
  159.                 n = n+order;
  160.             end
  161.         end
  162.         wmemtool('wmb',fig_tree,n_stored_val,ind_type_txt,'p');
  163.     case 'index'
  164.         fig_tree = in2;
  165.         type_txt = wmemtool('rmb',fig_tree,n_stored_val,ind_type_txt);
  166.         if type_txt=='i', return; end
  167.         [Ts,hdls_txt] = wmemtool('rmb',fig_tree,n_stored_val,...
  168.                                         ind_tree,ind_hdls_txt);
  169.         order = wtreemgr('order',Ts);
  170.         depth = wtreemgr('depth',Ts);
  171.         set(hdls_txt(1),'String','(0)')
  172.         n = 2;
  173.         for d=1:depth
  174.             nd_str = int2str(d);
  175.             for b=0:order:order^d-1
  176.                 if hdls_txt(n) ~= 0
  177.                     for i=0:order-1
  178.                         set(hdls_txt(n+i),'String',...
  179.                           ['(' int2str(depo2ind(order,[d b+i])) ')']);
  180.                     end
  181.                 end
  182.                 n = n+order;
  183.             end
  184.         end
  185.         wmemtool('wmb',fig_tree,n_stored_val,ind_type_txt,'i');
  186.     case 'read'
  187.         fig_tree = in2;
  188.         out1 = wmemtool('rmb',fig_tree,n_stored_val,ind_tree);
  189. end