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