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