source: trunk/src/series/relabel_i_j.m @ 555

Last change on this file since 555 was 555, checked in by sommeria, 12 years ago

relabel_i_j corrected

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