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 | % 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 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
47 | |
---|
48 | function ParamOut=relabel_i_j(Param) %default output=relabel_i_j(Param) |
---|
49 | |
---|
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 | ParamOut={'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 | ''}; |
---|
63 | return |
---|
64 | end |
---|
65 | |
---|
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 |
---|
73 | else |
---|
74 | hseries=guidata(Param.hseries);%handles of the GUI series |
---|
75 | if isfield(Param,'Specific')&& strcmp(Param.Specific,'?') |
---|
76 | checkrun=1;% will only search interactive input parameters (preparation of BATCH mode) |
---|
77 | else |
---|
78 | checkrun=2; % indicate the RUN option is used |
---|
79 | end |
---|
80 | end |
---|
81 | ParamOut=Param; %default output |
---|
82 | |
---|
83 | %% root input file(s) and type |
---|
84 | RootPath=Param.InputTable(:,1); |
---|
85 | RootFile=Param.InputTable(:,3); |
---|
86 | SubDir=Param.InputTable(:,2); |
---|
87 | NomType=Param.InputTable(:,4); |
---|
88 | FileExt=Param.InputTable(:,5); |
---|
89 | |
---|
90 | % get the set of input file names (cell array filecell), and the lists of |
---|
91 | % input file or frame indices i1_series,i2_series,j1_series,j2_series |
---|
92 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
93 | |
---|
94 | % numbers of slices and file indices |
---|
95 | |
---|
96 | NbSlice=1;%default |
---|
97 | if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice) |
---|
98 | NbSlice=Param.IndexRange.NbSlice; |
---|
99 | end |
---|
100 | nbview=numel(i1_series);%number of input file series (lines in InputTable) |
---|
101 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
102 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index |
---|
103 | nbfield=nbfield_j*nbfield_i; %total number of fields |
---|
104 | nbfield_i=floor(nbfield/NbSlice);%total number of indexes in a slice (adjusted to an integer number of slices) |
---|
105 | nbfield=nbfield_i*NbSlice; %total number of fields after adjustement |
---|
106 | |
---|
107 | %determine the file type on each line from the first input file |
---|
108 | ImageTypeOptions={'image','multimage','mmreader','video'}; |
---|
109 | NcTypeOptions={'netcdf','civx','civdata'}; |
---|
110 | for iview=1:nbview |
---|
111 | if ~exist(filecell{iview,1}','file') |
---|
112 | msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist']) |
---|
113 | return |
---|
114 | end |
---|
115 | [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1}); |
---|
116 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
---|
117 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
---|
118 | if ~isempty(j1_series{iview}) |
---|
119 | frame_index{iview}=j1_series{iview}; |
---|
120 | else |
---|
121 | frame_index{iview}=i1_series{iview}; |
---|
122 | end |
---|
123 | end |
---|
124 | |
---|
125 | %% calibration data and timing: read the ImaDoc files |
---|
126 | mode=''; %default |
---|
127 | timecell={}; |
---|
128 | itime=0; |
---|
129 | NbSlice_calib={}; |
---|
130 | XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing) |
---|
131 | for iview=1:nbview%Loop on views |
---|
132 | SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.' |
---|
133 | filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder |
---|
134 | if ~exist(filexml,'file') |
---|
135 | filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder |
---|
136 | if ~exist(filexml,'file') |
---|
137 | filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file |
---|
138 | if ~exist(filexml,'file') |
---|
139 | filexml=''; |
---|
140 | end |
---|
141 | end |
---|
142 | end |
---|
143 | if ~isempty(filexml) |
---|
144 | [XmlData{iview},error]=imadoc2struct_special(filexml); |
---|
145 | end |
---|
146 | if isfield(XmlData{iview},'Time') |
---|
147 | itime=itime+1; |
---|
148 | timecell{itime}=XmlData{iview}.Time; |
---|
149 | end |
---|
150 | if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') |
---|
151 | NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform |
---|
152 | if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) |
---|
153 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); |
---|
154 | end |
---|
155 | end |
---|
156 | end |
---|
157 | |
---|
158 | %% check coincidence in time for several input file series |
---|
159 | % not relevant |
---|
160 | |
---|
161 | %% coordinate transform or other user defined transform |
---|
162 | %not relevant |
---|
163 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
164 | % EDIT FROM HERE |
---|
165 | |
---|
166 | %% check the validity of input file types |
---|
167 | if CheckImage{1} |
---|
168 | FileExtOut='.png'; % write result as .png images for image inputs |
---|
169 | elseif CheckNc{1} |
---|
170 | FileExtOut='.nc';% write result as .nc files for netcdf inputs |
---|
171 | else |
---|
172 | msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}]) |
---|
173 | return |
---|
174 | end |
---|
175 | if nbview==2 && ~isequal(CheckImage{1},CheckImage{2}) |
---|
176 | msgbox_uvmat('ERROR','input must be two image series or two netcdf file series') |
---|
177 | return |
---|
178 | end |
---|
179 | % NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series |
---|
180 | % if NbSlice~=nbfield_j |
---|
181 | % answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]); |
---|
182 | % if ~strcmp(answer,'Yes') |
---|
183 | % return |
---|
184 | % end |
---|
185 | % end |
---|
186 | |
---|
187 | %% Set field names and velocity types |
---|
188 | % not relevant here |
---|
189 | |
---|
190 | %% Initiate output fields |
---|
191 | % not relevant here |
---|
192 | |
---|
193 | %% interactive input of specific parameters (for RDvision system) |
---|
194 | display('RDvision system') |
---|
195 | first_label=0; %image numbers start from 0 |
---|
196 | if ~strcmp(NomType{1},'_000001') |
---|
197 | msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation |
---|
198 | return |
---|
199 | else |
---|
200 | answer=msgbox_uvmat('','this function will relabel the file series from RDvision from and correct the xml file');%error message for directory creation |
---|
201 | if ~strcmp(answer,'Yes') |
---|
202 | return |
---|
203 | end |
---|
204 | end |
---|
205 | |
---|
206 | %% copy and adapt the xml file |
---|
207 | NomTypeNew='_1_1'; |
---|
208 | if ~isempty(XmlData{1}) |
---|
209 | t=xmltree(filexml); |
---|
210 | |
---|
211 | %update information on the first image name in the series |
---|
212 | uid_Heading=find(t,'ImaDoc/Heading'); |
---|
213 | if isempty(uid_Heading) |
---|
214 | [t,uid_Heading]=add(t,1,'element','Heading'); |
---|
215 | end |
---|
216 | uid_ImageName=find(t,'ImaDoc/Heading/ImageName'); |
---|
217 | j1=[]; |
---|
218 | if ~isempty(j1_series{1}) |
---|
219 | j1=j1_series{1}; |
---|
220 | end |
---|
221 | ImageName=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'_1_1',i1_series{1}(1),[],j1); |
---|
222 | [pth,ImageName]=fileparts(ImageName); |
---|
223 | ImageName=[ImageName '.png']; |
---|
224 | if isempty(uid_ImageName) |
---|
225 | [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName'); |
---|
226 | end |
---|
227 | uid_value=children(t,uid_ImageName); |
---|
228 | if isempty(uid_value) |
---|
229 | t=add(t,uid_ImageName,'chardata',ImageName);%indicate name of the first image, with ;png extension |
---|
230 | else |
---|
231 | t=set(t,uid_value(1),'value',ImageName);%indicate name of the first image, with ;png extension |
---|
232 | end |
---|
233 | |
---|
234 | %%%% correction RDvision %%%% |
---|
235 | if isfield(XmlData{1},'NbDtj') |
---|
236 | uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj'); |
---|
237 | uid_value=children(t,uid_NbDtj); |
---|
238 | if ~isempty(uid_value) |
---|
239 | t=set(t,uid_value(1),'value',num2str(XmlData{1}.NbDtj)); |
---|
240 | end |
---|
241 | end |
---|
242 | if isfield(XmlData{1},'NbDtk') |
---|
243 | uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk'); |
---|
244 | uid_value=children(t,uid_NbDtk); |
---|
245 | if ~isempty(uid_value) |
---|
246 | t=set(t,uid_value(1),'value',num2str(XmlData{1}.NbDtk)); |
---|
247 | end |
---|
248 | end |
---|
249 | if isempty(j1_series{1}) && isfield(XmlData{1},'NbDti') |
---|
250 | uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti'); |
---|
251 | t=add(t,uid_Dti,'chardata',num2str(XmlData{1}.Dti)); |
---|
252 | uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti'); |
---|
253 | t=add(t,uid_NbDti,'chardata',num2str(XmlData{1}.NbDti)); |
---|
254 | uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj'); |
---|
255 | uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk'); |
---|
256 | t=delete(t,uid_NbDtj); |
---|
257 | t=delete(t,uid_NbDtk); |
---|
258 | uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj'); |
---|
259 | uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk'); |
---|
260 | t=delete(t,uid_Dtj); |
---|
261 | t=delete(t,uid_Dtk); |
---|
262 | NomTypeNew='_1'; |
---|
263 | end |
---|
264 | SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.' |
---|
265 | filexml_new=[fullfile(RootPath{1},SubDirBase) '.xml']; |
---|
266 | save(t,filexml_new) |
---|
267 | end |
---|
268 | |
---|
269 | %% main loop on images |
---|
270 | %j1=[];%default |
---|
271 | nbfield2=size(XmlData{1}.Time,2); |
---|
272 | for ifile=1:nbfield |
---|
273 | if checkrun |
---|
274 | update_waitbar(hseries.Waitbar,ifile/nbfield) |
---|
275 | drawnow |
---|
276 | stopstate=get(hseries.RUN,'BusyAction'); |
---|
277 | else |
---|
278 | stopstate='queue'; |
---|
279 | end |
---|
280 | if isequal(stopstate,'queue') % enable STOP command |
---|
281 | filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile)); |
---|
282 | j1=mod(ifile-1+first_label,nbfield2)+1; |
---|
283 | i1=floor((ifile-1+first_label)/nbfield2)+1; |
---|
284 | filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomTypeNew,i1,[],j1); |
---|
285 | try |
---|
286 | movefile(filename,filename_new); |
---|
287 | [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a') |
---|
288 | if ~s |
---|
289 | msgbox_uvmat('ERROR',errormsg); |
---|
290 | return |
---|
291 | end |
---|
292 | catch ME |
---|
293 | msgbox_uvmat('ERROR',ME.message); |
---|
294 | return |
---|
295 | end |
---|
296 | end |
---|
297 | end |
---|
298 | |
---|
299 | %'imadoc2struct_special': reads the xml file for image documentation |
---|
300 | %------------------------------------------------------------------------ |
---|
301 | % function [s,errormsg]=imadoc2struct_special(ImaDoc,option) |
---|
302 | % |
---|
303 | % OUTPUT: |
---|
304 | % s: structure representing ImaDoc |
---|
305 | % s.Heading: information about the data hierarchical structure |
---|
306 | % s.Time: matrix of times |
---|
307 | % s.TimeUnit |
---|
308 | % s.GeometryCalib: substructure containing the parameters for geometric calibration |
---|
309 | % errormsg: error message |
---|
310 | % |
---|
311 | % INPUT: |
---|
312 | % ImaDoc: full name of the xml input file with head key ImaDoc |
---|
313 | % option: ='GeometryCalib': read the data of GeometryCalib, including source point coordinates |
---|
314 | |
---|
315 | function [s,errormsg]=imadoc2struct_special(ImaDoc,option) |
---|
316 | |
---|
317 | %% default input and output |
---|
318 | if ~exist('option','var') |
---|
319 | option='*'; |
---|
320 | end |
---|
321 | errormsg=[];%default |
---|
322 | s.Heading=[];%default |
---|
323 | s.Time=[]; %default |
---|
324 | s.TimeUnit=[]; %default |
---|
325 | s.GeometryCalib=[]; |
---|
326 | tsai=[];%default |
---|
327 | |
---|
328 | %% opening the xml file |
---|
329 | if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist |
---|
330 | try |
---|
331 | t=xmltree(ImaDoc); |
---|
332 | catch |
---|
333 | errormsg={[ImaDoc ' is not a valid xml file']; lasterr}; |
---|
334 | display(errormsg); |
---|
335 | return |
---|
336 | end |
---|
337 | uid_root=find(t,'/ImaDoc'); |
---|
338 | if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file |
---|
339 | |
---|
340 | |
---|
341 | %% Heading |
---|
342 | uid_Heading=find(t,'/ImaDoc/Heading'); |
---|
343 | if ~isempty(uid_Heading), |
---|
344 | uid_Campaign=find(t,'/ImaDoc/Heading/Campaign'); |
---|
345 | uid_Exp=find(t,'/ImaDoc/Heading/Experiment'); |
---|
346 | uid_Device=find(t,'/ImaDoc/Heading/Device'); |
---|
347 | uid_Record=find(t,'/ImaDoc/Heading/Record'); |
---|
348 | uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName'); |
---|
349 | s.Heading.Campaign=get(t,children(t,uid_Campaign),'value'); |
---|
350 | s.Heading.Experiment=get(t,children(t,uid_Exp),'value'); |
---|
351 | s.Heading.Device=get(t,children(t,uid_Device),'value'); |
---|
352 | if ~isempty(uid_Record) |
---|
353 | s.Heading.Record=get(t,children(t,uid_Record),'value'); |
---|
354 | end |
---|
355 | s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value'); |
---|
356 | end |
---|
357 | |
---|
358 | %% Camera and timing |
---|
359 | if strcmp(option,'*') || strcmp(option,'Camera') |
---|
360 | uid_Camera=find(t,'/ImaDoc/Camera'); |
---|
361 | if ~isempty(uid_Camera) |
---|
362 | uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize'); |
---|
363 | if ~isempty(uid_ImageSize); |
---|
364 | ImageSize=get(t,children(t,uid_ImageSize),'value'); |
---|
365 | xindex=findstr(ImageSize,'x'); |
---|
366 | if length(xindex)>=2 |
---|
367 | s.Npx=str2double(ImageSize(1:xindex(1)-1)); |
---|
368 | s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1)); |
---|
369 | end |
---|
370 | end |
---|
371 | uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit'); |
---|
372 | if ~isempty(uid_TimeUnit) |
---|
373 | s.TimeUnit=get(t,children(t,uid_TimeUnit),'value'); |
---|
374 | end |
---|
375 | uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming'); |
---|
376 | if ~isempty(uid_BurstTiming) |
---|
377 | for k=1:length(uid_BurstTiming) |
---|
378 | subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming |
---|
379 | % reading Dtk |
---|
380 | Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1); |
---|
381 | Dtj=get_value(subt,'/BurstTiming/Dtj',[]); |
---|
382 | Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's') |
---|
383 | NbDtj=get_value(subt,'/BurstTiming/NbDtj',[]); |
---|
384 | %%%% correction RDvision %%%% |
---|
385 | % NbDtj=NbDtj/numel(Dtj); |
---|
386 | % s.NbDtj=NbDtj; |
---|
387 | % %%%% |
---|
388 | Dti=get_value(subt,'/BurstTiming/Dti',[]); |
---|
389 | NbDti=get_value(subt,'/BurstTiming/NbDti',1); |
---|
390 | %%%% correction RDvision %%%% |
---|
391 | if isempty(Dti)% series |
---|
392 | Dti=Dtj; |
---|
393 | NbDti=NbDtj; |
---|
394 | Dtj=[]; |
---|
395 | s.Dti=Dti; |
---|
396 | s.NbDti=NbDti; |
---|
397 | else |
---|
398 | % NbDtj=NbDtj/numel(Dtj);%bursts |
---|
399 | if ~isempty(NbDtj) |
---|
400 | s.NbDtj=NbDtj/numel(Dtj);%bursts; |
---|
401 | else |
---|
402 | s.NbDtj=1; |
---|
403 | end |
---|
404 | end |
---|
405 | %%%% %%%% |
---|
406 | Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's') |
---|
407 | |
---|
408 | Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit |
---|
409 | if ~isempty(Dti) |
---|
410 | Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times |
---|
411 | Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals Dti |
---|
412 | end |
---|
413 | if ~isempty(Dtj) |
---|
414 | Dtj=reshape(Dtj'*ones(1,s.NbDtj),1,s.NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times |
---|
415 | Dtj=[0 Dtj]; |
---|
416 | Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj |
---|
417 | end |
---|
418 | % reading Dtk |
---|
419 | Dtk=get_value(subt,'/BurstTiming/Dtk',[]); |
---|
420 | NbDtk=get_value(subt,'/BurstTiming/NbDtk',1); |
---|
421 | %%%% correction RDvision %%%% |
---|
422 | if ~isequal(NbDtk,1) |
---|
423 | NbDtk=-1+(NbDtk+1)/(NbDti+1); |
---|
424 | end |
---|
425 | s.NbDtk=NbDtk; |
---|
426 | %%%%% |
---|
427 | if isempty(Dtk) |
---|
428 | s.Time=[s.Time;Time_val]; |
---|
429 | else |
---|
430 | for kblock=1:NbDtk+1 |
---|
431 | Time_val_k=Time_val+(kblock-1)*Dtk; |
---|
432 | s.Time=[s.Time;Time_val_k]; |
---|
433 | end |
---|
434 | end |
---|
435 | end |
---|
436 | end |
---|
437 | end |
---|
438 | end |
---|
439 | |
---|
440 | %% motor |
---|
441 | if strcmp(option,'*') || strcmp(option,'GeometryCalib') |
---|
442 | uid_subtree=find(t,'/ImaDoc/TranslationMotor'); |
---|
443 | if length(uid_subtree)==1 |
---|
444 | subt=branch(t,uid_subtree);%subtree under GeometryCalib |
---|
445 | [s.TranslationMotor,errormsg]=read_subtree(subt,{'Nbslice','ZStart','ZEnd'},[1 1 1],[1 1 1]); |
---|
446 | end |
---|
447 | end |
---|
448 | %% geometric calibration |
---|
449 | if strcmp(option,'*') || strcmp(option,'GeometryCalib') |
---|
450 | uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib'); |
---|
451 | if ~isempty(uid_GeometryCalib) |
---|
452 | if length(uid_GeometryCalib)>1 |
---|
453 | errormsg=['More than one GeometryCalib in ' filecivxml]; |
---|
454 | return |
---|
455 | end |
---|
456 | subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib |
---|
457 | cont=get(subt,1,'contents'); |
---|
458 | if ~isempty(cont) |
---|
459 | uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType'); |
---|
460 | if isequal(length(uid_CalibrationType),1) |
---|
461 | tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value'); |
---|
462 | end |
---|
463 | uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit'); |
---|
464 | if isequal(length(uid_CoordUnit),1) |
---|
465 | tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value'); |
---|
466 | end |
---|
467 | uid_fx_fy=find(subt,'/GeometryCalib/fx_fy'); |
---|
468 | focal=[];%default fro old convention (Reg Wilson) |
---|
469 | if isequal(length(uid_fx_fy),1) |
---|
470 | tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value')); |
---|
471 | else %old convention (Reg Wilson) |
---|
472 | uid_focal=find(subt,'/GeometryCalib/focal'); |
---|
473 | uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy'); |
---|
474 | uid_sx=find(subt,'/GeometryCalib/sx'); |
---|
475 | if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx) |
---|
476 | dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value')); |
---|
477 | sx=str2num(get(subt,children(subt,uid_sx),'value')); |
---|
478 | focal=str2num(get(subt,children(subt,uid_focal),'value')); |
---|
479 | tsai.fx_fy(1)=sx*focal/dpx_dpy(1); |
---|
480 | tsai.fx_fy(2)=focal/dpx_dpy(2); |
---|
481 | end |
---|
482 | end |
---|
483 | uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy'); |
---|
484 | if ~isempty(uid_Cx_Cy) |
---|
485 | tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value')); |
---|
486 | end |
---|
487 | uid_kc=find(subt,'/GeometryCalib/kc'); |
---|
488 | if ~isempty(uid_kc) |
---|
489 | tsai.kc=str2double(get(subt,children(subt,uid_kc),'value')); |
---|
490 | else %old convention (Reg Wilson) |
---|
491 | uid_kappa1=find(subt,'/GeometryCalib/kappa1'); |
---|
492 | if ~isempty(uid_kappa1)&& ~isempty(focal) |
---|
493 | kappa1=str2double(get(subt,children(subt,uid_kappa1),'value')); |
---|
494 | tsai.kc=-kappa1*focal*focal; |
---|
495 | end |
---|
496 | end |
---|
497 | uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz'); |
---|
498 | if ~isempty(uid_Tx_Ty_Tz) |
---|
499 | tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value')); |
---|
500 | end |
---|
501 | uid_R=find(subt,'/GeometryCalib/R'); |
---|
502 | if ~isempty(uid_R) |
---|
503 | RR=get(subt,children(subt,uid_R),'value'); |
---|
504 | if length(RR)==3 |
---|
505 | tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})]; |
---|
506 | end |
---|
507 | end |
---|
508 | |
---|
509 | %look for laser plane definitions |
---|
510 | uid_Angle=find(subt,'/GeometryCalib/PlaneAngle'); |
---|
511 | uid_Pos=find(subt,'/GeometryCalib/SliceCoord'); |
---|
512 | if isempty(uid_Pos) |
---|
513 | uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention |
---|
514 | end |
---|
515 | if ~isempty(uid_Angle) |
---|
516 | tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value')); |
---|
517 | end |
---|
518 | if ~isempty(uid_Pos) |
---|
519 | for j=1:length(uid_Pos) |
---|
520 | tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value')); |
---|
521 | end |
---|
522 | uid_DZ=find(subt,'/GeometryCalib/SliceDZ'); |
---|
523 | uid_NbSlice=find(subt,'/GeometryCalib/NbSlice'); |
---|
524 | if ~isempty(uid_DZ) && ~isempty(uid_NbSlice) |
---|
525 | DZ=str2double(get(subt,children(subt,uid_DZ),'value')); |
---|
526 | NbSlice=get(subt,children(subt,uid_NbSlice),'value'); |
---|
527 | if isequal(NbSlice,'volume') |
---|
528 | tsai.NbSlice='volume'; |
---|
529 | NbSlice=NbDtj+1; |
---|
530 | else |
---|
531 | tsai.NbSlice=str2double(NbSlice); |
---|
532 | end |
---|
533 | tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1]; |
---|
534 | end |
---|
535 | end |
---|
536 | tsai.SliceAngle=get_value(subt,'/GeometryCalib/SliceAngle',[0 0 0]); |
---|
537 | tsai.VolumeScan=get_value(subt,'/GeometryCalib/VolumeScan','n'); |
---|
538 | tsai.InterfaceCoord=get_value(subt,'/GeometryCalib/InterfaceCoord',[0 0 0]); |
---|
539 | tsai.RefractionIndex=get_value(subt,'/GeometryCalib/RefractionIndex',1); |
---|
540 | |
---|
541 | if strcmp(option,'GeometryCalib') |
---|
542 | tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]); |
---|
543 | end |
---|
544 | s.GeometryCalib=tsai; |
---|
545 | end |
---|
546 | end |
---|
547 | end |
---|
548 | |
---|
549 | %-------------------------------------------------- |
---|
550 | % read a subtree |
---|
551 | % INPUT: |
---|
552 | % t: xltree |
---|
553 | % head_element: head elelemnt of the subtree |
---|
554 | % Data, structure containing |
---|
555 | % .Key: element name |
---|
556 | % .Type: type of element ('charg', 'float'....) |
---|
557 | % .NbOccur: nbre of occurrence, NaN for un specified number |
---|
558 | function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest) |
---|
559 | %-------------------------------------------------- |
---|
560 | s=[];%default |
---|
561 | errormsg=''; |
---|
562 | head_element=get(subt,1,'name'); |
---|
563 | cont=get(subt,1,'contents'); |
---|
564 | if ~isempty(cont) |
---|
565 | for ilist=1:length(Data) |
---|
566 | uid_key=find(subt,[head_element '/' Data{ilist}]); |
---|
567 | if ~isequal(length(uid_key),NbOccur(ilist)) |
---|
568 | errormsg=['wrong number of occurence for ' Data{ilist}]; |
---|
569 | return |
---|
570 | end |
---|
571 | for ival=1:length(uid_key) |
---|
572 | val=get(subt,children(subt,uid_key(ival)),'value'); |
---|
573 | if ~NumTest(ilist) |
---|
574 | eval(['s.' Data{ilist} '=val;']); |
---|
575 | else |
---|
576 | eval(['s.' Data{ilist} '=str2double(val);']) |
---|
577 | end |
---|
578 | end |
---|
579 | end |
---|
580 | end |
---|
581 | |
---|
582 | |
---|
583 | %-------------------------------------------------- |
---|
584 | % read an xml element |
---|
585 | function val=get_value(t,label,default) |
---|
586 | %-------------------------------------------------- |
---|
587 | val=default; |
---|
588 | uid=find(t,label);%find the element iud(s) |
---|
589 | if ~isempty(uid) %if the element named label exists |
---|
590 | uid_child=children(t,uid);%find the children |
---|
591 | if ~isempty(uid_child) |
---|
592 | data=get(t,uid_child,'type');%get the type of child |
---|
593 | if iscell(data)% case of multiple element |
---|
594 | for icell=1:numel(data) |
---|
595 | val_read=str2num(get(t,uid_child(icell),'value')); |
---|
596 | if ~isempty(val_read) |
---|
597 | val(icell,:)=val_read; |
---|
598 | end |
---|
599 | end |
---|
600 | % val=val'; |
---|
601 | else % case of unique element value |
---|
602 | val_read=str2num(get(t,uid_child,'value')); |
---|
603 | if ~isempty(val_read) |
---|
604 | val=val_read; |
---|
605 | else |
---|
606 | val=get(t,uid_child,'value');%char string data |
---|
607 | end |
---|
608 | end |
---|
609 | end |
---|
610 | end |
---|