Home > . > imadoc2struct.m

# imadoc2struct

## PURPOSE

'imadoc2struct': reads the xml file for image documentation

## SYNOPSIS

function [s,errormsg]=imadoc2struct(ImaDoc)

## DESCRIPTION

    'imadoc2struct': reads the xml file for image documentation

    function [s,errormsg]=imadoc2struct(ImaDoc)
    --------------------------------------------------------
     OUTPUT:
     s: structutre representing ImaDoc
     errormsg: error message

     INPUT:
     ImaDoc: full name of the xml input file with head key ImaDoc

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- RUN_STLIN 'RUN_STLIN': combine velocity fields for stereo PIV
- civ 'civ': function associated with the interface 'civ.fig' for PIV, spline interpolation and stereo PIV (patch)
- civ_3D 'civ_3D': function associated with the interface 'civ_3D.fig' for PIV in volume
- series 'series': master function associated to the GUI series.m for analysis field series
- set_grid 'set_grid':produce grid for PIV with one or two images (stereo case)
- uvmat 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization

## SUBFUNCTIONS

- function abs_time=get_time(BurstTiming)
- function tsai=get_GeometryCalib(s)

## SOURCE CODE

    0001 %'imadoc2struct': reads the xml file for image documentation
    0002 %
    0003 %function [s,errormsg]=imadoc2struct(ImaDoc)
    0004 %--------------------------------------------------------
    0005 % OUTPUT:
    0006 % s: structutre representing ImaDoc
    0007 % errormsg: error message
    0008 %
    0009 % INPUT:
    0010 % ImaDoc: full name of the xml input file with head key ImaDoc
    0011
    0012 function [s,errormsg]=imadoc2struct(ImaDoc)
    0013 s=[];
    0014 errormsg=[];%default
    0015 try
    0016     t=xmltree(ImaDoc);
    0017 catch
    0018     errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
    0019     display(errormsg);
    0020     return
    0021 end
    0022 RootKey=get(t,1,'name');
    0023 if ~isequal(RootKey,'ImaDoc')
    0024     errormsg=[ImaDoc ' is not an image documentation file'];
    0025     return
    0026 end
    0027 s=convert(t);
    0028 s.Time=[];%default
    0029 if isfield(s,'Camera')
    0030     if isfield(s.Camera,'BurstTiming')
    0031         s.Time=get_time(s.Camera.BurstTiming);
    0032         s.Camera=rmfield(s.Camera,'BurstTiming');
    0033     end
    0034 end
    0035 if isfield(s,'GeometryCalib')
    0036     s.GeometryCalib=get_GeometryCalib(s.GeometryCalib);
    0037 end
    0038
    0039 %----------------------------------------
    0040 function abs_time=get_time(BurstTiming)
    0041 abs_time=[];
    0042 for k=1:length(BurstTiming)
    0043
    0044     Frequency=1;%default
    0045     if isfield(BurstTiming,'FrameFrequency')&&~isempty(BurstTiming.FrameFrequency)
    0046         Frequency=str2double(BurstTiming.FrameFrequency);
    0047     end
    0048
    0049     Dtj=[];%default
    0050     if isfield(BurstTiming,'Dtj')
    0051        Dtj=str2num(BurstTiming.Dtj);
    0052     end
    0053
    0054     NbDtj=1;%default
    0055     if isfield(BurstTiming,'NbDtj')&&~isempty(BurstTiming.NbDtj)
    0056         NbDtj=str2double(BurstTiming.NbDtj);
    0057     end
    0058     Dti=[]; %default
    0059     if isfield(BurstTiming,'Dti')
    0060         Dti=str2num(BurstTiming.Dti);
    0061     end
    0062
    0063     NbDti=1;%default
    0064     if isfield(BurstTiming,'NbDti')&&~isempty(BurstTiming.NbDti)
    0065        NbDti=str2double(BurstTiming.NbDti);
    0066     end
    0067     if ~isempty(Dtj)
    0068         Dtj=reshape(Dtj'*ones(1,NbDtj),1,length(Dtj)*NbDtj);
    0069     end
    0070     Dtj=[0 Dtj];
    0071     dtunit=Dtj/Frequency;
    0072     Time=[];%default
    0073     if isfield(BurstTiming,'Time') && ~isempty(BurstTiming.Time)
    0074         %nbfield=length(BurstTiming.Time)
    0075         if ischar(BurstTiming.Time)
    0076              Time(1,1)=str2num(BurstTiming.Time);
    0077              nbfield=1;
    0078         else
    0079             nbfield=length(BurstTiming.Time);
    0080              for itime=1:nbfield
    0081                  Time(itime,1)=str2num(BurstTiming.Time{itime});
    0082              end
    0083         end
    0084         abstime_read=Time*ones(1,length(Dtj))+ones(nbfield,1)*cumsum(dtunit);
    0085         abs_time=[abs_time;abstime_read];
    0086         if ~isempty(Dti) && size(abs_time,1)==1
    0087            abs_time=ones(NbDti+1,1)*abs_time+(Dti/Frequency)*(0:NbDti)'*ones(size(abs_time));
    0088         end
    0089     end
    0090 end
    0091
    0092 %----------------------------------------------------------------
    0093 function tsai=get_GeometryCalib(s)
    0094 %default values:
    0095 tsai.f=1;
    0096 tsai.dpx=1;
    0097 tsai.dpy=1;
    0098 tsai.sx=1;
    0099 tsai.Cx=0;
    0100 tsai.Cy=0;
    0101 tsai.Tx=0;
    0102 tsai.Ty=0;
    0103 tsai.Tz=1;
    0104 tsai.R=[1 0 0; 0 1 0; 0 0 0];
    0105 tsai.kappa1=0;
    0106 if isfield(s,'focal')
    0107     tsai.f=str2double(s.focal);
    0108 end
    0109 if isfield(s,'dpx_dpy')
    0110     dpx_dpy=str2num(s.dpx_dpy);
    0111     tsai.dpx=dpx_dpy(1);
    0112     tsai.dpy=dpx_dpy(2);
    0113 end
    0114 if isfield(s,'sx')
    0115     tsai.sx=str2double(s.sx);
    0116 end
    0117 if isfield(s,'Cx_Cy')
    0118     Cx_Cy=str2num(s.Cx_Cy);
    0119     tsai.Cx=Cx_Cy(1);
    0120     tsai.Cy=Cx_Cy(2);
    0121 end
    0122 if isfield(s,'Tx_Ty_Tz')
    0123     Tx_Ty_Tz=str2num(s.Tx_Ty_Tz);
    0124     tsai.Tx=Tx_Ty_Tz(1);
    0125     tsai.Ty=Tx_Ty_Tz(2);
    0126     tsai.Tz=Tx_Ty_Tz(3);
    0127 end
    0128 if isfield(s,'R')
    0129     tsai.R=[str2num(s.R{1});str2num(s.R{2});str2num(s.R{3})];
    0130 end
    0131 if isfield(s,'kappa1')
    0132     tsai.kappa1=str2double(s.kappa1);
    0133 end
    0134 if isfield(s,'SliceOrigin')
    0135     if ischar(s.SliceOrigin)
    0136         tsai.SliceOrigin=str2num(s.SliceOrigin);
    0137     end
    0138 end
    0139 if isfield(s,'SliceDZ')
    0140 %     SliceOrigin=0;
    0141 %     SliceOZ=1;%default
    0142     NbSlice=1;%default
    0143     if ischar(s.NbSlice)
    0144         NbSlice=str2double(s.NbSlice);
    0145     end
    0146     if ischar(s.SliceOrigin)
    0147         SliceOrigin=str2num(s.SliceOrigin);
    0148         if length(SliceOrigin)==3
    0149             tsai.SliceCoord(1,:)=SliceOrigin;%to generalize for angles
    0150         end
    0151     end
    0152     if ischar(s.SliceDZ)
    0153         SliceOZ=str2double(s.SliceDZ);
    0154         tsai.SliceCoord=tsai.SliceZ+SliceOZ*(0:NbSlice-1);
    0155     end
    0156     if iscell(s.SliceDZ)
    0157         for j=1:length(s.SliceDZ)
    0158             tsai.SliceCoord(j,:)=tsai.SliceZ(j-1,:)+str2num(s.SliceDZ{j});
    0159         end
    0160     end
    0161 end
    0162 if isfield(s,'PlanePos')%Obsolete
    0163     if ischar(s.PlanePos)
    0164         tsai.SliceCoord(1,:)=str2num(s.PlanePos);
    0165     else
    0166         for j=1:length(s.PlanePos)
    0167             PlanePos=str2num(s.PlanePos{j});
    0168             tsai.SliceCoord(j,:)=PlanePos;
    0169         end
    0170     end
    0171 end
    0172
    0173 %look for laser plane definitions
    0174
    0175
    0176
    0177