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