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

Last change on this file since 1162 was 1161, checked in by sommeria, 17 months ago

filter_tps modified to avoid possible bugs in case of few vectors, subpixel interpolation slightly modified in civ

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