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 | FigData=get(hObject,'UserData'); |
---|
28 | 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 |
---|
29 | hCurrentFig=get(get(FigData,'parent'),'parent'); |
---|
30 | else |
---|
31 | hCurrentFig=hObject;%usual plot |
---|
32 | end |
---|
33 | if strcmp(get(hCurrentFig,'Pointer'),'watch') |
---|
34 | return % no action if a calculation is running |
---|
35 | end |
---|
36 | hhCurrentFig=guidata(hCurrentFig);%handles of the elements in the GUI containing the current figure (uvmat or view_field) |
---|
37 | CheckZoom=get(hhCurrentFig.CheckZoom,'Value');% check for zoom on mode |
---|
38 | CheckZoomFig=get(hhCurrentFig.CheckZoomFig,'Value');% check for zoom sub fig creation mode |
---|
39 | hPlotAxes=hhCurrentFig.PlotAxes';% handles of the main plot axes |
---|
40 | AxeData=get(hPlotAxes,'UserData');% data attached to the axis |
---|
41 | htext_display(1)=handles.text_display; |
---|
42 | if isfield(AxeData,'htext_display')&&ishandle(AxeData.htext_display) |
---|
43 | htext_display(2)=AxeData.htext_display; |
---|
44 | end |
---|
45 | test_draw=0;%test for mouse drawing of object, =0 by default |
---|
46 | if isfield(AxeData,'Drawing')&& ~isempty(AxeData.Drawing) |
---|
47 | test_draw=~isequal(AxeData.Drawing,'off');%=1 if mouse drawing of object is active |
---|
48 | end |
---|
49 | test_zoom_draw=0; |
---|
50 | test_object=0; %test for object editing or creation |
---|
51 | test_create_object=0; |
---|
52 | test_edit_object=0;% edit test for mouse shape: an arrow |
---|
53 | test_ruler=0;%test for active ruler |
---|
54 | test_transform=0; |
---|
55 | huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle |
---|
56 | if ~isempty(huvmat) |
---|
57 | hhuvmat=guidata(huvmat);%handles of the elements in uvma |
---|
58 | test_create_object=strcmp(get(hhuvmat.MenuObject,'checked'),'on'); |
---|
59 | test_edit_object=get(hhuvmat.CheckEditObject,'Value'); |
---|
60 | test_ruler=isequal(get(hhuvmat.MenuRuler,'checked'),'on'); |
---|
61 | test_transform=~isequal(get(hhuvmat.TransformName,'Value'),1); |
---|
62 | end |
---|
63 | test_piv=0; |
---|
64 | if isfield(FigData,'CivHandle') |
---|
65 | if ~ishandle(FigData.CivHandle) |
---|
66 | delete(hObject) |
---|
67 | set(hCurrentFig,'Pointer','arrow'); |
---|
68 | return |
---|
69 | end |
---|
70 | hhciv=guidata(FigData.CivHandle); |
---|
71 | test_piv=1; |
---|
72 | end |
---|
73 | |
---|
74 | %find the current axe 'CurrentAxes' and display the current mouse position or uicontrol tag |
---|
75 | text_displ_1=''; |
---|
76 | text_displ_2=''; |
---|
77 | text_displ_3=''; |
---|
78 | text_displ_4=''; |
---|
79 | |
---|
80 | % AxeData=[];%default |
---|
81 | xy=[];%default |
---|
82 | set(hCurrentFig,'Units','normalized') |
---|
83 | xy_fig=get(hObject,'CurrentPoint');% current point of the current figure (gcbo) |
---|
84 | pointershape='arrow';% default pointer is an arrow |
---|
85 | |
---|
86 | %% loop on all the objects in the current figure, detect whether the mouse is over a plot axes |
---|
87 | hchildren=get(hObject,'Children');%handles of all objects in the current figure |
---|
88 | check_visible=strcmp(get(hchildren,'Visible'),'on');% if visible='on', =0 otherwise |
---|
89 | hchildren=hchildren(check_visible); %kkep only the visible children |
---|
90 | PosChildren=get(hchildren,'Position');% set of object positions |
---|
91 | if iscell(PosChildren)% only one child |
---|
92 | PosLength=cellfun('length',PosChildren);% set of vector lengths for object positions |
---|
93 | hchildren=hchildren(PosLength==4);% keep only objects with position defined by a 4 element vector |
---|
94 | PosChildren=cell2mat(PosChildren(PosLength==4));% convert cells to matrix of positions |
---|
95 | end |
---|
96 | if size(PosChildren,2)~=4 |
---|
97 | set(hCurrentFig,'Pointer','arrow'); |
---|
98 | return |
---|
99 | end |
---|
100 | xy_fig_mat=ones(size(PosChildren,1),1)*xy_fig;% mouse position set to a matrix |
---|
101 | check_pos=xy_fig_mat >= PosChildren(:,1:2) & xy_fig_mat <= PosChildren(:,1:2)+PosChildren(:,3:4);% compare object to mouse position |
---|
102 | ind_object=find(check_pos(:,1) & check_pos(:,2),1);% select the index of the (first) object under the mouse |
---|
103 | hchild=hchildren(ind_object);% corresponding object handle |
---|
104 | CurrentAxes=[]; |
---|
105 | |
---|
106 | %if the mouse is over an axis, look at the data |
---|
107 | htype=get(hchild,'Type'); |
---|
108 | if strcmp(htype,'axes') |
---|
109 | CurrentAxes=hchild; |
---|
110 | xy=get(CurrentAxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
111 | test_zoom_draw=test_draw && isequal(AxeData.Drawing,'zoom')&& isfield(AxeData,'CurrentOrigin') && isequal(get(gcf,'SelectionType'),'normal'); |
---|
112 | test_object=test_draw && isfield(AxeData,'CurrentObject') && ~isempty(AxeData.CurrentObject) && ishandle(AxeData.CurrentObject); |
---|
113 | if CheckZoom |
---|
114 | pointershape='zoom'; |
---|
115 | elseif CheckZoomFig |
---|
116 | pointershape='zoomfig'; |
---|
117 | elseif ~test_edit_object && ~test_ruler |
---|
118 | if CheckZoom |
---|
119 | pointershape='zoom'; |
---|
120 | elseif test_draw|| test_create_object |
---|
121 | pointershape='crosshair';%set pointer with cross shape |
---|
122 | else |
---|
123 | pointershape='fullcross';%set pointer with large cross (default when mouse is over an axis) |
---|
124 | end |
---|
125 | end |
---|
126 | FigData=get(hCurrentFig,'UserData'); |
---|
127 | tagaxes=get(CurrentAxes,'tag'); |
---|
128 | if isfield(FigData,tagaxes) |
---|
129 | Field=FigData.(tagaxes); |
---|
130 | if isfield(Field,'ListVarName') |
---|
131 | [CellInfo,NbDimArray]=find_field_cells(Field);%analyse the physical fields contained in Field |
---|
132 | text_displ_1=''; |
---|
133 | text_displ_2=''; |
---|
134 | text_displ_3=''; |
---|
135 | text_displ_4=''; |
---|
136 | text_displ_5=''; |
---|
137 | ivec=[]; |
---|
138 | xName=''; |
---|
139 | z=[]; |
---|
140 | for icell=1:numel(CellInfo)%look for all physical fields |
---|
141 | if NbDimArray(icell)>=2 % select 2D field |
---|
142 | if isfield(Field,'CoordMesh') && ~isempty(Field.CoordMesh)&& strcmp(CellInfo{icell}.CoordType,'scattered')%case of unstructured data |
---|
143 | X=Field.(Field.ListVarName{CellInfo{icell}.CoordIndex(end)}); |
---|
144 | Y=Field.(Field.ListVarName{CellInfo{icell}.CoordIndex(end-1)}); |
---|
145 | 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 |
---|
146 | (Y<(xy(1,2)+Field.CoordMesh/3) & Y>(xy(1,2)-Field.CoordMesh/3));%f |
---|
147 | ivec=find(flag_vec,1);% search the (first) selected vector index ivec |
---|
148 | hhh=findobj(CurrentAxes,'Tag','vector_marker'); |
---|
149 | if ~isempty(ivec) |
---|
150 | % mark the vectors with a circle in the absence of other operations |
---|
151 | if ~test_object && ~test_edit_object && ~test_ruler && ~CheckZoomFig |
---|
152 | pointershape='arrow'; %mouse indicates the detection of a vector |
---|
153 | if isempty(hhh) |
---|
154 | set(0,'CurrentFigure',hCurrentFig) |
---|
155 | set(hCurrentFig,'CurrentAxes',CurrentAxes) |
---|
156 | rectangle('Curvature',[1 1],... |
---|
157 | 'Position',[X(ivec)-Field.CoordMesh/2 Y(ivec)-Field.CoordMesh/2 Field.CoordMesh Field.CoordMesh],'EdgeColor','m',... |
---|
158 | 'LineStyle','-','Tag','vector_marker'); |
---|
159 | else |
---|
160 | set(hhh,'Visible','on') |
---|
161 | set(hhh,'Position',[X(ivec)-Field.CoordMesh/2 Y(ivec)-Field.CoordMesh/2 Field.CoordMesh Field.CoordMesh]) |
---|
162 | end |
---|
163 | end |
---|
164 | %display the field values |
---|
165 | for ivar=1:numel(CellInfo{icell}.VarIndex) |
---|
166 | VarName=Field.ListVarName{CellInfo{icell}.VarIndex(ivar)}; |
---|
167 | VarVal=Field.(VarName)(ivec); |
---|
168 | var_text=[VarName '=' num2str(VarVal,4) ',']; |
---|
169 | if isequal(ivar,CellInfo{icell}.CoordIndex(end))||isequal(ivar,CellInfo{icell}.CoordIndex(end-1))||isequal(ivar,CellInfo{icell}.CoordIndex(1)) |
---|
170 | text_displ_1=[text_displ_1 var_text]; |
---|
171 | elseif (isfield(CellInfo{icell},'VarIndex_vector_x') && isequal(ivar,CellInfo{icell}.VarIndex_vector_x))||isequal(ivar,CellInfo{icell}.VarIndex_vector_y)||... |
---|
172 | (isfield(CellInfo{icell},'VarIndex_vector_z') && isequal(ivar,CellInfo{icell}.VarIndex_vector_z)) |
---|
173 | text_displ_4=[text_displ_4 var_text]; |
---|
174 | else |
---|
175 | text_displ_5=[text_displ_5 var_text]; |
---|
176 | end |
---|
177 | end |
---|
178 | else |
---|
179 | if ~isempty(hhh) |
---|
180 | set(hhh,'Visible','off') |
---|
181 | end |
---|
182 | end |
---|
183 | elseif strcmp(CellInfo{icell}.CoordType,'grid') %structured coordinates |
---|
184 | yName=Field.ListVarName{CellInfo{icell}.CoordIndex(1)}; |
---|
185 | xName=Field.ListVarName{CellInfo{icell}.CoordIndex(2)}; |
---|
186 | y=Field.(yName); |
---|
187 | x=Field.(xName); |
---|
188 | VarName=Field.ListVarName{CellInfo{icell}.VarIndex(1)}; |
---|
189 | nxy=size(Field.(VarName)); |
---|
190 | MaxAY=max(y(1),y(end)); |
---|
191 | MinAY=min(y(1),y(end)); |
---|
192 | if (xy(1,1)>x(1))&(xy(1,1)<x(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY) |
---|
193 | indx0=1+round((nxy(2)-1)*(xy(1,1)-x(1))/(x(end)-x(1))); % index x of pixel |
---|
194 | indy0=1+round((nxy(1)-1)*(xy(1,2)-y(1))/(y(end)-y(1))); % index y of pixel |
---|
195 | if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1) |
---|
196 | text_displ_2=['i=' num2str(indx0) ',j=' num2str(indy0) ',']; |
---|
197 | for ivar=1:numel(CellInfo{icell}.VarIndex) |
---|
198 | VarName=Field.ListVarName{CellInfo{icell}.VarIndex(ivar)}; |
---|
199 | VarVal=Field.(VarName)(indy0,indx0,:); |
---|
200 | var_text=[VarName '=' num2str(VarVal) ',']; |
---|
201 | text_displ_4=[text_displ_4 var_text]; |
---|
202 | end |
---|
203 | end |
---|
204 | end |
---|
205 | end |
---|
206 | end |
---|
207 | end |
---|
208 | % display the current x,y plot coordinates in the absence of detected vector |
---|
209 | if isempty(ivec) |
---|
210 | if isempty(xName) |
---|
211 | xName='x'; |
---|
212 | yName='y'; |
---|
213 | end |
---|
214 | text_displ_1=[xName '=' num2str(xy(1,1),4) ', ' yName '=' num2str(xy(1,2),4) ',']; |
---|
215 | end |
---|
216 | %display the z coordinate if defined by the projection plane |
---|
217 | if isfield(Field,'ProjObjectType') && strcmp(Field.ProjObjectType,'plane') && isfield(Field,'ProjObjectCoord') && length(Field.ProjObjectCoord)>=3 |
---|
218 | pos=[xy(1,1) xy(1,2) 0]; |
---|
219 | if isfield(Field,'ProjObjectAngle')&&~isequal(Field.ProjObjectAngle,[0 0 0]) |
---|
220 | om=norm(Field.ProjObjectAngle);%norm of rotation angle in radians |
---|
221 | OmAxis=Field.ProjObjectAngle/om; %unit vector marking the rotation axis |
---|
222 | cos_om=cos(pi*om/180); |
---|
223 | sin_om=sin(pi*om/180); |
---|
224 | pos=[xy(1,1) xy(1,2) 0]; |
---|
225 | pos=cos_om*pos+sin_om*cross(OmAxis,pos)+(1-cos_om)*(OmAxis*pos')*OmAxis; |
---|
226 | end |
---|
227 | % pos=pos+[Field.ProjObjectCoord 0]; |
---|
228 | pos=pos+Field.ProjObjectCoord; |
---|
229 | text_displ_3=[text_displ_3 'x,y,z=' num2str(pos,4)]; |
---|
230 | end |
---|
231 | % if ~isempty(z) |
---|
232 | % text_displ_1=[text_displ_1 ' z=' num2str(z,4)]; |
---|
233 | % end |
---|
234 | % case of PIV correlation display |
---|
235 | if test_piv |
---|
236 | par=read_GUI(hhciv.Civ1); |
---|
237 | [dd,ind_pt]=min(abs(Field.X-xy(1,1))+abs(Field.Y-xy(1,2))); |
---|
238 | xround=Field.X(ind_pt); |
---|
239 | yround=Field.Y(ind_pt); |
---|
240 | % par.Grid=[xround size(Field.A,1)-yround+1]; |
---|
241 | par.Grid=[xround yround]; |
---|
242 | % mark the correlation box with a rectangle |
---|
243 | par.ImageA=Field.A; |
---|
244 | par.ImageB=Field.B; |
---|
245 | par.ImageHeight=size(par.ImageA,1); |
---|
246 | par.ImageWidth=size(par.ImageA,2); |
---|
247 | Param.Civ1=par; |
---|
248 | ibx2=floor((par.CorrBoxSize(1)-1)/2); |
---|
249 | iby2=floor((par.CorrBoxSize(2)-1)/2); |
---|
250 | isx2=floor((par.SearchBoxSize(1)-1)/2); |
---|
251 | isy2=floor((par.SearchBoxSize(2)-1)/2); |
---|
252 | shiftx=par.SearchBoxShift(1); |
---|
253 | shifty=par.SearchBoxShift(2); |
---|
254 | hhh=findobj(CurrentAxes,'Tag','PIV_box_marker'); |
---|
255 | hhhh=findobj(CurrentAxes,'Tag','PIV_search_marker'); |
---|
256 | if isempty(hhh) |
---|
257 | set(0,'CurrentFigure',hCurrentFig) |
---|
258 | set(hCurrentFig,'CurrentAxes',CurrentAxes) |
---|
259 | rectangle('Curvature',[0 0],... |
---|
260 | 'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2],'EdgeColor','m',... |
---|
261 | 'LineStyle','-','Tag','PIV_box_marker'); |
---|
262 | rectangle('Curvature',[0 0],... |
---|
263 | 'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2],'EdgeColor','m',... |
---|
264 | 'LineStyle','- -','Tag','PIV_search_marker'); |
---|
265 | else |
---|
266 | set(hhh,'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2]) |
---|
267 | set(hhhh,'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2]) |
---|
268 | end |
---|
269 | [Data,errormsg,result_conv]= civ_matlab(Param); |
---|
270 | if ~isempty(errormsg) |
---|
271 | text_displ_5=errormsg; |
---|
272 | else |
---|
273 | rangx(1)=-(isx2-ibx2)+shiftx; |
---|
274 | rangx(2)=isx2-ibx2+shiftx; |
---|
275 | rangy(1)=-(isy2-iby2)-shifty; |
---|
276 | rangy(2)=(isy2-iby2)-shifty; |
---|
277 | hcorr=[]; |
---|
278 | if isfield(AxeData,'CurrentCorrImage') |
---|
279 | hcorr=AxeData.CurrentCorrImage; |
---|
280 | if ~ishandle(hcorr) |
---|
281 | hcorr=[]; |
---|
282 | end |
---|
283 | end |
---|
284 | if isempty(hcorr) |
---|
285 | corrfig=findobj(allchild(0),'tag','corrfig'); |
---|
286 | if ~isempty(corrfig) |
---|
287 | set(0,'CurrentFigure',corrfig(1)) |
---|
288 | AxeData.CurrentCorrImage=imagesc(rangx,-rangy,result_conv,[0 1]); |
---|
289 | AxeData.CurrentVector=line([0 Data.Civ1_U],[0 Data.Civ1_V],'Tag','vector'); |
---|
290 | AxeData.TitleHandle=title(num2str(par.Grid)); |
---|
291 | colorbar |
---|
292 | set(CurrentAxes,'UserData',AxeData) |
---|
293 | set(get(AxeData.CurrentCorrImage,'parent'),'YDir','normal') |
---|
294 | end |
---|
295 | else |
---|
296 | set(AxeData.CurrentCorrImage,'CData',result_conv) |
---|
297 | set(AxeData.CurrentCorrImage,'XData',rangx) |
---|
298 | set(AxeData.CurrentCorrImage,'YData',-rangy) |
---|
299 | set(AxeData.CurrentVector,'XData',[0 Data.Civ1_U],'YData',[0 Data.Civ1_V]) |
---|
300 | set(AxeData.TitleHandle,'String',num2str(par.Grid)) |
---|
301 | end |
---|
302 | end |
---|
303 | end |
---|
304 | end |
---|
305 | end |
---|
306 | end |
---|
307 | if ~isempty(text_displ_1) |
---|
308 | text_displ=[{text_displ_1};{text_displ_2};{text_displ_3};{text_displ_4};{text_displ_5}]; |
---|
309 | ind_blank=find(strcmp('',text_displ)); |
---|
310 | if ~isempty(ind_blank) |
---|
311 | text_displ(ind_blank)=[]; |
---|
312 | end |
---|
313 | %set(handles.text_display,'String',text_displ) |
---|
314 | set(htext_display,'String',text_displ) |
---|
315 | else |
---|
316 | %set(handles.text_display,'String',get(handles.text_display,'UserData')) |
---|
317 | set(htext_display,'String',get(handles.text_display,'UserData')) |
---|
318 | end |
---|
319 | |
---|
320 | %%%%%%%%%%%%% |
---|
321 | %% draw a zoom rectangle if checkZoomFig has been selected |
---|
322 | if test_zoom_draw |
---|
323 | xy_rect=AxeData.CurrentOrigin;% mark the previous position from mouse down |
---|
324 | if ~isempty(xy_rect) |
---|
325 | rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate |
---|
326 | rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate |
---|
327 | rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width |
---|
328 | rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height |
---|
329 | if rect(3)>0 && rect(4)>0 |
---|
330 | if isfield(AxeData,'CurrentRectZoom')&& ~isempty(AxeData.CurrentRectZoom) && ishandle(AxeData.CurrentRectZoom) |
---|
331 | set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position |
---|
332 | else |
---|
333 | AxeData.CurrentRectZoom=rectangle('Position',rect,'Tag','rect_zoom','EdgeColor','b'); |
---|
334 | set(CurrentAxes,'UserData',AxeData) |
---|
335 | end |
---|
336 | end |
---|
337 | end |
---|
338 | end |
---|
339 | |
---|
340 | %%%%%%%%%%%%%%%%% |
---|
341 | %% create or modify an object |
---|
342 | if strcmp(htype,'axes') && ~isempty(huvmat) && test_object |
---|
343 | UvData=get(huvmat,'UserData'); |
---|
344 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
345 | if ~isfield(PlotData,'IndexObj') |
---|
346 | set(hCurrentFig,'Pointer','arrow'); |
---|
347 | return |
---|
348 | end |
---|
349 | ObjectData=UvData.ProjObject{PlotData.IndexObj}; |
---|
350 | if isequal(hObject,huvmat)% if the mouse ifs over the GUI uvmat |
---|
351 | ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')}; |
---|
352 | else |
---|
353 | ProjObject=UvData.ProjObject{get(hhuvmat.ListObject,'Value')}; |
---|
354 | end |
---|
355 | XYData=AxeData.CurrentOrigin; |
---|
356 | if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin) |
---|
357 | if strcmp(ObjectData.Type,'line')||strcmp(ObjectData.Type,'polyline')||strcmp(ObjectData.Type,'polygon')||strcmp(ObjectData.Type,'points') |
---|
358 | ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)]; |
---|
359 | % ObjectData.Coord(end,:)=xy(1,:); |
---|
360 | elseif strcmp(ObjectData.Type,'rectangle')||strcmp(ObjectData.Type,'ellipse')||strcmp(ObjectData.Type,'volume') |
---|
361 | ObjectData.Coord=(AxeData.CurrentOrigin+xy(1,1:2))/2;% keep only the first point coordinate |
---|
362 | ObjectData.RangeX=abs(ObjectData.Coord(1,1)-xy(1,1));%rectangle width |
---|
363 | ObjectData.RangeY=abs(ObjectData.Coord(1,2)-xy(1,2));%rectangle height |
---|
364 | elseif isequal(ObjectData.Type,'plane') %case of 'plane' |
---|
365 | DX=(xy(1,1)-ObjectData.Coord(1,1)); |
---|
366 | DY=(xy(1,2)-ObjectData.Coord(1,2)); |
---|
367 | ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt |
---|
368 | if isfield(ObjectData,'RangeX') |
---|
369 | XMax=sqrt(DX*DX+DY*DY); |
---|
370 | if XMax>max(ObjectData.RangeX) |
---|
371 | ObjectData.RangeX=[min(ObjectData.RangeX) XMax]; |
---|
372 | end |
---|
373 | end |
---|
374 | end |
---|
375 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
376 | pointershape='crosshair'; |
---|
377 | elseif test_edit_object && isequal(AxeData.Drawing,'translate') |
---|
378 | DX=xy(1,1)-XYData(1);%translation from initial position |
---|
379 | DY=xy(1,2)-XYData(2); |
---|
380 | ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX; |
---|
381 | ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY; |
---|
382 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
383 | pointershape='fleur'; |
---|
384 | elseif test_edit_object && isequal(AxeData.Drawing,'deform') |
---|
385 | ind_move=AxeData.CurrentIndex; |
---|
386 | ObjectData.Coord(ind_move,1)=xy(1,1); |
---|
387 | ObjectData.Coord(ind_move,2)=xy(1,2); |
---|
388 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
389 | pointershape='circle'; |
---|
390 | end |
---|
391 | end |
---|
392 | |
---|
393 | %% detect calibration points if the GUI geometry_calib is opened |
---|
394 | h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI |
---|
395 | if strcmp(htype,'axes') && ~CheckZoom && ~isempty(h_geometry_calib) |
---|
396 | pointershape='crosshair';%default for geometry_calib: ready to create new points |
---|
397 | hh_geometry_calib=guidata(h_geometry_calib); |
---|
398 | if ~isempty(xy) && isfield(hh_geometry_calib,'ListCoord') |
---|
399 | h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); |
---|
400 | data.Coord=get(h_ListCoord,'Data'); |
---|
401 | if isnumeric(data.Coord)&&~isempty(data.Coord) |
---|
402 | if test_transform |
---|
403 | XCoord=(data.Coord(:,1)); |
---|
404 | YCoord=(data.Coord(:,2)); |
---|
405 | else |
---|
406 | XCoord=(data.Coord(:,4)); |
---|
407 | YCoord=(data.Coord(:,5)); |
---|
408 | end |
---|
409 | xy=get(CurrentAxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
410 | if ~isempty(xy) |
---|
411 | xlim=get(CurrentAxes,'XLim'); |
---|
412 | % ind_range_x=abs((xlim(2)-xlim(1))/50); |
---|
413 | ylim=get(CurrentAxes,'YLim'); |
---|
414 | ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/25;%defines the size of the circle marker |
---|
415 | % ind_range_y=abs((ylim(2)-ylim(1))/50); |
---|
416 | % ind_range=sqrt(ind_range_x*ind_range_y); |
---|
417 | 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 |
---|
418 | (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 |
---|
419 | if ~isempty(index_point) |
---|
420 | pointershape='arrow';% default pointer is an arrow |
---|
421 | end |
---|
422 | hh=findobj('Tag','calib_points');%look for handle of calibration points |
---|
423 | if ~isempty(hh) && ~isempty(get(hh,'UserData')) %&& get(hh_geometry_calib.CheckEnableMouse,'Value') |
---|
424 | %set(hh,'UserData',index_point) |
---|
425 | index_point=get(hh,'UserData'); |
---|
426 | XCoord(index_point)=xy(1,1); |
---|
427 | YCoord(index_point)=xy(1,2); |
---|
428 | set(hh,'XData',XCoord) |
---|
429 | set(hh,'YData',YCoord) |
---|
430 | end |
---|
431 | if ~isempty(index_point) |
---|
432 | set(hh_geometry_calib.CoordLine,'String',num2str(index_point)) |
---|
433 | % Data=get(h_ListCoord,'Data'); |
---|
434 | % Data(:,6)=zeros(size(Data,1),1); |
---|
435 | % Data(index_point,6)=-1;%mrk the point on the GUI geometry_calib |
---|
436 | % set(h_ListCoord,'Data',Data); |
---|
437 | hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle) |
---|
438 | if ~isempty(hhh) |
---|
439 | set(hhh,'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range]) |
---|
440 | else |
---|
441 | rectangle('Curvature',[1 1],... |
---|
442 | 'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range],'EdgeColor','m',... |
---|
443 | 'LineStyle','-','Tag','calib_marker'); |
---|
444 | end |
---|
445 | end |
---|
446 | end |
---|
447 | end |
---|
448 | end |
---|
449 | end |
---|
450 | |
---|
451 | %% draw ruler |
---|
452 | if test_ruler && isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'ruler') |
---|
453 | if isfield(AxeData,'RulerHandle') |
---|
454 | pointershape='crosshair'; %give the mouse pointer a cross shape |
---|
455 | RulerCoord=[AxeData.RulerCoord ;xy(1,1:2)]; %coordinates defining the ruler segment |
---|
456 | set(AxeData.RulerHandle,'XData',RulerCoord(:,1));% updtate the x coordinates for the ruler graphic object |
---|
457 | set(AxeData.RulerHandle,'YData',RulerCoord(:,2));% updtate the y coordinates for the ruler graphic object |
---|
458 | end |
---|
459 | end |
---|
460 | |
---|
461 | %% update the mouse pointer |
---|
462 | if strcmp(pointershape,'zoom')||strcmp(pointershape,'zoomfig') |
---|
463 | CData=set_pointershape(pointershape); |
---|
464 | set(hCurrentFig,'Pointer','custom','PointerShapeCData',CData,'PointerShapeHotSpot',[9 9]) |
---|
465 | else |
---|
466 | set(hCurrentFig,'Pointer',pointershape); |
---|
467 | end |
---|
468 | |
---|
469 | function CData=set_pointershape(pointershape) |
---|
470 | CData=ones(16,16); |
---|
471 | [ind_x,ind_y]=meshgrid([1:16],[1:16]); |
---|
472 | if strcmp(pointershape,'zoom') |
---|
473 | radius=(ind_x-9).*(ind_x-9)+(ind_y-8.5).*(ind_y-9); |
---|
474 | CData(radius<25 & radius>16)=2; %make white circle |
---|
475 | CData(radius<16 | radius>40)=NaN; %make the centre transparent |
---|
476 | CData(16,16)=1; CData(15,16)=2; |
---|
477 | CData(15,15)=1; CData(14,15)=2; |
---|
478 | CData(14,14)=1; CData(13,14)=2; |
---|
479 | CData(13,13)=1; CData(12,13)=2; |
---|
480 | elseif strcmp(pointershape,'zoomfig') |
---|
481 | CData(:,1:3)=2; |
---|
482 | CData(:,14:16)=2; |
---|
483 | CData(1:3,:)=2; |
---|
484 | CData(14:16,:)=2; |
---|
485 | CData(CData==1)=NaN; |
---|
486 | end |
---|