[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) |
---|
| 10 | errormsg=''; |
---|
[13] | 11 | testappend=0; |
---|
[498] | 12 | %% backup the output file if it already exist, and read it |
---|
| 13 | if exist(outputfile,'file');%=1 if the output file already exists, 0 else |
---|
[29] | 14 | testappend=1; |
---|
[17] | 15 | backupfile=outputfile; |
---|
| 16 | testexist=2; |
---|
| 17 | while testexist==2 |
---|
[498] | 18 | backupfile=[backupfile '~']; |
---|
| 19 | testexist=exist(backupfile,'file'); |
---|
[17] | 20 | end |
---|
| 21 | [success,message]=copyfile(outputfile,backupfile);%make backup |
---|
[498] | 22 | if success~=1 |
---|
| 23 | errormsg=['errror in xml file backup: ' message]; |
---|
| 24 | return |
---|
[114] | 25 | end |
---|
[498] | 26 | t=xmltree(outputfile); %read the file |
---|
| 27 | title=get(t,1,'name'); |
---|
[499] | 28 | if strcmp(title,'ImaDoc') |
---|
[498] | 29 | testappend=1; |
---|
| 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 | uid_child=children(t,uid_calib); |
---|
| 36 | t=delete(t,uid_child); |
---|
[13] | 37 | end |
---|
| 38 | end |
---|
| 39 | end |
---|
[498] | 40 | |
---|
| 41 | %% create a new xml file |
---|
[13] | 42 | if ~testappend |
---|
| 43 | t=xmltree; |
---|
| 44 | t=set(t,1,'name','ImaDoc'); |
---|
[84] | 45 | % in case of movie (avi file), copy timing info in the new xml file |
---|
| 46 | [pp,outputroot]=fileparts(outputfile); |
---|
[414] | 47 | % imainfo=[]; |
---|
[84] | 48 | if exist(fullfile(pp,[outputroot '.avi']),'file') |
---|
[397] | 49 | FileName=fullfile(pp,[outputroot '.avi']); |
---|
| 50 | hhh=which('videoreader'); |
---|
| 51 | if isempty(hhh)%use old video function of matlab |
---|
| 52 | imainfo=aviinfo(FileName); |
---|
| 53 | imainfo.FrameRate=imainfo.FramesPerSecond; |
---|
| 54 | imainfo.NumberOfFrames=imainfo.NumFrames; |
---|
| 55 | else %use video function videoreader of matlab |
---|
| 56 | imainfo=get(videoreader(FileName)); |
---|
| 57 | end |
---|
| 58 | if ~isempty(imainfo) |
---|
| 59 | [t,uid_camera]=add(t,1,'element','Camera'); |
---|
| 60 | Camera.TimeUnit='s'; |
---|
| 61 | Camera.BurstTiming.Time=0; |
---|
| 62 | Camera.BurstTiming.Dti=1/imainfo.FrameRate; |
---|
| 63 | Camera.BurstTiming.NbDti=imainfo.NumberOfFrames-1; |
---|
| 64 | t=struct2xml(Camera,t,uid_camera); |
---|
| 65 | end |
---|
[84] | 66 | end |
---|
[414] | 67 | [t,uid_calib]=add(t,1,'element','GeometryCalib'); |
---|
[13] | 68 | end |
---|
[498] | 69 | |
---|
| 70 | %% save the output file |
---|
[13] | 71 | t=struct2xml(GeometryCalib,t,uid_calib); |
---|
| 72 | save(t,outputfile); |
---|