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