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

波变换

开发平台:

Matlab

  1. function wpplottr(option,win_wptool,Ts,in4,in5)
  2. %WPPLOTTR Plot wavelet packets tree.
  3. %   WPPLOTTR(OPTION,WIN_WPTOOL,TREE,IN4,IN5)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  5. %   Last Revision: 21-May-2003.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. % $Revision: 1.12.4.2 $
  8. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. % Draw or Redraw a tree after a node modification (split or merge)
  10. %   win_wptool = handle of the figure which contains the plot.
  11. %   d = depth of the node    : 0 <= d <= depth of the decomposition
  12. %   b = position of the node : 0 <= b <= (ordre^d)-1
  13. %   o = order of the tree (2 ou 4)
  14. %   prof = depth of the tree
  15. %   xnpos = row vector which contains the abscisses of the nodes.
  16. %   table_node = row vector containing nodes indices.
  17. %     table_node(i) =-1   if the node which indice is i-1 doesn't exist
  18. %     table_node(i) = i-1 if the node which indice is i-1 exists
  19. %     if depth-pos is (d,b) , i = (order^d-1)/(order-1)+b
  20. %   txtstr = matrix wich contains the string of the children of the node.
  21. %   txtstr = [] if the nodes is a leaf.
  22. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  23. % MB2 (main window).
  24. %-------------------
  25. n_wp_utils = 'WP_Utils';
  26. ind_tree_lin  = 1;
  27. ind_tree_txt  = 2;
  28. ind_type_txt  = 3;
  29. ind_sel_nodes = 4;
  30. ind_gra_area  = 5;
  31. ind_nb_colors = 6;
  32. nb2_stored    = 6;
  33. % Tag property of objects.
  34. %-------------------------
  35. tag_axe_t_lin = 'Axe_TreeLines';
  36. tag_txt_in_t  = 'Txt_In_tree';
  37. tag_lin_in_t  = 'Lin_In_tree';
  38. % Handles.
  39. %---------
  40. axe_handles = findobj(get(win_wptool,'Children'),'flat','type','axes');
  41. WP_Axe_Tree = findobj(axe_handles,'flat','Tag',tag_axe_t_lin);
  42. % Miscellaneous Values.
  43. %----------------------
  44. [txt_color,line_color,ftn_size] = ...
  45.                 wtbutils('wputils','plottree',get(WP_Axe_Tree,'Xcolor'));
  46. order = treeord(Ts);
  47. depth = treedpth(Ts);            
  48. all   = allnodes(Ts);
  49. NB    = (order^(depth+1)-1)/(order-1);
  50. table_node = -ones(1,NB);
  51. table_node(all+1) = all;
  52. [xnpos,ynpos] = xynodpos(table_node,order,depth);
  53. textProp = {...
  54.    'Parent',WP_Axe_Tree,           ...
  55.    'Clipping','on',                ...
  56.    'Color',txt_color,              ...
  57.    'HorizontalAlignment','center', ...
  58.    'VerticalAlignment','middle',   ...
  59.    'FontSize',ftn_size,            ...
  60.    'FontWeight','bold',            ...
  61.    'Tag',tag_txt_in_t              ...
  62.    };
  63. lineProp = {...
  64.    'Parent',WP_Axe_Tree, ...
  65.    'Color',line_color,   ...
  66.    'Tag',tag_lin_in_t    ...
  67.    };
  68. switch option
  69.     case 'first'
  70.         Tree_Lines = zeros(1,NB);
  71.         Tree_Texts = zeros(1,NB);
  72.         i_fath  = 1;
  73.         i_child = i_fath+[1:order];
  74.         for d=1:depth
  75.             for p=0:order^(d-1)-1
  76.                 if table_node(i_child(1)) ~= -1
  77.                     for k=1:order
  78.                         ic = i_child(k);
  79.                         Tree_Lines(ic) = line(...
  80.                             lineProp{:},...
  81.                             'XData',[xnpos(i_fath) xnpos(ic)],...
  82.                             'YData',ynpos(d,:),            ...
  83.                             'Userdata',[i_fath ic]         ...
  84.                         );
  85.                     end
  86.                 end
  87.                 i_child = i_child+order;
  88.                 i_fath  = i_fath+1;
  89.             end
  90.         end
  91.         Tree_Texts(1) = text(textProp{:},...
  92.                              'Position',[0 0.1 0],    ...
  93.                              'UserData',table_node(1) ...
  94.                              );
  95.         i_fath  = 1;
  96.         i_child = i_fath+[1:order];
  97.         for d=1:depth
  98.             for p=0:order:order^d-1
  99.                 if table_node(i_child(1)) ~= -1
  100.                     p_child = p+[0:order-1];
  101.                     for k=1:order
  102.                         ic = i_child(k);
  103.                         pt = [xnpos(ic) ynpos(d,2) 0];
  104.                         Tree_Texts(ic) = ...
  105.                             text(textProp{:},              ...
  106.                                  'Position',pt,            ...
  107.                                  'Userdata',table_node(ic) ...
  108.                                  );
  109.                     end
  110.                 end
  111.                 i_child = i_child+order;
  112.             end
  113.         end
  114.         Tree_Type_TxtV = 'p';
  115.         set(WP_Axe_Tree,'Visible','on')
  116.     case 'split_merge'
  117.         node   = in4;
  118.         txtstr = in5;
  119.         [Tree_Lines,Tree_Texts,Tree_Type_TxtV] =...
  120.             wmemtool('rmb',win_wptool,n_wp_utils,...
  121.                            ind_tree_lin,ind_tree_txt,ind_type_txt);
  122.         btndown_fcn = get(Tree_Texts(1),'ButtonDownFcn');
  123.                 
  124.         % Create the new tree.
  125.         %---------------------
  126.         node  = depo2ind(order,node);
  127.         [d,b] = ind2depo(order,node);
  128.         % Suppress the descendants of the node.
  129.         %--------------------------------------
  130.         if isempty(txtstr)
  131.             if NB < size(Tree_Texts,2)
  132.                 to_del = find(Tree_Texts(NB+1:size(Tree_Texts,2)))+NB;
  133.                 delete([Tree_Texts(to_del) Tree_Lines(to_del)]);
  134.                 Tree_Texts = Tree_Texts(1:NB);
  135.                 Tree_Lines = Tree_Lines(1:NB);
  136.             end
  137.             K = find((table_node==-1) & (Tree_Texts ~= 0));
  138.             K = K(K>1);
  139.             delete([Tree_Texts(K) Tree_Lines(K)]);
  140.             Tree_Texts(K) = zeros(size(K));
  141.             Tree_Lines(K) = zeros(size(K));
  142.         % Create the descendants of the node.
  143.         %------------------------------------
  144.         else
  145.             i_fath  = node+1;
  146.             i_child = (i_fath-1)*order+2+[0:order-1];
  147.             if NB > size(Tree_Lines,2)
  148.                 Tree_Texts = [Tree_Texts zeros(1,NB-size(Tree_Texts,2))];
  149.                 Tree_Lines = [Tree_Lines zeros(1,NB-size(Tree_Lines,2))];
  150.             end
  151.             for k=1:order
  152.                 ic = i_child(k);
  153.                 Tree_Lines(ic) = ...
  154.                     line(lineProp{:},...
  155.                          'XData',[xnpos(i_fath) xnpos(ic)],...
  156.                          'YData',ynpos(d+1,:),             ...
  157.                          'Userdata',[i_fath ic]            ...
  158.                          );
  159.             end     
  160.             for k=1:order
  161.                 ic = i_child(k);
  162.                 pt = [xnpos(ic) ynpos(d+1,2) 0];
  163.                 Tree_Texts(ic) = ...
  164.                     text(textProp{:}, ...
  165.                          'Position',pt,                 ...
  166.                          'String',deblank(txtstr(k,:)), ...
  167.                          'Userdata',table_node(ic),     ...
  168.                          'ButtonDownFcn',btndown_fcn    ...
  169.                          );
  170.             end
  171.         end
  172.         % Plot the new tree.
  173.         %-------------------
  174.         i_fath = 1;
  175.         i_child = i_fath+[1:order];
  176.         for d=1:depth
  177.             for p=0:order^(d-1)-1
  178.                 if table_node(i_child(1)) ~= -1
  179.                     for k=1:order
  180.                         ic = i_child(k);
  181.                         set(Tree_Texts(ic),'Position',[xnpos(ic) ynpos(d,2) 0]);
  182.                         set(Tree_Lines(ic),...
  183.                               'XData',[xnpos(i_fath) xnpos(ic)], ...
  184.                               'YData',ynpos(d,:));
  185.                     end
  186.                 end
  187.                 i_child = i_child+order;
  188.                 i_fath  = i_fath+1;
  189.             end
  190.         end
  191. end
  192. wmemtool('wmb',win_wptool,n_wp_utils,   ...
  193.                ind_tree_lin,Tree_Lines,     ...
  194.                ind_tree_txt,Tree_Texts,     ...
  195.                ind_type_txt,Tree_Type_TxtV  ...
  196.                );