1 | %'imadoc2struct': reads the xml file for image documentation
|
---|
2 | %
|
---|
3 | %function [s,errormsg]=imadoc2struct(ImaDoc)
|
---|
4 | %--------------------------------------------------------
|
---|
5 | % OUTPUT:
|
---|
6 | % s: structure representing ImaDoc
|
---|
7 | % s.Heading: information about the data hierarchical structure
|
---|
8 | % s.Time: matrix of times
|
---|
9 | % s.TimeUnit
|
---|
10 | % s.GeometryCalib: substructure containing the parameters for geometric calibration
|
---|
11 | % errormsg: error message
|
---|
12 | %
|
---|
13 | % INPUT:
|
---|
14 | % ImaDoc: full name of the xml input file with head key ImaDoc
|
---|
15 | %function [s,error,Heading,nom_type_ima,ext_ima,abs_time,TimeUnit,mode,NbSlice]=imadoc2struct(ImaDoc)
|
---|
16 | function [s,errormsg]=imadoc2struct(ImaDoc)
|
---|
17 |
|
---|
18 | errormsg=[];%default
|
---|
19 | s.Heading=[];%default
|
---|
20 | s.Time=[]; %default
|
---|
21 | s.TimeUnit=[]; %default
|
---|
22 | s.GeometryCalib=[];
|
---|
23 | % nom_type_ima=[];%default
|
---|
24 | % ext_ima=[];%default
|
---|
25 | % abs_time=[];%initiation
|
---|
26 | % GeometryCalib.CoordUnit='cm';%default
|
---|
27 | % mode=[]; %default
|
---|
28 | % NbSlice=1;%default
|
---|
29 | % npx=[];%default
|
---|
30 | % npy=[];%default
|
---|
31 | % GeometryCalib.Pxcmx=1;
|
---|
32 | % GeometryCalib.Pxcmy=1;
|
---|
33 | % GeometryCalib=[];
|
---|
34 | % NbDtj=1;
|
---|
35 | tsai=[];%default
|
---|
36 | % if ~exist('testime','var')
|
---|
37 | % testime=1;%default
|
---|
38 |
|
---|
39 | if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist
|
---|
40 | try
|
---|
41 | t=xmltree(ImaDoc);
|
---|
42 | catch
|
---|
43 | errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
|
---|
44 | display(errormsg);
|
---|
45 | return
|
---|
46 | end
|
---|
47 |
|
---|
48 | uid_root=find(t,'/ImaDoc');
|
---|
49 | if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file
|
---|
50 |
|
---|
51 | %Heading
|
---|
52 | uid_Heading=find(t,'/ImaDoc/Heading');
|
---|
53 | if ~isempty(uid_Heading),
|
---|
54 | uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
|
---|
55 | uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
|
---|
56 | uid_Device=find(t,'/ImaDoc/Heading/Device');
|
---|
57 | uid_Record=find(t,'/ImaDoc/Heading/Record');
|
---|
58 | uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
|
---|
59 | s.Heading.Campaign=get(t,children(t,uid_Campaign),'value');
|
---|
60 | s.Heading.Experiment=get(t,children(t,uid_Exp),'value');
|
---|
61 | s.Heading.Device=get(t,children(t,uid_Device),'value');
|
---|
62 | if ~isempty(uid_Record)
|
---|
63 | s.Heading.Record=get(t,children(t,uid_Record),'value');
|
---|
64 | end
|
---|
65 | s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
|
---|
66 | % FirstImage=s.Heading.ImageName;
|
---|
67 | % if ~isempty(FirstImage)
|
---|
68 | % [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type_ima]=name2display(FirstImage);
|
---|
69 | % end
|
---|
70 | end
|
---|
71 |
|
---|
72 | %Camera
|
---|
73 | uid_Camera=find(t,'/ImaDoc/Camera');
|
---|
74 | if ~isempty(uid_Camera)
|
---|
75 | uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
|
---|
76 | if ~isempty(uid_ImageSize);
|
---|
77 | ImageSize=get(t,children(t,uid_ImageSize),'value');
|
---|
78 | xindex=findstr(ImageSize,'x');
|
---|
79 | if length(xindex)>=2
|
---|
80 | % npx=str2num(ImageSize(1:xindex(1)-1));
|
---|
81 | % npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));
|
---|
82 | end
|
---|
83 | end
|
---|
84 | % uid_NbSlice=find(t,'/ImaDoc/Camera/NbSlice');
|
---|
85 | % if ~isempty(uid_NbSlice)
|
---|
86 | % NbSlice=str2num(get(t,children(t,uid_NbSlice),'value'));
|
---|
87 | % % if isempty(NbSlice),NbSlice=1;end; %default
|
---|
88 | % end
|
---|
89 | uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
|
---|
90 | if ~isempty(uid_TimeUnit)
|
---|
91 | s.TimeUnit=get(t,children(t,uid_TimeUnit),'value');
|
---|
92 | end
|
---|
93 | uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
|
---|
94 | if ~isempty(uid_BurstTiming)
|
---|
95 | for k=1:length(uid_BurstTiming)
|
---|
96 | % Dtj=[];%default
|
---|
97 | % NbDtj=1;%default
|
---|
98 | subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
|
---|
99 | % reading Dtk
|
---|
100 | Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1);
|
---|
101 | Dtj=get_value(subt,'/BurstTiming/Dtj',[]);
|
---|
102 | Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
|
---|
103 | NbDtj=get_value(subt,'/BurstTiming/NbDtj',1);
|
---|
104 | Dti=get_value(subt,'/BurstTiming/Dti',[]);
|
---|
105 | Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
|
---|
106 | NbDti=get_value(subt,'/BurstTiming/NbDti',1);
|
---|
107 | Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit
|
---|
108 | if ~isempty(Dti)
|
---|
109 | Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
|
---|
110 | Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals Dti
|
---|
111 | end
|
---|
112 | if ~isempty(Dtj)
|
---|
113 | Dtj=reshape(Dtj'*ones(1,NbDtj),1,NbDtj*numel(Dtj)); %concatene Dti vector NbDti times
|
---|
114 | Dtj=[0 Dtj];
|
---|
115 | % Time_val'
|
---|
116 | % ones(1,numel(Dtj))
|
---|
117 | % ones(numel(Time_val'),1)
|
---|
118 | % cumsum(Dtj)
|
---|
119 | Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
|
---|
120 | end
|
---|
121 | % reading Dtk
|
---|
122 | Dtk=get_value(subt,'/BurstTiming/Dtk',[]);
|
---|
123 | NbDtk=get_value(subt,'/BurstTiming/NbDtk',1);
|
---|
124 | if isempty(Dtk)
|
---|
125 | s.Time=[s.Time;Time_val];
|
---|
126 | else
|
---|
127 | for kblock=1:NbDtk+1
|
---|
128 | Time_val=Time_val+(kblock-1)*Dtk;
|
---|
129 | s.Time=[s.Time;Time_val];
|
---|
130 | end
|
---|
131 | end
|
---|
132 | end
|
---|
133 | end
|
---|
134 | if size(s.Time,1)==1
|
---|
135 | s.Time=(s.Time)'; %change vector into column
|
---|
136 | end
|
---|
137 | end
|
---|
138 |
|
---|
139 | %read calibration
|
---|
140 | uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
|
---|
141 | if ~isempty(uid_GeometryCalib)
|
---|
142 | if length(uid_GeometryCalib)>1
|
---|
143 | errormsg=['More than one GeometryCalib in ' filecivxml];
|
---|
144 | return
|
---|
145 | end
|
---|
146 | subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
|
---|
147 | cont=get(subt,1,'contents');
|
---|
148 | if ~isempty(cont)
|
---|
149 | uid_pixcmx=find(subt,'/GeometryCalib/Pxcmx');
|
---|
150 | uid_pixcmy=find(subt,'/GeometryCalib/Pxcmy');
|
---|
151 | if ~isempty(uid_pixcmx) && ~isempty(uid_pixcmy)%NON UTILISE
|
---|
152 | pixcmx=str2num(get(subt,children(subt,uid_pixcmx),'value'));
|
---|
153 | if isempty(pixcmx),pixcmx=1;end; %default
|
---|
154 | pixcmy=str2num(get(subt,children(subt,uid_pixcmy),'value'));
|
---|
155 | if isempty(pixcmy),pixcmy=1;end; %default
|
---|
156 | tsai.Pxcmx=pixcmx;
|
---|
157 | tsai.Pxcmy=pixcmy;
|
---|
158 | end
|
---|
159 | %default values:
|
---|
160 | tsai.f=1;
|
---|
161 | tsai.dpx=1;
|
---|
162 | tsai.dpy=1;
|
---|
163 | tsai.sx=1;
|
---|
164 | tsai.Cx=0;
|
---|
165 | tsai.Cy=0;
|
---|
166 | tsai.Tz=1;
|
---|
167 | tsai.Tx=0;
|
---|
168 | tsai.Ty=0;
|
---|
169 | tsai.R=[1 0 0; 0 1 0; 0 0 0];
|
---|
170 | tsai.kappa1=0;
|
---|
171 | uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
|
---|
172 | if ~isempty(uid_CoordUnit)
|
---|
173 | tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
|
---|
174 | end
|
---|
175 | uid_focal=find(subt,'/GeometryCalib/focal');
|
---|
176 | uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
|
---|
177 | uid_sx=find(subt,'/GeometryCalib/sx');
|
---|
178 | uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
|
---|
179 | uid_kappa1=find(subt,'/GeometryCalib/kappa1');
|
---|
180 | uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
|
---|
181 | uid_R=find(subt,'/GeometryCalib/R');
|
---|
182 | if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_Cx_Cy)
|
---|
183 | tsai.f=str2num(get(subt,children(subt,uid_focal),'value'));
|
---|
184 | dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
|
---|
185 | tsai.dpx=dpx_dpy(1);
|
---|
186 | tsai.dpy=dpx_dpy(2);
|
---|
187 | if ~isempty(uid_sx)
|
---|
188 | tsai.sx=str2num(get(subt,children(subt,uid_sx),'value'));
|
---|
189 | end
|
---|
190 | Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
|
---|
191 | tsai.Cx=Cx_Cy(1);
|
---|
192 | tsai.Cy=Cx_Cy(2);
|
---|
193 | end
|
---|
194 | if ~isempty(uid_Tx_Ty_Tz)
|
---|
195 | Tx_Ty_T_char=get(subt,children(subt,uid_Tx_Ty_Tz),'value');
|
---|
196 | Tx_Ty_Tz=str2num(Tx_Ty_T_char);
|
---|
197 | tsai.Tx=Tx_Ty_Tz(1);
|
---|
198 | tsai.Ty=Tx_Ty_Tz(2);
|
---|
199 | tsai.Tz=Tx_Ty_Tz(3);
|
---|
200 | end
|
---|
201 | if ~isempty(uid_R)
|
---|
202 | RR=get(subt,children(subt,uid_R),'value');
|
---|
203 | if length(RR)==3
|
---|
204 | tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
|
---|
205 | end
|
---|
206 | end
|
---|
207 | if ~isempty(uid_kappa1)
|
---|
208 | tsai.kappa1=str2num(get(subt,children(subt,uid_kappa1),'value'));
|
---|
209 | end
|
---|
210 | %look for laser plane definitions
|
---|
211 | uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
|
---|
212 | uid_Pos=find(subt,'/GeometryCalib/PlanePos');
|
---|
213 | if ~isempty(uid_Angle)
|
---|
214 | tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
|
---|
215 | end
|
---|
216 | if ~isempty(uid_Pos)
|
---|
217 | for j=1:length(uid_Pos)
|
---|
218 | tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
|
---|
219 | end
|
---|
220 | end
|
---|
221 | s.GeometryCalib=tsai;
|
---|
222 | end
|
---|
223 | end
|
---|
224 |
|
---|
225 | %--------------------------------------------------
|
---|
226 | % read an xml element
|
---|
227 | function val=get_value(t,label,default)
|
---|
228 | %--------------------------------------------------
|
---|
229 | val=default;
|
---|
230 | uid=find(t,label);%find the element iud(s)
|
---|
231 | if ~isempty(uid)
|
---|
232 | uid_child=children(t,uid);
|
---|
233 | if ~isempty(uid_child)
|
---|
234 | data=get(t,uid_child,'type');
|
---|
235 | if iscell(data)
|
---|
236 | for icell=1:numel(data)
|
---|
237 | val_read=str2num(get(t,uid_child(icell),'value'));
|
---|
238 | if ~isempty(val_read)
|
---|
239 | val(icell)=val_read;
|
---|
240 | end
|
---|
241 | end
|
---|
242 | val=val';
|
---|
243 | else
|
---|
244 | val_read=str2num(get(t,uid_child,'value'));
|
---|
245 | if ~isempty(val_read)
|
---|
246 | val=val_read;
|
---|
247 | end
|
---|
248 | end
|
---|
249 | end
|
---|
250 | end
|
---|