[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 |
|
---|
[565] | 43 | if nargin ==1
|
---|
[685] | 44 | [s,Heading,errormsg]=xml2struct(ImaDoc);% convert the whole xml file in a structure s
|
---|
[565] | 45 | elseif nargin ==2
|
---|
[685] | 46 | [s,Heading,errormsg]=xml2struct(ImaDoc,varargin{1});% convert the xml file in a structure s, keeping only the subtree defined in input
|
---|
[565] | 47 | else %TODO: deal with more than two subtrees?
|
---|
[685] | 48 | [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] | 49 | end
|
---|
[685] | 50 | if ~isempty(errormsg)
|
---|
[687] | 51 | errormsg=['error in reading ImaDoc xml file: ' errormsg];
|
---|
[685] | 52 | return
|
---|
| 53 | end
|
---|
[560] | 54 | if ~strcmp(Heading,'ImaDoc')
|
---|
[685] | 55 | errormsg='imadoc2struct/the input xml file is not ImaDoc';
|
---|
[8] | 56 | return
|
---|
| 57 | end
|
---|
[560] | 58 | %% reading timing
|
---|
[565] | 59 | if isfield(s,'Camera')
|
---|
[675] | 60 | if isfield(s.Camera,'TimeUnit')
|
---|
| 61 | s.TimeUnit=s.Camera.TimeUnit;
|
---|
| 62 | end
|
---|
[1149] | 63 | if ~isfield(s.Camera,'FirstFrameIndexI')
|
---|
| 64 | s.Camera.FirstFrameIndexI=1; %first index assumed equl to 1 by default
|
---|
| 65 | end
|
---|
[1150] | 66 | s.Time=xmlburst2time(s.Camera.BurstTiming,s.Camera.FirstFrameIndexI);
|
---|
[8] | 67 | end
|
---|
| 68 |
|
---|
[1150] | 69 |
|
---|
[191] | 70 | function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest)
|
---|
| 71 | %--------------------------------------------------
|
---|
| 72 | s=[];%default
|
---|
| 73 | errormsg='';
|
---|
[207] | 74 | head_element=get(subt,1,'name');
|
---|
[191] | 75 | cont=get(subt,1,'contents');
|
---|
| 76 | if ~isempty(cont)
|
---|
| 77 | for ilist=1:length(Data)
|
---|
[207] | 78 | uid_key=find(subt,[head_element '/' Data{ilist}]);
|
---|
[191] | 79 | if ~isequal(length(uid_key),NbOccur(ilist))
|
---|
[207] | 80 | errormsg=['wrong number of occurence for ' Data{ilist}];
|
---|
[191] | 81 | return
|
---|
| 82 | end
|
---|
| 83 | for ival=1:length(uid_key)
|
---|
[207] | 84 | val=get(subt,children(subt,uid_key(ival)),'value');
|
---|
[191] | 85 | if ~NumTest(ilist)
|
---|
| 86 | eval(['s.' Data{ilist} '=val;']);
|
---|
| 87 | else
|
---|
| 88 | eval(['s.' Data{ilist} '=str2double(val);'])
|
---|
| 89 | end
|
---|
| 90 | end
|
---|
| 91 | end
|
---|
| 92 | end
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | %--------------------------------------------------
|
---|
[8] | 96 | % read an xml element
|
---|
| 97 | function val=get_value(t,label,default)
|
---|
| 98 | %--------------------------------------------------
|
---|
| 99 | val=default;
|
---|
| 100 | uid=find(t,label);%find the element iud(s)
|
---|
[116] | 101 | if ~isempty(uid) %if the element named label exists
|
---|
| 102 | uid_child=children(t,uid);%find the children
|
---|
[8] | 103 | if ~isempty(uid_child)
|
---|
[116] | 104 | data=get(t,uid_child,'type');%get the type of child
|
---|
| 105 | if iscell(data)% case of multiple element
|
---|
[8] | 106 | for icell=1:numel(data)
|
---|
| 107 | val_read=str2num(get(t,uid_child(icell),'value'));
|
---|
| 108 | if ~isempty(val_read)
|
---|
[109] | 109 | val(icell,:)=val_read;
|
---|
[8] | 110 | end
|
---|
| 111 | end
|
---|
[116] | 112 | % val=val';
|
---|
| 113 | else % case of unique element value
|
---|
[8] | 114 | val_read=str2num(get(t,uid_child,'value'));
|
---|
| 115 | if ~isempty(val_read)
|
---|
| 116 | val=val_read;
|
---|
[207] | 117 | else
|
---|
| 118 | val=get(t,uid_child,'value');%char string data
|
---|
[8] | 119 | end
|
---|
| 120 | end
|
---|
| 121 | end
|
---|
| 122 | end
|
---|
[456] | 123 |
|
---|
| 124 | %------------------------------------------------------------------------
|
---|
| 125 | %'read_imatext': reads the .civ file for image documentation (obsolete)
|
---|
| 126 | % fileinput: name of the documentation file
|
---|
| 127 | % time: matrix of times for the set of images
|
---|
| 128 | %pxcmx: scale along x in pixels/cm
|
---|
| 129 | %pxcmy: scale along y in pixels/cm
|
---|
| 130 | function [error,time,TimeUnit,mode,npx,npy,GeometryCalib]=read_imatext(fileinput)
|
---|
| 131 | %------------------------------------------------------------------------
|
---|
[460] | 132 | error='';%default
|
---|
[456] | 133 | time=[]; %default
|
---|
| 134 | TimeUnit='s';
|
---|
| 135 | mode='pairs';
|
---|
| 136 | npx=[]; %default
|
---|
| 137 | npy=[]; %default
|
---|
[460] | 138 | GeometryCalib=[];
|
---|
| 139 | if ~exist(fileinput,'file'), error=['image doc file ' fileinput ' does not exist']; return;end;%input file does not exist
|
---|
[456] | 140 | dotciv=textread(fileinput);
|
---|
| 141 | sizdot=size(dotciv);
|
---|
| 142 | if ~isequal(sizdot(1)-8,dotciv(1,1));
|
---|
| 143 | error=1; %inconsistent number of bursts
|
---|
| 144 | end
|
---|
| 145 | nbfield=sizdot(1)-8;
|
---|
| 146 | npx=(dotciv(2,1));
|
---|
| 147 | npy=(dotciv(2,2));
|
---|
| 148 | pxcmx=(dotciv(6,1));% pixels/cm in the .civ file
|
---|
| 149 | pxcmy=(dotciv(6,2));
|
---|
| 150 | % nburst=dotciv(3,1); % nbre of bursts
|
---|
| 151 | abs_time1=dotciv([9:nbfield+8],2);
|
---|
| 152 | dtime=dotciv(5,1)*(dotciv([9:nbfield+8],[3:end-1])+1);
|
---|
| 153 | timeshift=[abs_time1 dtime];
|
---|
| 154 | time=cumsum(timeshift,2);
|
---|
[559] | 155 | GeometryCalib.CalibrationType='rescale';
|
---|
[456] | 156 | GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
|
---|
| 157 | GeometryCalib.Tx=0;
|
---|
| 158 | GeometryCalib.Ty=0;
|
---|
| 159 | GeometryCalib.Tz=1;
|
---|
| 160 | GeometryCalib.dpx=1;
|
---|
| 161 | GeometryCalib.dpy=1;
|
---|
| 162 | GeometryCalib.sx=1;
|
---|
| 163 | GeometryCalib.Cx=0;
|
---|
| 164 | GeometryCalib.Cy=0;
|
---|
| 165 | GeometryCalib.f=1;
|
---|
| 166 | GeometryCalib.kappa1=0;
|
---|
[809] | 167 | GeometryCalib.CoordUnit='cm';
|
---|