[13] | 1 | %'update_imadoc': update an xml file with geometric calibration parameters |
---|
| 2 | %-------------------------------------------------------------------------- |
---|
| 3 | % function update_imadoc(GeometryCalib,outputfile) |
---|
| 4 | % |
---|
| 5 | %INPUT: |
---|
| 6 | % GeometryCalib: structure containing the calibration parameters |
---|
| 7 | % outputfile: xml file to modify |
---|
| 8 | %------------------------------------------------------------- |
---|
| 9 | function update_imadoc(GeometryCalib,outputfile) |
---|
| 10 | testappend=0; |
---|
| 11 | if exist(outputfile,'file');%=1 if the output file already exists, 0 else |
---|
[29] | 12 | testappend=1; |
---|
[13] | 13 | t=xmltree(outputfile); %read the file |
---|
[17] | 14 | backupfile=outputfile; |
---|
| 15 | testexist=2; |
---|
| 16 | while testexist==2 |
---|
| 17 | backupfile=[backupfile '~']; |
---|
| 18 | testexist=exist(backupfile,'file'); |
---|
| 19 | end |
---|
| 20 | [success,message]=copyfile(outputfile,backupfile);%make backup |
---|
[13] | 21 | uid=find(t,'ImaDoc'); |
---|
| 22 | if ~isequal(uid,1) |
---|
| 23 | return |
---|
| 24 | end |
---|
| 25 | |
---|
| 26 | %if the xml file is ImaDoc |
---|
| 27 | uid_calib=find(t,'ImaDoc/GeometryCalib'); |
---|
| 28 | if isempty(uid_calib) %if GeometryCalib does not already exists, create it |
---|
| 29 | [t,uid_calib]=add(t,1,'element','GeometryCalib'); |
---|
| 30 | else %if GeometryCalib already exists, delete its content |
---|
| 31 | if isequal(success,1) |
---|
| 32 | delete(outputfile) |
---|
| 33 | else |
---|
| 34 | return |
---|
| 35 | end |
---|
| 36 | uid_child=children(t,uid_calib); |
---|
| 37 | t=delete(t,uid_child); |
---|
| 38 | end |
---|
| 39 | end |
---|
[84] | 40 | %create a new xml file |
---|
[13] | 41 | if ~testappend |
---|
| 42 | t=xmltree; |
---|
| 43 | t=set(t,1,'name','ImaDoc'); |
---|
[84] | 44 | % in case of movie (avi file), copy timing info in the new xml file |
---|
| 45 | [pp,outputroot]=fileparts(outputfile); |
---|
| 46 | info=[]; |
---|
| 47 | if exist(fullfile(pp,[outputroot '.avi']),'file') |
---|
| 48 | info=aviinfo(fullfile(pp,[outputroot '.avi'])); |
---|
| 49 | elseif exist(fullfile(pp,[outputroot '.AVI']),'file') |
---|
| 50 | info=fullfile(pp,[outputroot '.AVI']); |
---|
| 51 | end |
---|
| 52 | if ~isempty(info) |
---|
| 53 | [t,uid_camera]=add(t,1,'element','Camera'); |
---|
| 54 | Camera.TimeUnit='s'; |
---|
| 55 | % Camera.BurstTiming.FrameFrequency=info.FramesPerSecond; |
---|
| 56 | Camera.BurstTiming.Time=0; |
---|
| 57 | Camera.BurstTiming.Dti=1/info.FramesPerSecond; |
---|
| 58 | Camera.BurstTiming.NbDti=info.NumFrames-1; |
---|
| 59 | t=struct2xml(Camera,t,uid_camera) |
---|
| 60 | end |
---|
| 61 | [t,uid_calib]=add(t,1,'element','GeometryCalib'); |
---|
[13] | 62 | end |
---|
| 63 | t=struct2xml(GeometryCalib,t,uid_calib); |
---|
| 64 | save(t,outputfile); |
---|