source: trunk/src/mouse_motion.m @ 65

Last change on this file since 65 was 65, checked in by sommeria, 14 years ago

name_generator: remove unneeded indices at output
civ.m: & introduced at the end of system command lines (beginning by !) to allow matlab operations during civ in run mode
uvmat.m: debugging in dealing with projections
prove image pair movies superposed to velocity vectors
mouse: put circles along detected vectors

File size: 14.2 KB
RevLine 
[11]1%'mouse_motion': permanently called by mouse motion over a figure (Callback for 'WindowButtonMotionFcn' of the figure)
2%-----------------------------------------------------------------------
3%
4% function mouse_motion(hObject,eventdata,handles)
5% activated by the command:
6% set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})
7% where hObject is the handle of the figure
8%
9%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
10%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
11%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
12%     This file is part of the toolbox UVMAT.
13%
14%     UVMAT is free software; you can redistribute it and/or modify
15%     it under the terms of the GNU General Public License as published by
16%     the Free Software Foundation; either version 2 of the License, or
17%     (at your option) any later version.
18%
19%     UVMAT is distributed in the hope that it will be useful,
20%     but WITHOUT ANY WARRANTY; without even the implied warranty of
21%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
23%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
24
25function mouse_motion(hObject,eventdata,handles)
26if ~exist('handles','var')
27    return
28end
[60]29% if ~isfield(handles, 'mouse_coord')
30%     'TEST'
31%     return
32% end
33% if ~ishandle(handles.mouse_coord)
34%     return
35% end
36% proj_coord=get(handles.mouse_coord,'String');
37% choice=get(handles.mouse_coord,'Value');
38% if ~isempty(proj_coord); proj_coord=proj_coord{choice};else;proj_coord=[];end;
[11]39test_create=0;%default
40test_edit=0;%default
[61]41% if isfield(handles,'VOLUME') % mouse_motion not applied to the uvmat figure, no object creation
42%     test_create=get(handles.create,'Value');   
43% end
[11]44test_edit=isfield(handles,'edit') & get(handles.edit,'Value');% edit test for mouse shap: an arrow
45test_zoom=isfield(handles,'zoom')& get(handles.zoom,'Value');% edit test for mouse shap: an arrow
46
47%find the current axe 'haxes' and display the current mouse position or uicontrol tag
48text_displ_1='';
49text_displ_2='';
50text_displ_3='';
51text_displ_4='';
52
53haxes=[];
54AxeData=[];%default
55mouse=[];
56
57pointershape='arrow';% default pointer is an arrow
58
59xy_fig=get(gcbo,'CurrentPoint');% current point of the current figure (gcbo)
60hchild=get(gcbo,'Children');%handles of all objects in the current figure
61currentfig=gcbo;%store gcbo as variable currentfig
62% loop on all the objects in the current figure (selected by the last mouse click)
63for ichild=1:length(hchild)
64    obj_pos=get(hchild(ichild),'Position');%position of the object
65    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);
66        htype=get(hchild(ichild),'Type');%type of the crrent child
67        %if the mouse is over an axis, look at the data
68        if isequal(htype,'axes')
69            haxes=hchild(ichild);
70            xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
71            mouse.X=xy(1,1);
72            mouse.Y=xy(1,2);
73            u_mouse=[];
74            v_mouse=[];
75            w_mouse=[];
76            A_mouse=[];
77            c_text=[];
78            f_text=[];
79            ff_text=[];     
80            ivec=[];
81            AxeData=get(haxes,'UserData');% data attached to the axis
82             if ~test_edit && ~test_zoom
83                 pointershape='crosshair';%set pointer with cross shape (default when mouse is over an axis)
84%                % pointershape='crosshair';%set pointer with cross shape (default over axis)
85             end
86            if isfield(AxeData,'X') && isfield(AxeData,'Y') && isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis
87                if ~isempty(AxeData.Mesh)
88                    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
89                          (AxeData.Y<(xy(1,2)+AxeData.Mesh/3) & AxeData.Y>(xy(1,2)-AxeData.Mesh/3));%f
90                    ivec=find(flag_vec);% search the selected vector index ivec
[65]91                    hhh=findobj(haxes,'Tag','vector_marker');
[11]92                    if length(ivec)>0
[65]93                        %ivec=ivec(1);%choice the first selected vector if several are selected
[11]94                        if ~test_create
95                            pointershape='arrow'; %mouse indicates  the detection of a vector
[65]96 
[61]97                            if isempty(hhh)
[65]98                                set(currentfig,'CurrentAxes',haxes)
99                                rectangle('Curvature',[1 1],...
100                  'Position',[AxeData.X(ivec)-AxeData.Mesh AxeData.Y(ivec)/2-AxeData.Mesh/2 AxeData.Mesh AxeData.Mesh],'EdgeColor','m',...
101                  'LineStyle','-','Tag','vector_marker');
102%                                 line(AxeData.X(ivec),AxeData.Y(ivec),'Color','m','Tag','vector_marker','LineStyle','.','Marker','o','MarkerSize',AxeData.Mesh);
[61]103                            else
[65]104                                set(hhh,'Position',[AxeData.X(ivec)-AxeData.Mesh/2 AxeData.Y(ivec)-AxeData.Mesh/2 AxeData.Mesh AxeData.Mesh])
[61]105                            end
[65]106                        end                 
[11]107                        mouse.X=AxeData.X(ivec);
108                        mouse.Y=AxeData.Y(ivec);
109                        u_mouse=AxeData.U(ivec);%displacement
110                        v_mouse=AxeData.V(ivec);
111                        w_mouse=0; %default
[65]112                        if isfield(AxeData,'W') & length(AxeData.W)>=ivec
[11]113                            w_text=[',  w=' num2str(AxeData.W(ivec),3)];
114                        else
115                            w_text='';
116                        end
117                        if ~isfield(AxeData,'CName')
118                            AxeData.CName='C';%REVOIR
119                        end
120                        c_text=[', ' AxeData.CName '=' num2str(AxeData.C(ivec),3)];
121                        if isfield(AxeData,'F')&length(AxeData.F)>=ivec
122                            f_text=[',  f=' num2str(AxeData.F(ivec),3)];
123                        else
124                            f_text='';
125                        end
126                        if isfield(AxeData,'FF')&length(AxeData.FF)>=ivec
127                            ff_text=[',  ff=' num2str(AxeData.FF(ivec),3)];
128                        else
129                            ff_text='';
130                        end
[65]131                    else
132                        if ~isempty(hhh)
133                            delete(hhh)
134                        end
[11]135                    end
136                end
137            end
138            if isfield(AxeData,'Z')
139                mouse.Z=AxeData.Z; %generaliser au cas avec angle
140            end
141            if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3
142                mouse.Z=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle
143            end
144            testscal= isfield(AxeData,'A')& isfield(AxeData,'AX')& isfield(AxeData,'AY');%test the existence of an image (or scalar represented by an image)
145               if testscal
146                   testscal=~isempty(AxeData.A)&~isempty(AxeData.AX)& ~isempty(AxeData.AY);
147               end
148            if testscal%test the existence of an image (or scalar represented by an image)
149                nxy=size(AxeData.A);
150                MaxAY=max(AxeData.AY(1),AxeData.AY(end));
151                MinAY=min(AxeData.AY(1),AxeData.AY(end));
152                if (xy(1,1)>AxeData.AX(1))&(xy(1,1)<AxeData.AX(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY)
153                    indx0=1+round((nxy(2)-1)*(xy(1,1)-AxeData.AX(1))/(AxeData.AX(end)-AxeData.AX(1)));% index x of pixel
154                    indy0=1+round((nxy(1)-1)*(xy(1,2)-AxeData.AY(1))/(AxeData.AY(end)-AxeData.AY(1)));% index y of pixel
155                    if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1)
156                        A_mouse=AxeData.A(indy0,indx0,:);
157                    end
158                end
159            end
160            %coordinate transform if proj_coord differs from menu_coord
161            if isfield(AxeData,'CoordType')
162                  mouse.CoordType=AxeData.CoordType;
163            end
164            if isfield(AxeData,'CoordUnit')
165                  mouse.CoordUnit=AxeData.CoordUnit;
[60]166            end
[11]167            if isfield(mouse,'CoordType')
168                if isequal(mouse.CoordType,'px')
169                    mouse.CoordUnit='px';
170                end
171            else
172                mouse.CoordUnit='';%default     
173            end     
174            text_displ_1=['x=' num2str(mouse.X,4) ',y=' num2str(mouse.Y,4)];
175            if isfield(mouse,'Z')&~isempty(mouse.Z)
176                text_displ_1=[text_displ_1 ',z=' num2str(mouse.Z,3)];
177            end
178            if isfield(mouse,'CoordUnit')
179                 text_displ_1=[text_displ_1 ' ' mouse.CoordUnit];
180            end
181            if ~isempty(ivec)
182                text_displ_4=['vec#=' num2str(ivec)];
183            end
184            if ~isempty(u_mouse)
185                text_displ_3=['u=' num2str(u_mouse,3) ',v=' num2str(v_mouse,3) w_text ];
186                if  isfield(mouse,'CoordUnit')
187                    if isequal(mouse.CoordUnit,'px')
188                        text_displ_3=[text_displ_3 '  ' mouse.CoordUnit];
189                    elseif isfield(AxeData,'TimeUnit')
190                        text_displ_3=[text_displ_3 '  ' mouse.CoordUnit '/' AxeData.TimeUnit];
191                    end
192                end
193                text_displ_4=[text_displ_4 c_text f_text ff_text];
194            end
195           
196            if ~isempty(A_mouse)
197                text_displ_2=['A=' num2str(double(A_mouse)) ',i='  num2str(indx0) ',j=' num2str(indy0)];
198            end
[60]199        elseif isequal(htype,'uicontrol') && isequal(get(hchild(ichild),'Visible'),'on')&& ~isequal(get(hchild(ichild),'Style'),'frame')
[11]200            text_displ_1=get(hchild(ichild),'Tag');
201        end
202    end
203end
204set(handles.text_display_1,'String',text_displ_1);
205set(handles.text_display_2,'String',text_displ_2);
206set(handles.text_display_3,'String',text_displ_3);
207set(handles.text_display_4,'String',text_displ_4);
208
209%%%%%%%%%%%%%%%%%
210%create or modify an object
[61]211huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle
212if ~isempty(huvmat)
213    UvData=get(huvmat,'UserData');
214end
215if ~isempty(huvmat) & isfield(AxeData,'CurrentObject') & ishandle(AxeData.CurrentObject) & isfield(AxeData,'Drawing') & ~isequal(AxeData.Drawing,'off')
[11]216    PlotData=get(AxeData.CurrentObject,'UserData');
217    huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle
218    if ~isempty(huvmat)
219        UvData=get(huvmat,'UserData');
220        if ~isfield(PlotData,'IndexObj')
221             return
222        end
223        ObjectData=UvData.Object{PlotData.IndexObj};
224        XYData=AxeData.CurrentOrigin;
225        if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin)
226           if isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')|isequal(ObjectData.Style,'polygon')|isequal(ObjectData.Style,'points')
227              xy(1,3)=0;
228              ObjectData.Coord=[ObjectData.Coord ;xy(1,:)];
229             % ObjectData.Coord(end,:)=xy(1,:);
230           elseif isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')|isequal(ObjectData.Style,'volume')
231              ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
232              ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
233              ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
234              ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
235           elseif isequal(ObjectData.Style,'plane') %case of 'plane'
236                DX=(xy(1,1)-ObjectData.Coord(1,1));
237                DY=(xy(1,2)-ObjectData.Coord(1,2));
238                ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt
239                if isfield(ObjectData,'RangeX')
240                    XMax=sqrt(DX*DX+DY*DY);
241                    if XMax>max(ObjectData.RangeX)
242                        ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
243                    end
244                end
245           end
246            plot_object(ObjectData,[],AxeData.CurrentObject,'m');
247            pointershape='crosshair';
248        elseif  isequal(AxeData.Drawing,'translate')
249            DX=xy(1,1)-XYData(1);%translation from initial position
250            DY=xy(1,2)-XYData(2);
251            ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX;
252            ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
253            plot_object(ObjectData,[],AxeData.CurrentObject,'m');
254            pointershape='fleur';
255        elseif  isequal(AxeData.Drawing,'deform')
256            ind_move=AxeData.CurrentIndex;
257            ObjectData.Coord(ind_move,1)=xy(1,1);
258            ObjectData.Coord(ind_move,2)=xy(1,2);
259            plot_object(ObjectData,[],AxeData.CurrentObject,'m');
260            pointershape='circle';
261        end
262    end
263end   
264%%%%%%%%%%%%%
265%draw a rectangle if no object creation is selected
266if ~isempty(haxes) & isfield(AxeData,'Drawing')& isequal(AxeData.Drawing,'zoom')& isfield(AxeData,'CurrentOrigin')...
267        & isequal(get(gcf,'SelectionType'),'normal')%
268   xy_rect=AxeData.CurrentOrigin;
269   if ~isempty(xy_rect)
270        rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate
271        rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate
272        rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width
273        rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height
274        if rect(3)>0 & rect(4)>0
275            if isfield(AxeData,'CurrentRectZoom')& ishandle(AxeData.CurrentRectZoom)
276                set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position
277            else
278                AxeData.CurrentRectZoom=rectangle('Position',rect,'LineStyle',':','Tag','rect_zoom');
279                set(haxes,'UserData',AxeData)
280            end
281        end
282   end
283end
284if test_zoom
285    pointershape='arrow';
286end
[60]287
288%draw ruler
[61]289if ~isempty(huvmat)
290    UvData=get(huvmat,'UserData');
291    if isfield(UvData,'MouseAction') && isequal(UvData.MouseAction,'ruler')
292           if isfield(UvData,'RulerHandle')
293                RulerCoord=[UvData.RulerCoord ;xy(1,1:2)];
294                set(UvData.RulerHandle,'XData',RulerCoord(:,1));
295                set(UvData.RulerHandle,'YData',RulerCoord(:,2));
296           end
297    end
[60]298end
[11]299set(currentfig,'Pointer',pointershape);
Note: See TracBrowser for help on using the repository browser.