[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 | %======================================================================= |
---|
| 10 | % Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France |
---|
| 11 | % http://www.legi.grenoble-inp.fr |
---|
| 12 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.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) |
---|
[622] | 39 | CheckZoom=get(hhCurrentFig.CheckZoom,'Value');% check for zoom on mode |
---|
| 40 | CheckZoomFig=get(hhCurrentFig.CheckZoomFig,'Value');% check for zoom sub fig creation mode |
---|
[625] | 41 | hPlotAxes=hhCurrentFig.PlotAxes';% handles of the main plot axes |
---|
| 42 | AxeData=get(hPlotAxes,'UserData');% data attached to the axis |
---|
[627] | 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 |
---|
[625] | 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 |
---|
[622] | 51 | test_zoom_draw=0; |
---|
[150] | 52 | test_object=0; %test for object editing or creation |
---|
[701] | 53 | test_create_object=0; |
---|
[681] | 54 | test_edit_object=0;% edit test for mouse shape: an arrow |
---|
[150] | 55 | test_ruler=0;%test for active ruler |
---|
[663] | 56 | test_transform=0; |
---|
[150] | 57 | huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle |
---|
[71] | 58 | if ~isempty(huvmat) |
---|
[432] | 59 | hhuvmat=guidata(huvmat);%handles of the elements in uvma |
---|
[701] | 60 | test_create_object=strcmp(get(hhuvmat.MenuObject,'checked'),'on'); |
---|
[650] | 61 | test_edit_object=get(hhuvmat.CheckEditObject,'Value'); |
---|
[156] | 62 | test_ruler=isequal(get(hhuvmat.MenuRuler,'checked'),'on'); |
---|
[664] | 63 | test_transform=~isequal(get(hhuvmat.TransformName,'Value'),1); |
---|
[150] | 64 | end |
---|
[231] | 65 | test_piv=0; |
---|
[856] | 66 | if isfield(FigData,'CivHandle')% look for handle of the civ_input GUI |
---|
[231] | 67 | if ~ishandle(FigData.CivHandle) |
---|
| 68 | delete(hObject) |
---|
[682] | 69 | set(hCurrentFig,'Pointer','arrow'); |
---|
[231] | 70 | return |
---|
| 71 | end |
---|
[856] | 72 | hhciv=guidata(FigData.CivHandle);% list of handles in the GUI civ_input |
---|
[231] | 73 | test_piv=1; |
---|
[150] | 74 | end |
---|
[11] | 75 | |
---|
[432] | 76 | %find the current axe 'CurrentAxes' and display the current mouse position or uicontrol tag |
---|
[11] | 77 | text_displ_1=''; |
---|
| 78 | text_displ_2=''; |
---|
| 79 | text_displ_3=''; |
---|
| 80 | text_displ_4=''; |
---|
| 81 | |
---|
[625] | 82 | % AxeData=[];%default |
---|
[67] | 83 | xy=[];%default |
---|
[741] | 84 | set(hCurrentFig,'Units','normalized') |
---|
[622] | 85 | xy_fig=get(hObject,'CurrentPoint');% current point of the current figure (gcbo) |
---|
[11] | 86 | pointershape='arrow';% default pointer is an arrow |
---|
[150] | 87 | |
---|
[432] | 88 | %% loop on all the objects in the current figure, detect whether the mouse is over a plot axes |
---|
[622] | 89 | hchildren=get(hObject,'Children');%handles of all objects in the current figure |
---|
| 90 | check_visible=strcmp(get(hchildren,'Visible'),'on');% if visible='on', =0 otherwise |
---|
| 91 | hchildren=hchildren(check_visible); %kkep only the visible children |
---|
| 92 | PosChildren=get(hchildren,'Position');% set of object positions |
---|
| 93 | if iscell(PosChildren)% only one child |
---|
| 94 | PosLength=cellfun('length',PosChildren);% set of vector lengths for object positions |
---|
| 95 | hchildren=hchildren(PosLength==4);% keep only objects with position defined by a 4 element vector |
---|
| 96 | PosChildren=cell2mat(PosChildren(PosLength==4));% convert cells to matrix of positions |
---|
| 97 | end |
---|
| 98 | if size(PosChildren,2)~=4 |
---|
[682] | 99 | set(hCurrentFig,'Pointer','arrow'); |
---|
[622] | 100 | return |
---|
| 101 | end |
---|
| 102 | xy_fig_mat=ones(size(PosChildren,1),1)*xy_fig;% mouse position set to a matrix |
---|
| 103 | check_pos=xy_fig_mat >= PosChildren(:,1:2) & xy_fig_mat <= PosChildren(:,1:2)+PosChildren(:,3:4);% compare object to mouse position |
---|
| 104 | ind_object=find(check_pos(:,1) & check_pos(:,2),1);% select the index of the (first) object under the mouse |
---|
| 105 | hchild=hchildren(ind_object);% corresponding object handle |
---|
[432] | 106 | CurrentAxes=[]; |
---|
[622] | 107 | |
---|
| 108 | %if the mouse is over an axis, look at the data |
---|
[682] | 109 | htype=get(hchild,'Type'); |
---|
| 110 | if strcmp(htype,'axes') |
---|
[622] | 111 | CurrentAxes=hchild; |
---|
| 112 | xy=get(CurrentAxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
| 113 | test_zoom_draw=test_draw && isequal(AxeData.Drawing,'zoom')&& isfield(AxeData,'CurrentOrigin') && isequal(get(gcf,'SelectionType'),'normal'); |
---|
| 114 | test_object=test_draw && isfield(AxeData,'CurrentObject') && ~isempty(AxeData.CurrentObject) && ishandle(AxeData.CurrentObject); |
---|
[701] | 115 | if CheckZoom |
---|
| 116 | pointershape='zoom'; |
---|
| 117 | elseif CheckZoomFig |
---|
| 118 | pointershape='zoomfig'; |
---|
| 119 | elseif ~test_edit_object && ~test_ruler |
---|
[699] | 120 | if CheckZoom |
---|
| 121 | pointershape='zoom'; |
---|
[701] | 122 | elseif test_draw|| test_create_object |
---|
| 123 | pointershape='crosshair';%set pointer with cross shape |
---|
[699] | 124 | else |
---|
[701] | 125 | pointershape='fullcross';%set pointer with large cross (default when mouse is over an axis) |
---|
[699] | 126 | end |
---|
[622] | 127 | end |
---|
[625] | 128 | FigData=get(hCurrentFig,'UserData'); |
---|
[622] | 129 | tagaxes=get(CurrentAxes,'tag'); |
---|
| 130 | if isfield(FigData,tagaxes) |
---|
| 131 | Field=FigData.(tagaxes); |
---|
| 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) |
---|
[625] | 156 | set(0,'CurrentFigure',hCurrentFig) |
---|
| 157 | set(hCurrentFig,'CurrentAxes',CurrentAxes) |
---|
[622] | 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'); |
---|
[251] | 161 | else |
---|
[622] | 162 | set(hhh,'Visible','on') |
---|
| 163 | set(hhh,'Position',[X(ivec)-Field.CoordMesh/2 Y(ivec)-Field.CoordMesh/2 Field.CoordMesh Field.CoordMesh]) |
---|
[251] | 164 | end |
---|
[622] | 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]; |
---|
[105] | 178 | end |
---|
[61] | 179 | end |
---|
[622] | 180 | else |
---|
| 181 | if ~isempty(hhh) |
---|
| 182 | set(hhh,'Visible','off') |
---|
| 183 | end |
---|
[71] | 184 | end |
---|
[622] | 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 |
---|
[251] | 206 | end |
---|
| 207 | end |
---|
[622] | 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 z coordinate if defined by the projection plane |
---|
[741] | 219 | if isfield(Field,'ProjObjectType') && strcmp(Field.ProjObjectType,'plane') && isfield(Field,'ProjObjectCoord') && length(Field.ProjObjectCoord)>=3 |
---|
[622] | 220 | pos=[xy(1,1) xy(1,2) 0]; |
---|
[741] | 221 | if isfield(Field,'ProjObjectAngle')&&~isequal(Field.ProjObjectAngle,[0 0 0]) |
---|
| 222 | om=norm(Field.ProjObjectAngle);%norm of rotation angle in radians |
---|
| 223 | OmAxis=Field.ProjObjectAngle/om; %unit vector marking the rotation axis |
---|
[622] | 224 | cos_om=cos(pi*om/180); |
---|
| 225 | sin_om=sin(pi*om/180); |
---|
| 226 | pos=[xy(1,1) xy(1,2) 0]; |
---|
| 227 | pos=cos_om*pos+sin_om*cross(OmAxis,pos)+(1-cos_om)*(OmAxis*pos')*OmAxis; |
---|
| 228 | end |
---|
[741] | 229 | % pos=pos+[Field.ProjObjectCoord 0]; |
---|
| 230 | pos=pos+Field.ProjObjectCoord; |
---|
[622] | 231 | text_displ_3=[text_displ_3 'x,y,z=' num2str(pos,4)]; |
---|
| 232 | end |
---|
| 233 | % if ~isempty(z) |
---|
| 234 | % text_displ_1=[text_displ_1 ' z=' num2str(z,4)]; |
---|
| 235 | % end |
---|
| 236 | % case of PIV correlation display |
---|
| 237 | if test_piv |
---|
[856] | 238 | [dd,ind_pt]=min(abs(Field.X-xy(1,1))+abs(Field.Y-xy(1,2))); |
---|
| 239 | if (isfield(hhciv,'TestCiv2')&& get(hhciv.TestCiv2,'Value'))% if TestCiv2 is activated |
---|
| 240 | CivOption='Civ2'; |
---|
| 241 | Param.CheckCiv1=0; |
---|
| 242 | par_civ=read_GUI(hhciv.Civ2);%read the Civ2 panel in civ_input |
---|
| 243 | par_civ.Civ1_SubRange=Field.Civ1_SubRange; |
---|
| 244 | par_civ.Civ1_NbCentres=Field.Civ1_NbCentres; |
---|
| 245 | par_civ.Civ1_Coord_tps=Field.Civ1_Coord_tps; |
---|
| 246 | par_civ.Civ1_U_tps=Field.Civ1_U_tps; |
---|
| 247 | par_civ.Civ1_V_tps=Field.Civ1_V_tps; |
---|
| 248 | par_civ.Civ1_Dt=Field.Civ1_Dt; |
---|
[858] | 249 | par_civ.Civ2_Dt=Field.Civ2_Dt; |
---|
[856] | 250 | shiftx=Field.ShiftX(ind_pt); |
---|
| 251 | shifty=Field.ShiftY(ind_pt); |
---|
| 252 | else |
---|
| 253 | CivOption='Civ1'; |
---|
| 254 | Param.CheckCiv2=0; |
---|
| 255 | par_civ=read_GUI(hhciv.Civ1);%read the Civ1 panel in civ_input |
---|
| 256 | shiftx=par_civ.SearchBoxShift(1); |
---|
| 257 | shifty=par_civ.SearchBoxShift(2); |
---|
| 258 | end |
---|
[622] | 259 | xround=Field.X(ind_pt); |
---|
| 260 | yround=Field.Y(ind_pt); |
---|
[856] | 261 | |
---|
[622] | 262 | % mark the correlation box with a rectangle |
---|
[856] | 263 | ibx2=floor((par_civ.CorrBoxSize(1)-1)/2); |
---|
| 264 | iby2=floor((par_civ.CorrBoxSize(2)-1)/2); |
---|
| 265 | isx2=floor((par_civ.SearchBoxSize(1)-1)/2); |
---|
| 266 | isy2=floor((par_civ.SearchBoxSize(2)-1)/2); |
---|
[622] | 267 | hhh=findobj(CurrentAxes,'Tag','PIV_box_marker'); |
---|
| 268 | hhhh=findobj(CurrentAxes,'Tag','PIV_search_marker'); |
---|
| 269 | if isempty(hhh) |
---|
[625] | 270 | set(0,'CurrentFigure',hCurrentFig) |
---|
| 271 | set(hCurrentFig,'CurrentAxes',CurrentAxes) |
---|
[622] | 272 | rectangle('Curvature',[0 0],... |
---|
| 273 | 'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2],'EdgeColor','m',... |
---|
| 274 | 'LineStyle','-','Tag','PIV_box_marker'); |
---|
| 275 | rectangle('Curvature',[0 0],... |
---|
| 276 | 'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2],'EdgeColor','m',... |
---|
| 277 | 'LineStyle','- -','Tag','PIV_search_marker'); |
---|
| 278 | else |
---|
| 279 | set(hhh,'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2]) |
---|
| 280 | set(hhhh,'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2]) |
---|
| 281 | end |
---|
[856] | 282 | |
---|
| 283 | % perform the PIV calculation as the single point xround yround |
---|
| 284 | Param.CheckFix1=0; |
---|
| 285 | Param.CheckPatch1=0;%desactivate all calculations except Civ2 or Civ1 |
---|
[855] | 286 | Param.Action.RUN=1; |
---|
| 287 | Param.ActionInput.ListCompareMode='PIV'; |
---|
[856] | 288 | par_civ.ImageA=Field.A; |
---|
| 289 | par_civ.ImageB=Field.B; |
---|
| 290 | par_civ.ImageHeight=size(par_civ.ImageA,1); |
---|
| 291 | par_civ.ImageWidth=size(par_civ.ImageA,2); |
---|
| 292 | par_civ.Grid=[xround yround];% PIV calculation with a single point |
---|
[858] | 293 | Param.ActionInput.(CivOption)=par_civ; |
---|
[855] | 294 | [Data,errormsg,result_conv]= civ_series(Param); |
---|
[622] | 295 | if ~isempty(errormsg) |
---|
| 296 | text_displ_5=errormsg; |
---|
| 297 | else |
---|
| 298 | rangx(1)=-(isx2-ibx2)+shiftx; |
---|
| 299 | rangx(2)=isx2-ibx2+shiftx; |
---|
| 300 | rangy(1)=-(isy2-iby2)-shifty; |
---|
| 301 | rangy(2)=(isy2-iby2)-shifty; |
---|
| 302 | hcorr=[]; |
---|
| 303 | if isfield(AxeData,'CurrentCorrImage') |
---|
| 304 | hcorr=AxeData.CurrentCorrImage; |
---|
| 305 | if ~ishandle(hcorr) |
---|
| 306 | hcorr=[]; |
---|
[207] | 307 | end |
---|
[11] | 308 | end |
---|
[622] | 309 | if isempty(hcorr) |
---|
| 310 | corrfig=findobj(allchild(0),'tag','corrfig'); |
---|
| 311 | if ~isempty(corrfig) |
---|
| 312 | set(0,'CurrentFigure',corrfig(1)) |
---|
| 313 | AxeData.CurrentCorrImage=imagesc(rangx,-rangy,result_conv,[0 1]); |
---|
[858] | 314 | AxeData.CurrentVector=line([0 Data.([CivOption '_U'])],[0 Data.([CivOption '_V'])],'Tag','vector'); |
---|
| 315 | AxeData.TitleHandle=title(num2str(par_civ.Grid)); |
---|
[622] | 316 | colorbar |
---|
| 317 | set(CurrentAxes,'UserData',AxeData) |
---|
| 318 | set(get(AxeData.CurrentCorrImage,'parent'),'YDir','normal') |
---|
[150] | 319 | end |
---|
[622] | 320 | else |
---|
| 321 | set(AxeData.CurrentCorrImage,'CData',result_conv) |
---|
| 322 | set(AxeData.CurrentCorrImage,'XData',rangx) |
---|
| 323 | set(AxeData.CurrentCorrImage,'YData',-rangy) |
---|
[858] | 324 | set(AxeData.CurrentVector,'XData',[0 Data.([CivOption '_U'])],'YData',[0 Data.([CivOption '_V'])]); |
---|
| 325 | set(AxeData.TitleHandle,'String',num2str(par_civ.Grid)) |
---|
[11] | 326 | end |
---|
| 327 | end |
---|
[251] | 328 | end |
---|
[11] | 329 | end |
---|
| 330 | end |
---|
| 331 | end |
---|
[292] | 332 | if ~isempty(text_displ_1) |
---|
[542] | 333 | text_displ=[{text_displ_1};{text_displ_2};{text_displ_3};{text_displ_4};{text_displ_5}]; |
---|
| 334 | ind_blank=find(strcmp('',text_displ)); |
---|
| 335 | if ~isempty(ind_blank) |
---|
| 336 | text_displ(ind_blank)=[]; |
---|
| 337 | end |
---|
[627] | 338 | %set(handles.text_display,'String',text_displ) |
---|
| 339 | set(htext_display,'String',text_displ) |
---|
[292] | 340 | else |
---|
[627] | 341 | %set(handles.text_display,'String',get(handles.text_display,'UserData')) |
---|
| 342 | set(htext_display,'String',get(handles.text_display,'UserData')) |
---|
[292] | 343 | end |
---|
[11] | 344 | |
---|
[71] | 345 | %%%%%%%%%%%%% |
---|
[622] | 346 | %% draw a zoom rectangle if checkZoomFig has been selected |
---|
[71] | 347 | if test_zoom_draw |
---|
[622] | 348 | xy_rect=AxeData.CurrentOrigin;% mark the previous position from mouse down |
---|
[71] | 349 | if ~isempty(xy_rect) |
---|
| 350 | rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate |
---|
| 351 | rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate |
---|
| 352 | rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width |
---|
| 353 | rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height |
---|
[622] | 354 | if rect(3)>0 && rect(4)>0 |
---|
| 355 | if isfield(AxeData,'CurrentRectZoom')&& ~isempty(AxeData.CurrentRectZoom) && ishandle(AxeData.CurrentRectZoom) |
---|
[71] | 356 | set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position |
---|
| 357 | else |
---|
[622] | 358 | AxeData.CurrentRectZoom=rectangle('Position',rect,'Tag','rect_zoom','EdgeColor','b'); |
---|
[432] | 359 | set(CurrentAxes,'UserData',AxeData) |
---|
[71] | 360 | end |
---|
| 361 | end |
---|
| 362 | end |
---|
| 363 | end |
---|
| 364 | |
---|
[11] | 365 | %%%%%%%%%%%%%%%%% |
---|
[150] | 366 | %% create or modify an object |
---|
[682] | 367 | if strcmp(htype,'axes') && ~isempty(huvmat) && test_object |
---|
[432] | 368 | UvData=get(huvmat,'UserData'); |
---|
[11] | 369 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
[432] | 370 | if ~isfield(PlotData,'IndexObj') |
---|
[682] | 371 | set(hCurrentFig,'Pointer','arrow'); |
---|
[432] | 372 | return |
---|
| 373 | end |
---|
[622] | 374 | ObjectData=UvData.ProjObject{PlotData.IndexObj}; |
---|
[432] | 375 | if isequal(hObject,huvmat)% if the mouse ifs over the GUI uvmat |
---|
[622] | 376 | ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')}; |
---|
[432] | 377 | else |
---|
[622] | 378 | ProjObject=UvData.ProjObject{get(hhuvmat.ListObject,'Value')}; |
---|
[432] | 379 | end |
---|
| 380 | XYData=AxeData.CurrentOrigin; |
---|
| 381 | if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin) |
---|
| 382 | if strcmp(ObjectData.Type,'line')||strcmp(ObjectData.Type,'polyline')||strcmp(ObjectData.Type,'polygon')||strcmp(ObjectData.Type,'points') |
---|
| 383 | ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)]; |
---|
| 384 | % ObjectData.Coord(end,:)=xy(1,:); |
---|
| 385 | elseif strcmp(ObjectData.Type,'rectangle')||strcmp(ObjectData.Type,'ellipse')||strcmp(ObjectData.Type,'volume') |
---|
[622] | 386 | ObjectData.Coord=(AxeData.CurrentOrigin+xy(1,1:2))/2;% keep only the first point coordinate |
---|
| 387 | ObjectData.RangeX=abs(ObjectData.Coord(1,1)-xy(1,1));%rectangle width |
---|
| 388 | ObjectData.RangeY=abs(ObjectData.Coord(1,2)-xy(1,2));%rectangle height |
---|
[432] | 389 | elseif isequal(ObjectData.Type,'plane') %case of 'plane' |
---|
| 390 | DX=(xy(1,1)-ObjectData.Coord(1,1)); |
---|
| 391 | DY=(xy(1,2)-ObjectData.Coord(1,2)); |
---|
| 392 | ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt |
---|
| 393 | if isfield(ObjectData,'RangeX') |
---|
| 394 | XMax=sqrt(DX*DX+DY*DY); |
---|
| 395 | if XMax>max(ObjectData.RangeX) |
---|
| 396 | ObjectData.RangeX=[min(ObjectData.RangeX) XMax]; |
---|
[11] | 397 | end |
---|
[432] | 398 | end |
---|
[11] | 399 | end |
---|
[432] | 400 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
| 401 | pointershape='crosshair'; |
---|
[681] | 402 | elseif test_edit_object && isequal(AxeData.Drawing,'translate') |
---|
[432] | 403 | DX=xy(1,1)-XYData(1);%translation from initial position |
---|
| 404 | DY=xy(1,2)-XYData(2); |
---|
| 405 | ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX; |
---|
| 406 | ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY; |
---|
| 407 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
| 408 | pointershape='fleur'; |
---|
[681] | 409 | elseif test_edit_object && isequal(AxeData.Drawing,'deform') |
---|
[432] | 410 | ind_move=AxeData.CurrentIndex; |
---|
| 411 | ObjectData.Coord(ind_move,1)=xy(1,1); |
---|
| 412 | ObjectData.Coord(ind_move,2)=xy(1,2); |
---|
| 413 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
| 414 | pointershape='circle'; |
---|
[11] | 415 | end |
---|
[432] | 416 | end |
---|
[67] | 417 | |
---|
[150] | 418 | %% detect calibration points if the GUI geometry_calib is opened |
---|
[67] | 419 | h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI |
---|
[682] | 420 | if strcmp(htype,'axes') && ~CheckZoom && ~isempty(h_geometry_calib) |
---|
[67] | 421 | pointershape='crosshair';%default for geometry_calib: ready to create new points |
---|
| 422 | hh_geometry_calib=guidata(h_geometry_calib); |
---|
[156] | 423 | if ~isempty(xy) && isfield(hh_geometry_calib,'ListCoord') |
---|
[67] | 424 | h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); |
---|
[657] | 425 | data.Coord=get(h_ListCoord,'Data'); |
---|
| 426 | if isnumeric(data.Coord)&&~isempty(data.Coord) |
---|
[663] | 427 | if test_transform |
---|
[738] | 428 | XCoord=(data.Coord(:,1)); |
---|
| 429 | YCoord=(data.Coord(:,2)); |
---|
[663] | 430 | else |
---|
[738] | 431 | XCoord=(data.Coord(:,4)); |
---|
| 432 | YCoord=(data.Coord(:,5)); |
---|
[663] | 433 | end |
---|
[432] | 434 | xy=get(CurrentAxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
[67] | 435 | if ~isempty(xy) |
---|
[432] | 436 | xlim=get(CurrentAxes,'XLim'); |
---|
[738] | 437 | % ind_range_x=abs((xlim(2)-xlim(1))/50); |
---|
[432] | 438 | ylim=get(CurrentAxes,'YLim'); |
---|
[738] | 439 | ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/25;%defines the size of the circle marker |
---|
| 440 | % ind_range_y=abs((ylim(2)-ylim(1))/50); |
---|
| 441 | % ind_range=sqrt(ind_range_x*ind_range_y); |
---|
| 442 | 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 |
---|
| 443 | (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] | 444 | if ~isempty(index_point) |
---|
[738] | 445 | pointershape='arrow';% default pointer is an arrow |
---|
[78] | 446 | end |
---|
| 447 | hh=findobj('Tag','calib_points');%look for handle of calibration points |
---|
[738] | 448 | if ~isempty(hh) && ~isempty(get(hh,'UserData')) %&& get(hh_geometry_calib.CheckEnableMouse,'Value') |
---|
| 449 | %set(hh,'UserData',index_point) |
---|
[173] | 450 | index_point=get(hh,'UserData'); |
---|
[78] | 451 | XCoord(index_point)=xy(1,1); |
---|
| 452 | YCoord(index_point)=xy(1,2); |
---|
| 453 | set(hh,'XData',XCoord) |
---|
| 454 | set(hh,'YData',YCoord) |
---|
[738] | 455 | end |
---|
[78] | 456 | if ~isempty(index_point) |
---|
[738] | 457 | set(hh_geometry_calib.CoordLine,'String',num2str(index_point)) |
---|
| 458 | % Data=get(h_ListCoord,'Data'); |
---|
| 459 | % Data(:,6)=zeros(size(Data,1),1); |
---|
| 460 | % Data(index_point,6)=-1;%mrk the point on the GUI geometry_calib |
---|
| 461 | % set(h_ListCoord,'Data',Data); |
---|
[67] | 462 | hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle) |
---|
| 463 | if ~isempty(hhh) |
---|
[71] | 464 | set(hhh,'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range]) |
---|
[657] | 465 | else |
---|
[837] | 466 | axes(hchild) |
---|
[738] | 467 | rectangle('Curvature',[1 1],... |
---|
| 468 | 'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range],'EdgeColor','m',... |
---|
| 469 | 'LineStyle','-','Tag','calib_marker'); |
---|
[67] | 470 | end |
---|
[78] | 471 | end |
---|
[67] | 472 | end |
---|
| 473 | end |
---|
| 474 | end |
---|
| 475 | end |
---|
| 476 | |
---|
[150] | 477 | %% draw ruler |
---|
[156] | 478 | if test_ruler && isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'ruler') |
---|
| 479 | if isfield(AxeData,'RulerHandle') |
---|
| 480 | pointershape='crosshair'; %give the mouse pointer a cross shape |
---|
| 481 | RulerCoord=[AxeData.RulerCoord ;xy(1,1:2)]; %coordinates defining the ruler segment |
---|
| 482 | set(AxeData.RulerHandle,'XData',RulerCoord(:,1));% updtate the x coordinates for the ruler graphic object |
---|
| 483 | set(AxeData.RulerHandle,'YData',RulerCoord(:,2));% updtate the y coordinates for the ruler graphic object |
---|
| 484 | end |
---|
[60] | 485 | end |
---|
[150] | 486 | |
---|
| 487 | %% update the mouse pointer |
---|
[699] | 488 | if strcmp(pointershape,'zoom')||strcmp(pointershape,'zoomfig') |
---|
| 489 | CData=set_pointershape(pointershape); |
---|
| 490 | set(hCurrentFig,'Pointer','custom','PointerShapeCData',CData,'PointerShapeHotSpot',[9 9]) |
---|
| 491 | else |
---|
[625] | 492 | set(hCurrentFig,'Pointer',pointershape); |
---|
[699] | 493 | end |
---|
| 494 | |
---|
| 495 | function CData=set_pointershape(pointershape) |
---|
| 496 | CData=ones(16,16); |
---|
| 497 | [ind_x,ind_y]=meshgrid([1:16],[1:16]); |
---|
| 498 | if strcmp(pointershape,'zoom') |
---|
| 499 | radius=(ind_x-9).*(ind_x-9)+(ind_y-8.5).*(ind_y-9); |
---|
| 500 | CData(radius<25 & radius>16)=2; %make white circle |
---|
| 501 | CData(radius<16 | radius>40)=NaN; %make the centre transparent |
---|
| 502 | CData(16,16)=1; CData(15,16)=2; |
---|
| 503 | CData(15,15)=1; CData(14,15)=2; |
---|
| 504 | CData(14,14)=1; CData(13,14)=2; |
---|
| 505 | CData(13,13)=1; CData(12,13)=2; |
---|
| 506 | elseif strcmp(pointershape,'zoomfig') |
---|
| 507 | CData(:,1:3)=2; |
---|
| 508 | CData(:,14:16)=2; |
---|
| 509 | CData(1:3,:)=2; |
---|
| 510 | CData(14:16,:)=2; |
---|
| 511 | CData(CData==1)=NaN; |
---|
| 512 | end |
---|