source: trunk/src/geometry_calib.m @ 662

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

a few bugs corrected in geometry_calib

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