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

Last change on this file since 1027 was 1027, checked in by g7moreau, 3 years ago
  • Update Copyright 2017 -> 2018
File size: 96.8 KB
Line 
1%'civ_input': function associated with the GUI 'civ_input.fig' to set the input parameters for civ_series
2%------------------------------------------------------------------------
3% function ParamOut = civ_input(Param)
4%
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
10
11%=======================================================================
12% Copyright 2008-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
13%   http://www.legi.grenoble-inp.fr
14%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
15%
16%     This file is part of the toolbox UVMAT.
17%
18%     UVMAT is free software; you can redistribute it and/or modify
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.
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
26%     GNU General Public License (see LICENSE.txt) for more details.
27%=======================================================================
28
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
39if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback$','once'))
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)
61set(hObject,'WindowKeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
62set(handles.ref_i,'KeyPressFcn',{@ref_i_KeyPressFcn,handles})%set keyboard action function
63set(handles.ref_j,'KeyPressFcn',{@ref_i_KeyPressFcn,handles})%set keyboard action function
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
67
68%% set visibility options depending on the calling function (Param.Action.ActionName):
69if strcmp(Param.Action.ActionName,'civ_series')||strcmp(Param.Action.ActionName,'stereo_civ')
70     set(handles.num_MaxDiff,'Visible','on')
71    set(handles.num_MaxVel,'Visible','on')
72    set(handles.title_MaxVel,'Visible','on')
73    set(handles.title_MaxDiff,'Visible','on')
74    set(handles.num_Nx,'Visible','off')
75    set(handles.num_Ny,'Visible','off')
76    set(handles.title_Nx,'Visible','off')
77    set(handles.title_Ny,'Visible','off')
78    set(handles.num_CorrSmooth,'Style','popupmenu')
79    set(handles.num_CorrSmooth,'Value',1)
80    set(handles.num_CorrSmooth,'String',{'1';'2'})
81    set(handles.CheckThreshold,'Visible','on')
82    set(handles.CheckDeformation,'Value',0)% desactivate (work in progress)
83end
84switch Param.Action.ActionName
85    case 'stereo_civ'
86        set(handles.ListCompareMode,'Visible','off')
87        set(handles.PairIndices,'Visible','off')
88    case 'civ_series'
89        set(handles.ListCompareMode,'Visible','on')
90        set(handles.PairIndices,'Visible','on')
91end
92
93%% input file info
94NomTypeInput=Param.InputTable{1,4};
95FileType='image';%fdefault
96FileInfo=[];
97if isfield(SeriesData,'FileType')&&isfield(SeriesData,'FileInfo')...
98        &&numel(SeriesData.FileType)>=1&&numel(SeriesData.FileInfo)>=1
99    FileType=SeriesData.FileType{1};%type of the first input file series
100    FileInfo=SeriesData.FileInfo{1};% info on the first input file series
101else
102    set(hhseries.REFRESH,'BackgroundColor',[1 0 1])% indicate that the file input in series needs to be refreshed
103end
104
105%% case of netcdf file as input, read the processing stage and look for corresponding images
106ind_opening=0;%default
107NomTypeNc='';
108NomTypeImaA=NomTypeInput;
109iview_image=1;%line # for the input images
110switch FileType
111    case {'image','image_DaVis','multimage','video','mmreader','cine_phantom','netcdf'}
112%         NomTypeImaA=NomTypeInput;
113%         iview_image=1;%line # for the input images
114    case 'civdata'
115        if ~strcmp(Param.Action.ActionName,'civ_series')
116            msgbox_uvmat('ERROR','bad input data file: open an image or a nc file from civ_series')
117            return
118        end
119        NomTypeNc=NomTypeInput;
120        ind_opening=FileInfo.CivStage;
121        if isempty(regexp(NomTypeInput,'[ab|AB|-]', 'once'))
122            set(handles.ListCompareMode,'Value',2) %mode displacement advised if the nomencalture does not involve index pairs
123        else
124            set(handles.ListCompareMode,'Value',1)
125        end
126        [Data,tild,tild,errormsg]=nc2struct(FileInfo.FileName,[]);
127        if ~isempty(errormsg)
128            msgbox_uvmat('ERROR',['error in netcdf input file: ' errormsg])
129            return
130        end
131        if isfield(Data,'.Civ1_ImageA')
132        [PathCiv1_ImageA,Civ1_ImageA,FileExtA]=fileparts(Data.Civ1_ImageA);%look for the source image A
133        [PathCiv1_ImageB,Civ1_ImageB,FileExtA]=fileparts(Data.Civ1_ImageB);%look for the source image B
134        end
135        if isfield(Data,'Civ2_ImageA')
136            [PathCiv2_ImageA,Civ2_ImageA,FileExtA]=fileparts(Data.Civ2_ImageA);
137            [PathCiv2_ImageB,Civ2_ImageB,FileExtA]=fileparts(Data.Civ2_ImageB);
138        end
139        if size(Param.InputTable,1)==1
140             if isfield(Data,'.Civ1_ImageA')
141            series('display_file_name',hhseries,Data.Civ1_ImageA,'append');%append the image series to the input list
142                    [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaA]=fileparts_uvmat(Data.Civ1_ImageA);
143        [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaB]=fileparts_uvmat(Data.Civ1_ImageB);
144             else
145                 series('display_file_name',hhseries,Data.Civ2_ImageA,'append');%append the image series to the input list
146                         [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaA]=fileparts_uvmat(Data.Civ2_ImageA);
147        [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaB]=fileparts_uvmat(Data.Civ2_ImageB);
148             end
149        end
150
151        iview_image=2;%line # for the input images
152    case 'civxdata'% case of  civx data,
153        msgbox_uvmat('ERROR','old civX convention, use the GUI civ')
154        return
155    otherwise
156        msgbox_uvmat('ERROR','civ_series needs images, scalar fields in netcdf format, or civ data as input')
157        return
158end
159
160%% reinitialise menus
161set(handles.ListPairMode,'Value',1)
162set(handles.ListPairMode,'String',{''})
163set(handles.ListPairCiv1,'Value',1)
164set(handles.ListPairCiv1,'String',{''})
165set(handles.ListPairCiv2,'Value',1)
166set(handles.ListPairCiv2,'String',{''})
167       
168%% prepare the GUI with input parameters
169%
170set(handles.ref_i,'String',num2str(Param.IndexRange.first_i))
171if isfield(Param.IndexRange,'first_j')
172    set(handles.ref_j,'String',num2str(Param.IndexRange.first_j))
173end
174set(handles.ConfigSource,'String','\default')
175
176%%  set the menus of image pairs and default selection for civ_input   %%%%%%%%%%%%%%%%%%%
177
178%% display the min and max indices for the whole file series
179if isempty(Param.IndexRange.MaxIndex_i)|| isempty(Param.IndexRange.MinIndex_i)
180    msgbox_uvmat('ERROR','REFRESH the input files in the GUI series')
181     return
182end
183MaxIndex_i=Param.IndexRange.MaxIndex_i(iview_image);
184MinIndex_i=Param.IndexRange.MinIndex_i(iview_image);
185MaxIndex_j=1;%default
186MinIndex_j=1;
187if isfield(Param.IndexRange,'MaxIndex_j')&&isfield(Param.IndexRange,'MinIndex_j')...
188        && numel(Param.IndexRange.MaxIndex_j')>=iview_image &&numel(Param.IndexRange.MinIndex_j')>=iview_image
189    MaxIndex_j=Param.IndexRange.MaxIndex_j(iview_image);
190    MinIndex_j=Param.IndexRange.MinIndex_j(iview_image);
191end
192%update the bounds if possible
193if isfield(SeriesData,'i1_series')&&numel(SeriesData.i1_series)>=iview_image
194    if size(SeriesData.i1_series{iview_image},2)==2 && min(min(SeriesData.i1_series{iview_image}(:,1,:)))==0
195        MinIndex_j=1;% index j set to 1 by default
196        MaxIndex_j=1;
197        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)
198        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)
199    else
200        ref_i=squeeze(max(SeriesData.i1_series{iview_image}(1,:,:),[],2));% select ref_j index for each ref_i
201        ref_j=squeeze(max(SeriesData.j1_series{iview_image}(1,:,:),[],3));% select ref_i index for each ref_j
202        MinIndex_i=min(find(ref_i))-1;
203        MaxIndex_i=max(find(ref_i))-1;
204        MaxIndex_j=max(find(ref_j))-1;
205        MinIndex_j=min(find(ref_j))-1;
206    end
207end
208
209
210%%  transfer the time from the GUI series, or use file index by default
211time=[];
212TimeUnit='frame'; %default
213CoordUnit='';%default
214pxcm_search=1;
215if isfield(SeriesData,'Time') &&numel(SeriesData.Time')>=1 && ~isempty(SeriesData.Time{1})
216    time=SeriesData.Time{1};
217end
218if isfield(Param.IndexRange,'TimeUnit')&&~isempty(Param.IndexRange.TimeUnit)
219    TimeUnit=Param.IndexRange.TimeUnit;
220end
221if isfield(SeriesData,'GeometryCalib')
222    tsai=SeriesData.GeometryCalib;
223    if isfield(tsai,'fx_fy')
224        pxcm_search=max(tsai.fx_fy(1),tsai.fx_fy(2));%pixels:cm estimated for the search range
225    end
226    if isfield(tsai,'CoordUnit')
227        CoordUnit=tsai.CoordUnit;
228    end
229end
230
231%% timing display
232%show the reference image edit box if relevant (not needed for movies or in the absence of time information
233if numel(time)>=2 % if there are at least two time values to define dt
234    if size(time,1)<MaxIndex_i;
235        msgbox_uvmat('WARNING','maximum i index restricted by the timing of the xml file');
236    elseif size(time,2)<MaxIndex_j
237        msgbox_uvmat('WARNING','maximum j index restricted by the timing of the xml file');
238    end
239    MaxIndex_i=min(size(time,1),MaxIndex_i);%possibly adjust the max index according to time data
240    MaxIndex_j=min(size(time,2),MaxIndex_j);
241    set(handles.TimeSource,'String',Param.IndexRange.TimeSource);
242else
243    set(handles.TimeSource,'String',''); %xml file not used for timing
244    TimeUnit='frame';
245    time=ones(MaxIndex_j-MinIndex_j+1,1)*(MinIndex_i:MaxIndex_i);
246    time=time+0.001*(MinIndex_j:MaxIndex_j)'*ones(1,MaxIndex_i-MinIndex_i+1);
247end
248CivInputData.Time=time;
249CivInputData.NomTypeIma=NomTypeImaA;
250set(handles.civ_input,'UserData',CivInputData)
251set(handles.dt_unit,'String',['dt in m' TimeUnit]);%display dt in unit 10-3 of the time (e.g ms)
252set(handles.TimeUnit,'String',TimeUnit);
253%set(handles.CoordUnit,'String',CoordUnit)
254set(handles.SearchRange,'UserData', pxcm_search);
255
256
257%% set the civ_input options, depending on the input file content if a nc file has been opened
258ListOptions={'CheckCiv1', 'CheckFix1' 'CheckPatch1', 'CheckCiv2', 'CheckFix2', 'CheckPatch2'};
259checkbox=zeros(size(ListOptions));%default
260checkrefresh=0;
261if ind_opening==0  %case of image opening, start with Civ1
262    for index=1:numel(ListOptions)
263        checkbox(index)=get(handles.(ListOptions{index}),'Value');
264    end
265    index_max=find(checkbox, 1, 'last' );
266    if isempty(index_max),index_max=1;end
267    for index=1:index_max
268        set(handles.(ListOptions{index}),'Value',1)% select all operations starting from CIV1
269    end
270else  %case of netcdf file opening, start with the stage read in the file if the input file is being refreshed
271    if isequal(get(hhseries.REFRESH,'BackgroundColor'),[1 1 0]) &&...
272            ~(isfield(Param,'ActionInput') && isfield(Param.ActionInput,'ConfigSource'))
273            for index = 1:min(ind_opening,5)
274                set(handles.(ListOptions{index}),'value',0)
275                fill_civ_input(Data,handles); %fill civ_input with the parameters retrieved from an input Civ file
276            end
277            set(handles.ConfigSource,'String',FileInfo.FileName);
278            set(handles.(ListOptions{min(ind_opening+1,6)}),'value',1)
279            for index = ind_opening+2:6
280                set(handles.(ListOptions{index}),'value',0)
281            end
282            checkrefresh=1;
283    end
284    if ind_opening>=3
285        set(handles.CheckCiv3,'Visible','on')% make visible the switch 'iterate/repet' for Civ2.
286    else
287        set(handles.CheckCiv3,'Visible','off')
288    end
289end
290
291%% introduce the stored Civ parameters  if available (from previous input or ImportConfig in series)
292if ~checkrefresh && isfield(Param,'ActionInput')&& strcmp(Param.ActionInput.Program,Param.Action.ActionName)% the program fits with the stored data
293    fill_GUI(Param.ActionInput,hObject);%fill the GUI with the parameters retrieved from the input Param
294    hcheckgrid=findobj(handles.civ_input,'Tag','CheckGrid');
295    for ilist=1:numel(hcheckgrid)
296        if get(hcheckgrid(ilist),'Value')% if a grid is used, do not show Dx and Dy for an automatic grid
297            hparent=get(hcheckgrid(ilist),'parent');%handles of the parent panel
298            hchildren=get(hparent,'children');
299            handle_dx=findobj(hchildren,'tag','num_Dx');
300            handle_dy=findobj(hchildren,'tag','num_Dy');
301            handle_title_dx=findobj(hchildren,'tag','title_Dx');
302            handle_title_dy=findobj(hchildren,'tag','title_Dy');
303            set(handle_dx,'Visible','off');
304            set(handle_dy,'Visible','off');
305            set(handle_title_dy,'Visible','off');
306            set(handle_title_dx,'Visible','off');
307        end
308    end
309    if isfield(Param.ActionInput,'Civ2')
310       CheckDeformation_Callback(hObject, eventdata, handles)
311    end
312end
313       if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'ListCompareMode')&&...
314               strcmp(Param.ActionInput.ListCompareMode,'displacement')
315            set(handles.PairIndices,'Visible','off')
316        end
317
318%% set the menu and default choice of civ pairs
319if ~isfield(Param.IndexRange,'first_j')||isequal(MaxIndex_j,MinIndex_j)% no possibility of j pairs
320    set(handles.ListPairMode,'Value',1)
321    PairMenu={'series(Di)'};
322elseif  MaxIndex_i==1 && MaxIndex_j>1% simple series in j
323    PairMenu={'pair j1-j2';'series(Dj)'};
324    if  MaxIndex_j <= 10
325        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
326    end
327else
328    PairMenu={'pair j1-j2';'series(Dj)';'series(Di)'};%multiple choice
329    if strcmp(NomTypeNc,'_1-2_1')
330        set(handles.ListPairMode,'Value',3)% advise 'series(Di)'
331    elseif  MaxIndex_j <= 10
332        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
333    end
334end
335set(handles.ListPairMode,'String',PairMenu)
336
337%% set default choice of pair mode
338PairIndex=[];
339if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'PairIndices')
340    PairIndex=find(strcmp(Param.ActionInput.PairIndices.ListPairMode,PairMenu));
341end
342if isempty(PairIndex)
343    if ~isfield(Param.IndexRange,'first_j')||isequal(MaxIndex_j,MinIndex_j)% no possibility of j pairs
344        PairIndex=1;
345    elseif  MaxIndex_i==1 && MaxIndex_j>1% simple series in j
346        if  MaxIndex_j <= 10
347            PairIndex=1;% advice 'pair j1-j2' except in MaxIndex_j is large
348        end
349    else
350        if strcmp(NomTypeNc,'_1-2_1')
351            PairIndex=3;% advise 'series(Di)'
352        elseif  MaxIndex_j <= 10
353            PairIndex=1;% advice 'pair j1-j2' except in MaxIndex_j is large
354        end
355    end
356end
357set(handles.ListPairMode,'Value',PairIndex); 
358
359%% indicate the min and max indices i and j on the GUI
360set(handles.MinIndex_i,'String',num2str(MinIndex_i))
361set(handles.MaxIndex_i,'String',num2str(MaxIndex_i))
362set(handles.MinIndex_j,'String',num2str(MinIndex_j))
363set(handles.MaxIndex_j,'String',num2str(MaxIndex_j))
364
365%% set the reference indices from the input file indices
366if ~(isfield(Param,'ActionInput') && isfield(Param.ActionInput,'ConfigSource'))
367update_CivOptions(handles,ind_opening)% fill the menu of possible pairs
368end
369
370%% list the possible index pairs, depending on the option set in ListPairMode
371ListPairMode_Callback([], [], handles)
372%ListPairCiv1_Callback(hObject, eventdata, handles)
373
374%% set the GUI to modal: wait for OK to close
375set(handles.civ_input,'WindowStyle','modal')% Make the GUI modal
376drawnow
377uiwait(handles.civ_input);% wait for OK action to end the function
378
379
380%------------------------------------------------------------------------
381% --- Outputs from this function are returned to the command line.
382function varargout = civ_input_OutputFcn(hObject, eventdata, handles)
383%------------------------------------------------------------------------
384% Get default command line output from handles structure
385varargout{1}=[];% default output when civ_input is canceled (no 'OK')
386if ~isempty(handles)
387    varargout{1} = handles.output;
388    delete(handles.civ_input)
389end
390
391% --- Executes when user attempts to close get_field.
392function civ_input_CloseRequestFcn(hObject, eventdata, handles)
393if isequal(get(handles.get_field, 'waitstatus'), 'waiting')
394    % The GUI is still in UIWAIT, us UIRESUME
395    uiresume(handles.civ_input);
396else
397    % The GUI is no longer waiting, just close it
398    delete(handles.civ_input);
399end
400
401%------------------------------------------------------------------------
402% --- Executes on button press in SetDefaultParam.
403%------------------------------------------------------------------------
404function SetDefaultParam_Callback(hObject, eventdata, handles)
405
406Param.ConfigSource='\default';
407
408%% Civ1 parameters
409%Param.CheckCiv1=1;
410Param.Civ1.CorrBoxSize=[25 25];
411Param.Civ1.SearchBoxSize=[55 55];
412Param.Civ1.SearchBoxShift=[0 0];
413Param.Civ1.CorrSmooth=1;
414Param.Civ1.Dx=20;
415Param.Civ1.Dy=20;
416Param.Civ1.CheckGrid=0;
417Param.Civ1.CheckMask=0;
418Param.Civ1.Mask='';
419Param.Civ1.CheckThreshold=0;
420Param.Civ1.TestCiv1=0;
421
422%% Fix1 parameters
423%Param.CheckFix1=1;
424Param.Fix1.CheckFmin2=1;
425Param.Fix1.CheckF3=1;
426Param.Fix1.MinCorr=0.2000;
427
428%% Patch1 parameters
429%Param.CheckPatch1=1;
430Param.Patch1.FieldSmooth=10;
431Param.Patch1.MaxDiff=1.5000;
432Param.Patch1.SubDomainSize=1000;
433Param.Patch1.TestPatch1=0;
434
435%% Civ2 parameters
436%Param.CheckCiv2=1;
437Param.Civ2.CorrBoxSize=[21 21];
438Param.Civ2.SearchBoxSize=[27 27];
439Param.Civ2.CorrSmooth=1;
440Param.Civ2.Dx=10;
441Param.Civ2.Dy=10;
442Param.Civ2.CheckGrid=0;
443Param.Civ2.CheckMask=0;
444Param.Civ2.Mask='';
445Param.Civ2.CheckThreshold=0;
446Param.Civ2.TestCiv2=0;
447
448%% Fix2 parameters
449%Param.CheckFix2=1;
450Param.Fix2.CheckFmin2=1;
451Param.Fix2.CheckF4=1;
452Param.Fix2.CheckF3=1;
453Param.Fix2.MinCorr=0.2000;
454
455%% Patch2 parameters
456%Param.CheckPatch2=1;
457Param.Patch2.FieldSmooth=2;
458Param.Patch2.MaxDiff=1.5000;
459Param.Patch2.SubDomainSize=1000;
460Param.Patch2.TestPatch2=0;
461
462fill_GUI(Param,handles.civ_input)% fill the elements of the GUI series with the input parameters
463update_CivOptions(handles,0)
464
465% -----------------------------------------------------------------------
466% -----------------------------------------------------------------------
467% --- Open the help html file
468function MenuHelp_Callback(hObject, eventdata, handles)
469% -----------------------------------------------------------------------
470web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp#Civ')
471
472%------------------------------------------------------------------------
473% --- Executes on carriage return on the subdir checkciv1 edit window
474function Civ1_ImageB_Callback(hObject, eventdata, handles)
475%------------------------------------------------------------------------
476SubDir=get(handles.Civ1_ImageB,'String');
477menu_str=get(handles.ListSubdirCiv1,'String');% read the list of subdirectories for update
478ichoice=find(strcmp(SubDir,menu_str),1);
479if isempty(ichoice)
480    ilist=numel(menu_str); %select 'new...' in the menu
481else
482    ilist=ichoice;
483end
484set(handles.ListSubdirCiv1,'Value',ilist)% select the selected subdir in the menu
485if get(handles.CheckCiv1,'Value')% if Civ1 is performed
486    set(handles.Civ2_ImageA,'String',SubDir);% set by default civ2 directory the same as civ1
487%     set(handles.ListSubdirCiv2,'Value',ilist)
488else % if Civ1 data already exist
489    errormsg=find_netcpair_civ(handles,1); %update the list of available index pairs in the new directory
490    if ~isempty(errormsg)
491    msgbox_uvmat('ERROR',errormsg)
492    end
493end
494
495%------------------------------------------------------------------------
496% --- Executes on carriage return on the SubDir checkciv1 edit window
497function Civ2_ImageA_Callback(hObject, eventdata, handles)
498%------------------------------------------------------------------------
499SubDir=get(handles.Civ1_ImageB,'String');
500menu_str=get(handles.ListSubdirCiv2,'String');% read the list of subdirectories for update
501ichoice=find(strcmp(SubDir,menu_str),1);
502if isempty(ichoice)
503    ilist=numel(menu_str); %select 'new...' in the menu
504else
505    ilist=ichoice;
506end
507set(handles.ListSubdirCiv2,'Value',ilist)% select the selected subdir in the menu
508%update the list of available pairs from netcdf files in the new directory
509if ~get(handles.CheckCiv2,'Value') && ~get(handles.CheckCiv1,'Value') && ~get(handles.CheckFix1,'Value') && ~get(handles.CheckPatch1,'Value')
510    errormsg=find_netcpair_civ(handles,2);
511        if ~isempty(errormsg)
512    msgbox_uvmat('ERROR',errormsg)
513    end
514end
515
516%------------------------------------------------------------------------
517% --- Executes on button press in CheckCiv1.
518function CheckCiv1_Callback(hObject, eventdata, handles)
519%------------------------------------------------------------------------
520update_CivOptions(handles,0)
521
522%------------------------------------------------------------------------
523% --- Executes on button press in CheckFix1.
524function CheckFix1_Callback(hObject, eventdata, handles)
525%------------------------------------------------------------------------
526update_CivOptions(handles,0)
527
528%------------------------------------------------------------------------
529% --- Executes on button press in CheckPatch1.
530function CheckPatch1_Callback(hObject, eventdata, handles)
531%------------------------------------------------------------------------
532update_CivOptions(handles,0)
533
534%------------------------------------------------------------------------
535% --- Executes on button press in CheckCiv2.
536function CheckCiv2_Callback(hObject, eventdata, handles)
537%------------------------------------------------------------------------
538update_CivOptions(handles,0)
539
540%------------------------------------------------------------------------
541% --- Executes on button press in CheckFix2.
542function CheckFix2_Callback(hObject, eventdata, handles)
543%------------------------------------------------------------------------
544update_CivOptions(handles,0)
545
546%------------------------------------------------------------------------
547% --- Executes on button press in CheckPatch2.
548function CheckPatch2_Callback(hObject, eventdata, handles)
549%------------------------------------------------------------------------
550update_CivOptions(handles,0)
551
552%------------------------------------------------------------------------
553% --- activated by any checkbox controling the selection of Civ1,Fix1,Patch1,Civ2,Fix2,Patch2
554function update_CivOptions(handles,opening)
555%------------------------------------------------------------------------
556if opening>0
557    set(handles.CheckCiv2,'UserData',opening)% store the info on the current status of the civ processing
558end
559checkbox=zeros(1,6);
560checkbox(1)=get(handles.CheckCiv1,'Value');
561checkbox(2)=get(handles.CheckFix1,'Value');
562checkbox(3)=get(handles.CheckPatch1,'Value');
563checkbox(4)=get(handles.CheckCiv2,'Value');
564checkbox(5)=get(handles.CheckFix2,'Value');
565checkbox(6)=get(handles.CheckPatch2,'Value');
566if opening==0
567    errormsg=find_netcpair_civ(handles,1); % select the available netcdf files
568    if ~isempty(errormsg)
569        msgbox_uvmat('ERROR',errormsg)
570    end
571end
572if max(checkbox(4:6))>0% case of civ2 pair choice needed
573    set(handles.TitlePairCiv2,'Visible','on')
574    set(handles.ListPairCiv2,'Visible','on')
575    if ~opening
576        errormsg=find_netcpair_civ(handles,2); % select the available netcdf files
577        if ~isempty(errormsg)
578            msgbox_uvmat('ERROR',errormsg)
579        end
580    end
581else
582    set(handles.ListPairCiv2,'Visible','off')
583end
584hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
585hhseries=guidata(hseries); %handles of the elements in 'series'
586InputTable=get(hhseries.InputTable,'Data');
587if 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
588    set(handles.CheckCiv3,'Visible','on')
589else
590    set(handles.CheckCiv3,'Visible','off')
591end
592
593%% set the visibility of the different panels
594options={'Civ1','Fix1','Patch1','Civ2','Fix2','Patch2'};
595for ilist=1:length(options)
596    if checkbox(ilist)
597        set(handles.(options{ilist}),'Visible','on')
598    else
599        set(handles.(options{ilist}),'Visible','off')
600    end
601end
602
603%------------------------------------------------------------------------
604% --- Executes on button press in OK: processing on local computer
605function OK_Callback(hObject, eventdata, handles)
606%------------------------------------------------------------------------
607
608ActionInput=read_GUI(handles.civ_input);% read the infos on the GUI civ_input
609
610%% correct input inconsistencies
611if isfield(ActionInput,'Civ1')
612    checkeven=(mod(ActionInput.Civ1.CorrBoxSize,2)==0);
613    ActionInput.Civ1.CorrBoxSize(checkeven)=ActionInput.Civ1.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values
614    ActionInput.Civ1.SearchBoxSize=max(ActionInput.Civ1.SearchBoxSize,ActionInput.Civ1.CorrBoxSize+8);% insure that the search box size is large enough
615    checkeven=(mod(ActionInput.Civ1.SearchBoxSize,2)==0);
616    ActionInput.Civ1.SearchBoxSize(checkeven)=ActionInput.Civ1.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
617end
618if isfield(ActionInput,'Civ2')
619    checkeven=(mod(ActionInput.Civ2.CorrBoxSize,2)==0);
620    ActionInput.Civ2.CorrBoxSize(checkeven)=ActionInput.Civ2.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values
621    ActionInput.Civ2.SearchBoxSize=max(ActionInput.Civ2.SearchBoxSize,ActionInput.Civ2.CorrBoxSize+4);
622    checkeven=(mod(ActionInput.Civ2.SearchBoxSize,2)==0);
623    ActionInput.Civ2.SearchBoxSize(checkeven)=ActionInput.Civ2.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
624end
625
626%% correct mask or grid name for Windows system (replace '\' by '/')
627if isfield(ActionInput,'Civ1')
628    if isfield(ActionInput.Civ1,'Mask')
629        ActionInput.Civ1.Mask=regexprep(ActionInput.Civ1.Mask,'\','/');
630    end
631    if isfield(ActionInput.Civ1,'Grid')
632        ActionInput.Civ1.Grid=regexprep(ActionInput.Civ1.Grid,'\','/');
633    end
634end
635if isfield(ActionInput,'Civ2')
636    if isfield(ActionInput.Civ2,'Mask')
637        ActionInput.Civ2.Mask=regexprep(ActionInput.Civ2.Mask,'\','/');
638    end
639    if isfield(ActionInput.Civ2,'Grid')
640        ActionInput.Civ2.Grid=regexprep(ActionInput.Civ2.Grid,'\','/');
641    end
642end
643
644%% exit the GUI and close it
645handles.output.ActionInput=ActionInput;
646guidata(hObject, handles);% Update handles structure
647uiresume(handles.civ_input);
648
649
650%------------------------------------------------------------------------
651% --- Executes on button press in ListCompareMode.
652function ListCompareMode_Callback(hObject, eventdata, handles)
653%------------------------------------------------------------------------
654ListCompareMode=get(handles.ListCompareMode,'String');
655option=ListCompareMode{get(handles.ListCompareMode,'Value')};
656hseries=findobj(allchild(0),'Tag','series');
657SeriesData=get(hseries,'UserData');
658check_nc=strcmp(SeriesData.FileType{1},'.nc');
659ImageType=SeriesData.FileType(2:end);
660if check_nc
661    ImageType=SeriesData.FileType(2:end);
662else
663    ImageType=SeriesData.FileType;
664end
665hhseries=guidata(hseries);
666InputTable=get(hhseries.InputTable,'Data');
667OriginIndex='off';
668PairIndices='off';
669switch option
670    case 'PIV'
671        PairIndices='on';% needs to define index pairs for PIV       
672    case 'PIV volume'
673        PairIndices='on';% needs to define index pairs for PIV
674        set(handles.ListPairMode,'Value',1)
675        set(handles.ListPairMode,'String',{'series(Di)'})
676        ListPairMode_Callback(hObject, eventdata, handles)
677    case 'displacement'
678        OriginIndex='on';%define a frame origin for displacement
679end
680set(handles.num_OriginIndex,'Visible',OriginIndex)
681set(handles.OriginIndex_title,'Visible',OriginIndex)
682set(handles.CheckRefFile,'Visible',OriginIndex)
683set(handles.RefFile,'Visible',OriginIndex)
684set(handles.PairIndices,'Visible',PairIndices)
685ListPairMode_Callback(hObject,eventdata,handles)
686if strcmp(OriginIndex,'on')
687    set(handles.CheckRefFile,'Value',1)
688    CheckRefFile_Callback(hObject,eventdata,handles)
689end
690       
691
692
693%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
694% Callbacks in the uipanel Pair Indices
695%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
696%------------------------------------------------------------------------
697% --- Executes on button press in ListPairMode.
698function ListPairMode_Callback(hObject, eventdata, handles)
699%------------------------------------------------------------------------
700compare_list=get(handles.ListCompareMode,'String');
701val=get(handles.ListCompareMode,'Value');
702compare=compare_list{val};
703if strcmp(compare,'displacement')||strcmp(compare,'shift')
704    mode_selected='displacement';
705else
706    mode_list=get(handles.ListPairMode,'String');
707    if ischar(mode_list)
708        mode_list={mode_list};
709    end 
710    mode_value=get(handles.ListPairMode,'Value');
711    if isempty(mode_value)
712        mode_value=1;
713    end
714    mode_selected=mode_list{mode_value};
715end
716% displ_num=[];%default
717ref_i=str2double(get(handles.ref_i,'String'));
718% last_i=str2num(get(handles.last_i,'String'));
719CivInputData=get(handles.civ_input,'UserData');
720TimeUnit=get(handles.TimeUnit,'String');
721checkframe=strcmp(TimeUnit,'frame');
722time=CivInputData.Time;
723siztime=size(CivInputData.Time);
724nbfield=siztime(1)-1;
725nbfield2=siztime(2)-1;
726%indchosen=1;  %%first pair selected by default
727%displ_num used to define the indices of the civ_input pairs
728% in mode 'pair j1-j2', j1 and j2 are the file indices, else the indices
729% are relative to the reference indices ref_i and ref_j respectively.
730if isequal(mode_selected,'pair j1-j2')
731    dt=1;
732    displ='';
733    index=0;
734    numlist_a=[];
735    numlist_B=[];
736    %get all the time intervals in bursts
737    displ_dt=1;%default
738    nbfield2=min(nbfield2,10);%limitate the number of pairs to 10x10
739    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
740        for numod_b=(numod_a+1):nbfield2
741            index=index+1;
742            numlist_a(index)=numod_a;
743            numlist_b(index)=numod_b;
744            if size(time,2)>1 && ~checkframe && size(CivInputData.Time,1)>ref_i && size(CivInputData.Time,2)>numod_b
745                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
746                displ_dt(index)=dt(numod_a,numod_b);
747            else
748                displ_dt(index)=1;
749            end
750        end
751    end
752    [dtsort,indsort]=sort(displ_dt);
753    if ~isempty(numlist_a)
754        displ_num(1,:)=numlist_a(indsort);
755        displ_num(2,:)=numlist_b(indsort);
756    end
757    displ_num(3,:)=0;
758    displ_num(4,:)=0;
759    enable_j(handles, 'off')
760elseif isequal(mode_selected,'series(Dj)') %| isequal(mode,'st_series(Dj)')
761    index=1:200;
762    displ_num(1,index)=-floor(index/2);
763    displ_num(2,index)=ceil(index/2);
764    displ_num(3:4,index)=zeros(2,200);
765    enable_j(handles, 'on')
766elseif isequal(mode_selected,'series(Di)') %| isequal(mode,'st_series(Di)')
767%     index=1:200;
768%     displ_num(1:2,index)=zeros(2,200);
769%     displ_num(3,index)=-floor(index/2);
770%     displ_num(4,index)=ceil(index/2);
771    enable_i(handles, 'on')
772    if nbfield2 > 1
773        enable_j(handles, 'on')
774    else
775        enable_j(handles, 'off')
776    end
777elseif isequal(mode_selected,'displacement')%the pairs have the same indices
778    displ_num(1,1)=0;
779    displ_num(2,1)=0;
780    displ_num(3,1)=0;
781    displ_num(4,1)=0;
782    if nbfield > 1 || nbfield==0
783        enable_i(handles, 'on')
784    else
785        enable_j(handles, 'off')
786    end
787    if nbfield2 > 1
788        enable_j(handles, 'on')
789    else
790        enable_j(handles, 'off')
791    end
792end
793%set(handles.ListPairCiv1,'UserData',displ_num);
794errormsg=find_netcpair_civ( handles,1);
795    if ~isempty(errormsg)
796    msgbox_uvmat('ERROR',errormsg)
797    end
798% find_netcpair_civ2(handles)
799
800function enable_i(handles, state)
801set(handles.itext,'Visible',state)
802% set(handles.MinIndex_i,'Visible',state)
803% set(handles.last_i,'Visible',state)
804% set(handles.incr_i,'Visible',state)
805set(handles.MaxIndex_i,'Visible',state)
806set(handles.ref_i,'Visible',state)
807
808function enable_j(handles, state)
809set(handles.jtext,'Visible',state)
810% set(handles.MinIndex_j,'Visible',state)
811% set(handles.last_j,'Visible',state)
812% set(handles.incr_j,'Visible',state)
813set(handles.MinIndex_j,'Visible',state)
814set(handles.MaxIndex_j,'Visible',state)
815set(handles.ref_j,'Visible',state)
816%hseries=findobj(allchild(0),'Tag','series');
817%hhseries=guidata(hseries);
818%series('enable_j',hhseries,state); %file input with xml reading  in uvmat, show the image in phys coordinates
819
820
821
822%------------------------------------------------------------------------
823% --- Executes on selection change in ListPairCiv1.
824function ListPairCiv1_Callback(hObject, eventdata, handles)
825%------------------------------------------------------------------------
826%reproduce by default the chosen pair in the checkciv2 menu
827list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
828PairString=list_pair{get(handles.ListPairCiv1,'Value')};
829
830[ind1,ind2]=...
831    find_pair_indices(PairString);
832hseries=findobj(allchild(0),'Tag','series');
833hhseries=guidata(hseries);
834set(hhseries.num_first_j,'String',num2str(ind1));
835set(hhseries.num_last_j,'String',num2str(ind2));
836set(hhseries.num_incr_j,'String',num2str(ind2-ind1));
837set(handles.ListPairCiv2,'Value',get(handles.ListPairCiv1,'Value'))%civ2 selection the same as civ& by default
838
839
840%------------------------------------------------------------------------
841% --- Executes on selection change in ListPairCiv2.
842function ListPairCiv2_Callback(hObject, eventdata, handles)
843%------------------------------------------------------------------------
844
845
846%------------------------------------------------------------------------
847function ref_i_Callback(hObject, eventdata, handles)
848%------------------------------------------------------------------------
849mode_list=get(handles.ListPairMode,'String');
850mode_value=get(handles.ListPairMode,'Value');
851mode_selected=mode_list{mode_value};
852errormsg=find_netcpair_civ(handles,1);% update the menu of pairs depending on the available netcdf files
853if isequal(mode_selected,'series(Di)') || ...% we do patch2 only
854        (get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0)
855    errormsg=find_netcpair_civ( handles,2);
856end
857if isempty(errormsg)
858    set(handles.ref_i,'BackgroundColor',[1 1 1])
859    set(handles.ref_j,'BackgroundColor',[1 1 1])
860else
861    msgbox_uvmat('ERROR',errormsg)
862end
863
864function ref_i_KeyPressFcn(hObject, eventdata, handles)
865set(hObject,'BackgroundColor',[1 0 1])
866       
867% %------------------------------------------------------------------------
868
869function errormsg=find_netcpair_civ(handles,index)
870%------------------------------------------------------------------------
871set(gcf,'Pointer','watch')% set the mouse pointer to 'watch' (clock)
872
873%% initialisation
874errormsg='';
875CivInputData=get(handles.civ_input,'UserData');
876%browse=get(handles.RootPath,'UserData');
877compare_list=get(handles.ListCompareMode,'String');
878val=get(handles.ListCompareMode,'Value');
879compare=compare_list{val};
880mode_selected='displacement';
881if ~strcmp(compare,'displacement')%||strcmp(compare,'shift')
882 
883    mode_list=get(handles.ListPairMode,'String');
884    mode_value=get(handles.ListPairMode,'Value');
885    if isempty(mode_value)
886        mode_value=1;
887    end
888    if isempty(mode_list)
889        return
890    end
891    mode_selected=mode_list{mode_value};
892end
893nom_type_ima=CivInputData.NomTypeIma;
894menu_pair=get(handles.ListPairCiv1,'String');%previous menu of ListPairCiv1
895PairCiv1Init=menu_pair{get(handles.ListPairCiv1,'Value')};%previous choice of pair
896menu_pair=get(handles.ListPairCiv2,'String');%previous menu of ListPairCiv1
897PairCiv2Init=menu_pair{get(handles.ListPairCiv2,'Value')};%previous choice of pair
898
899%% determine nom_type_nc, nomenclature type of the .nc files:
900%[nom_type_nc]=nomtype2pair(nom_type_ima,mode);
901
902%% reads .nc subdirectoy and image numbers from the interface
903%SubDirImages=get(handles.Civ1_ImageA,'String');
904%TODO: determine
905%subdir_civ1=[SubDirImages get(handles.Civ1_ImageB,'String')];%subdirectory subdir_civ1 for the netcdf data
906%subdir_civ2=[SubDirImages get(handles.Civ2_ImageA,'String')];%subdirectory subdir_civ2 for the netcdf data
907ref_i=str2double(get(handles.ref_i,'String'));
908ref_j=[];
909if isequal(mode_selected,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
910    ref_j=0;
911elseif strcmp(get(handles.ref_j,'Visible'),'on')
912    ref_j=str2double(get(handles.ref_j,'String'));
913end
914if isempty(ref_j)
915    ref_j=1;
916end
917CivInputData=get(handles.civ_input,'UserData');
918TimeUnit=get(handles.TimeUnit,'String');
919Time=CivInputData.Time;
920checkframe=strcmp(TimeUnit,'frame');
921
922%% case with no Civ1 operation, netcdf files need to exist for reading
923displ_pair={''};
924nbpair=200;%default
925select=ones(size(1:nbpair));%flag for displayed pairs =1 for display
926%nbpair=200; %default
927
928%% determine the menu display in .ListPairCiv1
929switch mode_selected
930    case 'series(Di)'
931        for ipair=1:nbpair
932            if select(ipair)
933                displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2))];
934                displ_pair_dt{ipair}=displ_pair{ipair};
935                if ~checkframe
936                    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
937                        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
938                        displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(dt*1000)];
939                    end
940                else
941                    dt=ipair/1000;
942                    displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(ipair)];
943                end
944            else
945                displ_pair{ipair}='...';
946                displ_pair_dt{ipair}='...'; %pair not displayed in the menu
947            end
948        end
949    case 'series(Dj)'
950        for ipair=1:nbpair
951            if select(ipair)
952                displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2))];
953                displ_pair_dt{ipair}=displ_pair{ipair};
954                if ~checkframe
955                    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
956                        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
957                        displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(dt*1000)];
958                    end
959                else
960                    dt=ipair/1000;
961                    displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(dt*1000)];
962                end
963            else
964                displ_pair{ipair}='...'; %pair not displayed in the menu
965                displ_pair_dt{ipair}='...'; %pair not displayed in the menu
966            end
967        end
968    case 'pair j1-j2'%case of pairs
969        MinIndex_j=str2num(get(handles.MinIndex_j,'String'));
970        MaxIndex_j=str2num(get(handles.MaxIndex_j,'String'));
971        index_pair=0;
972        %get all the Time intervals in bursts
973        displ_pair_dt='';
974        for numod_a=MinIndex_j:MaxIndex_j-1 %nbfield2 always >=2 for 'pair j1-j2' mode
975            for numod_b=(numod_a+1):MaxIndex_j
976                index_pair=index_pair+1;
977                displ_pair{index_pair}=['j= ' num2stra(numod_a,nom_type_ima) '-' num2stra(numod_b,nom_type_ima)];
978                displ_pair_dt{index_pair}=displ_pair{index_pair};
979                dt(index_pair)=numod_b-numod_a;%default dt
980                if size(Time,1)>ref_i && size(Time,2)>numod_b  % && ~checkframe
981                    dt(index_pair)=Time(ref_i+1,numod_b+1)-Time(ref_i+1,numod_a+1);% Time interval dt
982                    displ_pair_dt{index_pair}=[displ_pair_dt{index_pair} ' :dt= ' num2str(dt(index_pair)*1000)];
983                end
984            end
985           
986        end
987        if index_pair ~=0
988        [tild,indsort]=sort(dt);
989        displ_pair=displ_pair(indsort);
990        displ_pair_dt=displ_pair_dt(indsort);
991        end
992    case 'displacement'
993        displ_pair={'Di=Dj=0'};
994        displ_pair_dt={'Di=Dj=0'};
995end
996if index==1
997    set(handles.ListPairCiv1,'String',displ_pair_dt');
998end
999
1000%% determine the default selection in the pair menu for Civ1
1001%ichoice=find(select,1);% index of first selected pair
1002%if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
1003end_pair=regexp(PairCiv1Init,' :dt=');
1004if ~isempty(end_pair)
1005    PairCiv1Init=PairCiv1Init(1:end_pair-1);
1006end
1007ichoice=find(strcmp(PairCiv1Init,displ_pair'),1);
1008if ~isempty(ichoice)
1009    set(handles.ListPairCiv1,'Value',ichoice);% first valid pair proposed by default in the menu
1010else
1011   set(handles.ListPairCiv1,'Value',1)
1012end
1013% if initial>nbpair || (numel(select)>=initial && ~isequal(select(initial),1))
1014%     set(handles.ListPairCiv1,'Value',ichoice);% first valid pair proposed by default in the menu
1015% end
1016
1017%% determine the default selection in the pair menu for Civ2
1018if strcmp(get(handles.ListPairCiv2,'Visible'),'on')
1019    end_pair=regexp(PairCiv2Init,' :dt=');
1020    if ~isempty(end_pair)
1021        PairCiv2Init=PairCiv2Init(1:end_pair-1);
1022    end
1023    ichoice=find(strcmp(PairCiv2Init,displ_pair'),1);
1024    if ~isempty(ichoice)
1025        set(handles.ListPairCiv2,'Value',ichoice);% first valid pair proposed by default in the menu
1026    else
1027        set(handles.ListPairCiv2,'Value',1)
1028    end
1029else
1030    set(handles.ListPairCiv2,'Value',get(handles.ListPairCiv1,'Value'))% initiate the choice of Civ2 as a reproduction of if civ1
1031end
1032set(handles.ListPairCiv2,'String',displ_pair_dt');
1033set(gcf,'Pointer','arrow')% Indicate that the process is finished
1034
1035
1036%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1037% Callbacks in the uipanel Reference Indices
1038%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1039%------------------------------------------------------------------------
1040function MinIndex_i_Callback(hObject, eventdata, handles)
1041%------------------------------------------------------------------------
1042first_i=str2double(get(handles.MinIndex_i,'String'));
1043set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
1044ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
1045
1046% %------------------------------------------------------------------------
1047% function MinIndex_j_Callback(hObject, eventdata, handles)
1048% %------------------------------------------------------------------------
1049% first_j=str2num(get(handles.MinIndex_j,'String'));
1050% set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
1051% ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
1052
1053%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1054% Callbacks in the uipanel Civ1
1055%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1056%------------------------------------------------------------------------
1057% --- Executes on button press in SearchRange: determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2
1058function SearchRange_Callback(hObject, eventdata, handles)
1059%------------------------------------------------------------------------
1060%determine pair numbers
1061if strcmp(get(handles.num_UMin,'Visible'),'off')
1062    set(handles.u_title,'Visible','on')
1063    set(handles.v_title,'Visible','on')
1064    set(handles.num_UMin,'Visible','on')
1065    set(handles.num_UMax,'Visible','on')
1066    set(handles.num_VMin,'Visible','on')
1067    set(handles.num_VMax,'Visible','on')
1068    %set(handles.CoordUnit,'Visible','on')
1069    %set(handles.TimeUnit,'Visible','on')
1070    %set(handles.slash_title,'Visible','on')
1071    set(handles.min_title,'Visible','on')
1072    set(handles.max_title,'Visible','on')
1073    set(handles.unit_title,'Visible','on')
1074else
1075    get_search_range(hObject, eventdata, handles)
1076end
1077
1078%------------------------------------------------------------------------
1079% ---  determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2 and shift
1080function get_search_range(hObject, eventdata, handles)
1081%------------------------------------------------------------------------
1082param_civ1=read_GUI(handles.Civ1);
1083umin=param_civ1.UMin;
1084umax=param_civ1.UMax;
1085vmin=param_civ1.VMin;
1086vmax=param_civ1.VMax;
1087%switch min_title and max_title in case of error
1088if umax<=umin
1089    umin_old=umin;
1090    umin=umax;
1091    umax=umin_old;
1092    set(handles.num_UMin,'String', num2str(umin))
1093    set(handles.num_UMax,'String', num2str(umax))
1094end
1095if vmax<=vmin
1096    vmin_old=vmin;
1097    vmin=vmax;
1098    vmax=vmin_old;
1099    set(handles.num_VMin,'String', num2str(vmin))
1100    set(handles.num_VMax,'String', num2str(vmax))
1101end   
1102if ~(isempty(umin)||isempty(umax)||isempty(vmin)||isempty(vmax))
1103    shiftx=round((umin+umax)/2);
1104    shifty=round((vmin+vmax)/2);
1105    isx=(umax+2-shiftx)*2+param_civ1.CorrBoxSize(1);
1106    isx=2*ceil(isx/2)+1;
1107    isy=(vmax+2-shifty)*2+param_civ1.CorrBoxSize(2);
1108    isy=2*ceil(isy/2)+1;
1109    set(handles.num_SearchBoxShift_1,'String',num2str(shiftx));
1110    set(handles.num_SearchBoxShift_2,'String',num2str(shifty));
1111    set(handles.num_SearchBoxSize_1,'String',num2str(isx));
1112    set(handles.num_SearchBoxSize_2,'String',num2str(isy));
1113end
1114
1115%------------------------------------------------------------------------
1116% --- Executes on selection in menu CorrSmooth.
1117function num_CorrSmooth_Callback(hObject, eventdata, handles)
1118set(handles.ConfigSource,'String','NEW')
1119set(handles.OK,'BackgroundColor',[1 0 1])
1120%------------------------------------------------------------------------
1121
1122% --- Executes on button press in CheckDeformation.
1123function CheckDeformation_Callback(hObject, eventdata, handles)
1124set(handles.ConfigSource,'String','NEW')
1125set(handles.OK,'BackgroundColor',[1 0 1])
1126handles_CoorSmooth=findobj(get(handles.Civ2,'children'),'Tag','num_CorrSmooth');
1127if get(handles.CheckDeformation,'Value')   
1128    set(handles_CoorSmooth,'Visible','off')
1129else
1130    set(handles_CoorSmooth,'Visible','on')
1131end
1132
1133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1134% Callbacks in the uipanel Fix1
1135%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1136%------------------------------------------------------------------------
1137% % --- Executes on button press in CheckMask.
1138% function get_mask_fix1_Callback(hObject, eventdata, handles)
1139% %------------------------------------------------------------------------
1140% maskval=get(handles.CheckMask,'Value');
1141% if isequal(maskval,0)
1142%     set(handles.Mask,'String','')
1143% else
1144%     mask_displ='no mask'; %default
1145%     filebase=get(handles.RootPath,'String');
1146%     [nbslice, flag_mask]=get_mask(filebase,handles);
1147%     if isequal(flag_mask,1)
1148%         mask_displ=[num2str(nbslice) 'mask'];
1149%     elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1150%         filebase_a=get(handles.RootFile_1,'String');
1151%         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1152%         if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1153%             mask_displ='no mask';
1154%         end
1155%     end
1156%     if isequal(mask_displ,'no mask')
1157%         [FileName, PathName, filterindex] = uigetfile( ...
1158%             {'*.png', ' (*.png)';
1159%             '*.png',  '.png files '; ...
1160%             '*.*', 'All Files (*.*)'}, ...
1161%             'Pick a mask file *.png',filebase);
1162%         mask_displ=fullfile(PathName,FileName);
1163%         if ~exist(mask_displ,'file')
1164%             mask_displ='no mask';
1165%         end
1166%     end
1167%     if isequal(mask_displ,'no mask')
1168%         set(handles.CheckMask,'Value',0)
1169%         set(handles.CheckMask,'Value',0)
1170%         set(handles.CheckMask,'Value',0)
1171%     else
1172%         %set(handles.CheckMask,'Value',1)
1173%         set(handles.CheckMask,'Value',1)
1174%     end
1175%     set(handles.Mask,'String',mask_displ)
1176%     set(handles.Mask,'String',mask_displ)
1177%     set(handles.Mask,'String',mask_displ)
1178% end
1179
1180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1181% Callbacks in the uipanel Civ2
1182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1183%------------------------------------------------------------------------
1184% --- Executes on button press in CheckMask: select box for mask option
1185function get_mask_civ2_Callback(hObject, eventdata, handles)
1186%------------------------------------------------------------------------
1187maskval=get(handles.CheckMask,'Value');
1188if isequal(maskval,0)
1189    set(handles.Mask,'String','')
1190else
1191    mask_displ='no mask'; %default
1192    filebase=get(handles.RootPath,'String');
1193    [nbslice, flag_mask]=get_mask(filebase,handles);
1194    if isequal(flag_mask,1)
1195        mask_displ=[num2str(nbslice) 'mask'];
1196    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1197        filebase_a=get(handles.RootFile_1,'String');
1198        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1199        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1200            mask_displ='no mask';
1201        end
1202    end
1203    if isequal(mask_displ,'no mask')
1204        [FileName, PathName, filterindex] = uigetfile( ...
1205            {'*.png', ' (*.png)';
1206            '*.png',  '.png files '; ...
1207            '*.*', 'All Files (*.*)'}, ...
1208            'Pick a mask file *.png',filebase);
1209        mask_displ=fullfile(PathName,FileName);
1210        if ~exist(mask_displ,'file')
1211            mask_displ='no mask';
1212        end
1213    end
1214    if isequal(mask_displ,'no mask')
1215        set(handles.CheckMask,'Value',0)
1216        set(handles.CheckMask,'Value',0)
1217    else
1218        set(handles.CheckMask,'Value',1)
1219    end
1220    set(handles.Mask,'String',mask_displ)
1221end
1222
1223% %------------------------------------------------------------------------
1224% % --- Executes on button press in CheckMask.
1225% function get_mask_fix2_Callback(hObject, eventdata, handles)
1226% %------------------------------------------------------------------------
1227% maskval=get(handles.CheckMask,'Value');
1228% if isequal(maskval,0)
1229%     set(handles.Mask,'String','')
1230% else
1231%     mask_displ='no mask'; %default
1232%     filebase=get(handles.RootPath,'String');
1233%     [nbslice, flag_mask]=get_mask(filebase,handles);
1234%     if isequal(flag_mask,1)
1235%         mask_displ=[num2str(nbslice) 'mask'];
1236%     elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1237%         filebase_a=get(handles.RootFile_1,'String');
1238%         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1239%         if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1240%             mask_displ='no mask';
1241%         end
1242%     end
1243%     if isequal(mask_displ,'no mask')
1244%         [FileName, PathName, filterindex] = uigetfile( ...
1245%             {'*.png', ' (*.png)';
1246%             '*.png',  '.png files '; ...
1247%             '*.*', 'All Files (*.*)'}, ...
1248%             'Pick a mask file *.png',filebase);
1249%         mask_displ=fullfile(PathName,FileName);
1250%         if ~exist(mask_displ,'file')
1251%             mask_displ='no mask';
1252%         end
1253%     end
1254%     if isequal(mask_displ,'no mask')
1255%         set(handles.CheckMask,'Value',0)
1256%     end
1257%     set(handles.Mask,'String',mask_displ)
1258% end
1259
1260%------------------------------------------------------------------------
1261% --- function called to look for mask files
1262function [nbslice, flag_mask]=get_mask(filebase,handles)
1263%------------------------------------------------------------------------
1264%detect mask files, images with appropriate file base
1265%[filebase '_' xx 'mask'], xx=nbslice
1266%flag_mask=1 indicates detection
1267
1268flag_mask=0;%default
1269nbslice=1;
1270
1271% subdir=get(handles.Civ1_ImageB,'String');
1272[Path,Name]=fileparts(filebase);
1273if ~isdir(Path)
1274    msgbox_uvmat('ERROR','no path for input files')
1275    return
1276end
1277% currentdir=pwd;
1278% cd(Path);%move in the dir of the root name filebase
1279maskfiles=dir(fullfile(Path,[Name '_*mask_*.png']));%look for mask files
1280% cd(currentdir);%come back to the current working directory
1281if ~isempty(maskfiles)
1282    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
1283    % else
1284    flag_mask=1;
1285    maskname=maskfiles(1).name;% take the first mask file in the list
1286    [Path2,Name,ext]=fileparts(maskname);
1287    Namedouble=double(Name);
1288    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1289    ind_mask=findstr('mask',Name);
1290    i=ind_mask-1;
1291    while val(i)==0 && i>0
1292        i=i-1;
1293    end
1294    nbslice=str2double(Name(i+1:ind_mask-1));
1295    if ~isnan(nbslice) && Name(i)=='_'
1296        flag_mask=1;
1297    else
1298        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
1299        return
1300        nbslice=1;
1301    end
1302end
1303
1304%------------------------------------------------------------------------
1305% --- function called to look for grid files
1306function [nbslice, flag_grid]=get_grid(filebase,handles)
1307%------------------------------------------------------------------------
1308flag_grid=0;%default
1309nbslice=1;
1310[Path,Name]=fileparts(filebase);
1311currentdir=pwd;
1312cd(Path);%move in the dir of the root name filebase
1313gridfiles=dir([Name '_*grid_*.grid']);%look for grid files
1314cd(currentdir);%come back to the current working directory
1315if ~isempty(gridfiles)
1316    flag_grid=1;
1317    gridname=gridfiles(1).name;% take the first grid file in the list
1318    [Path2,Name,ext]=fileparts(gridname);
1319    Namedouble=double(Name);
1320    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1321    ind_grid=findstr('grid',Name);
1322    i=ind_grid-1;
1323    while val(i)==0 && i>0
1324        i=i-1;
1325    end
1326    nbslice=str2double(Name(i+1:ind_grid-1));
1327    if ~isnan(nbslice) && Name(i)=='_'
1328        flag_grid=1;
1329    else
1330        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
1331        return
1332        nbslice=1;
1333    end
1334end
1335
1336%------------------------------------------------------------------------
1337% --- transform numbers to letters
1338function str=num2stra(num,nom_type)
1339%------------------------------------------------------------------------
1340if isempty(nom_type)
1341    str='';
1342elseif strcmp(nom_type(end),'a')
1343    str=char(96+num);
1344elseif strcmp(nom_type(end),'A')
1345    str=char(96+num);
1346elseif isempty(nom_type(2:end))%a single index
1347    str='';
1348else
1349    str=num2str(num);
1350end
1351
1352% %------------------------------------------------------------------------
1353% % --- Executes on button press in ListSubdirCiv1.
1354% function ListSubdirCiv1_Callback(hObject, eventdata, handles)
1355% %------------------------------------------------------------------------
1356% list_subdir_civ1=get(handles.ListSubdirCiv1,'String');
1357% val=get(handles.ListSubdirCiv1,'Value');
1358% SubDir=list_subdir_civ1{val};
1359% if strcmp(SubDir,'new...')
1360%     if get(handles.CheckCiv1,'Value')
1361%         SubDir='CIV_INPUT'; %default subdirectory
1362%     else
1363%         msgbox_uvmat('ERROR','select CheckCiv1 to perform a new civ_input operation')
1364%         return
1365%     end   
1366% end
1367% set(handles.Civ1_ImageB,'String',SubDir);
1368% errormsg=find_netcpair_civ(handles,1);
1369% if ~isempty(errormsg)
1370%     msgbox_uvmat('ERROR',errormsg)
1371% end
1372%     
1373%------------------------------------------------------------------------
1374% % --- Executes on button press in ListSubdirCiv2.
1375% function ListSubdirCiv2_Callback(hObject, eventdata, handles)
1376% %------------------------------------------------------------------------
1377% list_subdir_civ2=get(handles.ListSubdirCiv2,'String');
1378% val=get(handles.ListSubdirCiv2,'Value');
1379% SubDir=list_subdir_civ2{val};
1380% if strcmp(SubDir,'new...')
1381%     if get(handles.CheckCiv2,'Value')
1382%         SubDir='CIV_INPUT'; %default subdirectory
1383%     else
1384%         msgbox_uvmat('ERROR','select CheckCiv2 to perform a new civ_input operation')
1385%         return
1386%     end
1387% end
1388% set(handles.Civ2_ImageA,'String',SubDir);
1389
1390%------------------------------------------------------------------------
1391% --- Executes on button press in CheckGrid.
1392function CheckGrid_Callback(hObject, eventdata, handles)
1393%------------------------------------------------------------------------
1394value=get(hObject,'Value');
1395hparent=get(hObject,'parent');%handles of the parent panel
1396hchildren=get(hparent,'children');
1397handle_txtbox=findobj(hchildren,'tag','Grid');% look for the grid name box in the same panel
1398handle_dx=findobj(hchildren,'tag','num_Dx');
1399handle_dy=findobj(hchildren,'tag','num_Dy');
1400handle_title_dx=findobj(hchildren,'tag','title_Dx');
1401handle_title_dy=findobj(hchildren,'tag','title_Dy');
1402testgrid=0;
1403filegrid='';
1404if value
1405        hseries=findobj(allchild(0),'Tag','series');
1406    hhseries=guidata(hseries);
1407    InputTable=get(hhseries.InputTable,'Data');
1408     ind_A=1;% line index of the (first) image series
1409    if strcmp(InputTable{1,5},'.nc');
1410        ind_A=2;
1411    end
1412    filebase=InputTable{ind_A,1};
1413    [nbslice, flag_grid]=get_grid(filebase,handles);% look for a grid with appropriate name
1414    if isequal(flag_grid,1)
1415        filegrid=[num2str(nbslice) 'grid'];
1416        testgrid=1;
1417    else % browse for a grid
1418        filegrid=get(hObject,'UserData');%look for previous grid name stored as UserData
1419        if exist(filegrid,'file')
1420            filebase=filegrid;
1421        end
1422       filegrid = uigetfile_uvmat('pick a grid file .grid:',filebase,'.grid');
1423        set(hObject,'UserData',filegrid);%store for future use
1424        if ~isempty(filegrid)
1425            testgrid=1;
1426        end
1427        set(hObject,'UserData',filegrid);%store for future use
1428    end
1429end
1430if testgrid
1431    set(handle_dx,'Visible','off');
1432    set(handle_dy,'Visible','off');
1433    set(handle_title_dy,'Visible','off');
1434    set(handle_title_dx,'Visible','off');
1435    set(handle_txtbox,'Visible','on')
1436    set(handle_txtbox,'String',filegrid)
1437else
1438    set(hObject,'Value',0);
1439    set(handle_dx,'Visible','on');
1440    set(handle_dy,'Visible','on');
1441    set(handle_title_dy,'Visible','on');
1442    set(handle_title_dx,'Visible','on');
1443    set(handle_txtbox,'Visible','off')
1444end
1445
1446%% if hObject is on the checkciv1 frame, duplicate action for checkciv2 frame
1447PanelName=get(hparent,'tag');
1448if strcmp(PanelName,'Civ1')
1449    hchildren=get(handles.Civ2,'children');
1450    handle_checkbox=findobj(hchildren,'tag','CheckGrid');
1451    handle_txtbox=findobj(hchildren,'tag','Grid');
1452    handle_dx=findobj(hchildren,'tag','num_Dx');
1453    handle_dy=findobj(hchildren,'tag','num_Dy');
1454    handle_title_dx=findobj(hchildren,'tag','title_Dx');
1455    handle_title_dy=findobj(hchildren,'tag','title_Dy');
1456    set(handle_checkbox,'UserData',filegrid);%store for future use
1457    if testgrid
1458        set(handle_checkbox,'Value',1);
1459        set(handle_dx,'Visible','off');
1460        set(handle_dy,'Visible','off');
1461        set(handle_title_dx,'Visible','off');
1462        set(handle_title_dy,'Visible','off');
1463        set(handle_txtbox,'Visible','on')
1464        set(handle_txtbox,'String',filegrid)
1465    end
1466end
1467set(handles.ConfigSource,'String','NEW')
1468set(handles.OK,'BackgroundColor',[1 0 1])
1469
1470%------------------------------------------------------------------------
1471% --- Executes on button press in CheckMask: common to all panels (civ1, Civ2..)
1472function CheckMask_Callback(hObject, eventdata, handles)
1473%------------------------------------------------------------------------
1474value=get(hObject,'Value');
1475hparent=get(hObject,'parent');
1476parent_tag=get(hparent,'Tag');
1477hchildren=get(hparent,'children');
1478handle_txtbox=findobj(hchildren,'tag','Mask');% look for the mask name box in the same panel
1479handle_NbSlice=findobj(hchildren,'tag','num_NbSlice');% look for the mask name box in the same panel
1480testmask=0;
1481if value
1482    hseries=findobj(allchild(0),'Tag','series');
1483    hhseries=guidata(hseries);
1484    InputTable=get(hhseries.InputTable,'Data');
1485    ind_A=1;% line index of the (first) image series
1486    if strcmp(InputTable{1,5},'.nc');
1487        ind_A=2;
1488    end
1489 % browse for a mask
1490        filemask= uigetfile_uvmat('pick a mask image file:',InputTable{ind_A,1},'image');
1491        [FilePath,FileName,Ext]=fileparts(filemask);   
1492        [RootPath,SubDir,RootFile,i1_series,i2,j1,j2,NomType]=find_file_series(FilePath,[FileName,Ext]);
1493        if strcmp(NomType,'_1')
1494           NbSlice=i1_series(1,2,end);
1495           set(handles.num_NbSlice,'String',num2str(NbSlice))
1496        end
1497        set(hObject,'UserData',filemask);%store for future use
1498        if ~isempty(filemask)
1499            testmask=1;
1500        end
1501end
1502if testmask
1503    set(handles.Mask,'Visible','on')
1504    set(handles.Mask,'String',filemask)
1505    set(handles.CheckMask,'Value',1)
1506    if strcmp(NomType,'_1')
1507        set(handles.num_NbSlice,'Visible','on')
1508    end
1509else
1510    set(hObject,'Value',0);
1511    set(handle_txtbox,'Visible','off')
1512    set(handles.num_NbSlice,'Visible','off')
1513end
1514set(handles.ConfigSource,'String','NEW')
1515set(handles.ConfigSource,'BackgroundColor',[1 0 1])
1516
1517% %------------------------------------------------------------------------
1518% % --- Executes on button press in get_gridpatch1.
1519% function get_gridpatch1_Callback(hObject, eventdata, handles)
1520% %------------------------------------------------------------------------
1521% filebase=get(handles.RootPath,'String');
1522% [FileName, PathName, filterindex] = uigetfile( ...
1523%     {'*.grid', ' (*.grid)';
1524%     '*.grid',  '.grid files '; ...
1525%     '*.*', 'All Files (*.*)'}, ...
1526%     'Pick a file',filebase);
1527% filegrid=fullfile(PathName,FileName);
1528% set(handles.grid_patch1,'string',filegrid);
1529% set(hObject,'BackgroundColor',[1 0 1])
1530
1531%------------------------------------------------------------------------
1532% --- STEREO Interp
1533function cmd=RUN_STINTERP(stinterpBin,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
1534%------------------------------------------------------------------------
1535namelog=[filename_nc(1:end-3) '_stinterp.log'];
1536cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
1537    ' -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
1538
1539% %------------------------------------------------------------------------
1540% %--read images and convert them to the uint16 format used for PIV
1541% function A=read_image(filename,type_ima,num,movieobject)
1542% %------------------------------------------------------------------------
1543% %num is the view number needed for an avi movie
1544% switch type_ima
1545%     case 'movie'
1546%         A=read(movieobject,num);
1547%     case 'avi'
1548%         mov=aviread(filename,num);
1549%         A=frame2im(mov(1));
1550%     case 'multimage'
1551%         A=imread(filename,num);
1552%     case 'image'
1553%         A=imread(filename);
1554% end
1555% siz=size(A);
1556% if length(siz)==3;%color images
1557%     A=sum(double(A),3);
1558%     A=uint16(A);
1559% end
1560
1561
1562%------------------------------------------------------------------------
1563% --- Executes on button press in get_ref_fix1.
1564function get_ref_fix1_Callback(hObject, eventdata, handles)
1565%------------------------------------------------------------------------
1566filebase=get(handles.RootPath,'String');
1567[FileName, PathName, filterindex] = uigetfile( ...
1568    {'*.nc', ' (*.nc)';
1569    '*.nc',  'netcdf files '; ...
1570    '*.*', 'All Files (*.*)'}, ...
1571    'Pick a file',filebase);
1572
1573fileinput=[PathName FileName];
1574sizf=size(fileinput);
1575if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1576%[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1577[Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1578ref.filebase=fullfile(Path,File);
1579% ref.num_a=stra2num(str_a);
1580% ref.num_b=stra2num(str_b);
1581% ref.num1=str2double(field_count);
1582% ref.num2=str2double(str2);
1583browse=[];%initialisation
1584if ~isequal(ref.ext,'.nc')
1585    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1586    return
1587end
1588set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
1589set(handles.ref_fix1,'UserData',ref)
1590menu_field{1}='civ1';
1591Data=nc2struct(fileinput,[]);
1592if isfield(Data,'patch') && isequal(Data.patch,1)
1593    menu_field{2}='filter1';
1594end
1595if isfield(Data,'civ2') && isequal(Data.civ2,1)
1596    menu_field{3}='civ2';
1597end
1598if isfield(Data,'patch2') && isequal(Data.patch2,1)
1599    menu_field{4}='filter2';
1600end
1601set(handles.field_ref1,'String',menu_field);
1602set(handles.field_ref1,'Value',length(menu_field));
1603set(handles.num_MinVel,'Value',2);
1604set(handles.num_MinVel,'String','1');%default threshold
1605set(handles.ref_fix1,'Enable','on')
1606
1607%------------------------------------------------------------------------
1608% --- Executes on button press in get_ref_fix2.
1609function get_ref_fix2_Callback(hObject, eventdata, handles)
1610%------------------------------------------------------------------------
1611if isequal(get(handles.get_ref_fix2,'Value'),1)
1612    filebase=get(handles.RootPath,'String');
1613    [FileName, PathName, filterindex] = uigetfile( ...
1614        {'*.nc', ' (*.nc)';
1615        '*.nc',  'netcdf files '; ...
1616        '*.*', 'All Files (*.*)'}, ...
1617        'Pick a file',filebase);
1618    fileinput=[PathName FileName];
1619    sizf=size(fileinput);
1620    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1621    %[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1622    [Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1623    ref.filebase=fullfile(Path,File);
1624    %     ref.num_a=stra2num(str_a);
1625    %     ref.num_b=stra2num(str_b);
1626    %     ref.num1=str2num(field_count);
1627    %     ref.num2=str2num(str2);
1628    browse=[];%initialisation
1629    if ~isequal(ref.ext,'.nc')
1630        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1631        return
1632    end
1633    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
1634    set(handles.ref_fix2,'UserData',ref)
1635    menu_field{1}='civ1';
1636    Data=nc2struct(fileinput,[]);
1637    if isfield(Data,'patch') && isequal(Data.patch,1)
1638        menu_field{2}='filter1';
1639    end
1640    if isfield(Data,'civ2') && isequal(Data.civ2,1)
1641        menu_field{3}='civ2';
1642    end
1643    if isfield(Data,'patch2') && isequal(Data.patch2,1)
1644        menu_field{4}='filter2';
1645    end
1646    set(handles.field_ref2,'String',menu_field);
1647    set(handles.field_ref2,'Value',length(menu_field));
1648    set(handles.num_MinVel,'Value',2);
1649    set(handles.num_MinVel,'String','1');%default threshold
1650    set(handles.ref_fix2,'Enable','on')
1651    set(handles.ref_fix2,'Visible','on')
1652    set(handles.field_ref2,'Visible','on')
1653else
1654    set(handles.ref_fix2,'Visible','off')
1655    set(handles.field_ref2,'Visible','off')
1656end
1657
1658%------------------------------------------------------------------------
1659function ref_fix1_Callback(hObject, eventdata, handles)
1660%------------------------------------------------------------------------
1661set(handles.num_MinVel,'Value',1);
1662set(handles.field_ref1,'Value',1)
1663set(handles.field_ref1,'String',{' '})
1664set(handles.ref_fix1,'UserData',[]);
1665set(handles.ref_fix1,'String','');
1666set(handles.thresh_vel1,'String','0');
1667
1668%------------------------------------------------------------------------
1669function ref_fix2_Callback(hObject, eventdata, handles)
1670%------------------------------------------------------------------------
1671set(handles.num_MinVel,'Value',1);
1672set(handles.field_ref2,'Value',1)
1673set(handles.field_ref2,'String',{' '})
1674set(handles.ref_fix2,'UserData',[]);
1675set(handles.ref_fix2,'String','');
1676set(handles.num_MinVel,'String','0');
1677
1678%------------------------------------------------------------------------
1679% --- TO ABANDON Executes on button press in test_stereo1.
1680function CheckStereo_Callback(hObject, eventdata, handles)
1681%------------------------------------------------------------------------
1682hparent=get(hObject,'parent');
1683parent_tag=get(hparent,'Tag');
1684hchildren=get(hparent,'children');
1685handle_txtbox=findobj(hchildren,'tag','txt_Mask');
1686if isequal(get(hObject,'Value'),0)
1687    set(handles.num_SubDomainSize,'Visible','on')
1688    set(handles.num_FieldSmooth,'Visible','on')
1689else
1690    set(handles.num_SubDomainSize,'Visible','off')
1691    set(handles.num_FieldSmooth,'Visible','off')
1692end
1693
1694% %------------------------------------------------------------------------
1695% % --- Executes on button press in CheckStereo.
1696% function StereoCheck_Callback(hObject, eventdata, handles)
1697% %------------------------------------------------------------------------
1698% if isequal(get(handles.CheckStereo,'Value'),0)
1699%     set(handles.num_subdomainsize,'Visible','on')
1700%     set(handles.num_FieldSmooth,'Visible','on')
1701% else
1702
1703%     set(handles.num_subdomainsize,'Visible','off')
1704%     set(handles.num_FieldSmooth,'Visible','off')
1705% end
1706
1707
1708
1709%------------------------------------------------------------------------
1710%----function introduced for the correlation window figure, activated by deleting this window
1711function closeview_field(gcbo,eventdata)
1712%------------------------------------------------------------------------
1713hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1714if ~isempty(hview_field)
1715    delete(hview_field)
1716end
1717
1718%------------------------------------------------------------------------
1719% --- Executes on button press in CheckThreshold.
1720function CheckThreshold_Callback(hObject, eventdata, handles)
1721%------------------------------------------------------------------------
1722huipanel=get(hObject,'parent');
1723obj(1)=findobj(huipanel,'Tag','num_MinIma');
1724obj(2)=findobj(huipanel,'Tag','num_MaxIma');
1725obj(3)=findobj(huipanel,'Tag','title_Threshold');
1726if get(hObject,'Value')
1727    set(obj,'Visible','on')
1728else
1729    set(obj,'Visible','off')
1730end
1731set(handles.ConfigSource,'String','NEW')
1732set(handles.OK,'BackgroundColor',[1 0 1])
1733%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1734%%%%%%%%%%%%%%   TEST functions
1735%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1736%------------------------------------------------------------------------
1737% --- Executes on button press in TestCiv1: prepare the image correlation function
1738%     activated by mouse motion
1739function TestCiv1_Callback(hObject, eventdata, handles)
1740%------------------------------------------------------------------------
1741drawnow
1742if get(handles.TestCiv1,'Value')
1743    set(handles.TestCiv1,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch 
1744    set(handles.CheckFix1,'value',0)% desactivate next step
1745    set(handles.CheckPatch1,'value',0)% desactivate next step
1746    set(handles.CheckCiv2,'value',0)% desactivate next step
1747    set(handles.CheckFix2,'value',0)% desactivate next step
1748    set(handles.CheckPatch2,'value',0)% desactivate next step
1749    update_CivOptions(handles,0)
1750      hseries=findobj(allchild(0),'Tag','series');
1751     Param=read_GUI(hseries);
1752     Param.Action.RUN=1;
1753     Param.ActionInput=read_GUI(handles.civ_input);
1754     if isfield(Param.ActionInput,'Fix1')
1755         Param.ActionInput=rmfield(Param.ActionInput,'Fix1');
1756     end
1757     if isfield(Param.ActionInput,'Patch1')
1758         Param.ActionInput=rmfield(Param.ActionInput,'Patch1');
1759     end
1760     if isfield(Param.ActionInput,'Civ2')%remove options that may be selected beyond Patch1
1761         Param.ActionInput=rmfield(Param.ActionInput,'Civ2');
1762     end
1763     if isfield(Param.ActionInput,'Fix2')
1764         Param.ActionInput=rmfield(Param.ActionInput,'Fix2');
1765     end
1766     if isfield(Param.ActionInput,'Patch2')
1767         Param.ActionInput=rmfield(Param.ActionInput,'Patch2');
1768     end
1769     if isfield(Param,'OutputSubDir')
1770     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
1771     end
1772     Param.ActionInput.Civ1.CorrSmooth=0;% launch Civ1 with no data point (to get the image names for A and B)
1773     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
1774     Param.IndexRange.last_i=str2num(get(handles.ref_i,'String'));
1775     if strcmp(get(handles.ref_j,'Visible'),'on')
1776         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
1777         Param.IndexRange.last_j=Param.IndexRange.first_j;
1778     else
1779         Param.IndexRange.first_j=1;
1780         Param.IndexRange.last_j=1;
1781     end
1782     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
1783     if ~isempty(errormsg), return, end % rmq: error msg displayed in civ_series
1784     
1785 %% create image data ImageData for display
1786     ImageData.ListVarName={'ny','nx','A'};
1787     ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
1788     ImageData.A=imread(Data.Civ1_ImageA); % read the first image
1789     if ndims(ImageData.A)==3 %case of color image
1790         ImageData.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
1791     end
1792     ImageData.ny=[size(ImageData.A,1) 1];
1793     ImageData.nx=[1 size(ImageData.A,2)];
1794     ImageData.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
1795
1796     %% create the figure view_field for image visualization
1797     hview_field=view_field(ImageData); %view the image in the GUI view_field
1798     set(0,'CurrentFigure',hview_field)
1799     hhview_field=guihandles(hview_field);
1800     set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
1801     ViewData=get(hview_field,'UserData');
1802     ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
1803     ViewData.PlotAxes.X=Data.Civ1_X';
1804     ViewData.PlotAxes.Y=Data.Civ1_Y';
1805     ViewData.PlotAxes.B=imread(Data.Civ1_ImageB);%store the second image in the UserData of the GUI view_field
1806     set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
1807   
1808    %% look for a current figure for image correlation display
1809    corrfig=findobj(allchild(0),'tag','corrfig');
1810    if isempty(corrfig)
1811        corrfig=figure;
1812        set(corrfig,'tag','corrfig')
1813        set(corrfig,'name','image correlation')
1814        set(corrfig,'DeleteFcn',{@closeview_field})%
1815        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
1816    else
1817        set(handles.TestCiv1,'BackgroundColor',[1 0 0])% paint button to red
1818        corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1819        if ~isempty(corrfig)
1820            delete(corrfig)
1821        end
1822        hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1823        if ~isempty(hview_field)
1824            delete(hview_field)
1825        end
1826    end
1827else
1828    hview_field=findobj(allchild(0),'Tag','view_field'); %view the image in the GUI view_field
1829    if ~isempty(hview_field)
1830        delete(hview_field)
1831    end     
1832end
1833
1834% --------------------------------------------------------------------
1835% --- Executes on button press in TestPatch1.
1836% --------------------------------------------------------------------
1837function TestPatch1_Callback(hObject, eventdata, handles)
1838
1839if get(handles.TestPatch1,'Value')% if TestPatch1 is activated
1840     set(handles.TestPatch1,'BackgroundColor',[1 1 0])%paint TestPatch1 button in yellow to indicate activation
1841     set(handles.Civ1,'BackgroundColor',[1 1 0])% indicate civ1 calculation is performed
1842     hseries=findobj(allchild(0),'Tag','series');
1843     Param=read_GUI(hseries);
1844     Param.Action.RUN=1;
1845     Param.ActionInput=read_GUI(handles.civ_input);
1846     if isfield(Param.ActionInput,'Civ2')%remove options that may be selected beyond Patch1
1847         Param.ActionInput=rmfield(Param.ActionInput,'Civ2');
1848     end
1849     if isfield(Param.ActionInput,'Fix2')
1850         Param.ActionInput=rmfield(Param.ActionInput,'Fix2');
1851     end
1852     if isfield(Param.ActionInput,'Patch2')
1853         Param.ActionInput=rmfield(Param.ActionInput,'Patch2');
1854     end
1855     if isfield(Param,'OutputSubDir')
1856         Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
1857     end
1858     ParamPatch1=Param.ActionInput.Patch1; %store the patch1 parameters
1859     Param.ActionInput=rmfield(Param.ActionInput,'Patch1');% does not execute Patch
1860     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
1861     Param.IndexRange.last_i=Param.IndexRange.first_i;
1862     if strcmp(get(handles.ref_j,'Visible'),'on')
1863         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
1864         Param.IndexRange.last_j=Param.IndexRange.first_j;
1865     else
1866         Param.IndexRange.first_j=1;
1867         Param.IndexRange.last_j=1;
1868     end
1869     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
1870     bckcolor=get(handles.civ_input,'Color');
1871     set(handles.Civ1,'BackgroundColor',bckcolor)% indicate civ1 calculation is finished
1872     
1873     %% prepare Param for iterative Patch processing without input file reading
1874     Param.Civ1_X=Data.Civ1_X;
1875     Param.Civ1_Y=Data.Civ1_Y;
1876     Param.Civ1_U=Data.Civ1_U;
1877     Param.Civ1_V=Data.Civ1_V;
1878     Param.Civ1_FF=Data.Civ1_FF;
1879     Param=rmfield(Param,'InputTable');%desactivate input file reading
1880    if isfield(Param.ActionInput,'Civ1')
1881        Param.ActionInput=rmfield(Param.ActionInput,'Civ1');%desactivate civ1: remove civ1 input param if relevant
1882    end
1883    if isfield(Param.ActionInput,'Fix1')
1884        Param.ActionInput=rmfield(Param.ActionInput,'Fix1');%desactivate fix1:remove fix1 input param if relevant
1885    end
1886    SmoothingParam=(ParamPatch1.FieldSmooth/10)*2.^(1:7);%scan the smoothing param from 1/10 to 12.8 current value
1887    NbGood=numel(find(Data.Civ1_FF==0));
1888    NbExclude=zeros(1,7);% initialize the set of smoothing parameters
1889    DiffVel=zeros(1,7);% initialize the rms difference between patch and civ
1890    Param.ActionInput.Patch1=ParamPatch1;% retrieve Patch1 parameters
1891    for irho=1:7
1892        Param.ActionInput.Patch1.FieldSmooth=SmoothingParam(irho);
1893        [Data,errormsg]= civ_series(Param);%apply the processing fct
1894        if ~isempty(errormsg)
1895            msgbox_uvmat('ERROR',errormsg)
1896            return
1897        end
1898        ind_good=find(Data.Civ1_FF==0);
1899        Civ1_U_Diff=Data.Civ1_U(ind_good)-Data.Civ1_U_smooth(ind_good);
1900        Civ1_V_Diff=Data.Civ1_V(ind_good)-Data.Civ1_V_smooth(ind_good);
1901        DiffVel(irho)=sqrt(mean(Civ1_U_Diff.*Civ1_U_Diff+Civ1_V_Diff.*Civ1_V_Diff));
1902        NbExclude(irho)=(NbGood-numel(ind_good))/NbGood;
1903    end
1904    figure(1)
1905    semilogx(SmoothingParam,DiffVel,'b',SmoothingParam,NbExclude,'r',SmoothingParam,0.2*ones(size(SmoothingParam)),'m')
1906    grid on
1907    legend('rms velocity diff. Patch1-Civ1 (pixels)','proportion of excluded vectors (between 0 to 1)','recommended diff Patch1-Civ1')
1908    xlabel('smoothing parameter')
1909    ylabel('smoothing effect')
1910    set(handles.TestPatch1,'BackgroundColor',[0 1 0])
1911else
1912    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1913    if ~isempty(corrfig)
1914        delete(corrfig)
1915    end
1916    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1917    if ~isempty(hview_field)
1918        delete(hview_field)
1919    end
1920end
1921
1922%------------------------------------------------------------------------
1923% --- Executes on button press in TestCiv2.
1924%------------------------------------------------------------------------
1925function TestCiv2_Callback(hObject, eventdata, handles)
1926drawnow
1927if get(handles.TestCiv2,'Value')
1928    set(handles.TestCiv2,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch
1929    set(handles.CheckFix2,'value',0)% desactivate next step
1930    set(handles.CheckPatch2,'value',0)% desactivate next step
1931    update_CivOptions(handles,0)
1932      hseries=findobj(allchild(0),'Tag','series');
1933     Param=read_GUI(hseries);
1934     Param.Action.RUN=1;
1935     Param.ActionInput=read_GUI(handles.civ_input);
1936     if isfield(Param,'OutputSubDir')
1937     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
1938     end
1939     Param.ActionInput.Civ2.CorrSmooth=0;% launch Civ2 with no data point (to get the image names for A and B)
1940     set(handles.Civ1,'BackgroundColor',[1 1 0])
1941     set(handles.Fix1,'BackgroundColor',[1 1 0])
1942     set(handles.Patch1,'BackgroundColor',[1 1 0])
1943     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
1944     Param.IndexRange.last_i=Param.IndexRange.first_i;
1945     if strcmp(get(handles.ref_j,'Visible'),'on')
1946         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
1947         Param.IndexRange.last_j=Param.IndexRange.first_j;
1948     else
1949         Param.IndexRange.first_j=1;
1950         Param.IndexRange.last_j=1;
1951     end
1952     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
1953     
1954     %% create image data ImageData for display
1955     ImageData.ListVarName={'ny','nx','A'};
1956     ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
1957     ImageData.A=imread(Data.Civ2_ImageA); % read the first image
1958     if ndims(ImageData.A)==3 %case of color image
1959         ImageData.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
1960     end
1961     ImageData.ny=[size(ImageData.A,1) 1];
1962     ImageData.nx=[1 size(ImageData.A,2)];
1963     ImageData.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
1964
1965     %% create the figure view_field for image visualization
1966    hview_field=view_field(ImageData); %view the image in the GUI view_field
1967    set(0,'CurrentFigure',hview_field)
1968    % plot the boundaries of the subdomains used for patch
1969    for isub=1:size(Data.Civ1_SubRange,3);
1970        pos_x=Data.Civ1_SubRange(1,1,isub);
1971        pos_y=Data.Civ1_SubRange(2,1,isub);
1972        width=Data.Civ1_SubRange(1,2,isub)-Data.Civ1_SubRange(1,1,isub);
1973        height=Data.Civ1_SubRange(2,2,isub)-Data.Civ1_SubRange(2,1,isub);
1974        rectangle('Position',[pos_x pos_y width height],'EdgeColor',[0 0 1])
1975    end
1976    hhview_field=guihandles(hview_field);%
1977    set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
1978    ViewData=get(hview_field,'UserData'); % get the currently plotted field (the image A)
1979    % store info in the UserData of view-field
1980    ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
1981    ViewData.PlotAxes.B=imread(Data.Civ2_ImageB);%store the second image in the UserData of the GUI view_field
1982    ViewData.PlotAxes.X=Data.Civ2_X';
1983    ViewData.PlotAxes.Y=Data.Civ2_Y';
1984    ViewData.PlotAxes.ShiftX=Data.Civ2_U';% shift at each point (from patch1) estimated by the preliminary run of civ2
1985    ViewData.PlotAxes.ShiftY=Data.Civ2_V';
1986    ViewData.PlotAxes.Civ1_SubRange=Data.Civ1_SubRange;
1987    ViewData.PlotAxes.Civ1_NbCentres=Data.Civ1_NbCentres;
1988    ViewData.PlotAxes.Civ1_Coord_tps=Data.Civ1_Coord_tps;
1989    ViewData.PlotAxes.Civ1_U_tps=Data.Civ1_U_tps;
1990    ViewData.PlotAxes.Civ1_V_tps=Data.Civ1_V_tps;
1991    ViewData.PlotAxes.Civ1_Dt=Data.Civ1_Dt;
1992    ViewData.PlotAxes.Civ2_Dt=Data.Civ2_Dt;
1993    set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
1994    bckcolor=get(handles.civ_input,'Color');
1995    set(handles.Civ1,'BackgroundColor',bckcolor)% indicate civ1 calmculation is finished
1996    set(handles.Fix1,'BackgroundColor',bckcolor)
1997    set(handles.Patch1,'BackgroundColor',bckcolor)
1998    drawnow
1999   
2000    %% look for a current figure for image correlation display
2001    corrfig=findobj(allchild(0),'tag','corrfig');
2002    if isempty(corrfig)
2003        corrfig=figure;
2004        set(corrfig,'tag','corrfig')
2005        set(corrfig,'name','image correlation')
2006        set(corrfig,'DeleteFcn',{@closeview_field})%
2007        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
2008    else
2009        set(handles.TestCiv1,'BackgroundColor',[1 0 0])% paint button to red
2010        corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
2011        if ~isempty(corrfig)
2012            delete(corrfig)
2013        end
2014        hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
2015        if ~isempty(hview_field)
2016            delete(hview_field)
2017        end
2018    end   
2019else
2020    hview_field=findobj(allchild(0),'Tag','view_field'); %view the image in the GUI view_field
2021    if ~isempty(hview_field)
2022        delete(hview_field)
2023    end     
2024end
2025
2026
2027% --- Executes on button press in TestPatch2.
2028function TestPatch2_Callback(hObject, eventdata, handles)
2029if get(handles.TestPatch2,'Value')% if TestPatch2 is activated
2030     set(handles.TestPatch2,'BackgroundColor',[1 1 0])%paint TestPatch2 button in yellow to indicate activation
2031     set(handles.Civ1,'BackgroundColor',[1 1 0])% indicate civ1 calculation is activated
2032     set(handles.Fix1,'BackgroundColor',[1 1 0])% indicate fix1 calculation is activated
2033     set(handles.Patch1,'BackgroundColor',[1 1 0])% indicate Patch1 calculation is activated
2034     set(handles.Civ2,'BackgroundColor',[1 1 0])% indicate civ2 calculation is activated
2035     set(handles.Fix2,'BackgroundColor',[1 1 0])% indicate fix2 calculation is activated
2036     hseries=findobj(allchild(0),'Tag','series');
2037     Param=read_GUI(hseries);
2038     Param.Action.RUN=1;
2039     Param.ActionInput=read_GUI(handles.civ_input);
2040     if isfield(Param,'OutputSubDir')
2041     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
2042     end
2043     ParamPatch2=Param.ActionInput.Patch2; %store the patch1 parameters
2044     Param.ActionInput=rmfield(Param.ActionInput,'Patch2');% does not execute Patch
2045     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
2046     Param.IndexRange.last_i=Param.IndexRange.first_i;
2047     if strcmp(get(handles.ref_j,'Visible'),'on')
2048         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
2049         Param.IndexRange.last_j=Param.IndexRange.first_j;
2050     else
2051         Param.IndexRange.first_j=1;
2052         Param.IndexRange.last_j=1;
2053     end
2054     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
2055     bckcolor=get(handles.civ_input,'Color');
2056     set(handles.Civ1,'BackgroundColor',bckcolor)% indicate civ1 calculation is finished
2057     set(handles.Fix1,'BackgroundColor',bckcolor)% indicate fix1 calculation is finished
2058     set(handles.Patch1,'BackgroundColor',bckcolor)% indicate Patch1 calculation is finished
2059     set(handles.Civ2,'BackgroundColor',bckcolor)% indicate civ2 calculation is finished
2060     set(handles.Fix2,'BackgroundColor',bckcolor)% indicate fix2 calculation is finished
2061     
2062     %% prepare Param for iterative Patch processing without input file reading
2063     Param.Civ2_X=Data.Civ2_X;
2064     Param.Civ2_Y=Data.Civ2_Y;
2065     Param.Civ2_U=Data.Civ2_U;
2066     Param.Civ2_V=Data.Civ2_V;
2067     Param.Civ2_FF=Data.Civ2_FF;
2068     Param=rmfield(Param,'InputTable');%desactivate input file reading
2069    if isfield(Param.ActionInput,'Civ1')
2070        Param.ActionInput=rmfield(Param.ActionInput,'Civ1');%desactivate civ1: remove civ1 input param if relevant
2071    end
2072    if isfield(Param.ActionInput,'Fix1')
2073        Param.ActionInput=rmfield(Param.ActionInput,'Fix1');%desactivate fix1:remove fix1 input param if relevant
2074    end
2075    if isfield(Param.ActionInput,'Patch1')
2076        Param.ActionInput=rmfield(Param.ActionInput,'Patch1');%desactivate fix1:remove fix1 input param if relevant
2077    end
2078    if isfield(Param.ActionInput,'Civ2')
2079        Param.ActionInput=rmfield(Param.ActionInput,'Civ2');%desactivate civ2: remove civ2 input param if relevant
2080    end
2081    if isfield(Param.ActionInput,'Fix2')
2082        Param.ActionInput=rmfield(Param.ActionInput,'Fix2');%desactivate fix1:remove fix1 input param if relevant
2083    end
2084    SmoothingParam=(ParamPatch2.FieldSmooth/10)*2.^(1:7);%scan the smoothing param from 1/10 to 12.8 current value
2085    NbGood=numel(find(Data.Civ2_FF==0));
2086    NbExclude=zeros(1,7);% initialize the set of smoothing parameters
2087    DiffVel=zeros(1,7);% initialize the rms difference between patch and civ
2088    Param.ActionInput.Patch2=ParamPatch2;% retrieve Patch2 parameters
2089    for irho=1:7
2090        Param.ActionInput.Patch2.FieldSmooth=SmoothingParam(irho);
2091        [Data,errormsg]= civ_series(Param);%apply the processing fct
2092        if ~isempty(errormsg)
2093            msgbox_uvmat('ERROR',errormsg)
2094            return
2095        end
2096        ind_good=find(Data.Civ2_FF==0);
2097        Civ2_U_Diff=Data.Civ2_U(ind_good)-Data.Civ2_U_smooth(ind_good);
2098        Civ2_V_Diff=Data.Civ2_V(ind_good)-Data.Civ2_V_smooth(ind_good);
2099        DiffVel(irho)=sqrt(mean(Civ2_U_Diff.*Civ2_U_Diff+Civ2_V_Diff.*Civ2_V_Diff));
2100        NbExclude(irho)=(NbGood-numel(ind_good))/NbGood;
2101    end
2102    figure(1)
2103    semilogx(SmoothingParam,DiffVel,'b',SmoothingParam,NbExclude,'r',SmoothingParam,0.1*ones(size(SmoothingParam)),'m')
2104    grid on
2105    legend('rms velocity diff. Patch2-Civ2 (pixels)','proportion of excluded vectors (between 0 to 1)','recommended value diff. Patch2-Civ2')
2106    xlabel('smoothing parameter')
2107    ylabel('smoothing effect')
2108    set(handles.TestPatch2,'BackgroundColor',[0 1 0])
2109else
2110    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
2111    if ~isempty(corrfig)
2112        delete(corrfig)
2113    end
2114    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
2115    if ~isempty(hview_field)
2116        delete(hview_field)
2117    end
2118end
2119   
2120
2121%'nomtype2pair': creates nomencalture for index pairs knowing the image nomenclature
2122%---------------------------------------------------------------------
2123function NomTypeNc=nomtype2pair(NomTypeIma,mode_selected)
2124%---------------------------------------------------------------------           
2125% OUTPUT:
2126% NomTypeNc
2127%---------------------------------------------------------------------
2128% INPUT:
2129% 'NomTypeIma': string defining the kind of nomenclature used for images
2130
2131NomTypeNc=NomTypeIma;%default
2132switch mode_selected
2133    case 'pair j1-j2'     
2134    if ~isempty(regexp(NomTypeIma,'a$'))
2135        NomTypeNc=[NomTypeIma 'b'];
2136    elseif ~isempty(regexp(NomTypeIma,'A$'))
2137        NomTypeNc=[NomTypeIma 'B'];
2138    else
2139        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
2140        if ~isempty(r)
2141            NomTypeNc='_1_1-2';
2142        end
2143    end
2144    case 'series(Dj)' 
2145%         r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
2146%         if ~isempty(r)
2147            NomTypeNc='_1_1-2';
2148%         end
2149   case 'series(Di)'
2150        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
2151        if ~isempty(r)
2152            NomTypeNc='_1-2_1';
2153        else
2154            NomTypeNc='_1-2';
2155        end
2156end
2157
2158
2159%------------------------------------------------------------------------
2160% --- determine the list of index pairs of processing file
2161function [ind1,ind2,mode_selected]=...
2162    find_pair_indices(str_civ,i_series,j_series,MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j)
2163%------------------------------------------------------------------------
2164ind1='';
2165ind2='';
2166r=regexp(str_civ,'^\D(?<ind>[i|j])=( -| )(?<num1>\d+)\|(?<num2>\d+)','names');
2167if ~isempty(r)
2168    mode_selected=['D' r.ind];
2169    ind1=stra2num(r.num1);
2170    ind2=stra2num(r.num2);
2171else
2172    mode_selected='burst';
2173    r=regexp(str_civ,'^j= (?<num1>[a-z])-(?<num2>[a-z])','names');
2174    if ~isempty(r)
2175        NomTypeNc='_1ab';
2176    else
2177        r=regexp(str_civ,'^j= (?<num1>[A-Z])-(?<num2>[A-Z])','names');
2178        if ~isempty(r)
2179            NomTypeNc='_1AB';
2180        else
2181            r=regexp(str_civ,'^j= (?<num1>\d+)-(?<num2>\d+)','names');
2182            if ~isempty(r)
2183                NomTypeNc='_1_1-2';
2184            end           
2185        end
2186    end
2187    if isempty(r)
2188        display('wrong pair mode input option')
2189    else
2190    ind1=stra2num(r.num1);
2191    ind2=stra2num(r.num2);
2192    end
2193end
2194
2195%------------------------------------------------------------------------
2196% --- fill civ_input with the parameters retrieved from an input Civ file
2197%------------------------------------------------------------------------
2198function fill_civ_input(Data,handles)
2199
2200%% Civ param
2201% lists of parameters to enter
2202ListParamNum={'CorrBoxSize','SearchBoxSize','SearchBoxShift','Dx','Dy','Dz','MinIma','MaxIma'};% list of numerical values (to transform in strings)
2203ListParamValue={'CorrSmooth','CheckGrid','CheckMask','CheckThreshold'};
2204ListParamString={'Grid','Mask'};
2205% CorrSmooth ??
2206option={'Civ1','Civ2'};
2207for ichoice=1:2
2208    if isfield(Data,[option{ichoice} '_CorrBoxSize'])
2209        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2210    end
2211end
2212
2213%% Fix param
2214option={'Fix1','Fix2'};
2215for ichoice=1:2
2216    if isfield(Data,[option{ichoice} '_CheckFmin2'])
2217        ListParamNum={'MinVel','MaxVel','MinCorr'};% list of numerical values (to transform in strings)
2218        ListParamValue={'CheckFmin2','CheckF3','CheckF4'};
2219        ListParamString={'ref_fix_1'};
2220        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2221    end
2222end
2223
2224%% Patch param
2225option={'Patch1','Patch2'};
2226for ichoice=1:2
2227    if isfield(Data,[option{ichoice} '_FieldSmooth'])
2228        ListParamNum={'FieldSmooth','MaxDiff','SubDomainSize'};% list of numerical values (to transform in strings)
2229        ListParamValue={};
2230        ListParamString={};
2231        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2232    end
2233end
2234%------------------------------------------------------------------------
2235% --- fill a panel of civ_input with the parameters retrieved from an input Civ file
2236%------------------------------------------------------------------------
2237function fill_panel(Data,handles,panel,ListParamNum,ListParamValue,ListParamString)
2238children=get(handles.(panel),'children');%handles of the children of the input GUI with handle 'GUI_handle'
2239handles_panel=[];
2240for ichild=1:numel(children)
2241    if ~isempty(get(children(ichild),'tag'))
2242        handles_panel.(get(children(ichild),'tag'))=children(ichild);
2243    end
2244end
2245for ilist=1:numel(ListParamNum)
2246    ParamName=ListParamNum{ilist};
2247    CivParamName=[panel '_' ParamName];
2248    if isfield(Data,CivParamName)
2249        for icoord=1:numel(Data.(CivParamName))
2250            if numel(Data.(CivParamName))>1
2251                Tag=['num_' ParamName '_' num2str(icoord)];
2252            else
2253                Tag=['num_' ParamName];
2254            end
2255            if isfield(handles_panel,Tag)
2256                set(handles_panel.(Tag),'String',num2str(Data.(CivParamName)(icoord)))
2257                set(handles_panel.(Tag),'Visible','on')
2258            end
2259        end
2260    end
2261end
2262for ilist=1:numel(ListParamValue)
2263    ParamName=ListParamValue{ilist};
2264    CivParamName=[panel '_' ParamName];
2265    if strcmp(ParamName,'CorrSmooth')
2266        ParamName=['num_' ParamName];
2267    end
2268    if isfield(Data,CivParamName)
2269        if isfield(handles_panel,ParamName)
2270            set(handles_panel.(ParamName),'Value',Data.(CivParamName))
2271        end
2272    end
2273end
2274for ilist=1:numel(ListParamString)
2275    ParamName=ListParamString{ilist};
2276    CivParamName=[panel '_' ParamName];
2277    if isfield(Data,CivParamName)
2278        if isfield(handles_panel,ParamName)
2279            set(handles_panel.(ParamName),'String',Data.(CivParamName))
2280        end
2281    end
2282end
2283
2284%------------------------------------------------------------------------
2285% --- Executes on button press in ImportParam.
2286%------------------------------------------------------------------------
2287function ImportParam_Callback(hObject, eventdata, handles)
2288hseries=findobj(allchild(0),'Tag','series');
2289hhseries=guidata(hseries);
2290InputTable=get(hhseries.InputTable,'Data');% read the input file(s) table in the GUI series
2291oldfile=InputTable{1,1};
2292if isempty(oldfile)
2293    % use a file name stored in prefdir
2294    dir_perso=prefdir;
2295    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2296    if exist(profil_perso,'file')
2297        h=load (profil_perso);
2298        if isfield(h,'RootPath') && ischar(h.RootPath)
2299            oldfile=h.RootPath;
2300        end
2301    end
2302end
2303filexml=uigetfile_uvmat('pick a xml parameter file for civ',oldfile,'.xml');% get the xml file containing processing parameters
2304%proceed only if a file has been introduced by the browser
2305if ~isempty(filexml)
2306    Param=xml2struct(filexml);% read the input xml file as a Matlab structure
2307
2308   % Param.Action.RUN=0; %desactivate the input RUN=1
2309    if ~isfield(Param,'InputTable')||~isfield(Param,'IndexRange')
2310        msgbox_uvmat('ERROR','invalid config file: open a file in a folder ''/0_XML''')
2311        return
2312    end
2313    check_input=0;
2314    if isfield(Param,'ActionInput')
2315        if isfield(Param.ActionInput,'Program')&& strcmp(Param.ActionInput.Program,'civ_series')
2316            fill_GUI(Param.ActionInput,handles.civ_input)% fill the elements of the GUI series with the input parameters
2317            set(handles.ConfigSource,'String',filexml)
2318            check_input=1;
2319            update_CivOptions(handles,0)             
2320        end
2321    end
2322    if ~check_input
2323        msgbox_uvmat('ERROR','invalid config file (not for civ_series')
2324        return
2325    end
2326end
2327
2328% --- Executes on selection change in CheckCiv3.
2329function CheckCiv3_Callback(hObject, eventdata, handles)
2330
2331% --- Executes on button press in CheckRefFile.
2332function CheckRefFile_Callback(hObject, eventdata, handles)
2333
2334    hseries=findobj(allchild(0),'Tag','series');
2335    hhseries=guidata(hseries);
2336    InputTable=get(hhseries.InputTable,'Data');
2337    InputFile=fullfile(InputTable{1,1},InputTable{1,2},[InputTable{1,3} InputTable{1,5}]);
2338 % browse for a reference file for displacement
2339    fileref= uigetfile_uvmat('pick a reference image file:',InputFile);
2340        if ~isempty(fileref)
2341    set(handles.RefFile,'String',fileref)
2342    set(handles.ConfigSource,'String','NEW')
2343    set(handles.ConfigSource,'BackgroundColor',[1 0 1])
2344        end
2345
2346%------------------------------------------------------------------------
2347% --- Executes on key press with selection of a uicontrol
2348%------------------------------------------------------------------------
2349function keyboard_callback(hObject,eventdata,handles)
2350   
2351ListExclude={'CheckCiv1','CheckFix1','CheckPatch1','CheckCiv2','CheckFix2','CheckPatch2','ref_i'};
2352if isempty(find(strcmp(get(gco,'Tag'),ListExclude),1))% if the selected uicontrol is not in the Exclude list
2353    set(handles.ConfigSource,'String','NEW')% indicate that the configuration is new
2354    set(handles.OK,'BackgroundColor',[1 0 1])%
2355    drawnow
2356end
Note: See TracBrowser for help on using the repository browser.