source: trunk/src/geometry_calib.m @ 655

Last change on this file since 655 was 655, checked in by sommeria, 11 years ago

various bugs corrected

File size: 56.5 KB
RevLine 
[168]1%'geometry_calib': associated to the GUI geometry_calib to perform geometric calibration from a set of reference points
2%------------------------------------------------------------------------
3% function hgeometry_calib = geometry_calib(inputfile,pos)
[2]4%
[168]5%OUTPUT:
6% hgeometry_calib=current handles of the GUI geometry_calib.fig
[2]7%
[168]8%INPUT:
9% inputfile: (optional) name of an xml file containing coordinates of reference points
10% pos: (optional) 4 element vector setting the 'Position' of the GUI
11%
[109]12%A%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
[2]13%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
14%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
15%     This file is part of the toolbox UVMAT.
16%
17%     UVMAT is free software; you can redistribute it and/or modify
18%     it under the terms of the GNU General Public License as published by
19%     the Free Software Foundation; either version 2 of the License, or
20%     (at your option) any later version.
21%
22%     UVMAT is distributed in the hope that it will be useful,
23%     but WITHOUT ANY WARRANTY; without even the implied warranty of
24%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
26%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
27
28function varargout = geometry_calib(varargin)
29% GEOMETRY_CALIB M-file for geometry_calib.fig
30%      GEOMETRY_CALIB, by itself, creates a MenuCoord GEOMETRY_CALIB or raises the existing
31%      singleton*.
32%
33%      H = GEOMETRY_CALIB returns the handle to a MenuCoord GEOMETRY_CALIB or the handle to
34%      the existing singleton*.
35%
36%      GEOMETRY_CALIB('CALLBACK',hObject,eventData,handles,...) calls the local
37%      function named CALLBACK in GEOMETRY_CALIB.M with the given input arguments.
38%
39%      GEOMETRY_CALIB('Property','Value',...) creates a MenuCoord GEOMETRY_CALIB or raises the
40%      existing singleton*.  Starting from the left, property value pairs are
41%      applied to the GUI before geometry_calib_OpeningFunction gets called.  An
42%      unrecognized property name or invalid value makes property application
43%      stop.  All inputs are passed to geometry_calib_OpeningFcn via varargin.
44%
45%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
46%      instance to run (singleton)".
47%
48% See also: GUIDE, GUIDATA, GUIHANDLES
49
50% Edit the above text to modify the response to help geometry_calib
51
[654]52% Last Modified by GUIDE v2.5 29-Jun-2013 23:52:36
[2]53
54% Begin initialization code - DO NOT edit
55gui_Singleton = 1;
56gui_State = struct('gui_Name',       mfilename, ...
57                   'gui_Singleton',  gui_Singleton, ...
58                   'gui_OpeningFcn', @geometry_calib_OpeningFcn, ...
59                   'gui_OutputFcn',  @geometry_calib_OutputFcn, ...
60                   'gui_LayoutFcn',  [] , ...
61                   'gui_Callback',   []);
[128]62if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once'))
[2]63    gui_State.gui_Callback = str2func(varargin{1});
64end
65
66if nargout
67    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
68else
69    gui_mainfcn(gui_State, varargin{:});
70end
71% End initialization code - DO NOT edit
72
73
74% --- Executes just before geometry_calib is made visible.
75%INPUT:
76%handles: handles of the geometry_calib interface elements
77% PlotHandles: set of handles of the elements contolling the plotting
78% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
[60]79%------------------------------------------------------------------------
[116]80function geometry_calib_OpeningFcn(hObject, eventdata, handles,inputfile,pos)
[60]81%------------------------------------------------------------------------
[2]82% Choose default command line output for geometry_calib
[156]83
[2]84handles.output = hObject;
85
86% Update handles structure
87guidata(hObject, handles);
[71]88set(hObject,'DeleteFcn',{@closefcn})%
[252]89set(hObject,'WindowButtonDownFcn',{'mouse_alt_gui',handles}) % allows mouse action with right button (zoom for uicontrol display)
[71]90
[613]91%% position
92set(0,'Unit','points')
93ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
94Width=350;% fig width in points (1/72 inch)
95Height=min(0.9*ScreenSize(4),700);
96Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40
97Bottom=ScreenSize(4)-Height-40; %put fig at top right
98set(handles.geometry_calib,'Unit','points')
99set(handles.geometry_calib,'Position',[Left Bottom Width Height])
[109]100
[613]101% %set the position of the interface
102% if exist('pos','var')&& length(pos)>=4
103%     set(hObject,'Position',pos);
104% end
105
[109]106%set menu of calibration options
[121]107set(handles.calib_type,'String',{'rescale';'linear';'3D_linear';'3D_quadr';'3D_extrinsic'})
[116]108if exist('inputfile','var')&& ~isempty(inputfile)
[114]109    struct.XmlInputFile=inputfile;
[494]110    [RootPath,SubDir,RootFile,tild,tild,tild,tild,FileExt]=fileparts_uvmat(inputfile);
[341]111    if ~strcmp(FileExt,'.xml')
[494]112        inputfile=fullfile(RootPath,[SubDir '.xml']);%xml file corresponding to the input file
113        if ~exist(inputfile,'file')% case of civ files , removes the extension for subdir
114            inputfile=fullfile(RootPath,[regexprep(SubDir,'\..+$','') '.xml']);
115            if ~exist(inputfile,'file')
116                inputfile=[fullfile(RootPath,SubDir,RootFile) '.xml'];%old convention
117                if ~exist(inputfile,'file')
118                    inputfile='';
119                end
120            end
121        end
[116]122    end
[156]123    set(handles.ListCoord,'String',{'......'})
124    if exist(inputfile,'file')
[498]125        Heading=loadfile(handles,inputfile);% load data from the xml file
[156]126        if isfield(Heading,'Campaign')&& ischar(Heading.Campaign)
127            struct.Campaign=Heading.Campaign;
128        end
129    end   
130    set(hObject,'UserData',struct)
[2]131end
[156]132
[2]133set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function
134
[71]135
[17]136%------------------------------------------------------------------------
[2]137% --- Outputs from this function are returned to the command line.
138function varargout = geometry_calib_OutputFcn(hObject, eventdata, handles)
[17]139%------------------------------------------------------------------------
[2]140% Get default command line output from handles structure
141varargout{1} = handles.output;
142varargout{2}=handles;
[67]143%
[60]144%------------------------------------------------------------------------
[2]145% executed when closing: set the parent interface button to value 0
[67]146function closefcn(gcbo,eventdata)
[60]147%------------------------------------------------------------------------
[2]148huvmat=findobj(allchild(0),'Name','uvmat');
[67]149if ~isempty(huvmat)
150    handles=guidata(huvmat);
[541]151    hobject=findobj(handles.PlotAxes,'tag','calib_points');
[67]152    if ~isempty(hobject)
153        delete(hobject)
154    end
[541]155    hobject=findobj(handles.PlotAxes,'tag','calib_marker');
[67]156    if ~isempty(hobject)
157        delete(hobject)
158    end   
[2]159end
160
[60]161%------------------------------------------------------------------------
[569]162% --- Executes on button press APPLY (used to launch the calibration).
[2]163function APPLY_Callback(hObject, eventdata, handles)
[60]164%------------------------------------------------------------------------
[379]165%% look for the GUI uvmat and check for an image as input
166huvmat=findobj(allchild(0),'Name','uvmat');
167hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
168
[569]169RootPath='';
170if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile)
171    RootPath=get(hhuvmat.RootPath,'String');
172    SubDirBase=regexprep(get(hhuvmat.SubDir,'String'),'\..+$','');
173    outputfile=[fullfile(RootPath,SubDirBase) '.xml'];%xml file associated with the currently displayed image
174else
175    question={'save the calibration data and point coordinates in'};
176    def={fullfile(RootPath,'ObjectCalib.xml')};
177    options.Resize='on';
178    answer=inputdlg(question,'',1,def,options);
179    outputfile=answer{1};
180end
181[GeometryCalib,index]=calibrate(handles,hhuvmat);% apply calibration
182
183%% copy the xml file from the old location if appropriate, then update with the calibration parameters
184if ~exist(outputfile,'file') && ~isempty(SubDirBase)
185    oldxml=[fullfile(RootPath,SubDirBase,get(hhuvmat.RootFile,'String')) '.xml'];
186    if exist(oldxml,'file')
187        [success,message]=copyfile(oldxml,outputfile);%copy the old xml file to a new one with the new convention
188    end
189end
[630]190errormsg=update_imadoc(GeometryCalib,outputfile,'GeometryCalib');% introduce the calibration data in the xml file
[569]191if ~strcmp(errormsg,'')
192    msgbox_uvmat('ERROR',errormsg);
193end
194
195%% display image with new calibration in the currently opened uvmat interface
196hhh=findobj(hhuvmat.PlotAxes,'Tag','calib_marker');% delete calib points and markers
197if ~isempty(hhh)
198    delete(hhh);
199end
200hhh=findobj(hhuvmat.PlotAxes,'Tag','calib_points');
201if ~isempty(hhh)
202    delete(hhh);
203end
204set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off'
205set(hhuvmat.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
206UserData=get(handles.geometry_calib,'UserData');
207UserData.XmlInputFile=outputfile;%save the current xml file name
208set(handles.geometry_calib,'UserData',UserData)
209uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat, show the image in phys coordinates
[654]210PLOT_Callback(hObject, eventdata, handles)
[569]211set(handles.ListCoord,'Value',index)% indicate in the list the point with max deviation (possible mistake)
212ListCoord_Callback(hObject, eventdata, handles)
213figure(handles.geometry_calib)
214
215%------------------------------------------------------------------------
216% --- Executes on button press in REPLICATE
217function REPLICATE_Callback(hObject, eventdata, handles)
218%------------------------------------------------------------------------
219
220%% look for the GUI uvmat and check for an image as input
221huvmat=findobj(allchild(0),'Name','uvmat');
222hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
223GeometryCalib=calibrate(handles,hhuvmat);% apply calibration
224
225%% open the GUI browse_data
226CalibData=get(handles.geometry_calib,'UserData');%read the calibration image source on the interface userdata
227if isfield(CalibData,'XmlInputFile')
228    InputDir=fileparts(fileparts(CalibData.XmlInputFile));
229end
230answer=msgbox_uvmat('INPUT_TXT','Campaign to calibrate?',InputDir);
231if strcmp(answer,'Cancel')
232    return
233end
234OutPut=browse_data(answer);
235nbcalib=0;
236for ilist=1:numel(OutPut.Experiment)
237    SubDirBase=regexprep(OutPut.Device{1},'\..+$','');
238    XmlName=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},[SubDirBase '.xml']);
239    % copy the xml file from the old location if appropriate, then update with the calibration parameters
240    if ~exist(XmlName,'file') && ~isempty(SubDirBase)
241        oldxml=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},SubDirBase,[get(hhuvmat.RootFile,'String') '.xml']);
242        if exist(oldxml,'file')
243            [success,message]=copyfile(oldxml,XmlName);%copy the old xml file to a new one with the new convention
244        end
245    end
[630]246    errormsg=update_imadoc(GeometryCalib,XmlName,'GeometryCalib');% introduce the calibration data in the xml file
[569]247    if ~strcmp(errormsg,'')
248        msgbox_uvmat('ERROR',errormsg);
249    else
250        display([XmlName ' updated with calibration parameters'])
251        nbcalib=nbcalib+1;
252    end
253end
254msgbox_uvmat('CONFIMATION',[SubDirBase ' calibrated for ' num2str(nbcalib) ' experiments']);
255
256%------------------------------------------------------------------------
257% --- activate calibration and store parameters in ouputfile .
258function [GeometryCalib,index]=calibrate(handles,hhuvmat)
259%------------------------------------------------------------------------
[379]260%% read the current calibration points
[2]261Coord_cell=get(handles.ListCoord,'String');
262Object=read_geometry_calib(Coord_cell);
[109]263Coord=Object.Coord;
264% apply the calibration, whose type is selected in  handles.calib_type
265if ~isempty(Coord)
266    calib_cell=get(handles.calib_type,'String');
267    val=get(handles.calib_type,'Value');
268    GeometryCalib=feval(['calib_' calib_cell{val}],Coord,handles);
269else
270    msgbox_uvmat('ERROR','No calibration points, abort')
271    return
272end
[114]273Z_plane=[];
[109]274if ~isempty(Coord)
[114]275    %check error
[109]276    X=Coord(:,1);
277    Y=Coord(:,2);
278    Z=Coord(:,3);
279    x_ima=Coord(:,4);
280    y_ima=Coord(:,5);
[114]281    [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z);
[109]282    GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
283    [GeometryCalib.ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima));
284    GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
285    [GeometryCalib.ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima));
[494]286    [tild,ind_dim]=max(GeometryCalib.ErrorMax);
[109]287    index=index(ind_dim);
[114]288    %set the Z position of the reference plane used for calibration
[109]289    if isequal(max(Z),min(Z))%Z constant
[114]290        Z_plane=Z(1);
[109]291        GeometryCalib.NbSlice=1;
[114]292        GeometryCalib.SliceCoord=[0 0 Z_plane];
[109]293    end
294end
[114]295%set the coordinate unit
[2]296unitlist=get(handles.CoordUnit,'String');
297unit=unitlist{get(handles.CoordUnit,'value')};
298GeometryCalib.CoordUnit=unit;
[114]299%record the points
[109]300GeometryCalib.SourceCalib.PointCoord=Coord;
[114]301display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
[109]302
[114]303% Display extrinsinc parameters (rotation and translation of camera with  respect to the phys coordiantes)
[109]304set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4))
305set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4))
306set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4))
[114]307set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4))
308set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4))
309set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))
[109]310
[379]311%% store the calibration data, by default in the xml file of the currently displayed image
[569]312UvData=get(hhuvmat.uvmat,'UserData');
[191]313NbSlice_j=1;%default
314ZStart=Z_plane;
315ZEnd=Z_plane;
[196]316volume_scan='n';
[191]317if isfield(UvData,'XmlData')
318    if isfield(UvData.XmlData,'TranslationMotor')
319        NbSlice_j=UvData.XmlData.TranslationMotor.Nbslice;
[196]320        ZStart=UvData.XmlData.TranslationMotor.ZStart/10;
321        ZEnd=UvData.XmlData.TranslationMotor.ZEnd/10;
322        volume_scan='y';
[191]323    end
324end
[569]325
326answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
[2]327    ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
[84]328    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']});
[128]329
[569]330%% get plane position(s)
331if ~strcmp(answer,'Yes')
332    return
[2]333end
[569]334if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
335    input_key={'Z (first position)','Z (last position)','Z (water surface)', 'refractive index','NbSlice','volume scan (y/n)','tilt angle y axis','tilt angle x axis'};
336    input_val=[{num2str(ZEnd)} {num2str(ZStart)} {num2str(ZStart)} {'1.333'} num2str(NbSlice_j) {volume_scan} {'0'} {'0'}];
337    answer=inputdlg(input_key,'slice position(s)',ones(1,8), input_val,'on');
338    GeometryCalib.NbSlice=str2double(answer{5});
339    GeometryCalib.VolumeScan=answer{6};
340    if isempty(answer)
341        Z_plane=0; %default
342    else
343        Z_plane=linspace(str2double(answer{1}),str2double(answer{2}),GeometryCalib.NbSlice);
[114]344    end
[569]345    GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
346    GeometryCalib.SliceAngle(:,3)=0;
347    GeometryCalib.SliceAngle(:,2)=str2double(answer{7})*ones(GeometryCalib.NbSlice,1);%rotation around y axis (to generalise)
348    GeometryCalib.SliceAngle(:,1)=str2double(answer{8})*ones(GeometryCalib.NbSlice,1);%rotation around x axis (to generalise)
349    GeometryCalib.InterfaceCoord=[0 0 str2double(answer{3})];
350    GeometryCalib.RefractionIndex=str2double(answer{4});
[114]351end
[128]352
[114]353
354
[60]355%------------------------------------------------------------------------
[2]356% determine the parameters for a calibration by an affine function (rescaling and offset, no rotation)
[109]357function GeometryCalib=calib_rescale(Coord,handles)
[60]358%------------------------------------------------------------------------
[2]359X=Coord(:,1);
[109]360Y=Coord(:,2);% Z not used
[2]361x_ima=Coord(:,4);
362y_ima=Coord(:,5);
[341]363[px]=polyfit(X,x_ima,1);
364[py]=polyfit(Y,y_ima,1);
365% T_x=px(2);
366% T_y=py(2);
[2]367GeometryCalib.CalibrationType='rescale';
[121]368GeometryCalib.fx_fy=[px(1) py(1)];%.fx_fy corresponds to pxcm along x and y
[2]369GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
[114]370GeometryCalib.Tx_Ty_Tz=[px(2)/px(1) py(2)/py(1) 1];
371GeometryCalib.omc=[0 0 0];
[2]372
[60]373%------------------------------------------------------------------------
[2]374% determine the parameters for a calibration by a linear transform matrix (rescale and rotation)
[242]375
376
[227]377function GeometryCalib=calib_linear(Coord,handles)
[60]378%------------------------------------------------------------------------
[2]379X=Coord(:,1);
[109]380Y=Coord(:,2);% Z not used
[2]381x_ima=Coord(:,4);
382y_ima=Coord(:,5);
383XY_mat=[ones(size(X)) X Y];
384a_X1=XY_mat\x_ima; %transformation matrix for X
385a_Y1=XY_mat\y_ima;%transformation matrix for X
[121]386R=[a_X1(2),a_X1(3);a_Y1(2),a_Y1(3)];
[242]387epsilon=sign(det(R));
[116]388norm=abs(det(R));
[2]389GeometryCalib.CalibrationType='linear';
[238]390if (a_X1(2)/a_Y1(3))>0
[242]391    GeometryCalib.fx_fy(1)=sqrt((a_X1(2)/a_Y1(3))*norm);
[238]392else
[242]393    GeometryCalib.fx_fy(1)=-sqrt(-(a_X1(2)/a_Y1(3))*norm);
[238]394end
[121]395GeometryCalib.fx_fy(2)=(a_Y1(3)/a_X1(2))*GeometryCalib.fx_fy(1);
[2]396GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
[227]397GeometryCalib.Tx_Ty_Tz=[a_X1(1)/GeometryCalib.fx_fy(1) a_Y1(1)/GeometryCalib.fx_fy(2) 1];
[242]398R(1,:)=R(1,:)/GeometryCalib.fx_fy(1);
[121]399R(2,:)=R(2,:)/GeometryCalib.fx_fy(2);
400R=[R;[0 0]];
[242]401GeometryCalib.R=[R [0;0;-epsilon]];
402GeometryCalib.omc=(180/pi)*[acos(GeometryCalib.R(1,1)) 0 0];
[569]403
[109]404%------------------------------------------------------------------------
405% determine the tsai parameters for a view normal to the grid plane
[114]406% NOT USED
[109]407function GeometryCalib=calib_normal(Coord,handles)
408%------------------------------------------------------------------------
409Calib.f1=str2num(get(handles.fx,'String'));
410Calib.f2=str2num(get(handles.fy,'String'));
[114]411Calib.k=str2num(get(handles.kc,'String'));
[109]412Calib.Cx=str2num(get(handles.Cx,'String'));
413Calib.Cy=str2num(get(handles.Cy,'String'));
414%default
415if isempty(Calib.f1)
416    Calib.f1=25/0.012;
417end
418if isempty(Calib.f2)
419    Calib.f2=25/0.012;
420end
421if isempty(Calib.k)
422    Calib.k=0;
423end
424if isempty(Calib.Cx)||isempty(Calib.Cy)
425    huvmat=findobj(allchild(0),'Tag','uvmat');
426    hhuvmat=guidata(huvmat);
[332]427    Calib.Cx=str2num(get(hhuvmat.num_Npx,'String'))/2;
428    Calib.Cx=str2num(get(hhuvmat.num_Npy,'String'))/2;
[109]429end   
430%tsai parameters
431Calib.dpx=0.012;%arbitrary
432Calib.dpy=0.012;
433Calib.sx=Calib.f1*Calib.dpx/(Calib.f2*Calib.dpy);
434Calib.f=Calib.f2*Calib.dpy;
435Calib.kappa1=Calib.k/(Calib.f*Calib.f);
[2]436
[109]437%initial guess
438X=Coord(:,1);
439Y=Coord(:,2);
440Zmean=mean(Coord(:,3));
441x_ima=Coord(:,4)-Calib.Cx;
442y_ima=Coord(:,5)-Calib.Cy;
443XY_mat=[ones(size(X)) X Y];
444a_X1=XY_mat\x_ima; %transformation matrix for X
445a_Y1=XY_mat\y_ima;%transformation matrix for Y
446R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,-1];% rotation+ z axis reversal (upward)
447norm=sqrt(det(-R));
448calib_param(1)=0;% quadratic distortion
449calib_param(2)=a_X1(1);
450calib_param(3)=a_Y1(1);
451calib_param(4)=Calib.f/(norm*Calib.dpx)-R(3,3)*Zmean;
[121]452calib_param(5)=angle(a_X1(2)+1i*a_X1(3));
[109]453display(['initial guess=' num2str(calib_param)])
454
455%optimise the parameters: minimisation of error
[121]456calib_param = fminsearch(@(calib_param) error_calib(calib_param,Calib,Coord),calib_param);
[109]457
458GeometryCalib.CalibrationType='tsai_normal';
459GeometryCalib.focal=Calib.f;
460GeometryCalib.dpx_dpy=[Calib.dpx Calib.dpy];
461GeometryCalib.Cx_Cy=[Calib.Cx Calib.Cy];
462GeometryCalib.sx=Calib.sx;
463GeometryCalib.kappa1=calib_param(1);
464GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
465GeometryCalib.Tx_Ty_Tz=[calib_param(2) calib_param(3) calib_param(4)];
466alpha=calib_param(5);
467GeometryCalib.R=[cos(alpha) sin(alpha) 0;-sin(alpha) cos(alpha) 0;0 0 -1];
468
[60]469%------------------------------------------------------------------------
[109]470function GeometryCalib=calib_3D_linear(Coord,handles)
[69]471%------------------------------------------------------------------
472path_uvmat=which('uvmat');% check the path detected for source file uvmat
473path_UVMAT=fileparts(path_uvmat); %path to UVMAT
[78]474huvmat=findobj(allchild(0),'Tag','uvmat');
475hhuvmat=guidata(huvmat);
[121]476coord_files=get(handles.coord_files,'String');
477if ischar(coord_files)
478    coord_files={coord_files};
479end
480if isempty(coord_files{1}) || isequal(coord_files,{''})
481    coord_files={};
482end
483%retrieve the calibration points stored in the files listed in the popup list coord_files
484x_1=Coord(:,4:5)';%px coordinates of the ref points
[332]485nx=str2num(get(hhuvmat.num_Npx,'String'));
486ny=str2num(get(hhuvmat.num_Npy,'String'));
[121]487x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates
488X_1=Coord(:,1:3)';%phys coordinates of the ref points
489n_ima=numel(coord_files)+1;
490if ~isempty(coord_files)
491    msgbox_uvmat('CONFIRMATION',['The xy coordinates of the calibration points in ' num2str(n_ima) ' planes will be used'])
492    for ifile=1:numel(coord_files)
493    t=xmltree(coord_files{ifile});
494    s=convert(t);%convert to matlab structure
495        if isfield(s,'GeometryCalib')
496            if isfield(s.GeometryCalib,'SourceCalib')
497                if isfield(s.GeometryCalib.SourceCalib,'PointCoord')
498                PointCoord=s.GeometryCalib.SourceCalib.PointCoord;
499                Coord_file=zeros(length(PointCoord),5);%default
500                for i=1:length(PointCoord)
501                    line=str2num(PointCoord{i});
502                    Coord_file(i,4:5)=line(4:5);%px x
503                    Coord_file(i,1:3)=line(1:3);%phys x
504                end
505                eval(['x_' num2str(ifile+1) '=Coord_file(:,4:5)'';']);
506                eval(['x_' num2str(ifile+1) '(2,:)=ny-x_' num2str(ifile+1) '(2,:);' ]);
507                eval(['X_' num2str(ifile+1) '=Coord_file(:,1:3)'';']);
508                end
509            end
510        end
511    end
512end
513n_ima=numel(coord_files)+1;
[109]514est_dist=[0;0;0;0;0];
515est_aspect_ratio=0;
516est_fc=[1;1];
517%fc=[25;25]/0.012;
518center_optim=0;
519run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim'));
520GeometryCalib.CalibrationType='3D_linear';
[121]521GeometryCalib.fx_fy=fc';
522%GeometryCalib.focal=fc(2);
523%GeometryCalib.dpx_dpy=[1 1];
[109]524GeometryCalib.Cx_Cy=cc';
[121]525%GeometryCalib.sx=fc(1)/fc(2);
526GeometryCalib.kc=kc(1);
527%GeometryCalib.kappa1=-kc(1)/fc(2)^2;
[109]528GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
529GeometryCalib.Tx_Ty_Tz=Tc_1';
530GeometryCalib.R=Rc_1;
[121]531GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate
532GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate
533GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate
534GeometryCalib.omc=(180/pi)*omc_1;%angles in degrees
535GeometryCalib.ErrorRMS=[];
536GeometryCalib.ErrorMax=[];
[109]537
538%------------------------------------------------------------------------
539function GeometryCalib=calib_3D_quadr(Coord,handles)
540%------------------------------------------------------------------
541
542path_uvmat=which('uvmat');% check the path detected for source file uvmat
543path_UVMAT=fileparts(path_uvmat); %path to UVMAT
544huvmat=findobj(allchild(0),'Tag','uvmat');
545hhuvmat=guidata(huvmat);
546% check_cond=0;
547coord_files=get(handles.coord_files,'String');
548if ischar(coord_files)
549    coord_files={coord_files};
550end
551if isempty(coord_files{1}) || isequal(coord_files,{''})
552    coord_files={};
553end
554
555%retrieve the calibration points stored in the files listed in the popup list coord_files
[114]556x_1=Coord(:,4:5)';%px coordinates of the ref points
[332]557nx=str2num(get(hhuvmat.num_Npx,'String'));
558ny=str2num(get(hhuvmat.num_Npy,'String'));
[114]559x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates
560X_1=Coord(:,1:3)';%phys coordinates of the ref points
[109]561n_ima=numel(coord_files)+1;
562if ~isempty(coord_files)
563    msgbox_uvmat('CONFIRMATION',['The xy coordinates of the calibration points in ' num2str(n_ima) ' planes will be used'])
564    for ifile=1:numel(coord_files)
565    t=xmltree(coord_files{ifile});
566    s=convert(t);%convert to matlab structure
567        if isfield(s,'GeometryCalib')
568            if isfield(s.GeometryCalib,'SourceCalib')
569                if isfield(s.GeometryCalib.SourceCalib,'PointCoord')
570                PointCoord=s.GeometryCalib.SourceCalib.PointCoord;
[121]571                Coord_file=zeros(length(PointCoord),5);%default
[109]572                for i=1:length(PointCoord)
573                    line=str2num(PointCoord{i});
574                    Coord_file(i,4:5)=line(4:5);%px x
575                    Coord_file(i,1:3)=line(1:3);%phys x
576                end
577                eval(['x_' num2str(ifile+1) '=Coord_file(:,4:5)'';']);
[114]578                eval(['x_' num2str(ifile+1) '(2,:)=ny-x_' num2str(ifile+1) '(2,:);' ]);
[109]579                eval(['X_' num2str(ifile+1) '=Coord_file(:,1:3)'';']);
580                end
581            end
582        end
583    end
584end
585n_ima=numel(coord_files)+1;
[108]586est_dist=[1;0;0;0;0];
[109]587est_aspect_ratio=1;
588%est_fc=[0;0];
589%fc=[25;25]/0.012;
590center_optim=0;
[83]591run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim'));
[69]592
[109]593GeometryCalib.CalibrationType='3D_quadr';
[114]594GeometryCalib.fx_fy=fc';
595%GeometryCalib.focal=fc(2);
596%GeometryCalib.dpx_dpy=[1 1];
[69]597GeometryCalib.Cx_Cy=cc';
[114]598%GeometryCalib.sx=fc(1)/fc(2);
599GeometryCalib.kc=kc(1);
600%GeometryCalib.kappa1=-kc(1)/fc(2)^2;
[69]601GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
602GeometryCalib.Tx_Ty_Tz=Tc_1';
603GeometryCalib.R=Rc_1;
[114]604GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate
605GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate
606GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate
607GeometryCalib.omc=(180/pi)*omc_1;%angles in degrees
[109]608GeometryCalib.ErrorRMS=[];
609GeometryCalib.ErrorMax=[];
[69]610
[109]611
[60]612%------------------------------------------------------------------------
[109]613function GeometryCalib=calib_3D_extrinsic(Coord,handles)
614%------------------------------------------------------------------
615path_uvmat=which('geometry_calib');% check the path detected for source file uvmat
616path_UVMAT=fileparts(path_uvmat); %path to UVMAT
[116]617x_1=double(Coord(:,4:5)');%image coordiantes
618X_1=double(Coord(:,1:3)');% phys coordinates
[114]619huvmat=findobj(allchild(0),'Tag','uvmat');
620hhuvmat=guidata(huvmat);
[332]621ny=str2double(get(hhuvmat.num_Npy,'String'));
[114]622x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates
[109]623n_ima=1;
[114]624GeometryCalib.CalibrationType='3D_extrinsic';
625GeometryCalib.fx_fy(1)=str2num(get(handles.fx,'String'));
626GeometryCalib.fx_fy(2)=str2num(get(handles.fy,'String'));
627GeometryCalib.Cx_Cy(1)=str2num(get(handles.Cx,'String'));
628GeometryCalib.Cx_Cy(2)=str2num(get(handles.Cy,'String'));
629GeometryCalib.kc=str2num(get(handles.kc,'String'));
[109]630fct_path=fullfile(path_UVMAT,'toolbox_calib');
631addpath(fct_path)
[116]632GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%reverse Cx_Cy(2) for calibration (inversion of px ordinate)
[109]633% [omc1,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,...
634%     [Calib.f Calib.f*Calib.sx]',...
635%     [Calib.Cx Calib.Cy]',...
636%     [-Calib.kappa1*Calib.f^2 0 0 0 0]);
[114]637[omc,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,...
[116]638    (GeometryCalib.fx_fy)',GeometryCalib.Cx_Cy',[GeometryCalib.kc 0 0 0 0]);
[109]639rmpath(fct_path);
640GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
641GeometryCalib.Tx_Ty_Tz=Tc1';
642%inversion of z axis
643GeometryCalib.R=Rc1;
[114]644GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate
645GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate
[116]646GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate
[114]647GeometryCalib.omc=(180/pi)*omc';
[109]648%GeometryCalib.R(3,1:3)=-GeometryCalib.R(3,1:3);%inversion for z upward
649
650
[116]651
[109]652%------------------------------------------------------------------------
653%function GeometryCalib=calib_tsai_heikkila(Coord)
654% TEST: NOT IMPLEMENTED
655%------------------------------------------------------------------
656% path_uvmat=which('uvmat');% check the path detected for source file uvmat
657% path_UVMAT=fileparts(path_uvmat); %path to UVMAT
658% path_calib=fullfile(path_UVMAT,'toolbox_calib_heikkila');
659% addpath(path_calib)
660% npoints=size(Coord,1);
661% Coord(:,1:3)=10*Coord(:,1:3);
662% Coord=[Coord zeros(npoints,2) -ones(npoints,1)];
663% [par,pos,iter,res,er,C]=cacal('dalsa',Coord);
664% GeometryCalib.CalibrationType='tsai';
665% GeometryCalib.focal=par(2);
666
667
668%------------------------------------------------------------------------
669% --- determine the rms of calibration error
670function ErrorRms=error_calib(calib_param,Calib,Coord)
671%calib_param: vector of free calibration parameters (to optimise)
672%Calib: structure of the given calibration parameters
673%Coord: list of phys coordinates (columns 1-3, and pixel coordinates (columns 4-5)
674Calib.f=25;
675Calib.dpx=0.012;
676Calib.dpy=0.012;
677Calib.sx=1;
678Calib.Cx=512;
679Calib.Cy=512;
680Calib.kappa1=calib_param(1);
681Calib.Tx=calib_param(2);
682Calib.Ty=calib_param(3);
683Calib.Tz=calib_param(4);
684alpha=calib_param(5);
685Calib.R=[cos(alpha) sin(alpha) 0;-sin(alpha) cos(alpha) 0;0 0 -1];
[2]686
[109]687X=Coord(:,1);
688Y=Coord(:,2);
689Z=Coord(:,3);
690x_ima=Coord(:,4);
691y_ima=Coord(:,5);
692[Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z);
693ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
694ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
695ErrorRms=mean(ErrorRms);
696
[60]697%------------------------------------------------------------------------
[2]698function XImage_Callback(hObject, eventdata, handles)
[60]699%------------------------------------------------------------------------
[2]700update_list(hObject, eventdata,handles)
701
[60]702%------------------------------------------------------------------------
[2]703function YImage_Callback(hObject, eventdata, handles)
[60]704%------------------------------------------------------------------------
[2]705update_list(hObject, eventdata,handles)
706
[109]707%------------------------------------------------------------------------
708% --- Executes on button press in STORE.
709function STORE_Callback(hObject, eventdata, handles)
710Coord_cell=get(handles.ListCoord,'String');
711Object=read_geometry_calib(Coord_cell);
712unitlist=get(handles.CoordUnit,'String');
713unit=unitlist{get(handles.CoordUnit,'value')};
714GeometryCalib.CoordUnit=unit;
715GeometryCalib.SourceCalib.PointCoord=Object.Coord;
716huvmat=findobj(allchild(0),'Name','uvmat');
717hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
[128]718% RootPath='';
719% RootFile='';
[121]720if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile)
[341]721%     testhandle=1;
[109]722    RootPath=get(hhuvmat.RootPath,'String');
723    RootFile=get(hhuvmat.RootFile,'String');
724    filebase=fullfile(RootPath,RootFile);
725    while exist([filebase '.xml'],'file')
726        filebase=[filebase '~'];
727    end
728    outputfile=[filebase '.xml'];
[630]729    errormsg=update_imadoc(GeometryCalib,outputfile,'GeometryCalib');
[114]730    if ~strcmp(errormsg,'')
731        msgbox_uvmat('ERROR',errormsg);
732    end
[109]733    listfile=get(handles.coord_files,'string');
734    if isequal(listfile,{''})
735        listfile={outputfile};
736    else
[128]737        listfile=[listfile;{outputfile}];%update the list of coord files
[109]738    end
739    set(handles.coord_files,'string',listfile);
740end
741set(handles.ListCoord,'Value',1)% refresh the display of coordinates
742set(handles.ListCoord,'String',{'......'})
743
[114]744% --------------------------------------------------------------------
745% --- Executes on button press in CLEAR_PTS: clear the list of calibration points
746function CLEAR_PTS_Callback(hObject, eventdata, handles)
747% --------------------------------------------------------------------
748set(handles.ListCoord,'Value',1)% refresh the display of coordinates
749set(handles.ListCoord,'String',{'......'})
[654]750PLOT_Callback(hObject, eventdata, handles)
[114]751
[654]752
[109]753%------------------------------------------------------------------------
754% --- Executes on button press in CLEAR.
755function CLEAR_Callback(hObject, eventdata, handles)
756%------------------------------------------------------------------------
757set(handles.coord_files,'Value',1)
758set(handles.coord_files,'String',{''})
759
760%------------------------------------------------------------------------
[2]761function XObject_Callback(hObject, eventdata, handles)
[109]762%------------------------------------------------------------------------
[2]763update_list(hObject, eventdata,handles)
764
[109]765%------------------------------------------------------------------------
[2]766function YObject_Callback(hObject, eventdata, handles)
[109]767%------------------------------------------------------------------------
[2]768update_list(hObject, eventdata,handles)
769
[109]770%------------------------------------------------------------------------
[2]771function ZObject_Callback(hObject, eventdata, handles)
[109]772%------------------------------------------------------------------------
[2]773update_list(hObject, eventdata,handles)
774
[60]775%------------------------------------------------------------------------
[2]776function update_list(hObject, eventdata, handles)
[60]777%------------------------------------------------------------------------
[149]778newval(4)=str2double(get(handles.XImage,'String'));
779newval(5)=str2double(get(handles.YImage,'String'));
780newval(1)=str2double(get(handles.XObject,'String'));
781newval(2)=str2double(get(handles.YObject,'String'));
782newval(3)=str2double(get(handles.ZObject,'String'));
783if isnan(newval(3))
784    newval(3)=0;%put z to 0 by default
[2]785end
786Coord=get(handles.ListCoord,'String');
[149]787Coord(end)=[]; %remove last string '.....'
[2]788val=get(handles.ListCoord,'Value');
[149]789data=read_geometry_calib(Coord);
790data.Coord(val,:)=newval;
791for i=1:size(data.Coord,1)
792    for j=1:5
793          Coord_cell{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits
794    end
795end
796
797Tabchar=cell2tab(Coord_cell,' | ');
798Tabchar=[Tabchar ;{'......'}];
799set(handles.ListCoord,'String',Tabchar)
800
[60]801%update the plot
802ListCoord_Callback(hObject, eventdata, handles)
[654]803PLOT_Callback(hObject, eventdata, handles)
[71]804
[60]805%------------------------------------------------------------------------
[2]806% --- Executes on selection change in ListCoord.
807function ListCoord_Callback(hObject, eventdata, handles)
[60]808%------------------------------------------------------------------------
[71]809huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
[542]810hplot=findobj(huvmat,'Tag','PlotAxes');%main plotting axis of uvmat
[71]811hhh=findobj(hplot,'Tag','calib_marker');
[2]812Coord_cell=get(handles.ListCoord,'String');
813val=get(handles.ListCoord,'Value');
[78]814if numel(val)>1
815    return %no action if several lines have been selected
816end
[71]817coord_str=Coord_cell{val};
[128]818k=findstr(' | ',coord_str);
[71]819if isempty(k)%last line '.....' selected
820    if ~isempty(hhh)
821        delete(hhh)%delete the circle marker
[2]822    end
[71]823    return
824end
[542]825%fill the edit boxe
[149]826set(handles.XObject,'String',coord_str(1:k(1)-1))
827set(handles.YObject,'String',coord_str(k(1)+3:k(2)-1))
828set(handles.ZObject,'String',coord_str(k(2)+3:k(3)-1))
829set(handles.XImage,'String',coord_str(k(3)+3:k(4)-1))
830set(handles.YImage,'String',coord_str(k(4)+3:end))
[591]831h_menu_coord=findobj(huvmat,'Tag','TransformName');
[71]832menu=get(h_menu_coord,'String');
833choice=get(h_menu_coord,'Value');
834if iscell(menu)
835    option=menu{choice};
836else
837    option='px'; %default
838end
839if isequal(option,'phys')
[149]840    XCoord=str2double(coord_str(1:k(1)-1));
841    YCoord=str2double(coord_str(k(1)+3:k(2)-1));
[71]842elseif isequal(option,'px')|| isequal(option,'')
[149]843    XCoord=str2double(coord_str(k(3)+3:k(4)-1));
844    YCoord=str2double(coord_str(k(4)+3:end));
[71]845else
846    msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be px or phys ')
847end
848if isempty(XCoord)||isempty(YCoord)
849     if ~isempty(hhh)
850        delete(hhh)%delete the circle marker
[2]851    end
[71]852    return
[2]853end
[71]854xlim=get(hplot,'XLim');
855ylim=get(hplot,'YLim');
856ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/20;%defines the size of the circle marker
857if isempty(hhh)
[149]858    set(0,'CurrentFig',huvmat)
859    set(huvmat,'CurrentAxes',hplot)
[71]860    rectangle('Curvature',[1 1],...
861              'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range],'EdgeColor','m',...
862              'LineStyle','-','Tag','calib_marker');
863else
864    set(hhh,'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range])
865end
[2]866
[60]867%------------------------------------------------------------------------
[2]868% --- Executes on selection change in edit_append.
869function edit_append_Callback(hObject, eventdata, handles)
[60]870%------------------------------------------------------------------------
[2]871choice=get(handles.edit_append,'Value');
[78]872if choice
873    set(handles.edit_append,'BackgroundColor',[1 1 0])
[177]874    huvmat=findobj(allchild(0),'tag','uvmat');
875    if ishandle(huvmat)
876        hhuvmat=guidata(huvmat);
877        set(hhuvmat.edit_object,'Value',0)
878        set(hhuvmat.edit_object,'BackgroundColor',[0.7 0.7 0.7])
879    end
[78]880else
881    set(handles.edit_append,'BackgroundColor',[0.7 0.7 0.7])
[2]882end
883   
884function NEW_Callback(hObject, eventdata, handles)
885%A METTRE SOUS UN BOUTON
886huvmat=findobj(allchild(0),'Name','uvmat');
887hchild=get(huvmat,'children');
888hcoord=findobj(hchild,'Tag','menu_coord');
889coordtype=get(hcoord,'Value');
890haxes=findobj(hchild,'Tag','axes3');
891AxeData=get(haxes,'UserData');
892if ~isequal(hcoord,2)
893    set(hcoord,'Value',2)
894    huvmat=uvmat(AxeData);
895    'relancer uvmat';
896end
897if ~isfield(AxeData,'ZoomAxes')
[42]898    msgbox_uvmat('ERROR','first draw a window around a grid marker')
[2]899    return
900end
901XLim=get(AxeData.ZoomAxes,'XLim');
902YLim=get(AxeData.ZoomAxes,'YLim');
903np=size(AxeData.A);
904ind_sub_x=round(XLim);
905ind_sub_y=np(1)-round(YLim);
[227]906Mfiltre=AxeData.A(ind_sub_y(2):ind_sub_y(1) ,ind_sub_x,:);
[2]907Mfiltre_norm=double(Mfiltre);
908Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm));
909Mfiltre_norm=100*(Mfiltre_norm-mean(mean(Mfiltre_norm)));
910Atype=class(AxeData.A);
911Data.NbDim=2;
912Data.A=filter2(Mfiltre_norm,double(AxeData.A));
913Data.A=feval(Atype,Data.A);
914Data.AName='image';
915Data.AX=AxeData.AX;
916Data.AY=AxeData.AY;
917Data.CoordType='px';
918plot_field(Data)
919
[541]920
[2]921% --------------------------------------------------------------------
922function MenuHelp_Callback(hObject, eventdata, handles)
[116]923path_to_uvmat=which('uvmat');% check the path of uvmat
[2]924pathelp=fileparts(path_to_uvmat);
[116]925helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
[36]926if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
[2]927else
[36]928   addpath (fullfile(pathelp,'uvmat_doc'))
[2]929   web([helpfile '#geometry_calib'])
930end
931
[654]932% --------------------------------------------------------------------
933function MenuSetScale_Callback(hObject, eventdata, handles)
934% hObject    handle to MenuSetScale (see GCBO)
935% eventdata  reserved - to be defined in a future version of MATLAB
936% handles    structure with handles and user data (see GUIDATA)
937 answer=msgbox_uvmat('INPUT_TXT','scale pixel/cm?','')
938 %create test points
939 huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
940UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
[655]941npy=size(UvData.Field.A,1);
942npx=size(UvData.Field.A,2);
943Xima=[0.25*npx 0.75*npx 0.75*npx 0.25*npx]';
944Yima=[0.25*npy 0.25*npy 0.75*npy 0.75*npy]';
[654]945x=Xima/str2num(answer);
946y=Yima/str2num(answer);
[655]947Coord={num2str(x(1)) num2str(y(1)) '0' num2str(Xima(1)) num2str(Yima(1));...
948    num2str(x(2)) num2str(y(2)) '0' num2str(Xima(2)) num2str(Yima(2));...
949    num2str(x(3)) num2str(y(3)) '0' num2str(Xima(3)) num2str(Yima(3));...
950    num2str(x(4)) num2str(y(4)) '0' num2str(Xima(4)) num2str(Yima(4))};
[654]951Tabchar=cell2tab(Coord,' | ');
952Tabchar=[Tabchar ;{'......'}];
953set(handles.ListCoord,'String',Tabchar)
954
[17]955%------------------------------------------------------------------------
[2]956function MenuCreateGrid_Callback(hObject, eventdata, handles)
[17]957%------------------------------------------------------------------------
[36]958%hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib
[61]959CalibData=get(handles.geometry_calib,'UserData');
[12]960Tinput=[];%default
961if isfield(CalibData,'grid')
962    Tinput=CalibData.grid;
963end
[71]964[T,CalibData.grid]=create_grid(Tinput);%display the GUI create_grid
[61]965set(handles.geometry_calib,'UserData',CalibData)
[2]966
[12]967%grid in phys space
[71]968Coord=get(handles.ListCoord,'String');
969val=get(handles.ListCoord,'Value');
970data=read_geometry_calib(Coord);
971%nbpoints=size(data.Coord,1); %nbre of calibration points
972data.Coord(val:val+size(T,1)-1,1:3)=T(end:-1:1,:);%update the existing list of phys coordinates from the GUI create_grid
973% for i=1:nbpoints
974%    for j=1:5
975%           Coord{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits
976%    end
977% end
978%update the phys coordinates starting from the selected point (down in the
979Coord(end,:)=[]; %remove last string '.....'
980for i=1:size(data.Coord,1)
981    for j=1:5
[17]982          Coord{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits
983    end
984end
985
986%size(data.Coord,1)
[128]987Tabchar=cell2tab(Coord,' | ');
[71]988Tabchar=[Tabchar ;{'......'}];
[12]989set(handles.ListCoord,'String',Tabchar)
[2]990
[71]991% -----------------------------------------------------------------------
992% --- automatic grid dectection from local maxima of the images
[60]993function MenuDetectGrid_Callback(hObject, eventdata, handles)
[71]994%------------------------------------------------------------------------
[159]995%% read the four last point coordinates in pixels
[108]996Coord_cell=get(handles.ListCoord,'String');%read list of coordinates on geometry_calib
[60]997data=read_geometry_calib(Coord_cell);
998nbpoints=size(data.Coord,1); %nbre of calibration points
[62]999if nbpoints~=4
[227]1000    msgbox_uvmat('ERROR','four points must have be selected by the mouse to delimitate the phys grid area; the Ox axis will be defined by the two first points')
[71]1001    return
[60]1002end
[71]1003corners_X=(data.Coord(end:-1:end-3,4)); %pixel absissa of the four corners
1004corners_Y=(data.Coord(end:-1:end-3,5));
[60]1005
[71]1006%reorder the last two points (the two first in the list) if needed
[121]1007angles=angle((corners_X-corners_X(1))+1i*(corners_Y-corners_Y(1)));
[62]1008if abs(angles(4)-angles(2))>abs(angles(3)-angles(2))
1009      X_end=corners_X(4);
1010      Y_end=corners_Y(4);
1011      corners_X(4)=corners_X(3);
1012      corners_Y(4)=corners_Y(3);
1013      corners_X(3)=X_end;
1014      corners_Y(3)=Y_end;
1015end
1016
[227]1017%% initiate the grid
1018CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib
1019grid_input=[];%default
1020if isfield(CalibData,'grid')
1021    grid_input=CalibData.grid;%retrieve the previously used grid
1022end
1023[T,CalibData.grid,white_test]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T
1024set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use
1025
1026
1027
[159]1028%% read the current image, displayed in the GUI uvmat
[60]1029huvmat=findobj(allchild(0),'Name','uvmat');
1030UvData=get(huvmat,'UserData');
1031A=UvData.Field.A;
1032npxy=size(A);
[159]1033X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates (cm)
1034Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates (cm)
[109]1035
[159]1036%calculate transform matrices for plane projection
[108]1037% reference: http://alumni.media.mit.edu/~cwren/interpolator/ by Christopher R. Wren
1038B = [ X Y ones(size(X)) zeros(4,3)        -X.*corners_X -Y.*corners_X ...
1039      zeros(4,3)        X Y ones(size(X)) -X.*corners_Y -Y.*corners_Y ];
1040B = reshape (B', 8 , 8 )';
1041D = [ corners_X , corners_Y ];
1042D = reshape (D', 8 , 1 );
[121]1043l = (B' * B)\B' * D;
[108]1044Amat = reshape([l(1:6)' 0 0 1 ],3,3)';
1045C = [l(7:8)' 1];
1046
[159]1047% transform grid image into 'phys' coordinates
[544]1048GeometryCalib.CalibrationType='linear';
[114]1049GeometryCalib.fx_fy=[1 1];
1050GeometryCalib.Tx_Ty_Tz=[Amat(1,3) Amat(2,3) 1];
[108]1051GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0];
[159]1052GeometryCalib.CoordUnit='cm';
[114]1053path_uvmat=which('uvmat');% check the path detected for source file uvmat
1054path_UVMAT=fileparts(path_uvmat); %path to UVMAT
1055addpath(fullfile(path_UVMAT,'transform_field'))
1056Data.ListVarName={'AY','AX','A'};
1057Data.VarDimName={'AY','AX',{'AY','AX'}};
1058if ndims(A)==3
1059    A=mean(A,3);
1060end
1061Data.A=A-min(min(A));
1062Data.AY=[npxy(1)-0.5 0.5];
1063Data.AX=[0.5 npxy(2)];
[158]1064Data.CoordUnit='pixel';
[114]1065Calib.GeometryCalib=GeometryCalib;
[121]1066DataOut=phys(Data,Calib);
[114]1067rmpath(fullfile(path_UVMAT,'transform_field'))
1068Amod=DataOut.A;
1069Rangx=DataOut.AX;
1070Rangy=DataOut.AY;
[156]1071if white_test
[159]1072    Amod=double(Amod);%case of white grid markers: will look for image maxima
[156]1073else
[159]1074    Amod=-double(Amod);%case of black grid markers: will look for image minima
[156]1075end
[114]1076% figure(12) %display corrected image
[109]1077% Amax=max(max(Amod));
1078% image(Rangx,Rangy,uint8(255*Amod/Amax))
[114]1079
[159]1080%% detection of local image extrema in each direction
[88]1081Dx=(Rangx(2)-Rangx(1))/(npxy(2)-1); %x mesh in real space
1082Dy=(Rangy(2)-Rangy(1))/(npxy(1)-1); %y mesh in real space
[121]1083ind_range_x=ceil(abs(GeometryCalib.R(1,1)*CalibData.grid.Dx/3));% range of search of image ma around each point obtained by linear interpolation from the marked points
1084ind_range_y=ceil(abs(GeometryCalib.R(2,2)*CalibData.grid.Dy/3));% range of search of image ma around each point obtained by linear interpolation from the marked points
[60]1085nbpoints=size(T,1);
1086for ipoint=1:nbpoints
1087    i0=1+round((T(ipoint,1)-Rangx(1))/Dx);%round(Xpx(ipoint));
1088    j0=1+round((T(ipoint,2)-Rangy(1))/Dy);%round(Xpx(ipoint));
[109]1089    j0min=max(j0-ind_range_y,1);
1090    j0max=min(j0+ind_range_y,size(Amod,1));
1091    i0min=max(i0-ind_range_x,1);
1092    i0max=min(i0+ind_range_x,size(Amod,2));
1093    Asub=Amod(j0min:j0max,i0min:i0max);
[60]1094    x_profile=sum(Asub,1);
1095    y_profile=sum(Asub,2);
1096    [Amax,ind_x_max]=max(x_profile);
1097    [Amax,ind_y_max]=max(y_profile);
[61]1098    %sub-pixel improvement using moments
1099    x_shift=0;
1100    y_shift=0;
[109]1101    if ind_x_max+2<=numel(x_profile) && ind_x_max-2>=1
[61]1102        Atop=x_profile(ind_x_max-2:ind_x_max+2);
1103        x_shift=sum(Atop.*[-2 -1 0 1 2])/sum(Atop);
1104    end
[114]1105    if ind_y_max+2<=numel(y_profile) && ind_y_max-2>=1
[61]1106        Atop=y_profile(ind_y_max-2:ind_y_max+2);
1107        y_shift=sum(Atop.*[-2 -1 0 1 2]')/sum(Atop);
1108    end
[109]1109    Delta(ipoint,1)=(x_shift+ind_x_max+i0min-i0-1)*Dx;%shift from the initial guess
1110    Delta(ipoint,2)=(y_shift+ind_y_max+j0min-j0-1)*Dy;
[60]1111end
1112Tmod=T(:,(1:2))+Delta;
1113[Xpx,Ypx]=px_XYZ(GeometryCalib,Tmod(:,1),Tmod(:,2));
[63]1114for ipoint=1:nbpoints
1115     Coord{ipoint,1}=num2str(T(ipoint,1),4);%display coordiantes with 4 digits
1116     Coord{ipoint,2}=num2str(T(ipoint,2),4);%display coordiantes with 4 digits
[109]1117     Coord{ipoint,3}=num2str(T(ipoint,3),4);%display coordiantes with 4 digits;
1118     Coord{ipoint,4}=num2str(Xpx(ipoint),4);%display coordiantes with 4 digits
1119     Coord{ipoint,5}=num2str(Ypx(ipoint),4);%display coordiantes with 4 digits
[60]1120end
[128]1121Tabchar=cell2tab(Coord(end:-1:1,:),' | ');
[71]1122Tabchar=[Tabchar ;{'......'}];
[60]1123set(handles.ListCoord,'Value',1)
1124set(handles.ListCoord,'String',Tabchar)
[654]1125PLOT_Callback(hObject, eventdata, handles)
[60]1126
[71]1127%-----------------------------------------------------------------------
1128function MenuTranslatePoints_Callback(hObject, eventdata, handles)
1129%-----------------------------------------------------------------------
1130%hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib
1131CalibData=get(handles.geometry_calib,'UserData');
1132Tinput=[];%default
1133if isfield(CalibData,'translate')
1134    Tinput=CalibData.translate;
1135end
1136T=translate_points(Tinput);%display translate_points GUI and get shift parameters
1137CalibData.translate=T;
1138set(handles.geometry_calib,'UserData',CalibData)
1139%translation
1140Coord_cell=get(handles.ListCoord,'String');
1141data=read_geometry_calib(Coord_cell);
1142data.Coord(:,1)=T(1)+data.Coord(:,1);
1143data.Coord(:,2)=T(2)+data.Coord(:,2);
1144data.Coord(:,3)=T(3)+data.Coord(:,3);
1145data.Coord(:,[4 5])=data.Coord(:,[4 5]);
1146for i=1:size(data.Coord,1)
1147    for j=1:5
1148          Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z
1149   end
1150end
[128]1151Tabchar=cell2tab(Coord,' | ');
[88]1152Tabchar=[Tabchar; {'.....'}];
[71]1153%set(handles.ListCoord,'Value',1)
1154set(handles.ListCoord,'String',Tabchar)
1155
1156
1157% --------------------------------------------------------------------
1158function MenuRotatePoints_Callback(hObject, eventdata, handles)
1159%hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib
1160CalibData=get(handles.geometry_calib,'UserData');
1161Tinput=[];%default
1162if isfield(CalibData,'rotate')
1163    Tinput=CalibData.rotate;
1164end
[356]1165T=rotate_points(Tinput);%display rotate_points GUI to introduce rotation parameters
[71]1166CalibData.rotate=T;
1167set(handles.geometry_calib,'UserData',CalibData)
1168%-----------------------------------------------------
1169%rotation
1170Phi=T(1);
1171O_x=0;%default
1172O_y=0;%default
1173if numel(T)>=2
1174    O_x=T(2);%default
1175end
1176if numel(T)>=3
1177    O_y=T(3);%default
1178end
1179Coord_cell=get(handles.ListCoord,'String');
1180data=read_geometry_calib(Coord_cell);
1181r1=cos(pi*Phi/180);
1182r2=-sin(pi*Phi/180);
1183r3=sin(pi*Phi/180);
1184r4=cos(pi*Phi/180);
1185x=data.Coord(:,1)-O_x;
1186y=data.Coord(:,2)-O_y;
1187data.Coord(:,1)=r1*x+r2*y;
1188data.Coord(:,2)=r3*x+r4*y;
1189% data.Coord(:,[4 5])=data.Coord(:,[4 5]);
1190for i=1:size(data.Coord,1)
1191    for j=1:5
1192          Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z
1193   end
1194end
[148]1195Tabchar=cell2tab(Coord,' | ');
[71]1196Tabchar=[Tabchar;{'......'}];
1197set(handles.ListCoord,'Value',1)
1198set(handles.ListCoord,'String',Tabchar)
1199
[109]1200% --------------------------------------------------------------------
1201function MenuImportPoints_Callback(hObject, eventdata, handles)
[121]1202fileinput=browse_xml(hObject, eventdata, handles);
[109]1203if isempty(fileinput)
1204    return
1205end
1206[s,errormsg]=imadoc2struct(fileinput,'GeometryCalib');
1207GeometryCalib=s.GeometryCalib;
[114]1208%GeometryCalib=load_calib(hObject, eventdata, handles)
[655]1209calib=reshape(GeometryCalib.SourceCalib.PointCoord,[],1);
[109]1210for ilist=1:numel(calib)
1211    CoordCell{ilist}=num2str(calib(ilist));
1212end
1213CoordCell=reshape(CoordCell,[],5);
[128]1214Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display
[109]1215Tabchar=[Tabchar;{'......'}];
1216set(handles.ListCoord,'Value',1)
1217set(handles.ListCoord,'String',Tabchar)
[654]1218PLOT_Callback(handles.geometry_calib, [], handles)
[109]1219
1220% -----------------------------------------------------------------------
1221function MenuImportIntrinsic_Callback(hObject, eventdata, handles)
1222%------------------------------------------------------------------------
1223fileinput=browse_xml(hObject, eventdata, handles);
1224if isempty(fileinput)
1225    return
1226end
1227[s,errormsg]=imadoc2struct(fileinput,'GeometryCalib');
1228GeometryCalib=s.GeometryCalib;
[114]1229display_intrinsic(GeometryCalib,handles)
[109]1230
1231% -----------------------------------------------------------------------
1232function MenuImportAll_Callback(hObject, eventdata, handles)
1233%------------------------------------------------------------------------
[121]1234fileinput=browse_xml(hObject, eventdata, handles);
[109]1235if ~isempty(fileinput)
1236    loadfile(handles,fileinput)
1237end
1238
1239% -----------------------------------------------------------------------
1240% --- Executes on menubar option Import/Grid file: introduce previous grid files
1241function MenuGridFile_Callback(hObject, eventdata, handles)
1242% -----------------------------------------------------------------------
[121]1243inputfile=browse_xml(hObject, eventdata, handles);
[109]1244listfile=get(handles.coord_files,'string');
1245if isequal(listfile,{''})
1246    listfile={inputfile};
1247else
[121]1248    listfile=[listfile;{inputfile}];%update the list of coord files
[109]1249end
1250set(handles.coord_files,'string',listfile);
1251
1252%------------------------------------------------------------------------
[114]1253% --- 'key_press_fcn:' function activated when a key is pressed on the keyboard
1254function key_press_fcn(hObject,eventdata,handles)
1255%------------------------------------------------------------------------
1256xx=double(get(handles.geometry_calib,'CurrentCharacter')); %get the keyboard character
1257if ismember(xx,[8 127])%backspace or delete
1258    Coord_cell=get(handles.ListCoord,'String');
1259    val=get(handles.ListCoord,'Value');
1260     if max(val)<numel(Coord_cell) % the last element '...' has not been selected
1261        Coord_cell(val)=[];%remove the selected line
1262        set(handles.ListCoord,'Value',min(val))
1263        set(handles.ListCoord,'String',Coord_cell)         
1264        ListCoord_Callback(hObject, eventdata, handles)
[654]1265        PLOT_Callback(hObject,eventdata,handles)
[114]1266     end
1267end
1268
1269%------------------------------------------------------------------------
[109]1270function fileinput=browse_xml(hObject, eventdata, handles)
1271%------------------------------------------------------------------------
1272fileinput=[];%default
1273oldfile=''; %default
[116]1274UserData=get(handles.geometry_calib,'UserData');
[114]1275if isfield(UserData,'XmlInputFile')
1276    oldfile=UserData.XmlInputFile;
[109]1277end
1278[FileName, PathName, filterindex] = uigetfile( ...
1279       {'*.xml;*.mat', ' (*.xml,*.mat)';
1280       '*.xml',  '.xml files '; ...
1281        '*.mat',  '.mat matlab files '}, ...
1282        'Pick a file',oldfile);
1283fileinput=[PathName FileName];%complete file name
1284testblank=findstr(fileinput,' ');%look for blanks
1285if ~isempty(testblank)
1286    msgbox_uvmat('ERROR','forbidden input file name or path: no blank character allowed')
1287    return
1288end
1289sizf=size(fileinput);
1290if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
[114]1291UserData.XmlInputFile=fileinput;
[109]1292set(handles.geometry_calib,'UserData',UserData)%record current file foer further use of browser
1293
1294% -----------------------------------------------------------------------
[128]1295function Heading=loadfile(handles,fileinput)
[109]1296%------------------------------------------------------------------------
[128]1297Heading=[];%default
[565]1298[s,errormsg]=imadoc2struct(fileinput,'Heading','GeometryCalib');
[128]1299if ~isempty(errormsg)
[502]1300    msgbox_uvmat('ERROR',errormsg)
[128]1301    return
1302end
1303if ~isempty(s.Heading)
1304    Heading=s.Heading;
1305end
1306   
[116]1307GeometryCalib=s.GeometryCalib;
[114]1308fx=1;fy=1;Cx=0;Cy=0;kc=0; %default
1309CoordCell={};
1310Tabchar={};%default
1311val_cal=1;%default
1312if ~isempty(GeometryCalib)
1313    % choose the calibration option
1314    if isfield(GeometryCalib,'CalibrationType')
1315       calib_list=get(handles.calib_type,'String');
1316       for ilist=1:numel(calib_list)
1317           if strcmp(calib_list{ilist},GeometryCalib.CalibrationType)
1318               val_cal=ilist;
1319               break
1320           end
1321       end
1322    end
1323    display_intrinsic(GeometryCalib,handles)%intrinsic param
1324    %extrinsic param
1325    if isfield(GeometryCalib,'Tx_Ty_Tz')
1326        Tx_Ty_Tz=GeometryCalib.Tx_Ty_Tz;
1327        set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4))
1328        set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4))
1329        set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4))
1330    end
1331    if isfield(GeometryCalib,'omc')
1332        set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4))
1333        set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4))
1334        set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))
1335    end
[565]1336    calib=reshape(GeometryCalib.SourceCalib.PointCoord,[],1);
[109]1337    for ilist=1:numel(calib)
1338        CoordCell{ilist}=num2str(calib(ilist));
1339    end
1340    CoordCell=reshape(CoordCell,[],5);
[128]1341    Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display
[654]1342    PLOT_Callback(handles.geometry_calib, [], handles)
[109]1343end
[114]1344set(handles.calib_type,'Value',val_cal)
[109]1345Tabchar=[Tabchar;{'......'}];
[114]1346set(handles.ListCoord,'Value',1)
1347set(handles.ListCoord,'String',Tabchar)
1348
[109]1349if isempty(CoordCell)% allow mouse action by default in the absence of input points
1350    set(handles.edit_append,'Value',1)
1351    set(handles.edit_append,'BackgroundColor',[1 1 0])
1352else % does not allow mouse action by default in the presence of input points
1353    set(handles.edit_append,'Value',0)
1354    set(handles.edit_append,'BackgroundColor',[0.7 0.7 0.7])
1355end
1356
[114]1357%------------------------------------------------------------------------
1358%---display calibration intrinsic parameters
1359function display_intrinsic(GeometryCalib,handles)
1360%------------------------------------------------------------------------
1361fx=[];
1362fy=[];
1363if isfield(GeometryCalib,'fx_fy')
1364    fx=GeometryCalib.fx_fy(1);
1365    fy=GeometryCalib.fx_fy(2);
1366end
1367Cx_Cy=[0 0];%default
1368if isfield(GeometryCalib,'Cx_Cy')
1369    Cx_Cy=GeometryCalib.Cx_Cy;
1370end
1371kc=0;
1372if isfield(GeometryCalib,'kc')
[121]1373    kc=GeometryCalib.kc; %* GeometryCalib.focal*GeometryCalib.focal;
[114]1374end
1375set(handles.fx,'String',num2str(fx,5))
1376set(handles.fy,'String',num2str(fy,5))
1377set(handles.Cx,'String',num2str(Cx_Cy(1),'%1.1f'))
1378set(handles.Cy,'String',num2str(Cx_Cy(2),'%1.1f'))
1379set(handles.kc,'String',num2str(kc,'%1.4f'))
[109]1380
1381
[507]1382% --- Executes when user attempts to close geometry_calib.
1383function geometry_calib_CloseRequestFcn(hObject, eventdata, handles)
1384% hObject    handle to geometry_calib (see GCBO)
1385% eventdata  reserved - to be defined in a future version of MATLAB
1386% handles    structure with handles and user data (see GUIDATA)
1387
1388% Hint: delete(hObject) closes the figure
1389delete(hObject);
[654]1390
1391%------------------------------------------------------------------------
1392% --- Executes on button press in PLOT.
1393%------------------------------------------------------------------------
1394function PLOT_Callback(hObject, eventdata, handles)
1395
1396huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
1397%UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
1398hhuvmat=guidata(huvmat); %handles of GUI elements in uvmat
1399%hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat
1400h_menu_coord=findobj(huvmat,'Tag','TransformName');
1401menu=get(h_menu_coord,'String');
1402choice=get(h_menu_coord,'Value');
1403if iscell(menu)
1404    option=menu{choice};
1405else
1406    option='px'; %default
1407end
1408Coord_cell=get(handles.ListCoord,'String');
1409ObjectData=read_geometry_calib(Coord_cell);
1410%ObjectData=read_geometry_calib(handles);%read the interface input parameters defining the object
1411if ~isempty(ObjectData.Coord)
1412    if isequal(option,'phys')
1413        ObjectData.Coord=ObjectData.Coord(:,1:3);
1414    elseif isequal(option,'px')||isequal(option,'')
1415        ObjectData.Coord=ObjectData.Coord(:,4:5);
1416    else
1417        msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be '''', px or phys ')
1418    end
1419end
1420
1421set(0,'CurrentFigure',huvmat)
1422set(huvmat,'CurrentAxes',hhuvmat.PlotAxes)
1423hh=findobj('Tag','calib_points');
1424if  ~isempty(ObjectData.Coord) && isempty(hh)
1425    hh=line(ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
1426elseif isempty(ObjectData.Coord)%empty list of points, suppress the plot
1427    delete(hh)
1428else
1429    set(hh,'XData',ObjectData.Coord(:,1))
1430    set(hh,'YData',ObjectData.Coord(:,2))
1431end
1432pause(.1)
1433figure(handles.geometry_calib)
1434
1435
1436 
Note: See TracBrowser for help on using the repository browser.