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