source: trunk/src/imadoc2struct.m @ 131

Last change on this file since 131 was 116, checked in by sommeria, 14 years ago

geometry_calib is now updated when a new image is viewed by uvmat
imadoc2struct corrected for time reading

File size: 10.1 KB
RevLine 
[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]17function [s,errormsg]=imadoc2struct(ImaDoc,option)
18if ~exist('option','var')
19    option='default';
20end
[8]21errormsg=[];%default
22s.Heading=[];%default
23s.Time=[]; %default
24s.TimeUnit=[]; %default
25s.GeometryCalib=[];
26tsai=[];%default
27
28if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist
29try
30    t=xmltree(ImaDoc);
31catch
32    errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
33    display(errormsg);
34    return
35end
36
37uid_root=find(t,'/ImaDoc');
38if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file
39
40%Heading
41uid_Heading=find(t,'/ImaDoc/Heading');
42if ~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');
55end
56
57%Camera   
58uid_Camera=find(t,'/ImaDoc/Camera');
59if ~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
108end
109
110%read calibration
111uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
112if ~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)
[114]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');
[8]143        end
144        uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
[114]145        if isequal(length(uid_CoordUnit),1)
[8]146            tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
147        end
[114]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
[8]164        uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
[114]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;
[8]176            end
177        end
[114]178        uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
[8]179        if ~isempty(uid_Tx_Ty_Tz)
[114]180            tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value'));
[8]181        end
[114]182        uid_R=find(subt,'/GeometryCalib/R');
[8]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
[114]189       
[8]190        %look for laser plane definitions   
191        uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
[60]192        uid_Pos=find(subt,'/GeometryCalib/SliceCoord');
193        if isempty(uid_Pos)
194            uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention
195        end
[8]196        if ~isempty(uid_Angle)
197            tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
198        end
[60]199        if ~isempty(uid_Pos)     
[8]200            for j=1:length(uid_Pos)
201                tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
202            end
[60]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
[114]214                tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1];
[60]215            end         
[8]216        end
[109]217        if strcmp(option,'GeometryCalib')
218            tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);%time in TimeUnit
[116]219            size(tsai.PointCoord)
[109]220        end
[8]221        s.GeometryCalib=tsai;
222    end
223end   
224
225%--------------------------------------------------
226%  read an xml element
227function val=get_value(t,label,default)
228%--------------------------------------------------
229val=default;
230uid=find(t,label);%find the element iud(s)
[116]231if ~isempty(uid) %if the element named label exists
232   uid_child=children(t,uid);%find the children
[8]233   if ~isempty(uid_child)
[116]234       data=get(t,uid_child,'type');%get the type of child
235       if iscell(data)% case of multiple element
[8]236           for icell=1:numel(data)
237               val_read=str2num(get(t,uid_child(icell),'value'));
238               if ~isempty(val_read)
[109]239                   val(icell,:)=val_read;
[8]240               end
241           end
[116]242%           val=val';
243       else % case of unique element value
[8]244           val_read=str2num(get(t,uid_child,'value'));
245           if ~isempty(val_read)
246               val=val_read;
247           end
248       end
249   end
250end
Note: See TracBrowser for help on using the repository browser.