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

Last change on this file since 1170 was 1170, checked in by sommeria, 6 days ago

Library Teleops infrared camera added

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