source: trunk/src/mouse_motion.m @ 89

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

time_series: subdir for result /time_series
mouse_motio: attempt to improve the circle marking vectors: use Visible off and on.
phys: bug repair for combining two images
set_oject: bug repair for creating new object
--This line those below, will be ignored--time_series

M src/series/time_series.m
M src/mouse_motion.m
M src/transform_field/phys.m
M src/set_object.m

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