[8] | 1 | %'imadoc2struct': reads the xml file for image documentation
|
---|
[89] | 2 | %------------------------------------------------------------------------
|
---|
[109] | 3 | % function [s,errormsg]=imadoc2struct(ImaDoc,option)
|
---|
[8] | 4 | %
|
---|
| 5 | % OUTPUT:
|
---|
| 6 | % s: structure representing ImaDoc
|
---|
| 7 | % s.Heading: information about the data hierarchical structure
|
---|
[611] | 8 | % s.Time: matrix of times, note that s.Time(i+1,j+1) is the time for file indices i and j (in order to deal with index 0)
|
---|
[8] | 9 | % s.TimeUnit
|
---|
| 10 | % s.GeometryCalib: substructure containing the parameters for geometric calibration
|
---|
| 11 | % errormsg: error message
|
---|
| 12 | %
|
---|
| 13 | % INPUT:
|
---|
| 14 | % ImaDoc: full name of the xml input file with head key ImaDoc
|
---|
[560] | 15 | % varargin: optional list of strings to restrict the reading to a selection of subtrees, for instance 'GeometryCalib' (save time)
|
---|
[89] | 16 |
|
---|
[809] | 17 | %=======================================================================
|
---|
[977] | 18 | % Copyright 2008-2017, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[809] | 19 | % http://www.legi.grenoble-inp.fr
|
---|
| 20 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
| 21 | %
|
---|
| 22 | % This file is part of the toolbox UVMAT.
|
---|
| 23 | %
|
---|
| 24 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 25 | % it under the terms of the GNU General Public License as published
|
---|
| 26 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 27 | % or (at your option) any later version.
|
---|
| 28 | %
|
---|
| 29 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 30 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 31 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 32 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 33 | %=======================================================================
|
---|
| 34 |
|
---|
[560] | 35 | function [s,errormsg]=imadoc2struct(ImaDoc,varargin)
|
---|
[156] | 36 | %% default input and output
|
---|
[565] | 37 | errormsg='';%default
|
---|
| 38 | s=[];
|
---|
| 39 | % s.Heading=[];%default
|
---|
| 40 | % s.Time=[]; %default
|
---|
| 41 | % s.TimeUnit=[]; %default
|
---|
| 42 | % s.GeometryCalib=[];
|
---|
[560] | 43 | % tsai=[];%default
|
---|
[8] | 44 |
|
---|
[156] | 45 | %% opening the xml file
|
---|
[456] | 46 | [tild,tild,FileExt]=fileparts(ImaDoc);
|
---|
[560] | 47 | %% case of .civ files (obsolete)
|
---|
[456] | 48 | if strcmp(FileExt,'.civ')
|
---|
[460] | 49 | [errormsg,time,TimeUnit,mode,npx,npy,s.GeometryCalib]=read_imatext(ImaDoc);
|
---|
[456] | 50 | return
|
---|
| 51 | end
|
---|
[560] | 52 |
|
---|
| 53 | %% case of xml files
|
---|
[565] | 54 | if nargin ==1
|
---|
[685] | 55 | [s,Heading,errormsg]=xml2struct(ImaDoc);% convert the whole xml file in a structure s
|
---|
[565] | 56 | elseif nargin ==2
|
---|
[685] | 57 | [s,Heading,errormsg]=xml2struct(ImaDoc,varargin{1});% convert the xml file in a structure s, keeping only the subtree defined in input
|
---|
[565] | 58 | else %TODO: deal with more than two subtrees?
|
---|
[685] | 59 | [s,Heading,errormsg]=xml2struct(ImaDoc,varargin{1},varargin{2});% convert the xml file in a structure s, keeping only the subtree defined in input
|
---|
[560] | 60 | end
|
---|
[685] | 61 | if ~isempty(errormsg)
|
---|
[687] | 62 | errormsg=['error in reading ImaDoc xml file: ' errormsg];
|
---|
[685] | 63 | return
|
---|
| 64 | end
|
---|
[560] | 65 | if ~strcmp(Heading,'ImaDoc')
|
---|
[685] | 66 | errormsg='imadoc2struct/the input xml file is not ImaDoc';
|
---|
[8] | 67 | return
|
---|
| 68 | end
|
---|
[560] | 69 | %% reading timing
|
---|
[565] | 70 | if isfield(s,'Camera')
|
---|
[675] | 71 | if isfield(s.Camera,'TimeUnit')
|
---|
| 72 | s.TimeUnit=s.Camera.TimeUnit;
|
---|
| 73 | end
|
---|
[565] | 74 | Timing=s.Camera.BurstTiming;
|
---|
| 75 | if ~iscell(Timing)
|
---|
| 76 | Timing={Timing};
|
---|
[8] | 77 | end
|
---|
[565] | 78 | s.Time=[];
|
---|
| 79 | for k=1:length(Timing)
|
---|
| 80 | Frequency=1;
|
---|
[582] | 81 | if isfield(Timing{k},'FrameFrequency')
|
---|
[565] | 82 | Frequency=Timing{k}.FrameFrequency;
|
---|
[8] | 83 | end
|
---|
[565] | 84 | Dtj=[];
|
---|
| 85 | if isfield(Timing{k},'Dtj')
|
---|
| 86 | Dtj=Timing{k}.Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's');
|
---|
| 87 | end
|
---|
| 88 | NbDtj=1;
|
---|
| 89 | if isfield(Timing{k},'NbDtj')&&~isempty(Timing{k}.NbDtj)
|
---|
| 90 | NbDtj=Timing{k}.NbDtj;
|
---|
| 91 | end
|
---|
| 92 | Dti=[];
|
---|
| 93 | if isfield(Timing{k},'Dti')
|
---|
| 94 | Dti=Timing{k}.Dti/Frequency;%Dti converted from frame unit to TimeUnit (e.g. 's');
|
---|
| 95 | end
|
---|
| 96 | NbDti=1;
|
---|
| 97 | if isfield(Timing{k},'NbDti')&&~isempty(Timing{k}.NbDti)
|
---|
| 98 | NbDti=Timing{k}.NbDti;
|
---|
| 99 | end
|
---|
| 100 | Time_val=Timing{k}.Time;%time in TimeUnit
|
---|
| 101 | if ~isempty(Dti)
|
---|
| 102 | Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
|
---|
| 103 | Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals Dti
|
---|
| 104 | end
|
---|
| 105 | if ~isempty(Dtj)
|
---|
| 106 | Dtj=reshape(Dtj'*ones(1,NbDtj),1,NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times
|
---|
| 107 | Dtj=[0 Dtj];
|
---|
| 108 | Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
|
---|
| 109 | end
|
---|
| 110 | % reading Dtk
|
---|
| 111 | Dtk=[];%default
|
---|
| 112 | NbDtk=1;%default
|
---|
[591] | 113 | if isfield(Timing{k},'Dtk')
|
---|
[565] | 114 | Dtk=Timing{k}.Dtk;
|
---|
| 115 | end
|
---|
[591] | 116 | if isfield(Timing{k},'NbDtk')&&~isempty(Timing{k}.NbDtk)
|
---|
[565] | 117 | NbDtk=Timing{k}.NbDtk;
|
---|
| 118 | end
|
---|
| 119 | if isempty(Dtk)
|
---|
| 120 | s.Time=[s.Time;Time_val];
|
---|
| 121 | else
|
---|
| 122 | for kblock=1:NbDtk+1
|
---|
| 123 | Time_val_k=Time_val+(kblock-1)*Dtk;
|
---|
| 124 | s.Time=[s.Time;Time_val_k];
|
---|
| 125 | end
|
---|
| 126 | end
|
---|
[8] | 127 | end
|
---|
[950] | 128 | if ~isfield(s.Camera,'FirstFrameIndexI')
|
---|
| 129 | s.Camera.FirstFrameIndexI=1; %first index qssumed equl to 1 by default
|
---|
| 130 | end
|
---|
[611] | 131 | s.Time=[zeros(size(s.Time,1),1) s.Time]; %insert a vertical line of zeros (to deal with zero file indices)
|
---|
[950] | 132 | if s.Camera.FirstFrameIndexI~=0
|
---|
| 133 | s.Time=[zeros(s.Camera.FirstFrameIndexI,size(s.Time,2)); s.Time]; %insert a horizontal line of zeros
|
---|
| 134 | end
|
---|
[8] | 135 | end
|
---|
| 136 |
|
---|
[191] | 137 | function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest)
|
---|
| 138 | %--------------------------------------------------
|
---|
| 139 | s=[];%default
|
---|
| 140 | errormsg='';
|
---|
[207] | 141 | head_element=get(subt,1,'name');
|
---|
[191] | 142 | cont=get(subt,1,'contents');
|
---|
| 143 | if ~isempty(cont)
|
---|
| 144 | for ilist=1:length(Data)
|
---|
[207] | 145 | uid_key=find(subt,[head_element '/' Data{ilist}]);
|
---|
[191] | 146 | if ~isequal(length(uid_key),NbOccur(ilist))
|
---|
[207] | 147 | errormsg=['wrong number of occurence for ' Data{ilist}];
|
---|
[191] | 148 | return
|
---|
| 149 | end
|
---|
| 150 | for ival=1:length(uid_key)
|
---|
[207] | 151 | val=get(subt,children(subt,uid_key(ival)),'value');
|
---|
[191] | 152 | if ~NumTest(ilist)
|
---|
| 153 | eval(['s.' Data{ilist} '=val;']);
|
---|
| 154 | else
|
---|
| 155 | eval(['s.' Data{ilist} '=str2double(val);'])
|
---|
| 156 | end
|
---|
| 157 | end
|
---|
| 158 | end
|
---|
| 159 | end
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 | %--------------------------------------------------
|
---|
[8] | 163 | % read an xml element
|
---|
| 164 | function val=get_value(t,label,default)
|
---|
| 165 | %--------------------------------------------------
|
---|
| 166 | val=default;
|
---|
| 167 | uid=find(t,label);%find the element iud(s)
|
---|
[116] | 168 | if ~isempty(uid) %if the element named label exists
|
---|
| 169 | uid_child=children(t,uid);%find the children
|
---|
[8] | 170 | if ~isempty(uid_child)
|
---|
[116] | 171 | data=get(t,uid_child,'type');%get the type of child
|
---|
| 172 | if iscell(data)% case of multiple element
|
---|
[8] | 173 | for icell=1:numel(data)
|
---|
| 174 | val_read=str2num(get(t,uid_child(icell),'value'));
|
---|
| 175 | if ~isempty(val_read)
|
---|
[109] | 176 | val(icell,:)=val_read;
|
---|
[8] | 177 | end
|
---|
| 178 | end
|
---|
[116] | 179 | % val=val';
|
---|
| 180 | else % case of unique element value
|
---|
[8] | 181 | val_read=str2num(get(t,uid_child,'value'));
|
---|
| 182 | if ~isempty(val_read)
|
---|
| 183 | val=val_read;
|
---|
[207] | 184 | else
|
---|
| 185 | val=get(t,uid_child,'value');%char string data
|
---|
[8] | 186 | end
|
---|
| 187 | end
|
---|
| 188 | end
|
---|
| 189 | end
|
---|
[456] | 190 |
|
---|
| 191 | %------------------------------------------------------------------------
|
---|
| 192 | %'read_imatext': reads the .civ file for image documentation (obsolete)
|
---|
| 193 | % fileinput: name of the documentation file
|
---|
| 194 | % time: matrix of times for the set of images
|
---|
| 195 | %pxcmx: scale along x in pixels/cm
|
---|
| 196 | %pxcmy: scale along y in pixels/cm
|
---|
| 197 | function [error,time,TimeUnit,mode,npx,npy,GeometryCalib]=read_imatext(fileinput)
|
---|
| 198 | %------------------------------------------------------------------------
|
---|
[460] | 199 | error='';%default
|
---|
[456] | 200 | time=[]; %default
|
---|
| 201 | TimeUnit='s';
|
---|
| 202 | mode='pairs';
|
---|
| 203 | npx=[]; %default
|
---|
| 204 | npy=[]; %default
|
---|
[460] | 205 | GeometryCalib=[];
|
---|
| 206 | if ~exist(fileinput,'file'), error=['image doc file ' fileinput ' does not exist']; return;end;%input file does not exist
|
---|
[456] | 207 | dotciv=textread(fileinput);
|
---|
| 208 | sizdot=size(dotciv);
|
---|
| 209 | if ~isequal(sizdot(1)-8,dotciv(1,1));
|
---|
| 210 | error=1; %inconsistent number of bursts
|
---|
| 211 | end
|
---|
| 212 | nbfield=sizdot(1)-8;
|
---|
| 213 | npx=(dotciv(2,1));
|
---|
| 214 | npy=(dotciv(2,2));
|
---|
| 215 | pxcmx=(dotciv(6,1));% pixels/cm in the .civ file
|
---|
| 216 | pxcmy=(dotciv(6,2));
|
---|
| 217 | % nburst=dotciv(3,1); % nbre of bursts
|
---|
| 218 | abs_time1=dotciv([9:nbfield+8],2);
|
---|
| 219 | dtime=dotciv(5,1)*(dotciv([9:nbfield+8],[3:end-1])+1);
|
---|
| 220 | timeshift=[abs_time1 dtime];
|
---|
| 221 | time=cumsum(timeshift,2);
|
---|
[559] | 222 | GeometryCalib.CalibrationType='rescale';
|
---|
[456] | 223 | GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
|
---|
| 224 | GeometryCalib.Tx=0;
|
---|
| 225 | GeometryCalib.Ty=0;
|
---|
| 226 | GeometryCalib.Tz=1;
|
---|
| 227 | GeometryCalib.dpx=1;
|
---|
| 228 | GeometryCalib.dpy=1;
|
---|
| 229 | GeometryCalib.sx=1;
|
---|
| 230 | GeometryCalib.Cx=0;
|
---|
| 231 | GeometryCalib.Cy=0;
|
---|
| 232 | GeometryCalib.f=1;
|
---|
| 233 | GeometryCalib.kappa1=0;
|
---|
[809] | 234 | GeometryCalib.CoordUnit='cm';
|
---|