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

波变换

开发平台:

Matlab

  1. function out1 = wptreeop(option,win_wptool,in3,in4)
  2. %WPTREEOP Operations on wavelet packets tree.
  3. %   OUT1 = WPTREEOP(OPTION,WIN_WPTOOL,IN3,IN4)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  5. %   Last Revision: 03-Sep-2004.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. %   $Revision: 1.17.4.2 $
  8. % Local function(s): findnode.
  9. %==========================================================%
  10. switch option
  11.     case {'vis','split_merge','rec','select_on','stat'}
  12. mouseSelect  = get(win_wptool,'SelectionType');
  13. if ~isequal(mouseSelect,'normal')
  14. return; 
  15. end
  16. end
  17. %==========================================================%
  18. % MB2 (main window).
  19. %-------------------
  20. n_wp_utils = 'WP_Utils';
  21. ind_tree_lin  = 1;
  22. ind_tree_txt  = 2;
  23. ind_type_txt  = 3;
  24. ind_sel_nodes = 4;
  25. ind_gra_area  = 5;
  26. ind_nb_colors = 6;
  27. nb2_stored    = 6;
  28. % MB3 (main window).
  29. %-------------------
  30. n_structures = 'Structures';
  31. ind_tree_st  = 1;
  32. ind_data_st  = 2;
  33. nb3_stored   = 2;
  34. % MB4 (main window).
  35. %-------------------
  36. n_sav_struct    = 'Sav_Struct';
  37. ind_sav_tree_st = 1;
  38. ind_sav_data_st = 2;
  39. nb4_stored      = 2;
  40. % Tag property of objects.
  41. %-------------------------
  42. tag_pop_colm  = 'Txt_PopM';  % WP-1D only
  43. tag_axe_t_lin = 'Axe_TreeLines';
  44. tag_txt_in_t  = 'Txt_In_tree';
  45. tag_lin_in_t  = 'Lin_In_tree';
  46. tag_axe_sig   = 'Axe_Sig';
  47. tag_axe_pack  = 'Axe_Pack';
  48. tag_axe_cfs   = 'Axe_Cfs';
  49. tag_curtree   = 'Pop_CurTree';
  50. tag_nodlab    = 'Pop_NodLab';
  51. tag_nodact    = 'Pop_NodAct';
  52. tag_img_cfs   = 'Img_WPCfs';
  53. tag_img_nod   = 'Img_NodCfs';
  54. % Handles.
  55. %---------
  56. children    = get(win_wptool,'Children');
  57. pop_handles = findobj(children,'flat','style','popupmenu');
  58. axe_handles = findobj(children,'flat','type','axes');
  59. WP_Axe_Tree = findobj(axe_handles,'flat','Tag',tag_axe_t_lin);
  60. WP_Axe_Sig  = findobj(axe_handles,'flat','Tag',tag_axe_sig);
  61. WP_Axe_Pack = findobj(axe_handles,'flat','Tag',tag_axe_pack);
  62. WP_Axe_Cfs  = findobj(axe_handles,'flat','Tag',tag_axe_cfs);
  63. % Miscellaneous Values.
  64. %-------------------------
  65. [txt_color,sel_color,pack_color,ftn_size] = ...
  66.                 wtbutils('wputils','tree_op',get(WP_Axe_Tree,'Xcolor'));
  67. switch option
  68.     case 'nodact'
  69.         pop_nodact = findobj(pop_handles,'Tag',tag_nodact);
  70.         v     = get(pop_nodact,'Value');
  71.         old_v = get(pop_nodact,'Userdata');
  72.         if isempty(old_v) , old_v = 0; end
  73.         set(pop_nodact,'Userdata',v);
  74.         if     (find(v==[1:6]) & old_v==7)  , ok = 1;
  75.         elseif (find(old_v==[1:6]) & v==7)  , ok = 1;
  76.         elseif old_v==7 & v==7
  77.             if nargin==3
  78.                if strcmp(in3,'reset')
  79.                     set(pop_nodact,'Value',1);
  80.                     set(pop_nodact,'Userdata',1);
  81.                     v  = 1; ok = 1;
  82.                else
  83.                    return;
  84.                end
  85.             else
  86.                return;
  87.             end
  88.         else
  89.             ok = 0;
  90.         end
  91.         if ok 
  92.             WP_Tree = wmemtool('rmb',win_wptool,n_structures,ind_tree_st);
  93.             order = treeord(WP_Tree);
  94.             img_handles = findobj(WP_Axe_Cfs,'tag',tag_img_cfs);
  95.         end
  96.         Tree_Texts = wmemtool('rmb',win_wptool,n_wp_utils,ind_tree_txt);
  97.         str_win    = sprintf('%.0f',win_wptool);
  98.         switch v
  99.             case 1
  100.                 btndown_fcn = [mfilename '(''vis'',' str_win ');'];
  101.             case 2
  102.                 wptreeop('select_off',win_wptool);
  103.                 btndown_fcn = [mfilename '(''split_merge'',' str_win ');'];
  104.             case 3
  105.                 wptreeop('select_off',win_wptool);
  106.                 btndown_fcn = [mfilename '(''rec'',' str_win ');'];
  107.             case 4
  108.                 btndown_fcn = [mfilename '(''select_on'',' str_win ');'];
  109.             case 5
  110.                 wptreeop('select_off',win_wptool);
  111.                 set(pop_nodact,'Value',1);
  112.                 btndown_fcn = [mfilename '(''vis'',' str_win ');'];
  113.             case 6
  114.                 btndown_fcn = [mfilename '(''stat'',' str_win ');'];
  115.             case 7
  116.                 tn = tnodes(WP_Tree);
  117.                 nodes = [];
  118.                 for k = 1:length(Tree_Texts)
  119.                     us = get(Tree_Texts(k),'Userdata');
  120.                     if ~isempty(us)
  121.                         if isempty(find(tn==us)) , nodes = [nodes k]; end
  122.                     end
  123.                 end
  124.                 set(Tree_Texts(nodes),'Visible','off');
  125.                 btndown_fcn = ['wptreeop(''colcfs'',' str_win ');'];
  126.                 set(img_handles,'Visible','off');
  127.         end
  128.         if find(v==[1:6]) & old_v==7
  129.             if order==2
  130.                 delete(findobj(WP_Axe_Cfs,'tag',tag_img_nod));
  131.                 set(WP_Axe_Cfs,'Nextplot','replace');
  132.             end
  133.             set(Tree_Texts,'Visible','on');
  134.             set(img_handles,'Visible','on');
  135.             drawnow
  136.             if order==2
  137.                 pop_colm = findobj(win_wptool,'style','popupmenu',...
  138.                                 'tag',tag_pop_colm);
  139.                 col_mode = get(pop_colm,'Value');
  140.                 if find(col_mode==[1 2 3 4])
  141.                     strlab = ['frequency ordered coefficients'];
  142.                 else
  143.                     strlab = ...
  144.                     ['(down -> up) for Cfs <==> (left -> right) in Tree'];
  145.                 end
  146.                 wsetxlab(WP_Axe_Cfs,strlab);
  147.             else
  148.                 wsetxlab(WP_Axe_Cfs,'');
  149.             end
  150.         elseif find(old_v==[1:6]) & v==7
  151.             wsetxlab(WP_Axe_Cfs,'');
  152.         end
  153.         set(Tree_Texts,'ButtonDownFcn',btndown_fcn);
  154.         return
  155.     case 'nodlab'
  156.         pop_nodlab = findobj(pop_handles,'Tag',tag_nodlab);
  157.         pop_nodact = findobj(pop_handles,'Tag',tag_nodact);
  158.         v_lab = get(pop_nodlab,'Value');
  159.         v_act = get(pop_nodact,'Value');
  160.         if v_act==7
  161.             txt_in_tree = findobj(WP_Axe_Tree,'tag',tag_txt_in_t);
  162.             txt_off     = findobj(txt_in_tree,'Visible','off');
  163.         end
  164.         Tree_Texts  = wmemtool('rmb',win_wptool,n_wp_utils,ind_tree_txt);
  165.         if v_lab==6
  166.             set(Tree_Texts,'Visible','off'); return
  167.         end
  168.         switch v_lab
  169.            case 1 , labtype = 'p';
  170.            case 2 , labtype = 'i';
  171.            case 3 , labtype = 'e';
  172.            case 4 , labtype = 'eo';
  173.            case 5 , labtype = 's';
  174.            case 7 , labtype = 't';
  175.            case 8 , labtype = 'en';               
  176.         end
  177.         wmemtool('wmb',win_wptool,n_wp_utils,ind_type_txt,labtype);
  178.         WP_Tree = wmemtool('rmb',win_wptool,n_structures,ind_tree_st);
  179.         nodes   = allnodes(WP_Tree);
  180.         if isa(WP_Tree,'wptree')
  181.             labels = tlabels(WP_Tree,labtype,nodes);
  182.         else
  183.             WP_Data = wmemtool('rmb',win_wptool,n_structures,ind_data_st);
  184.             labels  = tlabels(WP_Tree,WP_Data,labtype,nodes);
  185.         end
  186.         for k=1:length(nodes)
  187.             set(Tree_Texts(1+nodes(k)),'String',deblank(labels(k,:)));
  188.         end
  189.         set(Tree_Texts,'Visible','on');
  190.         if v_act==7 , set(txt_off,'Visible','off'); end
  191.         return
  192.     case 'select_off'
  193.         Selected_Nodes = wmemtool('rmb',win_wptool,n_wp_utils,ind_sel_nodes);
  194.         if ~isempty(Selected_Nodes)
  195.             set(Selected_Nodes(2,:),'Color',txt_color);
  196.             wmemtool('wmb',win_wptool,n_wp_utils,ind_sel_nodes,[]);
  197.         end
  198.         return
  199.     case 'select_on'
  200.         [obj,node] = findnode(win_wptool,WP_Axe_Tree);
  201.         if isempty(obj) , return; end
  202.         Selected_Nodes = wmemtool('rmb',win_wptool,n_wp_utils,ind_sel_nodes);
  203.         col = get(obj,'Color');
  204.         if col==txt_color
  205.             Selected_Nodes = [Selected_Nodes [node;obj]];
  206.             set(obj,'Color',sel_color);
  207.         else
  208.             k = find(Selected_Nodes(2,:)==obj);
  209.             Selected_Nodes(:,k) = [];
  210.             set(obj,'Color',txt_color);
  211.         end
  212.         wmemtool('wmb',win_wptool,n_wp_utils,ind_sel_nodes,Selected_Nodes);
  213.         return;
  214.     case 'stat'
  215.         [obj,node] = findnode(win_wptool,WP_Axe_Tree);
  216.         if isempty(obj) , return; end
  217.         set(wfindobj('figure'),'Pointer','watch');
  218.         WP_Tree = wmemtool('rmb',win_wptool,n_structures,ind_tree_st);
  219.         order = treeord(WP_Tree);
  220.         if  order==2
  221.             out1 = feval('wp1dstat','create',win_wptool,node);
  222.         elseif  order==4
  223.             out1 = feval('wp2dstat','create',win_wptool,node);
  224.         end
  225.         set(wfindobj('figure'),'Pointer','arrow');
  226.         return
  227.     case 'colcfs'
  228.         [obj,node] = findnode(win_wptool,WP_Axe_Tree);
  229.         if isempty(obj) , return; end
  230.         set(wfindobj('figure'),'Pointer','watch');
  231.         WP_Tree = wmemtool('rmb',win_wptool,n_structures,ind_tree_st);
  232.         order = treeord(WP_Tree);
  233.         img_handles = findobj(WP_Axe_Cfs,'tag',tag_img_cfs);
  234.         if order==2
  235.             us = get(img_handles,'Userdata');
  236.             tn = depo2ind(order,us(:,1:2));
  237.             num_img = find(node==tn);
  238.             set(img_handles,'Visible','off');
  239.             if num_img~=0
  240.                 xd = get(img_handles,'xdata');
  241.                 yd = get(img_handles,'ydata');
  242.                 nd = get(img_handles,'Cdata');
  243.                 NBrows = size(nd,1);
  244.                 y1 = us(num_img,3);
  245.                 y2 = us(num_img,4); 
  246.                 r1 = ceil(y1*NBrows)+1;
  247.                 r2 = floor(y2*NBrows);
  248.                 nd = nd(r1:r2,:);
  249.                 if r1==r2
  250.                     ydata(1) = (y2+y1)/2;
  251.                     ydata(2) = y2;
  252.                 else
  253.                     alfa = 1/(2*(r2-r1+1));
  254.                     ydata = [(1-alfa)*y1+alfa*y2 (1-alfa)*y2+alfa*y1];
  255.                 end
  256.                 set(WP_Axe_Cfs,'Nextplot','add');
  257.                 axes(WP_Axe_Cfs);
  258.                 delete(findobj(WP_Axe_Cfs,'tag',tag_img_nod));
  259.                 image('Parent',WP_Axe_Cfs, ...
  260.                       'Xdata',xd,'Ydata',ydata, ...
  261.                       'Cdata',nd,'tag',tag_img_nod ...
  262.                       );
  263.                 strlab = ['Packet : (' sprintf('%.0f',us(num_img,1)) ',' ...
  264.                            sprintf('%.0f',us(num_img,2)) ') or (' sprintf('%.0f',node) ')'];
  265.                 wsetxlab(WP_Axe_Cfs,strlab);
  266.                 set(WP_Axe_Cfs,'Tag',tag_axe_cfs)
  267.             end
  268.         elseif order==4
  269.             num_img = 0;
  270.             for k=1:length(img_handles)
  271.                 us = get(img_handles(k),'Userdata');
  272.                 us = us(1:2);
  273.                 if node==depo2ind(order,us) , num_img = k; break; end
  274.             end
  275.             img_on = findobj(img_handles,'Visible','on');
  276.             set(img_on,'Visible','off');
  277.             if num_img~=0
  278.                 set(img_handles(num_img),'Visible','on');
  279.                 strlab = ['Packet : (' sprintf('%.0f',us(1)) ',' ...
  280.                        sprintf('%.0f',us(2)) ') or (' sprintf('%.0f',node) ')'];
  281.                 wsetxlab(WP_Axe_Cfs,strlab);
  282.             end
  283.         end
  284.         set(wfindobj('figure'),'Pointer','arrow');
  285.         return
  286.     case 'slide_size'
  287.         % in3 = slider_size.
  288.         % in4 = slider_pos.
  289.         %--------------------
  290.         v = get(in3,'Value');
  291.         set(in3,'UserData',v);
  292.         half = 1/((2*v)^(v/4));
  293.         % Setting slider-pos properties.
  294.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  295.         if v>1
  296.             old_bound = get(in4,'Max');
  297.             old_val   = get(in4,'Value');
  298.             new_bound = abs(0.5-half);
  299.             if old_bound ~= 0
  300.                 new_val = -new_bound+(old_val+old_bound)*(new_bound/old_bound);
  301.             else
  302.                 new_val = 0;
  303.             end
  304.             delta = 0;
  305.             if new_val>new_bound-delta , new_val = new_bound-delta;
  306.             elseif new_val<-new_bound+delta , new_val = -new_bound+delta;
  307.             end
  308.             set(in4,'Min',-new_bound,'Max',new_bound,...
  309.                 'Value',new_val,'Visible','on');
  310.         else
  311.             new_val = 0;
  312.             set(in4,'Min',0,'Max',0,'Value',0,'Visible','off');
  313.         end
  314.         set(WP_Axe_Tree,'XLim',[new_val-half new_val+half]);
  315.         return
  316.     case 'slide_pos'
  317.         % in3 = slider_pos.
  318.         %------------------
  319.         mVM = get(in3,{'min','val','max'});
  320.         delta = 1E-3; delta = 0; 
  321.         OK = (mVM{2}>mVM{1}+delta) &  (mVM{2}<mVM{3}-delta);
  322.         if ~OK
  323.             set(in3,'Value',mVM{3})
  324.             return;
  325.         end
  326.         x0 = mVM{2};
  327.         
  328.         u  = get(WP_Axe_Tree,'XLim');
  329.         demi_ecart = (u(2)-u(1))/2;
  330.         set(WP_Axe_Tree,'XLim',[x0-demi_ecart x0+demi_ecart]);
  331.         II = [x0-demi_ecart x0+demi_ecart];
  332.         return
  333.     case {'best','blvl','wp2wtree','restore','input_tree','cuttree'}
  334.         % Begin waiting.
  335.         %--------------
  336.         wwaiting('msg',win_wptool,'Wait ... computing');
  337.         pop_nodlab = findobj(pop_handles,'Tag',tag_nodlab);
  338.         wptreeop('select_off',win_wptool);
  339.         if ~strcmp(option,'input_tree')
  340.             WP_Tree = wmemtool('rmb',win_wptool,n_structures,ind_tree_st);
  341.         else
  342.             WP_Tree = in3;
  343.         end
  344.         if isa(WP_Tree,'wptree')
  345.            WP_Data = [];
  346.      switch option
  347.      case 'best'
  348.        WP_Tree = besttree(WP_Tree);
  349.        Axe_TreeTitle = 'Best Tree';
  350.      case 'blvl'
  351.        WP_Tree = bestlevt(WP_Tree);
  352.        Axe_TreeTitle = 'Best Level Tree';
  353.      case 'wp2wtree'
  354.        WP_Tree = wp2wtree(WP_Tree);
  355.        Axe_TreeTitle = 'Wavelet Tree';
  356.      case 'restore'
  357.        WP_Tree = wmemtool('rmb',win_wptool,n_sav_struct,ind_sav_tree_st);
  358.        Axe_TreeTitle = 'Decomposition Tree';
  359.      case 'input_tree'
  360.        Axe_TreeTitle = 'Decomposition Tree';
  361.      case 'cuttree'
  362.        % in3 = pop_hdl
  363.        %--------------
  364.        val = get(in3,'Value');
  365.        lev = val-1;
  366.        depth = treedpth(WP_Tree);
  367.        if lev==depth , wwaiting('off',win_wptool); return; end
  368.        [WP_Tree,n2m] = wpcutree(WP_Tree,lev);
  369.        if isempty(n2m) , wwaiting('off',win_wptool); return; end
  370.        Axe_TreeTitle = 'Cut Tree';
  371.      end
  372.         else
  373.             WP_Data = wmemtool('rmb',win_wptool,n_structures,ind_data_st);
  374.             switch option
  375.               case 'best'
  376.                   [WP_Tree,WP_Data] = besttree(WP_Tree,WP_Data);
  377.                   Axe_TreeTitle = 'Best Tree';
  378.               case 'blvl'
  379.                   [WP_Tree,WP_Data] = bestlevt(WP_Tree,WP_Data);
  380.                   Axe_TreeTitle = 'Best Level Tree';
  381.               case 'wp2wtree'
  382.                   [WP_Tree,WP_Data] = wp2wtree(WP_Tree,WP_Data);
  383.                   Axe_TreeTitle = 'Wavelet Tree';
  384.               case 'restore'
  385.                   [WP_Tree,WP_Data] = wmemtool('rmb',win_wptool,n_sav_struct,...
  386.                                                 ind_sav_tree_st,ind_sav_data_st);
  387.                   Axe_TreeTitle = 'Decomposition Tree';
  388.               case 'input_tree'
  389.                   WP_Data = in4;
  390.                   Axe_TreeTitle = 'Decomposition Tree';
  391.               case 'cuttree'
  392.                   % in3 = pop_hdl
  393.                   %--------------
  394.                   val = get(in3,'Value');
  395.                   lev = val-1;
  396.                   depth = treedpth(WP_Tree);
  397.                   if lev==depth , wwaiting('off',win_wptool); return; end
  398.                   [WP_Tree,WP_Data,n2m] = wpcutree(WP_Tree,WP_Data,lev);
  399.                   if isempty(n2m) , wwaiting('off',win_wptool); return; end
  400.                   Axe_TreeTitle = 'Cut Tree';
  401.             end
  402.         end
  403.         depth = treedpth(WP_Tree);
  404.         str_depth = [];
  405.         for k=0:depth , str_depth = [ str_depth ; sprintf('%2.0f',k) ]; end
  406.         pop_cur = findobj(pop_handles,'Tag',tag_curtree);
  407.         set(pop_cur,'String',str_depth,'Value',depth+1);
  408.         xlab    = get(WP_Axe_Cfs,'xlabel');
  409.         strxlab = get(xlab,'String');
  410.         titl    = get(WP_Axe_Cfs,'title');
  411.         strtitl = get(titl,'String');
  412.         hdl_in_axes = [...
  413.                         get(WP_Axe_Tree,'Children'); ...
  414.                         get(WP_Axe_Cfs,'Children');  ...
  415.                         get(WP_Axe_Pack,'Children')  ...
  416.                         ];
  417.         delete(hdl_in_axes); drawnow
  418.         wmemtool('wmb',win_wptool,n_wp_utils,...
  419.                        ind_tree_lin,[],ind_tree_txt,[]);
  420.         wmemtool('wmb',win_wptool,n_structures, ...
  421.                        ind_tree_st,WP_Tree, ...
  422.                        ind_data_st,WP_Data  ...
  423.                        );
  424.         nb_col = wmemtool('rmb',win_wptool,n_wp_utils,ind_nb_colors);
  425. axes(WP_Axe_Tree);
  426. wtitle(Axe_TreeTitle,'Parent',WP_Axe_Tree);
  427. axes(WP_Axe_Pack);
  428. wtitle('Node Action Result','Parent',WP_Axe_Pack);
  429. wpplottr('first',win_wptool,WP_Tree);
  430. wptreeop('nodlab',win_wptool);
  431. pop_nodact = findobj(pop_handles,'tag',tag_nodact);
  432. act = get(pop_nodact,'Value');
  433. wptreeop('nodact',win_wptool,'reset');
  434. pop_colm = findobj(pop_handles,'tag',tag_pop_colm);
  435.         col_mode = get(pop_colm,'Value');
  436.         if isa(WP_Tree,'wptree')
  437.             wpplotcf(WP_Tree,col_mode,WP_Axe_Cfs,nb_col);
  438.         else
  439.             wpplotcf(WP_Tree,WP_Data,col_mode,WP_Axe_Cfs,nb_col);
  440.         end
  441.         axes(WP_Axe_Cfs)
  442.         wtitle(strtitl,'Parent',WP_Axe_Cfs);
  443.         order = treeord(WP_Tree);
  444.         if order==2
  445.             if act==7
  446.                 xlab = get(WP_Axe_Cfs,'xlabel');
  447.                 strxlab = get(xlab,'String');
  448.             end
  449.             wsetxlab(WP_Axe_Cfs,strxlab);
  450.         end
  451.         if ~strcmp(option,'input_tree') , dynvtool('get',win_wptool,0); end
  452.         % End waiting.
  453.         %-------------
  454.         wwaiting('off',win_wptool);
  455.         return
  456.     case {'vis','rec','split_merge'}
  457.         [obj,node] = findnode(win_wptool,WP_Axe_Tree);
  458.         if isempty(obj) , return; end
  459. end
  460. % Begin waiting.
  461. %--------------
  462. wwaiting('msg',win_wptool,'Wait ... computing');
  463. [WP_Tree,WP_Data] = wmemtool('rmb',win_wptool,n_structures,...
  464.                                    ind_tree_st,ind_data_st);
  465. if ~isempty(WP_Tree) , order = treeord(WP_Tree); end
  466. switch option
  467.     case {'vis','rec'}
  468. [d,p] = ind2depo(order,node);
  469.         if isa(WP_Tree,'wptree')
  470.             size0   = read(WP_Tree,'sizes',0);
  471.             switch option
  472.               case 'vis' , pack = wpcoef(WP_Tree,node);
  473.               case 'rec' , pack = wprcoef(WP_Tree,node);
  474.             end
  475.         else
  476.             sizes = wdatamgr('rsizes',WP_Data);
  477.             size0 = sizes(:,1)';
  478.             switch option
  479.               case 'vis' , pack = wpcoef(WP_Tree,WP_Data,node);
  480.               case 'rec' , pack = wprcoef(WP_Tree,WP_Data,node);
  481.             end
  482.         end
  483.         switch option
  484.           case 'vis'
  485.             flg_code = 1;
  486.             trunc_p  = [d size0];
  487.             str_pck  = [];
  488.           case 'rec'
  489.             if p==0 , flg_code = 0; else , flg_code = 1; end
  490.             trunc_p = [0 size0];
  491.             str_pck = ['Reconstructed '];
  492.         end
  493. str_pck = [str_pck 'Packet : (' sprintf('%.0f',d) ',' sprintf('%.0f',p) ...
  494.       ') or (' sprintf('%.0f',node) ')'];
  495. delete(get(WP_Axe_Pack,'Children'));
  496. dynvtool('ini_his',win_wptool,1)
  497. axes(WP_Axe_Pack)
  498. if order == 2
  499.             xmax = length(pack);
  500.     if xmax==1, xmax = 1+0.01; end
  501.     ymin = min(pack);       ymax = max(pack);
  502. if abs(ymax-ymin)<sqrt(eps) , ymin = ymin-0.0001; ymax = ymax+0.0001; end
  503. if p==0
  504. if d==0 , colNAME = 'sig'; else, colNAME = 'app'; end
  505. else
  506. colNAME = 'det';
  507. end
  508. color = wtbutils('colors',colNAME,1);
  509. plot(pack,'Color',color,'Parent',WP_Axe_Pack);
  510. set(WP_Axe_Pack,'XLim',[1 xmax],'Ylim',[ymin ymax],'Tag',tag_axe_pack);
  511. wtitle(str_pck,...
  512. 'FontSize',ftn_size,...
  513. 'Color',get(WP_Axe_Tree,'Xcolor'),...
  514. 'Parent',WP_Axe_Pack);
  515. else
  516. % Image Coding Value.
  517. %-------------------
  518. codemat_v = wimgcode('get'); 
  519.     NB_Colors2D = wmemtool('rmb',win_wptool,n_wp_utils,ind_nb_colors);
  520.     pack = wimgcode('cod',flg_code,pack,NB_Colors2D,codemat_v,trunc_p);
  521.     image('CData',pack,'Parent',WP_Axe_Pack);
  522.     wtitle(str_pck,...
  523.            'FontSize',ftn_size,...
  524.            'Color',get(WP_Axe_Tree,'Xcolor'),...
  525.            'Parent',WP_Axe_Pack);
  526.     set(WP_Axe_Pack, ...
  527.            'Tag',tag_axe_pack,     ...
  528.            'Layer','top',          ...
  529.            'XLim',[1 size(pack,2)],...
  530.            'Ylim',[1 size(pack,1)],...
  531.            'Ydir','Reverse'        ...
  532.            );
  533. end
  534. dynvtool('put',win_wptool)
  535. axes(WP_Axe_Tree);
  536.     case 'split_merge'
  537.         pack_exist = istnode(WP_Tree,node);     
  538.         if isa(WP_Tree,'wptree')
  539.             WP_Data = [];
  540.             if pack_exist == 0
  541.                 WP_Tree = nodejoin(WP_Tree,node);
  542.                 labels  = [];
  543.             else
  544.                 WP_Tree = wpsplt(WP_Tree,node);
  545.                 child   = node*order+[1:order]';
  546.                 labtype = wmemtool('rmb',win_wptool,n_wp_utils,ind_type_txt);
  547.                 labels  = tlabels(WP_Tree,labtype,child);
  548.             end        
  549.         else
  550.             if pack_exist == 0
  551.                 [WP_Tree,WP_Data] = wpjoin(WP_Tree,WP_Data,node);
  552.                 labels = [];
  553.             else
  554.                 [WP_Tree,WP_Data] = wpsplt(WP_Tree,WP_Data,node);
  555.                 child   = node*order+[1:order]';
  556.                 labtype = wmemtool('rmb',win_wptool,n_wp_utils,ind_type_txt);
  557.                 labels  = tlabels(WP_Tree,WP_Data,labtype,child);
  558.             end
  559.         
  560.         end        
  561.         wmemtool('wmb',win_wptool,n_structures, ...
  562.                        ind_tree_st,WP_Tree, ...
  563.                        ind_data_st,WP_Data  ...
  564.                        );
  565.         depth = treedpth(WP_Tree);
  566.         str_depth = [];
  567.         for k=0:depth , str_depth = [ str_depth ; sprintf('%2.0f',k) ]; end
  568.         pop_cur = findobj(pop_handles,'Tag',tag_curtree);
  569.         set(pop_cur,'String',str_depth,'Value',depth+1);
  570.         % Drawing New Tree.
  571.         %------------------
  572.         axes(WP_Axe_Tree);
  573.         wtitle('Decomposition Tree','Parent',WP_Axe_Tree);
  574.         wpplottr('split_merge',win_wptool,WP_Tree,node,labels);
  575.         wptreeop('cfs',win_wptool);
  576.     case 'cfs'
  577.         xlab    = get(WP_Axe_Cfs,'xlabel');
  578.         strxlab = get(xlab,'String');
  579.         titl    = get(WP_Axe_Cfs,'title');
  580.         strtitl = get(titl,'String');
  581.         delete(get(WP_Axe_Cfs,'Children'));
  582.         nb_col   = wmemtool('rmb',win_wptool,n_wp_utils,ind_nb_colors);
  583.         pop_colm = findobj(pop_handles,'tag',tag_pop_colm);
  584.         col_mode = get(pop_colm,'Value');
  585.         if isa(WP_Tree,'wptree')
  586.             wpplotcf(WP_Tree,col_mode,WP_Axe_Cfs,nb_col);
  587.         else
  588.             wpplotcf(WP_Tree,WP_Data,col_mode,WP_Axe_Cfs,nb_col);
  589.         end
  590.         wtitle(strtitl,'Parent',WP_Axe_Cfs)
  591.         if order==2 , wsetxlab(WP_Axe_Cfs,strxlab); end
  592.     case 'col_mode' % option = 'col_mode' -- only for WP-1D
  593. % b_pop = in3.
  594. %-------------
  595. colorMode = get(in3,'Value');
  596. user = get(in3,'Userdata');
  597. if colorMode~=user
  598.     set(in3,'Userdata',colorMode);
  599.     titl    = get(WP_Axe_Cfs,'title');
  600.     strtitl = get(titl,'String');
  601.     delete(get(WP_Axe_Cfs,'Children'));
  602.     nb_col = wmemtool('rmb',win_wptool,n_wp_utils,ind_nb_colors);
  603.             if isa(WP_Tree,'wptree')
  604.                 wpplotcf(WP_Tree,colorMode,WP_Axe_Cfs,nb_col);
  605.             else
  606.                 wpplotcf(WP_Tree,WP_Data,colorMode,WP_Axe_Cfs,nb_col);
  607.             end
  608.     wtitle(strtitl,'Parent',WP_Axe_Cfs)
  609.     if order==2
  610.         if find(colorMode==[1 2 3 4])
  611.             strxlab = ['frequency ordered coefficients'];
  612.         else
  613.             strxlab = ...
  614.                ['(down -> up) for Cfs <==> (left -> right) in Tree'];
  615.         end
  616.         wsetxlab(WP_Axe_Cfs,strxlab);
  617.     end
  618. end
  619.     case 'recons'
  620.         Selected_Nodes = wmemtool('rmb',win_wptool,n_wp_utils,ind_sel_nodes);
  621.         if isempty(Selected_Nodes) , wwaiting('off',win_wptool); return; end
  622.         nodes   = sort(Selected_Nodes(1,:));
  623.         n2m     = [];
  624.         un_sel  = [];
  625.         ter_nod = [];
  626.         k = 1;
  627.         while k<=length(nodes)
  628.             nod_sel = nodes(k);
  629.             desc    = nodedesc(WP_Tree,nod_sel);
  630.             desc    = desc(2:length(desc));
  631.             if isempty(desc)
  632.                 ter_nod = [ter_nod nod_sel];
  633.             else
  634.                 [xind,yind] = wcommon(nodes,desc);
  635.                 indx = find(xind);
  636.                 un_sel = [un_sel nodes(indx)];
  637.                 nodes(indx) = [];
  638.                 n2m = [n2m nod_sel];
  639.             end
  640.             k = k+1;
  641.         end
  642.         if ~isempty(un_sel)
  643.             [xind,yind] = wcommon(Selected_Nodes(1,:),un_sel);
  644.             indx = find(xind);
  645.             set(Selected_Nodes(2,indx),'Color',txt_color);
  646.             Selected_Nodes(:,indx) = [];
  647.             wmemtool('wmb',win_wptool,n_wp_utils,...
  648.                            ind_sel_nodes,Selected_Nodes);
  649.         end
  650.         Tree_Texts = wmemtool('rmb',win_wptool,n_wp_utils,ind_tree_txt);
  651.         set(Tree_Texts,'Visible','off');
  652.         set(Selected_Nodes(2,:),'Visible','on');
  653.         drawnow
  654.         if isa(WP_Tree,'wptree')
  655.             WP_Tree = nodejoin(WP_Tree,n2m);
  656.             [order,tnods] = get(WP_Tree,'order','tn');
  657.             sizes = read(WP_Tree,'tnsizes');
  658.             [xind,yind] = wcommon(tnods,[ter_nod n2m]);
  659.             indic = find(xind==0);
  660.             for j = 1:length(indic)
  661.                 k = indic(j);
  662.                 WP_Tree = write(WP_Tree,'data',tnods(k),zeros(sizes(k,:)));
  663.             end
  664.             [WP_Tree,pack] = nodejoin(WP_Tree,0);
  665.         else
  666.             for n = n2m
  667.                 [WP_Tree,WP_Data] = wpjoin(WP_Tree,WP_Data,n);
  668.             end
  669.             [tnods,sizes,order] = wtreemgr('readall',WP_Tree);
  670.             [xind,yind] = wcommon(tnods,[ter_nod n2m]);
  671.             indic = find(xind==0);
  672.             if order==2 , sizes = [ones(length(sizes),1) sizes]; end
  673.     for j = 1:length(indic)
  674.                 k = indic(j);
  675.                 WP_Data = wdatamgr('write_cfs',WP_Data,WP_Tree,...
  676.                                     tnods(k),zeros(sizes(k,1),sizes(k,2)));
  677.             end
  678.             [WP_Tree,WP_Data,pack] = wpjoin(WP_Tree,WP_Data,0);
  679.         end
  680.         % Drawing Packet.
  681.         %----------------
  682.         nodes = (sort(Selected_Nodes(1,:)))';
  683.         Tree_Type_TxtV = wmemtool('rmb',win_wptool,n_wp_utils,ind_type_txt);
  684.         str_pck = ['Rec. Pack. : '];
  685.         len     =  length(nodes);
  686.         if strcmp(Tree_Type_TxtV,'i')
  687.             ind = depo2ind(order,nodes);
  688.             for k=1:len
  689.                 str_pck = [str_pck '(' sprintf('%.0f',ind(k)) ')'];
  690.                 if k<len , str_pck = [str_pck '+']; end
  691.             end
  692.         else
  693.             [d,p] = ind2depo(order,nodes);
  694.             for k=1:len
  695.                 str_pck = [str_pck '(' sprintf('%.0f',d(k)) ',' ...
  696.                                         sprintf('%.0f',p(k)), ')'];
  697.                 if k<len , str_pck = [str_pck '+']; end
  698.             end
  699.         end
  700.         delete(get(WP_Axe_Pack,'Children'));
  701.         dynvtool('ini_his',win_wptool,1)
  702.         axes(WP_Axe_Pack)
  703.         if order == 2
  704.             xmax = length(pack);
  705.             if xmax==1, xmax = 1+0.01; end
  706.             ymin = min(pack); ymax = max(pack);
  707.             if ymin==ymax , ymin = ymin-0.0001; ymax = ymax+0.0001; end
  708.             color = wtbutils('colors','wp1d','recons');
  709.             line(...
  710.                 'Xdata',[1:length(pack)],...
  711.                 'Ydata',pack,...
  712.                 'Color',color,...
  713.                 'Parent',WP_Axe_Pack);
  714.             set(WP_Axe_Pack,'XLim',[1 xmax],'Ylim',[ymin ymax]);
  715.             wtitle(str_pck,...
  716.                 'FontSize',ftn_size,...
  717.                 'Color',color,...
  718.                 'Parent',WP_Axe_Pack);
  719.         else
  720. % Image Coding Value.
  721. %-------------------
  722. codemat_v = wimgcode('get');
  723.             NB_Colors2D = ...
  724.                     wmemtool('rmb',win_wptool,n_wp_utils,ind_nb_colors);
  725.             image(...
  726.                   'CData',wimgcode('cod',0,pack,NB_Colors2D,codemat_v),...
  727.                   'Parent',WP_Axe_Pack);
  728.             wtitle(str_pck,...
  729.                    'FontSize',ftn_size,...
  730.                    'Color',get(WP_Axe_Tree,'Xcolor'),...
  731.                    'Parent',WP_Axe_Pack);
  732.             set(WP_Axe_Pack,...
  733.                 'Layer','top',           ...
  734.                 'Ydir','Reverse',        ...
  735.                 'XLim',[1 size(pack,2)], ...
  736.                 'Ylim',[1 size(pack,1)], ...
  737.                 'Tag',tag_axe_pack       ...
  738.                 );
  739.         end
  740.         dynvtool('put',win_wptool)
  741.         axes(WP_Axe_Tree);
  742.         set(Tree_Texts,'Visible','on');
  743. end
  744. % End waiting.
  745. %-------------
  746. wwaiting('off',win_wptool);
  747. %------------------------------------------------
  748. function [obj,node] = findnode(win,axe);
  749. obj = get(win,'CurrentObject');
  750. if ~isempty(obj)
  751.    if ~isequal(get(obj,'Parent'),axe)
  752.       obj = [];
  753.    else
  754.       node = get(obj,'UserData');
  755.    end
  756. end
  757. %------------------------------------------------