[829] | 1 | %'relabel_i_j': relabel an image series with two indices, and correct errors from the RDvision transfer program |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % function ParamOut=relabel_i_j(Param) |
---|
| 4 | %------------------------------------------------------------------------ |
---|
| 5 | % |
---|
| 6 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 7 | % |
---|
| 8 | %OUTPUT |
---|
| 9 | % ParamOut: sets options in the GUI series.fig needed for the function |
---|
| 10 | % |
---|
| 11 | %INPUT: |
---|
| 12 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. |
---|
| 13 | % In batch mode, Param is the name of the corresponding xml file containing the same information |
---|
| 14 | % when Param.Action.RUN=0 (as activated when the current Action is selected |
---|
| 15 | % in series), the function ouput paramOut set the activation of the needed GUI elements |
---|
| 16 | % |
---|
| 17 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to |
---|
| 18 | % see the current structure Param) |
---|
| 19 | % .InputTable: cell of input file names, (several lines for multiple input) |
---|
| 20 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} |
---|
| 21 | % .OutputSubDir: name of the subdirectory for data outputs |
---|
| 22 | % .OutputDirExt: directory extension for data outputs |
---|
| 23 | % .Action: .ActionName: name of the current activated function |
---|
| 24 | % .ActionPath: path of the current activated function |
---|
| 25 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct |
---|
| 26 | % .RUN =0 for GUI input, =1 for function activation |
---|
| 27 | % .RunMode='local','background', 'cluster': type of function use |
---|
| 28 | % |
---|
| 29 | % .IndexRange: set the file or frame indices on which the action must be performed |
---|
| 30 | % .FieldTransform: .TransformName: name of the selected transform function |
---|
| 31 | % .TransformPath: path of the selected transform function |
---|
| 32 | % .InputFields: sub structure describing the input fields withfields |
---|
| 33 | % .FieldName: name(s) of the field |
---|
| 34 | % .VelType: velocity type |
---|
| 35 | % .FieldName_1: name of the second field in case of two input series |
---|
| 36 | % .VelType_1: velocity type of the second field in case of two input series |
---|
| 37 | % .Coord_y: name of y coordinate variable |
---|
| 38 | % .Coord_x: name of x coordinate variable |
---|
| 39 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) |
---|
| 40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 41 | |
---|
| 42 | %======================================================================= |
---|
[1027] | 43 | % Copyright 2008-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[829] | 44 | % http://www.legi.grenoble-inp.fr |
---|
| 45 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 46 | % |
---|
| 47 | % This file is part of the toolbox UVMAT. |
---|
| 48 | % |
---|
| 49 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 50 | % it under the terms of the GNU General Public License as published |
---|
| 51 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 52 | % or (at your option) any later version. |
---|
| 53 | % |
---|
| 54 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 55 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 56 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 57 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 58 | %======================================================================= |
---|
| 59 | |
---|
| 60 | function ParamOut=relabel_i_j(Param) %default output=relabel_i_j(Param) |
---|
| 61 | |
---|
| 62 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName |
---|
| 63 | if isstruct(Param) && isequal(Param.Action.RUN,0) |
---|
| 64 | ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
---|
| 65 | ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
---|
| 66 | ParamOut.NbSlice='one'; ...%nbre of slices, 'one' prevents splitting in several processes, ('off' by default) |
---|
| 67 | ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
| 68 | ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
| 69 | ParamOut.FieldTransform = 'off';...%can use a transform function |
---|
| 70 | ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on', |
---|
| 71 | ParamOut.Mask='off';...%can use mask option (option 'off'/'on', 'off' by default) |
---|
| 72 | ParamOut.OutputDirExt='';%set the output dir extension |
---|
| 73 | if size(Param.InputTable,1)>1 |
---|
| 74 | msgbox_uvmat('WARNING', 'this function acts only on the first input file line') |
---|
| 75 | end |
---|
| 76 | return |
---|
| 77 | end |
---|
| 78 | |
---|
| 79 | ParamOut=[]; |
---|
| 80 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%% |
---|
| 81 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
| 82 | checkrun=1; |
---|
| 83 | if ischar(Param) |
---|
| 84 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
| 85 | checkrun=0; |
---|
| 86 | end |
---|
| 87 | hseries=findobj(allchild(0),'Tag','series'); |
---|
| 88 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
| 89 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
| 90 | |
---|
| 91 | %% root input file(s) and type |
---|
| 92 | RootPath=Param.InputTable(:,1); |
---|
| 93 | RootFile=Param.InputTable(:,3); |
---|
| 94 | SubDir=Param.InputTable(:,2); |
---|
| 95 | NomType=Param.InputTable(:,4); |
---|
| 96 | FileExt=Param.InputTable(:,5); |
---|
| 97 | |
---|
| 98 | % get the set of input file names (cell array filecell), and the lists of |
---|
| 99 | % input file or frame indices i1_series,i2_series,j1_series,j2_series |
---|
| 100 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
| 101 | |
---|
| 102 | % numbers of slices and file indices |
---|
| 103 | |
---|
| 104 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
| 105 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index |
---|
| 106 | nbfield=nbfield_j*nbfield_i; %total number of fields |
---|
| 107 | |
---|
| 108 | %determine the file type on each line from the first input file |
---|
| 109 | ImageTypeOptions={'image','multimage','mmreader','video'}; |
---|
| 110 | |
---|
| 111 | if ~exist(filecell{1,1}','file') |
---|
| 112 | msgbox_uvmat('ERROR',['the first input file ' filecell{1,1} ' does not exist']) |
---|
| 113 | return |
---|
| 114 | end |
---|
| 115 | [FileInfo{1},MovieObject{1}]=get_file_info(filecell{1,1}); |
---|
| 116 | FileType{1}=FileInfo{1}.FileType; |
---|
| 117 | CheckImage=~isempty(find(strcmp(FileType{1},ImageTypeOptions)));% =1 for images |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | %% calibration data and timing: read the ImaDoc files |
---|
| 121 | mode=''; %default |
---|
| 122 | timecell={}; |
---|
| 123 | itime=0; |
---|
| 124 | NbSlice_calib={}; |
---|
| 125 | |
---|
| 126 | SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.' |
---|
| 127 | filexml=[fullfile(RootPath{1},SubDirBase) '.xml'];%new convention: xml at the level of the image folder |
---|
| 128 | if ~exist(filexml,'file') |
---|
| 129 | filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.xml']; % old convention: xml inside the image folder |
---|
| 130 | if ~exist(filexml,'file') |
---|
| 131 | filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.civ']; % very old convention: .civ file |
---|
| 132 | if ~exist(filexml,'file') |
---|
| 133 | filexml=''; |
---|
| 134 | end |
---|
| 135 | end |
---|
| 136 | end |
---|
| 137 | XmlData=[]; |
---|
| 138 | if ~isempty(filexml) |
---|
| 139 | [XmlData,error]=imadoc2struct_special(filexml); |
---|
| 140 | end |
---|
| 141 | if isfield(XmlData,'Time') |
---|
| 142 | itime=itime+1; |
---|
| 143 | timecell{itime}=XmlData.Time; |
---|
| 144 | end |
---|
| 145 | if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord') |
---|
| 146 | NbSlice_calib{1}=size(XmlData.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform |
---|
| 147 | if ~isequal(NbSlice_calib{1},NbSlice_calib{1}) |
---|
| 148 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); |
---|
| 149 | end |
---|
| 150 | end |
---|
| 151 | |
---|
| 152 | %% check coincidence in time for several input file series |
---|
| 153 | % not relevant |
---|
| 154 | |
---|
| 155 | %% coordinate transform or other user defined transform |
---|
| 156 | %not relevant |
---|
| 157 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
| 158 | % EDIT FROM HERE |
---|
| 159 | |
---|
| 160 | |
---|
| 161 | %% Set field names and velocity types |
---|
| 162 | % not relevant here |
---|
| 163 | |
---|
| 164 | %% Initiate output fields |
---|
| 165 | % not relevant here |
---|
| 166 | |
---|
| 167 | %% interactive input of specific parameters (for RDvision system) |
---|
| 168 | display('RDvision system') |
---|
| 169 | first_label=0; %image numbers start from 0 |
---|
| 170 | if ~CheckImage || ~strcmp(NomType{1},'_000001') |
---|
| 171 | msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation |
---|
| 172 | return |
---|
| 173 | else |
---|
| 174 | answer=msgbox_uvmat('','this function will relabel the file series from RDvision from and correct the xml file');%error message for directory creation |
---|
| 175 | if ~strcmp(answer,'Yes') |
---|
| 176 | return |
---|
| 177 | end |
---|
| 178 | end |
---|
| 179 | |
---|
| 180 | %% copy and adapt the xml file |
---|
| 181 | NomTypeNew='_1_1'; |
---|
| 182 | if ~isempty(XmlData) |
---|
| 183 | t=xmltree(filexml); |
---|
| 184 | |
---|
| 185 | %update information on the first image name in the series |
---|
| 186 | uid_Heading=find(t,'ImaDoc/Heading'); |
---|
| 187 | if isempty(uid_Heading) |
---|
| 188 | [t,uid_Heading]=add(t,1,'element','Heading'); |
---|
| 189 | end |
---|
| 190 | uid_ImageName=find(t,'ImaDoc/Heading/ImageName'); |
---|
| 191 | j1=[]; |
---|
| 192 | if ~isempty(j1_series{1}) |
---|
| 193 | j1=j1_series{1}; |
---|
| 194 | end |
---|
| 195 | ImageName=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'_1_1',i1_series{1}(1),[],j1); |
---|
| 196 | [pth,ImageName]=fileparts(ImageName); |
---|
| 197 | ImageName=[ImageName '.png']; |
---|
| 198 | if isempty(uid_ImageName) |
---|
| 199 | [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName'); |
---|
| 200 | end |
---|
| 201 | uid_value=children(t,uid_ImageName); |
---|
| 202 | if isempty(uid_value) |
---|
| 203 | t=add(t,uid_ImageName,'chardata',ImageName);%indicate name of the first image, with ;png extension |
---|
| 204 | else |
---|
| 205 | t=set(t,uid_value(1),'value',ImageName);%indicate name of the first image, with ;png extension |
---|
| 206 | end |
---|
| 207 | |
---|
| 208 | %%%% correction RDvision %%%% |
---|
| 209 | if isfield(XmlData,'NbDtj') |
---|
| 210 | uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj'); |
---|
| 211 | uid_value=children(t,uid_NbDtj); |
---|
| 212 | if ~isempty(uid_value) |
---|
| 213 | t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj)); |
---|
| 214 | end |
---|
| 215 | end |
---|
| 216 | if isfield(XmlData,'NbDtk') |
---|
| 217 | uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk'); |
---|
| 218 | uid_value=children(t,uid_NbDtk); |
---|
| 219 | if ~isempty(uid_value) |
---|
| 220 | t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk)); |
---|
| 221 | end |
---|
| 222 | end |
---|
| 223 | if isempty(j1_series{1}) && isfield(XmlData,'NbDti') |
---|
| 224 | uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti'); |
---|
| 225 | t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti)); |
---|
| 226 | uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti'); |
---|
| 227 | t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti)); |
---|
| 228 | uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj'); |
---|
| 229 | uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk'); |
---|
| 230 | t=delete(t,uid_NbDtj); |
---|
| 231 | t=delete(t,uid_NbDtk); |
---|
| 232 | uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj'); |
---|
| 233 | uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk'); |
---|
| 234 | t=delete(t,uid_Dtj); |
---|
| 235 | t=delete(t,uid_Dtk); |
---|
| 236 | NomTypeNew='_1'; |
---|
| 237 | end |
---|
| 238 | SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.' |
---|
| 239 | filexml_new=[fullfile(RootPath{1},SubDirBase) '.xml']; |
---|
| 240 | save(t,filexml_new) |
---|
| 241 | end |
---|
| 242 | |
---|
| 243 | %% main loop on images |
---|
| 244 | %j1=[];%default |
---|
| 245 | nbfield2=1; |
---|
| 246 | if isfield(XmlData,'Time') |
---|
| 247 | nbfield2=size(XmlData.Time,2); |
---|
| 248 | end |
---|
| 249 | for ifile=1:nbfield |
---|
| 250 | update_waitbar(WaitbarHandle,ifile/nbfield) |
---|
| 251 | if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
---|
| 252 | disp('program stopped by user') |
---|
| 253 | break |
---|
| 254 | end |
---|
| 255 | filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile)); |
---|
| 256 | j1=[]; |
---|
| 257 | if ~isequal(nbfield2,1) |
---|
| 258 | j1=mod(ifile-1+first_label,nbfield2)+1; |
---|
| 259 | end |
---|
| 260 | i1=floor((ifile-1+first_label)/nbfield2)+1; |
---|
| 261 | filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomTypeNew,i1,[],j1); |
---|
| 262 | try |
---|
| 263 | movefile(filename,filename_new); |
---|
| 264 | [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a') |
---|
| 265 | if ~s |
---|
| 266 | msgbox_uvmat('ERROR',errormsg); |
---|
| 267 | return |
---|
| 268 | end |
---|
| 269 | catch ME |
---|
| 270 | msgbox_uvmat('ERROR',ME.message); |
---|
| 271 | return |
---|
| 272 | end |
---|
| 273 | |
---|
| 274 | end |
---|
| 275 | |
---|
| 276 | %'imadoc2struct_special': reads the xml file for image documentation |
---|
| 277 | %------------------------------------------------------------------------ |
---|
| 278 | % function [s,errormsg]=imadoc2struct_special(ImaDoc,option) |
---|
| 279 | % |
---|
| 280 | % OUTPUT: |
---|
| 281 | % s: structure representing ImaDoc |
---|
| 282 | % s.Heading: information about the data hierarchical structure |
---|
| 283 | % s.Time: matrix of times |
---|
| 284 | % s.TimeUnit |
---|
| 285 | % s.GeometryCalib: substructure containing the parameters for geometric calibration |
---|
| 286 | % errormsg: error message |
---|
| 287 | % |
---|
| 288 | % INPUT: |
---|
| 289 | % ImaDoc: full name of the xml input file with head key ImaDoc |
---|
| 290 | % option: ='GeometryCalib': read the data of GeometryCalib, including source point coordinates |
---|
| 291 | |
---|
| 292 | function [s,errormsg]=imadoc2struct_special(ImaDoc,option) |
---|
| 293 | |
---|
| 294 | %% default input and output |
---|
| 295 | if ~exist('option','var') |
---|
| 296 | option='*'; |
---|
| 297 | end |
---|
| 298 | errormsg=[];%default |
---|
| 299 | s.Heading=[];%default |
---|
| 300 | s.Time=[]; %default |
---|
| 301 | s.TimeUnit=[]; %default |
---|
| 302 | s.GeometryCalib=[]; |
---|
| 303 | tsai=[];%default |
---|
| 304 | |
---|
| 305 | %% opening the xml file |
---|
| 306 | if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist |
---|
| 307 | try |
---|
| 308 | t=xmltree(ImaDoc); |
---|
| 309 | catch |
---|
| 310 | errormsg={[ImaDoc ' is not a valid xml file']; lasterr}; |
---|
| 311 | display(errormsg); |
---|
| 312 | return |
---|
| 313 | end |
---|
| 314 | uid_root=find(t,'/ImaDoc'); |
---|
| 315 | if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file |
---|
| 316 | |
---|
| 317 | |
---|
| 318 | %% Heading |
---|
| 319 | uid_Heading=find(t,'/ImaDoc/Heading'); |
---|
| 320 | if ~isempty(uid_Heading), |
---|
| 321 | uid_Campaign=find(t,'/ImaDoc/Heading/Campaign'); |
---|
| 322 | uid_Exp=find(t,'/ImaDoc/Heading/Experiment'); |
---|
| 323 | uid_Device=find(t,'/ImaDoc/Heading/Device'); |
---|
| 324 | uid_Record=find(t,'/ImaDoc/Heading/Record'); |
---|
| 325 | uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName'); |
---|
| 326 | s.Heading.Campaign=get(t,children(t,uid_Campaign),'value'); |
---|
| 327 | s.Heading.Experiment=get(t,children(t,uid_Exp),'value'); |
---|
| 328 | s.Heading.Device=get(t,children(t,uid_Device),'value'); |
---|
| 329 | if ~isempty(uid_Record) |
---|
| 330 | s.Heading.Record=get(t,children(t,uid_Record),'value'); |
---|
| 331 | end |
---|
| 332 | s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value'); |
---|
| 333 | end |
---|
| 334 | |
---|
| 335 | %% Camera and timing |
---|
| 336 | if strcmp(option,'*') || strcmp(option,'Camera') |
---|
| 337 | uid_Camera=find(t,'/ImaDoc/Camera'); |
---|
| 338 | if ~isempty(uid_Camera) |
---|
| 339 | uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize'); |
---|
| 340 | if ~isempty(uid_ImageSize); |
---|
| 341 | ImageSize=get(t,children(t,uid_ImageSize),'value'); |
---|
| 342 | xindex=findstr(ImageSize,'x'); |
---|
| 343 | if length(xindex)>=2 |
---|
| 344 | s.Npx=str2double(ImageSize(1:xindex(1)-1)); |
---|
| 345 | s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1)); |
---|
| 346 | end |
---|
| 347 | end |
---|
| 348 | uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit'); |
---|
| 349 | if ~isempty(uid_TimeUnit) |
---|
| 350 | s.TimeUnit=get(t,children(t,uid_TimeUnit),'value'); |
---|
| 351 | end |
---|
| 352 | uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming'); |
---|
| 353 | if ~isempty(uid_BurstTiming) |
---|
| 354 | for k=1:length(uid_BurstTiming) |
---|
| 355 | subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming |
---|
| 356 | % reading Dtk |
---|
| 357 | Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1); |
---|
| 358 | Dtj=get_value(subt,'/BurstTiming/Dtj',[]); |
---|
| 359 | Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's') |
---|
| 360 | NbDtj=get_value(subt,'/BurstTiming/NbDtj',[]); |
---|
| 361 | %%%% correction RDvision %%%% |
---|
| 362 | % NbDtj=NbDtj/numel(Dtj); |
---|
| 363 | % s.NbDtj=NbDtj; |
---|
| 364 | % %%%% |
---|
| 365 | Dti=get_value(subt,'/BurstTiming/Dti',[]); |
---|
| 366 | NbDti=get_value(subt,'/BurstTiming/NbDti',1); |
---|
| 367 | %%%% correction RDvision %%%% |
---|
| 368 | if isempty(Dti)% series |
---|
| 369 | Dti=Dtj; |
---|
| 370 | NbDti=NbDtj; |
---|
| 371 | Dtj=[]; |
---|
| 372 | s.Dti=Dti; |
---|
| 373 | s.NbDti=NbDti; |
---|
| 374 | else |
---|
| 375 | % NbDtj=NbDtj/numel(Dtj);%bursts |
---|
| 376 | if ~isempty(NbDtj) |
---|
| 377 | s.NbDtj=NbDtj/numel(Dtj);%bursts; |
---|
| 378 | else |
---|
| 379 | s.NbDtj=1; |
---|
| 380 | end |
---|
| 381 | end |
---|
| 382 | %%%% %%%% |
---|
| 383 | Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's') |
---|
| 384 | |
---|
| 385 | Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit |
---|
| 386 | if ~isempty(Dti) |
---|
| 387 | Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times |
---|
| 388 | Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals Dti |
---|
| 389 | end |
---|
| 390 | if ~isempty(Dtj) |
---|
| 391 | Dtj=reshape(Dtj'*ones(1,s.NbDtj),1,s.NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times |
---|
| 392 | Dtj=[0 Dtj]; |
---|
| 393 | Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj |
---|
| 394 | end |
---|
| 395 | % reading Dtk |
---|
| 396 | Dtk=get_value(subt,'/BurstTiming/Dtk',[]); |
---|
| 397 | NbDtk=get_value(subt,'/BurstTiming/NbDtk',1); |
---|
| 398 | %%%% correction RDvision %%%% |
---|
| 399 | if ~isequal(NbDtk,1) |
---|
| 400 | NbDtk=-1+(NbDtk+1)/(NbDti+1); |
---|
| 401 | end |
---|
| 402 | s.NbDtk=NbDtk; |
---|
| 403 | %%%%% |
---|
| 404 | if isempty(Dtk) |
---|
| 405 | s.Time=[s.Time;Time_val]; |
---|
| 406 | else |
---|
| 407 | for kblock=1:NbDtk+1 |
---|
| 408 | Time_val_k=Time_val+(kblock-1)*Dtk; |
---|
| 409 | s.Time=[s.Time;Time_val_k]; |
---|
| 410 | end |
---|
| 411 | end |
---|
| 412 | end |
---|
| 413 | end |
---|
| 414 | end |
---|
| 415 | end |
---|
| 416 | |
---|
| 417 | %% motor |
---|
| 418 | if strcmp(option,'*') || strcmp(option,'GeometryCalib') |
---|
| 419 | uid_subtree=find(t,'/ImaDoc/TranslationMotor'); |
---|
| 420 | if length(uid_subtree)==1 |
---|
| 421 | subt=branch(t,uid_subtree);%subtree under GeometryCalib |
---|
| 422 | [s.TranslationMotor,errormsg]=read_subtree(subt,{'Nbslice','ZStart','ZEnd'},[1 1 1],[1 1 1]); |
---|
| 423 | end |
---|
| 424 | end |
---|
| 425 | %% geometric calibration |
---|
| 426 | if strcmp(option,'*') || strcmp(option,'GeometryCalib') |
---|
| 427 | uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib'); |
---|
| 428 | if ~isempty(uid_GeometryCalib) |
---|
| 429 | if length(uid_GeometryCalib)>1 |
---|
| 430 | errormsg=['More than one GeometryCalib in ' filecivxml]; |
---|
| 431 | return |
---|
| 432 | end |
---|
| 433 | subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib |
---|
| 434 | cont=get(subt,1,'contents'); |
---|
| 435 | if ~isempty(cont) |
---|
| 436 | uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType'); |
---|
| 437 | if isequal(length(uid_CalibrationType),1) |
---|
| 438 | tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value'); |
---|
| 439 | end |
---|
| 440 | uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit'); |
---|
| 441 | if isequal(length(uid_CoordUnit),1) |
---|
| 442 | tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value'); |
---|
| 443 | end |
---|
| 444 | uid_fx_fy=find(subt,'/GeometryCalib/fx_fy'); |
---|
| 445 | focal=[];%default fro old convention (Reg Wilson) |
---|
| 446 | if isequal(length(uid_fx_fy),1) |
---|
| 447 | tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value')); |
---|
| 448 | else %old convention (Reg Wilson) |
---|
| 449 | uid_focal=find(subt,'/GeometryCalib/focal'); |
---|
| 450 | uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy'); |
---|
| 451 | uid_sx=find(subt,'/GeometryCalib/sx'); |
---|
| 452 | if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx) |
---|
| 453 | dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value')); |
---|
| 454 | sx=str2num(get(subt,children(subt,uid_sx),'value')); |
---|
| 455 | focal=str2num(get(subt,children(subt,uid_focal),'value')); |
---|
| 456 | tsai.fx_fy(1)=sx*focal/dpx_dpy(1); |
---|
| 457 | tsai.fx_fy(2)=focal/dpx_dpy(2); |
---|
| 458 | end |
---|
| 459 | end |
---|
| 460 | uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy'); |
---|
| 461 | if ~isempty(uid_Cx_Cy) |
---|
| 462 | tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value')); |
---|
| 463 | end |
---|
| 464 | uid_kc=find(subt,'/GeometryCalib/kc'); |
---|
| 465 | if ~isempty(uid_kc) |
---|
| 466 | tsai.kc=str2double(get(subt,children(subt,uid_kc),'value')); |
---|
| 467 | else %old convention (Reg Wilson) |
---|
| 468 | uid_kappa1=find(subt,'/GeometryCalib/kappa1'); |
---|
| 469 | if ~isempty(uid_kappa1)&& ~isempty(focal) |
---|
| 470 | kappa1=str2double(get(subt,children(subt,uid_kappa1),'value')); |
---|
| 471 | tsai.kc=-kappa1*focal*focal; |
---|
| 472 | end |
---|
| 473 | end |
---|
| 474 | uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz'); |
---|
| 475 | if ~isempty(uid_Tx_Ty_Tz) |
---|
| 476 | tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value')); |
---|
| 477 | end |
---|
| 478 | uid_R=find(subt,'/GeometryCalib/R'); |
---|
| 479 | if ~isempty(uid_R) |
---|
| 480 | RR=get(subt,children(subt,uid_R),'value'); |
---|
| 481 | if length(RR)==3 |
---|
| 482 | tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})]; |
---|
| 483 | end |
---|
| 484 | end |
---|
| 485 | |
---|
| 486 | %look for laser plane definitions |
---|
| 487 | uid_Angle=find(subt,'/GeometryCalib/PlaneAngle'); |
---|
| 488 | uid_Pos=find(subt,'/GeometryCalib/SliceCoord'); |
---|
| 489 | if isempty(uid_Pos) |
---|
| 490 | uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention |
---|
| 491 | end |
---|
| 492 | if ~isempty(uid_Angle) |
---|
| 493 | tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value')); |
---|
| 494 | end |
---|
| 495 | if ~isempty(uid_Pos) |
---|
| 496 | for j=1:length(uid_Pos) |
---|
| 497 | tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value')); |
---|
| 498 | end |
---|
| 499 | uid_DZ=find(subt,'/GeometryCalib/SliceDZ'); |
---|
| 500 | uid_NbSlice=find(subt,'/GeometryCalib/NbSlice'); |
---|
| 501 | if ~isempty(uid_DZ) && ~isempty(uid_NbSlice) |
---|
| 502 | DZ=str2double(get(subt,children(subt,uid_DZ),'value')); |
---|
| 503 | NbSlice=get(subt,children(subt,uid_NbSlice),'value'); |
---|
| 504 | if isequal(NbSlice,'volume') |
---|
| 505 | tsai.NbSlice='volume'; |
---|
| 506 | NbSlice=NbDtj+1; |
---|
| 507 | else |
---|
| 508 | tsai.NbSlice=str2double(NbSlice); |
---|
| 509 | end |
---|
| 510 | tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1]; |
---|
| 511 | end |
---|
| 512 | end |
---|
| 513 | tsai.SliceAngle=get_value(subt,'/GeometryCalib/SliceAngle',[0 0 0]); |
---|
| 514 | tsai.VolumeScan=get_value(subt,'/GeometryCalib/VolumeScan','n'); |
---|
| 515 | tsai.InterfaceCoord=get_value(subt,'/GeometryCalib/InterfaceCoord',[0 0 0]); |
---|
| 516 | tsai.RefractionIndex=get_value(subt,'/GeometryCalib/RefractionIndex',1); |
---|
| 517 | |
---|
| 518 | if strcmp(option,'GeometryCalib') |
---|
| 519 | tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]); |
---|
| 520 | end |
---|
| 521 | s.GeometryCalib=tsai; |
---|
| 522 | end |
---|
| 523 | end |
---|
| 524 | end |
---|
| 525 | |
---|
| 526 | %-------------------------------------------------- |
---|
| 527 | % read a subtree |
---|
| 528 | % INPUT: |
---|
| 529 | % t: xltree |
---|
| 530 | % head_element: head elelemnt of the subtree |
---|
| 531 | % Data, structure containing |
---|
| 532 | % .Key: element name |
---|
| 533 | % .Type: type of element ('charg', 'float'....) |
---|
| 534 | % .NbOccur: nbre of occurrence, NaN for un specified number |
---|
| 535 | function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest) |
---|
| 536 | %-------------------------------------------------- |
---|
| 537 | s=[];%default |
---|
| 538 | errormsg=''; |
---|
| 539 | head_element=get(subt,1,'name'); |
---|
| 540 | cont=get(subt,1,'contents'); |
---|
| 541 | if ~isempty(cont) |
---|
| 542 | for ilist=1:length(Data) |
---|
| 543 | uid_key=find(subt,[head_element '/' Data{ilist}]); |
---|
| 544 | if ~isequal(length(uid_key),NbOccur(ilist)) |
---|
| 545 | errormsg=['wrong number of occurence for ' Data{ilist}]; |
---|
| 546 | return |
---|
| 547 | end |
---|
| 548 | for ival=1:length(uid_key) |
---|
| 549 | val=get(subt,children(subt,uid_key(ival)),'value'); |
---|
| 550 | if ~NumTest(ilist) |
---|
| 551 | eval(['s.' Data{ilist} '=val;']); |
---|
| 552 | else |
---|
| 553 | eval(['s.' Data{ilist} '=str2double(val);']) |
---|
| 554 | end |
---|
| 555 | end |
---|
| 556 | end |
---|
| 557 | end |
---|
| 558 | |
---|
| 559 | |
---|
| 560 | %-------------------------------------------------- |
---|
| 561 | % read an xml element |
---|
| 562 | function val=get_value(t,label,default) |
---|
| 563 | %-------------------------------------------------- |
---|
| 564 | val=default; |
---|
| 565 | uid=find(t,label);%find the element iud(s) |
---|
| 566 | if ~isempty(uid) %if the element named label exists |
---|
| 567 | uid_child=children(t,uid);%find the children |
---|
| 568 | if ~isempty(uid_child) |
---|
| 569 | data=get(t,uid_child,'type');%get the type of child |
---|
| 570 | if iscell(data)% case of multiple element |
---|
| 571 | for icell=1:numel(data) |
---|
| 572 | val_read=str2num(get(t,uid_child(icell),'value')); |
---|
| 573 | if ~isempty(val_read) |
---|
| 574 | val(icell,:)=val_read; |
---|
| 575 | end |
---|
| 576 | end |
---|
| 577 | % val=val'; |
---|
| 578 | else % case of unique element value |
---|
| 579 | val_read=str2num(get(t,uid_child,'value')); |
---|
| 580 | if ~isempty(val_read) |
---|
| 581 | val=val_read; |
---|
| 582 | else |
---|
| 583 | val=get(t,uid_child,'value');%char string data |
---|
| 584 | end |
---|
| 585 | end |
---|
| 586 | end |
---|
| 587 | end |
---|