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