source: trunk/src/imadoc2struct.m @ 1179

Last change on this file since 1179 was 1178, checked in by sommeria, 4 weeks ago

virtual frame indexing introduced

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