source: trunk/src/series/civ_input.m @ 1156

Last change on this file since 1156 was 1156, checked in by sommeria, 4 months ago

bugs repaired

File size: 76.3 KB
RevLine 
[647]1%'civ_input': function associated with the GUI 'civ_input.fig' to set the input parameters for civ_series
[597]2%------------------------------------------------------------------------
[647]3% function ParamOut = civ_input(Param)
[597]4%
[647]5% OUPUT:
6% ParamOut: Matlab structure containing the parameters set by the GUI civ_input
7%
8% INPUT:
9% Param: Matlab structure containing the input parameters set by the GUI
[810]10
11%=======================================================================
[1126]12% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[810]13%   http://www.legi.grenoble-inp.fr
[1127]14%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
[647]15%
[597]16%     This file is part of the toolbox UVMAT.
17%
18%     UVMAT is free software; you can redistribute it and/or modify
[810]19%     it under the terms of the GNU General Public License as published
20%     by the Free Software Foundation; either version 2 of the license,
21%     or (at your option) any later version.
[597]22%
23%     UVMAT is distributed in the hope that it will be useful,
24%     but WITHOUT ANY WARRANTY; without even the implied warranty of
25%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
[810]26%     GNU General Public License (see LICENSE.txt) for more details.
27%=======================================================================
28
[597]29function varargout = civ_input(varargin)
30
31gui_Singleton = 1;
32gui_State = struct('gui_Name',       mfilename, ...
33    'gui_Singleton',  gui_Singleton, ...
34    'gui_OpeningFcn', @civ_input_OpeningFcn, ...
35    'gui_OutputFcn',  @civ_input_OutputFcn, ...
36    'gui_LayoutFcn',  [] , ...
37    'gui_Callback',   []);
38
[598]39if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback$','once'))
[597]40        gui_State.gui_Callback = str2func(varargin{1});
41end
42
43if nargout
44    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
45else
46    gui_mainfcn(gui_State, varargin{:});
47end
48
49% End initialization code - DO NOT EDIT
50
51%------------------------------------------------------------------------
52% --- Executes just before civ_input is made visible.
53function civ_input_OpeningFcn(hObject, eventdata, handles, Param)
54%------------------------------------------------------------------------
55% This function has no output args, see OutputFcn.
56
57%% General settings
58handles.output = Param;
59guidata(hObject, handles); % Update handles structure
60set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
[774]61set(hObject,'WindowKeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
62set(handles.ref_i,'KeyPressFcn',{@ref_i_KeyPressFcn,handles})%set keyboard action function
[851]63set(handles.ref_j,'KeyPressFcn',{@ref_i_KeyPressFcn,handles})%set keyboard action function
[774]64hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
65hhseries=guidata(hseries); %handles of the elements in 'series'
66SeriesData=get(hseries,'UserData');% info stored in the GUI series
[597]67
[833]68%% set visibility options depending on the calling function (Param.Action.ActionName):
69switch Param.Action.ActionName
70    case 'stereo_civ'
71        set(handles.ListCompareMode,'Visible','off')
72        set(handles.PairIndices,'Visible','off')
73    case 'civ_series'
74        set(handles.ListCompareMode,'Visible','on')
75        set(handles.PairIndices,'Visible','on')
[1148]76    case 'civ_3D'
77        set(handles.ListCompareMode,'Visible','on')
78        set(handles.PairIndices,'Visible','on')
79        set(handles.title_z,'Visible','on')
80        set(handles.num_CorrBoxSize_3,'Visible','on')
81        set(handles.num_SearchBoxSize_3,'Visible','on')
82        set(handles.num_SearchBoxShift_3,'Visible','on')
83        set(handles.num_Dz,'Visible','on')
84        set(handles.title_Dz,'Visible','on')
[833]85end
[599]86
87%% input file info
88NomTypeInput=Param.InputTable{1,4};
[716]89FileType='image';%fdefault
90FileInfo=[];
[1143]91if isfield(SeriesData,'FileInfo')
[1033]92    FileType=SeriesData.FileInfo{1}.FileType;% info on the first input file series
93    FieldType=SeriesData.FileInfo{1}.FieldType;% info on the first input file series
[711]94else
[774]95    set(hhseries.REFRESH,'BackgroundColor',[1 0 1])% indicate that the file input in series needs to be refreshed
[711]96end
[599]97
[774]98%% case of netcdf file as input, read the processing stage and look for corresponding images
[599]99ind_opening=0;%default
100NomTypeNc='';
[851]101NomTypeImaA=NomTypeInput;
102iview_image=1;%line # for the input images
[599]103switch FileType
104    case 'civdata'
[603]105        if ~strcmp(Param.Action.ActionName,'civ_series')
106            msgbox_uvmat('ERROR','bad input data file: open an image or a nc file from civ_series')
[851]107            return
[603]108        end
[599]109        NomTypeNc=NomTypeInput;
[1122]110        ind_opening=SeriesData.FileInfo{1}.CivStage;
[599]111        if isempty(regexp(NomTypeInput,'[ab|AB|-]', 'once'))
[1155]112            set(handles.ListCompareMode,'Value',2) %mode displacement advised if the nomenclature does not involve index pairs
[599]113        else
114            set(handles.ListCompareMode,'Value',1)
115        end
[1155]116        [Data,~,~,errormsg]=nc2struct(SeriesData.FileInfo{1}.FileName,[]);
[774]117        if ~isempty(errormsg)
118            msgbox_uvmat('ERROR',['error in netcdf input file: ' errormsg])
119            return
120        end
[910]121        if isfield(Data,'.Civ1_ImageA')
[1155]122        %[PathCiv1_ImageA,Civ1_ImageA,FileExtA]=fileparts(Data.Civ1_ImageA);%look for the source image A
123        %[PathCiv1_ImageB,Civ1_ImageB,FileExtA]=fileparts(Data.Civ1_ImageB);%look for the source image B
[910]124        end
[774]125        if isfield(Data,'Civ2_ImageA')
[1155]126            %[PathCiv2_ImageA,Civ2_ImageA,FileExtA]=fileparts(Data.Civ2_ImageA);
127            %[PathCiv2_ImageB,Civ2_ImageB,FileExtA]=fileparts(Data.Civ2_ImageB);
[637]128        end
129        if size(Param.InputTable,1)==1
[910]130             if isfield(Data,'.Civ1_ImageA')
[661]131            series('display_file_name',hhseries,Data.Civ1_ImageA,'append');%append the image series to the input list
[1155]132                    [~,~,~,~,~,~,~,~,NomTypeImaA]=fileparts_uvmat(Data.Civ1_ImageA);
133       % [~,~,~,~,~,~,~,~,NomTypeImaB]=fileparts_uvmat(Data.Civ1_ImageB);
[910]134             else
135                 series('display_file_name',hhseries,Data.Civ2_ImageA,'append');%append the image series to the input list
[1155]136                         [~,~,~,~,~,~,~,~,NomTypeImaA]=fileparts_uvmat(Data.Civ2_ImageA);
137        %[RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaB]=fileparts_uvmat(Data.Civ2_ImageB);
[910]138             end
[637]139        end
[910]140
[642]141        iview_image=2;%line # for the input images
[761]142    otherwise
[1154]143        % if ~strcmp(FileType,'image')
144        % msgbox_uvmat('ERROR','civ_series needs images, scalar fields in netcdf format, or civ data as input')
145        % return
146        % end
[599]147end
[598]148       
149%% prepare the GUI with input parameters
[833]150%
[599]151set(handles.ref_i,'String',num2str(Param.IndexRange.first_i))
152if isfield(Param.IndexRange,'first_j')
[603]153    set(handles.ref_j,'String',num2str(Param.IndexRange.first_j))
[597]154end
[856]155set(handles.ConfigSource,'String','\default')
[599]156
[774]157%%  set the menus of image pairs and default selection for civ_input   %%%%%%%%%%%%%%%%%%%
158
159%% display the min and max indices for the whole file series
[855]160if isempty(Param.IndexRange.MaxIndex_i)|| isempty(Param.IndexRange.MinIndex_i)
161    msgbox_uvmat('ERROR','REFRESH the input files in the GUI series')
162     return
163end
[776]164MaxIndex_i=Param.IndexRange.MaxIndex_i(iview_image);
165MinIndex_i=Param.IndexRange.MinIndex_i(iview_image);
166MaxIndex_j=1;%default
167MinIndex_j=1;
168if isfield(Param.IndexRange,'MaxIndex_j')&&isfield(Param.IndexRange,'MinIndex_j')...
169        && numel(Param.IndexRange.MaxIndex_j')>=iview_image &&numel(Param.IndexRange.MinIndex_j')>=iview_image
170    MaxIndex_j=Param.IndexRange.MaxIndex_j(iview_image);
171    MinIndex_j=Param.IndexRange.MinIndex_j(iview_image);
[597]172end
[776]173%update the bounds if possible
174if isfield(SeriesData,'i1_series')&&numel(SeriesData.i1_series)>=iview_image
175    if size(SeriesData.i1_series{iview_image},2)==2 && min(min(SeriesData.i1_series{iview_image}(:,1,:)))==0
176        MinIndex_j=1;% index j set to 1 by default
177        MaxIndex_j=1;
178        MinIndex_i=find(SeriesData.i1_series{iview_image}(1,2,:), 1 )-1;% min ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index)
179        MaxIndex_i=find(SeriesData.i1_series{iview_image}(1,2,:),1,'last' )-1;%max ref index i detected in the series (corresponding to the last non-zero value of i1_series)
180    else
181        ref_i=squeeze(max(SeriesData.i1_series{iview_image}(1,:,:),[],2));% select ref_j index for each ref_i
182        ref_j=squeeze(max(SeriesData.j1_series{iview_image}(1,:,:),[],3));% select ref_i index for each ref_j
183        MinIndex_i=min(find(ref_i))-1;
184        MaxIndex_i=max(find(ref_i))-1;
185        MaxIndex_j=max(find(ref_j))-1;
186        MinIndex_j=min(find(ref_j))-1;
187    end
188end
[599]189
[918]190
[599]191%%  transfer the time from the GUI series, or use file index by default
192time=[];
193TimeUnit='frame'; %default
194CoordUnit='';%default
195pxcm_search=1;
[951]196if isfield(SeriesData,'Time') &&numel(SeriesData.Time')>=1 && ~isempty(SeriesData.Time{1})
[599]197    time=SeriesData.Time{1};
198end
[609]199if isfield(Param.IndexRange,'TimeUnit')&&~isempty(Param.IndexRange.TimeUnit)
200    TimeUnit=Param.IndexRange.TimeUnit;
[1020]201end
[599]202if isfield(SeriesData,'GeometryCalib')
203    tsai=SeriesData.GeometryCalib;
204    if isfield(tsai,'fx_fy')
205        pxcm_search=max(tsai.fx_fy(1),tsai.fx_fy(2));%pixels:cm estimated for the search range
206    end
207    if isfield(tsai,'CoordUnit')
208        CoordUnit=tsai.CoordUnit;
209    end
210end
211
212%% timing display
213%show the reference image edit box if relevant (not needed for movies or in the absence of time information
214if numel(time)>=2 % if there are at least two time values to define dt
[1153]215    if size(time,1)<MaxIndex_i
[599]216        msgbox_uvmat('WARNING','maximum i index restricted by the timing of the xml file');
217    elseif size(time,2)<MaxIndex_j
218        msgbox_uvmat('WARNING','maximum j index restricted by the timing of the xml file');
219    end
220    MaxIndex_i=min(size(time,1),MaxIndex_i);%possibly adjust the max index according to time data
221    MaxIndex_j=min(size(time,2),MaxIndex_j);
[851]222    set(handles.TimeSource,'String',Param.IndexRange.TimeSource);
[599]223else
[851]224    set(handles.TimeSource,'String',''); %xml file not used for timing
[599]225    TimeUnit='frame';
226    time=ones(MaxIndex_j-MinIndex_j+1,1)*(MinIndex_i:MaxIndex_i);
227    time=time+0.001*(MinIndex_j:MaxIndex_j)'*ones(1,MaxIndex_i-MinIndex_i+1);
228end
229CivInputData.Time=time;
[637]230CivInputData.NomTypeIma=NomTypeImaA;
[599]231set(handles.civ_input,'UserData',CivInputData)
232set(handles.dt_unit,'String',['dt in m' TimeUnit]);%display dt in unit 10-3 of the time (e.g ms)
233set(handles.TimeUnit,'String',TimeUnit);
234set(handles.SearchRange,'UserData', pxcm_search);
235
[668]236
[774]237%% set the civ_input options, depending on the input file content if a nc file has been opened
238ListOptions={'CheckCiv1', 'CheckFix1' 'CheckPatch1', 'CheckCiv2', 'CheckFix2', 'CheckPatch2'};
239checkbox=zeros(size(ListOptions));%default
[851]240checkrefresh=0;
[774]241if ind_opening==0  %case of image opening, start with Civ1
242    for index=1:numel(ListOptions)
243        checkbox(index)=get(handles.(ListOptions{index}),'Value');
244    end
245    index_max=find(checkbox, 1, 'last' );
246    if isempty(index_max),index_max=1;end
247    for index=1:index_max
248        set(handles.(ListOptions{index}),'Value',1)% select all operations starting from CIV1
249    end
[851]250else  %case of netcdf file opening, start with the stage read in the file if the input file is being refreshed
[1153]251    %     if isequal(get(hhseries.REFRESH,'BackgroundColor'),[1 1 0]) &&...
252    %             ~(isfield(Param,'ActionInput') && isfield(Param.ActionInput,'ConfigSource'))
253    for index = 1:min(ind_opening,5)
254        set(handles.(ListOptions{index}),'value',0)
255        fill_civ_input(Data,handles); %fill civ_input with the parameters retrieved from an input Civ file
256    end
257    if isempty(FileInfo)
258        FileInfo.FileName='';
259    end
260    set(handles.ConfigSource,'String',FileInfo.FileName);
261    if ind_opening<6
262        for index = 1:ind_opening
263            set(handles.(ListOptions{index}),'value',0)
264        end
265        for index = ind_opening+1:6
266            set(handles.(ListOptions{index}),'value',1)
267        end
268        set(handles.CheckCiv3,'Visible','off')% make visible the switch 'iterate/repet' for Civ2.
269        set(handles.CheckCiv3,'Value',0)% select'iterate/repet' by default
270    else
271        for index = 1:3
272            set(handles.(ListOptions{index}),'value',0)
273        end
274        for index = 4:6
275            set(handles.(ListOptions{index}),'value',1)
276        end
[855]277        set(handles.CheckCiv3,'Visible','on')% make visible the switch 'iterate/repet' for Civ2.
[1153]278        set(handles.CheckCiv3,'Value',1)% select'iterate/repet' by default
[774]279    end
[1153]280    checkrefresh=1;
281    %     end
282    % if ind_opening==6
283    %     set(handles.CheckCiv3,'Visible','on')% make visible the switch 'iterate/repet' for Civ2.
284    % else
285    %     set(handles.CheckCiv3,'Visible','off')
286    % end
[774]287end
288
[851]289%% introduce the stored Civ parameters  if available (from previous input or ImportConfig in series)
290if ~checkrefresh && isfield(Param,'ActionInput')&& strcmp(Param.ActionInput.Program,Param.Action.ActionName)% the program fits with the stored data
291    fill_GUI(Param.ActionInput,hObject);%fill the GUI with the parameters retrieved from the input Param
292    hcheckgrid=findobj(handles.civ_input,'Tag','CheckGrid');
293    for ilist=1:numel(hcheckgrid)
294        if get(hcheckgrid(ilist),'Value')% if a grid is used, do not show Dx and Dy for an automatic grid
295            hparent=get(hcheckgrid(ilist),'parent');%handles of the parent panel
296            hchildren=get(hparent,'children');
297            handle_dx=findobj(hchildren,'tag','num_Dx');
298            handle_dy=findobj(hchildren,'tag','num_Dy');
299            handle_title_dx=findobj(hchildren,'tag','title_Dx');
300            handle_title_dy=findobj(hchildren,'tag','title_Dy');
301            set(handle_dx,'Visible','off');
302            set(handle_dy,'Visible','off');
303            set(handle_title_dy,'Visible','off');
304            set(handle_title_dx,'Visible','off');
305        end
306    end
[885]307    if isfield(Param.ActionInput,'Civ2')
[1033]308        CheckDeformation_Callback(hObject, eventdata, handles)
[885]309    end
[851]310end
[1033]311if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'ListCompareMode')&&...
312        strcmp(Param.ActionInput.ListCompareMode,'displacement')
313    set(handles.PairIndices,'Visible','off')
314        set(handles.CheckRefFile,'Visible','on')
315else
316    set(handles.CheckRefFile,'Visible','off')
317end
[1020]318
[1148]319%% reinitialise pair menus
320set(handles.ListPairMode,'Value',1)
321set(handles.ListPairMode,'String',{''})
322set(handles.ListPairCiv1,'Value',1)
323set(handles.ListPairCiv1,'String',{''})
324set(handles.ListPairCiv2,'Value',1)
325set(handles.ListPairCiv2,'String',{''})
326
[918]327%% set the menu and default choice of civ pairs
[1148]328if isequal(MaxIndex_j,MinIndex_j)|| strcmp(Param.Action.ActionName,'civ_3D')% no possibility of j pairs
[1016]329    PairMenu={'series(Di)'};
[1141]330elseif MaxIndex_j-MinIndex_j==1
331    PairMenu={'pair j1-j2'};
332elseif  MaxIndex_i==MinIndex_i && MaxIndex_j-MinIndex_j>2% simple series in j
[1016]333    PairMenu={'pair j1-j2';'series(Dj)'};
[918]334else
[1016]335    PairMenu={'pair j1-j2';'series(Dj)';'series(Di)'};%multiple choice
[918]336end
[1016]337set(handles.ListPairMode,'String',PairMenu)
[918]338
[1016]339%% set default choice of pair mode
[1097]340PairIndex=[];
[1016]341if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'PairIndices')
[1097]342    PairIndex=find(strcmp(Param.ActionInput.PairIndices.ListPairMode,PairMenu));%retrieve the previous option
[1016]343end
[1148]344if strcmp(Param.Action.ActionName,'civ_3D')
[1156]345    PairIndex=1;
[1148]346else
347    if isempty(PairIndex)
348        if ~isfield(Param.IndexRange,'first_j')||isequal(MaxIndex_j,MinIndex_j)% no possibility of j pairs
349            PairIndex=1;
350        elseif  MaxIndex_i==1 && MaxIndex_j>1% simple series in j
351            if  MaxIndex_j <= 10
352                PairIndex=1;% advice 'pair j1-j2' except in MaxIndex_j is large
353            end
[1097]354        else
[1148]355            if strcmp(NomTypeNc,'_1-2_1')
356                PairIndex=3;% advise 'series(Di)'
357            elseif  MaxIndex_j <= 10
358                PairIndex=1;% advice 'pair j1-j2' except in MaxIndex_j is large
359            else
360                PairIndex=2;% advice 'Dj'
361            end
[1016]362        end
363    end
364end
[1148]365set(handles.ListPairMode,'Value',PairIndex);
[1016]366
[918]367%% indicate the min and max indices i and j on the GUI
368set(handles.MinIndex_i,'String',num2str(MinIndex_i))
369set(handles.MaxIndex_i,'String',num2str(MaxIndex_i))
370set(handles.MinIndex_j,'String',num2str(MinIndex_j))
371set(handles.MaxIndex_j,'String',num2str(MaxIndex_j))
372
[774]373%% set the reference indices from the input file indices
[852]374if ~(isfield(Param,'ActionInput') && isfield(Param.ActionInput,'ConfigSource'))
[774]375update_CivOptions(handles,ind_opening)% fill the menu of possible pairs
[851]376end
[774]377
378%% list the possible index pairs, depending on the option set in ListPairMode
379ListPairMode_Callback([], [], handles)
380
[599]381%% set the GUI to modal: wait for OK to close
[598]382set(handles.civ_input,'WindowStyle','modal')% Make the GUI modal
[597]383drawnow
[856]384uiwait(handles.civ_input);% wait for OK action to end the function
[597]385
[599]386
[597]387%------------------------------------------------------------------------
388% --- Outputs from this function are returned to the command line.
389function varargout = civ_input_OutputFcn(hObject, eventdata, handles)
390%------------------------------------------------------------------------
391% Get default command line output from handles structure
[668]392varargout{1}=[];% default output when civ_input is canceled (no 'OK')
393if ~isempty(handles)
394    varargout{1} = handles.output;
395    delete(handles.civ_input)
396end
[597]397
398% --- Executes when user attempts to close get_field.
[598]399function civ_input_CloseRequestFcn(hObject, eventdata, handles)
[597]400if isequal(get(handles.get_field, 'waitstatus'), 'waiting')
401    % The GUI is still in UIWAIT, us UIRESUME
[598]402    uiresume(handles.civ_input);
[597]403else
404    % The GUI is no longer waiting, just close it
[598]405    delete(handles.civ_input);
[597]406end
407
[851]408%------------------------------------------------------------------------
409% --- Executes on button press in SetDefaultParam.
410%------------------------------------------------------------------------
411function SetDefaultParam_Callback(hObject, eventdata, handles)
412
[856]413Param.ConfigSource='\default';
414
415%% Civ1 parameters
[874]416%Param.CheckCiv1=1;
[1148]417Param.Civ1.CorrBoxSize=[25 25 1];
418Param.Civ1.SearchBoxSize=[55 55 5];
[856]419Param.Civ1.SearchBoxShift=[0 0];
420Param.Civ1.CorrSmooth=1;
421Param.Civ1.Dx=20;
422Param.Civ1.Dy=20;
423Param.Civ1.CheckGrid=0;
424Param.Civ1.CheckMask=0;
[873]425Param.Civ1.Mask='';
[856]426Param.Civ1.CheckThreshold=0;
427Param.Civ1.TestCiv1=0;
428
429%% Fix1 parameters
430Param.Fix1.MinCorr=0.2000;
431
432%% Patch1 parameters
[874]433%Param.CheckPatch1=1;
[1148]434Param.Patch1.FieldSmooth=20;
435Param.Patch1.MaxDiff=2;
436Param.Patch1.SubDomainSize=125;
[856]437
438%% Civ2 parameters
[874]439%Param.CheckCiv2=1;
[856]440Param.Civ2.CorrBoxSize=[21 21];
[862]441Param.Civ2.SearchBoxSize=[27 27];
[856]442Param.Civ2.CorrSmooth=1;
443Param.Civ2.Dx=10;
444Param.Civ2.Dy=10;
445Param.Civ2.CheckGrid=0;
446Param.Civ2.CheckMask=0;
[873]447Param.Civ2.Mask='';
[856]448Param.Civ2.CheckThreshold=0;
449
450%% Fix2 parameters
451Param.Fix2.MinCorr=0.2000;
452
453%% Patch2 parameters
[1148]454Param.Patch2.FieldSmooth=5;
[856]455Param.Patch2.MaxDiff=1.5000;
[1148]456Param.Patch2.SubDomainSize=250;
[856]457Param.Patch2.TestPatch2=0;
458
459fill_GUI(Param,handles.civ_input)% fill the elements of the GUI series with the input parameters
[873]460update_CivOptions(handles,0)
[856]461
[597]462% -----------------------------------------------------------------------
463% -----------------------------------------------------------------------
464% --- Open the help html file
465function MenuHelp_Callback(hObject, eventdata, handles)
466% -----------------------------------------------------------------------
[774]467web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp#Civ')
[597]468
469%------------------------------------------------------------------------
470% --- Executes on carriage return on the subdir checkciv1 edit window
[604]471function Civ1_ImageB_Callback(hObject, eventdata, handles)
[597]472%------------------------------------------------------------------------
[604]473SubDir=get(handles.Civ1_ImageB,'String');
[597]474menu_str=get(handles.ListSubdirCiv1,'String');% read the list of subdirectories for update
475ichoice=find(strcmp(SubDir,menu_str),1);
476if isempty(ichoice)
477    ilist=numel(menu_str); %select 'new...' in the menu
478else
479    ilist=ichoice;
480end
481set(handles.ListSubdirCiv1,'Value',ilist)% select the selected subdir in the menu
482if get(handles.CheckCiv1,'Value')% if Civ1 is performed
[604]483    set(handles.Civ2_ImageA,'String',SubDir);% set by default civ2 directory the same as civ1
[597]484%     set(handles.ListSubdirCiv2,'Value',ilist)
485else % if Civ1 data already exist
[774]486    errormsg=find_netcpair_civ(handles,1); %update the list of available index pairs in the new directory
[597]487    if ~isempty(errormsg)
488    msgbox_uvmat('ERROR',errormsg)
489    end
490end
491
492%------------------------------------------------------------------------
493% --- Executes on carriage return on the SubDir checkciv1 edit window
[604]494function Civ2_ImageA_Callback(hObject, eventdata, handles)
[597]495%------------------------------------------------------------------------
[604]496SubDir=get(handles.Civ1_ImageB,'String');
[597]497menu_str=get(handles.ListSubdirCiv2,'String');% read the list of subdirectories for update
498ichoice=find(strcmp(SubDir,menu_str),1);
499if isempty(ichoice)
500    ilist=numel(menu_str); %select 'new...' in the menu
501else
502    ilist=ichoice;
503end
504set(handles.ListSubdirCiv2,'Value',ilist)% select the selected subdir in the menu
505%update the list of available pairs from netcdf files in the new directory
506if ~get(handles.CheckCiv2,'Value') && ~get(handles.CheckCiv1,'Value') && ~get(handles.CheckFix1,'Value') && ~get(handles.CheckPatch1,'Value')
507    errormsg=find_netcpair_civ(handles,2);
508        if ~isempty(errormsg)
509    msgbox_uvmat('ERROR',errormsg)
510    end
511end
512
513%------------------------------------------------------------------------
514% --- Executes on button press in CheckCiv1.
515function CheckCiv1_Callback(hObject, eventdata, handles)
516%------------------------------------------------------------------------
517update_CivOptions(handles,0)
518
519%------------------------------------------------------------------------
520% --- Executes on button press in CheckFix1.
521function CheckFix1_Callback(hObject, eventdata, handles)
522%------------------------------------------------------------------------
523update_CivOptions(handles,0)
524
525%------------------------------------------------------------------------
526% --- Executes on button press in CheckPatch1.
527function CheckPatch1_Callback(hObject, eventdata, handles)
528%------------------------------------------------------------------------
529update_CivOptions(handles,0)
530
531%------------------------------------------------------------------------
532% --- Executes on button press in CheckCiv2.
533function CheckCiv2_Callback(hObject, eventdata, handles)
534%------------------------------------------------------------------------
535update_CivOptions(handles,0)
536
537%------------------------------------------------------------------------
538% --- Executes on button press in CheckFix2.
539function CheckFix2_Callback(hObject, eventdata, handles)
540%------------------------------------------------------------------------
541update_CivOptions(handles,0)
542
543%------------------------------------------------------------------------
544% --- Executes on button press in CheckPatch2.
545function CheckPatch2_Callback(hObject, eventdata, handles)
546%------------------------------------------------------------------------
547update_CivOptions(handles,0)
548
549%------------------------------------------------------------------------
550% --- activated by any checkbox controling the selection of Civ1,Fix1,Patch1,Civ2,Fix2,Patch2
551function update_CivOptions(handles,opening)
552%------------------------------------------------------------------------
[851]553if opening>0
554    set(handles.CheckCiv2,'UserData',opening)% store the info on the current status of the civ processing
555end
[597]556checkbox=zeros(1,6);
557checkbox(1)=get(handles.CheckCiv1,'Value');
558checkbox(2)=get(handles.CheckFix1,'Value');
559checkbox(3)=get(handles.CheckPatch1,'Value');
560checkbox(4)=get(handles.CheckCiv2,'Value');
561checkbox(5)=get(handles.CheckFix2,'Value');
562checkbox(6)=get(handles.CheckPatch2,'Value');
563if opening==0
564    errormsg=find_netcpair_civ(handles,1); % select the available netcdf files
565    if ~isempty(errormsg)
566        msgbox_uvmat('ERROR',errormsg)
567    end
568end
[851]569if max(checkbox(4:6))>0% case of civ2 pair choice needed
[597]570    set(handles.TitlePairCiv2,'Visible','on')
571    set(handles.ListPairCiv2,'Visible','on')
572    if ~opening
573        errormsg=find_netcpair_civ(handles,2); % select the available netcdf files
574        if ~isempty(errormsg)
575            msgbox_uvmat('ERROR',errormsg)
576        end
577    end
578else
579    set(handles.ListPairCiv2,'Visible','off')
580end
[862]581hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
582hhseries=guidata(hseries); %handles of the elements in 'series'
583InputTable=get(hhseries.InputTable,'Data');
584if size(InputTable,1)>=1 && strcmp(InputTable{1,5},'.nc') && max(checkbox(1:3))==0 %&& get(handles.CheckCiv2,'UserData')==6,% no operation asked before Civ2 and input file ready for civ3
[855]585    set(handles.CheckCiv3,'Visible','on')
[851]586else
[855]587    set(handles.CheckCiv3,'Visible','off')
[851]588end
589
590%% set the visibility of the different panels
[597]591options={'Civ1','Fix1','Patch1','Civ2','Fix2','Patch2'};
592for ilist=1:length(options)
593    if checkbox(ilist)
594        set(handles.(options{ilist}),'Visible','on')
595    else
596        set(handles.(options{ilist}),'Visible','off')
597    end
598end
599
600%------------------------------------------------------------------------
601% --- Executes on button press in OK: processing on local computer
602function OK_Callback(hObject, eventdata, handles)
603%------------------------------------------------------------------------
604
[855]605ActionInput=read_GUI(handles.civ_input);% read the infos on the GUI civ_input
[851]606
[855]607%% correct input inconsistencies
[851]608if isfield(ActionInput,'Civ1')
609    checkeven=(mod(ActionInput.Civ1.CorrBoxSize,2)==0);
610    ActionInput.Civ1.CorrBoxSize(checkeven)=ActionInput.Civ1.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values
[1148]611    ActionInput.Civ1.SearchBoxSize(1:2)=max(ActionInput.Civ1.SearchBoxSize(1:2),ActionInput.Civ1.CorrBoxSize(1:2)+8);% insure that the search box size is large enough
[851]612    checkeven=(mod(ActionInput.Civ1.SearchBoxSize,2)==0);
613    ActionInput.Civ1.SearchBoxSize(checkeven)=ActionInput.Civ1.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
614end
615if isfield(ActionInput,'Civ2')
616    checkeven=(mod(ActionInput.Civ2.CorrBoxSize,2)==0);
617    ActionInput.Civ2.CorrBoxSize(checkeven)=ActionInput.Civ2.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values
[862]618    ActionInput.Civ2.SearchBoxSize=max(ActionInput.Civ2.SearchBoxSize,ActionInput.Civ2.CorrBoxSize+4);
[851]619    checkeven=(mod(ActionInput.Civ2.SearchBoxSize,2)==0);
620    ActionInput.Civ2.SearchBoxSize(checkeven)=ActionInput.Civ2.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
621end
622
[855]623%% correct mask or grid name for Windows system (replace '\' by '/')
624if isfield(ActionInput,'Civ1')
625    if isfield(ActionInput.Civ1,'Mask')
626        ActionInput.Civ1.Mask=regexprep(ActionInput.Civ1.Mask,'\','/');
[822]627    end
[855]628    if isfield(ActionInput.Civ1,'Grid')
629        ActionInput.Civ1.Grid=regexprep(ActionInput.Civ1.Grid,'\','/');
[822]630    end
631end
[855]632if isfield(ActionInput,'Civ2')
633    if isfield(ActionInput.Civ2,'Mask')
634        ActionInput.Civ2.Mask=regexprep(ActionInput.Civ2.Mask,'\','/');
[822]635    end
[855]636    if isfield(ActionInput.Civ2,'Grid')
637        ActionInput.Civ2.Grid=regexprep(ActionInput.Civ2.Grid,'\','/');
[822]638    end
639end
[855]640
641%% exit the GUI and close it
642handles.output.ActionInput=ActionInput;
[597]643guidata(hObject, handles);% Update handles structure
[598]644uiresume(handles.civ_input);
[597]645
646
647%------------------------------------------------------------------------
648% --- Executes on button press in ListCompareMode.
649function ListCompareMode_Callback(hObject, eventdata, handles)
650%------------------------------------------------------------------------
651ListCompareMode=get(handles.ListCompareMode,'String');
652option=ListCompareMode{get(handles.ListCompareMode,'Value')};
[645]653hseries=findobj(allchild(0),'Tag','series');
654SeriesData=get(hseries,'UserData');
655check_nc=strcmp(SeriesData.FileType{1},'.nc');
656ImageType=SeriesData.FileType(2:end);
657if check_nc
658    ImageType=SeriesData.FileType(2:end);
659else
660    ImageType=SeriesData.FileType;
661end
662hhseries=guidata(hseries);
663InputTable=get(hhseries.InputTable,'Data');
664OriginIndex='off';
665PairIndices='off';
[597]666switch option
667    case 'PIV'
[1020]668        PairIndices='on';% needs to define index pairs for PIV       
[1148]669    % case 'PIV volume'
670    %     PairIndices='on';% needs to define index pairs for PIV
671    %     set(handles.ListPairMode,'Value',1)
672    %     set(handles.ListPairMode,'String',{'series(Di)'})
673    %     ListPairMode_Callback(hObject, eventdata, handles)
[645]674    case 'displacement'
675        OriginIndex='on';%define a frame origin for displacement
[597]676end
[645]677set(handles.num_OriginIndex,'Visible',OriginIndex)
678set(handles.OriginIndex_title,'Visible',OriginIndex)
[1020]679set(handles.CheckRefFile,'Visible',OriginIndex)
680set(handles.RefFile,'Visible',OriginIndex)
[645]681set(handles.PairIndices,'Visible',PairIndices)
[1020]682ListPairMode_Callback(hObject,eventdata,handles)
683if strcmp(OriginIndex,'on')
684    set(handles.CheckRefFile,'Value',1)
685    CheckRefFile_Callback(hObject,eventdata,handles)
686end
[645]687       
[597]688
689
690%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691% Callbacks in the uipanel Pair Indices
692%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
693%------------------------------------------------------------------------
694% --- Executes on button press in ListPairMode.
695function ListPairMode_Callback(hObject, eventdata, handles)
696%------------------------------------------------------------------------
697compare_list=get(handles.ListCompareMode,'String');
698val=get(handles.ListCompareMode,'Value');
699compare=compare_list{val};
700if strcmp(compare,'displacement')||strcmp(compare,'shift')
[1020]701    mode_selected='displacement';
[597]702else
703    mode_list=get(handles.ListPairMode,'String');
704    if ischar(mode_list)
705        mode_list={mode_list};
[1018]706    end 
707    mode_value=get(handles.ListPairMode,'Value');
708    if isempty(mode_value)
709        mode_value=1;
[597]710    end
[1020]711    mode_selected=mode_list{mode_value};
[597]712end
713ref_i=str2double(get(handles.ref_i,'String'));
[599]714CivInputData=get(handles.civ_input,'UserData');
[597]715TimeUnit=get(handles.TimeUnit,'String');
716checkframe=strcmp(TimeUnit,'frame');
[599]717time=CivInputData.Time;
718siztime=size(CivInputData.Time);
[609]719nbfield=siztime(1)-1;
720nbfield2=siztime(2)-1;
[883]721%indchosen=1;  %%first pair selected by default
[597]722% in mode 'pair j1-j2', j1 and j2 are the file indices, else the indices
723% are relative to the reference indices ref_i and ref_j respectively.
[1020]724if isequal(mode_selected,'pair j1-j2')
[597]725    dt=1;
726    index=0;
727    numlist_a=[];
728    numlist_B=[];
729    %get all the time intervals in bursts
730    displ_dt=1;%default
731    nbfield2=min(nbfield2,10);%limitate the number of pairs to 10x10
732    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
733        for numod_b=(numod_a+1):nbfield2
734            index=index+1;
735            numlist_a(index)=numod_a;
736            numlist_b(index)=numod_b;
[932]737            if size(time,2)>1 && ~checkframe && size(CivInputData.Time,1)>ref_i && size(CivInputData.Time,2)>numod_b
[599]738                dt(numod_a,numod_b)=CivInputData.Time(ref_i+1,numod_b+1)-CivInputData.Time(ref_i+1,numod_a+1);%first time interval dt
[597]739                displ_dt(index)=dt(numod_a,numod_b);
740            else
741                displ_dt(index)=1;
742            end
743        end
744    end
745    [dtsort,indsort]=sort(displ_dt);
746    enable_j(handles, 'off')
[1020]747elseif isequal(mode_selected,'series(Dj)') %| isequal(mode,'st_series(Dj)')
[597]748    enable_j(handles, 'on')
[1020]749elseif isequal(mode_selected,'series(Di)') %| isequal(mode,'st_series(Di)')
[597]750    enable_i(handles, 'on')
751    if nbfield2 > 1
752        enable_j(handles, 'on')
753    else
754        enable_j(handles, 'off')
755    end
[1020]756elseif isequal(mode_selected,'displacement')%the pairs have the same indices
[597]757    if nbfield > 1 || nbfield==0
758        enable_i(handles, 'on')
759    else
760        enable_j(handles, 'off')
761    end
762    if nbfield2 > 1
763        enable_j(handles, 'on')
764    else
765        enable_j(handles, 'off')
766    end
767end
768errormsg=find_netcpair_civ( handles,1);
[1033]769if ~isempty(errormsg)
[597]770    msgbox_uvmat('ERROR',errormsg)
[1033]771end
[597]772
[1033]773%------------------------------------------------------------------------
[597]774function enable_i(handles, state)
775set(handles.itext,'Visible',state)
[645]776set(handles.MaxIndex_i,'Visible',state)
[597]777set(handles.ref_i,'Visible',state)
778
[1033]779%------------------------------------------------------------------------
[597]780function enable_j(handles, state)
781set(handles.jtext,'Visible',state)
[645]782set(handles.MinIndex_j,'Visible',state)
783set(handles.MaxIndex_j,'Visible',state)
[597]784set(handles.ref_j,'Visible',state)
785
786%------------------------------------------------------------------------
787% --- Executes on selection change in ListPairCiv1.
788function ListPairCiv1_Callback(hObject, eventdata, handles)
789%------------------------------------------------------------------------
790%reproduce by default the chosen pair in the checkciv2 menu
[1156]791set(handles.ListPairCiv2,'Value',get(handles.ListPairCiv1,'Value'))%civ2 selection the same as civ1 by default
792ListPairCiv2_Callback(hObject, eventdata, handles)
[597]793
794%------------------------------------------------------------------------
795% --- Executes on selection change in ListPairCiv2.
796function ListPairCiv2_Callback(hObject, eventdata, handles)
797%------------------------------------------------------------------------
798
799%------------------------------------------------------------------------
800function ref_i_Callback(hObject, eventdata, handles)
801%------------------------------------------------------------------------
802mode_list=get(handles.ListPairMode,'String');
803mode_value=get(handles.ListPairMode,'Value');
[1020]804mode_selected=mode_list{mode_value};
[597]805errormsg=find_netcpair_civ(handles,1);% update the menu of pairs depending on the available netcdf files
[1020]806if isequal(mode_selected,'series(Di)') || ...% we do patch2 only
[597]807        (get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0)
808    errormsg=find_netcpair_civ( handles,2);
809end
[851]810if isempty(errormsg)
811    set(handles.ref_i,'BackgroundColor',[1 1 1])
[856]812    set(handles.ref_j,'BackgroundColor',[1 1 1])
[851]813else
[597]814    msgbox_uvmat('ERROR',errormsg)
815end
816
[851]817function ref_i_KeyPressFcn(hObject, eventdata, handles)
818set(hObject,'BackgroundColor',[1 0 1])
819       
820% %------------------------------------------------------------------------
[1020]821
[597]822function errormsg=find_netcpair_civ(handles,index)
823%------------------------------------------------------------------------
824set(gcf,'Pointer','watch')% set the mouse pointer to 'watch' (clock)
825
826%% initialisation
827errormsg='';
[603]828CivInputData=get(handles.civ_input,'UserData');
[597]829compare_list=get(handles.ListCompareMode,'String');
830val=get(handles.ListCompareMode,'Value');
831compare=compare_list{val};
[1020]832mode_selected='displacement';
[880]833if ~strcmp(compare,'displacement')%||strcmp(compare,'shift')
834 
[597]835    mode_list=get(handles.ListPairMode,'String');
836    mode_value=get(handles.ListPairMode,'Value');
[1018]837    if isempty(mode_value)
838        mode_value=1;
839    end
[597]840    if isempty(mode_list)
841        return
842    end
[1020]843    mode_selected=mode_list{mode_value};
[597]844end
[603]845nom_type_ima=CivInputData.NomTypeIma;
[881]846menu_pair=get(handles.ListPairCiv1,'String');%previous menu of ListPairCiv1
847PairCiv1Init=menu_pair{get(handles.ListPairCiv1,'Value')};%previous choice of pair
848menu_pair=get(handles.ListPairCiv2,'String');%previous menu of ListPairCiv1
849PairCiv2Init=menu_pair{get(handles.ListPairCiv2,'Value')};%previous choice of pair
[597]850
851%% reads .nc subdirectoy and image numbers from the interface
[637]852%SubDirImages=get(handles.Civ1_ImageA,'String');
[609]853%TODO: determine
[637]854%subdir_civ1=[SubDirImages get(handles.Civ1_ImageB,'String')];%subdirectory subdir_civ1 for the netcdf data
855%subdir_civ2=[SubDirImages get(handles.Civ2_ImageA,'String')];%subdirectory subdir_civ2 for the netcdf data
[597]856ref_i=str2double(get(handles.ref_i,'String'));
857ref_j=[];
[1020]858if isequal(mode_selected,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
[597]859    ref_j=0;
860elseif strcmp(get(handles.ref_j,'Visible'),'on')
861    ref_j=str2double(get(handles.ref_j,'String'));
862end
863if isempty(ref_j)
864    ref_j=1;
865end
[609]866CivInputData=get(handles.civ_input,'UserData');
[597]867TimeUnit=get(handles.TimeUnit,'String');
[633]868Time=CivInputData.Time;
[597]869checkframe=strcmp(TimeUnit,'frame');
870
871%% case with no Civ1 operation, netcdf files need to exist for reading
872displ_pair={''};
[609]873nbpair=200;%default
[597]874select=ones(size(1:nbpair));%flag for displayed pairs =1 for display
875
876%% determine the menu display in .ListPairCiv1
[1020]877switch mode_selected
[774]878    case 'series(Di)'
[597]879        for ipair=1:nbpair
880            if select(ipair)
881                displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2))];
[883]882                displ_pair_dt{ipair}=displ_pair{ipair};
[774]883                if ~checkframe
884                    if size(Time,1)>=ref_i+1+ceil(ipair/2) && size(Time,2)>=ref_j+1&& ref_i-floor(ipair/2)>=0 && ref_j>=0
885                        dt=Time(ref_i+1+ceil(ipair/2),ref_j+1)-Time(ref_i+1-floor(ipair/2),ref_j+1);%Time interval dtref_j+1
[883]886                        displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(dt*1000)];
[774]887                    end
[597]888                else
[635]889                    dt=ipair/1000;
[883]890                    displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(ipair)];
[774]891                end
[597]892            else
[883]893                displ_pair{ipair}='...';
894                displ_pair_dt{ipair}='...'; %pair not displayed in the menu
[597]895            end
896        end
[774]897    case 'series(Dj)'
[597]898        for ipair=1:nbpair
899            if select(ipair)
900                displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2))];
[883]901                displ_pair_dt{ipair}=displ_pair{ipair};
[774]902                if ~checkframe
903                    if size(Time,2)>=ref_j+1+ceil(ipair/2) && size(Time,1)>=ref_i+1 && ref_j-floor(ipair/2)>=0 && ref_i>=0
904                        dt=Time(ref_i+1,ref_j+1+ceil(ipair/2))-Time(ref_i+1,ref_j+1-floor(ipair/2));%Time interval dtref_j+1
[883]905                        displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(dt*1000)];
[774]906                    end
[635]907                else
908                    dt=ipair/1000;
[883]909                    displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(dt*1000)];
[774]910                end
[597]911            else
912                displ_pair{ipair}='...'; %pair not displayed in the menu
[883]913                displ_pair_dt{ipair}='...'; %pair not displayed in the menu
[597]914            end
915        end
[774]916    case 'pair j1-j2'%case of pairs
[776]917        MinIndex_j=str2num(get(handles.MinIndex_j,'String'));
918        MaxIndex_j=str2num(get(handles.MaxIndex_j,'String'));
[774]919        index_pair=0;
920        %get all the Time intervals in bursts
[918]921        displ_pair_dt='';
[774]922        for numod_a=MinIndex_j:MaxIndex_j-1 %nbfield2 always >=2 for 'pair j1-j2' mode
923            for numod_b=(numod_a+1):MaxIndex_j
924                index_pair=index_pair+1;
925                displ_pair{index_pair}=['j= ' num2stra(numod_a,nom_type_ima) '-' num2stra(numod_b,nom_type_ima)];
[884]926                displ_pair_dt{index_pair}=displ_pair{index_pair};
[774]927                dt(index_pair)=numod_b-numod_a;%default dt
928                if size(Time,1)>ref_i && size(Time,2)>numod_b  % && ~checkframe
929                    dt(index_pair)=Time(ref_i+1,numod_b+1)-Time(ref_i+1,numod_a+1);% Time interval dt
[883]930                    displ_pair_dt{index_pair}=[displ_pair_dt{index_pair} ' :dt= ' num2str(dt(index_pair)*1000)];
[774]931                end
[597]932            end
[774]933           
[597]934        end
[918]935        if index_pair ~=0
[774]936        [tild,indsort]=sort(dt);
937        displ_pair=displ_pair(indsort);
[883]938        displ_pair_dt=displ_pair_dt(indsort);
[918]939        end
[774]940    case 'displacement'
[1033]941%         displ_pair={'Di=Dj=0'};
942%         displ_pair_dt={'Di=Dj=0'};
943        set(handles.PairIndices,'Visible','off')
[597]944end
[1033]945if index==1 && ~strcmp(mode_selected,'displacement')
[883]946    set(handles.ListPairCiv1,'String',displ_pair_dt');
[597]947end
948
[758]949%% determine the default selection in the pair menu for Civ1
[881]950%ichoice=find(select,1);% index of first selected pair
951%if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
[883]952end_pair=regexp(PairCiv1Init,' :dt=');
953if ~isempty(end_pair)
954    PairCiv1Init=PairCiv1Init(1:end_pair-1);
955end
[881]956ichoice=find(strcmp(PairCiv1Init,displ_pair'),1);
[880]957if ~isempty(ichoice)
[597]958    set(handles.ListPairCiv1,'Value',ichoice);% first valid pair proposed by default in the menu
[880]959else
960   set(handles.ListPairCiv1,'Value',1)
[597]961end
[758]962
963%% determine the default selection in the pair menu for Civ2
[1033]964if ~strcmp(mode_selected,'displacement')
[758]965if strcmp(get(handles.ListPairCiv2,'Visible'),'on')
[883]966    end_pair=regexp(PairCiv2Init,' :dt=');
967    if ~isempty(end_pair)
968        PairCiv2Init=PairCiv2Init(1:end_pair-1);
969    end
[881]970    ichoice=find(strcmp(PairCiv2Init,displ_pair'),1);
971    if ~isempty(ichoice)
972        set(handles.ListPairCiv2,'Value',ichoice);% first valid pair proposed by default in the menu
973    else
974        set(handles.ListPairCiv2,'Value',1)
[597]975    end
[758]976else
977    set(handles.ListPairCiv2,'Value',get(handles.ListPairCiv1,'Value'))% initiate the choice of Civ2 as a reproduction of if civ1
[597]978end
[883]979set(handles.ListPairCiv2,'String',displ_pair_dt');
[1033]980end
[758]981set(gcf,'Pointer','arrow')% Indicate that the process is finished
[597]982
983
984%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
985% Callbacks in the uipanel Reference Indices
986%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
987%------------------------------------------------------------------------
[645]988function MinIndex_i_Callback(hObject, eventdata, handles)
[597]989%------------------------------------------------------------------------
[645]990first_i=str2double(get(handles.MinIndex_i,'String'));
[597]991set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
992ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
993
[776]994% %------------------------------------------------------------------------
995% function MinIndex_j_Callback(hObject, eventdata, handles)
996% %------------------------------------------------------------------------
997% first_j=str2num(get(handles.MinIndex_j,'String'));
998% set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
999% ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[597]1000
1001%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1002% Callbacks in the uipanel Civ1
1003%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1004%------------------------------------------------------------------------
1005% --- Executes on button press in SearchRange: determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2
1006function SearchRange_Callback(hObject, eventdata, handles)
1007%------------------------------------------------------------------------
1008%determine pair numbers
1009if strcmp(get(handles.num_UMin,'Visible'),'off')
1010    set(handles.u_title,'Visible','on')
1011    set(handles.v_title,'Visible','on')
1012    set(handles.num_UMin,'Visible','on')
1013    set(handles.num_UMax,'Visible','on')
1014    set(handles.num_VMin,'Visible','on')
1015    set(handles.num_VMax,'Visible','on')
[854]1016    %set(handles.CoordUnit,'Visible','on')
1017    %set(handles.TimeUnit,'Visible','on')
1018    %set(handles.slash_title,'Visible','on')
[597]1019    set(handles.min_title,'Visible','on')
1020    set(handles.max_title,'Visible','on')
1021    set(handles.unit_title,'Visible','on')
1022else
1023    get_search_range(hObject, eventdata, handles)
1024end
1025
1026%------------------------------------------------------------------------
1027% ---  determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2 and shift
1028function get_search_range(hObject, eventdata, handles)
1029%------------------------------------------------------------------------
1030param_civ1=read_GUI(handles.Civ1);
1031umin=param_civ1.UMin;
1032umax=param_civ1.UMax;
1033vmin=param_civ1.VMin;
1034vmax=param_civ1.VMax;
1035%switch min_title and max_title in case of error
1036if umax<=umin
1037    umin_old=umin;
1038    umin=umax;
1039    umax=umin_old;
1040    set(handles.num_UMin,'String', num2str(umin))
1041    set(handles.num_UMax,'String', num2str(umax))
1042end
1043if vmax<=vmin
1044    vmin_old=vmin;
1045    vmin=vmax;
1046    vmax=vmin_old;
1047    set(handles.num_VMin,'String', num2str(vmin))
1048    set(handles.num_VMax,'String', num2str(vmax))
1049end   
1050if ~(isempty(umin)||isempty(umax)||isempty(vmin)||isempty(vmax))
1051    shiftx=round((umin+umax)/2);
1052    shifty=round((vmin+vmax)/2);
[854]1053    isx=(umax+2-shiftx)*2+param_civ1.CorrBoxSize(1);
[597]1054    isx=2*ceil(isx/2)+1;
[854]1055    isy=(vmax+2-shifty)*2+param_civ1.CorrBoxSize(2);
[597]1056    isy=2*ceil(isy/2)+1;
1057    set(handles.num_SearchBoxShift_1,'String',num2str(shiftx));
1058    set(handles.num_SearchBoxShift_2,'String',num2str(shifty));
1059    set(handles.num_SearchBoxSize_1,'String',num2str(isx));
1060    set(handles.num_SearchBoxSize_2,'String',num2str(isy));
1061end
1062
[851]1063%------------------------------------------------------------------------
[856]1064% --- Executes on selection in menu CorrSmooth.
[851]1065function num_CorrSmooth_Callback(hObject, eventdata, handles)
[873]1066set(handles.ConfigSource,'String','NEW')
[856]1067set(handles.OK,'BackgroundColor',[1 0 1])
[851]1068%------------------------------------------------------------------------
1069
[859]1070% --- Executes on button press in CheckDeformation.
1071function CheckDeformation_Callback(hObject, eventdata, handles)
[862]1072set(handles.ConfigSource,'String','NEW')
[859]1073set(handles.OK,'BackgroundColor',[1 0 1])
[885]1074handles_CoorSmooth=findobj(get(handles.Civ2,'children'),'Tag','num_CorrSmooth');
1075if get(handles.CheckDeformation,'Value')   
1076    set(handles_CoorSmooth,'Visible','off')
[883]1077else
[885]1078    set(handles_CoorSmooth,'Visible','on')
[883]1079end
[859]1080
[597]1081%------------------------------------------------------------------------
1082% --- function called to look for grid files
1083function [nbslice, flag_grid]=get_grid(filebase,handles)
1084%------------------------------------------------------------------------
1085flag_grid=0;%default
1086nbslice=1;
1087[Path,Name]=fileparts(filebase);
1088currentdir=pwd;
1089cd(Path);%move in the dir of the root name filebase
1090gridfiles=dir([Name '_*grid_*.grid']);%look for grid files
1091cd(currentdir);%come back to the current working directory
1092if ~isempty(gridfiles)
1093    flag_grid=1;
1094    gridname=gridfiles(1).name;% take the first grid file in the list
1095    [Path2,Name,ext]=fileparts(gridname);
1096    Namedouble=double(Name);
1097    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1098    ind_grid=findstr('grid',Name);
1099    i=ind_grid-1;
1100    while val(i)==0 && i>0
1101        i=i-1;
1102    end
1103    nbslice=str2double(Name(i+1:ind_grid-1));
1104    if ~isnan(nbslice) && Name(i)=='_'
1105        flag_grid=1;
1106    else
1107        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
1108        return
1109        nbslice=1;
1110    end
1111end
1112
1113%------------------------------------------------------------------------
1114% --- transform numbers to letters
1115function str=num2stra(num,nom_type)
1116%------------------------------------------------------------------------
1117if isempty(nom_type)
1118    str='';
1119elseif strcmp(nom_type(end),'a')
1120    str=char(96+num);
1121elseif strcmp(nom_type(end),'A')
1122    str=char(96+num);
1123elseif isempty(nom_type(2:end))%a single index
1124    str='';
1125else
1126    str=num2str(num);
1127end
1128
1129% %------------------------------------------------------------------------
1130% % --- Executes on button press in ListSubdirCiv1.
1131% function ListSubdirCiv1_Callback(hObject, eventdata, handles)
1132% %------------------------------------------------------------------------
1133% list_subdir_civ1=get(handles.ListSubdirCiv1,'String');
1134% val=get(handles.ListSubdirCiv1,'Value');
1135% SubDir=list_subdir_civ1{val};
1136% if strcmp(SubDir,'new...')
1137%     if get(handles.CheckCiv1,'Value')
1138%         SubDir='CIV_INPUT'; %default subdirectory
1139%     else
1140%         msgbox_uvmat('ERROR','select CheckCiv1 to perform a new civ_input operation')
1141%         return
1142%     end   
1143% end
[604]1144% set(handles.Civ1_ImageB,'String',SubDir);
[597]1145% errormsg=find_netcpair_civ(handles,1);
1146% if ~isempty(errormsg)
1147%     msgbox_uvmat('ERROR',errormsg)
1148% end
1149%     
1150%------------------------------------------------------------------------
1151% % --- Executes on button press in ListSubdirCiv2.
1152% function ListSubdirCiv2_Callback(hObject, eventdata, handles)
1153% %------------------------------------------------------------------------
1154% list_subdir_civ2=get(handles.ListSubdirCiv2,'String');
1155% val=get(handles.ListSubdirCiv2,'Value');
1156% SubDir=list_subdir_civ2{val};
1157% if strcmp(SubDir,'new...')
1158%     if get(handles.CheckCiv2,'Value')
1159%         SubDir='CIV_INPUT'; %default subdirectory
1160%     else
1161%         msgbox_uvmat('ERROR','select CheckCiv2 to perform a new civ_input operation')
1162%         return
1163%     end
1164% end
[604]1165% set(handles.Civ2_ImageA,'String',SubDir);
[597]1166
1167%------------------------------------------------------------------------
1168% --- Executes on button press in CheckGrid.
1169function CheckGrid_Callback(hObject, eventdata, handles)
1170%------------------------------------------------------------------------
1171value=get(hObject,'Value');
1172hparent=get(hObject,'parent');%handles of the parent panel
1173hchildren=get(hparent,'children');
1174handle_txtbox=findobj(hchildren,'tag','Grid');% look for the grid name box in the same panel
1175handle_dx=findobj(hchildren,'tag','num_Dx');
1176handle_dy=findobj(hchildren,'tag','num_Dy');
1177handle_title_dx=findobj(hchildren,'tag','title_Dx');
1178handle_title_dy=findobj(hchildren,'tag','title_Dy');
1179testgrid=0;
1180filegrid='';
1181if value
[665]1182        hseries=findobj(allchild(0),'Tag','series');
1183    hhseries=guidata(hseries);
1184    InputTable=get(hhseries.InputTable,'Data');
1185     ind_A=1;% line index of the (first) image series
1186    if strcmp(InputTable{1,5},'.nc');
1187        ind_A=2;
1188    end
1189    filebase=InputTable{ind_A,1};
[597]1190    [nbslice, flag_grid]=get_grid(filebase,handles);% look for a grid with appropriate name
1191    if isequal(flag_grid,1)
1192        filegrid=[num2str(nbslice) 'grid'];
1193        testgrid=1;
1194    else % browse for a grid
1195        filegrid=get(hObject,'UserData');%look for previous grid name stored as UserData
1196        if exist(filegrid,'file')
1197            filebase=filegrid;
1198        end
[665]1199       filegrid = uigetfile_uvmat('pick a grid file .grid:',filebase,'.grid');
[597]1200        set(hObject,'UserData',filegrid);%store for future use
[665]1201        if ~isempty(filegrid)
[597]1202            testgrid=1;
[665]1203        end
1204        set(hObject,'UserData',filegrid);%store for future use
[597]1205    end
1206end
1207if testgrid
1208    set(handle_dx,'Visible','off');
1209    set(handle_dy,'Visible','off');
1210    set(handle_title_dy,'Visible','off');
1211    set(handle_title_dx,'Visible','off');
1212    set(handle_txtbox,'Visible','on')
1213    set(handle_txtbox,'String',filegrid)
1214else
1215    set(hObject,'Value',0);
1216    set(handle_dx,'Visible','on');
1217    set(handle_dy,'Visible','on');
1218    set(handle_title_dy,'Visible','on');
1219    set(handle_title_dx,'Visible','on');
1220    set(handle_txtbox,'Visible','off')
1221end
1222
1223%% if hObject is on the checkciv1 frame, duplicate action for checkciv2 frame
1224PanelName=get(hparent,'tag');
1225if strcmp(PanelName,'Civ1')
1226    hchildren=get(handles.Civ2,'children');
1227    handle_checkbox=findobj(hchildren,'tag','CheckGrid');
1228    handle_txtbox=findobj(hchildren,'tag','Grid');
1229    handle_dx=findobj(hchildren,'tag','num_Dx');
1230    handle_dy=findobj(hchildren,'tag','num_Dy');
1231    handle_title_dx=findobj(hchildren,'tag','title_Dx');
1232    handle_title_dy=findobj(hchildren,'tag','title_Dy');
1233    set(handle_checkbox,'UserData',filegrid);%store for future use
1234    if testgrid
1235        set(handle_checkbox,'Value',1);
1236        set(handle_dx,'Visible','off');
1237        set(handle_dy,'Visible','off');
1238        set(handle_title_dx,'Visible','off');
1239        set(handle_title_dy,'Visible','off');
1240        set(handle_txtbox,'Visible','on')
1241        set(handle_txtbox,'String',filegrid)
1242    end
1243end
[873]1244set(handles.ConfigSource,'String','NEW')
[856]1245set(handles.OK,'BackgroundColor',[1 0 1])
[918]1246
[597]1247%------------------------------------------------------------------------
1248% --- Executes on button press in CheckMask: common to all panels (civ1, Civ2..)
1249function CheckMask_Callback(hObject, eventdata, handles)
1250%------------------------------------------------------------------------
1251hparent=get(hObject,'parent');
1252hchildren=get(hparent,'children');
1253handle_txtbox=findobj(hchildren,'tag','Mask');% look for the mask name box in the same panel
[1153]1254% handle_NbSlice=findobj(hchildren,'tag','num_NbSlice');% look for the mask name box in the same panel
[597]1255testmask=0;
[1153]1256if get(hObject,'Value')% if the checkbox is activated
[665]1257    hseries=findobj(allchild(0),'Tag','series');
1258    hhseries=guidata(hseries);
1259    InputTable=get(hhseries.InputTable,'Data');
[1153]1260    if strcmp(InputTable{1,5},'.nc')
1261        ind_A=2;%case of nc file as input (for civ3), image in second line
1262    else
1263        ind_A=1;% line index of the (first) image series
[665]1264    end
[1153]1265    % browse for a mask
1266    filemask= uigetfile_uvmat('pick a mask image file:',InputTable{ind_A,1},'image');
1267    if ~isempty(filemask)
1268        [FilePath,FileName,FileExt]=fileparts(filemask);
1269        [RootPath,SubDir,RootFile,i1_series,i2,j1,j2,NomType]=find_file_series(FilePath,[FileName FileExt]);
[1010]1270        if strcmp(NomType,'_1')
[1153]1271            NbSlice=i1_series(1,2,end);
1272            set(handles.num_NbSlice,'String',num2str(NbSlice))
1273        elseif ~strcmp(NomType,'*')
1274            msgbox_uvmat('ERROR','multilevel masks must be labeled with a single index as _1,_2,...');
1275            return
[1010]1276        end
[597]1277        set(hObject,'UserData',filemask);%store for future use
[1153]1278        testmask=1;
1279    end
[597]1280end
1281if testmask
[851]1282    set(handles.Mask,'Visible','on')
1283    set(handles.Mask,'String',filemask)
[597]1284    set(handles.CheckMask,'Value',1)
[1010]1285    if strcmp(NomType,'_1')
1286        set(handles.num_NbSlice,'Visible','on')
1287    end
[597]1288else
1289    set(hObject,'Value',0);
1290    set(handle_txtbox,'Visible','off')
[1010]1291    set(handles.num_NbSlice,'Visible','off')
[597]1292end
[873]1293set(handles.ConfigSource,'String','NEW')
1294set(handles.ConfigSource,'BackgroundColor',[1 0 1])
[597]1295
[851]1296% %------------------------------------------------------------------------
1297% % --- Executes on button press in get_gridpatch1.
1298% function get_gridpatch1_Callback(hObject, eventdata, handles)
1299% %------------------------------------------------------------------------
1300% filebase=get(handles.RootPath,'String');
1301% [FileName, PathName, filterindex] = uigetfile( ...
1302%     {'*.grid', ' (*.grid)';
1303%     '*.grid',  '.grid files '; ...
1304%     '*.*', 'All Files (*.*)'}, ...
1305%     'Pick a file',filebase);
1306% filegrid=fullfile(PathName,FileName);
1307% set(handles.grid_patch1,'string',filegrid);
1308% set(hObject,'BackgroundColor',[1 0 1])
[597]1309
1310%------------------------------------------------------------------------
1311% --- STEREO Interp
1312function cmd=RUN_STINTERP(stinterpBin,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
1313%------------------------------------------------------------------------
1314namelog=[filename_nc(1:end-3) '_stinterp.log'];
1315cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
1316    ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ' -c1 ' xmlA ' -c2 ' xmlB '  -xy  x -Nfy 1024 > ' namelog ' 2>&1']; % redirect standard output to the log file
1317
1318% %------------------------------------------------------------------------
1319% %--read images and convert them to the uint16 format used for PIV
1320% function A=read_image(filename,type_ima,num,movieobject)
1321% %------------------------------------------------------------------------
1322% %num is the view number needed for an avi movie
1323% switch type_ima
1324%     case 'movie'
1325%         A=read(movieobject,num);
1326%     case 'avi'
1327%         mov=aviread(filename,num);
1328%         A=frame2im(mov(1));
1329%     case 'multimage'
1330%         A=imread(filename,num);
1331%     case 'image'
1332%         A=imread(filename);
1333% end
1334% siz=size(A);
1335% if length(siz)==3;%color images
1336%     A=sum(double(A),3);
1337%     A=uint16(A);
1338% end
1339
1340
1341%------------------------------------------------------------------------
1342% --- Executes on button press in get_ref_fix1.
1343function get_ref_fix1_Callback(hObject, eventdata, handles)
1344%------------------------------------------------------------------------
1345filebase=get(handles.RootPath,'String');
1346[FileName, PathName, filterindex] = uigetfile( ...
1347    {'*.nc', ' (*.nc)';
1348    '*.nc',  'netcdf files '; ...
1349    '*.*', 'All Files (*.*)'}, ...
1350    'Pick a file',filebase);
1351
1352fileinput=[PathName FileName];
1353sizf=size(fileinput);
1354if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1355%[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1356[Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1357ref.filebase=fullfile(Path,File);
1358% ref.num_a=stra2num(str_a);
1359% ref.num_b=stra2num(str_b);
1360% ref.num1=str2double(field_count);
1361% ref.num2=str2double(str2);
1362browse=[];%initialisation
1363if ~isequal(ref.ext,'.nc')
1364    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1365    return
1366end
1367set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
1368set(handles.ref_fix1,'UserData',ref)
1369menu_field{1}='civ1';
1370Data=nc2struct(fileinput,[]);
1371if isfield(Data,'patch') && isequal(Data.patch,1)
1372    menu_field{2}='filter1';
1373end
1374if isfield(Data,'civ2') && isequal(Data.civ2,1)
1375    menu_field{3}='civ2';
1376end
1377if isfield(Data,'patch2') && isequal(Data.patch2,1)
1378    menu_field{4}='filter2';
1379end
1380set(handles.field_ref1,'String',menu_field);
1381set(handles.field_ref1,'Value',length(menu_field));
1382set(handles.num_MinVel,'Value',2);
1383set(handles.num_MinVel,'String','1');%default threshold
1384set(handles.ref_fix1,'Enable','on')
1385
1386%------------------------------------------------------------------------
1387% --- Executes on button press in get_ref_fix2.
1388function get_ref_fix2_Callback(hObject, eventdata, handles)
1389%------------------------------------------------------------------------
1390if isequal(get(handles.get_ref_fix2,'Value'),1)
1391    filebase=get(handles.RootPath,'String');
1392    [FileName, PathName, filterindex] = uigetfile( ...
1393        {'*.nc', ' (*.nc)';
1394        '*.nc',  'netcdf files '; ...
1395        '*.*', 'All Files (*.*)'}, ...
1396        'Pick a file',filebase);
1397    fileinput=[PathName FileName];
1398    sizf=size(fileinput);
1399    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1400    %[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1401    [Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1402    ref.filebase=fullfile(Path,File);
[692]1403    %     ref.num_a=stra2num(str_a);
1404    %     ref.num_b=stra2num(str_b);
1405    %     ref.num1=str2num(field_count);
1406    %     ref.num2=str2num(str2);
[597]1407    browse=[];%initialisation
1408    if ~isequal(ref.ext,'.nc')
1409        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1410        return
1411    end
1412    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
1413    set(handles.ref_fix2,'UserData',ref)
1414    menu_field{1}='civ1';
1415    Data=nc2struct(fileinput,[]);
1416    if isfield(Data,'patch') && isequal(Data.patch,1)
1417        menu_field{2}='filter1';
1418    end
1419    if isfield(Data,'civ2') && isequal(Data.civ2,1)
1420        menu_field{3}='civ2';
1421    end
1422    if isfield(Data,'patch2') && isequal(Data.patch2,1)
1423        menu_field{4}='filter2';
1424    end
1425    set(handles.field_ref2,'String',menu_field);
1426    set(handles.field_ref2,'Value',length(menu_field));
1427    set(handles.num_MinVel,'Value',2);
1428    set(handles.num_MinVel,'String','1');%default threshold
1429    set(handles.ref_fix2,'Enable','on')
1430    set(handles.ref_fix2,'Visible','on')
1431    set(handles.field_ref2,'Visible','on')
1432else
1433    set(handles.ref_fix2,'Visible','off')
1434    set(handles.field_ref2,'Visible','off')
1435end
1436
1437%------------------------------------------------------------------------
1438function ref_fix1_Callback(hObject, eventdata, handles)
1439%------------------------------------------------------------------------
1440set(handles.num_MinVel,'Value',1);
1441set(handles.field_ref1,'Value',1)
1442set(handles.field_ref1,'String',{' '})
1443set(handles.ref_fix1,'UserData',[]);
1444set(handles.ref_fix1,'String','');
1445set(handles.thresh_vel1,'String','0');
1446
1447%------------------------------------------------------------------------
1448function ref_fix2_Callback(hObject, eventdata, handles)
1449%------------------------------------------------------------------------
1450set(handles.num_MinVel,'Value',1);
1451set(handles.field_ref2,'Value',1)
1452set(handles.field_ref2,'String',{' '})
1453set(handles.ref_fix2,'UserData',[]);
1454set(handles.ref_fix2,'String','');
1455set(handles.num_MinVel,'String','0');
1456
1457%------------------------------------------------------------------------
1458% --- TO ABANDON Executes on button press in test_stereo1.
1459function CheckStereo_Callback(hObject, eventdata, handles)
1460%------------------------------------------------------------------------
1461hparent=get(hObject,'parent');
1462parent_tag=get(hparent,'Tag');
1463hchildren=get(hparent,'children');
1464handle_txtbox=findobj(hchildren,'tag','txt_Mask');
1465if isequal(get(hObject,'Value'),0)
1466    set(handles.num_SubDomainSize,'Visible','on')
1467    set(handles.num_FieldSmooth,'Visible','on')
1468else
1469    set(handles.num_SubDomainSize,'Visible','off')
1470    set(handles.num_FieldSmooth,'Visible','off')
1471end
1472
1473% %------------------------------------------------------------------------
1474% % --- Executes on button press in CheckStereo.
1475% function StereoCheck_Callback(hObject, eventdata, handles)
1476% %------------------------------------------------------------------------
1477% if isequal(get(handles.CheckStereo,'Value'),0)
1478%     set(handles.num_subdomainsize,'Visible','on')
1479%     set(handles.num_FieldSmooth,'Visible','on')
1480% else
[651]1481
[597]1482%     set(handles.num_subdomainsize,'Visible','off')
1483%     set(handles.num_FieldSmooth,'Visible','off')
1484% end
1485
[774]1486
1487
1488%------------------------------------------------------------------------
1489%----function introduced for the correlation window figure, activated by deleting this window
1490function closeview_field(gcbo,eventdata)
[597]1491%------------------------------------------------------------------------
[774]1492hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1493if ~isempty(hview_field)
1494    delete(hview_field)
1495end
1496
1497%------------------------------------------------------------------------
1498% --- Executes on button press in CheckThreshold.
1499function CheckThreshold_Callback(hObject, eventdata, handles)
1500%------------------------------------------------------------------------
1501huipanel=get(hObject,'parent');
1502obj(1)=findobj(huipanel,'Tag','num_MinIma');
1503obj(2)=findobj(huipanel,'Tag','num_MaxIma');
1504obj(3)=findobj(huipanel,'Tag','title_Threshold');
1505if get(hObject,'Value')
1506    set(obj,'Visible','on')
1507else
1508    set(obj,'Visible','off')
1509end
[873]1510set(handles.ConfigSource,'String','NEW')
[856]1511set(handles.OK,'BackgroundColor',[1 0 1])
[774]1512%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1513%%%%%%%%%%%%%%   TEST functions
1514%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1515%------------------------------------------------------------------------
[597]1516% --- Executes on button press in TestCiv1: prepare the image correlation function
[774]1517%     activated by mouse motion
[597]1518function TestCiv1_Callback(hObject, eventdata, handles)
1519%------------------------------------------------------------------------
1520drawnow
1521if get(handles.TestCiv1,'Value')
[855]1522    set(handles.TestCiv1,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch 
[873]1523    set(handles.CheckFix1,'value',0)% desactivate next step
1524    set(handles.CheckPatch1,'value',0)% desactivate next step
1525    set(handles.CheckCiv2,'value',0)% desactivate next step
1526    set(handles.CheckFix2,'value',0)% desactivate next step
1527    set(handles.CheckPatch2,'value',0)% desactivate next step
1528    update_CivOptions(handles,0)
[860]1529      hseries=findobj(allchild(0),'Tag','series');
1530     Param=read_GUI(hseries);
1531     Param.Action.RUN=1;
1532     Param.ActionInput=read_GUI(handles.civ_input);
[862]1533     if isfield(Param.ActionInput,'Fix1')
1534         Param.ActionInput=rmfield(Param.ActionInput,'Fix1');
1535     end
1536     if isfield(Param.ActionInput,'Patch1')
1537         Param.ActionInput=rmfield(Param.ActionInput,'Patch1');
1538     end
1539     if isfield(Param.ActionInput,'Civ2')%remove options that may be selected beyond Patch1
1540         Param.ActionInput=rmfield(Param.ActionInput,'Civ2');
1541     end
1542     if isfield(Param.ActionInput,'Fix2')
1543         Param.ActionInput=rmfield(Param.ActionInput,'Fix2');
1544     end
1545     if isfield(Param.ActionInput,'Patch2')
1546         Param.ActionInput=rmfield(Param.ActionInput,'Patch2');
1547     end
[860]1548     if isfield(Param,'OutputSubDir')
1549     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
1550     end
1551     Param.ActionInput.Civ1.CorrSmooth=0;% launch Civ1 with no data point (to get the image names for A and B)
[897]1552     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
1553     Param.IndexRange.last_i=str2num(get(handles.ref_i,'String'));
1554     if strcmp(get(handles.ref_j,'Visible'),'on')
1555         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
1556         Param.IndexRange.last_j=Param.IndexRange.first_j;
1557     else
1558         Param.IndexRange.first_j=1;
1559         Param.IndexRange.last_j=1;
1560     end
[860]1561     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
[861]1562     if ~isempty(errormsg), return, end % rmq: error msg displayed in civ_series
1563     
[860]1564 %% create image data ImageData for display
1565     ImageData.ListVarName={'ny','nx','A'};
1566     ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
[1097]1567     ImageData.VarAttribute{1}.Role='coord_y';
1568     ImageData.VarAttribute{2}.Role='coord_x';
1569     ImageData.VarAttribute{3}.Role='scalar';
[860]1570     ImageData.A=imread(Data.Civ1_ImageA); % read the first image
1571     if ndims(ImageData.A)==3 %case of color image
1572         ImageData.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
1573     end
1574     ImageData.ny=[size(ImageData.A,1) 1];
1575     ImageData.nx=[1 size(ImageData.A,2)];
1576     ImageData.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
[855]1577
[860]1578     %% create the figure view_field for image visualization
1579     hview_field=view_field(ImageData); %view the image in the GUI view_field
1580     set(0,'CurrentFigure',hview_field)
1581     hhview_field=guihandles(hview_field);
1582     set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
1583     ViewData=get(hview_field,'UserData');
1584     ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
1585     ViewData.PlotAxes.X=Data.Civ1_X';
1586     ViewData.PlotAxes.Y=Data.Civ1_Y';
1587     ViewData.PlotAxes.B=imread(Data.Civ1_ImageB);%store the second image in the UserData of the GUI view_field
1588     set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
[855]1589   
1590    %% look for a current figure for image correlation display
1591    corrfig=findobj(allchild(0),'tag','corrfig');
[597]1592    if isempty(corrfig)
1593        corrfig=figure;
1594        set(corrfig,'tag','corrfig')
1595        set(corrfig,'name','image correlation')
1596        set(corrfig,'DeleteFcn',{@closeview_field})%
[692]1597        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
1598    else
1599        set(handles.TestCiv1,'BackgroundColor',[1 0 0])% paint button to red
1600        corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1601        if ~isempty(corrfig)
1602            delete(corrfig)
1603        end
1604        hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1605        if ~isempty(hview_field)
1606            delete(hview_field)
1607        end
[597]1608    end
[774]1609else
1610    hview_field=findobj(allchild(0),'Tag','view_field'); %view the image in the GUI view_field
1611    if ~isempty(hview_field)
1612        delete(hview_field)
1613    end     
[597]1614end
1615
[774]1616% --------------------------------------------------------------------
1617% --- Executes on button press in TestPatch1.
1618% --------------------------------------------------------------------
1619function TestPatch1_Callback(hObject, eventdata, handles)
[1155]1620msgbox_uvmat('WARNING','open the civ file and run "series/test_filter_tps" ')
[597]1621
[856]1622
[1141]1623%'nomtype2pair': creates nomenclature for index pairs knowing the image nomenclature
[597]1624%---------------------------------------------------------------------
[1020]1625function NomTypeNc=nomtype2pair(NomTypeIma,mode_selected)
[597]1626%---------------------------------------------------------------------           
1627% OUTPUT:
1628% NomTypeNc
1629%---------------------------------------------------------------------
1630% INPUT:
1631% 'NomTypeIma': string defining the kind of nomenclature used for images
1632
1633NomTypeNc=NomTypeIma;%default
[1020]1634switch mode_selected
[597]1635    case 'pair j1-j2'     
1636    if ~isempty(regexp(NomTypeIma,'a$'))
1637        NomTypeNc=[NomTypeIma 'b'];
1638    elseif ~isempty(regexp(NomTypeIma,'A$'))
1639        NomTypeNc=[NomTypeIma 'B'];
1640    else
1641        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
1642        if ~isempty(r)
1643            NomTypeNc='_1_1-2';
1644        end
1645    end
1646    case 'series(Dj)' 
1647%         r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
1648%         if ~isempty(r)
1649            NomTypeNc='_1_1-2';
1650%         end
1651   case 'series(Di)'
1652        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
1653        if ~isempty(r)
1654            NomTypeNc='_1-2_1';
1655        else
1656            NomTypeNc='_1-2';
1657        end
1658end
1659
1660
[645]1661%------------------------------------------------------------------------
1662% --- determine the list of index pairs of processing file
[1020]1663function [ind1,ind2,mode_selected]=...
[645]1664    find_pair_indices(str_civ,i_series,j_series,MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j)
1665%------------------------------------------------------------------------
1666ind1='';
1667ind2='';
1668r=regexp(str_civ,'^\D(?<ind>[i|j])=( -| )(?<num1>\d+)\|(?<num2>\d+)','names');
1669if ~isempty(r)
[1020]1670    mode_selected=['D' r.ind];
[645]1671    ind1=stra2num(r.num1);
1672    ind2=stra2num(r.num2);
1673else
[1020]1674    mode_selected='burst';
[645]1675    r=regexp(str_civ,'^j= (?<num1>[a-z])-(?<num2>[a-z])','names');
1676    if ~isempty(r)
1677        NomTypeNc='_1ab';
1678    else
1679        r=regexp(str_civ,'^j= (?<num1>[A-Z])-(?<num2>[A-Z])','names');
1680        if ~isempty(r)
1681            NomTypeNc='_1AB';
1682        else
1683            r=regexp(str_civ,'^j= (?<num1>\d+)-(?<num2>\d+)','names');
1684            if ~isempty(r)
1685                NomTypeNc='_1_1-2';
1686            end           
1687        end
1688    end
1689    if isempty(r)
1690        display('wrong pair mode input option')
1691    else
1692    ind1=stra2num(r.num1);
1693    ind2=stra2num(r.num2);
1694    end
1695end
[774]1696
1697%------------------------------------------------------------------------
1698% --- fill civ_input with the parameters retrieved from an input Civ file
1699%------------------------------------------------------------------------
1700function fill_civ_input(Data,handles)
1701
1702%% Civ param
1703% lists of parameters to enter
1704ListParamNum={'CorrBoxSize','SearchBoxSize','SearchBoxShift','Dx','Dy','Dz','MinIma','MaxIma'};% list of numerical values (to transform in strings)
1705ListParamValue={'CorrSmooth','CheckGrid','CheckMask','CheckThreshold'};
1706ListParamString={'Grid','Mask'};
1707% CorrSmooth ??
1708option={'Civ1','Civ2'};
1709for ichoice=1:2
1710    if isfield(Data,[option{ichoice} '_CorrBoxSize'])
1711        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
1712    end
1713end
1714
1715%% Fix param
1716option={'Fix1','Fix2'};
1717for ichoice=1:2
1718    if isfield(Data,[option{ichoice} '_CheckFmin2'])
1719        ListParamNum={'MinVel','MaxVel','MinCorr'};% list of numerical values (to transform in strings)
1720        ListParamValue={'CheckFmin2','CheckF3','CheckF4'};
1721        ListParamString={'ref_fix_1'};
1722        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
1723    end
1724end
1725
1726%% Patch param
1727option={'Patch1','Patch2'};
1728for ichoice=1:2
1729    if isfield(Data,[option{ichoice} '_FieldSmooth'])
1730        ListParamNum={'FieldSmooth','MaxDiff','SubDomainSize'};% list of numerical values (to transform in strings)
1731        ListParamValue={};
1732        ListParamString={};
1733        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
1734    end
1735end
1736%------------------------------------------------------------------------
1737% --- fill a panel of civ_input with the parameters retrieved from an input Civ file
1738%------------------------------------------------------------------------
1739function fill_panel(Data,handles,panel,ListParamNum,ListParamValue,ListParamString)
1740children=get(handles.(panel),'children');%handles of the children of the input GUI with handle 'GUI_handle'
1741handles_panel=[];
1742for ichild=1:numel(children)
1743    if ~isempty(get(children(ichild),'tag'))
1744        handles_panel.(get(children(ichild),'tag'))=children(ichild);
1745    end
1746end
1747for ilist=1:numel(ListParamNum)
1748    ParamName=ListParamNum{ilist};
1749    CivParamName=[panel '_' ParamName];
1750    if isfield(Data,CivParamName)
1751        for icoord=1:numel(Data.(CivParamName))
1752            if numel(Data.(CivParamName))>1
1753                Tag=['num_' ParamName '_' num2str(icoord)];
1754            else
1755                Tag=['num_' ParamName];
1756            end
1757            if isfield(handles_panel,Tag)
1758                set(handles_panel.(Tag),'String',num2str(Data.(CivParamName)(icoord)))
1759                set(handles_panel.(Tag),'Visible','on')
1760            end
1761        end
1762    end
1763end
1764for ilist=1:numel(ListParamValue)
1765    ParamName=ListParamValue{ilist};
1766    CivParamName=[panel '_' ParamName];
1767    if strcmp(ParamName,'CorrSmooth')
1768        ParamName=['num_' ParamName];
1769    end
1770    if isfield(Data,CivParamName)
1771        if isfield(handles_panel,ParamName)
1772            set(handles_panel.(ParamName),'Value',Data.(CivParamName))
1773        end
1774    end
1775end
1776for ilist=1:numel(ListParamString)
1777    ParamName=ListParamString{ilist};
1778    CivParamName=[panel '_' ParamName];
1779    if isfield(Data,CivParamName)
1780        if isfield(handles_panel,ParamName)
1781            set(handles_panel.(ParamName),'String',Data.(CivParamName))
1782        end
1783    end
1784end
1785
1786%------------------------------------------------------------------------
[856]1787% --- Executes on button press in ImportParam.
[851]1788%------------------------------------------------------------------------
[856]1789function ImportParam_Callback(hObject, eventdata, handles)
[824]1790hseries=findobj(allchild(0),'Tag','series');
1791hhseries=guidata(hseries);
1792InputTable=get(hhseries.InputTable,'Data');% read the input file(s) table in the GUI series
1793oldfile=InputTable{1,1};
1794if isempty(oldfile)
1795    % use a file name stored in prefdir
1796    dir_perso=prefdir;
1797    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1798    if exist(profil_perso,'file')
1799        h=load (profil_perso);
1800        if isfield(h,'RootPath') && ischar(h.RootPath)
1801            oldfile=h.RootPath;
1802        end
1803    end
1804end
1805filexml=uigetfile_uvmat('pick a xml parameter file for civ',oldfile,'.xml');% get the xml file containing processing parameters
1806%proceed only if a file has been introduced by the browser
1807if ~isempty(filexml)
1808    Param=xml2struct(filexml);% read the input xml file as a Matlab structure
1809    if ~isfield(Param,'InputTable')||~isfield(Param,'IndexRange')
1810        msgbox_uvmat('ERROR','invalid config file: open a file in a folder ''/0_XML''')
1811        return
1812    end
1813    check_input=0;
1814    if isfield(Param,'ActionInput')
1815        if isfield(Param.ActionInput,'Program')&& strcmp(Param.ActionInput.Program,'civ_series')
1816            fill_GUI(Param.ActionInput,handles.civ_input)% fill the elements of the GUI series with the input parameters
[856]1817            set(handles.ConfigSource,'String',filexml)
[824]1818            check_input=1;
[856]1819            update_CivOptions(handles,0)             
[824]1820        end
1821    end
1822    if ~check_input
1823        msgbox_uvmat('ERROR','invalid config file (not for civ_series')
1824        return
1825    end
1826end
[849]1827
[1033]1828%------------------------------------------------------------------------
[855]1829% --- Executes on selection change in CheckCiv3.
[1033]1830%------------------------------------------------------------------------
[855]1831function CheckCiv3_Callback(hObject, eventdata, handles)
[860]1832
[1033]1833%------------------------------------------------------------------------
[1020]1834% --- Executes on button press in CheckRefFile.
[1033]1835%------------------------------------------------------------------------
[1020]1836function CheckRefFile_Callback(hObject, eventdata, handles)
[860]1837
[1033]1838hseries=findobj(allchild(0),'Tag','series');
1839hhseries=guidata(hseries);
1840InputTable=get(hhseries.InputTable,'Data');
1841i1=str2num(get(hhseries.num_first_i,'String'));
1842j1=str2num(get(hhseries.num_first_j,'String'));
1843InputFile=fullfile_uvmat(InputTable{1,1},InputTable{1,2},InputTable{1,3},InputTable{1,5},InputTable{1,4},i1,[],j1);
1844% browse for a reference file for displacement
1845fileref= uigetfile_uvmat('pick a reference image file:',InputFile);
1846if ~isempty(fileref)
1847    FileInfo=get_file_info(fileref);
1848    CheckImage=strcmp(FileInfo.FieldType,'image');% =1 for images
1849    if ~CheckImage
1850        msgbox_uvmat('ERROR',['invalid file type input for reference image: ' FileInfo.FileType ' not an image'])
1851    else
1852        if isfield (FileInfo,'NumberOfFrames')&& FileInfo.NumberOfFrames>1
1853            set(handles.num_OriginIndex,'Visible','on')
1854            set(handles.OriginIndex_title,'Visible','on')
1855        else
1856            set(handles.num_OriginIndex,'Visible','off')
1857            set(handles.OriginIndex_title,'Visible','off')
[1020]1858        end
[1033]1859        set(handles.RefFile,'String',fileref)
1860        set(handles.ConfigSource,'String','NEW')
1861        set(handles.ConfigSource,'BackgroundColor',[1 0 1])
1862    end
1863end
[1020]1864
[851]1865%------------------------------------------------------------------------
1866% --- Executes on key press with selection of a uicontrol
1867%------------------------------------------------------------------------
1868function keyboard_callback(hObject,eventdata,handles)
1869   
1870ListExclude={'CheckCiv1','CheckFix1','CheckPatch1','CheckCiv2','CheckFix2','CheckPatch2','ref_i'};
1871if isempty(find(strcmp(get(gco,'Tag'),ListExclude),1))% if the selected uicontrol is not in the Exclude list
1872    set(handles.ConfigSource,'String','NEW')% indicate that the configuration is new
[856]1873    set(handles.OK,'BackgroundColor',[1 0 1])%
1874    drawnow
[851]1875end
[1148]1876
1877
1878function num_CorrBoxSize_3_Callback(hObject, eventdata, handles)
1879
1880
1881function num_SearchBoxSize_3_Callback(hObject, eventdata, handles)
1882
1883
1884function MinIndex_j_Callback(hObject, eventdata, handles)
1885
1886
1887% --- Executes on selection change in field_ref2.
1888function field_ref2_Callback(hObject, eventdata, handles)
Note: See TracBrowser for help on using the repository browser.