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