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