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 | %======================================================================= |
---|
10 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
11 | % http://www.legi.grenoble-inp.fr |
---|
12 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr |
---|
13 | % |
---|
14 | % This file is part of the toolbox UVMAT. |
---|
15 | % |
---|
16 | % UVMAT is free software; you can redistribute it and/or modify |
---|
17 | % it under the terms of the GNU General Public License as published |
---|
18 | % by the Free Software Foundation; either version 2 of the license, |
---|
19 | % or (at your option) any later version. |
---|
20 | % |
---|
21 | % UVMAT is distributed in the hope that it will be useful, |
---|
22 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
23 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
24 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
25 | %======================================================================= |
---|
26 | |
---|
27 | function mouse_motion(hObject,eventdata,handles) |
---|
28 | |
---|
29 | FigData=get(hObject,'UserData'); |
---|
30 | if ishandle(FigData)% case of a zoom plot, the handle of the parent rectangle is stored in UserData, its parent is the plotting axes of the rectangle |
---|
31 | hCurrentFig=get(get(FigData,'parent'),'parent'); |
---|
32 | else |
---|
33 | hCurrentFig=hObject;%usual plot |
---|
34 | end |
---|
35 | if strcmp(get(hCurrentFig,'Pointer'),'watch') |
---|
36 | return % no action if a calculation is running |
---|
37 | end |
---|
38 | hhCurrentFig=guidata(hCurrentFig);%handles of the elements in the GUI containing the current figure (uvmat or view_field) |
---|
39 | CheckZoom=get(hhCurrentFig.CheckZoom,'Value');% check for zoom on mode |
---|
40 | CheckZoomFig=get(hhCurrentFig.CheckZoomFig,'Value');% check for zoom sub fig creation mode |
---|
41 | hPlotAxes=hhCurrentFig.PlotAxes';% handles of the main plot axes |
---|
42 | AxeData=get(hPlotAxes,'UserData');% data attached to the axis |
---|
43 | htext_display(1)=handles.text_display; |
---|
44 | if isfield(AxeData,'htext_display')&&ishandle(AxeData.htext_display) |
---|
45 | htext_display(2)=AxeData.htext_display; |
---|
46 | end |
---|
47 | test_draw=0;%test for mouse drawing of object, =0 by default |
---|
48 | if isfield(AxeData,'Drawing')&& ~isempty(AxeData.Drawing) |
---|
49 | test_draw=~isequal(AxeData.Drawing,'off');%=1 if mouse drawing of object is active |
---|
50 | end |
---|
51 | test_zoom_draw=0; |
---|
52 | test_object=0; %test for object editing or creation |
---|
53 | test_create_object=0; |
---|
54 | test_edit_object=0;% edit test for mouse shape: an arrow |
---|
55 | test_ruler=0;%test for active ruler |
---|
56 | test_transform=0; |
---|
57 | huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle |
---|
58 | if ~isempty(huvmat) |
---|
59 | hhuvmat=guidata(huvmat);%handles of the elements in uvma |
---|
60 | test_create_object=strcmp(get(hhuvmat.MenuObject,'checked'),'on'); |
---|
61 | test_edit_object=get(hhuvmat.CheckEditObject,'Value'); |
---|
62 | test_ruler=isequal(get(hhuvmat.MenuRuler,'checked'),'on'); |
---|
63 | test_transform=~isequal(get(hhuvmat.TransformName,'Value'),1); |
---|
64 | end |
---|
65 | test_piv=0; |
---|
66 | if isfield(FigData,'CivHandle')% look for handle of the civ_input GUI |
---|
67 | if ~ishandle(FigData.CivHandle) |
---|
68 | delete(hObject) |
---|
69 | set(hCurrentFig,'Pointer','arrow'); |
---|
70 | return |
---|
71 | end |
---|
72 | hhciv=guidata(FigData.CivHandle);% list of handles in the GUI civ_input |
---|
73 | test_piv=1; |
---|
74 | end |
---|
75 | %find the current axe 'CurrentAxes' and display the current mouse position or uicontrol tag |
---|
76 | text_displ_1=''; |
---|
77 | text_displ_2=''; |
---|
78 | text_displ_3=''; |
---|
79 | text_displ_4=''; |
---|
80 | |
---|
81 | % AxeData=[];%default |
---|
82 | xy=[];%default |
---|
83 | set(hCurrentFig,'Units','normalized') |
---|
84 | xy_fig=get(hObject,'CurrentPoint');% current point of the current figure (gcbo) |
---|
85 | pointershape='arrow';% default pointer is an arrow |
---|
86 | |
---|
87 | %% loop on all the objects in the current figure, detect whether the mouse is over a plot axes |
---|
88 | hchildren=get(hObject,'Children');%handles of all objects in the current figure |
---|
89 | check_visible=strcmp(get(hchildren,'Visible'),'on');% if visible='on', =0 otherwise |
---|
90 | hchildren=hchildren(check_visible); %kkep only the visible children |
---|
91 | PosChildren=get(hchildren,'Position');% set of object positions |
---|
92 | if iscell(PosChildren)% only one child |
---|
93 | PosLength=cellfun('length',PosChildren);% set of vector lengths for object positions |
---|
94 | hchildren=hchildren(PosLength==4);% keep only objects with position defined by a 4 element vector |
---|
95 | PosChildren=cell2mat(PosChildren(PosLength==4));% convert cells to matrix of positions |
---|
96 | end |
---|
97 | if size(PosChildren,2)~=4 |
---|
98 | set(hCurrentFig,'Pointer','arrow'); |
---|
99 | return |
---|
100 | end |
---|
101 | xy_fig_mat=ones(size(PosChildren,1),1)*xy_fig;% mouse position set to a matrix |
---|
102 | check_pos=xy_fig_mat >= PosChildren(:,1:2) & xy_fig_mat <= PosChildren(:,1:2)+PosChildren(:,3:4);% compare object to mouse position |
---|
103 | ind_object=find(check_pos(:,1) & check_pos(:,2),1);% select the index of the (first) object under the mouse |
---|
104 | hchild=hchildren(ind_object);% corresponding object handle |
---|
105 | CurrentAxes=[]; |
---|
106 | |
---|
107 | %if the mouse is over an axis, look at the data |
---|
108 | htype=get(hchild,'Type'); |
---|
109 | if strcmp(htype,'axes') |
---|
110 | CurrentAxes=hchild; |
---|
111 | xy=get(CurrentAxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
112 | test_zoom_draw=test_draw && isequal(AxeData.Drawing,'zoom')&& isfield(AxeData,'CurrentOrigin') && isequal(get(gcf,'SelectionType'),'normal'); |
---|
113 | test_object=test_draw && isfield(AxeData,'CurrentObject') && ~isempty(AxeData.CurrentObject) && ishandle(AxeData.CurrentObject); |
---|
114 | if CheckZoom |
---|
115 | pointershape='zoom'; |
---|
116 | elseif CheckZoomFig |
---|
117 | pointershape='zoomfig'; |
---|
118 | elseif ~test_edit_object && ~test_ruler |
---|
119 | if CheckZoom |
---|
120 | pointershape='zoom'; |
---|
121 | elseif test_draw|| test_create_object |
---|
122 | pointershape='crosshair';%set pointer with cross shape |
---|
123 | else |
---|
124 | pointershape='crosshair';%set pointer with large cross (default when mouse is over an axis) |
---|
125 | end |
---|
126 | end |
---|
127 | FigData=get(hCurrentFig,'UserData'); % user data of the current figure |
---|
128 | tagaxes=get(CurrentAxes,'tag'); % tag name of the current axes, for instance PlotAxes |
---|
129 | if isfield(FigData,tagaxes) |
---|
130 | Field=FigData.(tagaxes); % the current field is sought as substructure of FigData with key tagaxes |
---|
131 | |
---|
132 | if isfield(Field,'ListVarName') |
---|
133 | [CellInfo,NbDimArray]=find_field_cells(Field);%analyse the physical fields contained in Field |
---|
134 | text_displ_1=''; |
---|
135 | text_displ_2=''; |
---|
136 | text_displ_3=''; |
---|
137 | text_displ_4=''; |
---|
138 | text_displ_5=''; |
---|
139 | ivec=[]; |
---|
140 | xName=''; |
---|
141 | z=[]; |
---|
142 | for icell=1:numel(CellInfo)%look for all physical fields |
---|
143 | if NbDimArray(icell)>=2 % select 2D field |
---|
144 | if isfield(Field,'CoordMesh') && ~isempty(Field.CoordMesh)&& strcmp(CellInfo{icell}.CoordType,'scattered')%case of unstructured data |
---|
145 | X=Field.(Field.ListVarName{CellInfo{icell}.CoordIndex(end)}); |
---|
146 | Y=Field.(Field.ListVarName{CellInfo{icell}.CoordIndex(end-1)}); |
---|
147 | flag_vec=(X<(xy(1,1)+Field.CoordMesh/3) & X>(xy(1,1)-Field.CoordMesh/3)) & ...%flagx=1 for the vectors with x position selected by the mouse |
---|
148 | (Y<(xy(1,2)+Field.CoordMesh/3) & Y>(xy(1,2)-Field.CoordMesh/3));%f |
---|
149 | ivec=find(flag_vec,1);% search the (first) selected vector index ivec |
---|
150 | hhh=findobj(CurrentAxes,'Tag','vector_marker'); |
---|
151 | if ~isempty(ivec) |
---|
152 | % mark the vectors with a circle in the absence of other operations |
---|
153 | if ~test_object && ~test_edit_object && ~test_ruler && ~CheckZoomFig |
---|
154 | pointershape='arrow'; %mouse indicates the detection of a vector |
---|
155 | if isempty(hhh) |
---|
156 | set(0,'CurrentFigure',hCurrentFig) |
---|
157 | set(hCurrentFig,'CurrentAxes',CurrentAxes) |
---|
158 | rectangle('Curvature',[1 1],... |
---|
159 | 'Position',[X(ivec)-Field.CoordMesh/2 Y(ivec)-Field.CoordMesh/2 Field.CoordMesh Field.CoordMesh],'EdgeColor','m',... |
---|
160 | 'LineStyle','-','Tag','vector_marker'); |
---|
161 | else |
---|
162 | set(hhh,'Visible','on') |
---|
163 | set(hhh,'Position',[X(ivec)-Field.CoordMesh/2 Y(ivec)-Field.CoordMesh/2 Field.CoordMesh Field.CoordMesh]) |
---|
164 | end |
---|
165 | end |
---|
166 | %display the field values |
---|
167 | for ivar=1:numel(CellInfo{icell}.VarIndex) |
---|
168 | VarName=Field.ListVarName{CellInfo{icell}.VarIndex(ivar)}; |
---|
169 | VarVal=Field.(VarName)(ivec); |
---|
170 | var_text=[VarName '=' num2str(VarVal,4) ',']; |
---|
171 | if isequal(ivar,CellInfo{icell}.CoordIndex(end))||isequal(ivar,CellInfo{icell}.CoordIndex(end-1))||isequal(ivar,CellInfo{icell}.CoordIndex(1)) |
---|
172 | text_displ_1=[text_displ_1 var_text]; |
---|
173 | elseif (isfield(CellInfo{icell},'VarIndex_vector_x') && isequal(ivar,CellInfo{icell}.VarIndex_vector_x))||isequal(ivar,CellInfo{icell}.VarIndex_vector_y)||... |
---|
174 | (isfield(CellInfo{icell},'VarIndex_vector_z') && isequal(ivar,CellInfo{icell}.VarIndex_vector_z)) |
---|
175 | text_displ_4=[text_displ_4 var_text]; |
---|
176 | else |
---|
177 | text_displ_5=[text_displ_5 var_text]; |
---|
178 | end |
---|
179 | end |
---|
180 | else |
---|
181 | if ~isempty(hhh) |
---|
182 | set(hhh,'Visible','off') |
---|
183 | end |
---|
184 | end |
---|
185 | elseif strcmp(CellInfo{icell}.CoordType,'grid') %structured coordinates |
---|
186 | yName=Field.ListVarName{CellInfo{icell}.CoordIndex(1)}; |
---|
187 | xName=Field.ListVarName{CellInfo{icell}.CoordIndex(2)}; |
---|
188 | y=Field.(yName); |
---|
189 | x=Field.(xName); |
---|
190 | VarName=Field.ListVarName{CellInfo{icell}.VarIndex(1)}; |
---|
191 | nxy=size(Field.(VarName)); |
---|
192 | MaxAY=max(y(1),y(end)); |
---|
193 | MinAY=min(y(1),y(end)); |
---|
194 | if (xy(1,1)>x(1))&(xy(1,1)<x(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY) |
---|
195 | indx0=1+round((nxy(2)-1)*(xy(1,1)-x(1))/(x(end)-x(1))); % index x of pixel |
---|
196 | indy0=1+round((nxy(1)-1)*(xy(1,2)-y(1))/(y(end)-y(1))); % index y of pixel |
---|
197 | if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1) |
---|
198 | text_displ_2=['i=' num2str(indx0) ',j=' num2str(indy0) ',']; |
---|
199 | for ivar=1:numel(CellInfo{icell}.VarIndex) |
---|
200 | VarName=Field.ListVarName{CellInfo{icell}.VarIndex(ivar)}; |
---|
201 | VarVal=Field.(VarName)(indy0,indx0,:); |
---|
202 | var_text=[VarName '=' num2str(VarVal) ',']; |
---|
203 | text_displ_4=[text_displ_4 var_text]; |
---|
204 | end |
---|
205 | end |
---|
206 | end |
---|
207 | end |
---|
208 | end |
---|
209 | end |
---|
210 | % display the current x,y plot coordinates in the absence of detected vector |
---|
211 | if isempty(ivec) |
---|
212 | if isempty(xName) |
---|
213 | xName='x'; |
---|
214 | yName='y'; |
---|
215 | end |
---|
216 | text_displ_1=[xName '=' num2str(xy(1,1),4) ', ' yName '=' num2str(xy(1,2),4) ',']; |
---|
217 | end |
---|
218 | %display the original phys x,y,z coordinates if defined by the projection plane |
---|
219 | if isfield(Field,'ProjObjectType') && strcmp(Field.ProjObjectType,'plane') && isfield(Field,'ProjObjectCoord') && length(Field.ProjObjectCoord)>=3 |
---|
220 | pos=[xy(1,1) xy(1,2) 0];%coordinates on the graph |
---|
221 | if isfield(Field,'ProjObjectAngle')&&~isequal(Field.ProjObjectAngle,[0 0 0]) |
---|
222 | [norm_plane(1) norm_plane(2) norm_plane(3)] =rotate_vector(Field.ProjObjectAngle*pi/180,0,0,1);%angle2normal(Field.ProjObjectAngle); |
---|
223 | pos(3)=-(norm_plane(1)*(pos(1)-Field.ProjObjectCoord(1))+norm_plane(2)*(pos(2)-Field.ProjObjectCoord(2)))/norm_plane(3); |
---|
224 | end |
---|
225 | pos(3)=pos(3)+Field.ProjObjectCoord(3); |
---|
226 | text_displ_3=[text_displ_3 'x,y,z=' num2str(pos,4)]; |
---|
227 | end |
---|
228 | % case of PIV correlation display |
---|
229 | if test_piv |
---|
230 | [dd,ind_pt]=min(abs(Field.X-xy(1,1))+abs(Field.Y-xy(1,2))); |
---|
231 | if isfield(hhciv,'TestCiv2') && strcmp(get(hhciv.Civ2,'Visible'),'on')&& ... |
---|
232 | strcmp(get(hhciv.TestCiv2,'Visible'),'on')&& get(hhciv.TestCiv2,'Value')% if TestCiv2 is activated |
---|
233 | CivOption='Civ2'; |
---|
234 | Param.CheckCiv1=0; |
---|
235 | par_civ=read_GUI(hhciv.Civ2);%read the Civ2 panel in civ_input |
---|
236 | par_civ.Civ1_SubRange=Field.Civ1_SubRange;% get the subranges used for patch |
---|
237 | par_civ.Civ1_NbCentres=Field.Civ1_NbCentres;% get the nbre of civ1 data points in each subrange |
---|
238 | par_civ.Civ1_Coord_tps=Field.Civ1_Coord_tps;% get the positions of the centres (Civ1 data) |
---|
239 | par_civ.Civ1_U_tps=Field.Civ1_U_tps;% get the tps coefficients for spline, U component |
---|
240 | par_civ.Civ1_V_tps=Field.Civ1_V_tps;% get the tps coefficients for spline, V component |
---|
241 | par_civ.Civ1_Dt=Field.Civ1_Dt; |
---|
242 | par_civ.Civ2_Dt=Field.Civ2_Dt; |
---|
243 | shiftx=Field.ShiftX(ind_pt);% get field info stored in the cuirrent figure |
---|
244 | shifty=Field.ShiftY(ind_pt); |
---|
245 | else |
---|
246 | CivOption='Civ1'; |
---|
247 | Param.CheckCiv2=0; |
---|
248 | par_civ=read_GUI(hhciv.Civ1);%read the Civ1 panel in civ_input |
---|
249 | shiftx=par_civ.SearchBoxShift(1); |
---|
250 | shifty=par_civ.SearchBoxShift(2); |
---|
251 | end |
---|
252 | xround=Field.X(ind_pt); |
---|
253 | yround=Field.Y(ind_pt); |
---|
254 | |
---|
255 | % mark the correlation box with a rectangle in view_field |
---|
256 | ibx2=floor((par_civ.CorrBoxSize(1)-1)/2); |
---|
257 | iby2=floor((par_civ.CorrBoxSize(2)-1)/2); |
---|
258 | isx2=floor((par_civ.SearchBoxSize(1)-1)/2); |
---|
259 | isy2=floor((par_civ.SearchBoxSize(2)-1)/2); |
---|
260 | hhh=findobj(CurrentAxes,'Tag','PIV_box_marker'); |
---|
261 | hhhh=findobj(CurrentAxes,'Tag','PIV_search_marker'); |
---|
262 | if isempty(hhh) |
---|
263 | set(0,'CurrentFigure',hCurrentFig) |
---|
264 | set(hCurrentFig,'CurrentAxes',CurrentAxes) |
---|
265 | rectangle('Curvature',[0 0],... |
---|
266 | 'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2],'EdgeColor','m',... |
---|
267 | 'LineStyle','-','Tag','PIV_box_marker'); |
---|
268 | rectangle('Curvature',[0 0],... |
---|
269 | 'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2],'EdgeColor','m',... |
---|
270 | 'LineStyle','- -','Tag','PIV_search_marker'); |
---|
271 | else |
---|
272 | set(hhh,'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2]) |
---|
273 | set(hhhh,'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2]) |
---|
274 | end |
---|
275 | |
---|
276 | % perform the PIV calculation as the single point xround yround |
---|
277 | Param.CheckFix1=0; |
---|
278 | Param.CheckPatch1=0;%desactivate all calculations except Civ2 or Civ1 |
---|
279 | Param.Action.RUN=1; |
---|
280 | Param.ActionInput.ListCompareMode='PIV'; |
---|
281 | Param.ActionInput.PairIndices=read_GUI(hhciv.PairIndices); |
---|
282 | par_civ.ImageA=Field.A; |
---|
283 | par_civ.ImageB=Field.B; |
---|
284 | par_civ.ImageHeight=size(par_civ.ImageA,1); |
---|
285 | par_civ.ImageWidth=size(par_civ.ImageA,2); |
---|
286 | par_civ.Grid=[xround yround];% PIV calculation with a single point |
---|
287 | Param.ActionInput.(CivOption)=par_civ; |
---|
288 | [Data,errormsg,result_conv]= civ_series(Param); |
---|
289 | if ~isempty(errormsg) |
---|
290 | text_displ_5=errormsg; |
---|
291 | else |
---|
292 | rangx(1)=-(isx2-ibx2)+shiftx; |
---|
293 | rangx(2)=isx2-ibx2+shiftx; |
---|
294 | rangy(1)=-(isy2-iby2)-shifty; |
---|
295 | rangy(2)=(isy2-iby2)-shifty; |
---|
296 | hcorr=[]; |
---|
297 | if isfield(AxeData,'CurrentCorrImage') |
---|
298 | hcorr=AxeData.CurrentCorrImage; |
---|
299 | if ~ishandle(hcorr) |
---|
300 | hcorr=[]; |
---|
301 | end |
---|
302 | end |
---|
303 | if isempty(hcorr) |
---|
304 | corrfig=findobj(allchild(0),'tag','corrfig'); |
---|
305 | if ~isempty(corrfig) |
---|
306 | set(0,'CurrentFigure',corrfig(1)) |
---|
307 | AxeData.CurrentCorrImage=imagesc(rangx,-rangy,result_conv,[0 1]);% plot the correlation map, with full colormap from 0 to 1 |
---|
308 | AxeData.CurrentVector=line([0 Data.([CivOption '_U'])],[0 Data.([CivOption '_V'])],'Tag','vector'); |
---|
309 | AxeData.TitleHandle=title(['[x,y]= ' num2str(par_civ.Grid) ' px']); |
---|
310 | colorbar |
---|
311 | set(CurrentAxes,'UserData',AxeData) |
---|
312 | ParentAxe=get(AxeData.CurrentCorrImage,'parent'); |
---|
313 | set(ParentAxe,'YDir','normal') |
---|
314 | set(ParentAxe,'DataAspectRatio',[1 1 1]); %equal axis scale |
---|
315 | end |
---|
316 | else |
---|
317 | set(AxeData.CurrentCorrImage,'CData',result_conv) |
---|
318 | set(AxeData.CurrentCorrImage,'XData',rangx) |
---|
319 | set(AxeData.CurrentCorrImage,'YData',-rangy) |
---|
320 | ParentAxe=get(AxeData.CurrentCorrImage,'parent'); |
---|
321 | rangx(1)=min(rangx(1),0); |
---|
322 | rangx(2)=max(rangx(2),0); |
---|
323 | rangy(2)=max(rangy(2),0); |
---|
324 | rangy(1)=min(rangy(1),0); |
---|
325 | set(ParentAxe,'XLim',rangx) |
---|
326 | set(ParentAxe,'YLim',[-rangy(2) -rangy(1)]) |
---|
327 | set(AxeData.CurrentVector,'XData',[0 Data.([CivOption '_U'])],'YData',[0 Data.([CivOption '_V'])]); |
---|
328 | set(AxeData.TitleHandle,'String',['[x,y]= ' num2str(par_civ.Grid) ' px']) |
---|
329 | end |
---|
330 | end |
---|
331 | end |
---|
332 | end |
---|
333 | end |
---|
334 | end |
---|
335 | if ~isempty(text_displ_1) |
---|
336 | text_displ=[{text_displ_1};{text_displ_2};{text_displ_3};{text_displ_4};{text_displ_5}]; |
---|
337 | ind_blank=find(strcmp('',text_displ)); |
---|
338 | if ~isempty(ind_blank) |
---|
339 | text_displ(ind_blank)=[]; |
---|
340 | end |
---|
341 | set(htext_display,'String',text_displ) |
---|
342 | else |
---|
343 | set(htext_display,'String',get(handles.text_display,'UserData')) |
---|
344 | end |
---|
345 | |
---|
346 | %%%%%%%%%%%%% |
---|
347 | %% draw a zoom rectangle if checkZoomFig has been selected |
---|
348 | if test_zoom_draw |
---|
349 | xy_rect=AxeData.CurrentOrigin;% mark the previous position from mouse down |
---|
350 | if ~isempty(xy_rect) |
---|
351 | rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate |
---|
352 | rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate |
---|
353 | rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width |
---|
354 | rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height |
---|
355 | if rect(3)>0 && rect(4)>0 |
---|
356 | if isfield(AxeData,'CurrentRectZoom')&& ~isempty(AxeData.CurrentRectZoom) && ishandle(AxeData.CurrentRectZoom) |
---|
357 | set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position |
---|
358 | else |
---|
359 | AxeData.CurrentRectZoom=rectangle('Position',rect,'Tag','rect_zoom','EdgeColor','b'); |
---|
360 | set(CurrentAxes,'UserData',AxeData) |
---|
361 | end |
---|
362 | end |
---|
363 | end |
---|
364 | end |
---|
365 | |
---|
366 | %%%%%%%%%%%%%%%%% |
---|
367 | %% create or modify an object |
---|
368 | if strcmp(htype,'axes') && ~isempty(huvmat) && test_object |
---|
369 | UvData=get(huvmat,'UserData'); |
---|
370 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
371 | if ~isfield(PlotData,'IndexObj') |
---|
372 | set(hCurrentFig,'Pointer','arrow'); |
---|
373 | return |
---|
374 | end |
---|
375 | if numel(UvData.ProjObject)<PlotData.IndexObj |
---|
376 | return |
---|
377 | end |
---|
378 | ObjectData=UvData.ProjObject{PlotData.IndexObj}; |
---|
379 | if isequal(hObject,huvmat)% if the mouse ifs over the GUI uvmat |
---|
380 | if numel(UvData.ProjObject)<get(hhuvmat.ListObject_1,'Value') |
---|
381 | return |
---|
382 | end |
---|
383 | ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')}; |
---|
384 | else |
---|
385 | if numel(UvData.ProjObject)<get(hhuvmat.ListObject,'Value') |
---|
386 | return |
---|
387 | end |
---|
388 | ProjObject=UvData.ProjObject{get(hhuvmat.ListObject,'Value')}; |
---|
389 | end |
---|
390 | XYData=AxeData.CurrentOrigin; |
---|
391 | |
---|
392 | if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin) |
---|
393 | switch ObjectData.Type |
---|
394 | case {'line','polyline','polygon','points'} |
---|
395 | ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)]; |
---|
396 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
397 | case {'rectangle','ellipse','volume'} |
---|
398 | ObjectData.Coord=(AxeData.CurrentOrigin+xy(1,1:2))/2;% keep only the first point coordinate |
---|
399 | ObjectData.RangeX=abs(ObjectData.Coord(1,1)-xy(1,1));%rectangle width |
---|
400 | ObjectData.RangeY=abs(ObjectData.Coord(1,2)-xy(1,2));%rectangle height |
---|
401 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
402 | case 'plane' %case of 'plane' |
---|
403 | DX=(xy(1,1)-ObjectData.Coord(1,1)); |
---|
404 | DY=(xy(1,2)-ObjectData.Coord(1,2)); |
---|
405 | ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt |
---|
406 | if isfield(ObjectData,'RangeX') |
---|
407 | XMax=sqrt(DX*DX+DY*DY); |
---|
408 | if XMax>max(ObjectData.RangeX) |
---|
409 | ObjectData.RangeX=[min(ObjectData.RangeX) XMax]; |
---|
410 | end |
---|
411 | end |
---|
412 | hline=findobj(hPlotAxes,'Tag','mouse_line'); |
---|
413 | if isempty(hline) |
---|
414 | hline=line([AxeData.CurrentOrigin(1) xy(1,1)],[AxeData.CurrentOrigin(2) xy(1,2)],'Tag','mouse_line'); |
---|
415 | else |
---|
416 | set(hline,'XData',[AxeData.CurrentOrigin(1) xy(1,1)]) |
---|
417 | set(hline,'YData',[AxeData.CurrentOrigin(2) xy(1,2)]) |
---|
418 | end |
---|
419 | end |
---|
420 | |
---|
421 | pointershape='crosshair'; |
---|
422 | elseif test_edit_object && isequal(AxeData.Drawing,'translate') |
---|
423 | DX=xy(1,1)-XYData(1);%translation from initial position |
---|
424 | DY=xy(1,2)-XYData(2); |
---|
425 | ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX; |
---|
426 | ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY; |
---|
427 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
428 | pointershape='fleur'; |
---|
429 | elseif test_edit_object && isequal(AxeData.Drawing,'deform') |
---|
430 | ind_move=AxeData.CurrentIndex; |
---|
431 | ObjectData.Coord(ind_move,1)=xy(1,1); |
---|
432 | ObjectData.Coord(ind_move,2)=xy(1,2); |
---|
433 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
434 | pointershape='circle'; |
---|
435 | end |
---|
436 | end |
---|
437 | |
---|
438 | %% detect calibration points if the GUI geometry_calib is opened |
---|
439 | h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI |
---|
440 | if strcmp(htype,'axes') && ~CheckZoom && ~isempty(h_geometry_calib) |
---|
441 | pointershape='crosshair';%default for geometry_calib: ready to create new points |
---|
442 | hh_geometry_calib=guidata(h_geometry_calib); |
---|
443 | if ~isempty(xy) && isfield(hh_geometry_calib,'ListCoord') |
---|
444 | h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); |
---|
445 | data.Coord=get(h_ListCoord,'Data'); |
---|
446 | if isnumeric(data.Coord)&&~isempty(data.Coord) |
---|
447 | if test_transform |
---|
448 | XCoord=(data.Coord(:,1)); |
---|
449 | YCoord=(data.Coord(:,2)); |
---|
450 | else |
---|
451 | XCoord=(data.Coord(:,4)); |
---|
452 | YCoord=(data.Coord(:,5)); |
---|
453 | end |
---|
454 | xy=get(CurrentAxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
455 | if ~isempty(xy) |
---|
456 | xlim=get(CurrentAxes,'XLim'); |
---|
457 | % ind_range_x=abs((xlim(2)-xlim(1))/50); |
---|
458 | ylim=get(CurrentAxes,'YLim'); |
---|
459 | ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/25;%defines the size of the circle marker |
---|
460 | % ind_range_y=abs((ylim(2)-ylim(1))/50); |
---|
461 | % ind_range=sqrt(ind_range_x*ind_range_y); |
---|
462 | index_point=find((XCoord<xy(1,1)+ind_range/2) & (XCoord>xy(1,1)-ind_range/2) & ...%flagx=1 for the vectors with x position selected by the mouse |
---|
463 | (YCoord<xy(1,2)+ind_range/2) & (YCoord>xy(1,2)-ind_range/2),1);%find the first calibration point in the neighborhood of the mouse |
---|
464 | if ~isempty(index_point) |
---|
465 | pointershape='arrow';% default pointer is an arrow |
---|
466 | end |
---|
467 | hh=findobj('Tag','calib_points');%look for handle of calibration points |
---|
468 | if ~isempty(hh) && ~isempty(get(hh,'UserData')) %&& get(hh_geometry_calib.CheckEnableMouse,'Value') |
---|
469 | %set(hh,'UserData',index_point) |
---|
470 | index_point=get(hh,'UserData'); |
---|
471 | XCoord(index_point)=xy(1,1); |
---|
472 | YCoord(index_point)=xy(1,2); |
---|
473 | set(hh,'XData',XCoord) |
---|
474 | set(hh,'YData',YCoord) |
---|
475 | end |
---|
476 | if ~isempty(index_point) |
---|
477 | set(hh_geometry_calib.CoordLine,'String',num2str(index_point)) |
---|
478 | % Data=get(h_ListCoord,'Data'); |
---|
479 | % Data(:,6)=zeros(size(Data,1),1); |
---|
480 | % Data(index_point,6)=-1;%mrk the point on the GUI geometry_calib |
---|
481 | % set(h_ListCoord,'Data',Data); |
---|
482 | hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle) |
---|
483 | if ~isempty(hhh) |
---|
484 | set(hhh,'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range]) |
---|
485 | else |
---|
486 | axes(hchild) |
---|
487 | rectangle('Curvature',[1 1],... |
---|
488 | 'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range],'EdgeColor','m',... |
---|
489 | 'LineStyle','-','Tag','calib_marker'); |
---|
490 | end |
---|
491 | end |
---|
492 | end |
---|
493 | end |
---|
494 | end |
---|
495 | end |
---|
496 | |
---|
497 | %% draw ruler |
---|
498 | if test_ruler && isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'ruler') |
---|
499 | if isfield(AxeData,'RulerHandle') && ~isempty(findobj(AxeData.RulerHandle)) && size(xy,2)>=2 |
---|
500 | pointershape='crosshair'; %give the mouse pointer a cross shape |
---|
501 | RulerCoord=[AxeData.RulerCoord ;xy(1,1:2)]; %coordinates defining the ruler segment |
---|
502 | set(AxeData.RulerHandle,'XData',RulerCoord(:,1));% updtate the x coordinates for the ruler graphic object |
---|
503 | set(AxeData.RulerHandle,'YData',RulerCoord(:,2));% updtate the y coordinates for the ruler graphic object |
---|
504 | end |
---|
505 | end |
---|
506 | |
---|
507 | %% update the mouse pointer |
---|
508 | if strcmp(pointershape,'zoom')||strcmp(pointershape,'zoomfig') |
---|
509 | CData=set_pointershape(pointershape); |
---|
510 | set(hCurrentFig,'Pointer','custom','PointerShapeCData',CData,'PointerShapeHotSpot',[9 9]) |
---|
511 | else |
---|
512 | set(hCurrentFig,'Pointer',pointershape); |
---|
513 | end |
---|
514 | |
---|
515 | function CData=set_pointershape(pointershape) |
---|
516 | CData=ones(16,16); |
---|
517 | [ind_x,ind_y]=meshgrid([1:16],[1:16]); |
---|
518 | if strcmp(pointershape,'zoom') |
---|
519 | radius=(ind_x-9).*(ind_x-9)+(ind_y-8.5).*(ind_y-9); |
---|
520 | CData(radius<25 & radius>16)=2; %make white circle |
---|
521 | CData(radius<16 | radius>40)=NaN; %make the centre transparent |
---|
522 | CData(16,16)=1; CData(15,16)=2; |
---|
523 | CData(15,15)=1; CData(14,15)=2; |
---|
524 | CData(14,14)=1; CData(13,14)=2; |
---|
525 | CData(13,13)=1; CData(12,13)=2; |
---|
526 | elseif strcmp(pointershape,'zoomfig') |
---|
527 | CData(:,1:3)=2; |
---|
528 | CData(:,14:16)=2; |
---|
529 | CData(1:3,:)=2; |
---|
530 | CData(14:16,:)=2; |
---|
531 | CData(CData==1)=NaN; |
---|
532 | end |
---|