Changeset 525 for trunk/src/series.m


Ignore:
Timestamp:
Aug 19, 2012, 1:07:24 PM (9 years ago)
Author:
sommeria
Message:

various bug repairs and cleaning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series.m

    r523 r525  
    661661
    662662%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
    663 ext_imadoc='';
    664 if exist([FileBase '.xml'],'file')
    665     ext_imadoc='.xml';
    666 elseif exist([FileBase '.civ'],'file')
    667     ext_imadoc='.civ';
    668 end
    669 %read the ImaDoc file
    670663XmlData=[];
    671664NbSlice_calib={};
    672 if isequal(ext_imadoc,'.xml')
    673         [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
     665XmlFileName=find_imadoc(InputTable{iview,1},InputTable{iview,2},InputTable{iview,3},InputTable{iview,5});
     666if ~isempty(XmlFileName)
     667        [XmlData,warntext]=imadoc2struct(XmlFileName);
    674668        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
    675669            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
     
    692686            msgbox_uvmat('WARNING',warntext)
    693687        end 
    694 elseif isequal(ext_imadoc,'.civ')
    695     [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
    696     time=XmlData.Time;
    697     if error==2, warntext=['no file ' FileBase '.civ'];
    698     elseif error==1, warntext='inconsistent number of fields in the .civ file';
    699     end 
    700688end
    701689
     
    783771for iview=1:nbview
    784772    pair_max{iview}=squeeze(max(SeriesData.i1_series{iview},[],1)); %max on pair index
     773    if strcmp(get(handles.num_first_j,'Visible'),'off')
     774        pair_max{iview}=squeeze(max(pair_max{iview},[],1)); % consider only the i index
     775    end
    785776    index_min(iview)=find(pair_max{iview}>0, 1 );
    786777    index_max(iview)=find(pair_max{iview}>0, 1, 'last' );
     
    829820
    830821
     822%% set default options in menu 'Fields'
     823switch FileType
     824    case {'civx','civdata'}
     825        [FieldList,ColorList]=calc_field;
     826        set(handles.FieldName,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
     827        set(handles.FieldName,'Value',2) % set menu to 'velocity
     828        set(handles.Coord_x,'Value',1);
     829        set(handles.Coord_x,'String',{'X'});
     830        set(handles.Coord_y,'Value',1);
     831        set(handles.Coord_y,'String',{'Y'});
     832    case 'netcdf'
     833        set(handles_Fields,'Value',1)
     834        set(handles_Fields,'String',{'get_field...'})
     835        hget_field=get_field(FileName);
     836        hhget_field=guidata(hget_field);
     837        get_field('RUN_Callback',hhget_field.RUN,[],hhget_field);
     838    otherwise
     839        set(handles_Fields,'Value',1) % set menu to 'image'
     840        set(handles_Fields,'String',{'image'})
     841        set(handles.Coord_x,'Value',1);
     842        set(handles.Coord_x,'String',{'AX'});
     843        set(handles.Coord_y,'Value',1);
     844        set(handles.Coord_y,'String',{'AY'});
     845end
    831846% %% set default options in menu 'Fields'%% TODO: check VelType
    832847% if ~testima
     
    13271342set(handles.ref_j_text,'Visible',state)
    13281343
    1329 %-----------------------------------
    1330 % function view_FieldMenu(handles,state)
    1331 % % set(handles.FieldName,'Visible',state)
    1332 % % set(handles.Field_text,'Visible',state)
    1333 % set(handles.InputFields,'Visible',state)
    1334 
    1335 % %-----------------------------------
    1336 % function view_FieldMenu_1(handles,state)
    1337 % set(handles.FieldName_1,'Visible',state)
    1338 % set(handles.Field_text_1,'Visible',state)
    1339 
    13401344
    13411345%%%%%%%%%%%%%%%%%%%%
     
    20462050end
    20472051
    2048 % %------------------------------------------------------------------------
    2049 % % --- Executes on button press in REFRESH.
    2050 %     function REFRESH_INDICES_Callback(hObject, eventdata, handles)
    2051 % %------------------------------------------------------------------------       
    2052 % % hObject    handle to REFRESH (see GCBO)
    2053 % % eventdata  reserved - to be defined in a future version of MATLAB
    2054 % % handles    structure with handles and user data (see GUIDATA)
    2055 % set(handles.REFRESH,'BackgroundColor',[0.7 0.7 0.7])
    2056 % InputTable=get(handles.InputTable,'Data');
    2057 % check_lines=get(handles.REFRESH,'UserData');
    2058 %
    2059 % %% check the indices and FileTypes for each series (limited to the new ones to save time)
    2060 % for ind_list=1:length(check_lines)
    2061 %     if  check_lines(ind_list)
    2062 %         InputLine=InputTable(ind_list,:);
    2063 %         detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
    2064 %         detect_idem=detect_idem(detect_idem>0);
    2065 %         if ~isempty (detect_idem)
    2066 %             InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
    2067 %             set(handles.InputTable,'Data',InputTable)
    2068 %         end
    2069 %         fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
    2070 %         %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
    2071 %         %update file series defined by the selected line
    2072 %         [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
    2073 %         if ~isempty(errormsg)
    2074 %                 msgbox_uvmat('ERROR',errormsg)
    2075 %                 return
    2076 %         end
    2077 %     end
    2078 % end
    2079 % set(handles.InputTable,'Data',InputTable)
    2080 % SeriesData=get(handles.series,'UserData');
    2081 %
    2082 % state_j='off';
    2083 % state_Pairs='off';
    2084 % state_InputFields='off';
    2085 % val=get(handles.ListView,'Value');
    2086 % ListViewString={''};
    2087 % if ~isempty(SeriesData)
    2088 % %     ListViewString={};
    2089 %     for iview=1:size(InputTable,1)
    2090 %         if ~isempty(SeriesData.j1_series{iview})
    2091 %             state_j='on';
    2092 %         end
    2093 %         if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
    2094 %             state_Pairs='on';
    2095 %             ListViewString{iview}=num2str(iview);
    2096 %             if check_lines(iview)
    2097 %                 val=iview;%select the last pair if it is a new entry
    2098 %             end
    2099 %         end
    2100 %         if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
    2101 %             state_InputFields='on';
    2102 %         end
    2103 %     end
    2104 % end
    2105 % set(handles.ListView,'Value',val)
    2106 % set(handles.ListView,'String',ListViewString)
    2107 % if strcmp(state_Pairs,'on')
    2108 %     ListView_Callback(hObject,eventdata,handles)
    2109 % end
    2110 % set(handles.PairString,'Visible',state_Pairs)
    2111 % enable_j(handles,state_j)
    2112 % set(handles.REFRESH,'BackgroundColor',[1 0 0])
    2113 % set(handles.REFRESH,'visible','off')
    2114 
    2115 % -----------------------------------------------------------------------
    2116 % --- Update min and max indices of a file series by scanning with find_file_series
    2117 % --- which also changes the root file and NomType in case of movie. Also adjust the string representation of indices (e.g;
    2118 % --- 1 or 001 by the function find_file_series
    2119 % --- This function also dispaly the set of availbale files in the series
    2120 % --- and the menus appropriate to the file type as well as timing possibly set
    2121 % --- by an xml image documentation file
    2122 function [RootFile,NomType,errormsg]=update_indices(handles,fileinput,iview)
    2123 % -----------------------------------------------------------------------
    2124 %% look for min and max indices existing in the file series and update SeriesData
    2125 errormsg='';
    2126 [FilePath,FileName,FileExt]=fileparts(fileinput);
    2127 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
    2128 % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
    2129 [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
    2130 if isempty(RootFile)&&isempty(i1_series)
    2131     errormsg='no input file in the series';
    2132     return
    2133 end
    2134 
    2135 %% adjust the min and max indices common to all the file series
    2136 MinIndex=get(handles.MinIndex,'Data');
    2137 MaxIndex=get(handles.MaxIndex,'Data');
    2138 MinIndex_i=min(i1_series(i1_series>0));
    2139 if ~isempty(i2_series)
    2140     MaxIndex_i=max(i2_series(i2_series>0));
    2141 else
    2142     MaxIndex_i=max(i1_series(i1_series>0));
    2143 end
    2144 MinIndex_j=min(j1_series(j1_series>0));
    2145 if ~isempty(j2_series)
    2146     MaxIndex_j=max(j2_series(j2_series>0));
    2147 else
    2148     MaxIndex_j=max(j1_series(j1_series>0));
    2149 end
    2150 MinIndex{iview,1}=MinIndex_i;
    2151 MinIndex{iview,2}=MinIndex_j;
    2152 MaxIndex{iview,1}=MaxIndex_i;
    2153 MaxIndex{iview,2}=MaxIndex_j;
    2154 set(handles.MinIndex,'Data',MinIndex)
    2155 set(handles.MaxIndex,'Data',MaxIndex)
    2156 SeriesData=get(handles.series,'UserData');
    2157 SeriesData.i1_series{iview}=i1_series;
    2158 SeriesData.i2_series{iview}=i2_series;
    2159 SeriesData.j1_series{iview}=j1_series;
    2160 SeriesData.j2_series{iview}=j2_series;
    2161 SeriesData.FileType{iview}=FileType;
    2162 
    2163 %% display the set of existing files as an image
    2164 set(handles.Waitbar,'Units','pixels')
    2165 pos=get(handles.Waitbar,'Position');
    2166 xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
    2167 yima=0.5:pos(4)-0.5;
    2168 [XIma,YIma]=meshgrid(xima,yima);
    2169 nb_i=size(i1_series,3);
    2170 nb_j=size(i1_series,2);
    2171 ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
    2172 ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
    2173 [Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
    2174 CData=zeros([size(XIma) 3]);
    2175 file_ima=double((i1_series(:,:,1)>0)');
    2176 if numel(file_ima)>=2
    2177 if size(file_ima,1)==1
    2178     CLine=interp1(ind_i,file_ima,xima,'nearest');
    2179     CData(:,:,2)=ones(size(yima'))*CLine;
    2180 else
    2181     CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
    2182 end
    2183 set(handles.Waitbar,'CData',CData)
    2184 end
    2185 set(handles.Waitbar,'Units','normalized')
    2186 
    2187 %% enable field and veltype menus
    2188 % testfield=isequal(get(handles.FieldName,'enable'),'on');
    2189 % testfield_1=isequal(get(handles.FieldName_1,'enable'),'on');
    2190 % testveltype=isequal(get(handles.VelType,'enable'),'on');
    2191 % testveltype_1=isequal(get(handles.VelType_1,'enable'),'on');
    2192 % testtransform=isequal(get(handles.TransformName,'Enable'),'on');
    2193 % testnc=0;
    2194 % testnc_1=0;
    2195 % testcivx=0;
    2196 % testcivx_1=0;
    2197 % testima=0; %test for image input
    2198 % if isequal(lower(FileExt),'.avi') %.avi file
    2199 %     testima=1;
    2200 % elseif ~isempty(imformats(FileExt(2:end)))
    2201 %     testima=1;
    2202 % elseif isequal(FileExt,'.vol')
    2203 %      testima=1;
    2204 % end
    2205 %TODO: update
    2206 % if length(FileExtCell)==1 || length(FileExtCell)>2
    2207 %     for iview=1:length(FileExtCell)
    2208 %         if isequal(FileExtCell{iview},'.nc')
    2209 %             testnc=1;
    2210 %         end
    2211 %         if isequal(FileTypeCell{iview},'civx')
    2212 %             testcivx=1;
    2213 %         end
    2214 %     end
    2215 % elseif length(FileExtCell)==2
    2216 %     testnc=isequal(FileExtCell{1},'.nc');
    2217 %     testnc_1=isequal(FileExtCell{2},'.nc');
    2218 %     testcivx=isequal(FileTypeCell{1},'civx');
    2219 %     testcivx_1=isequal(FileTypeCell{2},'civx');
    2220 % end
    2221 switch FileType
    2222     case {'civx','civdata'}
    2223     %view_FieldMenu(handles,'on')
    2224     menustr=get(handles.FieldName,'String');
    2225     if isequal(menustr,{'get_field...'})
    2226         set(handles.FieldName,'String',{'get_field...';'velocity';'vort';'div';'more...'})
    2227     end
    2228     set(handles.VelType,'Visible','on')
    2229     set(handles.FieldTransform,'Visible','on')
    2230     %      view_TRANSFORM(handles,'on')
    2231     %     TODO: second menu
    2232     %           view_FieldMenu_1(handles,'on')
    2233     %     if testcivx_1
    2234     %         menustr=get(handles.FieldName_1,'String');
    2235     %         if isequal(menustr,{'get_field...'})
    2236     %             set(handles.FieldName_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
    2237     %         end
    2238     %     else
    2239     %         set(handles.FieldName_1,'Value',1)
    2240     %         set(handles.FieldName_1,'String',{'get_field...'})
    2241     %     set(handles.VelType_1,'Visible','on')
    2242     %     set(handles.VelType_text_1,'Visible','on');
    2243     %     end
    2244     %     view_FieldMenu_1(handles,'off')
    2245     case 'netcdf'
    2246   %  view_FieldMenu(handles,'on')
    2247     set(handles.FieldName,'Value',1)
    2248     set(handles.FieldName,'String',{'get_field...'})
    2249     set(handles.FieldTransform,'Visible','off')
    2250     %     view_TRANSFORM(handles,'off')
    2251     case {'image','multimage','video'}
    2252 %    view_FieldMenu(handles,'off')
    2253  %   view_FieldMenu_1(handles,'off')
    2254     set(handles.VelType,'Visible','off')
    2255     set(handles.VelType_text,'Visible','off');
    2256 end
    2257 
    2258 
    2259 %TODO:update
    2260 % if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
    2261 %     msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
    2262 %     return
    2263 % end 
    2264 
    2265 %%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2266 ext_imadoc='';
    2267 FileBase=fullfile(RootPath,RootFile);
    2268 if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
    2269     ext_imadoc=FileExt;
    2270 elseif exist([FileBase '.xml'],'file')
    2271     ext_imadoc='.xml';
    2272 elseif exist([FileBase '.civ'],'file')
    2273     ext_imadoc='.civ';
    2274 end
    2275 %read the ImaDoc file
    2276 XmlData=[];
    2277 NbSlice_calib={};
    2278 if isequal(ext_imadoc,'.xml')
    2279         [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
    2280         if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
    2281             [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
    2282         end
    2283         if isfield(XmlData,'Time')
    2284             time{iview}=XmlData.Time;
    2285         end
    2286         if isfield(XmlData,'Camera')
    2287             if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
    2288                 NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
    2289                 if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
    2290                     msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
    2291                 end
    2292             end
    2293             if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
    2294                 TimeUnit=XmlData.Camera.TimeUnit;
    2295             end
    2296         end
    2297         if ~isempty(warntext)
    2298             msgbox_uvmat('WARNING',warntext)
    2299         end 
    2300 elseif isequal(ext_imadoc,'.civ')
    2301     [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
    2302     time{iview}=XmlData.Time;
    2303     if error==2, warntext=['no file ' FileBase '.civ'];
    2304     elseif error==1, warntext='inconsistent number of fields in the .civ file';
    2305     end 
    2306 end
    2307 
    2308 %% update time table
    2309 TimeTable=get(handles.TimeTable,'Data');
    2310 TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
    2311 TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
    2312 set(handles.TimeTable,'Data',TimeTable)
    2313 
    2314 %% number of slices
    2315 if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
    2316        siz=size(XmlData.GeometryCalib.SliceCoord);
    2317        if siz(1)>1
    2318            NbSlice=siz(1);
    2319        else
    2320            NbSlice=1;
    2321        end
    2322        set(handles.num_NbSlice,'String',num2str(NbSlice))
    2323 end
    2324 % set(handles.mode,'Visible','off') % do not show index pairstring by default
    2325 set(handles.PairString,'Visible','off')
    2326 % set(handles.num_ref_i,'Visible','off')
    2327 % set(handles.ref_i_text,'Visible','off')
    2328 testpair=0;
    2329 %set the menus of image pairstring and default selection for series
    2330 %list pairstring if relevant
    2331 % Val=get(handles.NomType,'Value');
    2332 % synchronise_view(handles,Val)
    2333 
    2334 % if ~isfield(SeriesData,'j1_series')||isempty(SeriesData.j1_series{index})
    2335 %     state_j='off'; %no need for j index
    2336 % else
    2337 %     state_j='on'; %case of j index
    2338 % end
    2339 % show index pairstring if files exist
    2340 set(handles.series,'UserData',SeriesData)
    23412052
    23422053
     
    23552066% --- Executes on selection change in RunMode.
    23562067function RunMode_Callback(hObject, eventdata, handles)
     2068
     2069
     2070% --- Executes on selection change in popupmenu14.
     2071function popupmenu14_Callback(hObject, eventdata, handles)
     2072% hObject    handle to popupmenu14 (see GCBO)
     2073% eventdata  reserved - to be defined in a future version of MATLAB
     2074% handles    structure with handles and user data (see GUIDATA)
     2075
     2076% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu14 contents as cell array
     2077%        contents{get(hObject,'Value')} returns selected item from popupmenu14
     2078
     2079
     2080% --- Executes during object creation, after setting all properties.
     2081function popupmenu14_CreateFcn(hObject, eventdata, handles)
     2082% hObject    handle to popupmenu14 (see GCBO)
     2083% eventdata  reserved - to be defined in a future version of MATLAB
     2084% handles    empty - handles not created until after all CreateFcns called
     2085
     2086% Hint: popupmenu controls usually have a white background on Windows.
     2087%       See ISPC and COMPUTER.
     2088if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
     2089    set(hObject,'BackgroundColor','white');
     2090end
Note: See TracChangeset for help on using the changeset viewer.