Home > . > probe_calib.m

probe_calib

PURPOSE ^

'probe_calib': performs geometric calibration from a set of reference points

SYNOPSIS ^

function varargout = probe_calib(varargin)

DESCRIPTION ^

'probe_calib': performs geometric calibration from a set of reference points
 PROBE_CALIB M-file for probe_calib.fig
      PROBE_CALIB, by itself, creates a MenuCoord PROBE_CALIB or raises the existing
      singleton*.

      H = PROBE_CALIB returns the handle to a MenuCoord PROBE_CALIB or the handle to
      the existing singleton*.

      PROBE_CALIB('CALLBACK',hObject,eventData,handles,...) calls the local
      function named CALLBACK in PROBE_CALIB.M with the given input arguments.

      PROBE_CALIB('Property','Value',...) creates a MenuCoord PROBE_CALIB or raises the
      existing singleton*.  Starting from the left, property value pairs are
      applied to the GUI before probe_calib_OpeningFunction gets called.  An
      unrecognized property name or invalid value makes property application
      stop.  All inputs are passed to probe_calib_OpeningFcn via varargin.

      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
      instance to run (singleton)".

 See also: GUIDE, GUIDATA, GUIHANDLES

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %'probe_calib': performs geometric calibration from a set of reference points
0002 function varargout = probe_calib(varargin)
0003 % PROBE_CALIB M-file for probe_calib.fig
0004 %      PROBE_CALIB, by itself, creates a MenuCoord PROBE_CALIB or raises the existing
0005 %      singleton*.
0006 %
0007 %      H = PROBE_CALIB returns the handle to a MenuCoord PROBE_CALIB or the handle to
0008 %      the existing singleton*.
0009 %
0010 %      PROBE_CALIB('CALLBACK',hObject,eventData,handles,...) calls the local
0011 %      function named CALLBACK in PROBE_CALIB.M with the given input arguments.
0012 %
0013 %      PROBE_CALIB('Property','Value',...) creates a MenuCoord PROBE_CALIB or raises the
0014 %      existing singleton*.  Starting from the left, property value pairs are
0015 %      applied to the GUI before probe_calib_OpeningFunction gets called.  An
0016 %      unrecognized property name or invalid value makes property application
0017 %      stop.  All inputs are passed to probe_calib_OpeningFcn via varargin.
0018 %
0019 %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
0020 %      instance to run (singleton)".
0021 %
0022 % See also: GUIDE, GUIDATA, GUIHANDLES
0023 
0024 % Edit the above text to modify the response to help probe_calib
0025 
0026 % Last Modified by GUIDE v2.5 04-Feb-2008 15:46:42
0027 
0028 % Begin initialization code - DO NOT EDIT
0029 gui_Singleton = 1;
0030 gui_State = struct('gui_Name',       mfilename, ...
0031                    'gui_Singleton',  gui_Singleton, ...
0032                    'gui_OpeningFcn', @probe_calib_OpeningFcn, ...
0033                    'gui_OutputFcn',  @probe_calib_OutputFcn, ...
0034                    'gui_LayoutFcn',  [] , ...
0035                    'gui_Callback',   []);
0036 if nargin & isstr(varargin{1})
0037     gui_State.gui_Callback = str2func(varargin{1});
0038 end
0039 
0040 if nargout
0041     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0042 else
0043     gui_mainfcn(gui_State, varargin{:});
0044 end
0045 % End initialization code - DO NOT EDIT
0046 
0047 
0048 % --- Executes just before probe_calib is made visible.
0049 %INPUT:
0050 %handles: handles of the probe_calib interface elements
0051 % PlotHandles: set of handles of the elements contolling the plotting
0052 % parameters on the uvmat interface (obtained by 'get_plot_handle.m')
0053 function probe_calib_OpeningFcn(hObject, eventdata, handles, data,pos,inputfile)
0054 
0055 % Choose default command line output for probe_calib
0056 handles.output = hObject;
0057 
0058 % Update handles structure
0059 guidata(hObject, handles);
0060 
0061 %default
0062 % set(hObject,'Unit','Normalized')% set the unit normalized to the screen size
0063 % set(hObject,'Position',[0.7 0.1 0.25 0.5])%set the position of the probe_calib interface
0064 set(hObject,'DeleteFcn',@closefcn)
0065 
0066 %set the position of the interface
0067 if exist('pos','var')& length(pos)>2
0068     pos_gui=get(hObject,'Position');
0069     pos_gui(1)=pos(1);
0070     pos_gui(2)=pos(2);
0071     set(hObject,'Position',pos_gui);
0072 end
0073 % set(handles.XImage,'String','')
0074 % set(handles.YImage,'String','')
0075 % set(handles.XObject,'String','')
0076 % set(handles.YObject,'String','')
0077 % set(handles.ZObject,'String','')
0078 inputxml='';
0079 if exist('inputfile','var')& ~isempty(inputfile)
0080     [Path,Name,ext]=fileparts(inputfile);
0081     if isequal(ext,'.png')
0082         set(hObject,'UserData',inputfile)
0083         [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile);
0084         inputxml=[fullfile(Pathsub,RootFile) '.xml'];
0085     end   
0086 end
0087 if exist(inputxml,'file')
0088     loadfile(handles,inputxml)
0089 end
0090 set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function
0091 
0092 
0093 % --- Outputs from this function are returned to the command line.
0094 function varargout = probe_calib_OutputFcn(hObject, eventdata, handles)
0095 % varargout  cell array for returning output args (see VARARGOUT);
0096 % hObject    handle to figure
0097 % eventdata  reserved - to be defined in a future version of MATLAB
0098 % handles    structure with handles and user data (see GUIDATA)
0099 
0100 % Get default command line output from handles structure
0101 varargout{1} = handles.output;
0102 varargout{2}=handles;
0103 
0104 %------------
0105 function Phi_Callback(hObject, eventdata, handles)
0106 
0107 
0108 %-----------------------------------------------------
0109 % --- Executes on button press in import.
0110 function import_Callback(hObject, eventdata, handles)
0111 %get the object file
0112 huvmat=findobj('Tag','uvmat');
0113 UvData=get(huvmat,'UserData');
0114 hchild=get(huvmat,'Children');
0115 hrootpath=findobj(hchild,'Tag','RootPath');
0116 oldfile=get(hrootpath,'String');
0117 if isempty(oldfile)
0118     oldfile='';
0119 end
0120 %[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile)
0121 [FileName, PathName, filterindex] = uigetfile( ...
0122        {'*.xml;*.mat', ' (*.xml,*.mat)';
0123        '*.xml',  '.xml files '; ...
0124         '*.mat',  '.mat matlab files '}, ...
0125         'Pick a file',oldfile);
0126 fileinput=[PathName FileName];%complete file name
0127 testblank=findstr(fileinput,' ');%look for blanks
0128 if ~isempty(testblank)
0129     warndlg_uvmat('forbidden input file name or path: no blank character allowed','ERROR')
0130     return
0131 end
0132 sizf=size(fileinput);
0133 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
0134 loadfile(handles,fileinput)
0135 
0136 %--------------------------------------------------
0137 %read input xml file and update the edit boxes
0138 function loadfile(handles,fileinput)
0139 
0140 %read the input xml file
0141 t=xmltree(fileinput);
0142 s=convert(t);%convert to matlab structure
0143 
0144 %read data currently displayed on the interface
0145 PointCoord=[];
0146 data=read_probe_calib(handles);
0147 Coord=[]; %default
0148 if isfield(data,'Coord')
0149     Coord=data.Coord;
0150 end
0151 TabChar_0=get(handles.ListCoord,'String');
0152 nbcoord_0=size(TabChar_0,1);
0153 if isequal(get(handles.edit_append,'Value'),1) %edit mode
0154     val=get(handles.ListCoord,'Value')-1;
0155 else
0156    val=length(TabChar_0); 
0157 end
0158 nbcoord=0;
0159 
0160 %case of calibration (ImaDoc) input file
0161 if isfield(s,'GeometryCalib')
0162     Calib=s.GeometryCalib;
0163     if isfield(Calib,'SourceCalib')
0164         if isfield(Calib.SourceCalib,'PointCoord')
0165             PointCoord=Calib.SourceCalib.PointCoord;
0166         end
0167         if isfield(Calib.SourceCalib,'ImageCalib')
0168             hcalib=get(handles.import,'parent');
0169             set(hcalib,'UserData',Calib.SourceCalib.ImageCalib);%store the source image name in the interface 'UserData'
0170         end
0171     end
0172     nbcoord=length(PointCoord);
0173     if ~isfield(Calib,'ErrorRms')&~isfield(Calib,'ErrorMax') %old convention of Gauthier (cord in mm)
0174         for i=1:length(PointCoord)
0175           line=str2num(PointCoord{i});
0176           Coord(i+val,4:5)=line(4:5);%px x
0177           Coord(i+val,1:3)=line(1:3)/10;%phys x
0178         end
0179     else
0180         for i=1:length(PointCoord)
0181           line=str2num(PointCoord{i});
0182           Coord(i,4:5)=line(4:5);%px x
0183           Coord(i,1:3)=line(1:3);%phys x
0184        end
0185     end
0186 end
0187 
0188 %case of xml files of points
0189 if isfield(s,'Coord')
0190     PointCoord=s.Coord;
0191     nbcoord=length(PointCoord);
0192      %case of image coordinates
0193     if isfield(s,'CoordType')& isequal(s.CoordType,'px')
0194         for i=1:nbcoord
0195            line=str2num(PointCoord{i});
0196            Coord(i+val,4:5)=line(1:2);
0197         end
0198      %case of  physical coordinates
0199     else
0200         for i=1:nbcoord
0201            line=str2num(PointCoord{i})
0202            Coord(i+val,1:3)=line(1:3);
0203            nbcolumn=size(Coord,2);
0204            if nbcolumn<5
0205                Coord(i+val,nbcolumn+1:5)=zeros(1,5-nbcolumn);
0206            end
0207         end
0208      end
0209 end
0210 CoordCell={};
0211 for iline=1:size(Coord,1)
0212     for j=1:5
0213         CoordCell{iline,j}=num2str(Coord(iline,j));
0214     end
0215 end
0216         
0217 Tabchar=cell2tab(CoordCell,'    |    ');%transform cells into table ready for display
0218 set(handles.ListCoord,'Value',1)
0219 set(handles.ListCoord,'String',Tabchar)
0220 
0221 
0222 %----------------------------------------------------
0223 % executed when closing: set the parent interface button to value 0
0224 function closefcn(gcbo,eventdata)
0225 SetData=get(gcbf,'UserData');
0226 if isfield(SetData,'ParentButton') & ishandle(SetData.ParentButton)
0227     set(SetData.ParentButton, 'Value',0)
0228 end
0229 
0230 %-----------------------------------------------------------------------
0231 % --- Executes on button press in edit: PLOT the defined object and its projected field
0232 function edit_Callback(hObject, eventdata, handles)
0233 %hsetobject=get(hObject,'parent');
0234 %SetData=get(hsetobject,'UserData');%get the hidden interface data
0235 %IndexObj=SetData.IndexObj;%index of the current projection object in the list of projection objects (UvData.ProjObject)
0236 huvmat=findobj(allchild(0),'name','uvmat');%find the current uvmat interface handle
0237 UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
0238 hplot=findobj(huvmat,'Tag','axes3');
0239 h_menu_coord=findobj(huvmat,'Tag','menu_coord');
0240 menu=get(h_menu_coord,'String');
0241 choice=get(h_menu_coord,'Value');
0242 if iscell(menu)
0243     option=menu{choice};
0244 else
0245     option='px'; %default
0246 end
0247 %get axis
0248 %get CoordType
0249 ObjectData=read_probe_calib(handles);%read the interface input parameters defining the object
0250 if isequal(option,'phys')
0251     ObjectData.Coord=ObjectData.Coord(:,[1:3]);
0252 elseif isequal(option,'px')
0253     ObjectData.Coord=ObjectData.Coord(:,[4:5]);
0254 else
0255     errordlg('the choice in coord_coord must be px or phys ')
0256 end
0257 % [UvData,IndexObj]=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles);
0258 % SetData.IndexObj=IndexObj;
0259 % set(gcbf,'UserData',SetData)%update object index in the probe_calib interface
0260 % set(huvmat,'UserData',UvData)%update the data in the uvmat interface
0261 ObjectData.ProjMode='none';
0262 plot_object(ObjectData,[],hplot,'b');
0263 
0264 
0265 % --- Executes on button press in MenuCoord.
0266 function MenuCoord_Callback(hObject, eventdata, handles)
0267 
0268 
0269 % --- Executes on button press in delete.
0270 function delete_Callback(hObject, eventdata, handles)
0271 SetData=get(gcbf,'UserData');%get the interface data
0272 IndexObj=SetData.IndexObj;
0273 delete_object(IndexObj);
0274 
0275 % --- Executes on button press in calibrate_lin.
0276 function calib_offset_Callback(hObject, eventdata, handles)
0277 Object=read_probe_calib(handles);
0278 
0279 %make linear calibration
0280 % 'calibration_lin' provides a linear transform on coordinates,
0281 X=Object.Coord(:,1);
0282 Y=Object.Coord(:,2);
0283 x_ima=Object.Coord(:,4);
0284 y_ima=Object.Coord(:,5);
0285 [px,sx]=polyfit(X,x_ima,1);
0286 [py,sy]=polyfit(Y,y_ima,1);
0287 %err_X1=max(abs(x1-x_ima));%error
0288 %err_Y1=max(abs(y1-y_ima));%error
0289 T_x=px(2);
0290 T_y=py(2);
0291 GeometryCalib.focal=1;
0292 GeometryCalib.Tx_Ty_Tz=[T_x T_y 1];
0293 GeometryCalib.R=[px(1),0,0;0,py(1),0;0,0,1];
0294 %check error
0295 Calib.dpx=1;
0296 Calib.dpy=1;
0297 Calib.sx=1;
0298 Calib.Cx=0;
0299 Calib.Cy=0;
0300 Calib.Tz=1;
0301 Calib.kappa1=0;
0302 Calib.f=GeometryCalib.focal;
0303 Calib.Tx=T_x;
0304 Calib.Ty=T_y;
0305 Calib.R=GeometryCalib.R;
0306 [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,0);
0307 GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
0308 GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
0309 GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
0310 GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima))
0311 %calibrate_lin calibration results and point coordinates
0312 huvmat=findobj('Tag','uvmat');
0313 hchild=get(huvmat,'Children');
0314 hrootpath=findobj(hchild,'Tag','RootPath');
0315 hrootfile=findobj(hchild,'Tag','RootFile');
0316 RootPath='';
0317 RootFile='';
0318 if ~isempty(hrootpath)& ~isempty(hrootfile)
0319     testhandle=1;
0320     RootPath=get(hrootpath,'String');
0321     RootFile=get(hrootfile,'String');
0322     filebase=fullfile(RootPath,RootFile);
0323     outputfile=[filebase '.xml'] 
0324 else
0325     question={'save the calibration data and point coordinates in'};
0326     def={fullfile(RootPath,['ObjectCalib.xml'])};
0327     options.Resize='on';
0328     answer=inputdlg(question,'save average in a new file',1,def,options);
0329     outputfile=answer{1};
0330 end
0331 testappend=0;
0332 if exist(outputfile,'file');%=1 if the output file already exists, 0 else
0333     t=xmltree(outputfile); %read the file
0334     uid=find(t,'ImaDoc');
0335     if ~isequal(uid,1)%if the xml file is not ImaDoc, delete it (after backup)
0336         backupfile=outputfile;
0337         testexist=2;
0338         while testexist==2
0339             backupfile=[backupfile '~'];
0340             testexist=exist(backupfile,'file');       
0341         end
0342         [success,message]=copyfile(outputfile,backupfile);%make backup
0343         if isequal(success,1)
0344             delete(outputfile)
0345         else
0346             return
0347         end
0348     else
0349         uid_calib=find(t,'ImaDoc/GeometryCalib');
0350         if ~isempty(uid) %if GeometryCalib already exists, delete its content
0351             backupfile=outputfile;
0352             testexist=2;
0353             while testexist==2
0354                 backupfile=[backupfile '~'];
0355                 testexist=exist(backupfile,'file');      
0356             end
0357             [success,message]=copyfile(outputfile,backupfile)%make backup
0358             if isequal(success,1)
0359                 delete(outputfile)
0360             else
0361                 return
0362             end
0363             uid_child=children(t,uid_calib);
0364             t=delete(t,uid_child);
0365             testappend=1;
0366         end
0367     end
0368 end
0369 if ~testappend
0370     t=xmltree;
0371     t=set(t,1,'name','ImaDoc');
0372     [t,uid_calib]=add(t,1,'element','GeometryCalib');
0373 %     t=struct2xml(GeometryCalib,t,uid_calib);
0374 end
0375 Object.Coord(:,[1:3])=Object.Coord(:,[1:3])*10; %transform in
0376 GeometryCalib.SourceCalib.PointCoord=Object.Coord;
0377 t=struct2xml(GeometryCalib,t,uid_calib); 
0378 save(t,outputfile)
0379 
0380 warndlg_uvmat([outputfile 'updated with linear calibration data'],'CONFIRMATION')
0381 
0382 %display image with new calibration in the currently opened uvmat interface
0383 Indices=get(findobj(hchild,'Tag','FileIndex'),'String');
0384 Ext=get(findobj(hchild,'Tag','FileExt'),'String');
0385 imagename=[fullfile(RootPath,RootFile) Indices Ext];
0386 % input.menu_coord=1;
0387 huvmat=uvmat(imagename,1);%open uvmat, set phys coord (Value 1)
0388 
0389 
0390 
0391 % --- Executes on button press in calibrate_lin.
0392 function calib_lin_Callback(hObject, eventdata, handles)
0393 Object=read_probe_calib(handles);
0394 
0395 %make linear calibration
0396 % 'calibration_lin' provides a linear transform on coordinates,
0397 X=Object.Coord(:,1);
0398 Y=Object.Coord(:,2);
0399 x_ima=Object.Coord(:,4);
0400 y_ima=Object.Coord(:,5);
0401 XY_mat=[ones(size(X)) X Y];
0402 a_X1=XY_mat\x_ima; %transformation matrix for X
0403 x1=XY_mat*a_X1;%reconstruction
0404 err_X1=max(abs(x1-x_ima));%error
0405 a_Y1=XY_mat\y_ima;%transformation matrix for X
0406 y1=XY_mat*a_Y1;
0407 err_Y1=max(abs(y1-y_ima));%error
0408 T_x=a_X1(1);
0409 T_y=a_Y1(1);
0410 GeometryCalib.focal=1;
0411 GeometryCalib.Tx_Ty_Tz=[T_x T_y 1];
0412 GeometryCalib.R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,1];
0413 
0414 %check error
0415 GeometryCalib.ErrorRms(1)=sqrt(mean((x1-x_ima).*(x1-x_ima)));
0416 GeometryCalib.ErrorMax(1)=max(abs(x1-x_ima));
0417 GeometryCalib.ErrorRms(2)=sqrt(mean((y1-y_ima).*(y1-y_ima)));
0418 GeometryCalib.ErrorMax(2)=max(abs(y1-y_ima))
0419 
0420 %calibrate_lin calibration results and point coordinates
0421 huvmat=findobj('Tag','uvmat');
0422 hchild=get(huvmat,'Children');
0423 hrootpath=findobj(hchild,'Tag','RootPath');
0424 hrootfile=findobj(hchild,'Tag','RootFile');
0425 RootPath='';
0426 RootFile='';
0427 if ~isempty(hrootpath)& ~isempty(hrootfile)
0428     testhandle=1;
0429     RootPath=get(hrootpath,'String');
0430     RootFile=get(hrootfile,'String');
0431     filebase=fullfile(RootPath,RootFile);
0432     outputfile=[filebase '.xml']; 
0433 else
0434     question={'save the calibration data and point coordinates in'};
0435     def={fullfile(RootPath,['ObjectCalib.xml'])};
0436     options.Resize='on';
0437     answer=inputdlg(question,'save average in a new file',1,def,options);
0438     outputfile=answer{1};
0439 end
0440 testappend=0;
0441 if exist(outputfile,'file');%=1 if the output file already exists, 0 else
0442     t=xmltree(outputfile); %read the file
0443     uid=find(t,'ImaDoc');
0444     if ~isequal(uid,1)%if the xml file is not ImaDoc, delete it (after backup)
0445         backupfile=outputfile;
0446         testexist=2;
0447         while testexist==2
0448             backupfile=[backupfile '~'];
0449             testexist=exist(backupfile,'file');       
0450         end
0451         [success,message]=copyfile(outputfile,backupfile)%make backup
0452         if isequal(success,1);
0453             delete(outputfile)
0454         else
0455             return
0456         end
0457     else
0458         uid_calib=find(t,'ImaDoc/GeometryCalib');
0459         if ~isempty(uid) %if GeometryCalib already exists, delete its content
0460             backupfile=outputfile;
0461             testexist=2;
0462             while testexist==2
0463                 backupfile=[backupfile '~'];
0464                 testexist=exist(backupfile,'file');      
0465             end
0466             [success,message]=copyfile(outputfile,backupfile)%make backup
0467             if isequal(success,1)
0468                 delete(outputfile)
0469             else
0470                 return
0471             end
0472             uid_child=children(t,uid_calib);
0473             t=delete(t,uid_child);
0474             testappend=1;
0475         end
0476     end
0477 end
0478 if ~testappend
0479     t=xmltree;
0480     t=set(t,1,'name','ImaDoc');
0481     [t,uid_calib]=add(t,1,'element','GeometryCalib');
0482 %     t=struct2xml(GeometryCalib,t,uid_calib);
0483 end
0484 % Object.Coord(:,[1:3])=Object.Coord(:,[1:3]); %transform in
0485 GeometryCalib.SourceCalib.PointCoord=Object.Coord;
0486 t=struct2xml(GeometryCalib,t,uid_calib); 
0487 save(t,outputfile)
0488 
0489 warndlg_uvmat([outputfile 'updated with linear calibration data'],'CONFIRMATION')
0490 
0491 %display image with new calibration in the currently opened uvmat interface
0492 Indices=get(findobj(hchild,'Tag','FileIndex'),'String');
0493 Ext=get(findobj(hchild,'Tag','FileExt'),'String');
0494 imagename=[fullfile(RootPath,RootFile) Indices Ext];
0495 % input.menu_coord=1;
0496 if exist(imagename,'file')
0497     huvmat=uvmat(imagename,1);%open uvmat, set phys coord (Value 1)
0498 else
0499     huvmat=uvmat;
0500 end
0501 
0502 
0503 % --- Executes on button press in translation.
0504 function translation_Callback(hObject, eventdata, handles)
0505 
0506 
0507 function T_x_Callback(hObject, eventdata, handles)
0508 % hObject    handle to T_x (see GCBO)
0509 % eventdata  reserved - to be defined in a future version of MATLAB
0510 % handles    structure with handles and user data (see GUIDATA)
0511 
0512 % Hints: get(hObject,'String') returns contents of T_x as text
0513 %        str2double(get(hObject,'String')) returns contents of T_x as a double
0514 
0515 
0516 
0517 
0518 
0519 function T_y_Callback(hObject, eventdata, handles)
0520 % hObject    handle to T_y (see GCBO)
0521 % eventdata  reserved - to be defined in a future version of MATLAB
0522 % handles    structure with handles and user data (see GUIDATA)
0523 
0524 % Hints: get(hObject,'String') returns contents of T_y as text
0525 %        str2double(get(hObject,'String')) returns contents of T_y as a double
0526 
0527 
0528 function T_z_Callback(hObject, eventdata, handles)
0529 % hObject    handle to T_z (see GCBO)
0530 % eventdata  reserved - to be defined in a future version of MATLAB
0531 % handles    structure with handles and user data (see GUIDATA)
0532 
0533 % Hints: get(hObject,'String') returns contents of T_z as text
0534 %        str2double(get(hObject,'String')) returns contents of T_z as a double
0535 
0536 
0537 % --- Executes on button press in rotation.
0538 function rotation_Callback(hObject, eventdata, handles)
0539 angle_rot=(pi/180)*str2num(get(handles.Phi,'String'))
0540 data=read_probe_calib(handles)
0541 data.Coord(:,1)=cos(angle_rot)*data.Coord(:,1)+sin(angle_rot)*data.Coord(:,2);
0542 data.Coord(:,1)=-sin(angle_rot)*data.Coord(:,1)+cos(angle_rot)*data.Coord(:,2);
0543 set(handles.XObject,'String',num2str(data.Coord(:,1)));
0544 set(handles.YObject,'String',num2str(data.Coord(:,2)));
0545 
0546 
0547 function XImage_Callback(hObject, eventdata, handles)
0548 update_list(hObject, eventdata,handles)
0549 
0550 function YImage_Callback(hObject, eventdata, handles)
0551 update_list(hObject, eventdata,handles)
0552 
0553 function XObject_Callback(hObject, eventdata, handles)
0554 update_list(hObject, eventdata,handles)
0555 
0556 function YObject_Callback(hObject, eventdata, handles)
0557 update_list(hObject, eventdata,handles)
0558 
0559 function ZObject_Callback(hObject, eventdata, handles)
0560 update_list(hObject, eventdata,handles)
0561 
0562 function update_list(hObject, eventdata, handles)
0563 str4=get(handles.XImage,'String');
0564 str5=get(handles.YImage,'String');
0565 str1=get(handles.XObject,'String');
0566 tt=double(str1);
0567 str2=get(handles.YObject,'String');
0568 str3=get(handles.ZObject,'String');
0569 if ~isempty(str1) & ~isequal(double(str1),32) & (isempty(str3)|isequal(double(str3),32))
0570     str3='0';%put z to 0 by default
0571 end
0572 strline=[str1 '    |    ' str2 '    |    ' str3 '    |    ' str4 '    |    ' str5];
0573 Coord=get(handles.ListCoord,'String');
0574 testappend=get(handles.edit_append,'Value');
0575 if isequal(testappend,1); %edit mode
0576     val=get(handles.ListCoord,'Value');
0577     Coord{val}=strline;
0578 else
0579     val=length(get(handles.ListCoord,'String'));
0580     Coord{val+1}=strline;
0581     set(handles.ListCoord,'Value',val+1)
0582 % if val+1<=length(Coord)
0583 %     set(handles.ListCoord,'Value',val+1)
0584 %     ListCoord_Callback(hObject, eventdata, handles)
0585 end
0586 set(handles.ListCoord,'String',Coord)
0587 %set(handles.ListCoord,'Value',val+1)
0588 
0589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0590 function data=read_probe_calib(handles)
0591 data_XIma=[];
0592 data_YIma=[];
0593 data_XObject=[];
0594 data_YObject=[];
0595 data_ZObject=[];
0596 Coord=get(handles.ListCoord,'String');
0597 % XImage=get(handles.XImage,'String');
0598 % YImage=get(handles.YImage,'String');
0599 % XObject=get(handles.XObject,'String');
0600 % YObject=get(handles.YObject,'String');
0601 % ZObject=get(handles.ZObject,'String');
0602 % if ischar(Xcolumn)
0603 %     Xcolumn={Xcolumn};
0604 % end
0605 nb_defining_points=length(Coord);
0606 iline=0;
0607 for i=1:nb_defining_points
0608     coord_str=Coord{i};%character string of line number i
0609     k=findstr('|',coord_str);%find separators '|'
0610     data1=str2num(coord_str(1:k(1)-5));
0611     data2=str2num(coord_str(k(1)+5:k(2)-5));
0612     data3=str2num(coord_str(k(2)+5:k(3)-5));
0613     data4=str2num(coord_str(k(3)+5:k(4)-5));
0614     data5=str2num(coord_str(k(4)+5:end));
0615     if ~isempty(data1)|~isempty(data2)|~isempty(data3)|~isempty(data4)|~isempty(data5)
0616         iline=iline+1;
0617         if ~isempty(data1)
0618             data.Coord(iline,1)=data1;
0619         end    
0620         if ~isempty(data2)
0621             data.Coord(iline,2)=data2;
0622         end
0623         if ~isempty(data3)
0624             data.Coord(iline,3)=data3;
0625         end
0626         if ~isempty(data4)
0627             data.Coord(iline,4)=data4;
0628         end
0629         if isempty(data5)
0630             data.Coord(iline,5)=0;
0631         else
0632             data.Coord(iline,5)=data5;
0633         end
0634     end
0635 end
0636 data.Style='points';
0637 
0638 
0639 % --- Executes on selection change in ListCoord.
0640 function ListCoord_Callback(hObject, eventdata, handles)
0641 % hObject    handle to ListCoord (see GCBO)
0642 % eventdata  reserved - to be defined in a future version of MATLAB
0643 % handles    structure with handles and user data (see GUIDATA)
0644 
0645 % Hints: contents = get(hObject,'String') returns ListCoord contents as cell array
0646 %        contents{get(hObject,'Value')} returns selected item from ListCoord
0647 set(handles.edit_append,'Value',1); %set to edit mode
0648 Coord=get(handles.ListCoord,'String');
0649 val=get(handles.ListCoord,'Value');
0650 if length(Coord)>0
0651 coord_str=Coord{val};
0652 k=findstr('|',coord_str);
0653 set(handles.XObject,'String',coord_str(1:k(1)-5))
0654 set(handles.YObject,'String',coord_str(k(1)+5:k(2)-5))
0655 set(handles.ZObject,'String',coord_str(k(2)+5:k(3)-5))
0656 set(handles.XImage,'String',coord_str(k(3)+5:k(4)-5))
0657 set(handles.YImage,'String',coord_str(k(4)+5:end))
0658 end
0659 
0660 %------------------------------------------------------
0661 % --- Executes on button press in translation_plus.
0662 function translation_plus_Callback(hObject, eventdata, handles)
0663 
0664 T=[0 0 0];
0665 T_x=get(handles.T_x,'String')
0666 T_y=get(handles.T_y,'String')
0667 T_z=get(handles.T_z,'String')
0668 if ~isempty(T_x)
0669     T(1)=str2num(T_x);
0670 end
0671 if ~isempty(T_y)
0672     T(2)=str2num(T_y);
0673 end
0674 if ~isempty(T_z)
0675     T(3)=str2num(T_z);
0676 end
0677 translation(handles,T)
0678 
0679 
0680 
0681 % --- Executes on button press in translation_minus.
0682 function translation_minus_Callback(hObject, eventdata, handles)
0683 
0684 T=[0 0 0];
0685 T_x=get(handles.T_x,'String')
0686 T_y=get(handles.T_y,'String')
0687 T_z=get(handles.T_z,'String')
0688 if ~isempty(T_x)
0689     T(1)=-str2num(T_x);
0690 end
0691 if ~isempty(T_y)
0692     T(2)=-str2num(T_y);
0693 end
0694 if ~isempty(T_z)
0695     T(3)=-str2num(T_z);
0696 end
0697 translation(handles,T)
0698 
0699 
0700 %%%--------------------------------------
0701 function translation(handles,T)
0702 data=read_probe_calib(handles);
0703 data.Coord(:,1)=T(1)+data.Coord(:,1);
0704 data.Coord(:,2)=T(2)+data.Coord(:,2);
0705 data.Coord(:,3)=T(3)+data.Coord(:,3);
0706 data.Coord(:,[4 5])=data.Coord(:,[4 5]);
0707 for i=1:size(data.Coord,1)
0708     for j=1:5
0709           Coord{i,j}=num2str(data.Coord(i,j));%phys x,y,z
0710    end
0711 end
0712 Tabchar=cell2tab(Coord,'    |    ');
0713 set(handles.ListCoord,'String',Tabchar)
0714 
0715 %----------------------------------------------------
0716 % --- Executes on button press in rotation_plus.
0717 function rotation_plus_Callback(hObject, eventdata, handles)
0718 Phi=0;
0719 Phi=get(handles.Phi,'String')
0720 if ~isempty(Phi)
0721     Phi=str2num(Phi);
0722 end
0723 rotation(handles,Phi)
0724 
0725 %-------------------------------------------------
0726 % --- Executes on button press in rotation_minus.
0727 function rotation_minus_Callback(hObject, eventdata, handles)
0728 Phi=0;
0729 Phi=get(handles.Phi,'String')
0730 if ~isempty(Phi)
0731     Phi=-str2num(Phi);
0732 end
0733 rotation(handles,Phi)
0734 
0735 %-----------------------------------------------------
0736 %rotation
0737 function rotation(handles,Phi)
0738 O_x=str2num(get(handles.O_x,'String'));
0739 O_y=str2num(get(handles.O_y,'String'));
0740 if isempty(O_x)
0741     O_x=0;%default
0742 end
0743 if isempty(O_y)
0744     O_y=0;%default
0745 end
0746 data=read_probe_calib(handles);
0747 r1=cos(pi*Phi/180);
0748 r2=-sin(pi*Phi/180);
0749 r3=sin(pi*Phi/180);
0750 r4=cos(pi*Phi/180);
0751 data.Coord(:,1)=r1*data.Coord(:,1)+r2*data.Coord(:,2);
0752 data.Coord(:,2)=r3*data.Coord(:,1)+r4*data.Coord(:,2);
0753 % data.Coord(:,[4 5])=data.Coord(:,[4 5]);
0754 for i=1:size(data.Coord,1)
0755     for j=1:5
0756           Coord{i,j}=num2str(data.Coord(i,j));%phys x,y,z
0757    end
0758 end
0759 Tabchar=cell2tab(Coord,'    |    ');
0760 set(handles.ListCoord,'String',Tabchar)
0761 
0762 function O_x_Callback(hObject, eventdata, handles)
0763 % hObject    handle to O_x (see GCBO)
0764 % eventdata  reserved - to be defined in a future version of MATLAB
0765 % handles    structure with handles and user data (see GUIDATA)
0766 
0767 % Hints: get(hObject,'String') returns contents of O_x as text
0768 %        str2double(get(hObject,'String')) returns contents of O_x as a double
0769 
0770 
0771 
0772 function O_y_Callback(hObject, eventdata, handles)
0773 % hObject    handle to O_y (see GCBO)
0774 % eventdata  reserved - to be defined in a future version of MATLAB
0775 % handles    structure with handles and user data (see GUIDATA)
0776 
0777 % Hints: get(hObject,'String') returns contents of O_y as text
0778 %        str2double(get(hObject,'String')) returns contents of O_y as a double
0779 
0780 
0781 function O_z_Callback(hObject, eventdata, handles)
0782 % hObject    handle to O_z (see GCBO)
0783 % eventdata  reserved - to be defined in a future version of MATLAB
0784 % handles    structure with handles and user data (see GUIDATA)
0785 
0786 % Hints: get(hObject,'String') returns contents of O_z as text
0787 %        str2double(get(hObject,'String')) returns contents of O_z as a double
0788 
0789 
0790 
0791 
0792 
0793 
0794 
0795 % --- Executes on selection change in edit_append.
0796 function edit_append_Callback(hObject, eventdata, handles)
0797 val=get(handles.edit_append,'Value');
0798 if isequal(val,2); %append mode
0799     %appeler mouse
0800 end
0801 
0802 
0803 function NEW_Callback(hObject, eventdata, handles)
0804 %A METTRE SOUS UN BOUTON
0805 huvmat=findobj('name','uvmat');
0806 hchild=get(huvmat,'children');
0807 hcoord=findobj(hchild,'Tag','menu_coord')
0808 coordtype=get(hcoord,'Value')
0809 haxes=findobj(hchild,'Tag','axes3');
0810 AxeData=get(haxes,'UserData');
0811 if ~isequal(hcoord,2)
0812     set(hcoord,'Value',2)
0813     huvmat=uvmat(AxeData)
0814     'relancer uvmat'
0815 end
0816 if ~isfield(AxeData,'ZoomAxes')
0817     warndlg_uvmat('first draw a window around a grid marker','ERRROR')
0818     return
0819 end 
0820 XLim=get(AxeData.ZoomAxes,'XLim');
0821 YLim=get(AxeData.ZoomAxes,'YLim');
0822 np=size(AxeData.A);
0823 ind_sub_x=round(XLim)
0824 ind_sub_y=np(1)-round(YLim)
0825 Mfiltre=AxeData.A([ind_sub_y(2):ind_sub_y(1)] ,ind_sub_x,:);
0826 Mfiltre_norm=double(Mfiltre);
0827 Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm));
0828 Mfiltre_norm=100*(Mfiltre_norm-mean(mean(Mfiltre_norm)));
0829 Atype=class(AxeData.A)
0830 Data.NbDim=2;
0831 Data.A=filter2(Mfiltre_norm,double(AxeData.A)); 
0832 Data.A=feval(Atype,Data.A);
0833 Data.AName='image';
0834 Data.AX=AxeData.AX;
0835 Data.AY=AxeData.AY;
0836 Data.CoordType='px';
0837 plot_field(Data)
0838  
0839 
0840 % --- Executes on button press in HELP.
0841 function HELP_Callback(hObject, eventdata, handles)
0842 % hObject    handle to HELP (see GCBO)
0843 % eventdata  reserved - to be defined in a future version of MATLAB
0844 % handles    structure with handles and user data (see GUIDATA)
0845 path_to_uvmat=which ('uvmat');% check the path of uvmat
0846 pathelp=fileparts(path_to_uvmat);
0847 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
0848 if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
0849 else
0850    web([helpfile '#probe_calib'])
0851 end
0852 
0853 %'move_key:' function activated when a key is pressed on the keyboard
0854 %-----------------------------------
0855 function key_press_fcn(hObject,eventdata,handles)
0856 hh=get(hObject,'parent')
0857 xx=double(get(hh,'CurrentCharacter')) %get the keyboard character
0858 
0859 if isequal(xx,8)%move arrow right
0860    data=read_probe_calib(handles);
0861     Coord=[]; %default
0862     if isfield(data,'Coord')
0863         Coord=data.Coord
0864     end
0865     val=get(handles.ListCoord,'Value');
0866     Coord(val,:)=[];
0867     CoordCell={};
0868     for iline=1:size(Coord,1)
0869         for j=1:5
0870             CoordCell{iline,j}=num2str(Coord(iline,j));
0871         end
0872     end
0873     Tabchar=cell2tab(CoordCell,'    |    ');%transform cells into table ready for display
0874     val=min(size(Coord,1),val);
0875     set(handles.ListCoord,'Value',max(val,1))
0876     set(handles.ListCoord,'String',Tabchar)  
0877 end

Generated on Fri 13-Nov-2009 11:17:03 by m2html © 2003