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