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