source: trunk/src/probe_calib.m @ 20

Last change on this file since 20 was 19, checked in by gostiaux, 14 years ago

the private files have been moved down to the root folder

File size: 28.1 KB
Line 
1%'probe_calib': performs geometric calibration from a set of reference points
2function varargout = probe_calib(varargin)
3% PROBE_CALIB M-file for probe_calib.fig
4%      PROBE_CALIB, by itself, creates a MenuCoord PROBE_CALIB or raises the existing
5%      singleton*.
6%
7%      H = PROBE_CALIB returns the handle to a MenuCoord PROBE_CALIB or the handle to
8%      the existing singleton*.
9%
10%      PROBE_CALIB('CALLBACK',hObject,eventData,handles,...) calls the local
11%      function named CALLBACK in PROBE_CALIB.M with the given input arguments.
12%
13%      PROBE_CALIB('Property','Value',...) creates a MenuCoord PROBE_CALIB or raises the
14%      existing singleton*.  Starting from the left, property value pairs are
15%      applied to the GUI before probe_calib_OpeningFunction gets called.  An
16%      unrecognized property name or invalid value makes property application
17%      stop.  All inputs are passed to probe_calib_OpeningFcn via varargin.
18%
19%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
20%      instance to run (singleton)".
21%
22% See also: GUIDE, GUIDATA, GUIHANDLES
23
24% Edit the above text to modify the response to help probe_calib
25
26% Last Modified by GUIDE v2.5 04-Feb-2008 15:46:42
27
28% Begin initialization code - DO NOT EDIT
29gui_Singleton = 1;
30gui_State = struct('gui_Name',       mfilename, ...
31                   'gui_Singleton',  gui_Singleton, ...
32                   'gui_OpeningFcn', @probe_calib_OpeningFcn, ...
33                   'gui_OutputFcn',  @probe_calib_OutputFcn, ...
34                   'gui_LayoutFcn',  [] , ...
35                   'gui_Callback',   []);
36if nargin & isstr(varargin{1})
37    gui_State.gui_Callback = str2func(varargin{1});
38end
39
40if nargout
41    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
42else
43    gui_mainfcn(gui_State, varargin{:});
44end
45% End initialization code - DO NOT EDIT
46
47
48% --- Executes just before probe_calib is made visible.
49%INPUT:
50%handles: handles of the probe_calib interface elements
51% PlotHandles: set of handles of the elements contolling the plotting
52% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
53function probe_calib_OpeningFcn(hObject, eventdata, handles, data,pos,inputfile)
54
55% Choose default command line output for probe_calib
56handles.output = hObject;
57
58% Update handles structure
59guidata(hObject, handles);
60
61%default
62% set(hObject,'Unit','Normalized')% set the unit normalized to the screen size
63% set(hObject,'Position',[0.7 0.1 0.25 0.5])%set the position of the probe_calib interface
64set(hObject,'DeleteFcn',@closefcn)
65
66%set the position of the interface
67if exist('pos','var')& length(pos)>2
68    pos_gui=get(hObject,'Position');
69    pos_gui(1)=pos(1);
70    pos_gui(2)=pos(2);
71    set(hObject,'Position',pos_gui);
72end
73% set(handles.XImage,'String','')
74% set(handles.YImage,'String','')
75% set(handles.XObject,'String','')
76% set(handles.YObject,'String','')
77% set(handles.ZObject,'String','')
78inputxml='';
79if exist('inputfile','var')& ~isempty(inputfile)
80    [Path,Name,ext]=fileparts(inputfile);
81    if isequal(ext,'.png')
82        set(hObject,'UserData',inputfile)
83        [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile);
84        inputxml=[fullfile(Pathsub,RootFile) '.xml'];
85    end   
86end
87if exist(inputxml,'file')
88    loadfile(handles,inputxml)
89end
90set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function
91
92
93% --- Outputs from this function are returned to the command line.
94function varargout = probe_calib_OutputFcn(hObject, eventdata, handles)
95% varargout  cell array for returning output args (see VARARGOUT);
96% hObject    handle to figure
97% eventdata  reserved - to be defined in a future version of MATLAB
98% handles    structure with handles and user data (see GUIDATA)
99
100% Get default command line output from handles structure
101varargout{1} = handles.output;
102varargout{2}=handles;
103
104%------------
105function Phi_Callback(hObject, eventdata, handles)
106
107
108%-----------------------------------------------------
109% --- Executes on button press in import.
110function import_Callback(hObject, eventdata, handles)
111%get the object file
112huvmat=findobj('Tag','uvmat');
113UvData=get(huvmat,'UserData');
114hchild=get(huvmat,'Children');
115hrootpath=findobj(hchild,'Tag','RootPath');
116oldfile=get(hrootpath,'String');
117if isempty(oldfile)
118    oldfile='';
119end
120%[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile)
121[FileName, PathName, filterindex] = uigetfile( ...
122       {'*.xml;*.mat', ' (*.xml,*.mat)';
123       '*.xml',  '.xml files '; ...
124        '*.mat',  '.mat matlab files '}, ...
125        'Pick a file',oldfile);
126fileinput=[PathName FileName];%complete file name
127testblank=findstr(fileinput,' ');%look for blanks
128if ~isempty(testblank)
129    warndlg_uvmat('forbidden input file name or path: no blank character allowed','ERROR')
130    return
131end
132sizf=size(fileinput);
133if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
134loadfile(handles,fileinput)
135
136%--------------------------------------------------
137%read input xml file and update the edit boxes
138function loadfile(handles,fileinput)
139
140%read the input xml file
141t=xmltree(fileinput);
142s=convert(t);%convert to matlab structure
143
144%read data currently displayed on the interface
145PointCoord=[];
146data=read_probe_calib(handles);
147Coord=[]; %default
148if isfield(data,'Coord')
149    Coord=data.Coord;
150end
151TabChar_0=get(handles.ListCoord,'String');
152nbcoord_0=size(TabChar_0,1);
153if isequal(get(handles.edit_append,'Value'),1) %edit mode
154    val=get(handles.ListCoord,'Value')-1;
155else
156   val=length(TabChar_0);
157end
158nbcoord=0;
159
160%case of calibration (ImaDoc) input file
161if isfield(s,'GeometryCalib')
162    Calib=s.GeometryCalib;
163    if isfield(Calib,'SourceCalib')
164        if isfield(Calib.SourceCalib,'PointCoord')
165            PointCoord=Calib.SourceCalib.PointCoord;
166        end
167        if isfield(Calib.SourceCalib,'ImageCalib')
168            hcalib=get(handles.import,'parent');
169            set(hcalib,'UserData',Calib.SourceCalib.ImageCalib);%store the source image name in the interface 'UserData'
170        end
171    end
172    nbcoord=length(PointCoord);
173    if ~isfield(Calib,'ErrorRms')&~isfield(Calib,'ErrorMax') %old convention of Gauthier (cord in mm)
174        for i=1:length(PointCoord)
175          line=str2num(PointCoord{i});
176          Coord(i+val,4:5)=line(4:5);%px x
177          Coord(i+val,1:3)=line(1:3)/10;%phys x
178        end
179    else
180        for i=1:length(PointCoord)
181          line=str2num(PointCoord{i});
182          Coord(i,4:5)=line(4:5);%px x
183          Coord(i,1:3)=line(1:3);%phys x
184       end
185    end
186end
187
188%case of xml files of points
189if isfield(s,'Coord')
190    PointCoord=s.Coord;
191    nbcoord=length(PointCoord);
192     %case of image coordinates
193    if isfield(s,'CoordType')& isequal(s.CoordType,'px')
194        for i=1:nbcoord
195           line=str2num(PointCoord{i});
196           Coord(i+val,4:5)=line(1:2);
197        end
198     %case of  physical coordinates
199    else
200        for i=1:nbcoord
201           line=str2num(PointCoord{i})
202           Coord(i+val,1:3)=line(1:3);
203           nbcolumn=size(Coord,2);
204           if nbcolumn<5
205               Coord(i+val,nbcolumn+1:5)=zeros(1,5-nbcolumn);
206           end
207        end
208     end
209end
210CoordCell={};
211for iline=1:size(Coord,1)
212    for j=1:5
213        CoordCell{iline,j}=num2str(Coord(iline,j));
214    end
215end
216       
217Tabchar=cell2tab(CoordCell,'    |    ');%transform cells into table ready for display
218set(handles.ListCoord,'Value',1)
219set(handles.ListCoord,'String',Tabchar)
220
221
222%----------------------------------------------------
223% executed when closing: set the parent interface button to value 0
224function closefcn(gcbo,eventdata)
225SetData=get(gcbf,'UserData');
226if isfield(SetData,'ParentButton') & ishandle(SetData.ParentButton)
227    set(SetData.ParentButton, 'Value',0)
228end
229
230%-----------------------------------------------------------------------
231% --- Executes on button press in edit: PLOT the defined object and its projected field
232function edit_Callback(hObject, eventdata, handles)
233%hsetobject=get(hObject,'parent');
234%SetData=get(hsetobject,'UserData');%get the hidden interface data
235%IndexObj=SetData.IndexObj;%index of the current projection object in the list of projection objects (UvData.ProjObject)
236huvmat=findobj(allchild(0),'name','uvmat');%find the current uvmat interface handle
237UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
238hplot=findobj(huvmat,'Tag','axes3');
239h_menu_coord=findobj(huvmat,'Tag','menu_coord');
240menu=get(h_menu_coord,'String');
241choice=get(h_menu_coord,'Value');
242if iscell(menu)
243    option=menu{choice};
244else
245    option='px'; %default
246end
247%get axis
248%get CoordType
249ObjectData=read_probe_calib(handles);%read the interface input parameters defining the object
250if isequal(option,'phys')
251    ObjectData.Coord=ObjectData.Coord(:,[1:3]);
252elseif isequal(option,'px')
253    ObjectData.Coord=ObjectData.Coord(:,[4:5]);
254else
255    errordlg('the choice in coord_coord must be px or phys ')
256end
257% [UvData,IndexObj]=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles);
258% SetData.IndexObj=IndexObj;
259% set(gcbf,'UserData',SetData)%update object index in the probe_calib interface
260% set(huvmat,'UserData',UvData)%update the data in the uvmat interface
261ObjectData.ProjMode='none';
262plot_object(ObjectData,[],hplot,'b');
263
264
265% --- Executes on button press in MenuCoord.
266function MenuCoord_Callback(hObject, eventdata, handles)
267
268
269% --- Executes on button press in delete.
270function delete_Callback(hObject, eventdata, handles)
271SetData=get(gcbf,'UserData');%get the interface data
272IndexObj=SetData.IndexObj;
273delete_object(IndexObj);
274
275% --- Executes on button press in calibrate_lin.
276function calib_offset_Callback(hObject, eventdata, handles)
277Object=read_probe_calib(handles);
278
279%make linear calibration
280% 'calibration_lin' provides a linear transform on coordinates,
281X=Object.Coord(:,1);
282Y=Object.Coord(:,2);
283x_ima=Object.Coord(:,4);
284y_ima=Object.Coord(:,5);
285[px,sx]=polyfit(X,x_ima,1);
286[py,sy]=polyfit(Y,y_ima,1);
287%err_X1=max(abs(x1-x_ima));%error
288%err_Y1=max(abs(y1-y_ima));%error
289T_x=px(2);
290T_y=py(2);
291GeometryCalib.focal=1;
292GeometryCalib.Tx_Ty_Tz=[T_x T_y 1];
293GeometryCalib.R=[px(1),0,0;0,py(1),0;0,0,1];
294%check error
295Calib.dpx=1;
296Calib.dpy=1;
297Calib.sx=1;
298Calib.Cx=0;
299Calib.Cy=0;
300Calib.Tz=1;
301Calib.kappa1=0;
302Calib.f=GeometryCalib.focal;
303Calib.Tx=T_x;
304Calib.Ty=T_y;
305Calib.R=GeometryCalib.R;
306[Xpoints,Ypoints]=px_XYZ(Calib,X,Y,0);
307GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
308GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima));
309GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
310GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima))
311%calibrate_lin calibration results and point coordinates
312huvmat=findobj('Tag','uvmat');
313hchild=get(huvmat,'Children');
314hrootpath=findobj(hchild,'Tag','RootPath');
315hrootfile=findobj(hchild,'Tag','RootFile');
316RootPath='';
317RootFile='';
318if ~isempty(hrootpath)& ~isempty(hrootfile)
319    testhandle=1;
320    RootPath=get(hrootpath,'String');
321    RootFile=get(hrootfile,'String');
322    filebase=fullfile(RootPath,RootFile);
323    outputfile=[filebase '.xml']
324else
325    question={'save the calibration data and point coordinates in'};
326    def={fullfile(RootPath,['ObjectCalib.xml'])};
327    options.Resize='on';
328    answer=inputdlg(question,'save average in a new file',1,def,options);
329    outputfile=answer{1};
330end
331testappend=0;
332if exist(outputfile,'file');%=1 if the output file already exists, 0 else 
333    t=xmltree(outputfile); %read the file
334    uid=find(t,'ImaDoc');
335    if ~isequal(uid,1)%if the xml file is not ImaDoc, delete it (after backup)
336        backupfile=outputfile;
337        testexist=2;
338        while testexist==2
339            backupfile=[backupfile '~'];
340            testexist=exist(backupfile,'file');       
341        end
342        [success,message]=copyfile(outputfile,backupfile);%make backup
343        if isequal(success,1)
344            delete(outputfile)
345        else
346            return
347        end
348    else
349        uid_calib=find(t,'ImaDoc/GeometryCalib');
350        if ~isempty(uid) %if GeometryCalib already exists, delete its content
351            backupfile=outputfile;
352            testexist=2;
353            while testexist==2
354                backupfile=[backupfile '~'];
355                testexist=exist(backupfile,'file');     
356            end
357            [success,message]=copyfile(outputfile,backupfile)%make backup
358            if isequal(success,1)
359                delete(outputfile)
360            else
361                return
362            end
363            uid_child=children(t,uid_calib);
364            t=delete(t,uid_child);
365            testappend=1;
366        end
367    end
368end
369if ~testappend
370    t=xmltree;
371    t=set(t,1,'name','ImaDoc');
372    [t,uid_calib]=add(t,1,'element','GeometryCalib');
373%     t=struct2xml(GeometryCalib,t,uid_calib);
374end
375Object.Coord(:,[1:3])=Object.Coord(:,[1:3])*10; %transform in
376GeometryCalib.SourceCalib.PointCoord=Object.Coord;
377t=struct2xml(GeometryCalib,t,uid_calib);
378save(t,outputfile)
379
380warndlg_uvmat([outputfile 'updated with linear calibration data'],'CONFIRMATION')
381
382%display image with new calibration in the currently opened uvmat interface
383Indices=get(findobj(hchild,'Tag','FileIndex'),'String');
384Ext=get(findobj(hchild,'Tag','FileExt'),'String');
385imagename=[fullfile(RootPath,RootFile) Indices Ext];
386% input.menu_coord=1;
387huvmat=uvmat(imagename,1);%open uvmat, set phys coord (Value 1)
388
389
390
391% --- Executes on button press in calibrate_lin.
392function calib_lin_Callback(hObject, eventdata, handles)
393Object=read_probe_calib(handles);
394
395%make linear calibration
396% 'calibration_lin' provides a linear transform on coordinates,
397X=Object.Coord(:,1);
398Y=Object.Coord(:,2);
399x_ima=Object.Coord(:,4);
400y_ima=Object.Coord(:,5);
401XY_mat=[ones(size(X)) X Y];
402a_X1=XY_mat\x_ima; %transformation matrix for X
403x1=XY_mat*a_X1;%reconstruction
404err_X1=max(abs(x1-x_ima));%error
405a_Y1=XY_mat\y_ima;%transformation matrix for X
406y1=XY_mat*a_Y1;
407err_Y1=max(abs(y1-y_ima));%error
408T_x=a_X1(1);
409T_y=a_Y1(1);
410GeometryCalib.focal=1;
411GeometryCalib.Tx_Ty_Tz=[T_x T_y 1];
412GeometryCalib.R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,1];
413
414%check error
415GeometryCalib.ErrorRms(1)=sqrt(mean((x1-x_ima).*(x1-x_ima)));
416GeometryCalib.ErrorMax(1)=max(abs(x1-x_ima));
417GeometryCalib.ErrorRms(2)=sqrt(mean((y1-y_ima).*(y1-y_ima)));
418GeometryCalib.ErrorMax(2)=max(abs(y1-y_ima))
419
420%calibrate_lin calibration results and point coordinates
421huvmat=findobj('Tag','uvmat');
422hchild=get(huvmat,'Children');
423hrootpath=findobj(hchild,'Tag','RootPath');
424hrootfile=findobj(hchild,'Tag','RootFile');
425RootPath='';
426RootFile='';
427if ~isempty(hrootpath)& ~isempty(hrootfile)
428    testhandle=1;
429    RootPath=get(hrootpath,'String');
430    RootFile=get(hrootfile,'String');
431    filebase=fullfile(RootPath,RootFile);
432    outputfile=[filebase '.xml'];
433else
434    question={'save the calibration data and point coordinates in'};
435    def={fullfile(RootPath,['ObjectCalib.xml'])};
436    options.Resize='on';
437    answer=inputdlg(question,'save average in a new file',1,def,options);
438    outputfile=answer{1};
439end
440testappend=0;
441if exist(outputfile,'file');%=1 if the output file already exists, 0 else 
442    t=xmltree(outputfile); %read the file
443    uid=find(t,'ImaDoc');
444    if ~isequal(uid,1)%if the xml file is not ImaDoc, delete it (after backup)
445        backupfile=outputfile;
446        testexist=2;
447        while testexist==2
448            backupfile=[backupfile '~'];
449            testexist=exist(backupfile,'file');       
450        end
451        [success,message]=copyfile(outputfile,backupfile)%make backup
452        if isequal(success,1);
453            delete(outputfile)
454        else
455            return
456        end
457    else
458        uid_calib=find(t,'ImaDoc/GeometryCalib');
459        if ~isempty(uid) %if GeometryCalib already exists, delete its content
460            backupfile=outputfile;
461            testexist=2;
462            while testexist==2
463                backupfile=[backupfile '~'];
464                testexist=exist(backupfile,'file');     
465            end
466            [success,message]=copyfile(outputfile,backupfile)%make backup
467            if isequal(success,1)
468                delete(outputfile)
469            else
470                return
471            end
472            uid_child=children(t,uid_calib);
473            t=delete(t,uid_child);
474            testappend=1;
475        end
476    end
477end
478if ~testappend
479    t=xmltree;
480    t=set(t,1,'name','ImaDoc');
481    [t,uid_calib]=add(t,1,'element','GeometryCalib');
482%     t=struct2xml(GeometryCalib,t,uid_calib);
483end
484% Object.Coord(:,[1:3])=Object.Coord(:,[1:3]); %transform in
485GeometryCalib.SourceCalib.PointCoord=Object.Coord;
486t=struct2xml(GeometryCalib,t,uid_calib);
487save(t,outputfile)
488
489warndlg_uvmat([outputfile 'updated with linear calibration data'],'CONFIRMATION')
490
491%display image with new calibration in the currently opened uvmat interface
492Indices=get(findobj(hchild,'Tag','FileIndex'),'String');
493Ext=get(findobj(hchild,'Tag','FileExt'),'String');
494imagename=[fullfile(RootPath,RootFile) Indices Ext];
495% input.menu_coord=1;
496if exist(imagename,'file')
497    huvmat=uvmat(imagename,1);%open uvmat, set phys coord (Value 1)
498else
499    huvmat=uvmat;
500end
501
502
503% --- Executes on button press in translation.
504function translation_Callback(hObject, eventdata, handles)
505
506
507function T_x_Callback(hObject, eventdata, handles)
508% hObject    handle to T_x (see GCBO)
509% eventdata  reserved - to be defined in a future version of MATLAB
510% handles    structure with handles and user data (see GUIDATA)
511
512% Hints: get(hObject,'String') returns contents of T_x as text
513%        str2double(get(hObject,'String')) returns contents of T_x as a double
514
515
516
517
518
519function T_y_Callback(hObject, eventdata, handles)
520% hObject    handle to T_y (see GCBO)
521% eventdata  reserved - to be defined in a future version of MATLAB
522% handles    structure with handles and user data (see GUIDATA)
523
524% Hints: get(hObject,'String') returns contents of T_y as text
525%        str2double(get(hObject,'String')) returns contents of T_y as a double
526
527
528function T_z_Callback(hObject, eventdata, handles)
529% hObject    handle to T_z (see GCBO)
530% eventdata  reserved - to be defined in a future version of MATLAB
531% handles    structure with handles and user data (see GUIDATA)
532
533% Hints: get(hObject,'String') returns contents of T_z as text
534%        str2double(get(hObject,'String')) returns contents of T_z as a double
535
536
537% --- Executes on button press in rotation.
538function rotation_Callback(hObject, eventdata, handles)
539angle_rot=(pi/180)*str2num(get(handles.Phi,'String'))
540data=read_probe_calib(handles)
541data.Coord(:,1)=cos(angle_rot)*data.Coord(:,1)+sin(angle_rot)*data.Coord(:,2);
542data.Coord(:,1)=-sin(angle_rot)*data.Coord(:,1)+cos(angle_rot)*data.Coord(:,2);
543set(handles.XObject,'String',num2str(data.Coord(:,1)));
544set(handles.YObject,'String',num2str(data.Coord(:,2)));
545
546
547function XImage_Callback(hObject, eventdata, handles)
548update_list(hObject, eventdata,handles)
549
550function YImage_Callback(hObject, eventdata, handles)
551update_list(hObject, eventdata,handles)
552
553function XObject_Callback(hObject, eventdata, handles)
554update_list(hObject, eventdata,handles)
555
556function YObject_Callback(hObject, eventdata, handles)
557update_list(hObject, eventdata,handles)
558
559function ZObject_Callback(hObject, eventdata, handles)
560update_list(hObject, eventdata,handles)
561
562function update_list(hObject, eventdata, handles)
563str4=get(handles.XImage,'String');
564str5=get(handles.YImage,'String');
565str1=get(handles.XObject,'String');
566tt=double(str1);
567str2=get(handles.YObject,'String');
568str3=get(handles.ZObject,'String');
569if ~isempty(str1) & ~isequal(double(str1),32) & (isempty(str3)|isequal(double(str3),32))
570    str3='0';%put z to 0 by default
571end
572strline=[str1 '    |    ' str2 '    |    ' str3 '    |    ' str4 '    |    ' str5];
573Coord=get(handles.ListCoord,'String');
574testappend=get(handles.edit_append,'Value');
575if isequal(testappend,1); %edit mode 
576    val=get(handles.ListCoord,'Value');
577    Coord{val}=strline;
578else
579    val=length(get(handles.ListCoord,'String'));
580    Coord{val+1}=strline;
581    set(handles.ListCoord,'Value',val+1)
582% if val+1<=length(Coord)
583%     set(handles.ListCoord,'Value',val+1)
584%     ListCoord_Callback(hObject, eventdata, handles)
585end
586set(handles.ListCoord,'String',Coord)
587%set(handles.ListCoord,'Value',val+1)
588
589%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
590function data=read_probe_calib(handles)
591data_XIma=[];
592data_YIma=[];
593data_XObject=[];
594data_YObject=[];
595data_ZObject=[];
596Coord=get(handles.ListCoord,'String');
597% XImage=get(handles.XImage,'String');
598% YImage=get(handles.YImage,'String');
599% XObject=get(handles.XObject,'String');
600% YObject=get(handles.YObject,'String');
601% ZObject=get(handles.ZObject,'String');
602% if ischar(Xcolumn)
603%     Xcolumn={Xcolumn};
604% end
605nb_defining_points=length(Coord);
606iline=0;
607for i=1:nb_defining_points
608    coord_str=Coord{i};%character string of line number i
609    k=findstr('|',coord_str);%find separators '|'
610    data1=str2num(coord_str(1:k(1)-5));
611    data2=str2num(coord_str(k(1)+5:k(2)-5));
612    data3=str2num(coord_str(k(2)+5:k(3)-5));
613    data4=str2num(coord_str(k(3)+5:k(4)-5));
614    data5=str2num(coord_str(k(4)+5:end));
615    if ~isempty(data1)|~isempty(data2)|~isempty(data3)|~isempty(data4)|~isempty(data5)
616        iline=iline+1;
617        if ~isempty(data1)
618            data.Coord(iline,1)=data1;
619        end   
620        if ~isempty(data2)
621            data.Coord(iline,2)=data2;
622        end
623        if ~isempty(data3)
624            data.Coord(iline,3)=data3;
625        end
626        if ~isempty(data4)
627            data.Coord(iline,4)=data4;
628        end
629        if isempty(data5)
630            data.Coord(iline,5)=0;
631        else
632            data.Coord(iline,5)=data5;
633        end
634    end
635end
636data.Style='points';
637
638
639% --- Executes on selection change in ListCoord.
640function ListCoord_Callback(hObject, eventdata, handles)
641% hObject    handle to ListCoord (see GCBO)
642% eventdata  reserved - to be defined in a future version of MATLAB
643% handles    structure with handles and user data (see GUIDATA)
644
645% Hints: contents = get(hObject,'String') returns ListCoord contents as cell array
646%        contents{get(hObject,'Value')} returns selected item from ListCoord
647set(handles.edit_append,'Value',1); %set to edit mode
648Coord=get(handles.ListCoord,'String');
649val=get(handles.ListCoord,'Value');
650if length(Coord)>0
651coord_str=Coord{val};
652k=findstr('|',coord_str);
653set(handles.XObject,'String',coord_str(1:k(1)-5))
654set(handles.YObject,'String',coord_str(k(1)+5:k(2)-5))
655set(handles.ZObject,'String',coord_str(k(2)+5:k(3)-5))
656set(handles.XImage,'String',coord_str(k(3)+5:k(4)-5))
657set(handles.YImage,'String',coord_str(k(4)+5:end))
658end
659
660%------------------------------------------------------
661% --- Executes on button press in translation_plus.
662function translation_plus_Callback(hObject, eventdata, handles)
663
664T=[0 0 0];
665T_x=get(handles.T_x,'String')
666T_y=get(handles.T_y,'String')
667T_z=get(handles.T_z,'String')
668if ~isempty(T_x)
669    T(1)=str2num(T_x);
670end
671if ~isempty(T_y)
672    T(2)=str2num(T_y);
673end
674if ~isempty(T_z)
675    T(3)=str2num(T_z);
676end
677translation(handles,T)
678
679
680
681% --- Executes on button press in translation_minus.
682function translation_minus_Callback(hObject, eventdata, handles)
683
684T=[0 0 0];
685T_x=get(handles.T_x,'String')
686T_y=get(handles.T_y,'String')
687T_z=get(handles.T_z,'String')
688if ~isempty(T_x)
689    T(1)=-str2num(T_x);
690end
691if ~isempty(T_y)
692    T(2)=-str2num(T_y);
693end
694if ~isempty(T_z)
695    T(3)=-str2num(T_z);
696end
697translation(handles,T)
698
699
700%%%--------------------------------------
701function translation(handles,T)
702data=read_probe_calib(handles);
703data.Coord(:,1)=T(1)+data.Coord(:,1);
704data.Coord(:,2)=T(2)+data.Coord(:,2);
705data.Coord(:,3)=T(3)+data.Coord(:,3);
706data.Coord(:,[4 5])=data.Coord(:,[4 5]);
707for i=1:size(data.Coord,1)
708    for j=1:5
709          Coord{i,j}=num2str(data.Coord(i,j));%phys x,y,z
710   end
711end
712Tabchar=cell2tab(Coord,'    |    ');
713set(handles.ListCoord,'String',Tabchar)
714
715%----------------------------------------------------
716% --- Executes on button press in rotation_plus.
717function rotation_plus_Callback(hObject, eventdata, handles)
718Phi=0;
719Phi=get(handles.Phi,'String')
720if ~isempty(Phi)
721    Phi=str2num(Phi);
722end
723rotation(handles,Phi)
724
725%-------------------------------------------------
726% --- Executes on button press in rotation_minus.
727function rotation_minus_Callback(hObject, eventdata, handles)
728Phi=0;
729Phi=get(handles.Phi,'String')
730if ~isempty(Phi)
731    Phi=-str2num(Phi);
732end
733rotation(handles,Phi)
734
735%-----------------------------------------------------
736%rotation
737function rotation(handles,Phi)
738O_x=str2num(get(handles.O_x,'String'));
739O_y=str2num(get(handles.O_y,'String'));
740if isempty(O_x)
741    O_x=0;%default
742end
743if isempty(O_y)
744    O_y=0;%default
745end
746data=read_probe_calib(handles);
747r1=cos(pi*Phi/180);
748r2=-sin(pi*Phi/180);
749r3=sin(pi*Phi/180);
750r4=cos(pi*Phi/180);
751data.Coord(:,1)=r1*data.Coord(:,1)+r2*data.Coord(:,2);
752data.Coord(:,2)=r3*data.Coord(:,1)+r4*data.Coord(:,2);
753% data.Coord(:,[4 5])=data.Coord(:,[4 5]);
754for i=1:size(data.Coord,1)
755    for j=1:5
756          Coord{i,j}=num2str(data.Coord(i,j));%phys x,y,z
757   end
758end
759Tabchar=cell2tab(Coord,'    |    ');
760set(handles.ListCoord,'String',Tabchar)
761
762function O_x_Callback(hObject, eventdata, handles)
763% hObject    handle to O_x (see GCBO)
764% eventdata  reserved - to be defined in a future version of MATLAB
765% handles    structure with handles and user data (see GUIDATA)
766
767% Hints: get(hObject,'String') returns contents of O_x as text
768%        str2double(get(hObject,'String')) returns contents of O_x as a double
769
770
771
772function O_y_Callback(hObject, eventdata, handles)
773% hObject    handle to O_y (see GCBO)
774% eventdata  reserved - to be defined in a future version of MATLAB
775% handles    structure with handles and user data (see GUIDATA)
776
777% Hints: get(hObject,'String') returns contents of O_y as text
778%        str2double(get(hObject,'String')) returns contents of O_y as a double
779
780
781function O_z_Callback(hObject, eventdata, handles)
782% hObject    handle to O_z (see GCBO)
783% eventdata  reserved - to be defined in a future version of MATLAB
784% handles    structure with handles and user data (see GUIDATA)
785
786% Hints: get(hObject,'String') returns contents of O_z as text
787%        str2double(get(hObject,'String')) returns contents of O_z as a double
788
789
790
791
792
793
794
795% --- Executes on selection change in edit_append.
796function edit_append_Callback(hObject, eventdata, handles)
797val=get(handles.edit_append,'Value');
798if isequal(val,2); %append mode
799    %appeler mouse
800end
801
802
803function NEW_Callback(hObject, eventdata, handles)
804%A METTRE SOUS UN BOUTON
805huvmat=findobj('name','uvmat');
806hchild=get(huvmat,'children');
807hcoord=findobj(hchild,'Tag','menu_coord')
808coordtype=get(hcoord,'Value')
809haxes=findobj(hchild,'Tag','axes3');
810AxeData=get(haxes,'UserData');
811if ~isequal(hcoord,2)
812    set(hcoord,'Value',2)
813    huvmat=uvmat(AxeData)
814    'relancer uvmat'
815end
816if ~isfield(AxeData,'ZoomAxes')
817    warndlg_uvmat('first draw a window around a grid marker','ERRROR')
818    return
819end
820XLim=get(AxeData.ZoomAxes,'XLim');
821YLim=get(AxeData.ZoomAxes,'YLim');
822np=size(AxeData.A);
823ind_sub_x=round(XLim)
824ind_sub_y=np(1)-round(YLim)
825Mfiltre=AxeData.A([ind_sub_y(2):ind_sub_y(1)] ,ind_sub_x,:);
826Mfiltre_norm=double(Mfiltre);
827Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm));
828Mfiltre_norm=100*(Mfiltre_norm-mean(mean(Mfiltre_norm)));
829Atype=class(AxeData.A)
830Data.NbDim=2;
831Data.A=filter2(Mfiltre_norm,double(AxeData.A));
832Data.A=feval(Atype,Data.A);
833Data.AName='image';
834Data.AX=AxeData.AX;
835Data.AY=AxeData.AY;
836Data.CoordType='px';
837plot_field(Data)
838 
839
840% --- Executes on button press in HELP.
841function HELP_Callback(hObject, eventdata, handles)
842% hObject    handle to HELP (see GCBO)
843% eventdata  reserved - to be defined in a future version of MATLAB
844% handles    structure with handles and user data (see GUIDATA)
845path_to_uvmat=which ('uvmat');% check the path of uvmat
846pathelp=fileparts(path_to_uvmat);
847helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
848if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
849else
850   web([helpfile '#probe_calib'])
851end
852
853%'move_key:' function activated when a key is pressed on the keyboard
854%-----------------------------------
855function key_press_fcn(hObject,eventdata,handles)
856hh=get(hObject,'parent')
857xx=double(get(hh,'CurrentCharacter')) %get the keyboard character
858
859if isequal(xx,8)%move arrow right
860   data=read_probe_calib(handles);
861    Coord=[]; %default
862    if isfield(data,'Coord')
863        Coord=data.Coord
864    end
865    val=get(handles.ListCoord,'Value');
866    Coord(val,:)=[];
867    CoordCell={};
868    for iline=1:size(Coord,1)
869        for j=1:5
870            CoordCell{iline,j}=num2str(Coord(iline,j));
871        end
872    end
873    Tabchar=cell2tab(CoordCell,'    |    ');%transform cells into table ready for display
874    val=min(size(Coord,1),val);
875    set(handles.ListCoord,'Value',max(val,1))
876    set(handles.ListCoord,'String',Tabchar) 
877end
Note: See TracBrowser for help on using the repository browser.