Changeset 156 for trunk/src/imadoc2struct.m
- Timestamp:
- Dec 19, 2010, 10:11:04 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/imadoc2struct.m
r116 r156 16 16 17 17 function [s,errormsg]=imadoc2struct(ImaDoc,option) 18 %% default input and output 18 19 if ~exist('option','var') 19 option=' default';20 option='*'; 20 21 end 21 22 errormsg=[];%default … … 26 27 tsai=[];%default 27 28 29 %% opening the xml file 28 30 if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist 29 31 try … … 34 36 return 35 37 end 36 37 38 uid_root=find(t,'/ImaDoc'); 38 39 if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file 39 40 40 %Heading 41 42 %% Heading 41 43 uid_Heading=find(t,'/ImaDoc/Heading'); 42 44 if ~isempty(uid_Heading), … … 55 57 end 56 58 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 65 s.Npx=str2double(ImageSize(1:xindex(1)-1)); 66 s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1)); 59 %% Camera and timing 60 if strcmp(option,'*') || strcmp(option,'Camera') 61 uid_Camera=find(t,'/ImaDoc/Camera'); 62 if ~isempty(uid_Camera) 63 uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize'); 64 if ~isempty(uid_ImageSize); 65 ImageSize=get(t,children(t,uid_ImageSize),'value'); 66 xindex=findstr(ImageSize,'x'); 67 if length(xindex)>=2 68 s.Npx=str2double(ImageSize(1:xindex(1)-1)); 69 s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1)); 70 end 71 end 72 uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit'); 73 if ~isempty(uid_TimeUnit) 74 s.TimeUnit=get(t,children(t,uid_TimeUnit),'value'); 75 end 76 uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming'); 77 if ~isempty(uid_BurstTiming) 78 for k=1:length(uid_BurstTiming) 79 subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming 80 % reading Dtk 81 Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1); 82 Dtj=get_value(subt,'/BurstTiming/Dtj',[]); 83 Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's') 84 NbDtj=get_value(subt,'/BurstTiming/NbDtj',1); 85 Dti=get_value(subt,'/BurstTiming/Dti',[]); 86 Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's') 87 NbDti=get_value(subt,'/BurstTiming/NbDti',1); 88 Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit 89 if ~isempty(Dti) 90 Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times 91 Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals Dti 92 end 93 if ~isempty(Dtj) 94 Dtj=reshape(Dtj'*ones(1,NbDtj),1,NbDtj*numel(Dtj)); %concatene Dti vector NbDti times 95 Dtj=[0 Dtj]; 96 Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj 97 end 98 % reading Dtk 99 Dtk=get_value(subt,'/BurstTiming/Dtk',[]); 100 NbDtk=get_value(subt,'/BurstTiming/NbDtk',1); 101 if isempty(Dtk) 102 s.Time=[s.Time;Time_val]; 103 else 104 for kblock=1:NbDtk+1 105 Time_val=Time_val+(kblock-1)*Dtk; 106 s.Time=[s.Time;Time_val]; 107 end 108 end 109 end 67 110 end 68 111 end 69 uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit'); 70 if ~isempty(uid_TimeUnit) 71 s.TimeUnit=get(t,children(t,uid_TimeUnit),'value'); 112 end 113 114 %% geometric calibration 115 if strcmp(option,'*') || strcmp(option,'GeometryCalib') 116 uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib'); 117 if ~isempty(uid_GeometryCalib) 118 if length(uid_GeometryCalib)>1 119 errormsg=['More than one GeometryCalib in ' filecivxml]; 120 return 121 end 122 subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib 123 cont=get(subt,1,'contents'); 124 if ~isempty(cont) 125 uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType'); 126 if isequal(length(uid_CalibrationType),1) 127 tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value'); 128 end 129 uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit'); 130 if isequal(length(uid_CoordUnit),1) 131 tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value'); 132 end 133 uid_fx_fy=find(subt,'/GeometryCalib/fx_fy'); 134 focal=[];%default fro old convention (Reg Wilson) 135 if isequal(length(uid_fx_fy),1) 136 tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value')); 137 else %old convention (Reg Wilson) 138 uid_focal=find(subt,'/GeometryCalib/focal'); 139 uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy'); 140 uid_sx=find(subt,'/GeometryCalib/sx'); 141 if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx) 142 dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value')); 143 sx=str2num(get(subt,children(subt,uid_sx),'value')); 144 focal=str2num(get(subt,children(subt,uid_focal),'value')); 145 tsai.fx_fy(1)=sx*focal/dpx_dpy(1); 146 tsai.fx_fy(2)=focal/dpx_dpy(2); 147 end 148 end 149 uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy'); 150 if ~isempty(uid_Cx_Cy) 151 tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value')); 152 end 153 uid_kc=find(subt,'/GeometryCalib/kc'); 154 if ~isempty(uid_kc) 155 tsai.kc=str2double(get(subt,children(subt,uid_kc),'value')); 156 else %old convention (Reg Wilson) 157 uid_kappa1=find(subt,'/GeometryCalib/kappa1'); 158 if ~isempty(uid_kappa1)&& ~isempty(focal) 159 kappa1=str2double(get(subt,children(subt,uid_kappa1),'value')); 160 tsai.kc=-kappa1*focal*focal; 161 end 162 end 163 uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz'); 164 if ~isempty(uid_Tx_Ty_Tz) 165 tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value')); 166 end 167 uid_R=find(subt,'/GeometryCalib/R'); 168 if ~isempty(uid_R) 169 RR=get(subt,children(subt,uid_R),'value'); 170 if length(RR)==3 171 tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})]; 172 end 173 end 174 175 %look for laser plane definitions 176 uid_Angle=find(subt,'/GeometryCalib/PlaneAngle'); 177 uid_Pos=find(subt,'/GeometryCalib/SliceCoord'); 178 if isempty(uid_Pos) 179 uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention 180 end 181 if ~isempty(uid_Angle) 182 tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value')); 183 end 184 if ~isempty(uid_Pos) 185 for j=1:length(uid_Pos) 186 tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value')); 187 end 188 uid_DZ=find(subt,'/GeometryCalib/SliceDZ'); 189 uid_NbSlice=find(subt,'/GeometryCalib/NbSlice'); 190 if ~isempty(uid_DZ) && ~isempty(uid_NbSlice) 191 DZ=str2double(get(subt,children(subt,uid_DZ),'value')); 192 NbSlice=get(subt,children(subt,uid_NbSlice),'value'); 193 if isequal(NbSlice,'volume') 194 tsai.NbSlice='volume'; 195 NbSlice=NbDtj+1; 196 else 197 tsai.NbSlice=str2double(NbSlice); 198 end 199 tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1]; 200 end 201 end 202 if strcmp(option,'GeometryCalib') 203 tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]); 204 end 205 s.GeometryCalib=tsai; 206 end 72 207 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',[]); 97 NbDtk=get_value(subt,'/BurstTiming/NbDtk',1); 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 114 errormsg=['More than one GeometryCalib in ' filecivxml]; 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'); 122 % if ~isempty(uid_pixcmx) && ~isempty(uid_pixcmy)%NON UTILISE 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.dpx_dpy=1; 132 %tsai.dpy=1; 133 %tsai.sx=1; 134 % tsai.Cx_Cy=[0 0]; 135 % tsai.Cy=0; 136 % tsai.Tx_Ty_Tz=[0 0 1]; 137 % tsai.Tx=0; 138 % tsai.Ty=0; 139 % tsai.R=[1 0 0; 0 1 0; 0 0 0]; 140 uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType'); 141 if isequal(length(uid_CalibrationType),1) 142 tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value'); 143 end 144 uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit'); 145 if isequal(length(uid_CoordUnit),1) 146 tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value'); 147 end 148 uid_fx_fy=find(subt,'/GeometryCalib/fx_fy'); 149 focal=[];%default fro old convention (Reg Wilson) 150 if isequal(length(uid_fx_fy),1) 151 tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value')); 152 else %old convention (Reg Wilson) 153 uid_focal=find(subt,'/GeometryCalib/focal'); 154 uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy'); 155 uid_sx=find(subt,'/GeometryCalib/sx'); 156 if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx) 157 dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value')); 158 sx=str2num(get(subt,children(subt,uid_sx),'value')); 159 focal=str2num(get(subt,children(subt,uid_focal),'value')); 160 tsai.fx_fy(1)=sx*focal/dpx_dpy(1); 161 tsai.fx_fy(2)=focal/dpx_dpy(2); 162 end 163 end 164 uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy'); 165 if ~isempty(uid_Cx_Cy) 166 tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value')); 167 end 168 uid_kc=find(subt,'/GeometryCalib/kc'); 169 if ~isempty(uid_kc) 170 tsai.kc=str2num(get(subt,children(subt,uid_kc),'value')); 171 else %old convention (Reg Wilson) 172 uid_kappa1=find(subt,'/GeometryCalib/kappa1'); 173 if ~isempty(uid_kappa1)&& ~isempty(focal) 174 kappa1=str2num(get(subt,children(subt,uid_kappa1),'value')); 175 tsai.kc=-kappa1*focal*focal; 176 end 177 end 178 uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz'); 179 if ~isempty(uid_Tx_Ty_Tz) 180 tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value')); 181 end 182 uid_R=find(subt,'/GeometryCalib/R'); 183 if ~isempty(uid_R) 184 RR=get(subt,children(subt,uid_R),'value'); 185 if length(RR)==3 186 tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})]; 187 end 188 end 189 190 %look for laser plane definitions 191 uid_Angle=find(subt,'/GeometryCalib/PlaneAngle'); 192 uid_Pos=find(subt,'/GeometryCalib/SliceCoord'); 193 if isempty(uid_Pos) 194 uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention 195 end 196 if ~isempty(uid_Angle) 197 tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value')); 198 end 199 if ~isempty(uid_Pos) 200 for j=1:length(uid_Pos) 201 tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value')); 202 end 203 uid_DZ=find(subt,'/GeometryCalib/SliceDZ'); 204 uid_NbSlice=find(subt,'/GeometryCalib/NbSlice'); 205 if ~isempty(uid_DZ) && ~isempty(uid_NbSlice) 206 DZ=str2double(get(subt,children(subt,uid_DZ),'value')); 207 NbSlice=get(subt,children(subt,uid_NbSlice),'value'); 208 if isequal(NbSlice,'volume') 209 tsai.NbSlice='volume'; 210 NbSlice=NbDtj+1; 211 else 212 tsai.NbSlice=str2double(NbSlice); 213 end 214 tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1]; 215 end 216 end 217 if strcmp(option,'GeometryCalib') 218 tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);%time in TimeUnit 219 size(tsai.PointCoord) 220 end 221 s.GeometryCalib=tsai; 222 end 223 end 208 end 224 209 225 210 %--------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.