Ignore:
Timestamp:
Jul 3, 2013, 12:07:26 PM (11 years ago)
Author:
sommeria
Message:

a few bugs corrected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/geometry_calib.m

    r655 r657  
    5050% Edit the above text to modify the response to help geometry_calib
    5151
    52 % Last Modified by GUIDE v2.5 29-Jun-2013 23:52:36
     52% Last Modified by GUIDE v2.5 03-Jul-2013 09:23:35
    5353
    5454% Begin initialization code - DO NOT edit
     
    6060                   'gui_LayoutFcn',  [] , ...
    6161                   'gui_Callback',   []);
    62 if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once'))
     62if nargin && ischar(varargin{1}) %&& ~isempty(regexp(varargin{1},'_Callback','once'))
    6363    gui_State.gui_Callback = str2func(varargin{1});
    6464end
     
    7878% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
    7979%------------------------------------------------------------------------
    80 function geometry_calib_OpeningFcn(hObject, eventdata, handles,inputfile,pos)
     80function geometry_calib_OpeningFcn(hObject, eventdata, handles,inputfile)
    8181%------------------------------------------------------------------------
    8282% Choose default command line output for geometry_calib
     
    8787guidata(hObject, handles);
    8888set(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)
    9090
    9191%% position
    92 set(0,'Unit','points')
     92set(0,'Unit','pixels')
    9393ScreenSize=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);
     94FigSize=get(handles.geometry_calib,'Position');
     95
     96Width=FigSize(3);% fig width in points (1/72 inch)
     97Height=FigSize(4);
    9698Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40
    9799Bottom=ScreenSize(4)-Height-40; %put fig at top right
    98 set(handles.geometry_calib,'Unit','points')
    99100set(handles.geometry_calib,'Position',[Left Bottom Width Height])
    100101
     
    121122        end
    122123    end
    123     set(handles.ListCoord,'String',{'......'})
     124    set(handles.ListCoord,'Data',[])
     125   % set(handles.ListCoord,'Data',{[] [] [] [] [] []})
    124126    if exist(inputfile,'file')
    125127        Heading=loadfile(handles,inputfile);% load data from the xml file
     
    136138%------------------------------------------------------------------------
    137139% --- Outputs from this function are returned to the command line.
    138 function varargout = geometry_calib_OutputFcn(hObject, eventdata, handles)
     140function varargout = geometry_calib_OutputFcn(~, eventdata, handles)
    139141%------------------------------------------------------------------------
    140142% Get default command line output from handles structure
     
    209211uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat, show the image in phys coordinates
    210212PLOT_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)
     213Data=get(handles.ListCoord,'Data');
     214Data(:,6)=zeros(size(Data,1),1);
     215Data(index,6)=1;% indicate in the list the point with max deviation (possible mistake)
     216set(handles.ListCoord,'Data',Data)% indicate in the list the point with max deviation (possible mistake)
     217%ListCoord_Callback(hObject, eventdata, handles)
    213218figure(handles.geometry_calib)
    214219
     
    259264%------------------------------------------------------------------------
    260265%% 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);
     268Coord=get(handles.ListCoord,'Data');
     269Coord(:,6)=[];
    264270% apply the calibration, whose type is selected in  handles.calib_type
    265271if ~isempty(Coord)
     
    708714% --- Executes on button press in STORE.
    709715function STORE_Callback(hObject, eventdata, handles)
    710 Coord_cell=get(handles.ListCoord,'String');
    711 Object=read_geometry_calib(Coord_cell);
     716Coord=get(handles.ListCoord,'Data');
     717%Object=read_geometry_calib(Coord_cell);
    712718unitlist=get(handles.CoordUnit,'String');
    713719unit=unitlist{get(handles.CoordUnit,'value')};
    714720GeometryCalib.CoordUnit=unit;
    715 GeometryCalib.SourceCalib.PointCoord=Object.Coord;
     721GeometryCalib.SourceCalib.PointCoord=Coord(:,1:5);
    716722huvmat=findobj(allchild(0),'Name','uvmat');
    717723hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
     
    739745    set(handles.coord_files,'string',listfile);
    740746end
    741 set(handles.ListCoord,'Value',1)% refresh the display of coordinates
    742 set(handles.ListCoord,'String',{'......'})
     747% set(handles.ListCoord,'Value',1)% refresh the display of coordinates
     748set(handles.ListCoord,'Data',[])
    743749
    744750% --------------------------------------------------------------------
     
    746752function CLEAR_PTS_Callback(hObject, eventdata, handles)
    747753% --------------------------------------------------------------------
    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',{'......'})
     756set(handles.ListCoord,'Data',[])
    750757PLOT_Callback(hObject, eventdata, handles)
    751758
     
    804811
    805812%------------------------------------------------------------------------
    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 handle
    810 hplot=findobj(huvmat,'Tag','PlotAxes');%main plotting axis of uvmat
    811 hhh=findobj(hplot,'Tag','calib_marker');
    812 Coord_cell=get(handles.ListCoord,'String');
    813 val=get(handles.ListCoord,'Value');
    814 if numel(val)>1
    815     return %no action if several lines have been selected
    816 end
    817 coord_str=Coord_cell{val};
    818 k=findstr(' | ',coord_str);
    819 if isempty(k)%last line '.....' selected
    820     if ~isempty(hhh)
    821         delete(hhh)%delete the circle marker
    822     end
    823     return
    824 end
    825 %fill the edit boxe
    826 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 else
    837     option='px'; %default
    838 end
    839 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 else
    846     msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be px or phys ')
    847 end
    848 if isempty(XCoord)||isempty(YCoord)
    849      if ~isempty(hhh)
    850         delete(hhh)%delete the circle marker
    851     end
    852     return
    853 end
    854 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 marker
    857 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 else
    864     set(hhh,'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range])
    865 end
    866 
    867 %------------------------------------------------------------------------
    868813% --- Executes on selection change in edit_append.
    869814function edit_append_Callback(hObject, eventdata, handles)
     
    875820    if ishandle(huvmat)
    876821        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
    879826    end
    880827else
     
    945892x=Xima/str2num(answer);
    946893y=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)
     894Coord=[x y zeros(4,1) Xima Yima zeros(4,1)];
     895set(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)
    954906
    955907%------------------------------------------------------------------------
     
    12071159GeometryCalib=s.GeometryCalib;
    12081160%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)
     1170Coord=GeometryCalib.SourceCalib.PointCoord;
     1171Coord=[Coord zeros(size(Coord,1),1)]
     1172set(handles.ListCoord,'Data',Coord)
    12181173PLOT_Callback(handles.geometry_calib, [], handles)
    12191174
     
    12551210%------------------------------------------------------------------------
    12561211xx=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
     1213if 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)
     1227end
     1228
     1229
    12681230
    12691231%------------------------------------------------------------------------
     
    13341296        set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))
    13351297    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
    13421303    PLOT_Callback(handles.geometry_calib, [], handles)
    13431304end
    13441305set(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)
    13481308
    13491309if isempty(CoordCell)% allow mouse action by default in the absence of input points
     
    13931353%------------------------------------------------------------------------
    13941354function PLOT_Callback(hObject, eventdata, handles)
    1395 
     1355global Coord
    13961356huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
    1397 %UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
    13981357hhuvmat=guidata(huvmat); %handles of GUI elements in uvmat
    1399 %hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat
    14001358h_menu_coord=findobj(huvmat,'Tag','TransformName');
    14011359menu=get(h_menu_coord,'String');
     
    14061364    option='px'; %default
    14071365end
    1408 Coord_cell=get(handles.ListCoord,'String');
    1409 ObjectData=read_geometry_calib(Coord_cell);
     1366%ObjectData=read_geometry_calib(Coord_cell);
    14101367%ObjectData=read_geometry_calib(handles);%read the interface input parameters defining the object
    1411 if ~isempty(ObjectData.Coord)
     1368Coord=get(handles.ListCoord,'Data');
     1369% Coord(:,6)=[];
     1370if ~isempty(Coord)
    14121371    if isequal(option,'phys')
    1413         ObjectData.Coord=ObjectData.Coord(:,1:3);
     1372        Coord_plot=Coord(:,1:3);
    14141373    elseif isequal(option,'px')||isequal(option,'')
    1415         ObjectData.Coord=ObjectData.Coord(:,4:5);
     1374        Coord_plot=Coord(:,4:5);
    14161375    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 ')
    14181377    end
    14191378end
     
    14221381set(huvmat,'CurrentAxes',hhuvmat.PlotAxes)
    14231382hh=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 plot
     1383if  ~isempty(Coord) && isempty(hh)
     1384    hh=line(Coord_plot(:,1),Coord_plot(:,2),'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
     1385elseif isempty(Coord)%empty list of points, suppress the plot
    14271386    delete(hh)
    14281387else
    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))
     1390end
     1391
     1392% get data on the matlab work space
     1393
     1394evalin('base','global Coord')%make CurData global in the workspace
     1395display('coordinates of calibration points (phys,px,marker) :')
     1396evalin('base','Coord') %display CurData in the workspace
     1397commandwindow; %brings the Matlab command window to the front
    14321398pause(.1)
    14331399figure(handles.geometry_calib)
    14341400
    1435 
    14361401 
     1402
     1403
     1404% --- Executes when selected cell(s) is changed in ListCoord.
     1405function ListCoord_CellSelectionCallback(hObject, eventdata, handles)
     1406if ~isempty(eventdata.Indices)
     1407iline=eventdata.Indices(1);% selected line number
     1408Data=get(handles.ListCoord,'Data');
     1409Data(:,6)=zeros(size(Data,1),1);
     1410Data(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';
     1415set(handles.ListCoord,'Data',Data)
     1416update_calib_marker(Data(iline,:))
     1417end
     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.
     1427function ListCoord_CellEditCallback(hObject, eventdata, handles)
     1428
     1429Input=str2num(eventdata.EditData);%pasted input
     1430Coord=get(handles.ListCoord,'Data');
     1431iline=eventdata.Indices(1);% selected line number
     1432if size(Coord,1)<iline+numel(Input)
     1433    Coord=[Coord ; zeros(iline+numel(Input)-size(Coord,1),6)];% append zeros to fit the new column
     1434end
     1435Coord(iline:iline+numel(Input)-1,eventdata.Indices(2))=Input';
     1436set(handles.ListCoord,'Data',Coord)
     1437PLOT_Callback(hObject, eventdata, handles)
     1438
     1439function update_calib_marker(Coord)
     1440%% update the plot on uvmat
     1441huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
     1442hplot=findobj(huvmat,'Tag','PlotAxes');%main plotting axis of uvmat
     1443hhh=findobj(hplot,'Tag','calib_marker');
     1444
     1445h_menu_coord=findobj(huvmat,'Tag','TransformName');
     1446menu=get(h_menu_coord,'String');
     1447choice=get(h_menu_coord,'Value');
     1448if iscell(menu)
     1449    option=menu{choice};
     1450else
     1451    option='px'; %default
     1452end
     1453if isequal(option,'phys')
     1454    XCoord=Coord(1);
     1455    YCoord=Coord(2);
     1456elseif isequal(option,'px')|| isequal(option,'')
     1457    XCoord=Coord(4);
     1458    YCoord=Coord(5);
     1459else
     1460    msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be blank, px or phys ')
     1461end
     1462if isempty(XCoord)||isempty(YCoord)
     1463     if ~isempty(hhh)
     1464        delete(hhh)%delete the circle marker
     1465    end
     1466    return
     1467end
     1468xlim=get(hplot,'XLim');
     1469ylim=get(hplot,'YLim');
     1470ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/20;%defines the size of the circle marker
     1471if 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');
     1477else
     1478    set(hhh,'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range])
     1479end
Note: See TracChangeset for help on using the changeset viewer.