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