source: trunk/src/mouse_motion.m @ 60

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

-plot projections on a new specific GUI view_field, to avoid the multiplication of active figures
-introduce a ruler in uvmat (in menu/Tools), to measure distances and angles
-insert automatic detection of points for geometric calibration: tool 'detect_grid'. Four points, deliminating the grid to determine, must be marked with the mouse, as well as the physical grid. Then the points inside are automatically detected.
-reading plane positions in ImaDoc? improved to deal with volume scans

File size: 13.1 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)
26if ~exist('handles','var')
27    return
28end
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;
39test_create=0;%default
40test_edit=0;%default
41if isfield(handles,'VOLUME') % mouse_motion not applied to the uvmat figure, no object creation
42    test_create=get(handles.create,'Value');   
43end
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
91                    if length(ivec)>0
92                        if ~test_create
93                            pointershape='arrow'; %mouse indicates  the detection of a vector
94                        end
95                        ivec=ivec(1);%choice the first selected vector if several are selected
96                        mouse.X=AxeData.X(ivec);
97                        mouse.Y=AxeData.Y(ivec);
98                        u_mouse=AxeData.U(ivec);%displacement
99                        v_mouse=AxeData.V(ivec);
100                        w_mouse=0; %default
101                        if isfield(AxeData,'W')&length(AxeData.W)>=ivec
102                            w_text=[',  w=' num2str(AxeData.W(ivec),3)];
103                        else
104                            w_text='';
105                        end
106                        if ~isfield(AxeData,'CName')
107                            AxeData.CName='C';%REVOIR
108                        end
109                        c_text=[', ' AxeData.CName '=' num2str(AxeData.C(ivec),3)];
110                        if isfield(AxeData,'F')&length(AxeData.F)>=ivec
111                            f_text=[',  f=' num2str(AxeData.F(ivec),3)];
112                        else
113                            f_text='';
114                        end
115                        if isfield(AxeData,'FF')&length(AxeData.FF)>=ivec
116                            ff_text=[',  ff=' num2str(AxeData.FF(ivec),3)];
117                        else
118                            ff_text='';
119                        end
120                    end
121                end
122            end
123            if isfield(AxeData,'Z')
124                mouse.Z=AxeData.Z; %generaliser au cas avec angle
125            end
126            if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3
127                mouse.Z=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle
128            end
129            testscal= isfield(AxeData,'A')& isfield(AxeData,'AX')& isfield(AxeData,'AY');%test the existence of an image (or scalar represented by an image)
130               if testscal
131                   testscal=~isempty(AxeData.A)&~isempty(AxeData.AX)& ~isempty(AxeData.AY);
132               end
133            if testscal%test the existence of an image (or scalar represented by an image)
134                nxy=size(AxeData.A);
135                MaxAY=max(AxeData.AY(1),AxeData.AY(end));
136                MinAY=min(AxeData.AY(1),AxeData.AY(end));
137                if (xy(1,1)>AxeData.AX(1))&(xy(1,1)<AxeData.AX(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY)
138                    indx0=1+round((nxy(2)-1)*(xy(1,1)-AxeData.AX(1))/(AxeData.AX(end)-AxeData.AX(1)));% index x of pixel
139                    indy0=1+round((nxy(1)-1)*(xy(1,2)-AxeData.AY(1))/(AxeData.AY(end)-AxeData.AY(1)));% index y of pixel
140                    if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1)
141                        A_mouse=AxeData.A(indy0,indx0,:);
142                    end
143                end
144            end
145            %coordinate transform if proj_coord differs from menu_coord
146            if isfield(AxeData,'CoordType')
147                  mouse.CoordType=AxeData.CoordType;
148            end
149            if isfield(AxeData,'CoordUnit')
150                  mouse.CoordUnit=AxeData.CoordUnit;
151            end
152            if isfield(mouse,'CoordType')
153                if isequal(mouse.CoordType,'px')
154                    mouse.CoordUnit='px';
155                end
156            else
157                mouse.CoordUnit='';%default     
158            end     
159            text_displ_1=['x=' num2str(mouse.X,4) ',y=' num2str(mouse.Y,4)];
160            if isfield(mouse,'Z')&~isempty(mouse.Z)
161                text_displ_1=[text_displ_1 ',z=' num2str(mouse.Z,3)];
162            end
163            if isfield(mouse,'CoordUnit')
164                 text_displ_1=[text_displ_1 ' ' mouse.CoordUnit];
165            end
166            if ~isempty(ivec)
167                text_displ_4=['vec#=' num2str(ivec)];
168            end
169            if ~isempty(u_mouse)
170                text_displ_3=['u=' num2str(u_mouse,3) ',v=' num2str(v_mouse,3) w_text ];
171                if  isfield(mouse,'CoordUnit')
172                    if isequal(mouse.CoordUnit,'px')
173                        text_displ_3=[text_displ_3 '  ' mouse.CoordUnit];
174                    elseif isfield(AxeData,'TimeUnit')
175                        text_displ_3=[text_displ_3 '  ' mouse.CoordUnit '/' AxeData.TimeUnit];
176                    end
177                end
178                text_displ_4=[text_displ_4 c_text f_text ff_text];
179            end
180           
181            if ~isempty(A_mouse)
182                text_displ_2=['A=' num2str(double(A_mouse)) ',i='  num2str(indx0) ',j=' num2str(indy0)];
183            end
184        elseif isequal(htype,'uicontrol') && isequal(get(hchild(ichild),'Visible'),'on')&& ~isequal(get(hchild(ichild),'Style'),'frame')
185            text_displ_1=get(hchild(ichild),'Tag');
186        end
187    end
188end
189set(handles.text_display_1,'String',text_displ_1);
190set(handles.text_display_2,'String',text_displ_2);
191set(handles.text_display_3,'String',text_displ_3);
192set(handles.text_display_4,'String',text_displ_4);
193
194%%%%%%%%%%%%%%%%%
195%create or modify an object
196if isfield(AxeData,'CurrentObject') & ishandle(AxeData.CurrentObject) & isfield(AxeData,'Drawing') & ~isequal(AxeData.Drawing,'off')
197    PlotData=get(AxeData.CurrentObject,'UserData');
198    huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle
199    if ~isempty(huvmat)
200        UvData=get(huvmat,'UserData');
201        if ~isfield(PlotData,'IndexObj')
202             return
203        end
204        ObjectData=UvData.Object{PlotData.IndexObj};
205        XYData=AxeData.CurrentOrigin;
206        if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin)
207           if isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')|isequal(ObjectData.Style,'polygon')|isequal(ObjectData.Style,'points')
208              xy(1,3)=0;
209              ObjectData.Coord=[ObjectData.Coord ;xy(1,:)];
210             % ObjectData.Coord(end,:)=xy(1,:);
211           elseif isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')|isequal(ObjectData.Style,'volume')
212              ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
213              ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
214              ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
215              ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
216           elseif isequal(ObjectData.Style,'plane') %case of 'plane'
217                DX=(xy(1,1)-ObjectData.Coord(1,1));
218                DY=(xy(1,2)-ObjectData.Coord(1,2));
219                ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt
220                if isfield(ObjectData,'RangeX')
221                    XMax=sqrt(DX*DX+DY*DY);
222                    if XMax>max(ObjectData.RangeX)
223                        ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
224                    end
225                end
226           end
227            plot_object(ObjectData,[],AxeData.CurrentObject,'m');
228            pointershape='crosshair';
229        elseif  isequal(AxeData.Drawing,'translate')
230            DX=xy(1,1)-XYData(1);%translation from initial position
231            DY=xy(1,2)-XYData(2);
232            ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX;
233            ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
234            plot_object(ObjectData,[],AxeData.CurrentObject,'m');
235            pointershape='fleur';
236        elseif  isequal(AxeData.Drawing,'deform')
237            ind_move=AxeData.CurrentIndex;
238            ObjectData.Coord(ind_move,1)=xy(1,1);
239            ObjectData.Coord(ind_move,2)=xy(1,2);
240            plot_object(ObjectData,[],AxeData.CurrentObject,'m');
241            pointershape='circle';
242        end
243    end
244end   
245%%%%%%%%%%%%%
246%draw a rectangle if no object creation is selected
247if ~isempty(haxes) & isfield(AxeData,'Drawing')& isequal(AxeData.Drawing,'zoom')& isfield(AxeData,'CurrentOrigin')...
248        & isequal(get(gcf,'SelectionType'),'normal')%
249   xy_rect=AxeData.CurrentOrigin;
250   if ~isempty(xy_rect)
251        rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate
252        rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate
253        rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width
254        rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height
255        if rect(3)>0 & rect(4)>0
256            if isfield(AxeData,'CurrentRectZoom')& ishandle(AxeData.CurrentRectZoom)
257                set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position
258            else
259                AxeData.CurrentRectZoom=rectangle('Position',rect,'LineStyle',':','Tag','rect_zoom');
260                set(haxes,'UserData',AxeData)
261            end
262        end
263   end
264end
265if test_zoom
266    pointershape='arrow';
267end
268
269%draw ruler
270UvData=get(handles.uvmat,'UserData');
271if isfield(UvData,'MouseAction') && isequal(UvData.MouseAction,'ruler')
272       if isfield(UvData,'RulerHandle')
273            RulerCoord=[UvData.RulerCoord ;xy(1,1:2)];
274            set(UvData.RulerHandle,'XData',RulerCoord(:,1));
275            set(UvData.RulerHandle,'YData',RulerCoord(:,2));
276       end
277end
278set(currentfig,'Pointer',pointershape);
Note: See TracBrowser for help on using the repository browser.