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