Changeset 512 for trunk/src/uvmat.m


Ignore:
Timestamp:
Aug 3, 2012, 2:50:24 PM (12 years ago)
Author:
sommeria
Message:

various cleaning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uvmat.m

    r511 r512  
    5151%
    5252% 1) Input filenames are determined by MenuBrowse (first field), MenuBrowse_1
    53 % (second field), or by the stored file names under  Browse, or as an input of uvmat.
    54 % 2) These functions call 'display_file_name.m' which detects the file series, and fills the file index boxes
    55 % 3) Then 'update_rootinfo.m' Updates information about a new field series (indices to scan, timing, calibration from an xml file)
    56 % 4) Then fields are opened and visualised by the main sub-function 'refresh_field.m'
    57 % The function first reads the name of the input file from the edit boxes  of the GUI
    58 % A second input file can be introduced for file comparison
    59 % It then reads the input file(s) with the appropriate function, read for
    60 % images, read_civxdata.m for CIVx PIV data, nc2struct for other netcdf
    61 % files.
    62 %               Main input open   second input open(_1)        second image (pair animation)
    63 %            |                 |                             
    64 %            |                 |                                               
    65 %                     Field{1}         Field{2}               
    66 %                                                                         |
    67 % coord transform (phys.m) or other user defined  fct acting on Field{i}  |
    68 %                                                                   Field{i}
    69 %                                                                    |
    70 % calc_field.m: calculate scalar or other derived fields (vort, div..).
     53% (second field), or by the stored file name .FileName_1, or as an input of uvmat.
     54% 2) These functions call 'uvmat/display_file_name.m' which detects the file series, and fills the file index boxes
     55% 3) Then 'uvmat/update_rootinfo.m' Updates information about a new field series (indices to scan, timing, calibration from an xml file)
     56% 4) Then fields are opened and visualised by the main sub-function 'uvmat/refresh_field.m'
     57% The function first reads the name of the input file(s) (one or two) from the edit boxes  of the GUI
     58% It then reads the input file(s) with the function read_field.m and perform the following list of operations:
    7159%
    72 % sub_field.m: combine the input Field{i} in a single set of fields (vector + scalar):
    73 %              Field{i=1->3}.X --> UvData.X                          |
    74 %                                                                    |
    75 %                                                                 UvData
    76 %                                                                    |
    77 % plot histograms of the whole  field
    78 % proj_field.m: project the set of fields on the current projection objects defined by UvData.Object
    79 %                                                                    |                                                                          |
    80 %                                                                ObjectData
    81 %                                                                    |
    82 % plot_field.m: plot the projected fields and store them as          |
    83 % UvData.PlotAxes                                        |
    84 %                                                                    |
    85 %                                                                AxeData
     60%    %%%%%%%%  structure of uvmat/refresh_field.m %%%%%%%%
     61%
     62%           Main input open       second input open_1       
     63%                    |                   | 
     64%             read_field.m            read_field.m
     65%                    |                   |
     66%                 Field{1}            Field{2}               
     67%                    |                   |                                 
     68%                    --->transform fct<---             transform (e.g. phys.m) and combine input fields 
     69%                            |                                   
     70%                        (calc_tps.m)               calculate tps coefficients (for filter projection or spatial derivatives).
     71%                            |
     72%                       (calc_field.m)               calculate field
     73%                            |
     74%                       UvData.Field-------------->histogram
     75%               _____________|____________
     76%              |                          |                   
     77%        proj_field.m               proj_field.m       project the field on the projection objects             
     78%              |                          |
     79%         UvData.PlotAxes          ViewData.PlotAxes (on view_field)
     80%              |                          |
     81%       plot_field.m (uvmat)       plot_field.m (view_field)      plot the projected fields
     82%
     83% rmq: calc_field can be performed instead at the level of proj_field when needed
     84%
    8685%
    8786%%%%%%%%%%%%%%    SCALARS: %%%%%%%%%%%%??%%%
     
    357356function MenuBrowse_Callback(hObject, eventdata, handles)
    358357[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    359 oldfile=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
     358%oldfile=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
     359oldfile=fullfile(RootPath,SubDir);
    360360if isempty(oldfile)||isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
    361361         dir_perso=prefdir;
     
    371371fileinput=[PathName FileName];%complete file name
    372372if ~exist(fileinput,'file')
    373     return %abandon of the browser is cancelled
     373    return %abandon if the browser is cancelled
    374374end
    375375
     
    10141014    end
    10151015end
    1016 [ref_i,ref_j]=find(i1_series);
     1016[ref_j,ref_i]=find(i1_series);
    10171017if ~isempty(j1_series)
    10181018        state_j='on';
     
    15831583        if get(handles.scan_i,'Value')==1% case of scanning along index i
    15841584            ref_i=ref_i+step;
    1585             while ref_i>=0  && size(UvData.i1_series{1},1)>=ref_i+1 && UvData.i1_series{1}(ref_i+1,ref_j+1,1)==0
     1585            while ref_i>=0  && size(UvData.i1_series{1},3)>=ref_i+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0
    15861586                ref_i=ref_i+step;
    15871587            end
    15881588        else % case of scanning along index j (burst numbers)
    15891589            ref_j=ref_j+step;
    1590             while ref_j>=0  && size(UvData.i1_series{1},2)>=ref_j+1 && UvData.i1_series{1}(ref_i+1,ref_j+1,1)==0
     1590            while ref_j>=0  && size(UvData.i1_series{1},2)>=ref_j+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0
    15911591                ref_j=ref_j+step;
    15921592            end
     
    15971597    elseif ref_j<0
    15981598        errormsg='minimum j index reached';
    1599     elseif ref_i+1>size(UvData.i1_series{1},1)
     1599    elseif ref_i+1>size(UvData.i1_series{1},3)
    16001600        errormsg='maximum i index reached (reload the input file to update the index bound)';
    16011601    elseif ref_j+1>size(UvData.i1_series{1},2)
     
    16031603    end
    16041604    if ~isempty(errormsg),return,end
    1605     i1_subseries=UvData.i1_series{1}(ref_i+1,ref_j+1,:);
    1606     i1_subseries=i1_subseries(i1_subseries>0);
    1607     if isempty(i1_subseries)% case of pairs
    1608         i1_subseries=UvData.i1_series{1}(ref_i+1,:,:);
    1609     end
    1610     if isempty(i1_subseries),errormsg='no next frame: set num_IndexIncrement =''*'' to reach the next existing file';return
    1611     else
    1612         i1=i1_subseries(end);
    1613     end
     1605    siz=size(UvData.i1_series{1});
     1606    ref_indices=ref_i*siz(1)*siz(2)+ref_j*siz(1)+1:ref_i*siz(1)*siz(2)+(ref_j+1)*siz(1);   
     1607    i1_subseries=UvData.i1_series{1}(ref_indices);
     1608    ref_indices=ref_indices(i1_subseries>0);
     1609    if isempty(ref_indices)% case of pairs (free index i)
     1610        ref_indices=ref_i*siz(1)*siz(2)+1:(ref_i+1)*siz(1)*siz(2);
     1611        i1_subseries=UvData.i1_series{1}(ref_indices);
     1612        ref_indices=ref_indices(i1_subseries>0);
     1613    end
     1614    if isempty(ref_indices),errormsg='no next frame: set num_IndexIncrement =''*'' to reach the next existing file';return
     1615    end
     1616    i1=UvData.i1_series{1}(ref_indices(end));
    16141617    if ~isempty(UvData.i2_series{1})
    1615         i2_subseries=UvData.i2_series{1}(ref_i+1,ref_j+1,:);
    1616         i2_subseries=i2_subseries(i2_subseries>0);
    1617         i2=i2_subseries(end);
     1618        i2=UvData.i2_series{1}(ref_indices(end));
    16181619    end
    16191620    if ~isempty(UvData.j1_series{1})
    1620         j1_subseries=UvData.j1_series{1}(ref_i+1,ref_j+1,:);
    1621         j1_subseries=j1_subseries(j1_subseries>0);
    1622         j1=j1_subseries(end);
     1621        j1=UvData.j1_series{1}(ref_indices(end));
    16231622    end
    16241623    if ~isempty(UvData.j2_series{1})
    1625         j2_subseries=UvData.j2_series{1}(ref_i+1,ref_j+1,:);
    1626         j2_subseries=j2_subseries(j2_subseries>0);
    1627         j2=j2_subseries(end);
     1624        j2=UvData.j2_series{1}(ref_indices(end));
    16281625    end 
    1629     % case of a second file series
     1626    % case of a second file series (TODO:revise)
    16301627    if numel(UvData.i1_series)>=2
    16311628        i1_subseries=UvData.i1_series{2}(ref_i+1,ref_j+1,:);
     
    17051702UvData=get(handles.uvmat,'UserData');
    17061703if isequal(FieldName,'image')
    1707     test_1=0;
     1704    index=1;
    17081705    [RootPath,SubDir,RootFile,FileIndices,Ext]=read_file_boxes(handles);
    17091706    NomType=get(handles.NomType,'String');
     
    17131710    FieldName=list_fields{index_fields}; % selected field
    17141711    if isequal(FieldName,'image')
    1715         test_1=1;
     1712        index=2;
    17161713        [RootPath,tild,RootFile,FileIndex_1,Ext,NomType]=read_file_boxes_1(handles);
    17171714    else
     
    17391736    num_i2=num_i1;%repeat the index i1 by default
    17401737end
    1741 % imaname_1=name_generator(filebase,num_i2,num_j2,Ext,NomType);
    17421738imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,Ext,NomType,num_i2,[],num_j2);
     1739if strcmp(NomType,'*')
     1740    num_frame=num_i2;
     1741else
     1742    num_frame=num_j2;
     1743end
    17431744if ~exist(imaname_1,'file')
    17441745      msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
     
    17481749end
    17491750
     1751%% get the first image
     1752%Field.AName='image';
     1753if index==1
     1754    Field_a=UvData.Field;% movie on the second field
     1755else
     1756    Field_a=UvData.Field_1;% movie on the first field
     1757end
     1758
    17501759%% read the second image
    1751 Field.AName='image';
    1752 if test_1
    1753     Field_a=UvData.Field_1;
    1754 else
    1755     Field_a=UvData.Field;
    1756 end
    1757 Field_b.AX=Field_a.AX;
    1758 Field_b.AY=Field_a.AY;
    1759 % z index
    1760 nbslice=str2double(get(handles.num_NbSlice,'String'));
    1761 if ~isempty(nbslice)
    1762     Field_b.ZIndex=mod(num_i2-1,nbslice)+1;
    1763 end
    1764 Field_b.CoordUnit='pixel';
    1765 
    1766 %% determine the input file type
    1767 if (test_1 && isfield(UvData,'MovieObject')&& numel(UvData.MovieObject>=2))||(~test_1 && ~isempty(UvData.MovieObject{1}))
    1768     FileType='movie';
    1769 elseif isequal(lower(Ext),'.avi')
    1770     FileType='avi';
    1771 elseif isequal(lower(Ext),'.vol')
    1772     FileType='vol';
    1773 else
    1774    form=imformats(Ext(2:end));
    1775    if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
    1776        if isequal(NomType,'*');
    1777            FileType='multimage';
    1778        else
    1779            FileType='image';
    1780        end
    1781    end
    1782 end
    1783 switch FileType
    1784         case 'movie'
    1785             if test_1
    1786                 Field_b.A=read(UvData.MovieObject{2},num_i2);
    1787             else
    1788                 Field_b.A=read(UvData.MovieObject{1},num_i2);
    1789             end
    1790         case 'avi'
    1791             mov=aviread(imaname_1,num_i2);
    1792             Field_b.A=frame2im(mov(1));
    1793         case 'vol'
    1794             Field_b.A=imread(imaname_1);
    1795         case 'multimage'
    1796             Field_b.A=imread(imaname_1,num_i2);
    1797         case 'image'
    1798             Field_b.A=imread(imaname_1);
    1799 end
    1800 if get(handles.slices,'Value')
    1801     Field.ZIndex=str2double(get(handles.z_index,'String'));
    1802 end
     1760MovieObject=[];
     1761if numel(UvData.MovieObject)>=index
     1762    MovieObject=UvData.MovieObject{index};
     1763end
     1764[Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileType{index},MovieObject,num_frame)
     1765% Field_b.AX=Field_a.AX;
     1766% Field_b.AY=Field_a.AY;
     1767% % z index
     1768% nbslice=str2double(get(handles.num_NbSlice,'String'));
     1769% if ~isempty(nbslice)
     1770%     Field_b.ZIndex=mod(num_i2-1,nbslice)+1;
     1771% end
     1772% Field_b.CoordUnit='pixel';
     1773%
     1774% %% determine the input file type
     1775% if (test_1 && isfield(UvData,'MovieObject')&& numel(UvData.MovieObject>=2))||(~test_1 && ~isempty(UvData.MovieObject{1}))
     1776%     FileType='movie';
     1777% elseif isequal(lower(Ext),'.avi')
     1778%     FileType='avi';
     1779% elseif isequal(lower(Ext),'.vol')
     1780%     FileType='vol';
     1781% else
     1782%    form=imformats(Ext(2:end));
     1783%    if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
     1784%        if isequal(NomType,'*');
     1785%            FileType='multimage';
     1786%        else
     1787%            FileType='image';
     1788%        end
     1789%    end
     1790% end
     1791% switch FileType
     1792%         case 'movie'
     1793%             if test_1
     1794%                 Field_b.A=read(UvData.MovieObject{2},num_i2);
     1795%             else
     1796%                 Field_b.A=read(UvData.MovieObject{1},num_i2);
     1797%             end
     1798%         case 'avi'
     1799%             mov=aviread(imaname_1,num_i2);
     1800%             Field_b.A=frame2im(mov(1));
     1801%         case 'vol'
     1802%             Field_b.A=imread(imaname_1);
     1803%         case 'multimage'
     1804%             Field_b.A=imread(imaname_1,num_i2);
     1805%         case 'image'
     1806%             Field_b.A=imread(imaname_1);
     1807% end
     1808% if get(handles.slices,'Value')
     1809%     Field.ZIndex=str2double(get(handles.z_index,'String'));
     1810% end
    18031811
    18041812%px to phys or other transform on field
    1805 menu_transform=get(handles.transform_fct,'String');
    1806 choice_value=get(handles.transform_fct,'Value');
    1807 transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
    1808 transform_list=get(handles.transform_fct,'UserData');
    1809 transform=transform_list{choice_value};
    1810 if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
    1811     if test_1 && isfield(UvData,'XmlData') && numel(UvData.XmlData)==2 && isfield(UvData.XmlData{2},'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
    1812         Field_a=transform(Field_a,UvData.XmlData{2});%the first field has been stored without transform
    1813         Field_b=transform(Field_b,UvData.XmlData{2});
    1814     elseif ~test_1 && isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'GeometryCalib')%use geometry calib
    1815         Field_b=transform(Field_b,UvData.XmlData{1});
     1813% menu_transform=get(handles.transform_fct,'String');
     1814% choice_value=get(handles.transform_fct,'Value');
     1815% transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
     1816% transform_list=get(handles.transform_fct,'UserData');
     1817transform=get(handles.path_transform,'UserData');
     1818if  ~isempty(transform)
     1819    if isfield(UvData,'XmlData') && numel(UvData.XmlData)>=index %use geometry calib recorded from the ImaDoc xml file as first priority
     1820        if index==2
     1821        Field_a=transform(Field_a,UvData.XmlData{index});%the first field has been stored without transform
     1822        end
     1823        Field_b=transform(Field_b,UvData.XmlData{index});
    18161824    end
    18171825end
     
    22492257%% store the current open names, fields and vel types in uvmat interface
    22502258UvData.FileName_1=FileName_1;
     2259UvData.ParamOut_1=ParamOut_1;
     2260if numel(Field)==2
     2261UvData.Field_1=Field{2}; %store the second field for possible use at next RUN
     2262end
    22512263
    22522264%% apply coordinate transform or other user fct
     
    22622274    end
    22632275    transform=get(handles.path_transform,'UserData');
    2264     nbre_arg=nargin(transform);
    2265     if length(Field)==2
    2266         if nbre_arg==4
    2267             [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
    2268         else
    2269             Field{1}=transform(Field{1},XmlData);
    2270             Field(2)=[];
    2271         end
    2272     else
    2273         if nbre_arg==1
    2274             Field{1}=transform(Field{1});%transform which does not need input parameter
    2275         else
    2276             Field{1}=transform(Field{1},XmlData);
    2277         end
     2276    switch nargin(transform)
     2277        case 4
     2278            if length(Field)==2
     2279                UvData.Field=transform(Field{1},XmlData,Field{2},XmlData_1);
     2280            else
     2281                UvData.Field=transform(Field{1},XmlData);
     2282            end
     2283        case 3
     2284            if length(Field)==2
     2285                UvData.Field=transform(Field{1},XmlData,Field{2});
     2286            else
     2287                UvData.Field=transform(Field{1},XmlData);
     2288            end
     2289        case 2
     2290            UvData.Field=transform(Field{1},XmlData);
     2291        case 1
     2292            UvData.Field=transform(Field{1});
    22782293    end
    22792294end
     
    22932308       check_tps=1;%tps needed to get the requested field
    22942309end
    2295 if (check_tps ||check_proj_tps)&&~isfield(Field{1},'Coord_tps')
    2296     Field{1}=calc_tps(Field{1});
    2297 end
    2298 Field{1}.FieldList=[{ParamOut.FieldName} {ParamOut.ColorVar}];
     2310if (check_tps ||check_proj_tps)&&~isfield(UvData.Field,'Coord_tps')
     2311    UvData.Field=calc_tps(UvData.Field);
     2312end
     2313UvData.Field.FieldList=[{ParamOut.FieldName} {ParamOut.ColorVar}];
    22992314
    23002315%% calculate scalar
     
    23022317         &&~strcmp(ParamOut.FieldName,'velocity') && ~strcmp(ParamOut.FieldName,'get_field...')
    23032318    if ~check_proj_tps
    2304         Field{1}=calc_field([{ParamOut.FieldName} {ParamOut.ColorVar}],Field{1});
     2319        UvData.Field=calc_field([{ParamOut.FieldName} {ParamOut.ColorVar}],UvData.Field);
    23052320    end
    23062321end
     
    23142329end
    23152330
    2316 %% combine the two input fields (e.g. substract velocity fields)
    2317 if numel(Field)==2
    2318    [UvData.Field,errormsg]=sub_field(Field{1},Field{2}); 
    2319    UvData.Field_1=Field{2}; %store the second field for possible use at next RUN
    2320    UvData.ParamOut_1=ParamOut_1;
    2321 else
    2322    UvData.Field=Field{1};
    2323 end
    2324 if ~isempty(errormsg)
    2325     errormsg=['error in uvmat/refresh_field/sub_field:' errormsg];
    2326     return
    2327 end
    2328 %UvData.Field.FieldList={FieldName}; % TODO: to generalise, used for proj_field with tps interpolation
    23292331
    23302332%% analyse input field
     
    23362338    return
    23372339end
    2338 [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(UvData.Field);% analyse  the input field structure
     2340[CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(UvData.Field);% analyse  the input field structure
    23392341if ~isempty(errormsg)
    2340     errormsg=['error in uvmat/refresh_field/find_field_indices: ' errormsg];% display error
     2342    errormsg=['error in uvmat/refresh_field/find_field_cells: ' errormsg];% display error
    23412343    return
    23422344end
     
    35133515
    35143516%% create the function handle of the selected fct
     3517
    35153518if isempty(list_path{ichoice})% case of no selected fct
    35163519    transform_handle=[];
     
    35273530set(handles.path_transform,'String',list_path{ichoice})
    35283531set(handles.path_transform,'UserData',transform_handle)
     3532set(handles.transform_fct,'UserData',list_path)
    35293533
    35303534%% update the ToolTip string of the menu transform_fct with the first line of the selected fct file
     
    48064810ProjectDir = uigetdir(fileparts(fileparts(RootPath)), 'select the project source directory');
    48074811datatree_browser(ProjectDir)
     4812
     4813
     4814% --------------------------------------------------------------------
     4815function MenuBrowseProject_Callback(hObject, eventdata, handles)
     4816RootPath=get(handles.RootPath,'String');
     4817ProjectDir = uigetdir(fileparts(fileparts(RootPath)), 'select the project directory');
     4818datatree_browser(ProjectDir)
Note: See TracChangeset for help on using the changeset viewer.