[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 | %------------------------------------------------------------- |
---|
[809] | 10 | |
---|
| 11 | %======================================================================= |
---|
[908] | 12 | % Copyright 2008-2015, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France |
---|
[809] | 13 | % http://www.legi.grenoble-inp.fr |
---|
| 14 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 15 | % |
---|
| 16 | % This file is part of the toolbox UVMAT. |
---|
| 17 | % |
---|
| 18 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 19 | % it under the terms of the GNU General Public License as published |
---|
| 20 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 21 | % or (at your option) any later version. |
---|
| 22 | % |
---|
| 23 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 24 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 25 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 26 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 27 | %======================================================================= |
---|
| 28 | |
---|
[630] | 29 | function errormsg=update_imadoc(Struct,outputfile,StructName) |
---|
[114] | 30 | errormsg=''; |
---|
[13] | 31 | testappend=0; |
---|
[498] | 32 | %% backup the output file if it already exist, and read it |
---|
| 33 | if exist(outputfile,'file');%=1 if the output file already exists, 0 else |
---|
[29] | 34 | testappend=1; |
---|
[17] | 35 | backupfile=outputfile; |
---|
| 36 | testexist=2; |
---|
| 37 | while testexist==2 |
---|
[498] | 38 | backupfile=[backupfile '~']; |
---|
| 39 | testexist=exist(backupfile,'file'); |
---|
[17] | 40 | end |
---|
| 41 | [success,message]=copyfile(outputfile,backupfile);%make backup |
---|
[498] | 42 | if success~=1 |
---|
| 43 | errormsg=['errror in xml file backup: ' message]; |
---|
| 44 | return |
---|
[114] | 45 | end |
---|
[498] | 46 | t=xmltree(outputfile); %read the file |
---|
| 47 | title=get(t,1,'name'); |
---|
[499] | 48 | if strcmp(title,'ImaDoc') |
---|
[498] | 49 | testappend=1; |
---|
| 50 | %if the xml file is ImaDoc |
---|
[630] | 51 | uid_calib=find(t,['ImaDoc/' StructName]); |
---|
| 52 | if isempty(uid_calib) %if Struct does not already exists, create it |
---|
| 53 | [t,uid_calib]=add(t,1,'element',StructName); |
---|
| 54 | else %if Struct already exists, delete its content |
---|
[498] | 55 | uid_child=children(t,uid_calib); |
---|
| 56 | t=delete(t,uid_child); |
---|
[13] | 57 | end |
---|
| 58 | end |
---|
| 59 | end |
---|
[498] | 60 | |
---|
| 61 | %% create a new xml file |
---|
[13] | 62 | if ~testappend |
---|
| 63 | t=xmltree; |
---|
| 64 | t=set(t,1,'name','ImaDoc'); |
---|
[84] | 65 | % in case of movie (avi file), copy timing info in the new xml file |
---|
[634] | 66 | [pp,outputroot]=fileparts(outputfile); |
---|
[414] | 67 | % imainfo=[]; |
---|
[634] | 68 | if exist(fullfile(pp,[outputroot '.avi']),'file') |
---|
| 69 | FileName=fullfile(pp,[outputroot '.avi']); |
---|
| 70 | hhh=which('videoreader'); |
---|
| 71 | if isempty(hhh)%use old video function of matlab |
---|
| 72 | imainfo=aviinfo(FileName); |
---|
| 73 | imainfo.FrameRate=imainfo.FramesPerSecond; |
---|
| 74 | imainfo.NumberOfFrames=imainfo.NumFrames; |
---|
| 75 | else %use video function videoreader of matlab |
---|
| 76 | imainfo=get(videoreader(FileName)); |
---|
| 77 | end |
---|
| 78 | if ~isempty(imainfo) |
---|
| 79 | [t,uid_camera]=add(t,1,'element','Camera'); |
---|
| 80 | Camera.TimeUnit='s'; |
---|
| 81 | Camera.BurstTiming.Time=0; |
---|
| 82 | Camera.BurstTiming.Dti=1/imainfo.FrameRate; |
---|
| 83 | Camera.BurstTiming.NbDti=imainfo.NumberOfFrames-1; |
---|
| 84 | t=struct2xml(Camera,t,uid_camera); |
---|
| 85 | end |
---|
| 86 | end |
---|
[630] | 87 | [t,uid_calib]=add(t,1,'element',StructName); |
---|
[13] | 88 | end |
---|
[498] | 89 | |
---|
| 90 | %% save the output file |
---|
[630] | 91 | t=struct2xml(Struct,t,uid_calib); |
---|
[745] | 92 | try |
---|
[13] | 93 | save(t,outputfile); |
---|
[745] | 94 | catch ME |
---|
| 95 | errormsg=['error in update_imadoc' ME.message]; |
---|
| 96 | end |
---|