source: trunk/src/geometry_calib.m @ 657

Last change on this file since 657 was 657, checked in by sommeria, 7 years ago

a few bugs corrected

File size: 57.7 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 03-Jul-2013 09:23:35
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.coord_files,'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 coord_files
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.coord_files,'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 coord_files
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.coord_files,'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.coord_files,'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.coord_files,'Value',1)
765set(handles.coord_files,'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 edit_append.
814function edit_append_Callback(hObject, eventdata, handles)
815%------------------------------------------------------------------------
816choice=get(handles.edit_append,'Value');
817if choice
818    set(handles.edit_append,'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.edit_append,'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,'String');
921val=get(handles.ListCoord,'Value');
922data=read_geometry_calib(Coord);
923%nbpoints=size(data.Coord,1); %nbre of calibration points
924data.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
925% for i=1:nbpoints
926%    for j=1:5
927%           Coord{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits
928%    end
929% end
930%update the phys coordinates starting from the selected point (down in the
931Coord(end,:)=[]; %remove last string '.....'
932for i=1:size(data.Coord,1)
933    for j=1:5
934          Coord{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits
935    end
936end
937
938%size(data.Coord,1)
939Tabchar=cell2tab(Coord,' | ');
940Tabchar=[Tabchar ;{'......'}];
941set(handles.ListCoord,'String',Tabchar)
942
943% -----------------------------------------------------------------------
944% --- automatic grid dectection from local maxima of the images
945function MenuDetectGrid_Callback(hObject, eventdata, handles)
946%------------------------------------------------------------------------
947%% read the four last point coordinates in pixels
948Coord_cell=get(handles.ListCoord,'String');%read list of coordinates on geometry_calib
949data=read_geometry_calib(Coord_cell);
950nbpoints=size(data.Coord,1); %nbre of calibration points
951if nbpoints~=4
952    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')
953    return
954end
955corners_X=(data.Coord(end:-1:end-3,4)); %pixel absissa of the four corners
956corners_Y=(data.Coord(end:-1:end-3,5));
957
958%reorder the last two points (the two first in the list) if needed
959angles=angle((corners_X-corners_X(1))+1i*(corners_Y-corners_Y(1)));
960if abs(angles(4)-angles(2))>abs(angles(3)-angles(2))
961      X_end=corners_X(4);
962      Y_end=corners_Y(4);
963      corners_X(4)=corners_X(3);
964      corners_Y(4)=corners_Y(3);
965      corners_X(3)=X_end;
966      corners_Y(3)=Y_end;
967end
968
969%% initiate the grid
970CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib
971grid_input=[];%default
972if isfield(CalibData,'grid')
973    grid_input=CalibData.grid;%retrieve the previously used grid
974end
975[T,CalibData.grid,white_test]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T
976set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use
977
978
979
980%% read the current image, displayed in the GUI uvmat
981huvmat=findobj(allchild(0),'Name','uvmat');
982UvData=get(huvmat,'UserData');
983A=UvData.Field.A;
984npxy=size(A);
985X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates (cm)
986Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates (cm)
987
988%calculate transform matrices for plane projection
989% reference: http://alumni.media.mit.edu/~cwren/interpolator/ by Christopher R. Wren
990B = [ X Y ones(size(X)) zeros(4,3)        -X.*corners_X -Y.*corners_X ...
991      zeros(4,3)        X Y ones(size(X)) -X.*corners_Y -Y.*corners_Y ];
992B = reshape (B', 8 , 8 )';
993D = [ corners_X , corners_Y ];
994D = reshape (D', 8 , 1 );
995l = (B' * B)\B' * D;
996Amat = reshape([l(1:6)' 0 0 1 ],3,3)';
997C = [l(7:8)' 1];
998
999% transform grid image into 'phys' coordinates
1000GeometryCalib.CalibrationType='linear';
1001GeometryCalib.fx_fy=[1 1];
1002GeometryCalib.Tx_Ty_Tz=[Amat(1,3) Amat(2,3) 1];
1003GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0];
1004GeometryCalib.CoordUnit='cm';
1005path_uvmat=which('uvmat');% check the path detected for source file uvmat
1006path_UVMAT=fileparts(path_uvmat); %path to UVMAT
1007addpath(fullfile(path_UVMAT,'transform_field'))
1008Data.ListVarName={'AY','AX','A'};
1009Data.VarDimName={'AY','AX',{'AY','AX'}};
1010if ndims(A)==3
1011    A=mean(A,3);
1012end
1013Data.A=A-min(min(A));
1014Data.AY=[npxy(1)-0.5 0.5];
1015Data.AX=[0.5 npxy(2)];
1016Data.CoordUnit='pixel';
1017Calib.GeometryCalib=GeometryCalib;
1018DataOut=phys(Data,Calib);
1019rmpath(fullfile(path_UVMAT,'transform_field'))
1020Amod=DataOut.A;
1021Rangx=DataOut.AX;
1022Rangy=DataOut.AY;
1023if white_test
1024    Amod=double(Amod);%case of white grid markers: will look for image maxima
1025else
1026    Amod=-double(Amod);%case of black grid markers: will look for image minima
1027end
1028% figure(12) %display corrected image
1029% Amax=max(max(Amod));
1030% image(Rangx,Rangy,uint8(255*Amod/Amax))
1031
1032%% detection of local image extrema in each direction
1033Dx=(Rangx(2)-Rangx(1))/(npxy(2)-1); %x mesh in real space
1034Dy=(Rangy(2)-Rangy(1))/(npxy(1)-1); %y mesh in real space
1035ind_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
1036ind_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
1037nbpoints=size(T,1);
1038for ipoint=1:nbpoints
1039    i0=1+round((T(ipoint,1)-Rangx(1))/Dx);%round(Xpx(ipoint));
1040    j0=1+round((T(ipoint,2)-Rangy(1))/Dy);%round(Xpx(ipoint));
1041    j0min=max(j0-ind_range_y,1);
1042    j0max=min(j0+ind_range_y,size(Amod,1));
1043    i0min=max(i0-ind_range_x,1);
1044    i0max=min(i0+ind_range_x,size(Amod,2));
1045    Asub=Amod(j0min:j0max,i0min:i0max);
1046    x_profile=sum(Asub,1);
1047    y_profile=sum(Asub,2);
1048    [Amax,ind_x_max]=max(x_profile);
1049    [Amax,ind_y_max]=max(y_profile);
1050    %sub-pixel improvement using moments
1051    x_shift=0;
1052    y_shift=0;
1053    if ind_x_max+2<=numel(x_profile) && ind_x_max-2>=1
1054        Atop=x_profile(ind_x_max-2:ind_x_max+2);
1055        x_shift=sum(Atop.*[-2 -1 0 1 2])/sum(Atop);
1056    end
1057    if ind_y_max+2<=numel(y_profile) && ind_y_max-2>=1
1058        Atop=y_profile(ind_y_max-2:ind_y_max+2);
1059        y_shift=sum(Atop.*[-2 -1 0 1 2]')/sum(Atop);
1060    end
1061    Delta(ipoint,1)=(x_shift+ind_x_max+i0min-i0-1)*Dx;%shift from the initial guess
1062    Delta(ipoint,2)=(y_shift+ind_y_max+j0min-j0-1)*Dy;
1063end
1064Tmod=T(:,(1:2))+Delta;
1065[Xpx,Ypx]=px_XYZ(GeometryCalib,Tmod(:,1),Tmod(:,2));
1066for ipoint=1:nbpoints
1067     Coord{ipoint,1}=num2str(T(ipoint,1),4);%display coordiantes with 4 digits
1068     Coord{ipoint,2}=num2str(T(ipoint,2),4);%display coordiantes with 4 digits
1069     Coord{ipoint,3}=num2str(T(ipoint,3),4);%display coordiantes with 4 digits;
1070     Coord{ipoint,4}=num2str(Xpx(ipoint),4);%display coordiantes with 4 digits
1071     Coord{ipoint,5}=num2str(Ypx(ipoint),4);%display coordiantes with 4 digits
1072end
1073Tabchar=cell2tab(Coord(end:-1:1,:),' | ');
1074Tabchar=[Tabchar ;{'......'}];
1075set(handles.ListCoord,'Value',1)
1076set(handles.ListCoord,'String',Tabchar)
1077PLOT_Callback(hObject, eventdata, handles)
1078
1079%-----------------------------------------------------------------------
1080function MenuTranslatePoints_Callback(hObject, eventdata, handles)
1081%-----------------------------------------------------------------------
1082%hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib
1083CalibData=get(handles.geometry_calib,'UserData');
1084Tinput=[];%default
1085if isfield(CalibData,'translate')
1086    Tinput=CalibData.translate;
1087end
1088T=translate_points(Tinput);%display translate_points GUI and get shift parameters
1089CalibData.translate=T;
1090set(handles.geometry_calib,'UserData',CalibData)
1091%translation
1092Coord_cell=get(handles.ListCoord,'String');
1093data=read_geometry_calib(Coord_cell);
1094data.Coord(:,1)=T(1)+data.Coord(:,1);
1095data.Coord(:,2)=T(2)+data.Coord(:,2);
1096data.Coord(:,3)=T(3)+data.Coord(:,3);
1097data.Coord(:,[4 5])=data.Coord(:,[4 5]);
1098for i=1:size(data.Coord,1)
1099    for j=1:5
1100          Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z
1101   end
1102end
1103Tabchar=cell2tab(Coord,' | ');
1104Tabchar=[Tabchar; {'.....'}];
1105%set(handles.ListCoord,'Value',1)
1106set(handles.ListCoord,'String',Tabchar)
1107
1108
1109% --------------------------------------------------------------------
1110function MenuRotatePoints_Callback(hObject, eventdata, handles)
1111%hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib
1112CalibData=get(handles.geometry_calib,'UserData');
1113Tinput=[];%default
1114if isfield(CalibData,'rotate')
1115    Tinput=CalibData.rotate;
1116end
1117T=rotate_points(Tinput);%display rotate_points GUI to introduce rotation parameters
1118CalibData.rotate=T;
1119set(handles.geometry_calib,'UserData',CalibData)
1120%-----------------------------------------------------
1121%rotation
1122Phi=T(1);
1123O_x=0;%default
1124O_y=0;%default
1125if numel(T)>=2
1126    O_x=T(2);%default
1127end
1128if numel(T)>=3
1129    O_y=T(3);%default
1130end
1131Coord_cell=get(handles.ListCoord,'String');
1132data=read_geometry_calib(Coord_cell);
1133r1=cos(pi*Phi/180);
1134r2=-sin(pi*Phi/180);
1135r3=sin(pi*Phi/180);
1136r4=cos(pi*Phi/180);
1137x=data.Coord(:,1)-O_x;
1138y=data.Coord(:,2)-O_y;
1139data.Coord(:,1)=r1*x+r2*y;
1140data.Coord(:,2)=r3*x+r4*y;
1141% data.Coord(:,[4 5])=data.Coord(:,[4 5]);
1142for i=1:size(data.Coord,1)
1143    for j=1:5
1144          Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z
1145   end
1146end
1147Tabchar=cell2tab(Coord,' | ');
1148Tabchar=[Tabchar;{'......'}];
1149set(handles.ListCoord,'Value',1)
1150set(handles.ListCoord,'String',Tabchar)
1151
1152% --------------------------------------------------------------------
1153function MenuImportPoints_Callback(hObject, eventdata, handles)
1154fileinput=browse_xml(hObject, eventdata, handles);
1155if isempty(fileinput)
1156    return
1157end
1158[s,errormsg]=imadoc2struct(fileinput,'GeometryCalib');
1159GeometryCalib=s.GeometryCalib;
1160%GeometryCalib=load_calib(hObject, eventdata, handles)
1161% calib=reshape(GeometryCalib.SourceCalib.PointCoord,[],1);
1162% for ilist=1:numel(calib)
1163%     CoordCell{ilist}=num2str(calib(ilist));
1164% end
1165% CoordCell=reshape(CoordCell,[],5);
1166% Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display
1167% Tabchar=[Tabchar;{'......'}];
1168% set(handles.ListCoord,'Value',1)
1169% set(handles.ListCoord,'String',Tabchar)
1170Coord=GeometryCalib.SourceCalib.PointCoord;
1171Coord=[Coord zeros(size(Coord,1),1)]
1172set(handles.ListCoord,'Data',Coord)
1173PLOT_Callback(handles.geometry_calib, [], handles)
1174
1175% -----------------------------------------------------------------------
1176function MenuImportIntrinsic_Callback(hObject, eventdata, handles)
1177%------------------------------------------------------------------------
1178fileinput=browse_xml(hObject, eventdata, handles);
1179if isempty(fileinput)
1180    return
1181end
1182[s,errormsg]=imadoc2struct(fileinput,'GeometryCalib');
1183GeometryCalib=s.GeometryCalib;
1184display_intrinsic(GeometryCalib,handles)
1185
1186% -----------------------------------------------------------------------
1187function MenuImportAll_Callback(hObject, eventdata, handles)
1188%------------------------------------------------------------------------
1189fileinput=browse_xml(hObject, eventdata, handles);
1190if ~isempty(fileinput)
1191    loadfile(handles,fileinput)
1192end
1193
1194% -----------------------------------------------------------------------
1195% --- Executes on menubar option Import/Grid file: introduce previous grid files
1196function MenuGridFile_Callback(hObject, eventdata, handles)
1197% -----------------------------------------------------------------------
1198inputfile=browse_xml(hObject, eventdata, handles);
1199listfile=get(handles.coord_files,'string');
1200if isequal(listfile,{''})
1201    listfile={inputfile};
1202else
1203    listfile=[listfile;{inputfile}];%update the list of coord files
1204end
1205set(handles.coord_files,'string',listfile);
1206
1207%------------------------------------------------------------------------
1208% --- 'key_press_fcn:' function activated when a key is pressed on the keyboard
1209function key_press_fcn(hObject,eventdata,handles)
1210%------------------------------------------------------------------------
1211xx=double(get(handles.geometry_calib,'CurrentCharacter')); %get the keyboard character
1212%if ismember(xx,[8 127])%backspace or delete
1213if ismember(xx,[30 31 8 127])
1214    Coord=get(handles.ListCoord,'Data');
1215    ind=find(Coord(:,6));
1216    Coord(:,6)=zeros(size(Coord,1),1);% desactivate the current line mark
1217    switch xx
1218        case 30 % arrow upward
1219            Coord(ind-1,6)=1;
1220        case 31% arrow downward
1221            Coord(ind+1,6)=1;
1222        case {8 127}% remove line
1223            Coord(ind,:)=[];
1224    end
1225    set(handles.ListCoord,'Data',Coord);
1226    PLOT_Callback(hObject,eventdata,handles)
1227end
1228
1229
1230
1231%------------------------------------------------------------------------
1232function fileinput=browse_xml(hObject, eventdata, handles)
1233%------------------------------------------------------------------------
1234fileinput=[];%default
1235oldfile=''; %default
1236UserData=get(handles.geometry_calib,'UserData');
1237if isfield(UserData,'XmlInputFile')
1238    oldfile=UserData.XmlInputFile;
1239end
1240[FileName, PathName, filterindex] = uigetfile( ...
1241       {'*.xml;*.mat', ' (*.xml,*.mat)';
1242       '*.xml',  '.xml files '; ...
1243        '*.mat',  '.mat matlab files '}, ...
1244        'Pick a file',oldfile);
1245fileinput=[PathName FileName];%complete file name
1246testblank=findstr(fileinput,' ');%look for blanks
1247if ~isempty(testblank)
1248    msgbox_uvmat('ERROR','forbidden input file name or path: no blank character allowed')
1249    return
1250end
1251sizf=size(fileinput);
1252if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1253UserData.XmlInputFile=fileinput;
1254set(handles.geometry_calib,'UserData',UserData)%record current file foer further use of browser
1255
1256% -----------------------------------------------------------------------
1257function Heading=loadfile(handles,fileinput)
1258%------------------------------------------------------------------------
1259Heading=[];%default
1260[s,errormsg]=imadoc2struct(fileinput,'Heading','GeometryCalib');
1261if ~isempty(errormsg)
1262    msgbox_uvmat('ERROR',errormsg)
1263    return
1264end
1265if ~isempty(s.Heading)
1266    Heading=s.Heading;
1267end
1268   
1269GeometryCalib=s.GeometryCalib;
1270fx=1;fy=1;Cx=0;Cy=0;kc=0; %default
1271CoordCell={};
1272Tabchar={};%default
1273val_cal=1;%default
1274if ~isempty(GeometryCalib)
1275    % choose the calibration option
1276    if isfield(GeometryCalib,'CalibrationType')
1277       calib_list=get(handles.calib_type,'String');
1278       for ilist=1:numel(calib_list)
1279           if strcmp(calib_list{ilist},GeometryCalib.CalibrationType)
1280               val_cal=ilist;
1281               break
1282           end
1283       end
1284    end
1285    display_intrinsic(GeometryCalib,handles)%intrinsic param
1286    %extrinsic param
1287    if isfield(GeometryCalib,'Tx_Ty_Tz')
1288        Tx_Ty_Tz=GeometryCalib.Tx_Ty_Tz;
1289        set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4))
1290        set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4))
1291        set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4))
1292    end
1293    if isfield(GeometryCalib,'omc')
1294        set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4))
1295        set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4))
1296        set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))
1297    end
1298    calib=GeometryCalib.SourceCalib.PointCoord;
1299    Coord=[calib zeros(size(calib,1),1)];
1300    set(handles.ListCoord,'Data',Coord)
1301%     CoordCell=reshape(CoordCell,[],5);
1302%     Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display
1303    PLOT_Callback(handles.geometry_calib, [], handles)
1304end
1305set(handles.calib_type,'Value',val_cal)
1306% Tabchar=[Tabchar;{'......'}];
1307% set(handles.ListCoord,'Value',1)
1308
1309if isempty(CoordCell)% allow mouse action by default in the absence of input points
1310    set(handles.edit_append,'Value',1)
1311    set(handles.edit_append,'BackgroundColor',[1 1 0])
1312else % does not allow mouse action by default in the presence of input points
1313    set(handles.edit_append,'Value',0)
1314    set(handles.edit_append,'BackgroundColor',[0.7 0.7 0.7])
1315end
1316
1317%------------------------------------------------------------------------
1318%---display calibration intrinsic parameters
1319function display_intrinsic(GeometryCalib,handles)
1320%------------------------------------------------------------------------
1321fx=[];
1322fy=[];
1323if isfield(GeometryCalib,'fx_fy')
1324    fx=GeometryCalib.fx_fy(1);
1325    fy=GeometryCalib.fx_fy(2);
1326end
1327Cx_Cy=[0 0];%default
1328if isfield(GeometryCalib,'Cx_Cy')
1329    Cx_Cy=GeometryCalib.Cx_Cy;
1330end
1331kc=0;
1332if isfield(GeometryCalib,'kc')
1333    kc=GeometryCalib.kc; %* GeometryCalib.focal*GeometryCalib.focal;
1334end
1335set(handles.fx,'String',num2str(fx,5))
1336set(handles.fy,'String',num2str(fy,5))
1337set(handles.Cx,'String',num2str(Cx_Cy(1),'%1.1f'))
1338set(handles.Cy,'String',num2str(Cx_Cy(2),'%1.1f'))
1339set(handles.kc,'String',num2str(kc,'%1.4f'))
1340
1341
1342% --- Executes when user attempts to close geometry_calib.
1343function geometry_calib_CloseRequestFcn(hObject, eventdata, handles)
1344% hObject    handle to geometry_calib (see GCBO)
1345% eventdata  reserved - to be defined in a future version of MATLAB
1346% handles    structure with handles and user data (see GUIDATA)
1347
1348% Hint: delete(hObject) closes the figure
1349delete(hObject);
1350
1351%------------------------------------------------------------------------
1352% --- Executes on button press in PLOT.
1353%------------------------------------------------------------------------
1354function PLOT_Callback(hObject, eventdata, handles)
1355global Coord
1356huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
1357hhuvmat=guidata(huvmat); %handles of GUI elements in uvmat
1358h_menu_coord=findobj(huvmat,'Tag','TransformName');
1359menu=get(h_menu_coord,'String');
1360choice=get(h_menu_coord,'Value');
1361if iscell(menu)
1362    option=menu{choice};
1363else
1364    option='px'; %default
1365end
1366%ObjectData=read_geometry_calib(Coord_cell);
1367%ObjectData=read_geometry_calib(handles);%read the interface input parameters defining the object
1368Coord=get(handles.ListCoord,'Data');
1369% Coord(:,6)=[];
1370if ~isempty(Coord)
1371    if isequal(option,'phys')
1372        Coord_plot=Coord(:,1:3);
1373    elseif isequal(option,'px')||isequal(option,'')
1374        Coord_plot=Coord(:,4:5);
1375    else
1376        msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be blank, px or phys ')
1377    end
1378end
1379
1380set(0,'CurrentFigure',huvmat)
1381set(huvmat,'CurrentAxes',hhuvmat.PlotAxes)
1382hh=findobj('Tag','calib_points');
1383if  ~isempty(Coord) && isempty(hh)
1384    hh=line(Coord_plot(:,1),Coord_plot(:,2),'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
1385elseif isempty(Coord)%empty list of points, suppress the plot
1386    delete(hh)
1387else
1388    set(hh,'XData',Coord_plot(:,1))
1389    set(hh,'YData',Coord_plot(:,2))
1390end
1391
1392% get data on the matlab work space
1393
1394evalin('base','global Coord')%make CurData global in the workspace
1395display('coordinates of calibration points (phys,px,marker) :')
1396evalin('base','Coord') %display CurData in the workspace
1397commandwindow; %brings the Matlab command window to the front
1398pause(.1)
1399figure(handles.geometry_calib)
1400
1401 
1402
1403
1404% --- Executes when selected cell(s) is changed in ListCoord.
1405function ListCoord_CellSelectionCallback(hObject, eventdata, handles)
1406if ~isempty(eventdata.Indices)
1407iline=eventdata.Indices(1);% selected line number
1408Data=get(handles.ListCoord,'Data');
1409Data(:,6)=zeros(size(Data,1),1);
1410Data(iline,6)=1;% mark the selected line
1411% if size(Data,1)<iline+numel(Input)
1412%     Data=[Data ; zeros(iline+numel(Input)-size(Data,1),6)];% append zeros to fit the new column
1413% end
1414% Data(iline:iline+numel(Input)-1,eventdata.Indices(2))=Input';
1415set(handles.ListCoord,'Data',Data)
1416update_calib_marker(Data(iline,:))
1417end
1418
1419% if length(eventdata.Modifier) == 1 && strcmp(eventdata.Modifier{:},'control') && ...
1420% eventdata.Key == 'v'
1421%     import = importdata('-pastespecial');
1422%    %data treatment and checking
1423%     set(handles.uitable1,'Data',import);
1424% end
1425
1426% --- Executes when entered data in editable cell(s) in ListCoord.
1427function ListCoord_CellEditCallback(hObject, eventdata, handles)
1428
1429Input=str2num(eventdata.EditData);%pasted input
1430Coord=get(handles.ListCoord,'Data');
1431iline=eventdata.Indices(1);% selected line number
1432if size(Coord,1)<iline+numel(Input)
1433    Coord=[Coord ; zeros(iline+numel(Input)-size(Coord,1),6)];% append zeros to fit the new column
1434end
1435Coord(iline:iline+numel(Input)-1,eventdata.Indices(2))=Input';
1436set(handles.ListCoord,'Data',Coord)
1437PLOT_Callback(hObject, eventdata, handles)
1438
1439function update_calib_marker(Coord)
1440%% update the plot on uvmat
1441huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
1442hplot=findobj(huvmat,'Tag','PlotAxes');%main plotting axis of uvmat
1443hhh=findobj(hplot,'Tag','calib_marker');
1444
1445h_menu_coord=findobj(huvmat,'Tag','TransformName');
1446menu=get(h_menu_coord,'String');
1447choice=get(h_menu_coord,'Value');
1448if iscell(menu)
1449    option=menu{choice};
1450else
1451    option='px'; %default
1452end
1453if isequal(option,'phys')
1454    XCoord=Coord(1);
1455    YCoord=Coord(2);
1456elseif isequal(option,'px')|| isequal(option,'')
1457    XCoord=Coord(4);
1458    YCoord=Coord(5);
1459else
1460    msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be blank, px or phys ')
1461end
1462if isempty(XCoord)||isempty(YCoord)
1463     if ~isempty(hhh)
1464        delete(hhh)%delete the circle marker
1465    end
1466    return
1467end
1468xlim=get(hplot,'XLim');
1469ylim=get(hplot,'YLim');
1470ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/20;%defines the size of the circle marker
1471if isempty(hhh)
1472    set(0,'CurrentFig',huvmat)
1473    set(huvmat,'CurrentAxes',hplot)
1474    rectangle('Curvature',[1 1],...
1475              'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range],'EdgeColor','m',...
1476              'LineStyle','-','Tag','calib_marker');
1477else
1478    set(hhh,'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range])
1479end
Note: See TracBrowser for help on using the repository browser.