Home > . > mouse_motion.m

# mouse_motion

## PURPOSE

'mouse_motion': permanently called by mouse motion over a figure (Callback for 'WindowButtonMotionFcn' of the figure)

## SYNOPSIS

function mouse_motion(hObject,eventdata,handles)

## DESCRIPTION

    'mouse_motion': permanently called by mouse motion over a figure (Callback for 'WindowButtonMotionFcn' of the figure)
    -----------------------------------------------------------------------

     function mouse_motion(hObject,eventdata,handles)
     activated by the command:
     set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})
     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:

- plot_object 'plot_object': draws a projection object (points, line, plane...)

This function is called by:

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

## SOURCE CODE

    0001 %'mouse_motion': permanently called by mouse motion over a figure (Callback for 'WindowButtonMotionFcn' of the figure)
    0002 %-----------------------------------------------------------------------
    0003 %
    0004 % function mouse_motion(hObject,eventdata,handles)
    0005 % activated by the command:
    0006 % set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})
    0007 % where hObject is the handle of the figure
    0008 %
    0009 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0010 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    0011 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0012 %     This file is part of the toolbox UVMAT.
    0013 %
    0014 %     UVMAT is free software; you can redistribute it and/or modify
    0015 %     it under the terms of the GNU General Public License as published by
    0016 %     the Free Software Foundation; either version 2 of the License, or
    0017 %     (at your option) any later version.
    0018 %
    0019 %     UVMAT is distributed in the hope that it will be useful,
    0020 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
    0021 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0022 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
    0023 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0024
    0025 function mouse_motion(hObject,eventdata,handles)
    0026 if ~exist('handles','var')
    0027     return
    0028 end
    0029 if ~isfield(handles, 'mouse_coord')
    0030     return
    0031 end
    0032 if ~ishandle(handles.mouse_coord)
    0033     return
    0034 end
    0035 proj_coord=get(handles.mouse_coord,'String');
    0036 choice=get(handles.mouse_coord,'Value');
    0037 if ~isempty(proj_coord); proj_coord=proj_coord{choice};else;proj_coord=[];end;
    0038 test_create=0;%default
    0039 test_edit=0;%default
    0040 if isfield(handles,'VOLUME') % mouse_motion not applied to the uvmat figure, no object creation
    0041     test_create=get(handles.create,'Value');
    0042 end
    0043 test_edit=isfield(handles,'edit') & get(handles.edit,'Value');% edit test for mouse shap: an arrow
    0044 test_zoom=isfield(handles,'zoom')& get(handles.zoom,'Value');% edit test for mouse shap: an arrow
    0045
    0046 %find the current axe 'haxes' and display the current mouse position or uicontrol tag
    0047 text_displ_1='';
    0048 text_displ_2='';
    0049 text_displ_3='';
    0050 text_displ_4='';
    0051
    0052 haxes=[];
    0053 AxeData=[];%default
    0054 mouse=[];
    0055
    0056 pointershape='arrow';% default pointer is an arrow
    0057
    0058 xy_fig=get(gcbo,'CurrentPoint');% current point of the current figure (gcbo)
    0059 hchild=get(gcbo,'Children');%handles of all objects in the current figure
    0060 currentfig=gcbo;%store gcbo as variable currentfig
    0061 % loop on all the objects in the current figure (selected by the last mouse click)
    0062 for ichild=1:length(hchild)
    0063     obj_pos=get(hchild(ichild),'Position');%position of the object
    0064     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);
    0065         htype=get(hchild(ichild),'Type');%type of the crrent child
    0066         %if the mouse is over an axis, look at the data
    0067         if isequal(htype,'axes')
    0068             haxes=hchild(ichild);
    0069             xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
    0070             mouse.X=xy(1,1);
    0071             mouse.Y=xy(1,2);
    0072             u_mouse=[];
    0073             v_mouse=[];
    0074             w_mouse=[];
    0075             A_mouse=[];
    0076             c_text=[];
    0077             f_text=[];
    0078             ff_text=[];
    0079             ivec=[];
    0080             AxeData=get(haxes,'UserData');% data attached to the axis
    0081              if ~test_edit && ~test_zoom
    0082                  pointershape='crosshair';%set pointer with cross shape (default when mouse is over an axis)
    0083 %                % pointershape='crosshair';%set pointer with cross shape (default over axis)
    0084              end
    0085             if isfield(AxeData,'X') & isfield(AxeData,'Y') & isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis
    0086                 if ~isempty(AxeData.Mesh)
    0087                     flag_vec=(AxeData.X<(xy(1,1)+AxeData.Mesh/3) & AxeData.X>(xy(1,1)-AxeData.Mesh/3)) & ...%flagx=1 for the vectors with x position selected by the mouse
    0088                           (AxeData.Y<(xy(1,2)+AxeData.Mesh/3) & AxeData.Y>(xy(1,2)-AxeData.Mesh/3));%f
    0089                     ivec=find(flag_vec);% search the selected vector index ivec
    0090                     if length(ivec)>0
    0091                         if ~test_create
    0092                             pointershape='arrow'; %mouse indicates  the detection of a vector
    0093                         end
    0094                         ivec=ivec(1);%choice the first selected vector if several are selected
    0095                         mouse.X=AxeData.X(ivec);
    0096                         mouse.Y=AxeData.Y(ivec);
    0097                         u_mouse=AxeData.U(ivec);%displacement
    0098                         v_mouse=AxeData.V(ivec);
    0099                         w_mouse=0; %default
    0100                         if isfield(AxeData,'W')&length(AxeData.W)>=ivec
    0101                             w_text=[',  w=' num2str(AxeData.W(ivec),3)];
    0102                         else
    0103                             w_text='';
    0104                         end
    0105                         if ~isfield(AxeData,'CName')
    0106                             AxeData.CName='C';%REVOIR
    0107                         end
    0108                         c_text=[', ' AxeData.CName '=' num2str(AxeData.C(ivec),3)];
    0109                         if isfield(AxeData,'F')&length(AxeData.F)>=ivec
    0110                             f_text=[',  f=' num2str(AxeData.F(ivec),3)];
    0111                         else
    0112                             f_text='';
    0113                         end
    0114                         if isfield(AxeData,'FF')&length(AxeData.FF)>=ivec
    0115                             ff_text=[',  ff=' num2str(AxeData.FF(ivec),3)];
    0116                         else
    0117                             ff_text='';
    0118                         end
    0119                     end
    0120                 end
    0121             end
    0122             if isfield(AxeData,'ZObject')
    0123                 mouse.Z=AxeData.ZObject(1); %generaliser au cas avec angle
    0124             end
    0125             if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3
    0126                 mouse.Z=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle
    0127             end
    0128             testscal= isfield(AxeData,'A')& isfield(AxeData,'AX')& isfield(AxeData,'AY');%test the existence of an image (or scalar represented by an image)
    0129                if testscal
    0130                    testscal=~isempty(AxeData.A)&~isempty(AxeData.AX)& ~isempty(AxeData.AY);
    0131                end
    0132             if testscal%test the existence of an image (or scalar represented by an image)
    0133                 nxy=size(AxeData.A);
    0134                 MaxAY=max(AxeData.AY(1),AxeData.AY(end));
    0135                 MinAY=min(AxeData.AY(1),AxeData.AY(end));
    0136                 if (xy(1,1)>AxeData.AX(1))&(xy(1,1)<AxeData.AX(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY)
    0137                     indx0=1+round((nxy(2)-1)*(xy(1,1)-AxeData.AX(1))/(AxeData.AX(end)-AxeData.AX(1)));% index x of pixel
    0138                     indy0=1+round((nxy(1)-1)*(xy(1,2)-AxeData.AY(1))/(AxeData.AY(end)-AxeData.AY(1)));% index y of pixel
    0139                     if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1)
    0140                         A_mouse=AxeData.A(indy0,indx0,:);
    0141                     end
    0142                 end
    0143             end
    0144             %coordinate transform if proj_coord differs from menu_coord
    0145             if isfield(AxeData,'CoordType')
    0146                   mouse.CoordType=AxeData.CoordType;
    0147             end
    0148             if isfield(AxeData,'CoordUnit')
    0149                   mouse.CoordUnit=AxeData.CoordUnit;
    0150             end
    0151             if isfield(mouse,'CoordType') &~isequal(mouse.CoordType,proj_coord)
    0152                 huvmat=findobj(allchild(0),'Tag','uvmat');%find the uvmat interface handle
    0153                 UvData=get(huvmat,'UserData'); %coord transformed stored in the uvmat interface, updated by file input
    0154                 if isfield(AxeData,'CoordType')
    0155                     mouse.CoordType=AxeData.CoordType;
    0156                 end
    0157                 if isfield(AxeData,'dt')
    0158                     mouse.dt=AxeData.dt;
    0159                 end
    0160 %                 if ~isempty(z_mouse)
    0161 %                     mouse.Z=z_mouse;
    0162 %                 end
    0163                 if length(ivec)>0 %& isfield(AxeData,'dt')
    0164                       mouse.U=u_mouse;
    0165                       mouse.V=v_mouse;
    0166                 end
    0167                 mouse=feval(proj_coord,mouse,UvData);%apply transform proj_coord to the position
    0168                 if length(ivec)>0%& isfield(AxeData,'dt')
    0169                      u_mouse=mouse.U;
    0170                      v_mouse=mouse.V;
    0171                 end
    0172             end
    0173             if isfield(mouse,'CoordType')
    0174                 if isequal(mouse.CoordType,'px')
    0175                     mouse.CoordUnit='px';
    0176                 end
    0177             else
    0178                 mouse.CoordUnit='';%default
    0179             end
    0180             text_displ_1=['x=' num2str(mouse.X,4) ',y=' num2str(mouse.Y,4)];
    0181             if isfield(mouse,'Z')&~isempty(mouse.Z)
    0182                 text_displ_1=[text_displ_1 ',z=' num2str(mouse.Z,3)];
    0183             end
    0184             if isfield(mouse,'CoordUnit')
    0185                  text_displ_1=[text_displ_1 ' ' mouse.CoordUnit];
    0186             end
    0187             if ~isempty(ivec)
    0188                 text_displ_4=['vec#=' num2str(ivec)];
    0189             end
    0190             if ~isempty(u_mouse)
    0191                 text_displ_3=['u=' num2str(u_mouse,3) ',v=' num2str(v_mouse,3) w_text ];
    0192                 if  isfield(mouse,'CoordUnit')
    0193                     if isequal(mouse.CoordUnit,'px')
    0194                         text_displ_3=[text_displ_3 '  ' mouse.CoordUnit];
    0195                     elseif isfield(AxeData,'TimeUnit')
    0196                         text_displ_3=[text_displ_3 '  ' mouse.CoordUnit '/' AxeData.TimeUnit];
    0197                     end
    0198                 end
    0199                 text_displ_4=[text_displ_4 c_text f_text ff_text];
    0200             end
    0201
    0202             if ~isempty(A_mouse)
    0203                 text_displ_2=['A=' num2str(double(A_mouse)) ',i='  num2str(indx0) ',j=' num2str(indy0)];
    0204             end
    0205         elseif isequal(get(hchild(ichild),'Visible'),'on')& ~isequal(get(hchild(ichild),'Style'),'frame')
    0206             text_displ_1=get(hchild(ichild),'Tag');
    0207         end
    0208     end
    0209 end
    0210 set(handles.text_display_1,'String',text_displ_1);
    0211 set(handles.text_display_2,'String',text_displ_2);
    0212 set(handles.text_display_3,'String',text_displ_3);
    0213 set(handles.text_display_4,'String',text_displ_4);
    0214
    0215 %%%%%%%%%%%%%%%%%
    0216 %create or modify an object
    0217 if isfield(AxeData,'CurrentObject') & ishandle(AxeData.CurrentObject) & isfield(AxeData,'Drawing') & ~isequal(AxeData.Drawing,'off')
    0218     PlotData=get(AxeData.CurrentObject,'UserData');
    0219     huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle
    0220     if ~isempty(huvmat)
    0221         UvData=get(huvmat,'UserData');
    0222         if ~isfield(PlotData,'IndexObj')
    0223              return
    0224         end
    0225         ObjectData=UvData.Object{PlotData.IndexObj};
    0226         XYData=AxeData.CurrentOrigin;
    0227         if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin)
    0228            if isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')|isequal(ObjectData.Style,'polygon')|isequal(ObjectData.Style,'points')
    0229               xy(1,3)=0;
    0230               ObjectData.Coord=[ObjectData.Coord ;xy(1,:)];
    0231              % ObjectData.Coord(end,:)=xy(1,:);
    0232            elseif isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')|isequal(ObjectData.Style,'volume')
    0233               ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
    0234               ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
    0235               ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
    0236               ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
    0237            elseif isequal(ObjectData.Style,'plane') %case of 'plane'
    0238                 DX=(xy(1,1)-ObjectData.Coord(1,1));
    0239                 DY=(xy(1,2)-ObjectData.Coord(1,2));
    0240                 ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt
    0241                 if isfield(ObjectData,'RangeX')
    0242                     XMax=sqrt(DX*DX+DY*DY);
    0243                     if XMax>max(ObjectData.RangeX)
    0244                         ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
    0245                     end
    0246                 end
    0247            end
    0248             plot_object(ObjectData,[],AxeData.CurrentObject,'m');
    0249             pointershape='crosshair';
    0250         elseif  isequal(AxeData.Drawing,'translate')
    0251             DX=xy(1,1)-XYData(1);%translation from initial position
    0252             DY=xy(1,2)-XYData(2);
    0253             ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX;
    0254             ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
    0255             plot_object(ObjectData,[],AxeData.CurrentObject,'m');
    0256             pointershape='fleur';
    0257         elseif  isequal(AxeData.Drawing,'deform')
    0258             ind_move=AxeData.CurrentIndex;
    0259             ObjectData.Coord(ind_move,1)=xy(1,1);
    0260             ObjectData.Coord(ind_move,2)=xy(1,2);
    0261             plot_object(ObjectData,[],AxeData.CurrentObject,'m');
    0262             pointershape='circle';
    0263         end
    0264     end
    0265 end
    0266 %%%%%%%%%%%%%
    0267 %draw a rectangle if no object creation is selected
    0268 if ~isempty(haxes) & isfield(AxeData,'Drawing')& isequal(AxeData.Drawing,'zoom')& isfield(AxeData,'CurrentOrigin')...
    0269         & isequal(get(gcf,'SelectionType'),'normal')%
    0270    xy_rect=AxeData.CurrentOrigin;
    0271    if ~isempty(xy_rect)
    0272         rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate
    0273         rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate
    0274         rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width
    0275         rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height
    0276         if rect(3)>0 & rect(4)>0
    0277             if isfield(AxeData,'CurrentRectZoom')& ishandle(AxeData.CurrentRectZoom)
    0278                 set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position
    0279             else
    0280                 AxeData.CurrentRectZoom=rectangle('Position',rect,'LineStyle',':','Tag','rect_zoom');
    0281                 set(haxes,'UserData',AxeData)
    0282             end
    0283         end
    0284    end
    0285 end
    0286 if test_zoom
    0287     pointershape='arrow';
    0288 end
    0289 set(currentfig,'Pointer',pointershape);