Changeset 71 for trunk/src/geometry_calib.m
- Timestamp:
- Mar 29, 2010, 6:34:55 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/geometry_calib.m
r69 r71 78 78 % Update handles structure 79 79 guidata(hObject, handles); 80 %movegui(hObject,'east');% position the GUI ton the right of the screen 81 % if exist('handles_uvmat','var') %& isfield(data,'ParentButton') 82 set(hObject,'DeleteFcn',{@closefcn})% 83 % end 80 set(hObject,'DeleteFcn',{@closefcn})% 81 84 82 %set the position of the interface 85 83 if exist('pos','var')& length(pos)>2 … … 100 98 end 101 99 end 102 set(handles.ListCoord,'String',{'... '})100 set(handles.ListCoord,'String',{'......'}) 103 101 if exist(inputxml,'file') 104 102 loadfile(handles,inputxml)% load the point coordiantes existing in the xml file … … 106 104 107 105 set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function 108 %set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function on uvmat interface when geometry_calib is on top 109 %htable=uitable(10,5) 110 %set(htable,'ColumnNames',{'x','y','z','X(pixels)','Y(pixels)'}) 106 111 107 112 108 %------------------------------------------------------------------------ … … 214 210 end 215 211 end 216 CoordCell=[CoordCell;{' ',' ',' ',' ',' '}];212 % CoordCell=[CoordCell;{' ',' ',' ',' ',' '}]; 217 213 Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display 214 Tabchar=[Tabchar;{'......'}]; 218 215 set(handles.ListCoord,'Value',1) 219 216 set(handles.ListCoord,'String',Tabchar) 217 MenuPlot_Callback(handles.geometry_calib, [], handles) 220 218 221 219 % … … 227 225 if ~isempty(huvmat) 228 226 handles=guidata(huvmat); 229 set(handles.MenuTools,'enable','on') 227 set(handles.MenuMask,'enable','on') 228 set(handles.MenuGrid,'enable','on') 230 229 set(handles.MenuObject,'enable','on') 231 230 set(handles.MenuEdit,'enable','on') … … 298 297 set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7]) 299 298 uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat 300 299 MenuPlot_Callback(hObject, eventdata, handles) 301 300 figure(handles.geometry_calib) 302 301 … … 450 449 % est_kc=[1;0;0;0;0]; 451 450 est_dist=[1;0;0;0;0]; 452 run( 'D:\PROG\MATLAB\TOOLBOX_calib\go_calib_optim');451 run(fullfile(path_UVMAT,'TOOLBOX_calib','go_calib_optim')); 453 452 454 453 GeometryCalib.CalibrationType='tsai'; … … 497 496 sparam=convert(t); 498 497 end 499 if ~isfield(sparam,'GeometryCalib _exe')500 msgbox_uvmat('ERROR',['calibration program <GeometryCalib _exe> undefined in parameter file ' xmlfile])498 if ~isfield(sparam,'GeometryCalibBin') 499 msgbox_uvmat('ERROR',['calibration program <GeometryCalibBin> undefined in parameter file ' xmlfile]) 501 500 return 502 501 end 503 Tsai_exe=sparam.GeometryCalib _exe;502 Tsai_exe=sparam.GeometryCalibBin; 504 503 if ~exist(Tsai_exe,'file')%the binary is defined in /bin, default setting 505 504 Tsai_exe=fullfile(path_UVMAT,Tsai_exe); 506 505 end 507 506 if ~exist(Tsai_exe,'file') 508 msgbox_uvmat('ERROR',['calibration program ' sparam.GeometryCalib _exe' defined in PARAM.xml does not exist'])507 msgbox_uvmat('ERROR',['calibration program ' sparam.GeometryCalibBin ' defined in PARAM.xml does not exist']) 509 508 return 510 509 end … … 643 642 ListCoord_Callback(hObject, eventdata, handles) 644 643 MenuPlot_Callback(hObject, eventdata, handles) 644 645 645 %------------------------------------------------------------------------ 646 646 % --- Executes on selection change in ListCoord. 647 647 function ListCoord_Callback(hObject, eventdata, handles) 648 648 %------------------------------------------------------------------------ 649 huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle 650 hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat 651 hhh=findobj(hplot,'Tag','calib_marker'); 649 652 Coord_cell=get(handles.ListCoord,'String'); 650 653 val=get(handles.ListCoord,'Value'); 651 if length(Coord_cell)>0 652 coord_str=Coord_cell{val}; 653 k=findstr('|',coord_str); 654 if isempty(k) 655 return 656 end 657 set(handles.XObject,'String',coord_str(1:k(1)-5)) 658 set(handles.YObject,'String',coord_str(k(1)+5:k(2)-5)) 659 set(handles.ZObject,'String',coord_str(k(2)+5:k(3)-5)) 660 set(handles.XImage,'String',coord_str(k(3)+5:k(4)-5)) 661 set(handles.YImage,'String',coord_str(k(4)+5:end)) 662 huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle 663 hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat 664 h_menu_coord=findobj(huvmat,'Tag','menu_coord'); 665 menu=get(h_menu_coord,'String'); 666 choice=get(h_menu_coord,'Value'); 667 if iscell(menu) 668 option=menu{choice}; 669 else 670 option='px'; %default 671 end 672 if isequal(option,'phys') 673 XCoord=str2num(coord_str(1:k(1)-5)); 674 YCoord=str2num(coord_str(k(1)+5:k(2)-5)); 675 elseif isequal(option,'px')|| isequal(option,'') 676 XCoord=str2num(coord_str(k(3)+5:k(4)-5)); 677 YCoord=str2num(coord_str(k(4)+5:end)); 678 else 679 msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be px or phys ') 680 end 681 huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle 682 hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat 683 hhh=findobj(hplot,'Tag','calib_marker'); 684 if isempty(hhh) 685 axes(hplot) 686 line(XCoord,YCoord,'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',20); 687 else 688 set(hhh,'XData',XCoord) 689 set(hhh,'YData',YCoord) 690 end 654 coord_str=Coord_cell{val}; 655 k=findstr('|',coord_str); 656 if isempty(k)%last line '.....' selected 657 if ~isempty(hhh) 658 delete(hhh)%delete the circle marker 659 end 660 return 661 end 662 %fill the edit boxex 663 set(handles.XObject,'String',coord_str(1:k(1)-5)) 664 set(handles.YObject,'String',coord_str(k(1)+5:k(2)-5)) 665 set(handles.ZObject,'String',coord_str(k(2)+5:k(3)-5)) 666 set(handles.XImage,'String',coord_str(k(3)+5:k(4)-5)) 667 set(handles.YImage,'String',coord_str(k(4)+5:end)) 668 h_menu_coord=findobj(huvmat,'Tag','transform_fct'); 669 menu=get(h_menu_coord,'String'); 670 choice=get(h_menu_coord,'Value'); 671 if iscell(menu) 672 option=menu{choice}; 673 else 674 option='px'; %default 675 end 676 if isequal(option,'phys') 677 XCoord=str2num(coord_str(1:k(1)-5)); 678 YCoord=str2num(coord_str(k(1)+5:k(2)-5)); 679 elseif isequal(option,'px')|| isequal(option,'') 680 XCoord=str2num(coord_str(k(3)+5:k(4)-5)); 681 YCoord=str2num(coord_str(k(4)+5:end)); 682 else 683 msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be px or phys ') 684 end 685 if isempty(XCoord)||isempty(YCoord) 686 if ~isempty(hhh) 687 delete(hhh)%delete the circle marker 688 end 689 return 690 end 691 xlim=get(hplot,'XLim'); 692 ylim=get(hplot,'YLim'); 693 ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/20;%defines the size of the circle marker 694 if isempty(hhh) 695 axes(hplot) 696 rectangle('Curvature',[1 1],... 697 'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range],'EdgeColor','m',... 698 'LineStyle','-','Tag','calib_marker'); 699 else 700 set(hhh,'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range]) 691 701 end 692 702 … … 744 754 Data.CoordType='px'; 745 755 plot_field(Data) 746 747 756 748 757 %------------------------------------------------------------------------ … … 750 759 function key_press_fcn(hObject,eventdata,handles) 751 760 %------------------------------------------------------------------------ 752 hh=get(hObject,'parent'); 753 xx=double(get(hh,'CurrentCharacter')); %get the keyboard character 754 761 xx=double(get(handles.geometry_calib,'CurrentCharacter')); %get the keyboard character 755 762 if ismember(xx,[8 127])%backspace or delete 756 763 Coord_cell=get(handles.ListCoord,'String'); 757 data=read_geometry_calib(Coord_cell);758 Coord=[]; %default759 if isfield(data,'Coord')760 Coord=data.Coord;761 end762 764 val=get(handles.ListCoord,'Value'); 763 Coord(val,:)=[];%suppress the selected item in the list 764 CoordCell={}; 765 for iline=1:size(Coord,1) 766 for j=1:5 767 CoordCell{iline,j}=num2str(Coord(iline,j),4); 768 end 769 end 770 Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display 771 val=min(size(Coord,1),val); 772 set(handles.ListCoord,'Value',max(val,1)) 773 set(handles.ListCoord,'String',Tabchar) 774 ListCoord_Callback(hObject, eventdata, handles) 775 MenuPlot_Callback(hObject,eventdata,handles) 776 end 777 778 %------------------------------------------------------------------------ 779 % --- Executes on button press in append_point. 780 function append_point_Callback(hObject, eventdata, handles) 781 %------------------------------------------------------------------------ 782 Coord=get(handles.ListCoord,'String'); 783 val=length(Coord); 784 if val>=1 & isequal(Coord{val},'') 785 val=val-1; %do not take into account blank 786 end 787 Coord{val+1}=''; 788 set(handles.ListCoord,'String',Coord) 789 set(handles.ListCoord,'Value',val+1) 765 if val<numel(Coord_cell) % the last element '...' has not been selected 766 Coord_cell(val)=[];%remove the selected line 767 set(handles.ListCoord,'String',Coord_cell) 768 ListCoord_Callback(hObject, eventdata, handles) 769 MenuPlot_Callback(hObject,eventdata,handles) 770 end 771 end 772 773 % %------------------------------------------------------------------------ 774 % % --- Executes on button press in append_point. 775 % function append_point_Callback(hObject, eventdata, handles) 776 % %------------------------------------------------------------------------ 777 % Coord=get(handles.ListCoord,'String'); 778 % val=length(Coord); 779 % if val>=1 & isequal(Coord{val},'') 780 % val=val-1; %do not take into account blank 781 % end 782 % Coord{val+1}=''; 783 % set(handles.ListCoord,'String',Coord) 784 % set(handles.ListCoord,'Value',val+1) 790 785 791 786 %------------------------------------------------------------------------ … … 836 831 ObjectData=read_geometry_calib(Coord_cell); 837 832 %ObjectData=read_geometry_calib(handles);%read the interface input parameters defining the object 838 if isequal(option,'phys') 839 ObjectData.Coord=ObjectData.Coord(:,[1:3]); 840 elseif isequal(option,'px')||isequal(option,'') 841 ObjectData.Coord=ObjectData.Coord(:,[4:5]); 842 else 843 msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be px or phys ') 833 if ~isempty(ObjectData.Coord) 834 if isequal(option,'phys') 835 ObjectData.Coord=ObjectData.Coord(:,[1:3]); 836 elseif isequal(option,'px')||isequal(option,'') 837 ObjectData.Coord=ObjectData.Coord(:,[4:5]); 838 else 839 msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be '''', px or phys ') 840 end 844 841 end 845 842 axes(hhuvmat.axes3) 846 843 hh=findobj('Tag','calib_points'); 847 if isempty(hh)844 if ~isempty(ObjectData.Coord) && isempty(hh) 848 845 hh=line(ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color','m','Tag','calib_points','LineStyle','.','Marker','+'); 846 elseif isempty(ObjectData.Coord)%empty list of points, suppress the plot 847 delete(hh) 849 848 else 850 849 set(hh,'XData',ObjectData.Coord(:,1)) … … 874 873 Tinput=CalibData.grid; 875 874 end 876 [T,CalibData.grid]=create_grid( grid_input);%display the GUI create_grid875 [T,CalibData.grid]=create_grid(Tinput);%display the GUI create_grid 877 876 set(handles.geometry_calib,'UserData',CalibData) 878 877 879 878 %grid in phys space 880 Coord_cell=get(handles.ListCoord,'String'); 881 data=read_geometry_calib(Coord_cell); 882 nbpoints=size(data.Coord,1); %nbre of calibration points 883 data.Coord(1:size(T,1),1:3)=T;%update the existing list of phys coordinates from the GUI create_grid 884 for i=1:nbpoints 885 for j=1:5 879 Coord=get(handles.ListCoord,'String'); 880 val=get(handles.ListCoord,'Value'); 881 data=read_geometry_calib(Coord); 882 %nbpoints=size(data.Coord,1); %nbre of calibration points 883 data.Coord(val:val+size(T,1)-1,1:3)=T(end:-1:1,:);%update the existing list of phys coordinates from the GUI create_grid 884 % for i=1:nbpoints 885 % for j=1:5 886 % Coord{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits 887 % end 888 % end 889 %update the phys coordinates starting from the selected point (down in the 890 Coord(end,:)=[]; %remove last string '.....' 891 for i=1:size(data.Coord,1) 892 for j=1:5 886 893 Coord{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits 887 end 888 end 889 for i=nbpoints+1:size(data.Coord,1) 890 for j=1:3 891 Coord{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits 892 end 893 for j=4:5 894 Coord{i,j}='';%display coordiantes with 4 digi 895 end 896 end 897 894 end 895 end 898 896 899 897 %size(data.Coord,1) 900 898 Tabchar=cell2tab(Coord,' | '); 901 set(handles.ListCoord,'Value',1) 899 Tabchar=[Tabchar ;{'......'}]; 902 900 set(handles.ListCoord,'String',Tabchar) 903 901 904 %----------------------------------------------------------------------- 905 function MenuTranslatePoints_Callback(hObject, eventdata, handles) 906 %----------------------------------------------------------------------- 907 %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib 908 CalibData=get(handles.geometry_calib,'UserData'); 909 Tinput=[];%default 910 if isfield(CalibData,'translate') 911 Tinput=CalibData.translate; 912 end 913 T=translate_points(Tinput);%display translate_points GUI and get shift parameters 914 CalibData.translate=T; 915 set(handles.geometry_calib,'UserData',CalibData) 916 %translation 917 Coord_cell=get(handles.ListCoord,'String'); 918 data=read_geometry_calib(Coord_cell); 919 data.Coord(:,1)=T(1)+data.Coord(:,1); 920 data.Coord(:,2)=T(2)+data.Coord(:,2); 921 data.Coord(:,3)=T(3)+data.Coord(:,3); 922 data.Coord(:,[4 5])=data.Coord(:,[4 5]); 923 for i=1:size(data.Coord,1) 924 for j=1:5 925 Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z 926 end 927 end 928 Tabchar=cell2tab(Coord,' | '); 929 set(handles.ListCoord,'Value',1) 930 set(handles.ListCoord,'String',Tabchar) 931 932 933 % -------------------------------------------------------------------- 934 function MenuRotatePoints_Callback(hObject, eventdata, handles) 935 %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib 936 CalibData=get(handles.geometry_calib,'UserData'); 937 Tinput=[];%default 938 if isfield(CalibData,'rotate') 939 Tinput=CalibData.rotate; 940 end 941 T=rotate_points(Tinput);%display translate_points GUI and get shift parameters 942 CalibData.rotate=T; 943 set(handles.geometry_calib,'UserData',CalibData) 944 %----------------------------------------------------- 945 %rotation 946 Phi=T(1); 947 O_x=0;%default 948 O_y=0;%default 949 if numel(T)>=2 950 O_x=T(2);%default 951 end 952 if numel(T)>=3 953 O_y=T(3);%default 954 end 955 Coord_cell=get(handles.ListCoord,'String'); 956 data=read_geometry_calib(Coord_cell); 957 r1=cos(pi*Phi/180); 958 r2=-sin(pi*Phi/180); 959 r3=sin(pi*Phi/180); 960 r4=cos(pi*Phi/180); 961 x=data.Coord(:,1)-O_x; 962 y=data.Coord(:,2)-O_y; 963 data.Coord(:,1)=r1*x+r2*y; 964 data.Coord(:,2)=r3*x+r4*y; 965 % data.Coord(:,[4 5])=data.Coord(:,[4 5]); 966 for i=1:size(data.Coord,1) 967 for j=1:5 968 Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z 969 end 970 end 971 Tabchar=cell2tab(Coord,' | '); 972 set(handles.ListCoord,'Value',1) 973 set(handles.ListCoord,'String',Tabchar) 974 % -------------------------------------------------------------------- 902 % ----------------------------------------------------------------------- 903 % --- automatic grid dectection from local maxima of the images 975 904 function MenuDetectGrid_Callback(hObject, eventdata, handles) 976 905 %------------------------------------------------------------------------ 977 906 CalibData=get(handles.geometry_calib,'UserData'); 978 907 grid_input=[];%default … … 989 918 if nbpoints~=4 990 919 msgbox_uvmat('ERROR','four points must be selected by the mouse, beginning by the new x axis, to delimitate the phs grid area') 991 end 992 corners_X=(data.Coord(end-3:end,4)); %pixel absissa of the four corners 993 corners_Y=(data.Coord(end-3:end,5)); 994 995 %reorder the last two points if needed 920 return 921 end 922 corners_X=(data.Coord(end:-1:end-3,4)); %pixel absissa of the four corners 923 corners_Y=(data.Coord(end:-1:end-3,5)); 924 925 %reorder the last two points (the two first in the list) if needed 996 926 angles=angle((corners_X-corners_X(1))+i*(corners_Y-corners_Y(1))); 997 927 if abs(angles(4)-angles(2))>abs(angles(3)-angles(2)) … … 1015 945 a_X1=XY_mat\corners_X; %transformation matrix for X 1016 946 x1=XY_mat*a_X1;%reconstruction 1017 err_X1=max(abs(x1-corners_X)) %error947 err_X1=max(abs(x1-corners_X));%error 1018 948 a_Y1=XY_mat\corners_Y;%transformation matrix for X 1019 949 y1=XY_mat*a_Y1; 1020 err_Y1=max(abs(y1-corners_Y)) %error950 err_Y1=max(abs(y1-corners_Y));%error 1021 951 GeometryCalib.CalibrationType='linear'; 1022 952 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function … … 1072 1002 Coord{ipoint,5}=num2str(Ypx(ipoint),4);%display coordiantes with 4 digi 1073 1003 end 1074 Tabchar=cell2tab(Coord,' | '); 1004 Tabchar=cell2tab(Coord(end:-1:1,:),' | '); 1005 Tabchar=[Tabchar ;{'......'}]; 1075 1006 set(handles.ListCoord,'Value',1) 1076 1007 set(handles.ListCoord,'String',Tabchar) 1077 1008 MenuPlot_Callback(hObject, eventdata, handles) 1009 1010 %----------------------------------------------------------------------- 1011 function MenuTranslatePoints_Callback(hObject, eventdata, handles) 1012 %----------------------------------------------------------------------- 1013 %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib 1014 CalibData=get(handles.geometry_calib,'UserData'); 1015 Tinput=[];%default 1016 if isfield(CalibData,'translate') 1017 Tinput=CalibData.translate; 1018 end 1019 T=translate_points(Tinput);%display translate_points GUI and get shift parameters 1020 CalibData.translate=T; 1021 set(handles.geometry_calib,'UserData',CalibData) 1022 %translation 1023 Coord_cell=get(handles.ListCoord,'String'); 1024 data=read_geometry_calib(Coord_cell); 1025 data.Coord(:,1)=T(1)+data.Coord(:,1); 1026 data.Coord(:,2)=T(2)+data.Coord(:,2); 1027 data.Coord(:,3)=T(3)+data.Coord(:,3); 1028 data.Coord(:,[4 5])=data.Coord(:,[4 5]); 1029 for i=1:size(data.Coord,1) 1030 for j=1:5 1031 Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z 1032 end 1033 end 1034 Tabchar=cell2tab(Coord,' | '); 1035 Tabchar=[Tabchar {'.....'}]; 1036 %set(handles.ListCoord,'Value',1) 1037 set(handles.ListCoord,'String',Tabchar) 1038 1039 1040 % -------------------------------------------------------------------- 1041 function MenuRotatePoints_Callback(hObject, eventdata, handles) 1042 %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib 1043 CalibData=get(handles.geometry_calib,'UserData'); 1044 Tinput=[];%default 1045 if isfield(CalibData,'rotate') 1046 Tinput=CalibData.rotate; 1047 end 1048 T=rotate_points(Tinput);%display translate_points GUI and get shift parameters 1049 CalibData.rotate=T; 1050 set(handles.geometry_calib,'UserData',CalibData) 1051 %----------------------------------------------------- 1052 %rotation 1053 Phi=T(1); 1054 O_x=0;%default 1055 O_y=0;%default 1056 if numel(T)>=2 1057 O_x=T(2);%default 1058 end 1059 if numel(T)>=3 1060 O_y=T(3);%default 1061 end 1062 Coord_cell=get(handles.ListCoord,'String'); 1063 data=read_geometry_calib(Coord_cell); 1064 r1=cos(pi*Phi/180); 1065 r2=-sin(pi*Phi/180); 1066 r3=sin(pi*Phi/180); 1067 r4=cos(pi*Phi/180); 1068 x=data.Coord(:,1)-O_x; 1069 y=data.Coord(:,2)-O_y; 1070 data.Coord(:,1)=r1*x+r2*y; 1071 data.Coord(:,2)=r3*x+r4*y; 1072 % data.Coord(:,[4 5])=data.Coord(:,[4 5]); 1073 for i=1:size(data.Coord,1) 1074 for j=1:5 1075 Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z 1076 end 1077 end 1078 Tabchar=cell2tab(Coord,' | '); 1079 Tabchar=[Tabchar;{'......'}]; 1080 set(handles.ListCoord,'Value',1) 1081 set(handles.ListCoord,'String',Tabchar) 1082 1078 1083 1079 1084 %%%%%%%%%%%%%%%%%%%%
Note: See TracChangeset
for help on using the changeset viewer.