Changeset 657 for trunk/src/geometry_calib.m
- Timestamp:
- Jul 3, 2013, 12:07:26 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/geometry_calib.m
r655 r657 50 50 % Edit the above text to modify the response to help geometry_calib 51 51 52 % Last Modified by GUIDE v2.5 29-Jun-2013 23:52:3652 % Last Modified by GUIDE v2.5 03-Jul-2013 09:23:35 53 53 54 54 % Begin initialization code - DO NOT edit … … 60 60 'gui_LayoutFcn', [] , ... 61 61 'gui_Callback', []); 62 if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once'))62 if nargin && ischar(varargin{1}) %&& ~isempty(regexp(varargin{1},'_Callback','once')) 63 63 gui_State.gui_Callback = str2func(varargin{1}); 64 64 end … … 78 78 % parameters on the uvmat interface (obtained by 'get_plot_handle.m') 79 79 %------------------------------------------------------------------------ 80 function geometry_calib_OpeningFcn(hObject, eventdata, handles,inputfile ,pos)80 function geometry_calib_OpeningFcn(hObject, eventdata, handles,inputfile) 81 81 %------------------------------------------------------------------------ 82 82 % Choose default command line output for geometry_calib … … 87 87 guidata(hObject, handles); 88 88 set(hObject,'DeleteFcn',{@closefcn})% 89 set(hObject,'WindowButtonDownFcn',{'mouse_alt_gui',handles}) % allows mouse action with right button (zoom for uicontrol display)89 %set(hObject,'WindowButtonDownFcn',{'mouse_alt_gui',handles}) % allows mouse action with right button (zoom for uicontrol display) 90 90 91 91 %% position 92 set(0,'Unit','p oints')92 set(0,'Unit','pixels') 93 93 ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right 94 Width=350;% fig width in points (1/72 inch) 95 Height=min(0.9*ScreenSize(4),700); 94 FigSize=get(handles.geometry_calib,'Position'); 95 96 Width=FigSize(3);% fig width in points (1/72 inch) 97 Height=FigSize(4); 96 98 Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40 97 99 Bottom=ScreenSize(4)-Height-40; %put fig at top right 98 set(handles.geometry_calib,'Unit','points')99 100 set(handles.geometry_calib,'Position',[Left Bottom Width Height]) 100 101 … … 121 122 end 122 123 end 123 set(handles.ListCoord,'String',{'......'}) 124 set(handles.ListCoord,'Data',[]) 125 % set(handles.ListCoord,'Data',{[] [] [] [] [] []}) 124 126 if exist(inputfile,'file') 125 127 Heading=loadfile(handles,inputfile);% load data from the xml file … … 136 138 %------------------------------------------------------------------------ 137 139 % --- Outputs from this function are returned to the command line. 138 function varargout = geometry_calib_OutputFcn( hObject, eventdata, handles)140 function varargout = geometry_calib_OutputFcn(~, eventdata, handles) 139 141 %------------------------------------------------------------------------ 140 142 % Get default command line output from handles structure … … 209 211 uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat, show the image in phys coordinates 210 212 PLOT_Callback(hObject, eventdata, handles) 211 set(handles.ListCoord,'Value',index)% indicate in the list the point with max deviation (possible mistake) 212 ListCoord_Callback(hObject, eventdata, handles) 213 Data=get(handles.ListCoord,'Data'); 214 Data(:,6)=zeros(size(Data,1),1); 215 Data(index,6)=1;% indicate in the list the point with max deviation (possible mistake) 216 set(handles.ListCoord,'Data',Data)% indicate in the list the point with max deviation (possible mistake) 217 %ListCoord_Callback(hObject, eventdata, handles) 213 218 figure(handles.geometry_calib) 214 219 … … 259 264 %------------------------------------------------------------------------ 260 265 %% read the current calibration points 261 Coord_cell=get(handles.ListCoord,'String'); 262 Object=read_geometry_calib(Coord_cell); 263 Coord=Object.Coord; 266 %Coord_cell=get(handles.ListCoord,'Data'); 267 %Object=read_geometry_calib(Coord_cell); 268 Coord=get(handles.ListCoord,'Data'); 269 Coord(:,6)=[]; 264 270 % apply the calibration, whose type is selected in handles.calib_type 265 271 if ~isempty(Coord) … … 708 714 % --- Executes on button press in STORE. 709 715 function STORE_Callback(hObject, eventdata, handles) 710 Coord _cell=get(handles.ListCoord,'String');711 Object=read_geometry_calib(Coord_cell);716 Coord=get(handles.ListCoord,'Data'); 717 %Object=read_geometry_calib(Coord_cell); 712 718 unitlist=get(handles.CoordUnit,'String'); 713 719 unit=unitlist{get(handles.CoordUnit,'value')}; 714 720 GeometryCalib.CoordUnit=unit; 715 GeometryCalib.SourceCalib.PointCoord= Object.Coord;721 GeometryCalib.SourceCalib.PointCoord=Coord(:,1:5); 716 722 huvmat=findobj(allchild(0),'Name','uvmat'); 717 723 hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat … … 739 745 set(handles.coord_files,'string',listfile); 740 746 end 741 set(handles.ListCoord,'Value',1)% refresh the display of coordinates742 set(handles.ListCoord,' String',{'......'})747 % set(handles.ListCoord,'Value',1)% refresh the display of coordinates 748 set(handles.ListCoord,'Data',[]) 743 749 744 750 % -------------------------------------------------------------------- … … 746 752 function CLEAR_PTS_Callback(hObject, eventdata, handles) 747 753 % -------------------------------------------------------------------- 748 set(handles.ListCoord,'Value',1)% refresh the display of coordinates 749 set(handles.ListCoord,'String',{'......'}) 754 % set(handles.ListCoord,'Value',1)% refresh the display of coordinates 755 % set(handles.ListCoord,'String',{'......'}) 756 set(handles.ListCoord,'Data',[]) 750 757 PLOT_Callback(hObject, eventdata, handles) 751 758 … … 804 811 805 812 %------------------------------------------------------------------------ 806 % --- Executes on selection change in ListCoord.807 function ListCoord_Callback(hObject, eventdata, handles)808 %------------------------------------------------------------------------809 huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle810 hplot=findobj(huvmat,'Tag','PlotAxes');%main plotting axis of uvmat811 hhh=findobj(hplot,'Tag','calib_marker');812 Coord_cell=get(handles.ListCoord,'String');813 val=get(handles.ListCoord,'Value');814 if numel(val)>1815 return %no action if several lines have been selected816 end817 coord_str=Coord_cell{val};818 k=findstr(' | ',coord_str);819 if isempty(k)%last line '.....' selected820 if ~isempty(hhh)821 delete(hhh)%delete the circle marker822 end823 return824 end825 %fill the edit boxe826 set(handles.XObject,'String',coord_str(1:k(1)-1))827 set(handles.YObject,'String',coord_str(k(1)+3:k(2)-1))828 set(handles.ZObject,'String',coord_str(k(2)+3:k(3)-1))829 set(handles.XImage,'String',coord_str(k(3)+3:k(4)-1))830 set(handles.YImage,'String',coord_str(k(4)+3:end))831 h_menu_coord=findobj(huvmat,'Tag','TransformName');832 menu=get(h_menu_coord,'String');833 choice=get(h_menu_coord,'Value');834 if iscell(menu)835 option=menu{choice};836 else837 option='px'; %default838 end839 if isequal(option,'phys')840 XCoord=str2double(coord_str(1:k(1)-1));841 YCoord=str2double(coord_str(k(1)+3:k(2)-1));842 elseif isequal(option,'px')|| isequal(option,'')843 XCoord=str2double(coord_str(k(3)+3:k(4)-1));844 YCoord=str2double(coord_str(k(4)+3:end));845 else846 msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be px or phys ')847 end848 if isempty(XCoord)||isempty(YCoord)849 if ~isempty(hhh)850 delete(hhh)%delete the circle marker851 end852 return853 end854 xlim=get(hplot,'XLim');855 ylim=get(hplot,'YLim');856 ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/20;%defines the size of the circle marker857 if isempty(hhh)858 set(0,'CurrentFig',huvmat)859 set(huvmat,'CurrentAxes',hplot)860 rectangle('Curvature',[1 1],...861 'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range],'EdgeColor','m',...862 'LineStyle','-','Tag','calib_marker');863 else864 set(hhh,'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range])865 end866 867 %------------------------------------------------------------------------868 813 % --- Executes on selection change in edit_append. 869 814 function edit_append_Callback(hObject, eventdata, handles) … … 875 820 if ishandle(huvmat) 876 821 hhuvmat=guidata(huvmat); 877 set(hhuvmat.edit_object,'Value',0) 878 set(hhuvmat.edit_object,'BackgroundColor',[0.7 0.7 0.7]) 822 if get(hhuvmat.CheckEditObject,'Value') 823 set(hhuvmat.CheckEditObject,'Value',0) 824 uvmat('CheckEditObject_Callback',hhuvmat.CheckEditObject,[],hhuvmat) 825 end 879 826 end 880 827 else … … 945 892 x=Xima/str2num(answer); 946 893 y=Yima/str2num(answer); 947 Coord={num2str(x(1)) num2str(y(1)) '0' num2str(Xima(1)) num2str(Yima(1));... 948 num2str(x(2)) num2str(y(2)) '0' num2str(Xima(2)) num2str(Yima(2));... 949 num2str(x(3)) num2str(y(3)) '0' num2str(Xima(3)) num2str(Yima(3));... 950 num2str(x(4)) num2str(y(4)) '0' num2str(Xima(4)) num2str(Yima(4))}; 951 Tabchar=cell2tab(Coord,' | '); 952 Tabchar=[Tabchar ;{'......'}]; 953 set(handles.ListCoord,'String',Tabchar) 894 Coord=[x y zeros(4,1) Xima Yima zeros(4,1)]; 895 set(handles.ListCoord,'Data',Coord) 896 % Tabchar=cell2tab(Coord,' | '); 897 % Tabchar=[Tabchar ;{'......'}]; 898 % set(handles.ListCoord,'String',Tabchar) 899 % Coord={num2str(x(1)) num2str(y(1)) '0' num2str(Xima(1)) num2str(Yima(1));... 900 % num2str(x(2)) num2str(y(2)) '0' num2str(Xima(2)) num2str(Yima(2));... 901 % num2str(x(3)) num2str(y(3)) '0' num2str(Xima(3)) num2str(Yima(3));... 902 % num2str(x(4)) num2str(y(4)) '0' num2str(Xima(4)) num2str(Yima(4))}; 903 % Tabchar=cell2tab(Coord,' | '); 904 % Tabchar=[Tabchar ;{'......'}]; 905 % set(handles.ListCoord,'String',Tabchar) 954 906 955 907 %------------------------------------------------------------------------ … … 1207 1159 GeometryCalib=s.GeometryCalib; 1208 1160 %GeometryCalib=load_calib(hObject, eventdata, handles) 1209 calib=reshape(GeometryCalib.SourceCalib.PointCoord,[],1); 1210 for ilist=1:numel(calib) 1211 CoordCell{ilist}=num2str(calib(ilist)); 1212 end 1213 CoordCell=reshape(CoordCell,[],5); 1214 Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display 1215 Tabchar=[Tabchar;{'......'}]; 1216 set(handles.ListCoord,'Value',1) 1217 set(handles.ListCoord,'String',Tabchar) 1161 % calib=reshape(GeometryCalib.SourceCalib.PointCoord,[],1); 1162 % for ilist=1:numel(calib) 1163 % CoordCell{ilist}=num2str(calib(ilist)); 1164 % end 1165 % CoordCell=reshape(CoordCell,[],5); 1166 % Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display 1167 % Tabchar=[Tabchar;{'......'}]; 1168 % set(handles.ListCoord,'Value',1) 1169 % set(handles.ListCoord,'String',Tabchar) 1170 Coord=GeometryCalib.SourceCalib.PointCoord; 1171 Coord=[Coord zeros(size(Coord,1),1)] 1172 set(handles.ListCoord,'Data',Coord) 1218 1173 PLOT_Callback(handles.geometry_calib, [], handles) 1219 1174 … … 1255 1210 %------------------------------------------------------------------------ 1256 1211 xx=double(get(handles.geometry_calib,'CurrentCharacter')); %get the keyboard character 1257 if ismember(xx,[8 127])%backspace or delete 1258 Coord_cell=get(handles.ListCoord,'String'); 1259 val=get(handles.ListCoord,'Value'); 1260 if max(val)<numel(Coord_cell) % the last element '...' has not been selected 1261 Coord_cell(val)=[];%remove the selected line 1262 set(handles.ListCoord,'Value',min(val)) 1263 set(handles.ListCoord,'String',Coord_cell) 1264 ListCoord_Callback(hObject, eventdata, handles) 1265 PLOT_Callback(hObject,eventdata,handles) 1266 end 1267 end 1212 %if ismember(xx,[8 127])%backspace or delete 1213 if ismember(xx,[30 31 8 127]) 1214 Coord=get(handles.ListCoord,'Data'); 1215 ind=find(Coord(:,6)); 1216 Coord(:,6)=zeros(size(Coord,1),1);% desactivate the current line mark 1217 switch xx 1218 case 30 % arrow upward 1219 Coord(ind-1,6)=1; 1220 case 31% arrow downward 1221 Coord(ind+1,6)=1; 1222 case {8 127}% remove line 1223 Coord(ind,:)=[]; 1224 end 1225 set(handles.ListCoord,'Data',Coord); 1226 PLOT_Callback(hObject,eventdata,handles) 1227 end 1228 1229 1268 1230 1269 1231 %------------------------------------------------------------------------ … … 1334 1296 set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4)) 1335 1297 end 1336 calib=reshape(GeometryCalib.SourceCalib.PointCoord,[],1); 1337 for ilist=1:numel(calib) 1338 CoordCell{ilist}=num2str(calib(ilist)); 1339 end 1340 CoordCell=reshape(CoordCell,[],5); 1341 Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display 1298 calib=GeometryCalib.SourceCalib.PointCoord; 1299 Coord=[calib zeros(size(calib,1),1)]; 1300 set(handles.ListCoord,'Data',Coord) 1301 % CoordCell=reshape(CoordCell,[],5); 1302 % Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display 1342 1303 PLOT_Callback(handles.geometry_calib, [], handles) 1343 1304 end 1344 1305 set(handles.calib_type,'Value',val_cal) 1345 Tabchar=[Tabchar;{'......'}]; 1346 set(handles.ListCoord,'Value',1) 1347 set(handles.ListCoord,'String',Tabchar) 1306 % Tabchar=[Tabchar;{'......'}]; 1307 % set(handles.ListCoord,'Value',1) 1348 1308 1349 1309 if isempty(CoordCell)% allow mouse action by default in the absence of input points … … 1393 1353 %------------------------------------------------------------------------ 1394 1354 function PLOT_Callback(hObject, eventdata, handles) 1395 1355 global Coord 1396 1356 huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle 1397 %UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface1398 1357 hhuvmat=guidata(huvmat); %handles of GUI elements in uvmat 1399 %hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat1400 1358 h_menu_coord=findobj(huvmat,'Tag','TransformName'); 1401 1359 menu=get(h_menu_coord,'String'); … … 1406 1364 option='px'; %default 1407 1365 end 1408 Coord_cell=get(handles.ListCoord,'String'); 1409 ObjectData=read_geometry_calib(Coord_cell); 1366 %ObjectData=read_geometry_calib(Coord_cell); 1410 1367 %ObjectData=read_geometry_calib(handles);%read the interface input parameters defining the object 1411 if ~isempty(ObjectData.Coord) 1368 Coord=get(handles.ListCoord,'Data'); 1369 % Coord(:,6)=[]; 1370 if ~isempty(Coord) 1412 1371 if isequal(option,'phys') 1413 ObjectData.Coord=ObjectData.Coord(:,1:3);1372 Coord_plot=Coord(:,1:3); 1414 1373 elseif isequal(option,'px')||isequal(option,'') 1415 ObjectData.Coord=ObjectData.Coord(:,4:5);1374 Coord_plot=Coord(:,4:5); 1416 1375 else 1417 msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be '''', px or phys ')1376 msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be blank, px or phys ') 1418 1377 end 1419 1378 end … … 1422 1381 set(huvmat,'CurrentAxes',hhuvmat.PlotAxes) 1423 1382 hh=findobj('Tag','calib_points'); 1424 if ~isempty( ObjectData.Coord) && isempty(hh)1425 hh=line( ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color','m','Tag','calib_points','LineStyle','.','Marker','+');1426 elseif isempty( ObjectData.Coord)%empty list of points, suppress the plot1383 if ~isempty(Coord) && isempty(hh) 1384 hh=line(Coord_plot(:,1),Coord_plot(:,2),'Color','m','Tag','calib_points','LineStyle','.','Marker','+'); 1385 elseif isempty(Coord)%empty list of points, suppress the plot 1427 1386 delete(hh) 1428 1387 else 1429 set(hh,'XData',ObjectData.Coord(:,1)) 1430 set(hh,'YData',ObjectData.Coord(:,2)) 1431 end 1388 set(hh,'XData',Coord_plot(:,1)) 1389 set(hh,'YData',Coord_plot(:,2)) 1390 end 1391 1392 % get data on the matlab work space 1393 1394 evalin('base','global Coord')%make CurData global in the workspace 1395 display('coordinates of calibration points (phys,px,marker) :') 1396 evalin('base','Coord') %display CurData in the workspace 1397 commandwindow; %brings the Matlab command window to the front 1432 1398 pause(.1) 1433 1399 figure(handles.geometry_calib) 1434 1400 1435 1436 1401 1402 1403 1404 % --- Executes when selected cell(s) is changed in ListCoord. 1405 function ListCoord_CellSelectionCallback(hObject, eventdata, handles) 1406 if ~isempty(eventdata.Indices) 1407 iline=eventdata.Indices(1);% selected line number 1408 Data=get(handles.ListCoord,'Data'); 1409 Data(:,6)=zeros(size(Data,1),1); 1410 Data(iline,6)=1;% mark the selected line 1411 % if size(Data,1)<iline+numel(Input) 1412 % Data=[Data ; zeros(iline+numel(Input)-size(Data,1),6)];% append zeros to fit the new column 1413 % end 1414 % Data(iline:iline+numel(Input)-1,eventdata.Indices(2))=Input'; 1415 set(handles.ListCoord,'Data',Data) 1416 update_calib_marker(Data(iline,:)) 1417 end 1418 1419 % if length(eventdata.Modifier) == 1 && strcmp(eventdata.Modifier{:},'control') && ... 1420 % eventdata.Key == 'v' 1421 % import = importdata('-pastespecial'); 1422 % %data treatment and checking 1423 % set(handles.uitable1,'Data',import); 1424 % end 1425 1426 % --- Executes when entered data in editable cell(s) in ListCoord. 1427 function ListCoord_CellEditCallback(hObject, eventdata, handles) 1428 1429 Input=str2num(eventdata.EditData);%pasted input 1430 Coord=get(handles.ListCoord,'Data'); 1431 iline=eventdata.Indices(1);% selected line number 1432 if size(Coord,1)<iline+numel(Input) 1433 Coord=[Coord ; zeros(iline+numel(Input)-size(Coord,1),6)];% append zeros to fit the new column 1434 end 1435 Coord(iline:iline+numel(Input)-1,eventdata.Indices(2))=Input'; 1436 set(handles.ListCoord,'Data',Coord) 1437 PLOT_Callback(hObject, eventdata, handles) 1438 1439 function update_calib_marker(Coord) 1440 %% update the plot on uvmat 1441 huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle 1442 hplot=findobj(huvmat,'Tag','PlotAxes');%main plotting axis of uvmat 1443 hhh=findobj(hplot,'Tag','calib_marker'); 1444 1445 h_menu_coord=findobj(huvmat,'Tag','TransformName'); 1446 menu=get(h_menu_coord,'String'); 1447 choice=get(h_menu_coord,'Value'); 1448 if iscell(menu) 1449 option=menu{choice}; 1450 else 1451 option='px'; %default 1452 end 1453 if isequal(option,'phys') 1454 XCoord=Coord(1); 1455 YCoord=Coord(2); 1456 elseif isequal(option,'px')|| isequal(option,'') 1457 XCoord=Coord(4); 1458 YCoord=Coord(5); 1459 else 1460 msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be blank, px or phys ') 1461 end 1462 if isempty(XCoord)||isempty(YCoord) 1463 if ~isempty(hhh) 1464 delete(hhh)%delete the circle marker 1465 end 1466 return 1467 end 1468 xlim=get(hplot,'XLim'); 1469 ylim=get(hplot,'YLim'); 1470 ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/20;%defines the size of the circle marker 1471 if isempty(hhh) 1472 set(0,'CurrentFig',huvmat) 1473 set(huvmat,'CurrentAxes',hplot) 1474 rectangle('Curvature',[1 1],... 1475 'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range],'EdgeColor','m',... 1476 'LineStyle','-','Tag','calib_marker'); 1477 else 1478 set(hhh,'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range]) 1479 end
Note: See TracChangeset
for help on using the changeset viewer.