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

Last change on this file since 824 was 824, checked in by sommeria, 9 years ago

message

File size: 24.7 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
119if exist(fullfile(RootPath{1},OutputDir),'dir')
120     msgbox_uvmat('ERROR',['output folder ' OutputDir ' already exists, put data in a new folder Experiment']);
121     return
122end
123
124%% calibration data and timing: read the ImaDoc files
125mode=''; %default
126timecell={};
127itime=0;
128NbSlice_calib={};
129
130SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
131filexml=[fullfile(RootPath{1},RootFile{1}) '.xml'];%new convention: xml at the level of the image folder
132if ~exist(filexml,'file')
133    disp_uvmat('ERROR',[filexml ' missing'],checkrun)
134    return
135end
136[XmlData,error]=imadoc2struct_special(filexml);
137if isfield(XmlData,'Time')
138    itime=itime+1;
139    timecell{itime}=XmlData.Time;
140end
141if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
142    NbSlice_calib{1}=size(XmlData.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
143    if ~isequal(NbSlice_calib{1},NbSlice_calib{1})
144        msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
145    end
146end
147
148
149%% check coincidence in time for several input file series
150% not relevant
151
152%% coordinate transform or other user defined transform
153%not relevant
154%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
155 % EDIT FROM HERE
156
157
158%% Set field names and velocity types
159% not relevant here
160
161%% Initiate output fields
162% not relevant here
163
164%% interactive input of specific parameters (for RDvision system)
165display('RDvision system')
166first_label=0; %image numbers start from 0
167
168%% correction to RDvision xml file
169t=xmltree(filexml);
170
171% correct Dtj and Dtk
172NomTypeNew='_1_1';% new file nomencalture by default
173ImageName='img_1_1.png';% first image name
174if isfield(XmlData,'NbDtj')
175    uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
176    uid_value=children(t,uid_NbDtj);
177    if ~isempty(uid_value)
178        t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
179    end
180end
181if isfield(XmlData,'NbDtk')
182    uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
183    uid_value=children(t,uid_NbDtk);
184    if ~isempty(uid_value)
185        t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
186    end
187end
188if isempty(j1_series{1}) && isfield(XmlData,'NbDti')
189    uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
190    t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
191    uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
192    t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
193    uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
194    uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
195    t=delete(t,uid_NbDtj);
196    t=delete(t,uid_NbDtk);
197    uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
198    uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
199    t=delete(t,uid_Dtj);
200    t=delete(t,uid_Dtk);
201    NomTypeNew='_1';
202    ImageName='img_1.png';
203end
204 
205%update information of 'Heading'
206uid_Heading=find(t,'ImaDoc/Heading');
207if isempty(uid_Heading)
208    [t,uid_Heading]=add(t,1,'element','Heading');
209end
210uid_SubCampaign=find(t,'ImaDoc/Heading/SubCampaign');
211if ~isempty(uid_SubCampaign), t=delete(t,uid_SubCampaign); end
212uid_Experiment=find(t,'ImaDoc/Heading/Experiment');
213if ~isempty(uid_Experiment), t=delete(t,uid_Experiment); end
214uid_Device=find(t,'ImaDoc/Heading/Device');
215if ~isempty(uid_Device), t=delete(t,uid_Device); end
216uid_Record=find(t,'ImaDoc/Heading/Record');
217if ~isempty(uid_Record), t=delete(t,uid_Record); end
218uid_DateExp=find(t,'ImaDoc/Heading/DateExp');
219if ~isempty(uid_DateExp), t=delete(t,uid_DateExp); end
220
221%indicate the name of the first image (as a check that the xml file is not moved)
222uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
223if isempty(uid_ImageName)
224    [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
225end
226uid_value=children(t,uid_ImageName);
227if isempty(uid_value)
228    t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
229else
230    t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
231end
232
233%indicate the date and time of the image acquisition start
234if isfield(FileInfo,'binrepertoire') && isfield(FileInfo,'starttime')
235    sep_pos=regexp(FileInfo.binrepertoire,'T');
236    DateTime=FileInfo.starttime;
237    if ~isempty(sep_pos)
238        DateTime=[FileInfo.binrepertoire(1:sep_pos-1) ' ' DateTime];
239    end
240    uid_DateTime=find(t,'ImaDoc/Heading/DateTime');
241    if isempty(uid_DateTime)
242        [t,uid_DateTime]=add(t,uid_Heading,'element','DateTime');
243    end
244    uid_value=children(t,uid_DateTime);
245    if isempty(uid_value)
246        t=add(t,uid_DateTime,'chardata',DateTime);%indicate  name of the first image, with ;png extension
247    else
248        t=set(t,uid_value(1),'value',DateTime);%indicate  name of the first image, with ;png extension
249    end
250end
251 
252%% backup the previous xml file and save the corrected one
253[success,message]=copyfile(filexml,[filexml '~']);%make backup
254if success~=1
255    dips(['errror in xml file backup: ' message]);
256    return
257end
258save(t,filexml)
259
260%% main loop on images
261nbfield2=1;
262if isfield(XmlData,'Time')
263nbfield2=size(XmlData.Time,2);
264end
265for ifile=1:nbfield
266            update_waitbar(WaitbarHandle,ifile/nbfield)
267    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
268        disp('program stopped by user')
269        break
270    end
271    [A,FileInfo,timestamps]=read_rdvision(filename,ifile);
272    if ifile==1
273        classA=class(A);
274        if strcmp(classA,'uint8')
275            BitDepth=8;
276        else
277        BitDepth=16;
278        end
279    end
280    j1=[];
281    if ~isequal(nbfield2,1)
282    j1=mod(ifile-1+first_label,nbfield2)+1;
283    end
284    i1=floor((ifile-1+first_label)/nbfield2)+1;
285    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,'img','.png',NomTypeNew,i1,[],j1);
286    try
287        imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
288    disp([OutputFile ' written']);
289        [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
290        if ~s
291            disp_uvmat('ERROR',errormsg,checkrun);
292            return
293        end
294    catch ME
295        disp_uvmat('ERROR',ME.message,checkrun);
296        return
297    end
298   
299end
300
301%'imadoc2struct_special': reads the xml file for image documentation
302%------------------------------------------------------------------------
303% function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
304%
305% OUTPUT:
306% s: structure representing ImaDoc
307%   s.Heading: information about the data hierarchical structure
308%   s.Time: matrix of times
309%   s.TimeUnit
310%  s.GeometryCalib: substructure containing the parameters for geometric calibration
311% errormsg: error message
312%
313% INPUT:
314% ImaDoc: full name of the xml input file with head key ImaDoc
315% option: ='GeometryCalib': read  the data of GeometryCalib, including source point coordinates
316
317function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
318
319%% default input and output
320if ~exist('option','var')
321    option='*';
322end
323errormsg=[];%default
324s.Heading=[];%default
325s.Time=[]; %default
326s.TimeUnit=[]; %default
327s.GeometryCalib=[];
328tsai=[];%default
329
330%% opening the xml file
331if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist
332try
333    t=xmltree(ImaDoc);
334catch
335    errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
336    display(errormsg);
337    return
338end
339uid_root=find(t,'/ImaDoc');
340if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file
341
342
343%% Heading
344uid_Heading=find(t,'/ImaDoc/Heading');
345if ~isempty(uid_Heading),
346    uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
347    uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
348    uid_Device=find(t,'/ImaDoc/Heading/Device');
349    uid_Record=find(t,'/ImaDoc/Heading/Record');
350    uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
351    s.Heading.Campaign=get(t,children(t,uid_Campaign),'value');
352    s.Heading.Experiment=get(t,children(t,uid_Exp),'value');
353    s.Heading.Device=get(t,children(t,uid_Device),'value');
354    if ~isempty(uid_Record)
355        s.Heading.Record=get(t,children(t,uid_Record),'value');
356    end
357    s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
358end
359
360%% Camera  and timing
361if strcmp(option,'*') || strcmp(option,'Camera')
362    uid_Camera=find(t,'/ImaDoc/Camera');
363    if ~isempty(uid_Camera)
364        uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
365        if ~isempty(uid_ImageSize);
366            ImageSize=get(t,children(t,uid_ImageSize),'value');
367            xindex=findstr(ImageSize,'x');
368            if length(xindex)>=2
369                s.Npx=str2double(ImageSize(1:xindex(1)-1));
370                s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1));
371            end
372        end
373        uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
374        if ~isempty(uid_TimeUnit)
375            s.TimeUnit=get(t,children(t,uid_TimeUnit),'value');
376        end
377        uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
378        if ~isempty(uid_BurstTiming)
379            for k=1:length(uid_BurstTiming)
380                subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
381                % reading Dtk
382                Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1);
383                Dtj=get_value(subt,'/BurstTiming/Dtj',[]);
384                Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
385                NbDtj=get_value(subt,'/BurstTiming/NbDtj',[]);
386                %%%% correction RDvision %%%%
387%                 NbDtj=NbDtj/numel(Dtj);
388%                 s.NbDtj=NbDtj;
389%                 %%%%
390                Dti=get_value(subt,'/BurstTiming/Dti',[]);
391                NbDti=get_value(subt,'/BurstTiming/NbDti',1);
392                 %%%% correction RDvision %%%%
393                if isempty(Dti)% series
394                     Dti=Dtj;
395                      NbDti=NbDtj;
396                     Dtj=[];
397                     s.Dti=Dti;
398                     s.NbDti=NbDti;
399                else
400                    % NbDtj=NbDtj/numel(Dtj);%bursts
401                    if ~isempty(NbDtj)
402                    s.NbDtj=NbDtj/numel(Dtj);%bursts;
403                    else
404                        s.NbDtj=1;
405                    end
406                end
407                %%%% %%%%
408                Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
409
410                Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit
411                if ~isempty(Dti)
412                    Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
413                    Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals  Dti
414                end
415                if ~isempty(Dtj)
416                    Dtj=reshape(Dtj'*ones(1,s.NbDtj),1,s.NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times
417                    Dtj=[0 Dtj];
418                    Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
419                end
420                % reading Dtk
421                Dtk=get_value(subt,'/BurstTiming/Dtk',[]);
422                NbDtk=get_value(subt,'/BurstTiming/NbDtk',1);
423                %%%% correction RDvision %%%%
424                if ~isequal(NbDtk,1)
425                    NbDtk=-1+(NbDtk+1)/(NbDti+1);
426                end
427                s.NbDtk=NbDtk;
428                %%%%%
429                if isempty(Dtk)
430                    s.Time=[s.Time;Time_val];
431                else
432                    for kblock=1:NbDtk+1
433                        Time_val_k=Time_val+(kblock-1)*Dtk;
434                        s.Time=[s.Time;Time_val_k];
435                    end
436                end
437            end
438        end
439    end
440end
441
442%% motor
443if strcmp(option,'*') || strcmp(option,'GeometryCalib')
444    uid_subtree=find(t,'/ImaDoc/TranslationMotor');
445    if length(uid_subtree)==1
446        subt=branch(t,uid_subtree);%subtree under GeometryCalib
447       [s.TranslationMotor,errormsg]=read_subtree(subt,{'Nbslice','ZStart','ZEnd'},[1 1 1],[1 1 1]);
448    end
449end
450%%  geometric calibration
451if strcmp(option,'*') || strcmp(option,'GeometryCalib')
452    uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
453    if ~isempty(uid_GeometryCalib)
454        if length(uid_GeometryCalib)>1
455            errormsg=['More than one GeometryCalib in ' filecivxml];
456            return
457        end
458        subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
459        cont=get(subt,1,'contents');
460        if ~isempty(cont)
461            uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType');
462            if isequal(length(uid_CalibrationType),1)
463                tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value');
464            end
465            uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
466            if isequal(length(uid_CoordUnit),1)
467                tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
468            end
469            uid_fx_fy=find(subt,'/GeometryCalib/fx_fy');
470            focal=[];%default fro old convention (Reg Wilson)
471            if isequal(length(uid_fx_fy),1)
472                tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value'));
473            else %old convention (Reg Wilson)
474                uid_focal=find(subt,'/GeometryCalib/focal');
475                uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
476                uid_sx=find(subt,'/GeometryCalib/sx');
477                if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx)
478                    dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
479                    sx=str2num(get(subt,children(subt,uid_sx),'value'));
480                    focal=str2num(get(subt,children(subt,uid_focal),'value'));
481                    tsai.fx_fy(1)=sx*focal/dpx_dpy(1);
482                    tsai.fx_fy(2)=focal/dpx_dpy(2);
483                end
484            end
485            uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
486            if ~isempty(uid_Cx_Cy)
487                tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
488            end
489            uid_kc=find(subt,'/GeometryCalib/kc');
490            if ~isempty(uid_kc)
491                tsai.kc=str2double(get(subt,children(subt,uid_kc),'value'));
492            else %old convention (Reg Wilson)
493                uid_kappa1=find(subt,'/GeometryCalib/kappa1');
494                if ~isempty(uid_kappa1)&& ~isempty(focal)
495                    kappa1=str2double(get(subt,children(subt,uid_kappa1),'value'));
496                    tsai.kc=-kappa1*focal*focal;
497                end
498            end
499            uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
500            if ~isempty(uid_Tx_Ty_Tz)
501                tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value'));
502            end
503            uid_R=find(subt,'/GeometryCalib/R');
504            if ~isempty(uid_R)
505                RR=get(subt,children(subt,uid_R),'value');
506                if length(RR)==3
507                    tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
508                end
509            end
510           
511            %look for laser plane definitions
512            uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
513            uid_Pos=find(subt,'/GeometryCalib/SliceCoord');
514            if isempty(uid_Pos)
515                uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention
516            end
517            if ~isempty(uid_Angle)
518                tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
519            end
520            if ~isempty(uid_Pos)
521                for j=1:length(uid_Pos)
522                    tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
523                end
524                uid_DZ=find(subt,'/GeometryCalib/SliceDZ');
525                uid_NbSlice=find(subt,'/GeometryCalib/NbSlice');
526                if ~isempty(uid_DZ) && ~isempty(uid_NbSlice)
527                    DZ=str2double(get(subt,children(subt,uid_DZ),'value'));
528                    NbSlice=get(subt,children(subt,uid_NbSlice),'value');
529                    if isequal(NbSlice,'volume')
530                        tsai.NbSlice='volume';
531                        NbSlice=NbDtj+1;
532                    else
533                        tsai.NbSlice=str2double(NbSlice);
534                    end
535                    tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1];
536                end
537            end   
538            tsai.SliceAngle=get_value(subt,'/GeometryCalib/SliceAngle',[0 0 0]);
539            tsai.VolumeScan=get_value(subt,'/GeometryCalib/VolumeScan','n');
540            tsai.InterfaceCoord=get_value(subt,'/GeometryCalib/InterfaceCoord',[0 0 0]);
541            tsai.RefractionIndex=get_value(subt,'/GeometryCalib/RefractionIndex',1);
542           
543            if strcmp(option,'GeometryCalib')
544                tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);
545            end
546            s.GeometryCalib=tsai;
547        end
548    end
549end
550
551%--------------------------------------------------
552%  read a subtree
553% INPUT:
554% t: xltree
555% head_element: head elelemnt of the subtree
556% Data, structure containing
557%    .Key: element name
558%    .Type: type of element ('charg', 'float'....)
559%    .NbOccur: nbre of occurrence, NaN for un specified number
560function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest)
561%--------------------------------------------------
562s=[];%default
563errormsg='';
564head_element=get(subt,1,'name');
565    cont=get(subt,1,'contents');
566    if ~isempty(cont)
567        for ilist=1:length(Data)
568            uid_key=find(subt,[head_element '/' Data{ilist}]);
569            if ~isequal(length(uid_key),NbOccur(ilist))
570                errormsg=['wrong number of occurence for ' Data{ilist}];
571                return
572            end
573            for ival=1:length(uid_key)
574                val=get(subt,children(subt,uid_key(ival)),'value');
575                if ~NumTest(ilist)
576                    eval(['s.' Data{ilist} '=val;']);
577                else
578                    eval(['s.' Data{ilist} '=str2double(val);'])
579                end
580            end
581        end
582    end
583
584
585%--------------------------------------------------
586%  read an xml element
587function val=get_value(t,label,default)
588%--------------------------------------------------
589val=default;
590uid=find(t,label);%find the element iud(s)
591if ~isempty(uid) %if the element named label exists
592   uid_child=children(t,uid);%find the children
593   if ~isempty(uid_child)
594       data=get(t,uid_child,'type');%get the type of child
595       if iscell(data)% case of multiple element
596           for icell=1:numel(data)
597               val_read=str2num(get(t,uid_child(icell),'value'));
598               if ~isempty(val_read)
599                   val(icell,:)=val_read;
600               end
601           end
602%           val=val';
603       else % case of unique element value
604           val_read=str2num(get(t,uid_child,'value'));
605           if ~isempty(val_read)
606               val=val_read;
607           else
608              val=get(t,uid_child,'value');%char string data
609           end
610       end
611   end
612end
Note: See TracBrowser for help on using the repository browser.