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