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

Last change on this file since 1165 was 1164, checked in by sommeria, 19 months ago

civ3D updated

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