Changeset 1164


Ignore:
Timestamp:
Jul 29, 2024, 9:43:17 AM (2 months ago)
Author:
sommeria
Message:

civ3D updated

Location:
trunk/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/filter_tps_3D.m

    r1163 r1164  
    3838%=======================================================================
    3939
    40 function [SubRange,NbCentre,Coord_tps,U_tps,V_tps,W_tps,U_smooth,V_smooth,W_smooth,FF] =filter_tps(Coord,U,V,W,SubDomainSize,FieldSmooth,Threshold)
     40function [SubRange,NbCentre,Coord_tps,U_tps,V_tps,W_tps,U_smooth,V_smooth,W_smooth,FF] =filter_tps_3D(Coord_x,Coord_y,Coord_z,U,V,W,SubDomainSize,FieldSmooth,Threshold)
    4141
    4242%% adjust subdomain decomposition
    4343warning off
    44 NbVec=size(Coord,1);% nbre of vectors in the field to interpolate
    45 NbCoord=size(Coord,2);% space dimension,Coord(:,1)= x,Coord(:,2)=  y , Coord(:,3)=  z
     44% [npz,npy,npx]=size(Coord_x);
     45Coord=[Coord_x Coord_y Coord_z];
     46NbVec=numel(Coord_x);% nbre of vectors in the field to interpolate
     47NbCoord=3;% space dimension,Coord(:,1)= x,Coord(:,2)=  y , Coord(:,3)=  z
    4648MinCoord=min(Coord,[],1);%lower coordinate bounds
    4749MaxCoord=max(Coord,[],1);%upper coordinate bounds
    4850Range=MaxCoord-MinCoord;%along eacch coordiante x,y,z
    49 Cellmesh=(prod(Range)/NbVec)^(1/3);
    50 NbSubDomainX=floor(range(1)/Cellmesh);
    51 NbSubDomainY=floor(range(2)/Cellmesh);
    52 NbSubDomainZ=floor(range(3)/Cellmesh);
     51Cellmesh=(10*prod(Range)/NbVec)^(1/3);
     52NbSubDomainX=ceil(Range(1)/Cellmesh);
     53NbSubDomainY=ceil(Range(2)/Cellmesh);
     54NbSubDomainZ=ceil(10*Range(3)/Cellmesh);
    5355
    5456% NbSubDomain=NbVec/SubDomainSize;% estimated number of subdomains
     
    5658% NbSubDomainY=max(floor(sqrt(NbSubDomain*AspectRatio)),1);% estimated number of subdomains in y
    5759% NbSubDomainZ=max(floor(sqrt(NbSubDomain*AspectRatio)),1);% estimated number of subdomains in y
    58 NbSubDomain=NbSubDomainX*NbSubDomainY;% new estimated number of subdomains in a matrix shape partition in subdomains
     60NbSubDomain=NbSubDomainX*NbSubDomainY*NbSubDomainZ;% new estimated number of subdomains in a matrix shape partition in subdomains
    5961Siz(1)=Range(1)/NbSubDomainX;%width of subdomains
    6062Siz(2)=Range(2)/NbSubDomainY;%height of subdomains
     
    7173%smoothing=Siz(1)*Siz(2)*FieldSmooth/1000%old calculation before 03 May < r1129
    7274NbVecSub=NbVec/NbSubDomain;% refined estimation of the nbre of vectors per subdomain
    73 smoothing=sqrt(Siz(1)*Siz(2)/NbVecSub)*FieldSmooth;%optimum smoothing increase as the typical mesh size =sqrt(SizX*SizY/NbVecSub)^1/2
     75smoothing=(Siz(1)*Siz(2)*Siz(3)/NbVecSub)^(1/3)*FieldSmooth;%optimum smoothing increase as the typical mesh size =sqrt(SizX*SizY/NbVecSub)^1/2
    7476Threshold=Threshold*Threshold;% take the square of the threshold to work with the modulus squared (not done before r1154)
    7577
     
    7981U_tps=zeros(1,NbSubDomain);% initialize  interpolated u component
    8082V_tps=zeros(1,NbSubDomain);% initialize interpolated v component
     83W_tps=zeros(1,NbSubDomain);% initialize interpolated v component
    8184NbCentre=zeros(1,NbSubDomain);%number of interpolated field values per subdomain, =0 by default
    82 W_tps=[];%default (2 component case)
    8385U_smooth=zeros(NbVec,1); % smoothed velocity U at the initial positions
    8486V_smooth=zeros(NbVec,1);% smoothed velocity V at the initial positions
    85 W_smooth=[];%default (2 component case)
     87W_smooth=zeros(NbVec,1);%default (2 component case)
    8688FF=false(NbVec,1);%false flag=0 (false) by default
    8789nb_select=zeros(NbVec,1);
     
    100102        %check_next=false;% test to go to next iteration with wider subdomain
    101103        ind_sel_previous=ind_sel;% record the set of selected vector indices for next iteration
    102         ind_sel= find(~FF & Coord(:,1)>=SubRange(1,1,isub) & Coord(:,1)<=SubRange(1,2,isub) & Coord(:,2)>=SubRange(2,1,isub) & Coord(:,2)<=SubRange(2,2,isub));% indices of vectors in the subdomain #isub
     104        ind_sel= find(~FF & Coord(:,1)>=SubRange(1,1,isub) & Coord(:,1)<=SubRange(1,2,isub)...
     105            & Coord(:,2)>=SubRange(2,1,isub) & Coord(:,2)<=SubRange(2,2,isub)&...
     106            Coord(:,3)>=SubRange(3,1,isub) & Coord(:,3)<=SubRange(3,2,isub));% indices of vectors in the subdomain #isub
    103107         check_partial_domain=sum(SubRange(:,1,isub)> MinCoord' | SubRange(:,2,isub)< MaxCoord');
    104108        % isub
     
    121125            [U_smooth_sub,U_tps_sub]=tps_coeff(Coord(ind_sel,:),U(ind_sel),smoothing);
    122126            [V_smooth_sub,V_tps_sub]=tps_coeff(Coord(ind_sel,:),V(ind_sel),smoothing);
     127            [W_smooth_sub,W_tps_sub]=tps_coeff(Coord(ind_sel,:),W(ind_sel),smoothing);
    123128            UDiff=U_smooth_sub-U(ind_sel);% difference between interpolated U component and initial value
    124129            VDiff=V_smooth_sub-V(ind_sel);% difference between interpolated V component and initial value
    125             NormDiff=UDiff.*UDiff+VDiff.*VDiff;% Square of difference norm
     130            WDiff=W_smooth_sub-W(ind_sel);% difference between interpolated V component and initial value
     131            NormDiff=UDiff.*UDiff+VDiff.*VDiff+WDiff.*WDiff;% Square of difference norm
    126132            ind_ind_sel=1:numel(ind_sel);%default
    127133            if exist('Threshold','var')&&~isempty(Threshold)
     
    134140                x_width=(SubRange(1,2,isub)-SubRange(1,1,isub))/pi;
    135141                y_width=(SubRange(2,2,isub)-SubRange(2,1,isub))/pi;
     142                z_width=(SubRange(3,2,isub)-SubRange(3,1,isub))/pi;
    136143                x_dist=(Coord(ind_sel,1)-CentreX(isub))/x_width;% relative x distance to the retangle centre
    137144                y_dist=(Coord(ind_sel,2)-CentreY(isub))/y_width;% relative ydistance to the retangle centre
    138                 weight=cos(x_dist).*cos(y_dist);%weighting fct =1 at the rectangle center and 0 at edge
    139                 %weight=1;% case for r1129 and before
     145                z_dist=(Coord(ind_sel,3)-CentreZ(isub))/z_width;% relative ydistance to the retangle centre
     146                weight=cos(x_dist).*cos(y_dist).*cos(z_dist);%weighting fct =1 at the rectangle center and 0 at edge
    140147                U_smooth(ind_sel)=U_smooth(ind_sel)+weight.*U_smooth_sub;
    141148                V_smooth(ind_sel)=V_smooth(ind_sel)+weight.*V_smooth_sub;
     149                W_smooth(ind_sel)=W_smooth(ind_sel)+weight.*W_smooth_sub;
    142150                NbCentre(isub)=numel(ind_sel);
    143151                Coord_tps(1:NbCentre(isub),:,isub)=Coord(ind_sel,:);
    144                 U_tps(1:NbCentre(isub)+3,isub)=U_tps_sub;
    145                 V_tps(1:NbCentre(isub)+3,isub)=V_tps_sub;
     152                U_tps(1:NbCentre(isub)+4,isub)=U_tps_sub;
     153                V_tps(1:NbCentre(isub)+4,isub)=V_tps_sub;
     154                W_tps(1:NbCentre(isub)+4,isub)=W_tps_sub;
    146155                nb_select(ind_sel)=nb_select(ind_sel)+weight;
    147156                display(['tps done with ' num2str(numel(ind_sel)) ' vectors in subdomain # ' num2str(isub)  ' among ' num2str(NbSubDomain)])
     
    157166                [U_smooth_sub,U_tps_sub]=tps_coeff(Coord(ind_sel(ind_ind_sel),:),U(ind_sel(ind_ind_sel)),smoothing);
    158167                [V_smooth_sub,V_tps_sub]=tps_coeff(Coord(ind_sel(ind_ind_sel),:),V(ind_sel(ind_ind_sel)),smoothing);
     168                [W_smooth_sub,W_tps_sub]=tps_coeff(Coord(ind_sel(ind_ind_sel),:),W(ind_sel(ind_ind_sel)),smoothing);
    159169                x_width=(SubRange(1,2,isub)-SubRange(1,1,isub))/pi;
    160170                y_width=(SubRange(2,2,isub)-SubRange(2,1,isub))/pi;
     171                z_width=(SubRange(3,2,isub)-SubRange(3,1,isub))/pi;
    161172                x_dist=(Coord(ind_sel(ind_ind_sel),1)-CentreX(isub))/x_width;% relative x distance to the retangle centre
    162173                y_dist=(Coord(ind_sel(ind_ind_sel),2)-CentreY(isub))/y_width;% relative ydistance to the retangle centre
    163                 weight=cos(x_dist).*cos(y_dist);%weighting fct =1 at the rectangle center and 0 at edge
     174                  z_dist=(Coord(ind_sel(ind_ind_sel),3)-CentreZ(isub))/z_width;% relative ydistance to the retangle centre
     175                weight=cos(x_dist).*cos(y_dist).*cos(z_dist);%weighting fct =1 at the rectangle center and 0 at edge
    164176                %weight=1;
    165177                U_smooth(ind_sel(ind_ind_sel))=U_smooth(ind_sel(ind_ind_sel))+weight.*U_smooth_sub;
    166178                V_smooth(ind_sel(ind_ind_sel))=V_smooth(ind_sel(ind_ind_sel))+weight.*V_smooth_sub;
     179                   W_smooth(ind_sel(ind_ind_sel))=W_smooth(ind_sel(ind_ind_sel))+weight.*W_smooth_sub;
    167180                NbCentre(isub)=numel(ind_ind_sel);
    168181                Coord_tps(1:NbCentre(isub),:,isub)=Coord(ind_sel(ind_ind_sel),:);
    169                 U_tps(1:NbCentre(isub)+3,isub)=U_tps_sub;
    170                 V_tps(1:NbCentre(isub)+3,isub)=V_tps_sub;
     182                U_tps(1:NbCentre(isub)+4,isub)=U_tps_sub;
     183                V_tps(1:NbCentre(isub)+4,isub)=V_tps_sub;
     184                W_tps(1:NbCentre(isub)+4,isub)=W_tps_sub;
    171185                nb_select(ind_sel(ind_ind_sel))=nb_select(ind_sel(ind_ind_sel))+weight;
    172186                display(['tps redone with ' num2str(numel(ind_sel)) ' vectors after elimination of ' num2str(numel(ind_sel)-numel(ind_ind_sel)) ' erratic vectors in subdomain # ' num2str(isub) ' among ' num2str(NbSubDomain)])
     
    189203    U_tps(:,ind_empty)=[];
    190204    V_tps(:,ind_empty)=[];
     205    W_tps(:,ind_empty)=[];
    191206    NbCentre(ind_empty)=[];
    192207end
     
    196211U_smooth=U_smooth./nb_select;% take the average at the intersection of several subdomains
    197212V_smooth=V_smooth./nb_select;
     213W_smooth=W_smooth./nb_select;
    198214
    199215%eliminate the vectors with diff>threshold not yet eliminated
     
    201217UDiff=U_smooth-U;% difference between interpolated U component and initial value
    202218VDiff=V_smooth-V;% difference between interpolated V component and initial value
    203 NormDiff=UDiff.*UDiff+VDiff.*VDiff;% Square of difference norm
     219WDiff=W_smooth-W;% difference between interpolated V component and initial value
     220NormDiff=UDiff.*UDiff+VDiff.*VDiff+WDiff.*WDiff;% Square of difference norm
    204221FF(NormDiff>Threshold)=true;%put FF value to 1 to identify the criterium of elimmination
    205222end
     
    207224U_smooth(FF)=U(FF);% set to the initial values the eliminated vectors (flagged as false)
    208225V_smooth(FF)=V(FF);
     226W_smooth(FF)=W(FF);
    209227fill=zeros(NbCoord+1,NbCoord,size(SubRange,3)); %matrix of zeros to complement the matrix Data.Civ1_Coord_tps (conveninent for file storage)
    210228Coord_tps=cat(1,Coord_tps,fill);
    211229
     230
  • trunk/src/find_file_series.m

    r1127 r1164  
    4949
    5050%% get input root name and info on the input file
    51 if isempty(regexp(FilePath,'^http://','once'))
     51if isempty(regexp(FilePath,'^http://','once'))% case of usual file input
    5252fullfileinput=fullfile(FilePath,fileinput);% input file name with path
    5353else
    54   fullfileinput=[FilePath '/' fileinput];
     54  fullfileinput=[FilePath '/' fileinput]; % case of web input
    5555end
    5656[FileInfo,MovieObject]=get_file_info(fullfileinput);
     
    105105        sep2='';
    106106        i1_str='(?<i1>)';%will set i1=[];
    107         i1_star='';
    108107        i2_str='(?<i2>)';%will set i2=[];
    109         i2_star='';
    110108        j1_str='(?<j1>)';%will set j1=[];
    111         j1_star='';
    112109        j2_str='(?<j2>)';%will set j2=[];
    113         j2_star='';
     110
    114111        %Look for cases with letter indexing for the second index
    115112        r=regexp(NomType,'^(?<sep1>_?)(?<i1>\d+)(?<sep2>_?)(?<j1>[a|A])(?<j2>[b|B]?)$','names');
     
    118115            sep2=r.sep2;
    119116            i1_str='(?<i1>\d+)';
    120             i1_star='*';
    121117            if strcmp(lower(r.j1),r.j1)% lower case index
    122118                j1_str='(?<j1>[a-z])';
     
    124120                j1_str='(?<j1>[A-Z])'; % upper case index
    125121            end
    126             j1_star='*';
    127122            if ~isempty(r.j2)
    128123                if strcmp(lower(r.j1),r.j1)
     
    131126                    j2_str='(?<j2>[A-Z])';
    132127                end
    133                 j2_star='*';
    134128            end
    135129        else %numerical indexing
     
    138132                sep1=r.sep1;
    139133                i1_str='(?<i1>\d+)';
    140                 i1_star='*';
    141134                if ~isempty(r.i2)
    142135                    i2_str='(?<i2>-\d+)';
    143                     i2_star='-*';
    144136                end
    145137                if ~isempty(r.j1)
    146138                    j1_str='(?<j1>_\d+)';
    147                     j1_star='_*';
    148139                end
    149140                if ~isempty(r.j2)
    150141                    j2_str='(?<j2>-\d+)';
    151                     j2_star='-*';
    152142                end
    153143            end
     
    290280            i1_series=i1_series(:,2)*ones(1,FileInfo.NumberOfFrames);%
    291281            i1_series=[zeros(size(i1_series,1),1) i1_series];
     282            if ~isempty(i2_series)
     283                i2_series=i2_series(:,2)*ones(1,FileInfo.NumberOfFrames);%
     284            i2_series=[zeros(size(i2_series,1),1) i2_series];
     285            end
    292286            j1_series=ones(size(i1_series,1),1)*(1:FileInfo.NumberOfFrames);%
    293287            j1_series=[zeros(size(i1_series,1),1) j1_series];
  • trunk/src/get_file_info.m

    r1162 r1164  
    153153                        [Data,tild,tild,errormsg]=nc2struct(fileinput,[]);
    154154                        if isempty(errormsg)
    155                             if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart)
    156                                 FileInfo.FileType='civx';%old civ data from the Fortran program
    157                                 if isfield(Data,'patch2') && isequal(Data.patch2,1)
    158                                     FileInfo.CivStage=6;
    159                                 elseif isfield(Data,'fix2') && isequal(Data.fix2,1)
    160                                     FileInfo.CivStage=5;
    161                                 elseif  isfield(Data,'civ2')&& isequal(Data.civ2,1)
    162                                     FileInfo.CivStage=4;
    163                                 elseif isfield(Data,'patch')&&isequal(Data.patch,1)
    164                                     FileInfo.CivStage=3;
    165                                 elseif isfield(Data,'fix')&&isequal(Data.fix,1)
    166                                     FileInfo.CivStage=2;
    167                                 else
    168                                     FileInfo.CivStage=1;
    169                                 end
    170                             elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata')
     155                            %                             if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart)
     156                            %                                 FileInfo.FileType='civx';%old civ data from the Fortran program
     157                            %                                 if isfield(Data,'patch2') && isequal(Data.patch2,1)
     158                            %                                     FileInfo.CivStage=6;
     159                            %                                 elseif isfield(Data,'fix2') && isequal(Data.fix2,1)
     160                            %                                     FileInfo.CivStage=5;
     161                            %                                 elseif  isfield(Data,'civ2')&& isequal(Data.civ2,1)
     162                            %                                     FileInfo.CivStage=4;
     163                            %                                 elseif isfield(Data,'patch')&&isequal(Data.patch,1)
     164                            %                                     FileInfo.CivStage=3;
     165                            %                                 elseif isfield(Data,'fix')&&isequal(Data.fix,1)
     166                            %                                     FileInfo.CivStage=2;
     167                            %                                 else
     168                            %                                     FileInfo.CivStage=1;
     169                            %                                 end
     170                            %                             else
     171                            if isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata')
    171172                                FileInfo.FileType='civdata'; % test for civ velocity fields
    172173                                FileInfo.CivStage=Data.CivStage;
     174                                MaskFile='';
     175                                if isfield(Data,'Civ2_Mask')
     176                                    MaskFile=Data.Civ2_Mask;
     177                                    if isfield(Data,'Civ2_NbSlice')
     178                                        FileInfo.MaskNbSlice=Data.Civ2_NbSlice;
     179                                    end
     180                                elseif isfield(Data,'Civ1_Mask')
     181                                    MaskFile=Data.Civ1_Mask;
     182                                    if isfield(Data,'Civ1_NbSlice')
     183                                        FileInfo.MaskNbSlice=Data.Civ1_NbSlice;
     184                                    end
     185                                end
     186                                if isfield(Data,'VolumeScan')
     187                                    FileInfo.VolumeScan=Data.VolumeScan;
     188                                end
     189                                if ~isempty(MaskFile)
     190                                    [RootPath,SubDir,RootFile,~,~,~,~,FileExt,NomType]=fileparts_uvmat(MaskFile);
     191                                    if strcmp(NomType,'_1')&& isfield(FileInfo,'MaskNbSlice')
     192                                        FileInfo.MaskFile=fullfile(RootPath,SubDir,RootFile);
     193                                    else
     194                                        FileInfo.MaskFile=MaskFile;% single mask for the series (no indexing)
     195                                    end
     196                                    FileInfo.MaskExt=FileExt;
     197                                end
    173198                            elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata_3D')
    174199                                FileInfo.FileType='civdata_3D'; % test for 3D volume civ velocity fields
  • trunk/src/get_file_series.m

    r1134 r1164  
    8484        FilePath=fullfile(InputTable{iview,1},InputTable{iview,2});
    8585        fileinput=[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}];
    86         [tild,tild,tild,i1_series{iview},i2_series{iview},j1_series{iview},j2_series{iview},NomType,FileInfo,MovieObject,...
    87             i1_input,i2_input,j1_input,j2_input]=find_file_series(FilePath,fileinput);
     86        [tild,tild,tild,i1_series{iview},i2_series{iview},j1_series{iview},j2_series{iview}]=find_file_series(FilePath,fileinput);
    8887        i1_series{iview}=squeeze(i1_series{iview}(1,:,:)); %select first  pair index as ordered by find_file_series
    8988        i2_series{iview}=squeeze(i2_series{iview}(1,:,:)); %select first  pair index as ordered by find_file_series
     
    137136        [i1_series{iview},i2_series{iview},j1_series{iview},j2_series{iview}]=find_file_indices(ref_i,ref_j,str2num(r.num1),str2num(r.num2),r.mode);
    138137    end
    139     %     if ~isequal(r(1).mode,'*-*')% imposed pairs or single i and/or j index
    140     %         [i1_series{iview},i2_series{iview},j1_series{iview},j2_series{iview}]=find_file_indices(ref_i,ref_j,str2num(r.num1),str2num(r.num2),r.mode);
    141     %     end
    142138   
    143139    %list of files
  • trunk/src/series/check_data_files.m

    r1127 r1164  
    6363    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
    6464    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
    65     ParamOut.OutputSubDirMode='none'; %(options 'none'/'custom'/'auto'/'first'/'last','auto' by default)
     65    ParamOut.OutputSubDirMode='auto'; %(options 'none'/'custom'/'auto'/'first'/'last','auto' by default)
    6666    %                      'none' =no output files
     67    ParamOut.OutputDirExt='.check_series';%set the output dir extension
    6768    return
    6869end
     
    120121for iview=1:nbview
    121122    if isequal(FileType{iview},'mmreader')||isequal(FileType{iview},'video')||isequal(FileType{iview},'multimage')
    122         [FileInfo]=get_file_info(filecell{iview,1});
     123        [FileInfo]=get_file_info(filecell{iview,1});% get infos on the first file in the current line
    123124        Tabchar{1}=filecell{iview,1};%info.Filename;
    124125        Tabchar{2}='';
     
    128129        message='';
    129130    else
    130         Tabchar={};
     131        Tabchar=cell(nbfield_i+1,NbSlice);
    131132        %LOOP ON SLICES
    132133        for i_slice=1:NbSlice
    133134            index_slice=i_slice:NbSlice:nbfield;
    134             filefound={};
    135             datnum=zeros(1,nbfield_j);
     135            filefound=cell(nbfield_i);
     136            datnum=zeros(1,nbfield_i);
     137            Tabchar(1,i_slice)={['slice #' num2str(i_slice)]};
    136138            for ifile=1:nbfield_i
    137                 update_waitbar(WaitbarHandle,ifile/nbfield_i)
    138                 if ishandle(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
    139                     disp('program stopped by user')
    140                     break
    141                 end
     139 %               update_waitbar(WaitbarHandle,ifile/nbfield_i)
     140%                 if ishandle(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
     141%                     disp('program stopped by user')
     142%                     break
     143%                 end
    142144                file=filecell{iview,index_slice(ifile)};
    143145                [Path,Name,ext]=fileparts(file);
     
    149151                    if isfield(datfile,'datenum')
    150152                        datnum(ifile)=datfile.datenum;
    151                         filefound(ifile)={datfile.name};
     153                        filefound{ifile}=datfile.name;
    152154                    end
    153155                    lastfield='';
    154                     [FileInfo,Object]=get_file_info(file);
     156                    [FileInfo]=get_file_info(file);
    155157                    FileType{iview}=FileInfo.FileType;
    156158                    if strcmp(FileType{iview},'civx')||strcmp(FileType{iview},'civdata')
     
    159161                            stagechoice=1+mod(FileInfo.CivStage-1,3);
    160162                            iter=1+floor((FileInfo.CivStage-1)/3);
    161                             lastfield=[liststage{stagechoice} num2str(iter)];
    162                             %liststage={'civ1','fix1','patch1','civ2','fix2','patch2'};                       
    163                             %lastfield=liststage{FileInfo.CivStage};                           
     163                            lastfield=[liststage{stagechoice} num2str(iter)];                         
    164164                        end
    165165                    end
    166166                    lastfield=[FileType{iview} ', ' lastfield];
    167167                end
    168                 Tabchar(1,i_slice)={['slice #' num2str(i_slice)]};
    169168                Tabchar(ifile+1,i_slice)={[file '...' lastfield]};
    170169            end
     
    177176            end
    178177        else
    179             datnum=datnum(find(datnum));%keep the non zero values corresponding to existing files
    180             filefound=filefound(find(datnum));
     178            datnum=datnum(datnum);%keep the non zero values corresponding to existing files
     179            filefound=filefound(datnum);
    181180            [first,ind]=min(datnum);
    182181            [last,indlast]=max(datnum);
     
    188187        end
    189188    end
    190     hfig=figure(iview);
    191     clf
    192     if iview>1
    193         pos=get(iview-1,'Position');
    194         pos(1)=pos(1)+(iview-1)*pos(1)/nbview;
    195         set(hfig,'Position',pos)
     189    if checkrun
     190        hfig=figure(iview);
     191        clf
     192        if iview>1
     193            pos=get(iview-1,'Position');
     194            pos(1)=pos(1)+(iview-1)*pos(1)/nbview;
     195            set(hfig,'Position',pos)
     196        end
     197        set(hfig,'name',['check_data_files:view= ' num2str(iview)])
     198        set(hfig,'MenuBar','none')% suppress the menu bar
     199        set(hfig,'NumberTitle','off')%suppress the fig number in the title
     200        h=uicontrol('Style','listbox', 'Position', [20 20 500 300], 'String', Tabchar, 'Callback', {'open_uvmat'});
     201        hh=uicontrol('Style','listbox', 'Position', [20 340 500 40], 'String', message);
     202    else % show results in log file
     203        disp(Tabchar)
     204        disp(message)
    196205    end
    197     set(hfig,'name',['check_data_files:view= ' num2str(iview)])
    198     set(hfig,'MenuBar','none')% suppress the menu bar
    199     set(hfig,'NumberTitle','off')%suppress the fig number in the title
    200     h=uicontrol('Style','listbox', 'Position', [20 20 500 300], 'String', Tabchar, 'Callback', {'open_uvmat'});
    201     hh=uicontrol('Style','listbox', 'Position', [20 340 500 40], 'String', message);
    202 end
    203 
     206end
     207'END'
    204208% 'open_uvmat': open with uvmat the  field selected in the list of 'series/check_data_files'
    205209%------------------------------------------------------------------------
  • trunk/src/series/civ_3D.m

    r1163 r1164  
    1 %'civ_3D': 3D PIV from image scan in a volume 
     1%'civ_3D': 3D PIV from image scan in a volume
    22
    33%------------------------------------------------------------------------
     
    1212% Param: Matlab structure of input  parameters
    1313%     Param contains info of the GUI series using the fct read_GUI.
    14 %     Param.Action.RUN = 0 (to set the status of the GUI series) or =1 to RUN the computation 
     14%     Param.Action.RUN = 0 (to set the status of the GUI series) or =1 to RUN the computation
    1515%     Param.InputTable: sets the input file(s)
    1616%           if absent, the fct looks for input data in Param.ActionInput     (test mode)
     
    4949    path_series=fileparts(which('series'));
    5050    addpath(fullfile(path_series,'series'))
    51 
    52    Data=civ_input(Param)
    53 
     51   
     52    Data=civ_input(Param)
     53   
    5454    Data.Program=mfilename;%gives the name of the current function
    5555    Data.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
     
    8383        end
    8484    end
    85 
    86 
     85   
     86   
    8787    return
    8888end
     
    114114if isfield(Param,'OutputSubDir')&& isfield(Param,'OutputDirExt')
    115115    OutputDir=[Param.OutputSubDir Param.OutputDirExt];
    116      OutputPath=fullfile(Param.OutputPath,num2str(Param.Experiment),num2str(Param.Device));
     116    OutputPath=fullfile(Param.OutputPath,num2str(Param.Experiment),num2str(Param.Device));
    117117else
    118118    disp_uvmat('ERROR','no output folder defined',checkrun)
     
    129129end
    130130
    131 [~,i1_series,~,j1_series,~]=get_file_series(Param);
    132 iview_A=0;% series index (iview) for the first image series
    133 iview_B=0;% series index (iview) for the second image series (only non zero for option 'shift' comparing two image series )
    134 if Param.ActionInput.CheckCiv1
    135     iview_A=1;% usual PIV, the image series is on the first line of the table
    136 elseif Param.ActionInput.CheckCiv2 % civ2 is performed without Civ1, a netcdf file series is needed in the first table line
    137     iview_A=2;% the second line is used for the input images of Civ2
    138 end
    139 if iview_A~=0
    140     RootPath_A=Param.InputTable{iview_A,1};
    141     RootFile_A=Param.InputTable{iview_A,3};
    142     SubDir_A=Param.InputTable{iview_A,2};
    143     NomType_A=Param.InputTable{iview_A,4};
    144     FileExt_A=Param.InputTable{iview_A,5};
    145     if iview_B==0
    146         iview_B=iview_A;% the second image series is the same as the first
    147     end
    148     RootPath_B=Param.InputTable{iview_B,1};
    149     RootFile_B=Param.InputTable{iview_B,3};
    150     SubDir_B=Param.InputTable{iview_B,2};
    151     NomType_B=Param.InputTable{iview_B,4};
    152     FileExt_B=Param.InputTable{iview_B,5};
    153 end
     131[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     132
     133if size(Param.InputTable,1)==2% netcdf file as first input line
     134    RootPath_nc=Param.InputTable{1,1};
     135    RootFile_nc=Param.InputTable{1,3};
     136    SubDir_nc=Param.InputTable{1,2};
     137    NomType_nc=Param.InputTable{1,4};
     138    FileExt_nc=Param.InputTable{1,5};
     139    iview_A=2;%second line used for image input
     140    iview_B=2;
     141else
     142    iview_A=1;%second line used for image input
     143    iview_B=1;
     144end
     145RootPath_A=Param.InputTable{iview_A,1};
     146RootFile_A=Param.InputTable{iview_A,3};
     147SubDir_A=Param.InputTable{iview_A,2};
     148NomType_A=Param.InputTable{iview_A,4};
     149FileExt_A=Param.InputTable{iview_A,5};
     150RootPath_B=Param.InputTable{iview_B,1};
     151RootFile_B=Param.InputTable{iview_B,3};
     152SubDir_B=Param.InputTable{iview_B,2};
     153NomType_B=Param.InputTable{iview_B,4};
     154FileExt_B=Param.InputTable{iview_B,5};
     155
    154156
    155157PairCiv1=Param.ActionInput.PairIndices.ListPairCiv1;
    156158
    157159[i1_series_Civ1,i2_series_Civ1,j1_series_Civ1,j2_series_Civ1,~,NomTypeNc]=...
    158                         find_pair_indices(PairCiv1,i1_series{1},j1_series{1},MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j);
    159                    
     160    find_pair_indices(PairCiv1,i1_series{1},j1_series{1},MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j);
     161
    160162if isempty(i1_series_Civ1)
    161163    disp_uvmat('ERROR','no image pair for civ in the input file index range',checkrun)
     
    173175end
    174176Data.CivStage=0;%default
    175 list_param=(fieldnames(Param.ActionInput.Civ1))';
    176 list_param(strcmp('TestCiv1',list_param))=[];% remove the parameter TestCiv1 from the list
    177 Civ1_param=regexprep(list_param,'^.+','Civ1_$0');% insert 'Civ1_' before  each string in list_param
    178 Civ1_param=[{'Civ1_ImageA','Civ1_ImageB','Civ1_Time','Civ1_Dt'} Civ1_param]; %insert the names of the two input images
    179 Data.ListGlobalAttribute=[ListGlobalAttribute Civ1_param];
     177if Param.ActionInput.CheckCiv1
     178    list_param=(fieldnames(Param.ActionInput.Civ1))';
     179    list_param(strcmp('TestCiv1',list_param))=[];% remove the parameter TestCiv1 from the list
     180    Civ1_param=regexprep(list_param,'^.+','Civ1_$0');% insert 'Civ1_' before  each string in list_param
     181    Civ1_param=[{'Civ1_ImageA','Civ1_ImageB','Civ1_Time','Civ1_Dt'} Civ1_param]; %insert the names of the two input images
     182    Data.ListGlobalAttribute=[ListGlobalAttribute Civ1_param];
     183end
    180184% set the list of variables
    181185Data.ListVarName={'Coord_z','Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_FF'};%  cell array containing the names of the fields to record
     
    224228    CheckOverwrite=Param.CheckOverwrite;
    225229end
    226    Data.Civ1_ImageA=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(1),[],j1_series_Civ1(1,1));
    227    Data.Civ1_ImageB=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i1_series_Civ1(1),[],j2_series_Civ1(1,1));
    228     FileInfo=get_file_info(Data.Civ1_ImageA);
    229         par_civ1=Param.ActionInput.Civ1;% parameters for civ1
    230     par_civ1.ImageHeight=FileInfo.Height;npy=FileInfo.Height;
    231     par_civ1.ImageWidth=FileInfo.Width;npx=FileInfo.Width;
     230Data.Civ1_ImageA=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(1),[],j1_series_Civ1(1,1));
     231Data.Civ1_ImageB=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i1_series_Civ1(1),[],j2_series_Civ1(1,1));
     232FileInfo=get_file_info(Data.Civ1_ImageA);
     233par_civ1=Param.ActionInput.Civ1;% parameters for civ1
     234par_civ1.ImageHeight=FileInfo.Height;npy=FileInfo.Height;
     235par_civ1.ImageWidth=FileInfo.Width;npx=FileInfo.Width;
    232236SearchRange_z=Param.ActionInput.Civ1.SearchRange(3);
    233     par_civ1.Dz=Param.ActionInput.Civ1.Dz;
    234     par_civ1.ImageA=zeros(2*SearchRange_z+1,npy,npx);
     237par_civ1.Dz=Param.ActionInput.Civ1.Dz;
     238par_civ1.ImageA=zeros(2*SearchRange_z+1,npy,npx);
    235239par_civ1.ImageB=zeros(2*SearchRange_z+1,npy,npx);
    236240
     
    268272        j2=j2_series_Civ1(ifield);
    269273    end
    270 
    271     Data.Civ1_Time=(Time(i2+1,j2+1)+Time(i1+1,j1+1))/2;% the Time is the Time at the middle of the image pair
    272     Data.Civ1_Dt=Time(i2+1,j2+1)-Time(i1+1,j1+1);
    273 
    274     for ilist=1:length(list_param)
    275         Data.(Civ1_param{4+ilist})=Param.ActionInput.Civ1.(list_param{ilist});
    276     end
    277    
    278     Data.CivStage=1;
    279  
     274   
     275   
     276   
    280277    ncfile_out=fullfile_uvmat(OutputPath,'',Param.InputTable{1,3},'.nc',...
    281                 '_1-1',i1_series_Civ1(ifield),i2_series_Civ1(ifield)); %output file name
    282 
     278        '_1-1',i1_series_Civ1(ifield),i2_series_Civ1(ifield)); %output file name
     279   
    283280    if ~CheckOverwrite && exist(ncfile_out,'file')
    284281        disp(['existing output file ' ncfile_out ' already exists, skip to next field'])
    285282        continue% skip iteration if the mode overwrite is desactivated and the result file already exists
    286283    end
    287 
    288 
    289     %% Civ1
    290     % if Civ1 computation is requested
    291     if isfield (Param.ActionInput,'Civ1')
    292 
     284   
     285   
     286%% Civ1 computation if requested
     287    if Param.ActionInput.CheckCiv1
     288       
    293289        disp('civ1 started')
    294 
     290        Data.Civ1_Time=(Time(i2+1,j2+1)+Time(i1+1,j1+1))/2;% the Time is the Time at the middle of the image pair
     291        Data.Civ1_Dt=Time(i2+1,j2+1)-Time(i1+1,j1+1);
     292       
     293        for ilist=1:length(list_param)
     294            Data.(Civ1_param{4+ilist})=Param.ActionInput.Civ1.(list_param{ilist});
     295        end
     296       
     297        Data.CivStage=1;
    295298        % read input images by vertical blocks with nbre of images equal to 2*SearchRange+1,
    296299        par_civ1.ImageA=zeros(2*SearchRange_z+1,npy,npx);%image block initiation
     
    307310            par_civ1.ImageB(iz,:,:) = B;
    308311        end
    309         % calculate velocity data at the first position z, corresponding to j_index=par_civ1.Dz
    310         [Data.Civ1_X(1,:,:),Data.Civ1_Y(1,:,:), Data.Civ1_U(1,:,:), Data.Civ1_V(1,:,:),Data.Civ1_W(1,:,:),...
    311             Data.Civ1_C(1,:,:), Data.Civ1_FF(1,:,:), ~, errormsg] = civ3D (par_civ1);
    312         if ~isempty(errormsg)
    313             disp_uvmat('ERROR',errormsg,checkrun)
    314             return
    315         end
    316      % loop on slices
    317 
    318         for z_index=2:floor((NbSlice-SearchRange_z)/par_civ1.Dz)% loop on slices
    319             par_civ1.ImageA=circshift(par_civ1.ImageA,-par_civ1.Dz,1);%shift the indices in the image block upward by par_civ1.Dz
    320             par_civ1.ImageB=circshift(par_civ1.ImageB,-par_civ1.Dz,1);
    321             for iz=1:par_civ1.Dz %read the new images at the end of the image block
    322                 image_index=z_index*par_civ1.Dz+SearchRange_z-par_civ1.Dz+iz+1;
    323                 if image_index<=size(j1_series_Civ1,1)
    324                 j_image_index=j1_series_Civ1(z_index*par_civ1.Dz+SearchRange_z-par_civ1.Dz+iz+1,1)
    325                 ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(1,ifield),[],j_image_index);%           
    326                 A= read_image(ImageName_A,FileType_A);
    327                 ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(1,ifield),[],j_image_index);
    328                 B= read_image(ImageName_B,FileType_B);
    329                 else
    330                     A=zeros(1,size(par_civ1.ImageA,2),size(par_civ1.ImageA,3));
    331                     B=zeros(1,size(par_civ1.ImageA,2),size(par_civ1.ImageA,3));
    332                 end
    333                 par_civ1.ImageA(2*SearchRange_z+1-par_civ1.Dz+iz,:,:) = A;
    334                 par_civ1.ImageB(2*SearchRange_z+1-par_civ1.Dz+iz,:,:) = B;
    335             end
    336             % caluclate velocity data (y and v in indices, reverse to y component)
    337             [Data.Civ1_X(z_index,:,:),Data.Civ1_Y(z_index,:,:), Data.Civ1_U(z_index,:,:), Data.Civ1_V(z_index,:,:),Data.Civ1_W(z_index,:,:),...
    338                 Data.Civ1_C(z_index,:,:), Data.Civ1_FF(z_index,:,:), result_conv, errormsg] = civ3D (par_civ1);
    339             if ~isempty(errormsg)
    340                 disp_uvmat('ERROR',errormsg,checkrun)
    341                 return
    342             end
    343         end
    344         Data.Civ1_V=-Data.Civ1_V;%reverse v
    345         Data.Civ1_Y=npy-Data.Civ1_Y+1;%reverse y
    346         [npz,npy,npx]=size(Data.Civ1_X);
    347        
    348       %  Data.Coord_y=flip(1:npy);
    349        % Data.Coord_x=1:npx;
     312       
    350313        % case of mask TO ADAPT
    351314        if par_civ1.CheckMask&&~isempty(par_civ1.Mask)
     
    377340            end
    378341        end
     342       
     343        % calculate velocity data at the first position z, corresponding to j_index=par_civ1.Dz
     344        [Data.Civ1_X(1,:,:),Data.Civ1_Y(1,:,:), Data.Civ1_U(1,:,:), Data.Civ1_V(1,:,:),Data.Civ1_W(1,:,:),...
     345            Data.Civ1_C(1,:,:), Data.Civ1_FF(1,:,:), ~, errormsg] = civ3D (par_civ1);
     346        if ~isempty(errormsg)
     347            disp_uvmat('ERROR',errormsg,checkrun)
     348            return
     349        end
     350       
     351        % loop on slices
     352        for z_index=2:floor((NbSlice-SearchRange_z)/par_civ1.Dz)% loop on slices
     353            par_civ1.ImageA=circshift(par_civ1.ImageA,-par_civ1.Dz,1);%shift the indices in the image block upward by par_civ1.Dz
     354            par_civ1.ImageB=circshift(par_civ1.ImageB,-par_civ1.Dz,1);
     355            for iz=1:par_civ1.Dz %read the new images at the end of the image block
     356                image_index=z_index*par_civ1.Dz+SearchRange_z-par_civ1.Dz+iz+1;
     357                if image_index<=size(j1_series_Civ1,1)
     358                    j_image_index=j1_series_Civ1(z_index*par_civ1.Dz+SearchRange_z-par_civ1.Dz+iz+1,1)
     359                    ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(1,ifield),[],j_image_index);%
     360                    A= read_image(ImageName_A,FileType_A);
     361                    ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(1,ifield),[],j_image_index);
     362                    B= read_image(ImageName_B,FileType_B);
     363                else
     364                    A=zeros(1,size(par_civ1.ImageA,2),size(par_civ1.ImageA,3));
     365                    B=zeros(1,size(par_civ1.ImageA,2),size(par_civ1.ImageA,3));
     366                end
     367                par_civ1.ImageA(2*SearchRange_z+1-par_civ1.Dz+iz,:,:) = A;
     368                par_civ1.ImageB(2*SearchRange_z+1-par_civ1.Dz+iz,:,:) = B;
     369            end
     370            % caluclate velocity data
     371            [Data.Civ1_X(z_index,:,:),Data.Civ1_Y(z_index,:,:), Data.Civ1_U(z_index,:,:), Data.Civ1_V(z_index,:,:),Data.Civ1_W(z_index,:,:),...
     372                Data.Civ1_C(z_index,:,:), Data.Civ1_FF(z_index,:,:), result_conv, errormsg] = civ3D (par_civ1);
     373            if ~isempty(errormsg)
     374                disp_uvmat('ERROR',errormsg,checkrun)
     375                return
     376            end
     377        end
     378        %         Data.Civ1_V=-Data.Civ1_V;%reverse v
     379        %         Data.Civ1_Y=npy-Data.Civ1_Y+1;%reverse y
     380       
     381       
     382        %  Data.Coord_y=flip(1:npy);
     383        % Data.Coord_x=1:npx;
     384       
     385    else
     386        Data=nc2struct(filecell{1,ifield});%read civ1 and fix1 data in the existing netcdf file
     387       
    379388        % Data.ListVarName=[Data.ListVarName 'Civ1_Z'];
    380389        % Data.Civ1_X=[];Data.Civ1_Y=[];Data.Civ1_Z=[];
    381390        % Data.Civ1_U=[];Data.Civ1_V=[];Data.Civ1_C=[];
    382         % 
    383         % 
     391        %
     392        %
    384393        % Data.Civ1_X=[Data.Civ1_X reshape(xtable,[],1)];
    385394        % Data.Civ1_Y=[Data.Civ1_Y reshape(Param.Civ1.ImageHeight-ytable+1,[],1)];
     
    389398        % Data.Civ1_C=[Data.Civ1_C reshape(ctable,[],1)];
    390399        % Data.Civ1_FF=[Data.Civ1_FF reshape(F,[],1)];
    391 
    392     end
    393 
    394     %% Fix1
     400       
     401    end
     402   
     403%% Fix1
    395404    if isfield (Param.ActionInput,'Fix1')
    396405        disp('detect_false1 started')
     
    412421        Data.CivStage=2;
    413422    end
    414     %% Patch1
     423   
     424%% Patch1
    415425    if isfield (Param.ActionInput,'Patch1')
    416426        disp('patch1 started')
    417427        tstart_patch1=tic;
    418 
     428       
    419429        % record the processing parameters of Patch1 as global attributes in the result nc file
    420430        list_param=fieldnames(Param.ActionInput.Patch1)';
     
    426436        Data.CivStage=3;% record the new state of processing
    427437        Data.ListGlobalAttribute=[Data.ListGlobalAttribute Patch1_param];
    428 
     438       
    429439        % list the variables to record
    430440        nbvar=length(Data.ListVarName);
     
    433443        Data.VarAttribute{nbvar+1}.Role='vector_x';
    434444        Data.VarAttribute{nbvar+2}.Role='vector_y';
    435         Data.VarAttribute{nbvar+5}.Role='vector_z';     
     445        Data.VarAttribute{nbvar+5}.Role='vector_z';
    436446        Data.Civ1_U_smooth=Data.Civ1_U;
    437         Data.Civ1_V_smooth=Data.Civ1_V; 
    438         Data.Civ1_W_smooth=Data.Civ1_W; 
     447        Data.Civ1_V_smooth=Data.Civ1_V;
     448        Data.Civ1_W_smooth=Data.Civ1_W;
    439449        if isfield(Data,'Civ1_FF')
    440450            ind_good=find(Data.Civ1_FF==0);
     
    447457            return
    448458        end
    449 
     459       
    450460        % perform Patch calculation using the UVMAT fct 'filter_tps'
    451 Civ1_Z=0.5*Data.Civ1_W(ind_good);
    452 for iz=1:numel(Data.Coord_z)
    453     Civ1_Z(iz,:,:)=Civ1_Z(iz,:,:)+Data.Coord_z(iz);
    454 end
     461        Civ1_Z=0.5*Data.Civ1_W;
     462        for iz=1:numel(Data.Coord_z)
     463            Civ1_Z(iz,:,:)=Civ1_Z(iz,:,:)+Data.Coord_z(iz);   
     464        end
     465        [npz,npy,npx]=size(Data.Civ1_X);
    455466        [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps,Data.Civ1_W_tps,...
    456             Data.Civ1_U_smooth(ind_good),Data.Civ1_V_smooth(ind_good),Data.Civ1_V_smooth(ind_good),FFres]=...
    457             filter_tps_3D([Data.Civ1_X(ind_good) Data.Civ1_Y(ind_good)],Civ_1_Z,Data.Civ1_U(ind_good),Data.Civ1_V(ind_good),Data.Civ1_W(ind_good),Data.Patch1_SubDomainSize,Data.Patch1_FieldSmooth,Data.Patch1_MaxDiff);
    458         Data.Civ1_FF(ind_good)=uint8(FFres);
     467            Data.Civ1_U_smooth(ind_good),Data.Civ1_V_smooth(ind_good),Data.Civ1_W_smooth(ind_good),FFres]=...
     468            filter_tps_3D(Data.Civ1_X(ind_good),Data.Civ1_Y(ind_good),Civ1_Z(ind_good),Data.Civ1_U(ind_good),Data.Civ1_V(ind_good),Data.Civ1_W(ind_good),...
     469            Data.Patch1_SubDomainSize,Data.Patch1_FieldSmooth,Data.Patch1_MaxDiff);
     470        Data.Civ1_FF(ind_good)=uint8(4*FFres);
     471        Data.Civ1_FF=reshape(Data.Civ1_FF,npz,npy,npx);
     472        Data.Civ1_U=reshape(Data.Civ1_U,npz,npy,npx);
     473        Data.Civ1_V=reshape(Data.Civ1_V,npz,npy,npx);
     474        Data.Civ1_W=reshape(Data.Civ1_W,npz,npy,npx);
    459475        time_patch1=toc(tstart_patch1);
    460476        disp('patch1 performed')
    461477    end
    462 
     478   
    463479    %% Civ2
    464480    if isfield (Param.ActionInput,'Civ2')
     
    503519        end
    504520        % end
    505 
     521       
    506522        % get the guess from patch1 or patch2 (case 'CheckCiv3')
    507 
     523       
    508524        if isfield (par_civ2,'CheckCiv3') && par_civ2.CheckCiv3 %get the guess from  patch2
    509525            SubRange= Data.Civ2_SubRange;
     
    530546            Data.CivStage=4;
    531547        end
    532 
     548       
    533549        Shiftx=zeros(size(par_civ2.Grid,1),1);% shift expected from civ1 data
    534550        Shifty=zeros(size(par_civ2.Grid,1),1);
    535551        nbval=zeros(size(par_civ2.Grid,1),1);% nbre of interpolated values at each grid point (from the different patch subdomains)
    536 
     552       
    537553        NbSubDomain=size(SubRange,3);
    538554        for isub=1:NbSubDomain% for each sub-domain of Patch1
     
    577593            end
    578594        end
    579 
    580 
     595       
     596       
    581597        if strcmp(Param.ActionInput.ListCompareMode,'displacement')
    582598            Civ1_Dt=1;
     
    585601            Civ2_Dt=Time(i2_civ2+1,j2_civ2+1)-Time(i1_civ2+1,j1_civ2+1);
    586602        end
    587 
     603       
    588604        par_civ2.SearchBoxShift=(Civ2_Dt/Civ1_Dt)*[Shiftx(nbval>=1)./nbval(nbval>=1) Shifty(nbval>=1)./nbval(nbval>=1)];
    589605        % shift the grid points by half the expected shift to provide the correlation box position in image A
     
    595611            par_civ2.DVDY=DVDY(nbval>=1)./nbval(nbval>=1);
    596612        end
    597 
     613       
    598614        % calculate velocity data (y and v in image indices, reverse to y component)
    599 
     615       
    600616        [xtable, ytable, utable, vtable, ctable, F,result_conv,errormsg] = civ (par_civ2);
    601 
     617       
    602618        list_param=(fieldnames(Param.ActionInput.Civ2))';
    603619        list_param(strcmp('TestCiv2',list_param))=[];% remove the parameter TestCiv2 from the list
     
    620636        end
    621637        Data.ListGlobalAttribute=[Data.ListGlobalAttribute Civ2_param];
    622 
     638       
    623639        nbvar=numel(Data.ListVarName);
    624640        % define the Civ2 variable (if Civ2 data are not replaced from previous calculation)
     
    651667        end
    652668    end
    653 
     669   
    654670    %% Fix2
    655671    if isfield (Param.ActionInput,'Fix2')
     
    665681        Data.CivStage=Data.CivStage+1;
    666682    end
    667 
     683   
    668684    %% Patch2
    669685    if isfield (Param.ActionInput,'Patch2')
     
    678694        end
    679695        Data.ListGlobalAttribute=[Data.ListGlobalAttribute Patch2_param];
    680 
     696       
    681697        nbvar=length(Data.ListVarName);
    682698        Data.ListVarName=[Data.ListVarName {'Civ2_U_smooth','Civ2_V_smooth','Civ2_SubRange','Civ2_NbCentres','Civ2_Coord_tps','Civ2_U_tps','Civ2_V_tps'}];
    683699        Data.VarDimName=[Data.VarDimName {'nb_vec_2','nb_vec_2',{'nb_coord','nb_bounds','nb_subdomain_2'},{'nb_subdomain_2'},...
    684700            {'nb_tps_2','nb_coord','nb_subdomain_2'},{'nb_tps_2','nb_subdomain_2'},{'nb_tps_2','nb_subdomain_2'}}];
    685 
     701       
    686702        Data.VarAttribute{nbvar+1}.Role='vector_x';
    687703        Data.VarAttribute{nbvar+2}.Role='vector_y';
     
    700716            return
    701717        end
    702 
     718       
    703719        [Data.Civ2_SubRange,Data.Civ2_NbCentres,Data.Civ2_Coord_tps,Data.Civ2_U_tps,Data.Civ2_V_tps,tild,Ures,Vres,tild,FFres]=...
    704720            filter_tps([Data.Civ2_X(ind_good) Data.Civ2_Y(ind_good)],Data.Civ2_U(ind_good),Data.Civ2_V(ind_good),[],Data.Patch2_SubDomainSize,Data.Patch2_FieldSmooth,Data.Patch2_MaxDiff);
     
    710726        disp('patch2 performed')
    711727    end
    712 
     728   
    713729    %% write result in a netcdf file if requested
    714730    % if CheckOutputFile
     
    726742    disp(['time civ2 ' num2str(time_civ2,2) ' s'])
    727743    disp(['time patch2 ' num2str(time_patch2,2) ' s'])
    728 
     744   
    729745end
    730746
     
    747763%  .ImageB: second image for correlation(matrix)
    748764%  .CorrBoxSize: 1,2 vector giving the size of the correlation box in x and y
    749 %  .SearchBoxSize:  1,2 vector giving the size of the search box in x and y
     765%  .SearchRange:  1,2 vector giving the range of the search in x and y
    750766%  .SearchBoxShift: 1,2 vector or 2 column matrix (for civ2) giving the shift of the search box in x and y
    751767%  .CorrSmooth: =1 or 2 determines the choice of the sub-pixel determination of the correlation max
     
    764780function [xtable,ytable,utable,vtable,wtable,ctable,FF,result_conv,errormsg] = civ3D (par_civ)
    765781%% check image sizes
    766 [npz,npy_ima,npx_ima]=size(par_civ.ImageA);% npz = 
     782[npz,npy_ima,npx_ima]=size(par_civ.ImageA);% npz =
    767783if ~isequal(size(par_civ.ImageB),[npz npy_ima npx_ima])
    768784    errormsg='image pair with unequal size';
     
    786802ibx2=floor(par_civ.CorrBoxSize(1)/2);
    787803iby2=floor(par_civ.CorrBoxSize(2)/2);
    788 isx2=par_civ.SearchRange(1);
    789 isy2=par_civ.SearchRange(2);
     804isx2=par_civ.SearchRange(1)+ibx2;
     805isy2=par_civ.SearchRange(2)+iby2;
    790806isz2=par_civ.SearchRange(3);
    791807kref=isz2+1;%middle index of the z slice
     
    878894                image2_mean=mean(mean(image2_crop,2),3);
    879895            end
    880      
     896            
    881897            if FF(ivec_y,ivec_x)==0
    882898                if check_MinIma && (image1_mean < par_civ.MinIma || image2_mean < par_civ.MinIma)
    883899                    FF(ivec_y,ivec_x)=1;       %threshold on image minimum
    884                
     900                   
    885901                elseif check_MaxIma && (image1_mean > par_civ.MaxIma || image2_mean > par_civ.MaxIma)
    886902                    FF(ivec_y,ivec_x)=1;    %threshold on image maximum
    887903                end
    888904                if FF(ivec_y,ivec_x)==1
    889                     utable(ivec_y,ivec_x)=NaN; 
     905                    utable(ivec_y,ivec_x)=NaN;
    890906                    vtable(ivec_y,ivec_x)=NaN;
    891907                else
     
    898914                    %     % image2_crop=(image2_crop-image2_mean);
    899915                    % end
    900 
     916                   
    901917                    npxycorr=2*par_civ.SearchRange(1:2)+1;
    902918                    result_conv=zeros([2*par_civ.SearchRange(3)+1 npxycorr]);%initialise the conv product
    903919                    max_xy=zeros(2*par_civ.SearchRange(3)+1,1);%initialise the max correlation vs z
    904                     xk=ones(npz,1);%initialise the x displacement corresponding to the max corr 
    905                     yk=ones(npz,1);%initialise the y displacement corresponding to the max corr 
     920                    xk=ones(npz,1);%initialise the x displacement corresponding to the max corr
     921                    yk=ones(npz,1);%initialise the y displacement corresponding to the max corr
    906922                    subima1=squeeze(image1_crop(kref,:,:))-image1_mean(kref);
    907923                    for kz=1:npz
    908                         subima2=squeeze(image2_crop(kz,:,:))-image2_mean(kz);   
     924                        subima2=squeeze(image2_crop(kz,:,:))-image2_mean(kz);
    909925                        correl_xy=conv2(subima2,flip(flip(subima1,2),1),'valid');
    910926                        result_conv(kz,:,:)=correl_xy;
    911                         max_xy(kz)=max(max(correl_xy));             
    912                          [yk(kz),xk(kz)]=find(correl_xy==max_xy(kz),1);%find the indices of the maximum, use 0.999 to avoid rounding errors
     927                        max_xy(kz)=max(max(correl_xy));
     928                        [yk(kz),xk(kz)]=find(correl_xy==max_xy(kz),1);%find the indices of the maximum, use 0.999 to avoid rounding errors
    913929                    end
    914930                    [corrmax,dz]=max(max_xy);
     
    932948                        end
    933949                        utable(ivec_y,ivec_x)=vector(1)+shiftx(ivec_y,ivec_x);
    934                         vtable(ivec_y,ivec_x)=vector(2)+shifty(ivec_y,ivec_x);
     950                        vtable(ivec_y,ivec_x)=-vector(2)+shifty(ivec_y,ivec_x);
    935951                        wtable(ivec_y,ivec_x)=vector(3);
    936952                        xtable(ivec_y,ivec_x)=iref+utable(ivec_y,ivec_x)/2-0.5;% convec flow (velocity taken at the point middle from imgae 1 and 2)
     
    938954                        iref=round(xtable(ivec_y,ivec_x)+0.5);% nearest image index for the middle of the vector
    939955                        jref=round(ytable(ivec_y,ivec_x)+0.5);
    940                        % if utable(ivec_y,ivec_x)==0 && vtable(ivec_y,ivec_x)==0
    941                        %     'test'
    942                        % end
     956                        % if utable(ivec_y,ivec_x)==0 && vtable(ivec_y,ivec_x)==0
     957                        %     'test'
     958                        % end
    943959                        % eliminate vectors located in the mask
    944960                        if  checkmask && (iref<1 || jref<1 ||iref>npx_ima || jref>npy_ima ||( par_civ.Mask(jref,iref)<200 && par_civ.Mask(jref,iref)>=100))
     
    956972    end
    957973end
     974ytable=npy_ima-ytable+1;%reverse from j index to image coordinate y
    958975result_conv=result_conv*corrmax/(255*sum_square);% keep the last correlation matrix for output
    959976
     
    980997    f2 = log(result_conv(z+1,y,x));
    981998    peakz = peakz+ (f1-f2)/(2*f1-4*f0+2*f2);
    982 
     999   
    9831000    f1 = log(result_conv(z,y-1,x));
    9841001    f2 = log(result_conv(z,y+1,x));
    9851002    peaky = peaky+ (f1-f2)/(2*f1-4*f0+2*f2);
    986 
     1003   
    9871004    f1 = log(result_conv(z,y,x-1));
    9881005    f2 = log(result_conv(z,y,x+1));
     
    10841101
    10851102if isfield (Param,'MinCorr')
    1086      FF(C<Param.MinCorr & FFIn==0)=2;
     1103    FF(C<Param.MinCorr & FFIn==0)=2;
    10871104end
    10881105if (isfield(Param,'MinVel')&&~isempty(Param.MinVel))||(isfield (Param,'MaxVel')&&~isempty(Param.MaxVel))
     
    10931110    end
    10941111    if isfield (Param,'MaxVel')&&~isempty(Param.MaxVel)
    1095          U2Max=Param.MaxVel*Param.MaxVel;
     1112        U2Max=Param.MaxVel*Param.MaxVel;
    10961113        FF(Umod>U2Max & FFIn==0)=3;
    10971114    end
     
    11391156        i1_series=i_series-ind1;% set of first image numbers
    11401157        i2_series=i_series+ind2;
    1141         check_bounds=i1_series<MinIndex_i | i2_series>MaxIndex_i;
     1158        check_bounds=i1_series(1)<MinIndex_i | i2_series(1)>MaxIndex_i;
    11421159        if isempty(j_series)
    11431160            NomTypeNc='_1-2';
  • trunk/src/series/civ_input.m

    r1163 r1164  
    101101NomTypeImaA=NomTypeInput;
    102102iview_image=1;%line # for the input images
    103 switch 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
     103if ismember( FileType,{'civdata','civdata_3D'})
    109104        NomTypeNc=NomTypeInput;
    110105        ind_opening=SeriesData.FileInfo{1}.CivStage;
     
    120115        end
    121116       
    122         if size(Param.InputTable,1)==1
    123            
    124             Param.InputTable(2,:)=Param.InputTable(1,:);
    125               set(hhseries.InputTable,'Data',Param.InputTable)
     117        if size(Param.InputTable,1)==1     
    126118             if isfield(Data,'Civ2_ImageA')
    127119                 ImageName=Data.Civ2_ImageA;
    128120             elseif isfield(Data,'Civ1_ImageA')
    129121                 ImageName=Data.Civ1_ImageA;
     122             else
     123                  msgbox_uvmat('ERROR','no original image defined in netcdf input file ')
     124            return
    130125             end
    131             series('display_file_name',hhseries,ImageName,1);%append the image series to the input list
     126            series('display_file_name',hhseries,ImageName,'append');%append the image series to the input list
    132127                    [~,~,~,~,~,~,~,~,NomTypeImaA]=fileparts_uvmat(ImageName);
    133      
    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 %     
    138 %              end
    139         end
    140 
    141         iview_image=1;%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
     128        end
     129
     130        iview_image=2;%line # for the input images
    147131end
    148132       
     
    162146     return
    163147end
     148
    164149MaxIndex_i=Param.IndexRange.MaxIndex_i(1);
    165150MinIndex_i=Param.IndexRange.MinIndex_i(1);
  • trunk/src/series/civ_series.m

    r1163 r1164  
    117117        if Param.ActionInput.CheckCiv1
    118118            iview_A=1;% usual PIV, the image series is on the first line of the table
    119         elseif Param.ActionInput.CheckCiv2 % civ2 is performed without Civ1, a netcdf file series is needed in the first table line
    120             iview_A=2;% the second line is used for the input images of Civ2
     119        else % Civ1 has been already stored in a netcdf file input
     120            iview_A=2;% the second line is used for the input images
    121121        end
    122122        if iview_A~=0
     
    274274    tstart=tic;
    275275    time_civ1=0;
    276   time_patch1=0;
    277   time_civ2=0;
    278   time_patch2=0;
     276    time_patch1=0;
     277    time_civ2=0;
     278    time_patch2=0;
    279279    if ~isempty(RUNHandle)% update the waitbar in interactive mode with GUI series  (checkrun=1)
    280280        update_waitbar(WaitbarHandle,ifield/NbField)
     
    335335    %% Civ1
    336336    % if Civ1 computation is requested
    337     if isfield (Param.ActionInput,'Civ1')
     337    if Param.ActionInput.CheckCiv1
    338338        if CheckInputFile
    339339            disp('civ1 started')
     
    377377                end
    378378                ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(ifield),[],j2_series_Civ1(ifield));
    379                     if isempty(FileType_B)% determine the image type for the first field
    380                         [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
    381                         FileType_B=FileInfo_B.FileType;
    382                     end
    383                     if isempty(regexp(ImageName_B,'(^http://)|(^https://)', 'once')) && ~exist(ImageName_B,'file')
    384                         disp([ImageName_B ' missing'])
    385                         continue
    386                     end
    387                     [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ1(ifield));
     379                if isempty(FileType_B)% determine the image type for the first field
     380                    [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
     381                    FileType_B=FileInfo_B.FileType;
     382                end
     383                if isempty(regexp(ImageName_B,'(^http://)|(^https://)', 'once')) && ~exist(ImageName_B,'file')
     384                    disp([ImageName_B ' missing'])
     385                    continue
     386                end
     387                [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ1(ifield));
    388388            catch ME % display errors in reading input images
    389389                if ~isempty(ME.message)
     
    392392                end
    393393            end
     394           
    394395            % par_civ1.ImageWidth=size(par_civ1.ImageA,2);
    395396            % par_civ1.ImageHeight=size(par_civ1.ImageA,1);
     
    425426            end
    426427            Data.ListGlobalAttribute=[ListGlobalAttribute Civ1_param];
     428           
    427429            Data.CivStage=1;
    428430        else
     
    438440        Data.VarAttribute{5}.Role='ancillary';
    439441        Data.VarAttribute{6}.Role='errorflag';
    440 
     442       
    441443        % case of mask
    442444        if par_civ1.CheckMask&&~isempty(par_civ1.Mask)
     
    451453                i1_mask=mod(i1-1,par_civ1.NbSlice)+1;
    452454                maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',i1_mask);
    453             else
    454                 maskname=Param.ActionInput.Civ1.Mask;
    455             end
    456             if strcmp(maskoldname,maskname)% mask exist, not already read in civ1
    457                 par_civ1.Mask=mask; %use mask already opened
    458             else
    459                 if ~isempty(regexp(maskname,'(^http://)|(^https://)', 'once'))|| exist(maskname,'file')
    460                     try
    461                         par_civ1.Mask=imread(maskname);%update the mask, an store it for future use
    462                     catch ME
    463                         if ~isempty(ME.message)
    464                             errormsg=['error reading input image: ' ME.message];
    465                             disp_uvmat('ERROR',errormsg,checkrun)
    466                             return
    467                         end
     455                if strcmp(Param.ActionInput.PairIndices.ListPairMode,'series(Di)')% case of volume, mask index refers to j index
     456                    par_civ1.NbSlice_j=par_civ1.NbSlice;
     457                end
     458            end
     459        else
     460            maskname=Param.ActionInput.Civ1.Mask;
     461        end
     462        if strcmp(maskoldname,maskname)% mask exist, not already read in civ1
     463            par_civ1.Mask=mask; %use mask already opened
     464        else
     465            if ~isempty(regexp(maskname,'(^http://)|(^https://)', 'once'))|| exist(maskname,'file')
     466                try
     467                    par_civ1.Mask=imread(maskname);%update the mask, an store it for future use
     468                catch ME
     469                    if ~isempty(ME.message)
     470                        errormsg=['error reading input image: ' ME.message];
     471                        disp_uvmat('ERROR',errormsg,checkrun)
     472                        return
    468473                    end
    469                 else
    470                     par_civ1.Mask=[];
    471                 end
    472                 mask=par_civ1.Mask;
    473                 maskoldname=maskname;
    474             end
    475         end
    476 
     474                end
     475            else
     476                par_civ1.Mask=[];
     477            end
     478            mask=par_civ1.Mask;
     479            maskoldname=maskname;
     480        end
     481       
     482       
    477483        % case of input grid
    478484        if par_civ1.CheckGrid &&~isempty(par_civ1.Grid)
     
    481487            par_civ1.CorrBoxSize=GridData.CorrBox;
    482488        end
    483 
    484         % caluclate velocity data 
     489       
     490        % caluclate velocity data
    485491        tstart_civ1=tic;
    486492        [Data.Civ1_X,Data.Civ1_Y,Data.Civ1_U,Data.Civ1_V,Data.Civ1_C,Data.Civ1_FF, result_conv, errormsg] = civ (par_civ1);
     
    489495            return
    490496        end
    491 
    492     else% we use existing Civ1 data
     497       
    493498        if exist('ncfile','var')
    494499            CivFile=ncfile;
    495             [Data,tild,tild,errormsg]=nc2struct(CivFile,'ListGlobalAttribute','absolut_time_T0'); %look for the constant 'absolut_time_T0' to detect old civx data format
    496             if ~isempty(errormsg)
    497                 disp_uvmat('ERROR',errormsg,checkrun)
    498                 return
    499             end
     500            % [Data,tild,tild,errormsg]=nc2struct(CivFile,'ListGlobalAttribute','absolut_time_T0'); %look for the constant 'absolut_time_T0' to detect old civx data format
     501            % if ~isempty(errormsg)
     502            %     disp_uvmat('ERROR',errormsg,checkrun)
     503            %     return
     504            % end
    500505            [Data,tild,tild,errormsg]=nc2struct(CivFile);%read civ1 and fix1 data in the existing netcdf file
    501506        elseif isfield(Param,'Civ1_X')
     
    510515        end
    511516    end
     517
    512518   
    513519    %% Fix1
     
    717723                i1_mask=mod(i1-1,par_civ2.NbSlice)+1;
    718724                maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',i1_mask);
     725                if strcmp(Param.ActionInput.PairIndices.ListPairMode,'series(Di)')% case of volume, mask index refers to j index
     726                    par_civ2.NbSlice_j=par_civ2.NbSlice;
     727                end
    719728            else
    720729                maskname=Param.ActionInput.Civ2.Mask;
     
    876885        if isempty(errormsg)
    877886            disp([ncfile_out ' written'])
    878             %[success,msg] = fileattrib(ncfile_out ,'+w','g');% done in struct2nc
    879887        else
    880888            disp(errormsg)
  • trunk/src/series/extract_rdvision.m

    r1163 r1164  
    160160            timestamp(ii)=m.Data(ii).timestamp;
    161161        end
    162        
    163 %         
    164 %         %%%%%BRICOLAGE EXP40
    165 %         ind1=5*59-10;
    166 %         ind2=12*59-10;
    167 %         ind3=119*59-10;
    168 %         ind4=483*59-10;
    169 %         timestamp=[timestamp(1:ind4) timestamp(ind4) timestamp(ind4+1:end)];
    170 %          timestamp=[timestamp(1:ind3) timestamp(ind3) timestamp(ind3+1:end)];
    171 %           timestamp=[timestamp(1:ind2) timestamp(ind2) timestamp(ind2+1:end)];
    172 %            timestamp=[timestamp(1:ind1) timestamp(ind1) timestamp(ind1+1:end)];
    173 %            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    174            
    175            
     162
    176163        if ParamOut.ActionInput.Createxml
    177164            ParamOut.ActionInput.XmlData.Camera.BurstTiming=time2xmlburst(timestamp,ParamOut.ActionInput.BurstLength);
     
    457444end
    458445bin_file_counter=0;
    459 %for ii=1:SeqData.nb_frames
    460  %%%%%BRICOLAGE EXP40
    461         ind1=5*59-10;
    462         ind2=12*59-10;
    463         ind3=119*59-10;
    464         ind4=483*59-10;
    465446
    466447for ii=first:last
    467448    j1=[];
    468449    iinew=ii;
    469 %     %%%%%BRICOLAGE EXP40
    470 %     switch ii
    471 %         case  ii>=ind1 && ii<ind2
    472 %       iinew=ii+1;
    473 %         case ii>=ind2 && ii<ind3
    474 %         iinew=ii+2;
    475 %         case  ii>=ind3 && ii<ind4
    476 %       iinew=ii+3;
    477 %         case       ii>=ind4 && ii<ind3
    478 %         iinew=ii+4;   
    479 %     end
    480 %      %%%%%%%%%
     450
    481451    if ~isequal(nbfield2,1)
    482452        j1=mod(iinew-1,nbfield2)+1;
  • trunk/src/uvmat.m

    r1163 r1164  
    21982198%------------------------------------------------------------------------
    21992199% --- Fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
    2200 function errormsg=display_file_name(handles,fileinput,index)
     2200function errormsg=display_file_name(handles,fileinput,input_line)
    22012201%------------------------------------------------------------------------
    22022202%% look for the input file existence
     
    22082208end
    22092209
    2210 %% define the relevant handles for the first field series (index=1) or the second file series (index=2)
    2211 if ~exist('index','var')
    2212     index=1;
    2213 end
    2214 if index==1
     2210%% define the relevant handles for the first field series (input_line=1) or the second file series (input_line=2)
     2211if ~exist('input_line','var')
     2212    input_line=1;
     2213end
     2214if input_line==1
    22152215    handles_RootPath=handles.RootPath;
    22162216    handles_SubDir=handles.SubDir;
     
    22192219    handles_NomType=handles.NomType;
    22202220    handles_FileExt=handles.FileExt;
    2221 elseif index==2
     2221elseif input_line==2
    22222222    handles_RootPath=handles.RootPath_1;
    22232223    handles_SubDir=handles.SubDir_1;
     
    22872287        set(handles_NomType,'String',NomType);
    22882288        set(handles_FileExt,'String',FileExt);
    2289         if index==1
     2289        if input_line==1
    22902290            % fill file index counters if the first file series is opened
    22912291            set(handles.i1,'String',num2str(i1));
     
    22932293            set(handles.j1,'String',num2stra(j1,NomType));
    22942294            set(handles.j2,'String',num2stra(j2,NomType));
     2295            if isfield(FileInfo,'MaskFile')
     2296                set(handles.CheckMask,'Value',1)
     2297                 Mask.File=FileInfo.MaskFile;
     2298                 if isfield(FileInfo,'MaskNbSlice')
     2299                     Mask.NbSlice=FileInfo.MaskNbSlice;
     2300                 elseif isfield(FileInfo,'VolumeScan')
     2301                     Mask.VolumeScan=FileInfo.VolumeScan;
     2302                 end 
     2303                 set(handles.CheckMask,'UserData', Mask)
     2304            else
     2305                set(handles.CheckMask,'Value',0)
     2306                CheckMask_Callback(handles.CheckMask, [], handles)
     2307            end                         
    22952308        else %read the current field index to synchronise with the first series
    22962309            i1_s=str2num(get(handles.i1,'String'));
     
    23512364       
    23522365        % initiate input file series and inputfilerefresh the current field view:
    2353         update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,index);
     2366        update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,input_line);
    23542367end
    23552368
     
    23792392% --- Update information about a new field series (indices to scan, timing,
    23802393%     calibration from an xml file, then inputfilerefresh current plots
    2381 function errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,VideoObject,index)
     2394function errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,VideoObject,input_line)
    23822395%------------------------------------------------------------------------
    23832396errormsg=''; %default error msg
    23842397
    2385 %% define the relevant handles depending on the index (1=first file series, 2= second file series)
    2386 if ~exist('index','var')
    2387     index=1;
    2388 end
    2389 if index==1
     2398%% define the relevant handles depending on the input_line (1=first file series, 2= second file series)
     2399if ~exist('input_line','var')
     2400    input_line=1;
     2401end
     2402if input_line==1
    23902403    handles_Fields=handles.FieldName;
    2391 elseif index==2
     2404elseif input_line==2
    23922405    handles_Fields=handles.FieldName_1;
    23932406end
     
    23982411UvData.NewSeries=1; %flag for REFRESH: begin a new series
    23992412UvData.FileName_1='';% name of the current second field (used to detect a  constant field during file scanning)
    2400 %UvData.FileType{index}=FileInfo.FileType;
    2401 UvData.FileInfo{index}=FileInfo;
    2402 UvData.MovieObject{index}=VideoObject;
    2403 UvData.i1_series{index}=i1_series;
    2404 UvData.i2_series{index}=i2_series;
    2405 UvData.j1_series{index}=j1_series;
    2406 UvData.j2_series{index}=j2_series;
     2413%UvData.FileType{input_line}=FileInfo.FileType;
     2414UvData.FileInfo{input_line}=FileInfo;
     2415UvData.MovieObject{input_line}=VideoObject;
     2416UvData.i1_series{input_line}=i1_series;
     2417UvData.i2_series{input_line}=i2_series;
     2418UvData.j1_series{input_line}=j1_series;
     2419UvData.j2_series{input_line}=j2_series;
    24072420nbfield=max(max(max(i2_series)));% total number of fields (i index)
    24082421if isempty(nbfield)
     
    24472460%% read parameters (time, geometric calibration..) from a documentation file (.xml advised)
    24482461XmlData.GeometryCalib=[];%default
    2449 if index==1
     2462if input_line==1
    24502463    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    24512464else
     
    25152528    TimeName='civdata_3D';
    25162529end
    2517 if index==1
     2530if input_line==1
    25182531    set(handles.TimeName,'String',TimeName)
    25192532else
     
    25312544last_i_cell=get(handles.MaxIndex_i,'String');
    25322545if isempty(nbfield)
    2533     last_i_cell{index}='';
    2534 else
    2535     last_i_cell{index}=num2str(nbfield);
     2546    last_i_cell{input_line}='';
     2547else
     2548    last_i_cell{input_line}=num2str(nbfield);
    25362549end
    25372550set(handles.MaxIndex_i,'String',last_i_cell)
    25382551last_j_cell=get(handles.MaxIndex_j,'String');
    25392552if isempty(nbfield_j)
    2540      last_j_cell{index}='';
    2541 else
    2542      last_j_cell{index}=num2str(nbfield_j);
     2553     last_j_cell{input_line}='';
     2554else
     2555     last_j_cell{input_line}=num2str(nbfield_j);
    25432556end
    25442557set(handles.MaxIndex_j,'String',last_j_cell);
     
    25522565        set(handles.pxcmx,'Visible','off')
    25532566        set(handles.pxcmy,'Visible','off')
    2554         if index==1
     2567        if input_line==1
    25552568        set(handles.TransformName,'Value',1); %  no transform by default
    25562569        end
     
    25682581            set(handles.pxcmy,'String',num2str(pixcmy))
    25692582        end
    2570         if ~get(handles.CheckFixLimits,'Value')&& index==1
     2583        if ~get(handles.CheckFixLimits,'Value')&& input_line==1
    25712584            set(handles.TransformName,'Value',3); % phys transform by default if fixedLimits is off
    25722585        end
     
    25912604%% update the data attached to the uvmat interface
    25922605if ~isempty(TimeUnit)
    2593     if index==2 && isfield(UvData,'TimeUnit') && ~strcmp(UvData.TimeUnit,TimeUnit)
     2606    if input_line==2 && isfield(UvData,'TimeUnit') && ~strcmp(UvData.TimeUnit,TimeUnit)
    25942607        msgbox_uvmat('WARNING',['time unit for second file series ' TimeUnit ' inconsistent with first series'])
    25952608    else
     
    25972610    end
    25982611end
    2599 UvData.XmlData{index}=XmlData;
     2612UvData.XmlData{input_line}=XmlData;
    26002613UvData.NewSeries=1;
    26012614set(handles.uvmat,'UserData',UvData)
     
    26122625        set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
    26132626        set(handles_Fields,'Value',2) % set menu to 'velocity
    2614         if index==1
     2627        if input_line==1
    26152628            set(handles.FieldName_1,'Value',1);
    26162629            set(handles.FieldName_1,'String',[{''};{'image'};FieldList;{'get_field...'}]);%standard menu for civx data reproduced for the second field
     
    26272640        set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
    26282641        set(handles_Fields,'Value',2) % set menu to 'velocity
    2629         if index==1
     2642        if input_line==1
    26302643            set(handles.FieldName_1,'Value',1);
    26312644            set(handles.FieldName_1,'String',[{''};{'image'};FieldList;{'get_field...'}]);%standard menu for civx data reproduced for the second field
     
    26412654        set(handles_Fields,'Value',1)
    26422655        set(handles_Fields,'String',{'get_field...'})
    2643         if index==1
     2656        if input_line==1
    26442657            FieldName_Callback([],[], handles)
    26452658        else
     
    26602673scan_option='i';%default
    26612674state_j='off'; %default
    2662 if index==2
     2675if input_line==2
    26632676    if get(handles.scan_j,'Value')
    26642677        scan_option='j'; %keep the scan option for the second file series
     
    26722685    if ~isempty(j1_series)
    26732686        state_j='on';
    2674         if index==1
     2687        if input_line==1
    26752688            if isequal(ref_i,ref_i(1)*ones(size(ref_j)))% if ref_i is always equal to its first value
    26762689                scan_option='j'; %scan j indext
     
    27072720if ~isempty(i2_series)||~isempty(j2_series)
    27082721    set(handles.CheckFixPair,'Visible','on')
    2709 elseif index==1
     2722elseif input_line==1
    27102723    set(handles.CheckFixPair,'Visible','off')
    27112724end
     
    27132726%% apply the effect of the transform fct and view the field
    27142727transform=get(handles.TransformPath,'UserData');
    2715 if index==2 && (~isa(transform,'function_handle')||nargin(transform)<3)
     2728if input_line==2 && (~isa(transform,'function_handle')||nargin(transform)<3)
    27162729    set(handles.TransformName,'value',2); % set transform to sub_field if the current fct doe not accept two input fields
    27172730end
     
    29082921    end
    29092922    if mdetect==0 % if no mask is detected in the current folder
    2910         MaskFullName=uigetfile_uvmat('pick a mask image file:',RootPath,'image');
    2911         if isempty(MaskFullName)
    2912             set(handles.CheckMask,'Value',0)
    2913         end
    2914 
    2915         [MaskPath,MaskName,MaskExt]=fileparts(MaskFullName);
    2916         [tild,tild,MaskFile,i1_series,i2,j1,j2,MaskNomType]=find_file_series(MaskPath,[MaskName MaskExt],0);
     2923         filemask= uigetfile_uvmat('pick a mask image file:',RootPath,'image');
     2924    if ~isempty(filemask)
     2925        [FilePath,FileName,FileExt]=fileparts(filemask);
     2926        [RootPath,SubDir,RootFile,i1_series,i2,j1,j2,NomType]=find_file_series(FilePath,[FileName FileExt]);
    29172927        if strcmp(NomType,'_1')
    29182928            NbSlice=i1_series(1,2,end);
    2919            set(handles.num_NbSlice,'String',num2str(NbSlice))
    2920         end
     2929            set(handles.num_NbSlice,'String',num2str(NbSlice))
     2930        elseif ~strcmp(NomType,'*')
     2931            msgbox_uvmat('ERROR','multilevel masks must be labeled with a single index as _1,_2,...');
     2932            return
     2933        end
     2934        set(hObject,'UserData',filemask);%store for future use
     2935        testmask=1;
     2936    end
     2937       
     2938        %TO COMPLEMENT......................
     2939         
     2940       
     2941%         MaskFullName=uigetfile_uvmat('pick a mask image file:',RootPath,'image');
     2942%         if isempty(MaskFullName)
     2943%             set(handles.CheckMask,'Value',0)
     2944%         end
     2945%
     2946%         [MaskPath,MaskName,MaskExt]=fileparts(MaskFullName);
     2947%         [tild,tild,MaskFile,i1_series,i2,j1,j2,MaskNomType]=find_file_series(MaskPath,[MaskName MaskExt],0);
     2948%         if strcmp(MaskNomType,'_1')
     2949%             NbSlice=i1_series(1,2,end);
     2950%            set(handles.num_NbSlice,'String',num2str(NbSlice))
     2951%         end
    29212952    end
    29222953    % Mask.Path=MaskPath;
     
    29612992%------------------------------------------------------------------------
    29622993errormsg=[];%default
    2963 Mask=get(handles.CheckMask,'UserData');
    2964 if strcmp(get(handles.z_index,'Visible'),'on')
    2965     MaskIndex_i=str2num(get(handles.z_index,'String'));
    2966 else
    2967     MaskIndex_i=mod(str2num(get(handles.i1,'String'))-1,Mask.NbSlice_i)+1;
    2968 end
    2969 MaskIndex_z=MaskIndex_i;%default
    2970 if Mask.NbSlice_j>1
    2971     MaskIndex_j=str2num(get(handles.j1,'String'));
    2972     MaskIndex_z=MaskIndex_j;
    2973 else
    2974     MaskIndex_j=1;
    2975 end
    2976 if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
    2977     uistack(Mask.maskhandle,'top');
    2978 end
    2979 MaskName=fullfile_uvmat(Mask.Path,'',Mask.File,Mask.Ext,Mask.NomType,MaskIndex_i,[],MaskIndex_j);
    2980 UvData=get(handles.uvmat,'UserData');
    2981 
    2982 %% update mask image if the mask is new
    2983 if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
    2984     UvData.MaskName=MaskName; %update the recorded name on UvData
    2985     set(handles.uvmat,'UserData',UvData);
    2986     if ~exist(MaskName,'file')
    2987         if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
    2988             delete(Mask.maskhandle)
    2989         end
     2994MaskName='';
     2995
     2996%% get the current mask name recorded in CheckMask/UserData, possibly indexed with file index
     2997MaskInfo=get(handles.CheckMask,'UserData');
     2998if isfield(MaskInfo,'File')
     2999    if isfield(MaskInfo,'NbSlice')
     3000        if isfield(MaskInfo,'VolumeScan') &&  MaskInfo.VolumeScan
     3001            MaskIndex_i=str2num(get(handles.j1,'String'));
     3002        else
     3003            MaskIndex_i=mod(str2num(get(handles.i1,'String'))-1,MaskInfo.NbSlice)+1;
     3004        end
     3005        MaskName=[MaskInfo.File '_' num2str(MaskIndex_i) '.png'];
    29903006    else
    2991         %read mask image
    2992         [MaskField,tild,errormsg] = read_field(MaskName,'image');
    2993         if ~isempty(errormsg)
    2994             return
    2995         end
    2996         npxy=size(MaskField.A);
    2997         if length(npxy)>2
    2998             errormsg=[MaskName ' is not a grey scale image'];
    2999             return
    3000         elseif ~isa(MaskField.A,'uint8')
    3001             errormsg=[MaskName ' is not a 8 bit grey level image'];
    3002             return
    3003         end
    3004         MaskField.ZIndex=MaskIndex_z;
    3005         %px to phys or other transform on field
    3006          menu_transform=get(handles.TransformName,'String');
    3007         choice_value=get(handles.TransformName,'Value');
    3008         transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
    3009         transform=get(handles.TransformPath,'UserData');
    3010         if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
    3011             if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
    3012                 Calib=UvData.XmlData{1}.GeometryCalib;
    3013                 MaskField=transform(MaskField,UvData.XmlData{1});
    3014             end
    3015         end
    3016         flagmask=MaskField.A < 200;
    3017 
    3018         %make brown color image
    3019         imflag(:,:,1)=0.9*flagmask;
    3020         imflag(:,:,2)=0.7*flagmask;
    3021         imflag(:,:,3)=zeros(size(flagmask));
    3022 
    3023         %update mask image
    3024         hmask=[]; %default
    3025         if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
    3026             hmask=Mask.maskhandle;
    3027         end
    3028         if ~isempty(hmask)
    3029             set(hmask,'CData',imflag)
    3030             set(hmask,'AlphaData',flagmask*0.6)
    3031             set(hmask,'XData',MaskField.Coord_x);
    3032             set(hmask,'YData',MaskField.Coord_y);
    3033 %             uistack(hmask,'top')
     3007        MaskIndex_i=1;
     3008        MaskName=MaskInfo.MaskFile;
     3009    end
     3010   
     3011    %% update mask image if the mask is new
     3012    UvData=get(handles.uvmat,'UserData');
     3013    if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
     3014        UvData.MaskName=MaskName; %update the recorded name on UvData
     3015        set(handles.uvmat,'UserData',UvData);
     3016        if ~exist(MaskName,'file')
     3017            if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
     3018                delete(Mask.maskhandle)
     3019            end
    30343020        else
    3035             axes(handles.PlotAxes)
    3036             hold on
    3037             Mask.maskhandle=image(MaskField.Coord_x,MaskField.Coord_y,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask)));
    3038             set(handles.CheckMask,'UserData',Mask)
    3039         end
    3040     end
    3041 end
    3042 
     3021            %read mask image
     3022            [MaskField,tild,errormsg] = read_field(MaskName,'image');
     3023            if ~isempty(errormsg)
     3024                return
     3025            end
     3026            npxy=size(MaskField.A);
     3027            if length(npxy)>2
     3028                errormsg=[MaskName ' is not a grey scale image'];
     3029                return
     3030            elseif ~isa(MaskField.A,'uint8')
     3031                errormsg=[MaskName ' is not a 8 bit grey level image'];
     3032                return
     3033            end
     3034            MaskField.ZIndex=MaskIndex_i;
     3035            %px to phys or other transform on field
     3036            menu_transform=get(handles.TransformName,'String');
     3037            choice_value=get(handles.TransformName,'Value');
     3038            transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
     3039            transform=get(handles.TransformPath,'UserData');
     3040            if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
     3041                if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
     3042                    Calib=UvData.XmlData{1}.GeometryCalib;
     3043                    MaskField=transform(MaskField,UvData.XmlData{1});
     3044                end
     3045            end
     3046            flagmask=MaskField.A < 200;
     3047           
     3048            %make brown color image
     3049            imflag(:,:,1)=0.9*flagmask;
     3050            imflag(:,:,2)=0.7*flagmask;
     3051            imflag(:,:,3)=zeros(size(flagmask));
     3052           
     3053            %update mask image
     3054            hmask=[]; %default
     3055            if isfield(MaskInfo,'maskhandle')&& ishandle(MaskInfo.maskhandle)
     3056                hmask=MaskInfo.maskhandle;
     3057            end
     3058            if ~isempty(hmask)
     3059                set(hmask,'CData',imflag)
     3060                set(hmask,'AlphaData',flagmask*0.6)
     3061                set(hmask,'XData',MaskField.Coord_x);
     3062                set(hmask,'YData',MaskField.Coord_y);
     3063                %             uistack(hmask,'top')
     3064            else
     3065                axes(handles.PlotAxes)
     3066                hold on
     3067                MaskInfo.maskhandle=image(MaskField.Coord_x,MaskField.Coord_y,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask)));
     3068                set(handles.CheckMask,'UserData',MaskInfo)
     3069            end
     3070        end
     3071    end
     3072end
    30433073%------------------------------------------------------------------------
    30443074%------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.