[13] | 1 | %'update_imadoc': update an xml file with geometric calibration parameters |
---|
| 2 | %-------------------------------------------------------------------------- |
---|
[630] | 3 | % function update_imadoc(Struct,outputfile) |
---|
[13] | 4 | % |
---|
| 5 | %INPUT: |
---|
[630] | 6 | % Struct: structure containing the calibration parameters |
---|
[13] | 7 | % outputfile: xml file to modify |
---|
[630] | 8 | % StructName : Name of the field in the xml file |
---|
[13] | 9 | %------------------------------------------------------------- |
---|
[630] | 10 | function errormsg=update_imadoc(Struct,outputfile,StructName) |
---|
[114] | 11 | errormsg=''; |
---|
[13] | 12 | testappend=0; |
---|
[498] | 13 | %% backup the output file if it already exist, and read it |
---|
| 14 | if exist(outputfile,'file');%=1 if the output file already exists, 0 else |
---|
[29] | 15 | testappend=1; |
---|
[17] | 16 | backupfile=outputfile; |
---|
| 17 | testexist=2; |
---|
| 18 | while testexist==2 |
---|
[498] | 19 | backupfile=[backupfile '~']; |
---|
| 20 | testexist=exist(backupfile,'file'); |
---|
[17] | 21 | end |
---|
| 22 | [success,message]=copyfile(outputfile,backupfile);%make backup |
---|
[498] | 23 | if success~=1 |
---|
| 24 | errormsg=['errror in xml file backup: ' message]; |
---|
| 25 | return |
---|
[114] | 26 | end |
---|
[498] | 27 | t=xmltree(outputfile); %read the file |
---|
| 28 | title=get(t,1,'name'); |
---|
[499] | 29 | if strcmp(title,'ImaDoc') |
---|
[498] | 30 | testappend=1; |
---|
| 31 | %if the xml file is ImaDoc |
---|
[630] | 32 | uid_calib=find(t,['ImaDoc/' StructName]); |
---|
| 33 | if isempty(uid_calib) %if Struct does not already exists, create it |
---|
| 34 | [t,uid_calib]=add(t,1,'element',StructName); |
---|
| 35 | else %if Struct already exists, delete its content |
---|
[498] | 36 | uid_child=children(t,uid_calib); |
---|
| 37 | t=delete(t,uid_child); |
---|
[13] | 38 | end |
---|
| 39 | end |
---|
| 40 | end |
---|
[498] | 41 | |
---|
| 42 | %% create a new xml file |
---|
[13] | 43 | if ~testappend |
---|
| 44 | t=xmltree; |
---|
| 45 | t=set(t,1,'name','ImaDoc'); |
---|
[84] | 46 | % in case of movie (avi file), copy timing info in the new xml file |
---|
[634] | 47 | [pp,outputroot]=fileparts(outputfile); |
---|
[414] | 48 | % imainfo=[]; |
---|
[634] | 49 | if exist(fullfile(pp,[outputroot '.avi']),'file') |
---|
| 50 | FileName=fullfile(pp,[outputroot '.avi']); |
---|
| 51 | hhh=which('videoreader'); |
---|
| 52 | if isempty(hhh)%use old video function of matlab |
---|
| 53 | imainfo=aviinfo(FileName); |
---|
| 54 | imainfo.FrameRate=imainfo.FramesPerSecond; |
---|
| 55 | imainfo.NumberOfFrames=imainfo.NumFrames; |
---|
| 56 | else %use video function videoreader of matlab |
---|
| 57 | imainfo=get(videoreader(FileName)); |
---|
| 58 | end |
---|
| 59 | if ~isempty(imainfo) |
---|
| 60 | [t,uid_camera]=add(t,1,'element','Camera'); |
---|
| 61 | Camera.TimeUnit='s'; |
---|
| 62 | Camera.BurstTiming.Time=0; |
---|
| 63 | Camera.BurstTiming.Dti=1/imainfo.FrameRate; |
---|
| 64 | Camera.BurstTiming.NbDti=imainfo.NumberOfFrames-1; |
---|
| 65 | t=struct2xml(Camera,t,uid_camera); |
---|
| 66 | end |
---|
| 67 | end |
---|
[630] | 68 | [t,uid_calib]=add(t,1,'element',StructName); |
---|
[13] | 69 | end |
---|
[498] | 70 | |
---|
| 71 | %% save the output file |
---|
[630] | 72 | t=struct2xml(Struct,t,uid_calib); |
---|
[745] | 73 | try |
---|
[13] | 74 | save(t,outputfile); |
---|
[745] | 75 | catch ME |
---|
| 76 | errormsg=['error in update_imadoc' ME.message]; |
---|
| 77 | end |
---|