[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 | %=======================================================================
|
---|
[1126] | 18 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[809] | 19 | % http://www.legi.grenoble-inp.fr
|
---|
[1127] | 20 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
|
---|
[809] | 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=[];
|
---|
[8] | 39 |
|
---|
[156] | 40 | %% opening the xml file
|
---|
[456] | 41 | [tild,tild,FileExt]=fileparts(ImaDoc);
|
---|
[560] | 42 | %% case of .civ files (obsolete)
|
---|
[456] | 43 | if strcmp(FileExt,'.civ')
|
---|
[460] | 44 | [errormsg,time,TimeUnit,mode,npx,npy,s.GeometryCalib]=read_imatext(ImaDoc);
|
---|
[456] | 45 | return
|
---|
| 46 | end
|
---|
[560] | 47 |
|
---|
| 48 | %% case of xml files
|
---|
[565] | 49 | if nargin ==1
|
---|
[685] | 50 | [s,Heading,errormsg]=xml2struct(ImaDoc);% convert the whole xml file in a structure s
|
---|
[565] | 51 | elseif nargin ==2
|
---|
[685] | 52 | [s,Heading,errormsg]=xml2struct(ImaDoc,varargin{1});% convert the xml file in a structure s, keeping only the subtree defined in input
|
---|
[565] | 53 | else %TODO: deal with more than two subtrees?
|
---|
[685] | 54 | [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] | 55 | end
|
---|
[685] | 56 | if ~isempty(errormsg)
|
---|
[687] | 57 | errormsg=['error in reading ImaDoc xml file: ' errormsg];
|
---|
[685] | 58 | return
|
---|
| 59 | end
|
---|
[560] | 60 | if ~strcmp(Heading,'ImaDoc')
|
---|
[685] | 61 | errormsg='imadoc2struct/the input xml file is not ImaDoc';
|
---|
[8] | 62 | return
|
---|
| 63 | end
|
---|
[560] | 64 | %% reading timing
|
---|
[565] | 65 | if isfield(s,'Camera')
|
---|
[675] | 66 | if isfield(s.Camera,'TimeUnit')
|
---|
| 67 | s.TimeUnit=s.Camera.TimeUnit;
|
---|
| 68 | end
|
---|
[1149] | 69 | if ~isfield(s.Camera,'FirstFrameIndexI')
|
---|
| 70 | s.Camera.FirstFrameIndexI=1; %first index assumed equl to 1 by default
|
---|
| 71 | end
|
---|
[565] | 72 | Timing=s.Camera.BurstTiming;
|
---|
| 73 | if ~iscell(Timing)
|
---|
| 74 | Timing={Timing};
|
---|
[8] | 75 | end
|
---|
[1149] | 76 |
|
---|
[565] | 77 | s.Time=[];
|
---|
| 78 | for k=1:length(Timing)
|
---|
| 79 | Frequency=1;
|
---|
[582] | 80 | if isfield(Timing{k},'FrameFrequency')
|
---|
[565] | 81 | Frequency=Timing{k}.FrameFrequency;
|
---|
[8] | 82 | end
|
---|
[565] | 83 | Dtj=[];
|
---|
| 84 | if isfield(Timing{k},'Dtj')
|
---|
| 85 | Dtj=Timing{k}.Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's');
|
---|
| 86 | end
|
---|
| 87 | NbDtj=1;
|
---|
| 88 | if isfield(Timing{k},'NbDtj')&&~isempty(Timing{k}.NbDtj)
|
---|
| 89 | NbDtj=Timing{k}.NbDtj;
|
---|
| 90 | end
|
---|
| 91 | Dti=[];
|
---|
| 92 | if isfield(Timing{k},'Dti')
|
---|
| 93 | Dti=Timing{k}.Dti/Frequency;%Dti converted from frame unit to TimeUnit (e.g. 's');
|
---|
| 94 | end
|
---|
| 95 | NbDti=1;
|
---|
| 96 | if isfield(Timing{k},'NbDti')&&~isempty(Timing{k}.NbDti)
|
---|
| 97 | NbDti=Timing{k}.NbDti;
|
---|
| 98 | end
|
---|
| 99 | Time_val=Timing{k}.Time;%time in TimeUnit
|
---|
| 100 | if ~isempty(Dti)
|
---|
| 101 | Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
|
---|
| 102 | Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals Dti
|
---|
| 103 | end
|
---|
| 104 | if ~isempty(Dtj)
|
---|
| 105 | Dtj=reshape(Dtj'*ones(1,NbDtj),1,NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times
|
---|
| 106 | Dtj=[0 Dtj];
|
---|
| 107 | Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
|
---|
| 108 | end
|
---|
| 109 | % reading Dtk
|
---|
| 110 | Dtk=[];%default
|
---|
| 111 | NbDtk=1;%default
|
---|
[591] | 112 | if isfield(Timing{k},'Dtk')
|
---|
[565] | 113 | Dtk=Timing{k}.Dtk;
|
---|
| 114 | end
|
---|
[591] | 115 | if isfield(Timing{k},'NbDtk')&&~isempty(Timing{k}.NbDtk)
|
---|
[565] | 116 | NbDtk=Timing{k}.NbDtk;
|
---|
| 117 | end
|
---|
| 118 | if isempty(Dtk)
|
---|
| 119 | s.Time=[s.Time;Time_val];
|
---|
| 120 | else
|
---|
| 121 | for kblock=1:NbDtk+1
|
---|
| 122 | Time_val_k=Time_val+(kblock-1)*Dtk;
|
---|
| 123 | s.Time=[s.Time;Time_val_k];
|
---|
| 124 | end
|
---|
| 125 | end
|
---|
[8] | 126 | end
|
---|
[1149] | 127 |
|
---|
[611] | 128 | s.Time=[zeros(size(s.Time,1),1) s.Time]; %insert a vertical line of zeros (to deal with zero file indices)
|
---|
[950] | 129 | if s.Camera.FirstFrameIndexI~=0
|
---|
| 130 | s.Time=[zeros(s.Camera.FirstFrameIndexI,size(s.Time,2)); s.Time]; %insert a horizontal line of zeros
|
---|
| 131 | end
|
---|
[8] | 132 | end
|
---|
| 133 |
|
---|
[191] | 134 | function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest)
|
---|
| 135 | %--------------------------------------------------
|
---|
| 136 | s=[];%default
|
---|
| 137 | errormsg='';
|
---|
[207] | 138 | head_element=get(subt,1,'name');
|
---|
[191] | 139 | cont=get(subt,1,'contents');
|
---|
| 140 | if ~isempty(cont)
|
---|
| 141 | for ilist=1:length(Data)
|
---|
[207] | 142 | uid_key=find(subt,[head_element '/' Data{ilist}]);
|
---|
[191] | 143 | if ~isequal(length(uid_key),NbOccur(ilist))
|
---|
[207] | 144 | errormsg=['wrong number of occurence for ' Data{ilist}];
|
---|
[191] | 145 | return
|
---|
| 146 | end
|
---|
| 147 | for ival=1:length(uid_key)
|
---|
[207] | 148 | val=get(subt,children(subt,uid_key(ival)),'value');
|
---|
[191] | 149 | if ~NumTest(ilist)
|
---|
| 150 | eval(['s.' Data{ilist} '=val;']);
|
---|
| 151 | else
|
---|
| 152 | eval(['s.' Data{ilist} '=str2double(val);'])
|
---|
| 153 | end
|
---|
| 154 | end
|
---|
| 155 | end
|
---|
| 156 | end
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 | %--------------------------------------------------
|
---|
[8] | 160 | % read an xml element
|
---|
| 161 | function val=get_value(t,label,default)
|
---|
| 162 | %--------------------------------------------------
|
---|
| 163 | val=default;
|
---|
| 164 | uid=find(t,label);%find the element iud(s)
|
---|
[116] | 165 | if ~isempty(uid) %if the element named label exists
|
---|
| 166 | uid_child=children(t,uid);%find the children
|
---|
[8] | 167 | if ~isempty(uid_child)
|
---|
[116] | 168 | data=get(t,uid_child,'type');%get the type of child
|
---|
| 169 | if iscell(data)% case of multiple element
|
---|
[8] | 170 | for icell=1:numel(data)
|
---|
| 171 | val_read=str2num(get(t,uid_child(icell),'value'));
|
---|
| 172 | if ~isempty(val_read)
|
---|
[109] | 173 | val(icell,:)=val_read;
|
---|
[8] | 174 | end
|
---|
| 175 | end
|
---|
[116] | 176 | % val=val';
|
---|
| 177 | else % case of unique element value
|
---|
[8] | 178 | val_read=str2num(get(t,uid_child,'value'));
|
---|
| 179 | if ~isempty(val_read)
|
---|
| 180 | val=val_read;
|
---|
[207] | 181 | else
|
---|
| 182 | val=get(t,uid_child,'value');%char string data
|
---|
[8] | 183 | end
|
---|
| 184 | end
|
---|
| 185 | end
|
---|
| 186 | end
|
---|
[456] | 187 |
|
---|
| 188 | %------------------------------------------------------------------------
|
---|
| 189 | %'read_imatext': reads the .civ file for image documentation (obsolete)
|
---|
| 190 | % fileinput: name of the documentation file
|
---|
| 191 | % time: matrix of times for the set of images
|
---|
| 192 | %pxcmx: scale along x in pixels/cm
|
---|
| 193 | %pxcmy: scale along y in pixels/cm
|
---|
| 194 | function [error,time,TimeUnit,mode,npx,npy,GeometryCalib]=read_imatext(fileinput)
|
---|
| 195 | %------------------------------------------------------------------------
|
---|
[460] | 196 | error='';%default
|
---|
[456] | 197 | time=[]; %default
|
---|
| 198 | TimeUnit='s';
|
---|
| 199 | mode='pairs';
|
---|
| 200 | npx=[]; %default
|
---|
| 201 | npy=[]; %default
|
---|
[460] | 202 | GeometryCalib=[];
|
---|
| 203 | if ~exist(fileinput,'file'), error=['image doc file ' fileinput ' does not exist']; return;end;%input file does not exist
|
---|
[456] | 204 | dotciv=textread(fileinput);
|
---|
| 205 | sizdot=size(dotciv);
|
---|
| 206 | if ~isequal(sizdot(1)-8,dotciv(1,1));
|
---|
| 207 | error=1; %inconsistent number of bursts
|
---|
| 208 | end
|
---|
| 209 | nbfield=sizdot(1)-8;
|
---|
| 210 | npx=(dotciv(2,1));
|
---|
| 211 | npy=(dotciv(2,2));
|
---|
| 212 | pxcmx=(dotciv(6,1));% pixels/cm in the .civ file
|
---|
| 213 | pxcmy=(dotciv(6,2));
|
---|
| 214 | % nburst=dotciv(3,1); % nbre of bursts
|
---|
| 215 | abs_time1=dotciv([9:nbfield+8],2);
|
---|
| 216 | dtime=dotciv(5,1)*(dotciv([9:nbfield+8],[3:end-1])+1);
|
---|
| 217 | timeshift=[abs_time1 dtime];
|
---|
| 218 | time=cumsum(timeshift,2);
|
---|
[559] | 219 | GeometryCalib.CalibrationType='rescale';
|
---|
[456] | 220 | GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
|
---|
| 221 | GeometryCalib.Tx=0;
|
---|
| 222 | GeometryCalib.Ty=0;
|
---|
| 223 | GeometryCalib.Tz=1;
|
---|
| 224 | GeometryCalib.dpx=1;
|
---|
| 225 | GeometryCalib.dpy=1;
|
---|
| 226 | GeometryCalib.sx=1;
|
---|
| 227 | GeometryCalib.Cx=0;
|
---|
| 228 | GeometryCalib.Cy=0;
|
---|
| 229 | GeometryCalib.f=1;
|
---|
| 230 | GeometryCalib.kappa1=0;
|
---|
[809] | 231 | GeometryCalib.CoordUnit='cm';
|
---|