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