source: trunk/src/series/extract_rdvision.m @ 810

Last change on this file since 810 was 810, checked in by g7moreau, 9 years ago
  • Add license
File size: 24.5 KB
Line 
1%'extract_rdvision': relabel an image series with two indices, and correct errors from the RDvision transfer program
2%------------------------------------------------------------------------
3% function ParamOut=extract_rdvision(Param)
4%------------------------------------------------------------------------
5%
6%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
7%
8%OUTPUT
9% ParamOut: sets options in the GUI series.fig needed for the function
10%
11%INPUT:
12% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
13% In batch mode, Param is the name of the corresponding xml file containing the same information
14% when Param.Action.RUN=0 (as activated when the current Action is selected
15% in series), the function ouput paramOut set the activation of the needed GUI elements
16%
17% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
18% see the current structure Param)
19%    .InputTable: cell of input file names, (several lines for multiple input)
20%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
21%    .OutputSubDir: name of the subdirectory for data outputs
22%    .OutputDirExt: directory extension for data outputs
23%    .Action: .ActionName: name of the current activated function
24%             .ActionPath:   path of the current activated function
25%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
26%             .RUN =0 for GUI input, =1 for function activation
27%             .RunMode='local','background', 'cluster': type of function  use
28%             
29%    .IndexRange: set the file or frame indices on which the action must be performed
30%    .FieldTransform: .TransformName: name of the selected transform function
31%                     .TransformPath:   path  of the selected transform function
32%    .InputFields: sub structure describing the input fields withfields
33%              .FieldName: name(s) of the field
34%              .VelType: velocity type
35%              .FieldName_1: name of the second field in case of two input series
36%              .VelType_1: velocity type of the second field in case of two input series
37%              .Coord_y: name of y coordinate variable
38%              .Coord_x: name of x coordinate variable
39%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41
42%=======================================================================
43% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
44%   http://www.legi.grenoble-inp.fr
45%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
46%
47%     This file is part of the toolbox UVMAT.
48%
49%     UVMAT is free software; you can redistribute it and/or modify
50%     it under the terms of the GNU General Public License as published
51%     by the Free Software Foundation; either version 2 of the license,
52%     or (at your option) any later version.
53%
54%     UVMAT is distributed in the hope that it will be useful,
55%     but WITHOUT ANY WARRANTY; without even the implied warranty of
56%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57%     GNU General Public License (see LICENSE.txt) for more details.
58%=======================================================================
59
60function ParamOut=extract_rdvision(Param) %default output=relabel_i_j(Param)
61
62%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
63if isstruct(Param) && isequal(Param.Action.RUN,0)
64    ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
65    ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
66    ParamOut.NbSlice='one'; ...%nbre of slices, 'one' prevents splitting in several processes, ('off' by default)
67    ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
68    ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
69    ParamOut.FieldTransform = 'off';...%can use a transform function
70    ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
71    ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
72    ParamOut.OutputSubDir=Param.InputTable{1,3};
73    ParamOut.OutputDirExt='';%set the output dir extension
74    if size(Param.InputTable,1)>1
75        msgbox_uvmat('WARNING', 'this function acts only on the first input file line')
76    end
77return
78end
79
80ParamOut=[];
81%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
82%% read input parameters from an xml file if input is a file name (batch mode)
83checkrun=1;
84if ischar(Param)
85    Param=xml2struct(Param);% read Param as input file (batch case)
86    checkrun=0;
87end
88hseries=findobj(allchild(0),'Tag','series');
89RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
90WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
91
92%% root input file(s) and type
93RootPath=Param.InputTable(:,1);
94RootFile=Param.InputTable(:,3);
95SubDir=Param.InputTable(:,2);
96FileExt=Param.InputTable(:,5);
97
98% get the set of input file names (cell array filecell), and the lists of
99% input file or frame indices i1_series,i2_series,j1_series,j2_series
100[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
101filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'*',1);
102OutputDir=[Param.OutputSubDir Param.OutputDirExt];
103 
104% numbers of slices and file indices
105nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
106nbfield_i=size(i1_series{1},2); %nb of fields for the i index
107nbfield=nbfield_j*nbfield_i; %total number of fields
108
109%determine the file type on each line from the first input file
110% if ~exist(filecell{1,1}','file')
111%     msgbox_uvmat('ERROR',['the first input file ' filecell{1,1} ' does not exist'])
112%     return
113% end
114FileInfo=get_file_info(filecell{1,1});
115if ~strcmp(FileInfo.FileType,'rdvision')
116    msgbox_uvmat('ERROR','the input is not from rdvision: a .seq or .sqb file must be opened')
117    return
118end
119
120%% calibration data and timing: read the ImaDoc files
121mode=''; %default
122timecell={};
123itime=0;
124NbSlice_calib={};
125
126SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
127filexml=[fullfile(RootPath{1},RootFile{1}) '.xml'];%new convention: xml at the level of the image folder
128if ~exist(filexml,'file')
129    disp_uvmat('ERROR',[filexml ' missing'],checkrun)
130    return
131end
132[XmlData,error]=imadoc2struct_special(filexml);
133if isfield(XmlData,'Time')
134    itime=itime+1;
135    timecell{itime}=XmlData.Time;
136end
137if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
138    NbSlice_calib{1}=size(XmlData.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
139    if ~isequal(NbSlice_calib{1},NbSlice_calib{1})
140        msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
141    end
142end
143
144
145%% check coincidence in time for several input file series
146% not relevant
147
148%% coordinate transform or other user defined transform
149%not relevant
150%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
151 % EDIT FROM HERE
152
153
154%% Set field names and velocity types
155% not relevant here
156
157%% Initiate output fields
158% not relevant here
159
160%% interactive input of specific parameters (for RDvision system)
161display('RDvision system')
162first_label=0; %image numbers start from 0
163
164%% correction to RDvision xml file
165t=xmltree(filexml);
166
167% correct Dtj and Dtk
168NomTypeNew='_1_1';% new file nomencalture by default
169ImageName='img_1_1.png';% first image name
170if isfield(XmlData,'NbDtj')
171    uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
172    uid_value=children(t,uid_NbDtj);
173    if ~isempty(uid_value)
174        t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
175    end
176end
177if isfield(XmlData,'NbDtk')
178    uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
179    uid_value=children(t,uid_NbDtk);
180    if ~isempty(uid_value)
181        t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
182    end
183end
184if isempty(j1_series{1}) && isfield(XmlData,'NbDti')
185    uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
186    t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
187    uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
188    t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
189    uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
190    uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
191    t=delete(t,uid_NbDtj);
192    t=delete(t,uid_NbDtk);
193    uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
194    uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
195    t=delete(t,uid_Dtj);
196    t=delete(t,uid_Dtk);
197    NomTypeNew='_1';
198    ImageName='img_1.png';
199end
200
201%update information of 'Heading'
202uid_Heading=find(t,'ImaDoc/Heading');
203if isempty(uid_Heading)
204    [t,uid_Heading]=add(t,1,'element','Heading');
205end
206uid_SubCampaign=find(t,'ImaDoc/Heading/SubCampaign');
207if ~isempty(uid_SubCampaign), t=delete(t,uid_SubCampaign); end
208uid_Experiment=find(t,'ImaDoc/Heading/Experiment');
209if ~isempty(uid_Experiment), t=delete(t,uid_Experiment); end
210uid_Device=find(t,'ImaDoc/Heading/Device');
211if ~isempty(uid_Device), t=delete(t,uid_Device); end
212uid_Record=find(t,'ImaDoc/Heading/Record');
213if ~isempty(uid_Record), t=delete(t,uid_Record); end
214uid_DateExp=find(t,'ImaDoc/Heading/DateExp');
215if ~isempty(uid_DateExp), t=delete(t,uid_DateExp); end
216
217%indicate the name of the first image (as a check that the xml file is not moved)
218uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
219if isempty(uid_ImageName)
220    [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
221end
222uid_value=children(t,uid_ImageName);
223if isempty(uid_value)
224    t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
225else
226    t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
227end
228
229%indicate the date and time of the image acquisition start
230if isfield(FileInfo,'binrepertoire') && isfield(FileInfo,'starttime')
231    sep_pos=regexp(FileInfo.binrepertoire,'T');
232    DateTime=FileInfo.starttime;
233    if ~isempty(sep_pos)
234        DateTime=[FileInfo.binrepertoire(1:sep_pos-1) ' ' DateTime];
235    end
236    uid_DateTime=find(t,'ImaDoc/Heading/DateTime');
237    if isempty(uid_DateTime)
238        [t,uid_DateTime]=add(t,uid_Heading,'element','DateTime');
239    end
240    uid_value=children(t,uid_DateTime);
241    if isempty(uid_value)
242        t=add(t,uid_DateTime,'chardata',DateTime);%indicate  name of the first image, with ;png extension
243    else
244        t=set(t,uid_value(1),'value',DateTime);%indicate  name of the first image, with ;png extension
245    end
246end
247 
248%% backup the previous xml file and save the corrected one
249[success,message]=copyfile(filexml,[filexml '~']);%make backup
250if success~=1
251    dips(['errror in xml file backup: ' message]);
252    return
253end
254save(t,filexml)
255
256%% main loop on images
257nbfield2=1;
258if isfield(XmlData,'Time')
259nbfield2=size(XmlData.Time,2);
260end
261for ifile=1:nbfield
262            update_waitbar(WaitbarHandle,ifile/nbfield)
263    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
264        disp('program stopped by user')
265        break
266    end
267    [A,FileInfo,timestamps]=read_rdvision(filename,ifile);
268    if ifile==1
269        classA=class(A);
270        if strcmp(classA,'uint8')
271            BitDepth=8;
272        else
273        BitDepth=16;
274        end
275    end
276    j1=[];
277    if ~isequal(nbfield2,1)
278    j1=mod(ifile-1+first_label,nbfield2)+1;
279    end
280    i1=floor((ifile-1+first_label)/nbfield2)+1;
281    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,'img','.png',NomTypeNew,i1,[],j1);
282    try
283        imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
284    disp([OutputFile ' written']);
285        [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
286        if ~s
287            disp_uvmat('ERROR',errormsg,checkrun);
288            return
289        end
290    catch ME
291        disp_uvmat('ERROR',ME.message,checkrun);
292        return
293    end
294   
295end
296
297%'imadoc2struct_special': reads the xml file for image documentation
298%------------------------------------------------------------------------
299% function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
300%
301% OUTPUT:
302% s: structure representing ImaDoc
303%   s.Heading: information about the data hierarchical structure
304%   s.Time: matrix of times
305%   s.TimeUnit
306%  s.GeometryCalib: substructure containing the parameters for geometric calibration
307% errormsg: error message
308%
309% INPUT:
310% ImaDoc: full name of the xml input file with head key ImaDoc
311% option: ='GeometryCalib': read  the data of GeometryCalib, including source point coordinates
312
313function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
314
315%% default input and output
316if ~exist('option','var')
317    option='*';
318end
319errormsg=[];%default
320s.Heading=[];%default
321s.Time=[]; %default
322s.TimeUnit=[]; %default
323s.GeometryCalib=[];
324tsai=[];%default
325
326%% opening the xml file
327if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist
328try
329    t=xmltree(ImaDoc);
330catch
331    errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
332    display(errormsg);
333    return
334end
335uid_root=find(t,'/ImaDoc');
336if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file
337
338
339%% Heading
340uid_Heading=find(t,'/ImaDoc/Heading');
341if ~isempty(uid_Heading),
342    uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
343    uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
344    uid_Device=find(t,'/ImaDoc/Heading/Device');
345    uid_Record=find(t,'/ImaDoc/Heading/Record');
346    uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
347    s.Heading.Campaign=get(t,children(t,uid_Campaign),'value');
348    s.Heading.Experiment=get(t,children(t,uid_Exp),'value');
349    s.Heading.Device=get(t,children(t,uid_Device),'value');
350    if ~isempty(uid_Record)
351        s.Heading.Record=get(t,children(t,uid_Record),'value');
352    end
353    s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
354end
355
356%% Camera  and timing
357if strcmp(option,'*') || strcmp(option,'Camera')
358    uid_Camera=find(t,'/ImaDoc/Camera');
359    if ~isempty(uid_Camera)
360        uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
361        if ~isempty(uid_ImageSize);
362            ImageSize=get(t,children(t,uid_ImageSize),'value');
363            xindex=findstr(ImageSize,'x');
364            if length(xindex)>=2
365                s.Npx=str2double(ImageSize(1:xindex(1)-1));
366                s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1));
367            end
368        end
369        uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
370        if ~isempty(uid_TimeUnit)
371            s.TimeUnit=get(t,children(t,uid_TimeUnit),'value');
372        end
373        uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
374        if ~isempty(uid_BurstTiming)
375            for k=1:length(uid_BurstTiming)
376                subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
377                % reading Dtk
378                Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1);
379                Dtj=get_value(subt,'/BurstTiming/Dtj',[]);
380                Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
381                NbDtj=get_value(subt,'/BurstTiming/NbDtj',[]);
382                %%%% correction RDvision %%%%
383%                 NbDtj=NbDtj/numel(Dtj);
384%                 s.NbDtj=NbDtj;
385%                 %%%%
386                Dti=get_value(subt,'/BurstTiming/Dti',[]);
387                NbDti=get_value(subt,'/BurstTiming/NbDti',1);
388                 %%%% correction RDvision %%%%
389                if isempty(Dti)% series
390                     Dti=Dtj;
391                      NbDti=NbDtj;
392                     Dtj=[];
393                     s.Dti=Dti;
394                     s.NbDti=NbDti;
395                else
396                    % NbDtj=NbDtj/numel(Dtj);%bursts
397                    if ~isempty(NbDtj)
398                    s.NbDtj=NbDtj/numel(Dtj);%bursts;
399                    else
400                        s.NbDtj=1;
401                    end
402                end
403                %%%% %%%%
404                Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
405
406                Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit
407                if ~isempty(Dti)
408                    Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
409                    Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals  Dti
410                end
411                if ~isempty(Dtj)
412                    Dtj=reshape(Dtj'*ones(1,s.NbDtj),1,s.NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times
413                    Dtj=[0 Dtj];
414                    Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
415                end
416                % reading Dtk
417                Dtk=get_value(subt,'/BurstTiming/Dtk',[]);
418                NbDtk=get_value(subt,'/BurstTiming/NbDtk',1);
419                %%%% correction RDvision %%%%
420                if ~isequal(NbDtk,1)
421                    NbDtk=-1+(NbDtk+1)/(NbDti+1);
422                end
423                s.NbDtk=NbDtk;
424                %%%%%
425                if isempty(Dtk)
426                    s.Time=[s.Time;Time_val];
427                else
428                    for kblock=1:NbDtk+1
429                        Time_val_k=Time_val+(kblock-1)*Dtk;
430                        s.Time=[s.Time;Time_val_k];
431                    end
432                end
433            end
434        end
435    end
436end
437
438%% motor
439if strcmp(option,'*') || strcmp(option,'GeometryCalib')
440    uid_subtree=find(t,'/ImaDoc/TranslationMotor');
441    if length(uid_subtree)==1
442        subt=branch(t,uid_subtree);%subtree under GeometryCalib
443       [s.TranslationMotor,errormsg]=read_subtree(subt,{'Nbslice','ZStart','ZEnd'},[1 1 1],[1 1 1]);
444    end
445end
446%%  geometric calibration
447if strcmp(option,'*') || strcmp(option,'GeometryCalib')
448    uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
449    if ~isempty(uid_GeometryCalib)
450        if length(uid_GeometryCalib)>1
451            errormsg=['More than one GeometryCalib in ' filecivxml];
452            return
453        end
454        subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
455        cont=get(subt,1,'contents');
456        if ~isempty(cont)
457            uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType');
458            if isequal(length(uid_CalibrationType),1)
459                tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value');
460            end
461            uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
462            if isequal(length(uid_CoordUnit),1)
463                tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
464            end
465            uid_fx_fy=find(subt,'/GeometryCalib/fx_fy');
466            focal=[];%default fro old convention (Reg Wilson)
467            if isequal(length(uid_fx_fy),1)
468                tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value'));
469            else %old convention (Reg Wilson)
470                uid_focal=find(subt,'/GeometryCalib/focal');
471                uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
472                uid_sx=find(subt,'/GeometryCalib/sx');
473                if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx)
474                    dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
475                    sx=str2num(get(subt,children(subt,uid_sx),'value'));
476                    focal=str2num(get(subt,children(subt,uid_focal),'value'));
477                    tsai.fx_fy(1)=sx*focal/dpx_dpy(1);
478                    tsai.fx_fy(2)=focal/dpx_dpy(2);
479                end
480            end
481            uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
482            if ~isempty(uid_Cx_Cy)
483                tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
484            end
485            uid_kc=find(subt,'/GeometryCalib/kc');
486            if ~isempty(uid_kc)
487                tsai.kc=str2double(get(subt,children(subt,uid_kc),'value'));
488            else %old convention (Reg Wilson)
489                uid_kappa1=find(subt,'/GeometryCalib/kappa1');
490                if ~isempty(uid_kappa1)&& ~isempty(focal)
491                    kappa1=str2double(get(subt,children(subt,uid_kappa1),'value'));
492                    tsai.kc=-kappa1*focal*focal;
493                end
494            end
495            uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
496            if ~isempty(uid_Tx_Ty_Tz)
497                tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value'));
498            end
499            uid_R=find(subt,'/GeometryCalib/R');
500            if ~isempty(uid_R)
501                RR=get(subt,children(subt,uid_R),'value');
502                if length(RR)==3
503                    tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
504                end
505            end
506           
507            %look for laser plane definitions
508            uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
509            uid_Pos=find(subt,'/GeometryCalib/SliceCoord');
510            if isempty(uid_Pos)
511                uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention
512            end
513            if ~isempty(uid_Angle)
514                tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
515            end
516            if ~isempty(uid_Pos)
517                for j=1:length(uid_Pos)
518                    tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
519                end
520                uid_DZ=find(subt,'/GeometryCalib/SliceDZ');
521                uid_NbSlice=find(subt,'/GeometryCalib/NbSlice');
522                if ~isempty(uid_DZ) && ~isempty(uid_NbSlice)
523                    DZ=str2double(get(subt,children(subt,uid_DZ),'value'));
524                    NbSlice=get(subt,children(subt,uid_NbSlice),'value');
525                    if isequal(NbSlice,'volume')
526                        tsai.NbSlice='volume';
527                        NbSlice=NbDtj+1;
528                    else
529                        tsai.NbSlice=str2double(NbSlice);
530                    end
531                    tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1];
532                end
533            end   
534            tsai.SliceAngle=get_value(subt,'/GeometryCalib/SliceAngle',[0 0 0]);
535            tsai.VolumeScan=get_value(subt,'/GeometryCalib/VolumeScan','n');
536            tsai.InterfaceCoord=get_value(subt,'/GeometryCalib/InterfaceCoord',[0 0 0]);
537            tsai.RefractionIndex=get_value(subt,'/GeometryCalib/RefractionIndex',1);
538           
539            if strcmp(option,'GeometryCalib')
540                tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);
541            end
542            s.GeometryCalib=tsai;
543        end
544    end
545end
546
547%--------------------------------------------------
548%  read a subtree
549% INPUT:
550% t: xltree
551% head_element: head elelemnt of the subtree
552% Data, structure containing
553%    .Key: element name
554%    .Type: type of element ('charg', 'float'....)
555%    .NbOccur: nbre of occurrence, NaN for un specified number
556function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest)
557%--------------------------------------------------
558s=[];%default
559errormsg='';
560head_element=get(subt,1,'name');
561    cont=get(subt,1,'contents');
562    if ~isempty(cont)
563        for ilist=1:length(Data)
564            uid_key=find(subt,[head_element '/' Data{ilist}]);
565            if ~isequal(length(uid_key),NbOccur(ilist))
566                errormsg=['wrong number of occurence for ' Data{ilist}];
567                return
568            end
569            for ival=1:length(uid_key)
570                val=get(subt,children(subt,uid_key(ival)),'value');
571                if ~NumTest(ilist)
572                    eval(['s.' Data{ilist} '=val;']);
573                else
574                    eval(['s.' Data{ilist} '=str2double(val);'])
575                end
576            end
577        end
578    end
579
580
581%--------------------------------------------------
582%  read an xml element
583function val=get_value(t,label,default)
584%--------------------------------------------------
585val=default;
586uid=find(t,label);%find the element iud(s)
587if ~isempty(uid) %if the element named label exists
588   uid_child=children(t,uid);%find the children
589   if ~isempty(uid_child)
590       data=get(t,uid_child,'type');%get the type of child
591       if iscell(data)% case of multiple element
592           for icell=1:numel(data)
593               val_read=str2num(get(t,uid_child(icell),'value'));
594               if ~isempty(val_read)
595                   val(icell,:)=val_read;
596               end
597           end
598%           val=val';
599       else % case of unique element value
600           val_read=str2num(get(t,uid_child,'value'));
601           if ~isempty(val_read)
602               val=val_read;
603           else
604              val=get(t,uid_child,'value');%char string data
605           end
606       end
607   end
608end
Note: See TracBrowser for help on using the repository browser.