Home > . > mouse_down.m

# mouse_down

## PURPOSE

'mouse_down': function activated when the mouse button is pressed on a figure (callback for 'WindowButtonDownFcn'

## SYNOPSIS

function xy=mouse_down(hObject,eventdata)

## DESCRIPTION

    'mouse_down': function activated when the mouse button is pressed on a figure (callback for 'WindowButtonDownFcn'
    --------------------------------------------------------------
     xy=mouse_down(hObject,eventdata)
     activated by the command:
     set(hObject,'WindowButtonDownFcn',{'mouse_down'}),
     where hObject is the handle of the figure

    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
         This file is part of the toolbox UVMAT.

         UVMAT is free software; you can redistribute it and/or modify
         it under the terms of the GNU General Public License as published by
         the Free Software Foundation; either version 2 of the License, or
         (at your option) any later version.

         UVMAT is distributed in the hope that it will be useful,
         but WITHOUT ANY WARRANTY; without even the implied warranty of
         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
         GNU General Public License (file UVMAT/COPYING.txt) for more details.
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

## CROSS-REFERENCE INFORMATION

This function calls:

- geometry_calib 'geometry_calib': performs geometric calibration from a set of reference points
- plot_field 'plot_field': plot any field with the structure defined in the uvmat package
- plot_object 'plot_object': draws a projection object (points, line, plane...)
- read_geometry_calib 'read_geometry_calib': read data on the GUI geometry_calib
- read_set_object 'read_set_object': read the data on the 'set_object' interface
- set_title 'set_title': defines the 'TITLE' of a projection object
- uvmat 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization

This function is called by:

- mouse_up 'mouse_up': function activated when the mouse button is released

## SUBFUNCTIONS

- function update_plot

## SOURCE CODE

    0001 %'mouse_down': function activated when the mouse button is pressed on a figure (callback for 'WindowButtonDownFcn'
    0002 %--------------------------------------------------------------
    0003 % xy=mouse_down(hObject,eventdata)
    0004 % activated by the command:
    0005 % set(hObject,'WindowButtonDownFcn',{'mouse_down'}),
    0006 % where hObject is the handle of the figure
    0007 %
    0008 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0009 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    0010 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0011 %     This file is part of the toolbox UVMAT.
    0012 %
    0013 %     UVMAT is free software; you can redistribute it and/or modify
    0014 %     it under the terms of the GNU General Public License as published by
    0015 %     the Free Software Foundation; either version 2 of the License, or
    0016 %     (at your option) any later version.
    0017 %
    0018 %     UVMAT is distributed in the hope that it will be useful,
    0019 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
    0020 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0021 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
    0022 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0023
    0024 function xy=mouse_down(hObject,eventdata)
    0025 testzoom=0;%default
    0026 MouseAction='none'; %default
    0027 huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle which controls theoption of  mouse action
    0028 if ~isempty(huvmat)
    0029     hhuvmat=guidata(huvmat);%handles of elements in uvmat
    0030     UvData=get(huvmat,'UserData');
    0031     testzoom=get(hhuvmat.zoom,'Value');% get the mouse action from the uvmat GUI: options:
    0032     if isfield(UvData,'MouseAction')
    0033         MouseAction=UvData.MouseAction;% get the mouse action from the uvmat GUI: options:
    0034     end
    0035 end
    0036 test_create=~testzoom && (isequal(MouseAction,'create_object') || isequal(MouseAction,'create_mask'));
    0037 %test_cal=get(handles.cal,'Value');
    0038 test_cal=isequal(MouseAction,'calib');
    0039 handles_coord=findobj(huvmat,'Tag','menu_coord');
    0040 menu_coord=get(handles_coord,'String');
    0041 coord_choice=get(handles_coord,'Value');
    0042 coord_type=menu_coord{coord_choice};
    0043 test_edit=isequal(MouseAction,'edit_object');
    0044 test_edit_vect=isequal(MouseAction,'edit_vect');
    0045 xdisplay=[];%default
    0046 ydisplay=[];%default
    0047 haxes=[];
    0048 AxeData=[];%default
    0049
    0050 %edit an existing point or line if found
    0051 hcurrentobject=gco;% current object handle (selected by the mouse)
    0052 hcurrentfig=gcbo;% current figure handle
    0053 tag_obj=get(gco,'Tag');
    0054 xy=[];%default
    0055 xy_fig=get(hcurrentfig,'CurrentPoint');% current point of the current figure (gcbo)
    0056 hchild=get(hcurrentfig,'Children');%handles of all objects in the current figure
    0057 % loop on all the objects in the current figure (selected by the last mouse click)
    0058 for ichild=1:length(hchild)
    0059     obj_pos=get(hchild(ichild),'Position');%position of the object
    0060     if xy_fig(1) >=obj_pos(1) & xy_fig(2) >= obj_pos(2)& xy_fig(1) <=obj_pos(1)+obj_pos(3) & xy_fig(2) <= obj_pos(2)+obj_pos(4);
    0061         htype=get(hchild(ichild),'Type');%type of object child of the current figure
    0062         %if the mouse is over an axis, look at the data
    0063         if isequal(htype,'axes')
    0064             haxes=hchild(ichild);
    0065             xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
    0066             AxeData=get(haxes,'UserData');% data attached to the axis
    0067             AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin
    0068             if ~isequal(tag_obj,'proj_object') & ~test_create
    0069                 x_mouse=xy(1,1);%default
    0070                 y_mouse=xy(1,2);%default
    0071                 u_mouse=[];
    0072                 v_mouse=[];
    0073                 w_mouse=[];
    0074                 A_mouse=[];
    0075                 c_text=[];
    0076                 f_text=[];
    0077                 ff_text=[];
    0078                 ivec=[];
    0079                 if isfield(AxeData,'X') & isfield(AxeData,'Y') & isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis
    0080                     flag_vec=(AxeData.X<(xy(1,1)+AxeData.Mesh/4) & AxeData.X>(xy(1,1)-AxeData.Mesh/4)) & ...%flagx=1 for the vectors with x position selected by the mouse
    0081                       (AxeData.Y<(xy(1,2)+AxeData.Mesh/4) & AxeData.Y>(xy(1,2)-AxeData.Mesh/4));%f
    0082                     ivec=find(flag_vec);% search the selected vector index ivec
    0083                     if length(ivec)>0
    0084                         ivec=ivec(1);%choice the first selected vector if several are selected
    0085                     end
    0086                 end
    0087             end
    0088         elseif isequal(get(hchild(ichild),'Visible'),'on')& ~isequal(get(hchild(ichild),'Style'),'frame')
    0089            %FAIRE UNE OPTION D'AIDE AVEC BOUTON SOURIS DROIT (ALT)??
    0090         end
    0091     end
    0092 end
    0093 test2D=0;
    0094 if isfield(AxeData,'NbDim')
    0095     if isequal(AxeData.NbDim,2)
    0096         test2D=1;
    0097     end
    0098 end
    0099 if ~test2D     %desable  object creation and vector editing if NbDim different from 2
    0100     test_create=0;
    0101     test_edit_vect=0;
    0102 end
    0103 %delete the current zoom rectangle
    0104 if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom)
    0105     delete(AxeData.CurrentRectZoom)
    0106     AxeData.CurrentRectZoom=[];
    0107 end
    0108
    0109 if testzoom %&& ~test_create && ~test_edit && ~test_edit_vect && exist('xy','var')
    0110      AxeData.Drawing='zoom'; %initiate drawing mode
    0111      AxeData.CurrentObject=[];%unselect objects
    0112 elseif ~isempty(huvmat)
    0113     %selection of an existing projection object
    0114     if  test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint'))
    0115         if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create'))
    0116             userdata=get(hcurrentobject,'UserData');
    0117             if ishandle(userdata)%the selected line depends on a parent line
    0118                 AxeData.CurrentObject=userdata;% the parent object becomes the current one
    0119             else
    0120                 AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one
    0121             end
    0122             ObjectData=get(AxeData.CurrentObject,'UserData');
    0123             if test_edit & isfield(ObjectData,'IndexObj')
    0124                 hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
    0125                 set(hother,'Color','b');%reset all the proj objects in 'blue' by default
    0126                 set(hother,'Selected','off')
    0127                 hother=findobj('Tag','proj_object','Type','rectangle');
    0128                 set(hother,'EdgeColor','b');
    0129                 set(hother,'Selected','off');
    0130                 hother=findobj('Tag','proj_object','Type','image');
    0131                 for iobj=1:length(hother)
    0132                        Acolor=get(hother(iobj),'CData');
    0133                        Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
    0134                        set(hother(iobj),'CData',Acolor);
    0135                 end
    0136                 hother=findobj('Tag','DeformPoint');
    0137                 set(hother,'Color','b');
    0138                 set(hother,'Selected','off')
    0139                 if isequal(get(AxeData.CurrentObject,'Type'),'line')
    0140                     set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color
    0141                 elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle')
    0142                      set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color
    0143                 end
    0144                 if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject)
    0145                     for iobj=1:length(ObjectData.SubObject)
    0146                         hsub=ObjectData.SubObject(iobj);
    0147                         if isequal(get(hsub,'Type'),'rectangle')
    0148                             set(hsub,'EdgeColor','m'); %set the selected object to magenta color
    0149                         elseif isequal(get(hsub,'Type'),'image')
    0150                            Acolor=get(hsub,'CData');
    0151                            Acolor(:,:,1)=Acolor(:,:,3);
    0152                            set(hsub,'CData',Acolor);
    0153                         else
    0154                             set(hsub,'Color','m')
    0155                         end
    0156                     end
    0157                 end
    0158                 if isequal(tag_obj,'DeformPoint')
    0159                      set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color
    0160                 end
    0161                 IndexObj=ObjectData.IndexObj;
    0162                 hlist_object=findobj(huvmat,'Tag','list_object');
    0163                 set(hlist_object,'Value',IndexObj);
    0164                 testdeform=0;
    0165                 set(gcbo,'Pointer','circle');
    0166                 AxeData.Drawing='deform';
    0167                 if isequal(tag_obj,'DeformPoint')
    0168                    if isfield(ObjectData,'DeformPoint')
    0169                        set(hcurrentobject,'Selected','on')
    0170                        for ipt=1:length(ObjectData.DeformPoint)
    0171                            if isequal(ObjectData.DeformPoint(ipt),hcurrentobject)
    0172                                 AxeData.CurrentIndex=ipt;
    0173                                 testdeform=1;
    0174                            end
    0175                        end
    0176                    end
    0177                 end
    0178                 if testdeform==0
    0179                     AxeData.Drawing='translate';
    0180                     set(AxeData.CurrentObject,'Selected','on')
    0181                     set(gcbo,'Pointer','fleur');
    0182                 end
    0183             end
    0184         end
    0185     end
    0186     %  create new projection  object
    0187     if  test_create && ~isempty(xy) && ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create'))
    0188             ObjectData=read_set_object(UvData.sethandles);
    0189             ObjectData.Coord=[]; %reset previous object coordinates
    0190             ObjectData.Coord(1,1)=xy(1,1);
    0191             ObjectData.Coord(1,2)=xy(1,2);
    0192             ObjectData.Coord(1,3)=0;
    0193             if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3
    0194                  ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle
    0195             end
    0196             AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject
    0197             if isfield(UvData,'Object')
    0198                 IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface
    0199             else
    0200                 IndexObj=2;
    0201             end
    0202             UvData.Object{IndexObj}=ObjectData;
    0203             UvData.Object{IndexObj}.HandlesDisplay(1)=AxeData.CurrentObject;
    0204             set(huvmat,'UserData',UvData)
    0205             list_str=get(hhuvmat.list_object,'String');
    0206             list_str{IndexObj}=[num2str(IndexObj) '-' set_title(ObjectData.Style,ObjectData.ProjMode)];
    0207             if ~isequal(list_str{end},'...')
    0208                  list_str{end+1}='...';
    0209             end
    0210             set(hhuvmat.list_object,'String',list_str)
    0211             set(hhuvmat.list_object,'Value',IndexObj)
    0212             PlotData=get(AxeData.CurrentObject,'UserData');
    0213             PlotData.IndexObj=IndexObj;
    0214             set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph
    0215             AxeData.Drawing='create';
    0216     end
    0217
    0218     % create calibration points if the GUI geometry_calib is opened
    0219     if test_cal & ~isempty(xy)
    0220         h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
    0221         hh_geometry_calib=guidata(h_geometry_calib);
    0222         h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
    0223         h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append');
    0224         if isequal(get(h_edit_append,'Value'),1)
    0225             if ~isequal(coord_type,'')
    0226                 set(handles_coord,'Value',1)
    0227                 coord_type='';
    0228                 set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off'
    0229                 set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
    0230                 uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
    0231             end
    0232 %             if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates
    0233                 strline=[ '    |    '  '    |    '  '    |    ' num2str(xy(1,1),4) '    |    ' num2str(xy(1,2),4)];
    0234 %             else %phys cordinates
    0235 %                 strline=[ num2str(xy(1,1),4) '    |    '  num2str(xy(1,2),4) '    |    0      |    '  '    |    ' ];
    0236 %             end
    0237             Coord=get(h_ListCoord,'String');
    0238             val=get(h_ListCoord,'Value');
    0239             if isequal(Coord,{''})
    0240                 val=0;
    0241             end
    0242             if length(Coord)>val
    0243                 Coord(val+2:length(Coord)+1)=Coord(val+1:length(Coord));% push the list forward beyond the current point
    0244             end
    0245             Coord{val+1}=strline;
    0246             set(h_ListCoord,'String',Coord)
    0247             set(h_ListCoord,'Value',val+1)
    0248             geometry_calib('ListCoord_Callback',hObject,eventdata,hh_geometry_calib)
    0249             data=read_geometry_calib(Coord);
    0250             if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates
    0251                 XCoord=data.Coord(:,4);
    0252                 YCoord=data.Coord(:,5);
    0253             else %phys cordinates
    0254                 XCoord=data.Coord(:,1);
    0255                 YCoord=data.Coord(:,2);
    0256             end
    0257             hh=findobj('Tag','calib_points')
    0258             if isempty(hh)
    0259                 line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
    0260             else
    0261                 set(hh,'XData',XCoord)
    0262                 set(hh,'YData',YCoord)
    0263             end
    0264             hhh=findobj('Tag','calib_marker');
    0265             if ~isempty(hhh)
    0266                 set(hhh,'XData',xy(1,1))
    0267                 set(hhh,'YData',xy(1,2))
    0268             else
    0269                 line(xy(1,1),xy(1,2),'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',20);
    0270             end
    0271             %uistack(h_geometry_calib,'top')
    0272         end
    0273     end
    0274
    0275     % edit vectors
    0276     if test_edit_vect & ~isempty(ivec)
    0277     %     FF_100=FF-100*double(uint(abs(FF)/100); %value of FF without units and dizaines
    0278         if ~isfield(AxeData,'FF')
    0279             AxeData.FF=zeros(size(AxeData.X));
    0280         end
    0281         if isequal(AxeData.FF(ivec),0)
    0282
    0283             AxeData.FF(ivec)=100; %mark vector #ivec as false
    0284
    0285         else
    0286             AxeData.FF(ivec)=0;
    0287         end
    0288         set(haxes,'UserData',AxeData)
    0289         update_plot
    0290     end
    0291 end
    0292 set(haxes,'UserData',AxeData);
    0293
    0294 %------------------------------------------------------
    0295 function update_plot
    0296 %--------------------------------------------
    0297 huvmat=gcbf;
    0298 UvData=get(gcbf,'UserData');
    0299 %determine the axes of action of the set_edit interface
    0300 % list_axes=get(handles.MenuAxes,'String');% list menu fields
    0301 % index_axes=get(handles.MenuAxes,'Value');% selected string index
    0302 % current_axes= list_axes{index_axes(1)} % selected string
    0303 % eval(['haxes=UvData.' current_axes '.Axes']);
    0304 % if isempty(haxes)|~ishandle(haxes)| ~isequal(get(haxes,'Type'),'axes')
    0305      haxes= findobj(huvmat,'Tag','axes3'); %main plotting axes as default
    0306 %      set(handles.MenuAxes,'Value',1)
    0307 % end
    0308 AxeData=get(haxes,'UserData');
    0309 %For vector field representation
    0310 %NEW
    0311 PlotHandles.VecScale=findobj(huvmat,'Tag','VecScale');
    0312 PlotHandles.AutoVec=findobj(huvmat,'Tag','AutoVec');
    0313 PlotHandles.checkyellow=findobj(huvmat,'Tag','checkyellow');
    0314 PlotHandles.checkblack=findobj(huvmat,'Tag','checkblack');
    0315 PlotHandles.col_vec=findobj(huvmat,'Tag','col_vec');
    0316 PlotHandles.colcode1=findobj(huvmat,'Tag','colcode1');
    0317 PlotHandles.colcode2=findobj(huvmat,'Tag','colcode2');
    0318 PlotHandles.vec_col_bar=findobj(huvmat,'Tag','vec_col_bar');
    0319 PlotHandles.slider1=findobj(huvmat,'Tag','slider1');
    0320 PlotHandles.slider2=findobj(huvmat,'Tag','slider2');
    0321 PlotHandles.max_vec=findobj(huvmat,'Tag','max_vec');
    0322 PlotHandles.min_vec=findobj(huvmat,'Tag','min_vec');
    0323 PlotHandles.AutoVecColor=findobj(huvmat,'Tag','AutoVecColor');
    0324 PlotHandles.decimate4=findobj(huvmat,'Tag','decimate4');
    0325
    0326 %vectors
    0327 Vectors.VecScale=str2num(get(PlotHandles.VecScale,'String'));
    0328 Vectors.AutoVec=get(PlotHandles.AutoVec,'Value');%automatic vector length
    0329 Vectors.checkyellow=get(PlotHandles.checkyellow,'Value');
    0330 Vectors.checkblack=get(PlotHandles.checkblack,'Value');
    0331 Vectors.decimate4=get(PlotHandles.decimate4,'Value');% =1; for reducing the nbre of vectors
    0332 menu_col=get(PlotHandles.col_vec,'String');
    0333 menu_val=get(PlotHandles.col_vec,'Value');
    0334 Vectors.CName=menu_col{menu_val}; %'ima_cor','black','white',...
    0335 Vectors.colcode1=str2num(get(PlotHandles.colcode1,'String'));% first threshold for rgb, first value for'continuous'
    0336 Vectors.colcode2=str2num(get(PlotHandles.colcode2,'String'));% second threshold for rgb, last value (saturation) for 'continuous'
    0337 Vectors.option=get(PlotHandles.vec_col_bar,'Value'); % =1 (64 colors), =0 (3 colors)
    0338 Vectors.min=get(PlotHandles.slider1,'Min');
    0339 Vectors.max=get(PlotHandles.slider1,'Max');
    0340 Vectors.auto=get(PlotHandles.AutoVecColor,'Value');% =1; thresholds scaling relative to min and max, =0 fixed thresholds
    0341 PlotParam.Vectors=Vectors;
    0342
    0343 [PlotType,ScalOut]= plot_field(AxeData,haxes,PlotParam,1);