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

Last change on this file since 1168 was 1167, checked in by sommeria, 13 months ago

mask display fixed

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