[245] | 1 | %'relabel_i_j': relabel an image series with two indices, and correct errors from the RDvision transfer program
|
---|
[457] | 2 | %------------------------------------------------------------------------
|
---|
| 3 | % function GUI_config=relabel_i_j(Param)
|
---|
| 4 | %------------------------------------------------------------------------
|
---|
[40] | 5 |
|
---|
[457] | 6 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 7 | %
|
---|
| 8 | % This function is used in four modes by the GUI series:
|
---|
| 9 | % 1) config GUI: with no input argument, the function determine the suitable GUI configuration
|
---|
| 10 | % 2) interactive input: the function is used to interactively introduce input parameters, and then stops
|
---|
| 11 | % 3) RUN: the function itself runs, when an appropriate input structure Param has been introduced.
|
---|
| 12 | % 4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
|
---|
| 13 | %
|
---|
| 14 | % This function is used in four modes by the GUI series:
|
---|
| 15 | % 1) config GUI: with no input argument, the function determine the suitable GUI configuration
|
---|
| 16 | % 2) interactive input: the function is used to interactively introduce input parameters, and then stops
|
---|
| 17 | % 3) RUN: the function itself runs, when an appropriate input structure Param has been introduced.
|
---|
| 18 | % 4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
|
---|
| 19 | %
|
---|
| 20 | %OUTPUT
|
---|
| 21 | % GUI_input=list of options in the GUI series.fig needed for the function
|
---|
| 22 | %
|
---|
| 23 | %INPUT:
|
---|
| 24 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
|
---|
| 25 | % In batch mode, Param is the name of the corresponding xml file containing the same information
|
---|
| 26 | % In the absence of input (as activated when the current Action is selected
|
---|
| 27 | % in series), the function ouput GUI_input set the activation of the needed GUI elements
|
---|
| 28 | %
|
---|
| 29 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
|
---|
| 30 | % .InputTable: cell of input file names, (several lines for multiple input)
|
---|
| 31 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
|
---|
| 32 | % .OutputSubDir: name of the subdirectory for data outputs
|
---|
| 33 | % .OutputDir: directory for data outputs, including path
|
---|
| 34 | % .Action: .ActionName: name of the current activated function
|
---|
| 35 | % .ActionPath: path of the current activated function
|
---|
| 36 | % .IndexRange: set the file or frame indices on which the action must be performed
|
---|
| 37 | % .FieldTransform: .TransformName: name of the selected transform function
|
---|
| 38 | % .TransformPath: path of the selected transform function
|
---|
| 39 | % .TransformHandle: corresponding function handle
|
---|
| 40 | % .InputFields: sub structure describing the input fields withfields
|
---|
| 41 | % .FieldName: name of the field
|
---|
| 42 | % .VelType: velocity type
|
---|
| 43 | % .FieldName_1: name of the second field in case of two input series
|
---|
| 44 | % .VelType_1: velocity type of the second field in case of two input series
|
---|
| 45 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
|
---|
| 46 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
[214] | 47 |
|
---|
[457] | 48 | function GUI_config=relabel_i_j(Param)
|
---|
[40] | 49 |
|
---|
[457] | 50 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName
|
---|
| 51 | if ~exist('Param','var') % case with no input parameter
|
---|
| 52 | GUI_config={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
|
---|
| 53 | 'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
|
---|
| 54 | 'WholeIndexRange';'on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
|
---|
| 55 | 'NbSlice';'off'; ...%nbre of slices ('off' by default)
|
---|
| 56 | 'VelType';'off';...% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default)
|
---|
| 57 | 'FieldName';'off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
|
---|
| 58 | 'FieldTransform'; 'off';...%can use a transform function
|
---|
| 59 | 'ProjObject';'off';...%can use projection object(option 'off'/'on',
|
---|
| 60 | 'Mask';'off';...%can use mask option (option 'off'/'on', 'off' by default)
|
---|
| 61 | 'OutputDirExt';'';...%set the output dir extension
|
---|
| 62 | ''};
|
---|
[245] | 63 | return
|
---|
[216] | 64 | end
|
---|
[40] | 65 |
|
---|
[457] | 66 | %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
|
---|
| 67 | %% select different modes, RUN, parameter input, BATCH
|
---|
| 68 | % BATCH case: read the xml file for batch case
|
---|
| 69 | if ischar(Param)
|
---|
| 70 | Param=xml2struct(Param);
|
---|
| 71 | checkrun=0;
|
---|
| 72 | % RUN case: parameters introduced as the input structure Param
|
---|
[245] | 73 | else
|
---|
[457] | 74 | hseries=guidata(Param.hseries);%handles of the GUI series
|
---|
| 75 | WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
|
---|
[462] | 76 | if isfield(Param,'Specific')&& strcmp(Param.Specific,'?')
|
---|
| 77 | checkrun=1;% will only search interactive input parameters (preparation of BATCH mode)
|
---|
| 78 | else
|
---|
| 79 | checkrun=2; % indicate the RUN option is used
|
---|
| 80 | end
|
---|
[245] | 81 | end
|
---|
[462] | 82 | ParamOut=Param; %default output
|
---|
[457] | 83 |
|
---|
| 84 | %% root input file(s) and type
|
---|
| 85 | RootPath=Param.InputTable(:,1);
|
---|
| 86 | RootFile=Param.InputTable(:,3);
|
---|
| 87 | SubDir=Param.InputTable(:,2);
|
---|
| 88 | NomType=Param.InputTable(:,4);
|
---|
| 89 | FileExt=Param.InputTable(:,5);
|
---|
| 90 |
|
---|
| 91 | % get the set of input file names (cell array filecell), and the lists of
|
---|
| 92 | % input file or frame indices i1_series,i2_series,j1_series,j2_series
|
---|
| 93 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
|
---|
| 94 | % filecell{iview,fileindex}: cell array representing the list of file names
|
---|
| 95 | % iview: line in the table corresponding to a given file series
|
---|
| 96 | % fileindex: file index within the file series,
|
---|
| 97 | % i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
|
---|
| 98 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
|
---|
| 99 | % set of frame indices used for movie or multimage input
|
---|
| 100 | % numbers of slices and file indices
|
---|
| 101 |
|
---|
| 102 | NbSlice=1;%default
|
---|
| 103 | if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
|
---|
| 104 | NbSlice=Param.IndexRange.NbSlice;
|
---|
[245] | 105 | end
|
---|
[457] | 106 | nbview=numel(i1_series);%number of input file series (lines in InputTable)
|
---|
| 107 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
|
---|
| 108 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index
|
---|
| 109 | nbfield=nbfield_j*nbfield_i; %total number of fields
|
---|
| 110 | nbfield_i=floor(nbfield/NbSlice);%total number of indexes in a slice (adjusted to an integer number of slices)
|
---|
| 111 | nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
|
---|
[214] | 112 |
|
---|
[457] | 113 | %determine the file type on each line from the first input file
|
---|
| 114 | ImageTypeOptions={'image','multimage','mmreader','video'};
|
---|
| 115 | NcTypeOptions={'netcdf','civx','civdata'};
|
---|
| 116 | for iview=1:nbview
|
---|
| 117 | if ~exist(filecell{iview,1}','file')
|
---|
| 118 | msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
|
---|
[249] | 119 | return
|
---|
[214] | 120 | end
|
---|
[457] | 121 | [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
|
---|
| 122 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
|
---|
| 123 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
|
---|
| 124 | if ~isempty(j1_series{iview})
|
---|
| 125 | frame_index{iview}=j1_series{iview};
|
---|
[40] | 126 | else
|
---|
[457] | 127 | frame_index{iview}=i1_series{iview};
|
---|
[214] | 128 | end
|
---|
[457] | 129 | end
|
---|
| 130 |
|
---|
| 131 | %% calibration data and timing: read the ImaDoc files
|
---|
| 132 | mode=''; %default
|
---|
| 133 | timecell={};
|
---|
| 134 | itime=0;
|
---|
| 135 | NbSlice_calib={};
|
---|
| 136 | XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing)
|
---|
| 137 | for iview=1:nbview%Loop on views
|
---|
| 138 | SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.'
|
---|
| 139 | filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
|
---|
| 140 | if ~exist(filexml,'file')
|
---|
| 141 | filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder
|
---|
| 142 | if ~exist(filexml,'file')
|
---|
| 143 | filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file
|
---|
| 144 | if ~exist(filexml,'file')
|
---|
| 145 | filexml='';
|
---|
| 146 | end
|
---|
[249] | 147 | end
|
---|
[223] | 148 | end
|
---|
[457] | 149 | if ~isempty(filexml)
|
---|
| 150 | [XmlData{iview},error]=imadoc2struct_special(filexml);
|
---|
| 151 | end
|
---|
| 152 | if isfield(XmlData{iview},'Time')
|
---|
| 153 | itime=itime+1;
|
---|
| 154 | timecell{itime}=XmlData{iview}.Time;
|
---|
| 155 | end
|
---|
| 156 | if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
|
---|
| 157 | NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
|
---|
| 158 | if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
|
---|
| 159 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
|
---|
[249] | 160 | end
|
---|
[223] | 161 | end
|
---|
[457] | 162 | end
|
---|
| 163 |
|
---|
| 164 | %% check coincidence in time for several input file series
|
---|
| 165 | % not relevant
|
---|
| 166 |
|
---|
| 167 | %% coordinate transform or other user defined transform
|
---|
| 168 | %not relevant
|
---|
| 169 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%%
|
---|
| 170 | % EDIT FROM HERE
|
---|
| 171 |
|
---|
| 172 | %% check the validity of input file types
|
---|
| 173 | if CheckImage{1}
|
---|
| 174 | FileExtOut='.png'; % write result as .png images for image inputs
|
---|
| 175 | elseif CheckNc{1}
|
---|
| 176 | FileExtOut='.nc';% write result as .nc files for netcdf inputs
|
---|
| 177 | else
|
---|
| 178 | msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
|
---|
| 179 | return
|
---|
| 180 | end
|
---|
| 181 | if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
|
---|
| 182 | msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
|
---|
| 183 | return
|
---|
| 184 | end
|
---|
| 185 | NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
|
---|
| 186 | if NbSlice~=nbfield_j
|
---|
| 187 | answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
|
---|
| 188 | if ~strcmp(answer,'Yes')
|
---|
| 189 | return
|
---|
[245] | 190 | end
|
---|
[40] | 191 | end
|
---|
| 192 |
|
---|
[457] | 193 | %% Set field names and velocity types
|
---|
| 194 | % not relevant here
|
---|
[245] | 195 |
|
---|
[457] | 196 | %% Initiate output fields
|
---|
| 197 | % not relevant here
|
---|
| 198 |
|
---|
| 199 | %% interactive input of specific parameters (for RDvision system)
|
---|
| 200 | display('RDvision system')
|
---|
| 201 | first_label=0; %image numbers start from 0
|
---|
| 202 | if ~strcmp(NomType{1},'_000001')
|
---|
| 203 | msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation
|
---|
| 204 | return
|
---|
| 205 | else
|
---|
| 206 | answer=msgbox_uvmat('','this function will relabel the file series from RDvision from and correct the xml file');%error message for directory creation
|
---|
| 207 | if ~strcmp(answer,'Yes')
|
---|
| 208 | return
|
---|
| 209 | end
|
---|
| 210 | end
|
---|
| 211 |
|
---|
| 212 | %% read imadoc
|
---|
| 213 | % RootPath=get(hseries.RootPath,'String');
|
---|
| 214 | % RootFile=get(hseries.RootFile,'String');
|
---|
| 215 | % if ~iscell(RootFile)
|
---|
| 216 | % msgbox_uvmat('ERROR','please enter an input image series from RDVision system')%error message for xml file reading
|
---|
| 217 | % return
|
---|
| 218 | % end
|
---|
| 219 | % basename=fullfile(RootPath{1},RootFile{1});
|
---|
| 220 | % [XmlData,warntext]=imadoc2struct_special([basename '.xml']);% read the xml file appended to the present function (containing bug corrections)
|
---|
| 221 | % if ~isempty(warntext)
|
---|
| 222 | % msgbox_uvmat('ERROR',warntext)%error message for xml file reading
|
---|
| 223 | % end
|
---|
| 224 | % nbfield1=size(XmlData.Time,1);
|
---|
| 225 | % nbfield2=size(XmlData.Time,2);
|
---|
| 226 | % set(hseries.first_i,'String',num2str(first_label))% display the first image in the process
|
---|
| 227 | % set(hseries.last_i,'String',num2str(nbfield1*nbfield2-1+first_label))% display the last image in the process
|
---|
| 228 | % set(hseries.nb_field,'String',{num2str(nbfield1*nbfield2-1+first_label)})% display the total nbre of images
|
---|
| 229 | % SeriesData=get(hGUI,'UserData');
|
---|
| 230 |
|
---|
| 231 |
|
---|
| 232 | %% stop program there when it is selected in the menu (no run action)
|
---|
| 233 | % if ~exist('num_i1','var')
|
---|
| 234 | % return
|
---|
| 235 | % end
|
---|
| 236 | % if nbfield2>=2
|
---|
| 237 | % answer=msgbox_uvmat('',[num2str(nbfield1) ' bursts containing ' num2str(nbfield2) ' images each']);%error message for directory creation
|
---|
| 238 | % nomtype='_i_j';
|
---|
| 239 | % else
|
---|
| 240 | % answer=msgbox_uvmat('',['image series with ' num2str(nbfield1) ' images']);%error message for directory creation
|
---|
| 241 | % nomtype='_i';
|
---|
| 242 | % end
|
---|
| 243 | % if ~strcmp(answer,'Yes')
|
---|
| 244 | % return
|
---|
| 245 | % end
|
---|
| 246 |
|
---|
| 247 | %% copy and adapt the xml file
|
---|
| 248 | if ~isempty(XmlData{1})
|
---|
| 249 |
|
---|
| 250 | % if exist([basename '.xml'],'file')
|
---|
| 251 | % try
|
---|
| 252 | % copyfile([basename '.xml'],[basename '.xml~']);% backup the xml file
|
---|
| 253 | % catch ME
|
---|
| 254 | % msgbox_uvmat('ERROR',ME.message);
|
---|
| 255 | % return
|
---|
| 256 | % end
|
---|
| 257 | % filexml=[filebase{1} '.xml']
|
---|
| 258 | t=xmltree(filexml);
|
---|
| 259 |
|
---|
| 260 | %update information on the first image name in the series
|
---|
| 261 | uid_Heading=find(t,'ImaDoc/Heading');
|
---|
| 262 | if isempty(uid_Heading)
|
---|
| 263 | [t,uid_Heading]=add(t,1,'element','Heading');
|
---|
| 264 | end
|
---|
| 265 | uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
|
---|
| 266 | j1=[];
|
---|
| 267 | if ~isempty(j1_series{1})
|
---|
| 268 | j1=j1_series{1};
|
---|
| 269 | end
|
---|
| 270 | ImageName=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'_1_1',i1_series{1}(1),[],j);
|
---|
| 271 | % ImageName=name_generator(basename,1,1,'.png','_i_j');
|
---|
| 272 | [pth,ImageName]=fileparts(ImageName);
|
---|
| 273 | ImageName=[ImageName '.png'];
|
---|
| 274 | if isempty(uid_ImageName)
|
---|
| 275 | [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
|
---|
| 276 | end
|
---|
| 277 | uid_value=children(t,uid_ImageName);
|
---|
| 278 | if isempty(uid_value)
|
---|
| 279 | t=add(t,uid_ImageName,'chardata',ImageName);%indicate name of the first image, with ;png extension
|
---|
| 280 | else
|
---|
| 281 | t=set(t,uid_value(1),'value',ImageName);%indicate name of the first image, with ;png extension
|
---|
| 282 | end
|
---|
| 283 |
|
---|
| 284 | %%%% correction RDvision %%%%
|
---|
| 285 | if isfield(XmlData,'NbDtj')
|
---|
| 286 | uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
|
---|
| 287 | uid_value=children(t,uid_NbDtj);
|
---|
| 288 | if ~isempty(uid_value)
|
---|
| 289 | t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
|
---|
| 290 | end
|
---|
| 291 | end
|
---|
| 292 | if isfield(XmlData,'NbDtk')
|
---|
| 293 | uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
|
---|
| 294 | uid_value=children(t,uid_NbDtk);
|
---|
| 295 | if ~isempty(uid_value)
|
---|
| 296 | t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
|
---|
| 297 | end
|
---|
| 298 | end
|
---|
| 299 | if isempty(j1_series{1}) && isfield(XmlData,'NbDti')
|
---|
| 300 | uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
|
---|
| 301 | t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
|
---|
| 302 | uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
|
---|
| 303 | t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
|
---|
| 304 | uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
|
---|
| 305 | uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
|
---|
| 306 | t=delete(t,uid_NbDtj);
|
---|
| 307 | t=delete(t,uid_NbDtk);
|
---|
| 308 | uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
|
---|
| 309 | uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
|
---|
| 310 | t=delete(t,uid_Dtj);
|
---|
| 311 | t=delete(t,uid_Dtk);
|
---|
| 312 | end
|
---|
| 313 | SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
|
---|
| 314 | filexml_new=[fullfile(RootPath{1},SubDirBase) '.xml'];
|
---|
| 315 | save(t,filexml_new)
|
---|
| 316 | % end
|
---|
| 317 | end
|
---|
| 318 |
|
---|
| 319 | %% main loop on images
|
---|
| 320 | %j1=[];%default
|
---|
| 321 | nbfield2=size(XmlData{1}.Time,2);
|
---|
| 322 | for ifile=1:nbfield
|
---|
| 323 | if checkrun
|
---|
| 324 | update_waitbar(hseries.waitbar_frame,WaitbarPos,ifile/nbfield)
|
---|
| 325 | stopstate=get(hseries.RUN,'BusyAction');
|
---|
| 326 | else
|
---|
| 327 | stopstate='queue';
|
---|
| 328 | end
|
---|
| 329 | if isequal(stopstate,'queue') % enable STOP command
|
---|
| 330 | filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile));
|
---|
| 331 | j1=mod(ifile-1+first_label,nbfield2)+1;
|
---|
| 332 | i1=floor((ifile-1+first_label)/nbfield2)+1;
|
---|
| 333 | % filename_new=name_generator(basename,num_i,num_j,'.png',nomtype);
|
---|
| 334 | filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'_1_1',i1,[],j1);
|
---|
| 335 | try
|
---|
| 336 | movefile(filename,filename_new);
|
---|
| 337 | [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a')
|
---|
| 338 | if ~s
|
---|
| 339 | msgbox_uvmat('ERROR',errormsg);
|
---|
| 340 | return
|
---|
| 341 | end
|
---|
| 342 | catch ME
|
---|
| 343 | msgbox_uvmat('ERROR',ME.message);
|
---|
[214] | 344 | return
|
---|
| 345 | end
|
---|
| 346 | end
|
---|
[40] | 347 | end
|
---|
| 348 |
|
---|
[457] | 349 | %'imadoc2struct_special': reads the xml file for image documentation
|
---|
[214] | 350 | %------------------------------------------------------------------------
|
---|
[457] | 351 | % function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
|
---|
[214] | 352 | %
|
---|
| 353 | % OUTPUT:
|
---|
| 354 | % s: structure representing ImaDoc
|
---|
| 355 | % s.Heading: information about the data hierarchical structure
|
---|
| 356 | % s.Time: matrix of times
|
---|
| 357 | % s.TimeUnit
|
---|
| 358 | % s.GeometryCalib: substructure containing the parameters for geometric calibration
|
---|
| 359 | % errormsg: error message
|
---|
| 360 | %
|
---|
| 361 | % INPUT:
|
---|
| 362 | % ImaDoc: full name of the xml input file with head key ImaDoc
|
---|
| 363 | % option: ='GeometryCalib': read the data of GeometryCalib, including source point coordinates
|
---|
| 364 |
|
---|
[457] | 365 | function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
|
---|
[223] | 366 |
|
---|
[214] | 367 | %% default input and output
|
---|
| 368 | if ~exist('option','var')
|
---|
| 369 | option='*';
|
---|
| 370 | end
|
---|
| 371 | errormsg=[];%default
|
---|
| 372 | s.Heading=[];%default
|
---|
| 373 | s.Time=[]; %default
|
---|
| 374 | s.TimeUnit=[]; %default
|
---|
| 375 | s.GeometryCalib=[];
|
---|
| 376 | tsai=[];%default
|
---|
| 377 |
|
---|
| 378 | %% opening the xml file
|
---|
| 379 | if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist
|
---|
| 380 | try
|
---|
| 381 | t=xmltree(ImaDoc);
|
---|
| 382 | catch
|
---|
| 383 | errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
|
---|
| 384 | display(errormsg);
|
---|
| 385 | return
|
---|
| 386 | end
|
---|
| 387 | uid_root=find(t,'/ImaDoc');
|
---|
| 388 | if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file
|
---|
| 389 |
|
---|
| 390 |
|
---|
| 391 | %% Heading
|
---|
| 392 | uid_Heading=find(t,'/ImaDoc/Heading');
|
---|
| 393 | if ~isempty(uid_Heading),
|
---|
| 394 | uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
|
---|
| 395 | uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
|
---|
| 396 | uid_Device=find(t,'/ImaDoc/Heading/Device');
|
---|
| 397 | uid_Record=find(t,'/ImaDoc/Heading/Record');
|
---|
| 398 | uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
|
---|
| 399 | s.Heading.Campaign=get(t,children(t,uid_Campaign),'value');
|
---|
| 400 | s.Heading.Experiment=get(t,children(t,uid_Exp),'value');
|
---|
| 401 | s.Heading.Device=get(t,children(t,uid_Device),'value');
|
---|
| 402 | if ~isempty(uid_Record)
|
---|
| 403 | s.Heading.Record=get(t,children(t,uid_Record),'value');
|
---|
| 404 | end
|
---|
| 405 | s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
|
---|
| 406 | end
|
---|
| 407 |
|
---|
| 408 | %% Camera and timing
|
---|
| 409 | if strcmp(option,'*') || strcmp(option,'Camera')
|
---|
| 410 | uid_Camera=find(t,'/ImaDoc/Camera');
|
---|
| 411 | if ~isempty(uid_Camera)
|
---|
| 412 | uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
|
---|
| 413 | if ~isempty(uid_ImageSize);
|
---|
| 414 | ImageSize=get(t,children(t,uid_ImageSize),'value');
|
---|
| 415 | xindex=findstr(ImageSize,'x');
|
---|
| 416 | if length(xindex)>=2
|
---|
| 417 | s.Npx=str2double(ImageSize(1:xindex(1)-1));
|
---|
| 418 | s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1));
|
---|
| 419 | end
|
---|
| 420 | end
|
---|
| 421 | uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
|
---|
| 422 | if ~isempty(uid_TimeUnit)
|
---|
| 423 | s.TimeUnit=get(t,children(t,uid_TimeUnit),'value');
|
---|
| 424 | end
|
---|
| 425 | uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
|
---|
| 426 | if ~isempty(uid_BurstTiming)
|
---|
| 427 | for k=1:length(uid_BurstTiming)
|
---|
| 428 | subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
|
---|
| 429 | % reading Dtk
|
---|
| 430 | Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1);
|
---|
| 431 | Dtj=get_value(subt,'/BurstTiming/Dtj',[]);
|
---|
| 432 | Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
|
---|
| 433 | NbDtj=get_value(subt,'/BurstTiming/NbDtj',1);
|
---|
| 434 | %%%% correction RDvision %%%%
|
---|
[245] | 435 | % NbDtj=NbDtj/numel(Dtj);
|
---|
| 436 | % s.NbDtj=NbDtj;
|
---|
| 437 | % %%%%
|
---|
[249] | 438 | Dti=get_value(subt,'/BurstTiming/Dti',[]);
|
---|
| 439 | NbDti=get_value(subt,'/BurstTiming/NbDti',1);
|
---|
[245] | 440 | %%%% correction RDvision %%%%
|
---|
| 441 | if isempty(Dti)% series
|
---|
[249] | 442 | Dti=Dtj;
|
---|
| 443 | NbDti=NbDtj;
|
---|
[245] | 444 | Dtj=[];
|
---|
| 445 | s.Dti=Dti;
|
---|
| 446 | else
|
---|
[457] | 447 | % NbDtj=NbDtj/numel(Dtj);%bursts
|
---|
[245] | 448 | s.NbDtj=NbDtj;
|
---|
| 449 | end
|
---|
| 450 | %%%% %%%%
|
---|
[214] | 451 | Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
|
---|
[245] | 452 |
|
---|
[214] | 453 | Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit
|
---|
| 454 | if ~isempty(Dti)
|
---|
| 455 | Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
|
---|
| 456 | Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals Dti
|
---|
| 457 | end
|
---|
| 458 | if ~isempty(Dtj)
|
---|
| 459 | Dtj=reshape(Dtj'*ones(1,NbDtj),1,NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times
|
---|
| 460 | Dtj=[0 Dtj];
|
---|
| 461 | Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
|
---|
| 462 | end
|
---|
| 463 | % reading Dtk
|
---|
| 464 | Dtk=get_value(subt,'/BurstTiming/Dtk',[]);
|
---|
| 465 | NbDtk=get_value(subt,'/BurstTiming/NbDtk',1);
|
---|
| 466 | %%%% correction RDvision %%%%
|
---|
[223] | 467 | if ~isequal(NbDtk,1)
|
---|
| 468 | NbDtk=-1+(NbDtk+1)/(NbDti+1);
|
---|
| 469 | end
|
---|
[214] | 470 | s.NbDtk=NbDtk;
|
---|
| 471 | %%%%%
|
---|
| 472 | if isempty(Dtk)
|
---|
| 473 | s.Time=[s.Time;Time_val];
|
---|
| 474 | else
|
---|
| 475 | for kblock=1:NbDtk+1
|
---|
| 476 | Time_val_k=Time_val+(kblock-1)*Dtk;
|
---|
| 477 | s.Time=[s.Time;Time_val_k];
|
---|
| 478 | end
|
---|
| 479 | end
|
---|
| 480 | end
|
---|
| 481 | end
|
---|
| 482 | end
|
---|
| 483 | end
|
---|
| 484 |
|
---|
| 485 | %% motor
|
---|
| 486 | if strcmp(option,'*') || strcmp(option,'GeometryCalib')
|
---|
| 487 | uid_subtree=find(t,'/ImaDoc/TranslationMotor');
|
---|
| 488 | if length(uid_subtree)==1
|
---|
| 489 | subt=branch(t,uid_subtree);%subtree under GeometryCalib
|
---|
| 490 | [s.TranslationMotor,errormsg]=read_subtree(subt,{'Nbslice','ZStart','ZEnd'},[1 1 1],[1 1 1]);
|
---|
| 491 | end
|
---|
| 492 | end
|
---|
| 493 | %% geometric calibration
|
---|
| 494 | if strcmp(option,'*') || strcmp(option,'GeometryCalib')
|
---|
| 495 | uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
|
---|
| 496 | if ~isempty(uid_GeometryCalib)
|
---|
| 497 | if length(uid_GeometryCalib)>1
|
---|
| 498 | errormsg=['More than one GeometryCalib in ' filecivxml];
|
---|
| 499 | return
|
---|
| 500 | end
|
---|
| 501 | subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
|
---|
| 502 | cont=get(subt,1,'contents');
|
---|
| 503 | if ~isempty(cont)
|
---|
| 504 | uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType');
|
---|
| 505 | if isequal(length(uid_CalibrationType),1)
|
---|
| 506 | tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value');
|
---|
| 507 | end
|
---|
| 508 | uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
|
---|
| 509 | if isequal(length(uid_CoordUnit),1)
|
---|
| 510 | tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
|
---|
| 511 | end
|
---|
| 512 | uid_fx_fy=find(subt,'/GeometryCalib/fx_fy');
|
---|
| 513 | focal=[];%default fro old convention (Reg Wilson)
|
---|
| 514 | if isequal(length(uid_fx_fy),1)
|
---|
| 515 | tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value'));
|
---|
| 516 | else %old convention (Reg Wilson)
|
---|
| 517 | uid_focal=find(subt,'/GeometryCalib/focal');
|
---|
| 518 | uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
|
---|
| 519 | uid_sx=find(subt,'/GeometryCalib/sx');
|
---|
| 520 | if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx)
|
---|
| 521 | dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
|
---|
| 522 | sx=str2num(get(subt,children(subt,uid_sx),'value'));
|
---|
| 523 | focal=str2num(get(subt,children(subt,uid_focal),'value'));
|
---|
| 524 | tsai.fx_fy(1)=sx*focal/dpx_dpy(1);
|
---|
| 525 | tsai.fx_fy(2)=focal/dpx_dpy(2);
|
---|
| 526 | end
|
---|
| 527 | end
|
---|
| 528 | uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
|
---|
| 529 | if ~isempty(uid_Cx_Cy)
|
---|
| 530 | tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
|
---|
| 531 | end
|
---|
| 532 | uid_kc=find(subt,'/GeometryCalib/kc');
|
---|
| 533 | if ~isempty(uid_kc)
|
---|
| 534 | tsai.kc=str2double(get(subt,children(subt,uid_kc),'value'));
|
---|
| 535 | else %old convention (Reg Wilson)
|
---|
| 536 | uid_kappa1=find(subt,'/GeometryCalib/kappa1');
|
---|
| 537 | if ~isempty(uid_kappa1)&& ~isempty(focal)
|
---|
| 538 | kappa1=str2double(get(subt,children(subt,uid_kappa1),'value'));
|
---|
| 539 | tsai.kc=-kappa1*focal*focal;
|
---|
| 540 | end
|
---|
| 541 | end
|
---|
| 542 | uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
|
---|
| 543 | if ~isempty(uid_Tx_Ty_Tz)
|
---|
| 544 | tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value'));
|
---|
| 545 | end
|
---|
| 546 | uid_R=find(subt,'/GeometryCalib/R');
|
---|
| 547 | if ~isempty(uid_R)
|
---|
| 548 | RR=get(subt,children(subt,uid_R),'value');
|
---|
| 549 | if length(RR)==3
|
---|
| 550 | tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
|
---|
| 551 | end
|
---|
| 552 | end
|
---|
| 553 |
|
---|
| 554 | %look for laser plane definitions
|
---|
| 555 | uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
|
---|
| 556 | uid_Pos=find(subt,'/GeometryCalib/SliceCoord');
|
---|
| 557 | if isempty(uid_Pos)
|
---|
| 558 | uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention
|
---|
| 559 | end
|
---|
| 560 | if ~isempty(uid_Angle)
|
---|
| 561 | tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
|
---|
| 562 | end
|
---|
| 563 | if ~isempty(uid_Pos)
|
---|
| 564 | for j=1:length(uid_Pos)
|
---|
| 565 | tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
|
---|
| 566 | end
|
---|
| 567 | uid_DZ=find(subt,'/GeometryCalib/SliceDZ');
|
---|
| 568 | uid_NbSlice=find(subt,'/GeometryCalib/NbSlice');
|
---|
| 569 | if ~isempty(uid_DZ) && ~isempty(uid_NbSlice)
|
---|
| 570 | DZ=str2double(get(subt,children(subt,uid_DZ),'value'));
|
---|
| 571 | NbSlice=get(subt,children(subt,uid_NbSlice),'value');
|
---|
| 572 | if isequal(NbSlice,'volume')
|
---|
| 573 | tsai.NbSlice='volume';
|
---|
| 574 | NbSlice=NbDtj+1;
|
---|
| 575 | else
|
---|
| 576 | tsai.NbSlice=str2double(NbSlice);
|
---|
| 577 | end
|
---|
| 578 | tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1];
|
---|
| 579 | end
|
---|
| 580 | end
|
---|
| 581 | tsai.SliceAngle=get_value(subt,'/GeometryCalib/SliceAngle',[0 0 0]);
|
---|
| 582 | tsai.VolumeScan=get_value(subt,'/GeometryCalib/VolumeScan','n');
|
---|
| 583 | tsai.InterfaceCoord=get_value(subt,'/GeometryCalib/InterfaceCoord',[0 0 0]);
|
---|
| 584 | tsai.RefractionIndex=get_value(subt,'/GeometryCalib/RefractionIndex',1);
|
---|
| 585 |
|
---|
| 586 | if strcmp(option,'GeometryCalib')
|
---|
| 587 | tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);
|
---|
| 588 | end
|
---|
| 589 | s.GeometryCalib=tsai;
|
---|
| 590 | end
|
---|
| 591 | end
|
---|
| 592 | end
|
---|
| 593 |
|
---|
| 594 | %--------------------------------------------------
|
---|
| 595 | % read a subtree
|
---|
| 596 | % INPUT:
|
---|
| 597 | % t: xltree
|
---|
| 598 | % head_element: head elelemnt of the subtree
|
---|
| 599 | % Data, structure containing
|
---|
| 600 | % .Key: element name
|
---|
| 601 | % .Type: type of element ('charg', 'float'....)
|
---|
| 602 | % .NbOccur: nbre of occurrence, NaN for un specified number
|
---|
| 603 | function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest)
|
---|
| 604 | %--------------------------------------------------
|
---|
| 605 | s=[];%default
|
---|
| 606 | errormsg='';
|
---|
| 607 | head_element=get(subt,1,'name');
|
---|
| 608 | cont=get(subt,1,'contents');
|
---|
| 609 | if ~isempty(cont)
|
---|
| 610 | for ilist=1:length(Data)
|
---|
| 611 | uid_key=find(subt,[head_element '/' Data{ilist}]);
|
---|
| 612 | if ~isequal(length(uid_key),NbOccur(ilist))
|
---|
| 613 | errormsg=['wrong number of occurence for ' Data{ilist}];
|
---|
| 614 | return
|
---|
| 615 | end
|
---|
| 616 | for ival=1:length(uid_key)
|
---|
| 617 | val=get(subt,children(subt,uid_key(ival)),'value');
|
---|
| 618 | if ~NumTest(ilist)
|
---|
| 619 | eval(['s.' Data{ilist} '=val;']);
|
---|
| 620 | else
|
---|
| 621 | eval(['s.' Data{ilist} '=str2double(val);'])
|
---|
| 622 | end
|
---|
| 623 | end
|
---|
| 624 | end
|
---|
| 625 | end
|
---|
| 626 |
|
---|
| 627 |
|
---|
| 628 | %--------------------------------------------------
|
---|
| 629 | % read an xml element
|
---|
| 630 | function val=get_value(t,label,default)
|
---|
| 631 | %--------------------------------------------------
|
---|
| 632 | val=default;
|
---|
| 633 | uid=find(t,label);%find the element iud(s)
|
---|
| 634 | if ~isempty(uid) %if the element named label exists
|
---|
| 635 | uid_child=children(t,uid);%find the children
|
---|
| 636 | if ~isempty(uid_child)
|
---|
| 637 | data=get(t,uid_child,'type');%get the type of child
|
---|
| 638 | if iscell(data)% case of multiple element
|
---|
| 639 | for icell=1:numel(data)
|
---|
| 640 | val_read=str2num(get(t,uid_child(icell),'value'));
|
---|
| 641 | if ~isempty(val_read)
|
---|
| 642 | val(icell,:)=val_read;
|
---|
| 643 | end
|
---|
| 644 | end
|
---|
| 645 | % val=val';
|
---|
| 646 | else % case of unique element value
|
---|
| 647 | val_read=str2num(get(t,uid_child,'value'));
|
---|
| 648 | if ~isempty(val_read)
|
---|
| 649 | val=val_read;
|
---|
| 650 | else
|
---|
| 651 | val=get(t,uid_child,'value');%char string data
|
---|
| 652 | end
|
---|
| 653 | end
|
---|
| 654 | end
|
---|
| 655 | end
|
---|