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

波变换

开发平台:

Matlab

  1. function varargout = utthrset(option,in2,in3)
  2. %UTTHRSET Utilities for threshold settings.
  3. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 23-May-97.
  4. %   Last Revision: 16-Jan-2001.
  5. %   Copyright 1995-2002 The MathWorks, Inc.
  6. %   $Revision: 1.11 $  $Date: 2002/06/17 12:19:38 $
  7. % MemBloc of stored values.
  8. %==========================
  9. % MB1.
  10. %-----
  11. n_membloc1  = 'ReturnTHR_Bloc';
  12. ind_ret_fig = 1;
  13. ind_tog_thr = 2;
  14. ind_status  = 3;
  15. nb1_stored  = 3;
  16. % Same bloc in utthrw1d.
  17. %-----------------------
  18. n_memblocTHR   = 'MB_ThrStruct';
  19. ind_thr_struct = 1;
  20. ind_int_thr    = 2;
  21. % Tag property.
  22. %--------------
  23. tag_figThresh = 'Fig_Thresh';
  24. tag_pus_close = 'Close';
  25. % Tag property (2).
  26. %------------------
  27. tag_lineH_up   = 'LH_u';
  28. tag_lineH_down = 'LH_d';
  29. tag_lineV      = 'LV';
  30. switch option
  31.     case 'init'
  32.         % Handle of Calling Toggle Button.
  33.         %---------------------------------
  34.         switch nargin
  35.           case 1 , tog_thr = gcbo;
  36.           case 2 , tog_thr = in2;
  37.         end
  38.         calling_Fig = get(tog_thr,'Parent');
  39.         oldFig = wfindobj('figure','tag',tag_figThresh);
  40.         existFig = ~isempty(oldFig);
  41.         if existFig
  42.             existFig = 0;
  43.             for k = 1:length(oldFig)
  44.                 oldCall = wmemtool('rmb',oldFig(k),n_membloc1,ind_ret_fig);
  45.                 if isequal(oldCall,calling_Fig)
  46.                    existFig = oldFig(k);
  47.                    break
  48.                 end
  49.             end
  50.         end
  51.         if existFig == 0
  52.              [den_struct,int_DepThr_Cell] = ...
  53.                  wmemtool('rmb',calling_Fig,n_memblocTHR, ...
  54.                           ind_thr_struct,ind_int_thr);
  55.              nb = size(den_struct,1);
  56.              jj = zeros(nb,1);
  57.              for k = 1:nb
  58.                  jj(k) = ~isempty(den_struct(k).thrParams);
  59.              end
  60.              NB_lev = length(find(jj>0));
  61.              NB_Max_Int = 6;
  62.             % Create window.
  63.             %---------------
  64.             [Def_Txt_Height,Def_Btn_Height] = ...
  65.                 mextglob('get','Def_Txt_Height','Def_Btn_Height');
  66.             pos_win = get(0,'DefaultfigurePosition');
  67.             pos_win(3) = 6*pos_win(3)/5;
  68.             leftx = 45;   rightx  = 160;
  69.             topy  = 30;   bottomy = 60;
  70.             bdx   = 30;   bdy     = 30;
  71.             callName = get(calling_Fig,'Name');
  72.             lenName  = length(callName);
  73.             if lenName<36
  74.                 strDEB = ['Interval Dependent Threshold Settings for '];
  75.             else
  76.                 strDEB = ['Int. Dependent Threshold Settings for '];
  77.             end
  78.             lenStrDEB = length(strDEB);
  79.             lenTOT = lenName+lenStrDEB;
  80.             strDEB = [strDEB callName];            
  81.             if lenTOT>72 , strDEB = [strDEB(1:72) '...']; end
  82.             strName  = [strDEB ' (fig. ' int2str(calling_Fig),')'];
  83.             fig = wfigmngr('init',      ...
  84.                      'Name',strName,    ...
  85.                      'Position',pos_win,...
  86.                      'Visible','Off',   ...
  87.                      'Tag',tag_figThresh...
  88.                      );
  89.             wfigmngr('extfig',fig,'ExtFig_ThrSet')
  90. % Add Help for Tool.
  91. %------------------
  92. wfighelp('addHelpTool',fig,'&One-Dimensional Local Thresholding','IDTS_GUI');
  93. % Add Help Item.
  94. %----------------
  95. wfighelp('addHelpItem',fig,'Variance Adaptive Thresholding','VARTHR');
  96.             set(fig,'Visible','On')
  97.             xprop = (pos_win(3)+bdx-rightx)/pos_win(3);
  98.             pos_dyn_visu = dynvtool('create',fig,xprop,0);
  99.             ylow = pos_dyn_visu(4);
  100.             pos_gra = [0, pos_dyn_visu(4), pos_win(3), pos_win(4)-ylow];
  101.             % Creating axes and uicontrols.
  102.             %==============================
  103.             noINT_DEP = isempty(int_DepThr_Cell);
  104.             % Positions
  105.             %-----------
  106.             d_txt   = (Def_Btn_Height-Def_Txt_Height)/2;
  107.             w_fra   = rightx-bdx;
  108.             x_fra   = pos_gra(3)-w_fra;
  109.             pos_fra = [x_fra 0 w_fra pos_win(4)+5];
  110.             bdx     = 6;
  111.             bdy     = 6;
  112.             h_txt   = Def_Txt_Height;
  113.             h_btn   = Def_Btn_Height;
  114.             w_fra_lev = w_fra-2*bdx;
  115.             x_fra_lev = x_fra+bdx;
  116.             w_pus     = (5*w_fra_lev)/6;
  117.             x_pus     = x_fra_lev+(w_fra_lev-w_pus)/2; 
  118.             h_fra_lev   = h_btn+2*bdy;
  119.             y_fra_lev   = pos_win(4)-h_fra_lev-2*bdy;
  120.             pos_fra_lev = [x_fra_lev y_fra_lev w_fra_lev h_fra_lev];            
  121.             w_uic       = (w_fra_lev-2*bdx)/2;
  122.             x_uic       = x_fra_lev+bdx;
  123.             y_uic       = y_fra_lev+bdy;
  124.             pos_txt_lev = [x_uic, y_uic+d_txt/2, w_uic, h_txt];
  125.             x_uic       = x_uic+w_uic;
  126.             pos_pop_lev = [x_uic, y_uic, w_uic, h_btn];
  127.             y_fra_top   = y_fra_lev-6*bdy;
  128.             w_uic       = w_fra_lev-bdx;
  129.             x_uic       = x_fra_lev+(w_fra_lev-w_uic)/2;
  130.             y_uic       = y_fra_top-h_txt-bdy;
  131.             pos_txt_lim = [x_uic y_uic w_uic h_txt];        
  132.             h_uic       = 1.5*h_btn;
  133.             y_uic       = y_uic-h_uic-2*bdy;
  134.             pos_pus_del = [x_pus, y_uic, w_pus, h_uic];
  135.             y_uic       = y_uic-h_uic-2*bdy;
  136.             pos_pus_pro = [x_pus, y_uic, w_pus, h_uic];
  137.             y_fra_lim   = y_uic-bdy;
  138.             h_fra_lim   = y_fra_top-y_fra_lim;
  139.             pos_fra_lim = [x_fra_lev y_fra_lim w_fra_lev h_fra_lim];
  140.             y_fra_top   = y_fra_lim-6*bdy;
  141.             w_uic       = w_fra_lev-bdx;
  142.             x_uic       = x_fra_lev+(w_fra_lev-w_uic)/2;
  143.             h_def       = 2*h_txt;
  144.             y_uic       = y_fra_top-h_def-bdy;
  145.             pos_txt_def = [x_uic y_uic w_uic h_def];
  146.             w_uic       = (w_fra_lev-2*bdx)/2;
  147.             x_uic       = x_fra_lev+bdx;
  148.             y_uic       = y_uic-h_btn-1*bdy;
  149.             pos_txt_num = [x_uic, y_uic+d_txt/2, w_uic, h_txt];
  150.             x_uic       = x_uic+w_uic;
  151.             pos_pop_num = [x_uic, y_uic, w_uic, h_btn];
  152.             h_uic       = 1.5*h_btn;
  153.             w_uic       = (2*w_fra_lev)/3;
  154.             if noINT_DEP , y_uic = y_uic-0.5*h_btn; end
  155.             pos_pus_gen = [x_pus, y_uic, w_pus, h_uic];
  156.             y_fra_def   = y_uic-bdy;
  157.             h_fra_def   = y_fra_top-y_fra_def;
  158.             pos_fra_def = [x_fra_lev y_fra_def w_fra_lev h_fra_def];
  159.             y_uic       = y_uic-h_uic-8*bdy;
  160.             y_uic       = h_btn/2;
  161.             pos_close   = [x_pus y_uic w_pus h_uic];
  162.             % Strings
  163.             %--------
  164.             str_txt_lev = 'Level';
  165.             str_levels  = int2str([1:NB_lev]');
  166.             str_txt_lim = 'Interval Delimiters';
  167.             str_pus_del = 'Delete';
  168.             tip_pus_pro = 'Propagate intervals to all levels';
  169.             str_pus_pro = 'Propagate';
  170.             str_txt_num = 'Number';
  171.             str_pop_num = int2str([1:NB_Max_Int]');
  172.             str_pus_gen = 'Generate';
  173.             str_close   = 'Close';
  174.             if noINT_DEP
  175.                 strBEG = '    Generate    ';
  176.                 strEND = 'Default Intervals';
  177.                 toolTipGEN = 'Generate Interval Dependent Thresholds';
  178.                 visNum = 'Off'; visGen = 'On';
  179.             else
  180.                 strBEG = 'Select Number';
  181.                 strEND = 'of Intervals ';
  182.                 toolTipGEN = 'Select Number of Intervals';
  183.                 visNum = 'On'; visGen = 'Off';
  184.             end
  185.             str_txt_def = strvcat(strBEG,strEND);
  186.             % Create UIC and Axes.
  187.             %---------------------
  188.             commonProp = {'Parent',fig,'Unit','pixels'}; 
  189.             fra_ini  = uicontrol(...
  190.                         commonProp{:},   ...
  191.                         'Style','frame', ...
  192.                         'Position', pos_fra ...
  193.                         );
  194.             fra_lev  = uicontrol(...
  195.                         commonProp{:},  ...
  196.                         'Style','frame',...
  197.                         'Position', pos_fra_lev ...
  198.                         );
  199.             txt_lev = uicontrol(...
  200.                         commonProp{:},  ...
  201.                         'Style','text', ...
  202.                         'HorizontalAlignment','left', ...
  203.                         'Position',pos_txt_lev,       ...
  204.                         'String',str_txt_lev ...
  205.                         );
  206.             pop_lev = uicontrol(...
  207.                         commonProp{:},  ...
  208.                         'Style','Popup',...
  209.                         'Position',pos_pop_lev, ...
  210.                         'String',str_levels,    ...
  211.                         'Userdata',1            ...
  212.                         );
  213.             fra_lim  = uicontrol(...
  214.                         commonProp{:},  ...
  215.                         'Style','frame',...
  216.                         'Position', pos_fra_lim ...
  217.                         );
  218.             txt_lim = uicontrol(...
  219.                         commonProp{:},  ...
  220.                         'Style','text', ...
  221.                         'HorizontalAlignment','Center', ...
  222.                         'Position',pos_txt_lim,       ...
  223.                         'String',str_txt_lim ...
  224.                         );
  225.             pus_pro = uicontrol(...
  226.                         commonProp{:},...
  227.                         'Style','Pushbutton',  ...
  228.                         'Position',pos_pus_pro, ...
  229.                         'String',xlate(str_pus_pro),   ...
  230.                         'Enable','On',         ...
  231.                         'TooltipString',xlate(tip_pus_pro) ...
  232.                         );
  233.             pus_del = uicontrol(...
  234.                         commonProp{:},     ...
  235.                         'Style','Pushbutton',   ...
  236.                         'Position',pos_pus_del, ...
  237.                         'String',xlate(str_pus_del),   ...
  238.                         'Interruptible','on'    ...
  239.                         );
  240.             fra_def  = uicontrol(...
  241.                         commonProp{:},  ...
  242.                         'Style','frame',...
  243.                         'Position', pos_fra_def ...
  244.                         );
  245.             txt_def = uicontrol(...
  246.                         commonProp{:},  ...
  247.                         'Style','text', ...
  248.                         'HorizontalAlignment','Center', ...
  249.                         'Max',2,                ...
  250.                         'Position',pos_txt_def, ...
  251.                         'ToolTip',toolTipGEN,   ...
  252.                         'String',str_txt_def    ...
  253.                         );
  254.             txt_num = uicontrol(...
  255.                         commonProp{:},  ...
  256.                         'Style','text', ...
  257.                         'Visible',visNum, ...
  258.                         'HorizontalAlignment','left', ...
  259.                         'Position',pos_txt_num,       ...
  260.                         'ToolTip',toolTipGEN,...
  261.                         'String',str_txt_num ...
  262.                         );
  263.             pop_num = uicontrol(...
  264.                         commonProp{:},  ...
  265.                         'Style','Popup',...
  266.                         'Visible',visNum, ...
  267.                         'Position',pos_pop_num, ...
  268.                         'ToolTip',toolTipGEN,   ...
  269.                         'String',str_pop_num    ...
  270.                         );
  271.             pus_gen = uicontrol(...
  272.                         commonProp{:},          ...
  273.                         'Style','Pushbutton',   ...
  274.                         'Visible',visGen,       ...
  275.                         'Position',pos_pus_gen, ...
  276.                         'String',xlate(str_pus_gen),   ...
  277.                         'ToolTip',toolTipGEN,   ...
  278.                         'Interruptible','on'    ...
  279.                         );
  280.             pus_close = uicontrol(...
  281.                         commonProp{:},        ...
  282.                         'Style','Pushbutton', ...
  283.                         'Position',pos_close, ...
  284.                         'String',xlate(str_close),   ...
  285.                         'Interruptible','on', ...
  286.                         'Tag',tag_pus_close,  ...
  287.                         'Userdata',0          ...
  288.                         );
  289.             pos_axe = pos_gra+[leftx bottomy -(leftx+rightx) -(bottomy+topy)];
  290.             ax_hdl  = axes(...
  291.                         commonProp{:},     ...
  292.                        'Position',pos_axe, ...
  293.                        'box','on');
  294.             ind_lev = 1;
  295.             % Setting Callback.
  296.             %------------------
  297.             handles = ...
  298.               [fig;ax_hdl;pop_lev;txt_def;txt_num;pop_num;pus_gen;fra_def];
  299.             if nargout>0 , varargout{1} = handles; end
  300.             handles    = num2mstr(handles);
  301.             cb_pop_lev = [mfilename '(''chg_level'',' handles ');'];
  302.             cb_pus_del = [mfilename '(''del_Delimiters'',' handles ');'];
  303.             cb_pus_pro = [mfilename '(''propagate'',' handles ');'];
  304.             cb_pop_num = [mfilename '(''gen_Intervals'',' handles ');'];
  305.             cb_pus_gen = [mfilename '(''gen_Intervals'',' handles ');'];
  306.             cb_close   = wfigmngr('attach_close',fig,mfilename,'cond');
  307.             set(pop_lev,'Callback',cb_pop_lev);
  308.             set(pus_del,'Callback',cb_pus_del);
  309.             set(pus_pro,'Callback',cb_pus_pro);
  310.             set(pop_num,'Callback',cb_pop_num);
  311.             set(pus_gen,'Callback',cb_pus_gen);
  312.             set(pus_close,'Callback',cb_close);
  313.             % Waiting Text construction.
  314.             %---------------------------
  315.             wwaiting('create',fig,xprop);
  316.             %  Normalization.
  317.             %----------------
  318.             pos_gra = wfigmngr('normalize',fig,pos_gra);
  319.             set(fig,'visible','on')
  320.         else
  321.           pus_close = wfindobj(existFig,...
  322.                           'style','Pushbutton','Tag',tag_pus_close);
  323.           eval(get(pus_close,'Callback'));
  324.           return
  325.         end
  326. % Add Context Sensitive Help (CSHelp).
  327. %-------------------------------------
  328. hdl_GENER_VARTHR = [fra_lim,txt_lim,pus_pro,pus_del];
  329. hdl_MODIF_VARTHR = [fra_def,txt_def,txt_num,pop_num,pus_gen];
  330. wfighelp('add_ContextMenu',fig,hdl_GENER_VARTHR,'GENER_VARTHR');
  331. wfighelp('add_ContextMenu',fig,hdl_MODIF_VARTHR,'MODIF_VARTHR');
  332. %-------------------------------------
  333.         % Memory blocks update.
  334.         %----------------------
  335.         wmemtool('wmb',fig,n_membloc1,...
  336.                        ind_ret_fig,calling_Fig,ind_tog_thr,tog_thr,...
  337.                        ind_status,0);
  338.         wmemtool('wmb',fig,n_memblocTHR,...
  339.                        ind_thr_struct,den_struct,...
  340.                        ind_int_thr,int_DepThr_Cell ...
  341.                        );
  342.         % Plotting lines.
  343.         %----------------
  344.         plotlines(fig,ax_hdl,den_struct(ind_lev),ind_lev)
  345.     case 'chg_level'
  346.         % in2 = [fig;ax_hdl;pop_lev;txt_def;txt_num;pop_num;pus_gen;fra_def];
  347.         %---------------------------------------------------------------------
  348.         fig     = in2(1);
  349.         ax_hdl  = in2(2);
  350.         pop     = in2(3);
  351.         old_lev = get(pop,'Userdata');
  352.         new_lev = get(pop,'Value');
  353.         if old_lev==new_lev , return; end
  354.         lHu     = findobj(ax_hdl,'tag',tag_lineH_up);
  355.         cbthrw1d('upd_thrStruct',fig,lHu);
  356.         thrStruct = wmemtool('rmb',fig,n_memblocTHR,ind_thr_struct);
  357.         set(pop,'Userdata',new_lev)
  358.         plotlines(fig,ax_hdl,thrStruct(new_lev),new_lev);
  359.     case 'del_Delimiters'
  360.         % in2 = [fig;ax_hdl;pop_lev;txt_def;txt_num;pop_num;pus_gen;fra_def];
  361.         %---------------------------------------------------------------------
  362.         fig   = in2(1);
  363.         axe   = in2(2);
  364.         pop_num = in2(6);
  365.         lines = findobj(axe,'type','line');
  366.         lHu   = findobj(lines,'tag',tag_lineH_up);
  367.         lHd   = findobj(lines,'tag',tag_lineH_down);
  368.         lV    = findobj(lines,'tag',tag_lineV);
  369.         xh    = get(lHu,'Xdata');
  370.         yh    = get(lHu,'Ydata');
  371.         xh    = xh([1 length(xh)]);
  372.         yhok  = yh(~isnan(yh));
  373.         yh    = mean(yhok);
  374.         yh    = [yh yh];
  375.         if ~isempty(lV),  delete(lV); end
  376.         set(lHu,'Xdata',xh,'Ydata',yh)
  377.         set(lHd,'Xdata',xh,'Ydata',-yh)
  378.         cbthrw1d('upd_thrStruct',fig,lHu);
  379.     case 'gen_Intervals'
  380.         % in2 = [fig;ax_hdl;pop_lev;txt_def;txt_num;pop_num;pus_gen;fra_def];
  381.         %---------------------------------------------------------------------
  382.         fig     = in2(1);
  383.         ax_hdl  = in2(2);
  384.         pop_lev = in2(3);
  385.         txt_def = in2(4);
  386.         txt_num = in2(5);
  387.         pop_num = in2(6);
  388.         pus_gen = in2(7);
  389.         nb_IntVal = get(pop_num,'Value');
  390.         % Delete previous delimiters.
  391.         %----------------------------
  392.         utthrset('del_Delimiters',in2);
  393.         % Computing Intervals.
  394.         %---------------------
  395.         [thrStruct,int_DepThr_Cell] = wmemtool('rmb',fig,n_memblocTHR,...
  396.                                           ind_thr_struct,ind_int_thr);
  397.         if isempty(int_DepThr_Cell)
  398.             % Compute decomposition and plot.
  399.             %--------------------------------
  400. uic_ON = findall(fig,'type','uicontrol','enable','on');
  401. set(uic_ON,'enable','Off');
  402. uic_MSG = wwaiting('handle',fig);
  403. set(uic_MSG,'enable','On');
  404.             msg = 'Wait ... computing (only for the first request)';
  405.             wwaiting('msg',fig,msg);
  406.             % Extract the detail of order1.
  407.             %------------------------------
  408.             hdl_DET1 = thrStruct(1).hdlLines;
  409.             det   = get(hdl_DET1,'Ydata');
  410.             xdata = get(hdl_DET1,'Xdata');
  411.             % Replacing 2% of biggest values of by the mean.
  412.             %-----------------------------------------------
  413.             x = sort(abs(det));
  414.             v2p100 = x(fix(length(x)*0.98));
  415.             ind = find(abs(det)>v2p100);
  416.             det(ind) = mean(det);
  417.             lenDet   = length(det);
  418.             % Finding breaking points.
  419.             %-------------------------
  420.             dum = get(pop_num,'String');
  421.             nb_Max_Int = wstr2num(dum(end,:));
  422.             d = 10;            
  423.             if lenDet>1024
  424.                 ratio = ceil(lenDet/1024);
  425.                 [Rupt_Pts,nb_Opt_Rupt,Xidx] = ...
  426.                     wvarchg(det(1:ratio:end),nb_Max_Int,d);
  427.                 Xidx = min(ratio*Xidx,lenDet);
  428.             else
  429.                 [Rupt_Pts,nb_Opt_Rupt,Xidx] = wvarchg(det,nb_Max_Int,d);            
  430.             end    
  431.             nb_Opt_Int = nb_Opt_Rupt+1;
  432.             % Computing denoising structure.
  433.             %-------------------------------
  434.             Xidx = [zeros(size(Xidx,1),1) Xidx];
  435.             norma = sqrt(2)*thselect(det,'minimaxi');
  436.             % sqrt(2) comes from the fact that if x is a white noise 
  437.             % of variance 1 the reconstructed detail_1 of x is of 
  438.             % variance 1/sqrt(2)            
  439.             int_DepThr = cell(1,nb_Max_Int);
  440.             for nbint = 1:nb_Max_Int
  441.               for j = 1:nbint
  442.                  sig = median(abs(det(Xidx(nbint,j)+1:Xidx(nbint,j+1))))/0.6745;
  443.                  thr = norma*sig;
  444.                  int_DepThr{nbint}(j,:) = ...
  445.                      [Xidx(nbint,j) , Xidx(nbint,j+1), thr];
  446.               end
  447.               int_DepThr{nbint}(1,1) = 1;
  448.               int_DepThr{nbint}(:,[1 2]) = xdata(int_DepThr{nbint}(:,[1 2]));
  449.             end
  450.             int_DepThr_Cell = {int_DepThr,nb_Opt_Int}; 
  451.             wmemtool('wmb',fig,n_memblocTHR,ind_int_thr,int_DepThr_Cell);
  452.             calling_Fig = wmemtool('rmb',fig,n_membloc1,ind_ret_fig);
  453.             wmemtool('wmb',calling_Fig,n_memblocTHR,ind_int_thr,int_DepThr_Cell);            
  454.             viewNUM = 1;
  455.             % End waiting.
  456.             %-------------
  457.             wwaiting('off',fig);
  458. set(uic_ON,'enable','On');
  459.         else
  460.             int_DepThr = int_DepThr_Cell{1};
  461.             nb_Opt_Int = int_DepThr_Cell{2};
  462.             viewNUM = isequal(lower(get(pus_gen,'Visible')),'on');
  463.         end
  464.         if viewNUM
  465.             nb_IntVal = nb_Opt_Int;
  466.             str_txt_def = strvcat('Select Number','of Intervals ');
  467.             toolTipGEN  = 'Select Number of Intervals';            
  468.             set(pop_num,'Value',nb_IntVal);
  469.             set(pus_gen,'Visible','Off','ToolTip',toolTipGEN);
  470.             set(txt_def,'String',str_txt_def,'ToolTip',toolTipGEN)
  471.             set([txt_num,pop_num],'Visible','On','ToolTip',toolTipGEN);
  472.         end
  473.         intervals = int_DepThr{nb_IntVal};
  474.         for k=1:length(thrStruct);
  475.            if ~isempty(thrStruct(k).thrParams)
  476.                maxTHR = max(abs(get(thrStruct(k).hdlLines,'Ydata')));
  477.                thrPAR = intervals;
  478.                TMP = min(thrPAR(:,3),maxTHR);
  479.                thrPAR(:,3) = TMP;
  480.                thrStruct(k).thrParams = thrPAR;
  481.            end
  482.         end
  483.         wmemtool('wmb',fig,n_memblocTHR,ind_thr_struct,thrStruct);
  484.         % Plotting lines.
  485.         %----------------
  486.         ind_lev = get(pop_lev,'Value');
  487.         plotlines(fig,ax_hdl,thrStruct(ind_lev),ind_lev);
  488.     case 'propagate'
  489.         % in2 = [fig;ax_hdl;pop_lev;txt_def;txt_num;pop_num;pus_gen;fra_def];
  490.         %---------------------------------------------------------------------
  491.         fig   = in2(1);
  492.         axe   = in2(2);
  493.         pop   = in2(3);
  494.         lines = findobj(axe,'type','line');
  495.         lHu   = findobj(lines,'tag',tag_lineH_up);
  496.         xini  = get(lHu,'Xdata');
  497.         yini  = get(lHu,'Ydata');
  498.         iniPar = getparam(xini,zeros(size(yini)));
  499.         thrStruct = wmemtool('rmb',fig,n_memblocTHR,ind_thr_struct);
  500.         level  = get(pop,'Value');
  501.         strlev = get(pop,'String');
  502.         for k=1:size(strlev,1)
  503.             lev = str2num(strlev(k,:));
  504.             if lev~=level
  505.                 oldPar = thrStruct(lev).thrParams;
  506.                 [x,y] = getxy(oldPar);
  507.                 for j = 1:length(xini)
  508.                     [dummy,ind] = min(x-xini(j));
  509.                     yini(j) = y(ind);
  510.                 end
  511.                 newPar = getparam(xini,yini);
  512.                 thrStruct(lev).thrParams = newPar;
  513.             end
  514.         end
  515.        wmemtool('wmb',fig,n_memblocTHR,ind_thr_struct,thrStruct);
  516.     case 'clear_GRAPHICS'
  517.         % called by lines callback
  518.         % do nothing
  519.         %--------------------------
  520.     case 'close'
  521.         fig = in2(1);
  522.         [calling_Fig,tog_thr,status] = ...
  523.             wmemtool('rmb',fig,n_membloc1,ind_ret_fig,ind_tog_thr,ind_status);
  524.         if status
  525.             thrStruct = wmemtool('rmb',fig,n_memblocTHR,ind_thr_struct);
  526.             status = wwaitans(fig,'Update thresholds ?',2,'cond');
  527.             switch status
  528.               case -1 ,  
  529.               case  0 ,
  530.               case  1 , utthrw1d('return_SetThr',calling_Fig,thrStruct);
  531.             end            
  532.         end
  533.         if status>-1 , set(tog_thr,'Value',0); end
  534.         varargout{1} = status;
  535.     case 'stop'
  536.         calling_Fig = in2;
  537.         oldFig = wfindobj('figure','tag',tag_figThresh);
  538.         existFig = ~isempty(oldFig);
  539.         if existFig
  540.             existFig = 0;
  541.             for k = 1:length(oldFig)
  542.                 oldCall = wmemtool('rmb',oldFig(k),n_membloc1,ind_ret_fig);
  543.                 if isequal(oldCall,calling_Fig)
  544.                    existFig = oldFig(k);
  545.                    break
  546.                 end
  547.             end
  548.         end
  549.         if existFig == 0 , return; end
  550.         wmemtool('wmb',existFig,n_membloc1,ind_status,0);
  551.         pus_close = ...
  552.           wfindobj(existFig,'style','Pushbutton','Tag',tag_pus_close);
  553.         eval(get(pus_close,'Callback'));
  554.     case 'demo'
  555.         tog_thr = in2;
  556.         nbINT   = in3;
  557.         handles = utthrset('init',tog_thr);
  558.         drawnow;
  559.         % in2 = [fig;ax_hdl;pop_lev;txt_def;txt_num;pop_num;pus_gen;fra_def];
  560.         %---------------------------------------------------------------------
  561.         fig = handles(1);
  562.         figure(fig)
  563.         txt_def = handles(4);
  564.         txt_num = handles(5);        
  565.         pop_num = handles(6);
  566.         pus_gen = handles(7);
  567. % Generating Intervals.
  568. %----------------------
  569.         eval(get(pus_gen,'Callback'));
  570. % Setting message for waiting.
  571. %-----------------------------
  572. uic_ON = findall(fig,'type','uicontrol','enable','on');
  573. uic_MSG = wwaiting('handle',fig);
  574. set(uic_ON,'enable','Off');
  575. set(uic_MSG,'enable','On');
  576. msg = 'The intervals are generated ...';
  577. wwaiting('msg',fig,msg);
  578.         str_txt_def = strvcat('Select Number','of Intervals ');
  579.         toolTipGEN  = 'Select Number of Intervals';
  580.         set(pus_gen,'Visible','Off','ToolTip',toolTipGEN);
  581.         
  582.         %--------------------------------------------------------%
  583.         fra_def = handles(end);
  584.         pos_fra = get(fra_def,'Position');
  585.         pos_num = get(pop_num,'Position');
  586.         deltaH  = pos_num(4)/2;
  587.         set(fra_def,'Position',pos_fra+[0 deltaH 0 -deltaH]);
  588.         drawnow
  589.         %--------------------------------------------------------%
  590.         
  591.         set(txt_def,'String',str_txt_def,'ToolTip',toolTipGEN)
  592.         set([txt_num,pop_num],'Visible','On','ToolTip',toolTipGEN);
  593.         nbINTComp = get(pop_num,'Value');
  594.         if ~isequal(nbINTComp,nbINT)
  595.     msg = 'Selecting the best number of Intervals';
  596.     wwaiting('msg',fig,msg);
  597.             pause(1.5)
  598.             set(pop_num,'Value',nbINT);
  599.             eval(get(pop_num,'Callback'));
  600.         end
  601.         pause(3)
  602.         thrStruct = wmemtool('rmb',fig,n_memblocTHR,ind_thr_struct);
  603.         calling_Fig = wmemtool('rmb',fig,n_membloc1,ind_ret_fig);
  604.         utthrw1d('return_SetThr',calling_Fig,thrStruct);
  605.         delete(fig)
  606.         set(tog_thr,'Value',0);
  607.     otherwise
  608.         errargt(mfilename,'Unknown Option','msg');
  609.         error('*');
  610. end
  611. %=============================================================================%
  612. % INTERNAL FUNCTIONS
  613. %=============================================================================%
  614. %-----------------------------------------------------------------------------%
  615. function param = getparam(x,y)
  616. lx    = length(x);
  617. x_beg = x(1:3:lx);
  618. x_end = x(2:3:lx);
  619. y     = y(1:3:lx);
  620. param = [x_beg(:) , x_end(:) , y(:)];
  621. %-----------------------------------------------------------------------------%
  622. function [x,y] = getxy(arg)
  623. NB_int  = size(arg,1);
  624. if NB_int>1
  625.     x = [arg(:,1:2) NaN*ones(NB_int,1)]';
  626.     x = x(:)';
  627.     l = 3*NB_int-1;
  628.     x = x(1:l);
  629.     y = [arg(:,[3 3]) NaN*ones(NB_int,1)]';
  630.     y = y(:)';
  631.     y = y(1:l);
  632. else
  633.     x = arg(1,1:2); y = arg(1,[3 3]);
  634. end
  635. %-----------------------------------------------------------------------------%
  636. function plotlines(fig,ax_hdl,deno_struct,level)
  637. linesHDL = findobj(ax_hdl,'type','line');
  638. if ~isempty(linesHDL), delete(linesHDL); end
  639. hdlLineVal  = deno_struct.hdlLines;
  640. [xHOR,yHOR] = getxy(deno_struct.thrParams);
  641. if ~isempty(hdlLineVal)
  642.     xdata = get(hdlLineVal,'Xdata');
  643.     ydata = get(hdlLineVal,'Ydata');
  644.     color = get(hdlLineVal,'Color');
  645.     lsig  = line(...
  646.               'Parent',ax_hdl, ...
  647.               'Xdata',xdata,   ...
  648.               'Ydata',ydata,   ...
  649.               'Linestyle','-', ...
  650.               'linewidth',1,   ...
  651.               'Color',color,   ...
  652.               'Tag','Sig'      ...
  653.               );
  654.     ysigmax = max(abs(ydata));
  655. else
  656.     ysigmax = 1;
  657. end
  658. [lHu,lHd] = cbthrw1d('plotLH',ax_hdl,xHOR,yHOR,level,ysigmax);
  659. ylim  = get(ax_hdl,'Ylim');
  660. yVMin = 2*abs(ylim(1));
  661. cbthrw1d('plotLV',[fig ; lHu ; lHd],[xHOR ; yHOR],yVMin);
  662. notNAN = ~isnan(xHOR);
  663. xmin   = min(xHOR(notNAN));
  664. xmax   = max(xHOR(notNAN));
  665. ymax   = 1.05*max([yHOR(notNAN),ysigmax]);
  666. set(ax_hdl,'Xlim',[xmin xmax],'Ylim',[-ymax ymax])
  667. % Dynvtool Attachement.
  668. %---------------------
  669. dynvtool('init',fig,[],ax_hdl,[],[1 0],...
  670.                 '','','',[],'cbthrw1d',[ax_hdl lHu lHd]);
  671. %-----------------------------------------------------------------------------%
  672. %=============================================================================%