source: trunk/src/imadoc2struct.m @ 71

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

civ3D updated: introduction of image size
imadoc2struct: reding of image size from the xml file
set_object, view_field and related functions: improvement of projection object editing
mouse: possibility of adjusting the calibrations points with the mouse

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