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 | |
---|
25 | function mouse_motion(hObject,eventdata,handles) |
---|
26 | |
---|
27 | if ~exist('handles','var') |
---|
28 | return |
---|
29 | end |
---|
30 | test_draw=0; |
---|
31 | test_create=0;%default |
---|
32 | test_object=0; %default |
---|
33 | test_edit=isfield(handles,'edit') && get(handles.edit,'Value');% edit test for mouse shap: an arrow |
---|
34 | test_zoom_draw=0; %default |
---|
35 | test_ruler=0; |
---|
36 | huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle |
---|
37 | hhuvmat=guidata(huvmat); |
---|
38 | test_zoom=get(hhuvmat.zoom,'Value'); |
---|
39 | if ~isempty(huvmat) |
---|
40 | UvData=get(huvmat,'UserData'); |
---|
41 | test_ruler=isfield(UvData,'MouseAction') && isequal(UvData.MouseAction,'ruler'); |
---|
42 | end |
---|
43 | |
---|
44 | |
---|
45 | %find the current axe 'haxes' and display the current mouse position or uicontrol tag |
---|
46 | text_displ_1=''; |
---|
47 | text_displ_2=''; |
---|
48 | text_displ_3=''; |
---|
49 | text_displ_4=''; |
---|
50 | |
---|
51 | AxeData=[];%default |
---|
52 | mouse=[]; |
---|
53 | xy=[];%default |
---|
54 | |
---|
55 | pointershape='arrow';% default pointer is an arrow |
---|
56 | currentfig=hObject; |
---|
57 | xy_fig=get(currentfig,'CurrentPoint');% current point of the current figure (gcbo) |
---|
58 | hchild=get(currentfig,'Children');%handles of all objects in the current figure |
---|
59 | |
---|
60 | % loop on all the objects in the current figure and detect whether the mouse is over a plot axes |
---|
61 | haxes=[]; |
---|
62 | for ichild=1:length(hchild) |
---|
63 | obj_pos=get(hchild(ichild),'Position'); |
---|
64 | if numel(obj_pos)~=4% for some versions of matlab some objects |
---|
65 | get(hchild(ichild)) |
---|
66 | % continue |
---|
67 | end%position of the object |
---|
68 | 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); |
---|
69 | htype=get(hchild(ichild),'Type');%type of the crrent child |
---|
70 | %if the mouse is over an axis, look at the data |
---|
71 | if isequal(htype,'axes') |
---|
72 | haxes=hchild(ichild); |
---|
73 | xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
74 | mouse.X=xy(1,1); |
---|
75 | mouse.Y=xy(1,2); |
---|
76 | u_mouse=[]; |
---|
77 | v_mouse=[]; |
---|
78 | w_mouse=[]; |
---|
79 | A_mouse=[]; |
---|
80 | c_text=[]; |
---|
81 | f_text=[]; |
---|
82 | ff_text=[]; |
---|
83 | ivec=[]; |
---|
84 | AxeData=get(haxes,'UserData');% data attached to the axis |
---|
85 | if isfield(AxeData,'Drawing')&& ~isempty(AxeData.Drawing) |
---|
86 | test_draw=~isequal(AxeData.Drawing,'off'); |
---|
87 | end |
---|
88 | test_zoom_draw=test_draw && isequal(AxeData.Drawing,'zoom')&& isfield(AxeData,'CurrentOrigin') && isequal(get(gcf,'SelectionType'),'normal'); |
---|
89 | test_object=test_draw && isfield(AxeData,'CurrentObject') && ~isempty(AxeData.CurrentObject) && ishandle(AxeData.CurrentObject); |
---|
90 | if ~test_edit && ~test_zoom_draw && ~test_ruler |
---|
91 | pointershape='crosshair';%set pointer with cross shape (default when mouse is over an axis) |
---|
92 | end |
---|
93 | if isfield(AxeData,'X') && isfield(AxeData,'Y') && isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis |
---|
94 | if ~isempty(AxeData.Mesh) |
---|
95 | 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 |
---|
96 | (AxeData.Y<(xy(1,2)+AxeData.Mesh/3) & AxeData.Y>(xy(1,2)-AxeData.Mesh/3));%f |
---|
97 | ivec=find(flag_vec,1);% search the (first) selected vector index ivec |
---|
98 | hhh=findobj(haxes,'Tag','vector_marker'); |
---|
99 | if ~isempty(ivec) |
---|
100 | if ~test_object % mark the vectors with a circle in the absence of other operations |
---|
101 | if ~test_create && ~test_edit && ~test_ruler |
---|
102 | pointershape='arrow'; %mouse indicates the detection of a vector |
---|
103 | if isempty(hhh) |
---|
104 | hstack=findobj(allchild(0),'Type','figure');%current stack order of figures in matlab |
---|
105 | axes(haxes) |
---|
106 | rectangle('Curvature',[1 1],... |
---|
107 | 'Position',[AxeData.X(ivec)-AxeData.Mesh/2 AxeData.Y(ivec)-AxeData.Mesh/2 AxeData.Mesh AxeData.Mesh],'EdgeColor','m',... |
---|
108 | 'LineStyle','-','Tag','vector_marker'); |
---|
109 | set(0,'Children',hstack);%put back the initial figure stack after plot creation |
---|
110 | else |
---|
111 | set(hhh,'Visible','on') |
---|
112 | set(hhh,'Position',[AxeData.X(ivec)-AxeData.Mesh/2 AxeData.Y(ivec)-AxeData.Mesh/2 AxeData.Mesh AxeData.Mesh]) |
---|
113 | end |
---|
114 | end |
---|
115 | end |
---|
116 | mouse.X=AxeData.X(ivec); |
---|
117 | mouse.Y=AxeData.Y(ivec); |
---|
118 | u_mouse=AxeData.U(ivec);%displacement |
---|
119 | v_mouse=AxeData.V(ivec); |
---|
120 | w_mouse=0; %default |
---|
121 | if isfield(AxeData,'W') & length(AxeData.W)>=ivec |
---|
122 | w_text=[', w=' num2str(AxeData.W(ivec),3)]; |
---|
123 | else |
---|
124 | w_text=''; |
---|
125 | end |
---|
126 | if ~isfield(AxeData,'CName') |
---|
127 | AxeData.CName='C';%REVOIR |
---|
128 | end |
---|
129 | c_text=[', ' AxeData.CName '=' num2str(AxeData.C(ivec),3)]; |
---|
130 | if isfield(AxeData,'F')&length(AxeData.F)>=ivec |
---|
131 | f_text=[', f=' num2str(AxeData.F(ivec),3)]; |
---|
132 | else |
---|
133 | f_text=''; |
---|
134 | end |
---|
135 | if isfield(AxeData,'FF')&length(AxeData.FF)>=ivec |
---|
136 | ff_text=[', ff=' num2str(AxeData.FF(ivec),3)]; |
---|
137 | else |
---|
138 | ff_text=''; |
---|
139 | end |
---|
140 | else |
---|
141 | if ~isempty(hhh) |
---|
142 | set(hhh,'Visible','off') |
---|
143 | end |
---|
144 | end |
---|
145 | end |
---|
146 | end |
---|
147 | if isfield(AxeData,'Z') |
---|
148 | mouse.Z=AxeData.Z; %generaliser au cas avec angle |
---|
149 | end |
---|
150 | if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3 |
---|
151 | mouse.Z=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle |
---|
152 | end |
---|
153 | testscal= isfield(AxeData,'A')& isfield(AxeData,'AX')& isfield(AxeData,'AY');%test the existence of an image (or scalar represented by an image) |
---|
154 | if testscal |
---|
155 | testscal=~isempty(AxeData.A)&~isempty(AxeData.AX)& ~isempty(AxeData.AY); |
---|
156 | end |
---|
157 | if testscal%test the existence of an image (or scalar represented by an image) |
---|
158 | nxy=size(AxeData.A); |
---|
159 | MaxAY=max(AxeData.AY(1),AxeData.AY(end)); |
---|
160 | MinAY=min(AxeData.AY(1),AxeData.AY(end)); |
---|
161 | if (xy(1,1)>AxeData.AX(1))&(xy(1,1)<AxeData.AX(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY) |
---|
162 | indx0=1+round((nxy(2)-1)*(xy(1,1)-AxeData.AX(1))/(AxeData.AX(end)-AxeData.AX(1)));% index x of pixel |
---|
163 | indy0=1+round((nxy(1)-1)*(xy(1,2)-AxeData.AY(1))/(AxeData.AY(end)-AxeData.AY(1)));% index y of pixel |
---|
164 | if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1) |
---|
165 | A_mouse=AxeData.A(indy0,indx0,:); |
---|
166 | end |
---|
167 | end |
---|
168 | end |
---|
169 | %coordinate transform if proj_coord differs from menu_coord |
---|
170 | if isfield(AxeData,'CoordType') |
---|
171 | mouse.CoordType=AxeData.CoordType; |
---|
172 | end |
---|
173 | if isfield(AxeData,'CoordUnit') |
---|
174 | mouse.CoordUnit=AxeData.CoordUnit; |
---|
175 | end |
---|
176 | if isfield(mouse,'CoordType') |
---|
177 | if isequal(mouse.CoordType,'px') |
---|
178 | mouse.CoordUnit='px'; |
---|
179 | end |
---|
180 | else |
---|
181 | mouse.CoordUnit='';%default |
---|
182 | end |
---|
183 | text_displ_1=['x=' num2str(mouse.X,4) ',y=' num2str(mouse.Y,4)]; |
---|
184 | if isfield(mouse,'Z')&~isempty(mouse.Z) |
---|
185 | text_displ_1=[text_displ_1 ',z=' num2str(mouse.Z,3)]; |
---|
186 | end |
---|
187 | if isfield(mouse,'CoordUnit') |
---|
188 | text_displ_1=[text_displ_1 ' ' mouse.CoordUnit]; |
---|
189 | end |
---|
190 | if ~isempty(ivec) |
---|
191 | text_displ_4=['vec#=' num2str(ivec)]; |
---|
192 | end |
---|
193 | if ~isempty(u_mouse) |
---|
194 | text_displ_3=['u=' num2str(u_mouse,3) ',v=' num2str(v_mouse,3) w_text ]; |
---|
195 | if isfield(mouse,'CoordUnit') |
---|
196 | if isequal(mouse.CoordUnit,'px') |
---|
197 | text_displ_3=[text_displ_3 ' ' mouse.CoordUnit]; |
---|
198 | elseif isfield(AxeData,'TimeUnit') |
---|
199 | text_displ_3=[text_displ_3 ' ' mouse.CoordUnit '/' AxeData.TimeUnit]; |
---|
200 | end |
---|
201 | end |
---|
202 | text_displ_4=[text_displ_4 c_text f_text ff_text]; |
---|
203 | end |
---|
204 | |
---|
205 | if ~isempty(A_mouse) |
---|
206 | text_displ_2=['A=' num2str(double(A_mouse)) ',i=' num2str(indx0) ',j=' num2str(indy0)]; |
---|
207 | end |
---|
208 | elseif isequal(htype,'uicontrol') && isequal(get(hchild(ichild),'Visible'),'on')&& ~isequal(get(hchild(ichild),'Style'),'frame') |
---|
209 | text_displ_1=get(hchild(ichild),'Tag'); |
---|
210 | end |
---|
211 | end |
---|
212 | end |
---|
213 | set(handles.text_display_1,'String',text_displ_1); |
---|
214 | set(handles.text_display_2,'String',text_displ_2); |
---|
215 | set(handles.text_display_3,'String',text_displ_3); |
---|
216 | set(handles.text_display_4,'String',text_displ_4); |
---|
217 | % if ~test_draw |
---|
218 | % return |
---|
219 | % end |
---|
220 | % At this stage if no drawing operation is done |
---|
221 | |
---|
222 | |
---|
223 | %%%%%%%%%%%%% |
---|
224 | %draw a zoom rectangle if no object creation is selected |
---|
225 | if test_zoom_draw |
---|
226 | xy_rect=AxeData.CurrentOrigin; |
---|
227 | if ~isempty(xy_rect) |
---|
228 | rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate |
---|
229 | rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate |
---|
230 | rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width |
---|
231 | rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height |
---|
232 | if rect(3)>0 & rect(4)>0 |
---|
233 | if isfield(AxeData,'CurrentRectZoom')& ishandle(AxeData.CurrentRectZoom) |
---|
234 | set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position |
---|
235 | else |
---|
236 | AxeData.CurrentRectZoom=rectangle('Position',rect,'LineStyle',':','Tag','rect_zoom'); |
---|
237 | set(haxes,'UserData',AxeData) |
---|
238 | end |
---|
239 | end |
---|
240 | end |
---|
241 | pointershape='arrow'; |
---|
242 | end |
---|
243 | |
---|
244 | %%%%%%%%%%%%%%%%% |
---|
245 | %create or modify an object |
---|
246 | |
---|
247 | if ~isempty(huvmat) && test_object |
---|
248 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
249 | huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle |
---|
250 | if ~isempty(huvmat) |
---|
251 | UvData=get(huvmat,'UserData'); |
---|
252 | if ~isfield(PlotData,'IndexObj') |
---|
253 | return |
---|
254 | end |
---|
255 | ObjectData=UvData.Object{PlotData.IndexObj}; |
---|
256 | XYData=AxeData.CurrentOrigin; |
---|
257 | if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin) |
---|
258 | if isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')|isequal(ObjectData.Style,'polygon')|isequal(ObjectData.Style,'points') |
---|
259 | xy(1,3)=0; |
---|
260 | ObjectData.Coord=[ObjectData.Coord ;xy(1,:)]; |
---|
261 | % ObjectData.Coord(end,:)=xy(1,:); |
---|
262 | elseif isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')|isequal(ObjectData.Style,'volume') |
---|
263 | ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate |
---|
264 | ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2; |
---|
265 | ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width |
---|
266 | ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height |
---|
267 | elseif isequal(ObjectData.Style,'plane') %case of 'plane' |
---|
268 | DX=(xy(1,1)-ObjectData.Coord(1,1)); |
---|
269 | DY=(xy(1,2)-ObjectData.Coord(1,2)); |
---|
270 | ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt |
---|
271 | if isfield(ObjectData,'RangeX') |
---|
272 | XMax=sqrt(DX*DX+DY*DY); |
---|
273 | if XMax>max(ObjectData.RangeX) |
---|
274 | ObjectData.RangeX=[min(ObjectData.RangeX) XMax]; |
---|
275 | end |
---|
276 | end |
---|
277 | end |
---|
278 | plot_object(ObjectData,[],AxeData.CurrentObject,'m'); |
---|
279 | pointershape='crosshair'; |
---|
280 | elseif isequal(AxeData.Drawing,'translate') |
---|
281 | DX=xy(1,1)-XYData(1);%translation from initial position |
---|
282 | DY=xy(1,2)-XYData(2); |
---|
283 | ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX; |
---|
284 | ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY; |
---|
285 | plot_object(ObjectData,[],AxeData.CurrentObject,'m'); |
---|
286 | pointershape='fleur'; |
---|
287 | elseif isequal(AxeData.Drawing,'deform') |
---|
288 | ind_move=AxeData.CurrentIndex; |
---|
289 | ObjectData.Coord(ind_move,1)=xy(1,1); |
---|
290 | ObjectData.Coord(ind_move,2)=xy(1,2); |
---|
291 | plot_object(ObjectData,[],AxeData.CurrentObject,'m'); |
---|
292 | pointershape='circle'; |
---|
293 | end |
---|
294 | end |
---|
295 | end |
---|
296 | |
---|
297 | % detect calibration points if the GUI geometry_calib is opened |
---|
298 | h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI |
---|
299 | if ~test_zoom && ~isempty(h_geometry_calib) |
---|
300 | pointershape='crosshair';%default for geometry_calib: ready to create new points |
---|
301 | hh_geometry_calib=guidata(h_geometry_calib); |
---|
302 | if ~isempty(xy) |
---|
303 | h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); |
---|
304 | Coord=get(h_ListCoord,'String'); |
---|
305 | data=read_geometry_calib(Coord);%transform char cell to numbers |
---|
306 | if size(data.Coord,2)>=5 |
---|
307 | XCoord=(data.Coord(:,4)); |
---|
308 | YCoord=(data.Coord(:,5)); |
---|
309 | xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
310 | if ~isempty(xy) |
---|
311 | xlim=get(haxes,'XLim'); |
---|
312 | ind_range_x=abs((xlim(2)-xlim(1))/50); |
---|
313 | ylim=get(haxes,'YLim'); |
---|
314 | ind_range_y=abs((ylim(2)-ylim(1))/50); |
---|
315 | ind_range=sqrt(ind_range_x*ind_range_y); |
---|
316 | index_point=find((XCoord<xy(1,1)+ind_range) & (XCoord>xy(1,1)-ind_range) & ...%flagx=1 for the vectors with x position selected by the mouse |
---|
317 | (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse |
---|
318 | if ~isempty(index_point) |
---|
319 | pointershape='arrow';% default pointer is an arrow |
---|
320 | end |
---|
321 | hh=findobj('Tag','calib_points');%look for handle of calibration points |
---|
322 | if ~isempty(hh) && ~isempty(get(hh,'UserData')) && get(hh_geometry_calib.edit_append,'Value') |
---|
323 | index_point=get(hh,'UserData'); |
---|
324 | XCoord(index_point)=xy(1,1); |
---|
325 | YCoord(index_point)=xy(1,2); |
---|
326 | set(hh,'XData',XCoord) |
---|
327 | set(hh,'YData',YCoord) |
---|
328 | end |
---|
329 | if ~isempty(index_point) |
---|
330 | set(h_ListCoord,'Value',index_point)%mrk the point on the GUI geometry_calib |
---|
331 | hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle) |
---|
332 | if ~isempty(hhh) |
---|
333 | set(hhh,'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range]) |
---|
334 | end |
---|
335 | end |
---|
336 | end |
---|
337 | end |
---|
338 | end |
---|
339 | end |
---|
340 | |
---|
341 | %draw ruler |
---|
342 | if test_ruler && isequal(AxeData.Drawing,'ruler') |
---|
343 | if isfield(UvData,'RulerHandle') |
---|
344 | pointershape='crosshair'; |
---|
345 | RulerCoord=[UvData.RulerCoord ;xy(1,1:2)]; |
---|
346 | set(UvData.RulerHandle,'XData',RulerCoord(:,1)); |
---|
347 | set(UvData.RulerHandle,'YData',RulerCoord(:,2)); |
---|
348 | end |
---|
349 | end |
---|
350 | set(currentfig,'Pointer',pointershape); |
---|