[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) |
---|
| 99 | eval(['Field=FigData.' tagaxes ';']) |
---|
| 100 | if isfield(Field,'ListVarName') |
---|
| 101 | [CellVarIndex,NbDim,VarType]=find_field_indices(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=''; |
---|
| 106 | ivec=[]; |
---|
| 107 | xName=''; |
---|
| 108 | z=[]; |
---|
| 109 | for icell=1:numel(CellVarIndex)%look for all physical fields |
---|
| 110 | if NbDim(icell)>=2 % select 2D field |
---|
| 111 | if isfield(Field,'Mesh') && ~isempty(Field.Mesh)&& ~isempty(VarType{icell}.coord_x) && ~isempty(VarType{icell}.coord_y)%case of unstructured data |
---|
| 112 | eval(['X=Field.' Field.ListVarName{VarType{icell}.coord_x} ';']) |
---|
| 113 | eval(['Y=Field.' Field.ListVarName{VarType{icell}.coord_y} ';']) |
---|
| 114 | 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 |
---|
| 115 | (Y<(xy(1,2)+Field.Mesh/3) & Y>(xy(1,2)-Field.Mesh/3));%f |
---|
| 116 | ivec=find(flag_vec,1);% search the (first) selected vector index ivec |
---|
[432] | 117 | hhh=findobj(CurrentAxes,'Tag','vector_marker'); |
---|
[251] | 118 | if ~isempty(ivec) |
---|
| 119 | % mark the vectors with a circle in the absence of other operations |
---|
| 120 | if ~test_object && ~test_edit_object && ~test_ruler |
---|
| 121 | pointershape='arrow'; %mouse indicates the detection of a vector |
---|
| 122 | if isempty(hhh) |
---|
[432] | 123 | set(0,'CurrentFigure',CurrentFig) |
---|
| 124 | set(CurrentFig,'CurrentAxes',CurrentAxes) |
---|
[251] | 125 | rectangle('Curvature',[1 1],... |
---|
| 126 | 'Position',[X(ivec)-Field.Mesh/2 Y(ivec)-Field.Mesh/2 Field.Mesh Field.Mesh],'EdgeColor','m',... |
---|
| 127 | 'LineStyle','-','Tag','vector_marker'); |
---|
| 128 | else |
---|
| 129 | set(hhh,'Visible','on') |
---|
| 130 | set(hhh,'Position',[X(ivec)-Field.Mesh/2 Y(ivec)-Field.Mesh/2 Field.Mesh Field.Mesh]) |
---|
[105] | 131 | end |
---|
[251] | 132 | end |
---|
| 133 | %display the field values |
---|
| 134 | for ivar=1:numel(CellVarIndex{icell}) |
---|
| 135 | VarName=Field.ListVarName{CellVarIndex{icell}(ivar)}; |
---|
| 136 | eval(['VarVal=Field.' VarName '(ivec);']) |
---|
| 137 | var_text=[VarName '=' num2str(VarVal,3) ',']; |
---|
| 138 | if isequal(ivar,VarType{icell}.coord_x)||isequal(ivar,VarType{icell}.coord_y)||isequal(ivar,VarType{icell}.coord_z) |
---|
| 139 | text_displ_1=[text_displ_1 var_text]; |
---|
| 140 | elseif isequal(ivar,VarType{icell}.vector_x)||isequal(ivar,VarType{icell}.vector_y)||isequal(ivar,VarType{icell}.vector_z) |
---|
| 141 | text_displ_3=[text_displ_3 var_text]; |
---|
| 142 | else |
---|
| 143 | text_displ_4=[text_displ_4 var_text]; |
---|
| 144 | end |
---|
| 145 | end |
---|
| 146 | else |
---|
| 147 | if ~isempty(hhh) |
---|
| 148 | set(hhh,'Visible','off') |
---|
| 149 | end |
---|
| 150 | end |
---|
[399] | 151 | elseif numel(VarType{icell}.coord) >=2 & VarType{icell}.coord > 0 %structured coordinates |
---|
[251] | 152 | yName=Field.ListVarName{VarType{icell}.coord(1)}; |
---|
| 153 | xName=Field.ListVarName{VarType{icell}.coord(2)}; |
---|
| 154 | eval(['y=Field.' yName ';']) |
---|
| 155 | eval(['x=Field.' xName ';']) |
---|
| 156 | VarName=Field.ListVarName{CellVarIndex{icell}(1)}; |
---|
| 157 | eval(['nxy=size(Field.' VarName ');']); |
---|
| 158 | MaxAY=max(y(1),y(end)); %#ok<COLND> |
---|
| 159 | MinAY=min(y(1),y(end)); %#ok<COLND> |
---|
| 160 | if (xy(1,1)>x(1))&(xy(1,1)<x(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY) %#ok<COLND> |
---|
| 161 | indx0=1+round((nxy(2)-1)*(xy(1,1)-x(1))/(x(end)-x(1)));%#ok<COLND> % index x of pixel |
---|
| 162 | indy0=1+round((nxy(1)-1)*(xy(1,2)-y(1))/(y(end)-y(1)));%#ok<COLND> % index y of pixel |
---|
| 163 | if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1) |
---|
| 164 | text_displ_2=['i=' num2str(indx0) ',j=' num2str(indy0) ',']; |
---|
[105] | 165 | for ivar=1:numel(CellVarIndex{icell}) |
---|
[150] | 166 | VarName=Field.ListVarName{CellVarIndex{icell}(ivar)}; |
---|
[251] | 167 | eval(['VarVal=Field.' VarName '(indy0,indx0,:);']) |
---|
| 168 | var_text=[VarName '=' num2str(VarVal) ',']; |
---|
| 169 | text_displ_2=[text_displ_2 var_text]; |
---|
[105] | 170 | end |
---|
| 171 | end |
---|
| 172 | end |
---|
[61] | 173 | end |
---|
[71] | 174 | end |
---|
[251] | 175 | end |
---|
| 176 | % display the current x,y coordinates in the absence of detected vector |
---|
| 177 | if isempty(ivec) |
---|
| 178 | if isempty(xName) |
---|
| 179 | xName='x'; |
---|
| 180 | yName='y'; |
---|
| 181 | end |
---|
| 182 | text_displ_1=[xName '=' num2str(xy(1,1),3) ', ' yName '=' num2str(xy(1,2),3) ',']; |
---|
| 183 | end |
---|
| 184 | %display the z coordinate if defined by the projection plane |
---|
| 185 | if isfield(Field,'PlaneCoord') |
---|
| 186 | % ZIndex=Field.ZIndex; |
---|
| 187 | if size(Field.PlaneCoord)>=[1 3] |
---|
| 188 | z=Field.PlaneCoord(1,3); |
---|
[213] | 189 | if isfield(Field,'PlaneAngle')&&~isequal(Field.PlaneAngle,[0 0 0]) |
---|
[251] | 190 | om=norm(Field.PlaneAngle);%norm of rotation angle in radians |
---|
| 191 | OmAxis=Field.PlaneAngle/om; %unit vector marking the rotation axis |
---|
[207] | 192 | cos_om=cos(pi*om/180); |
---|
| 193 | sin_om=sin(pi*om/180); |
---|
| 194 | coeff=OmAxis(3)*(1-cos_om); |
---|
| 195 | norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om; |
---|
| 196 | norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om; |
---|
| 197 | norm_plane(3)=OmAxis(3)*coeff+cos_om; |
---|
[251] | 198 | Z0=norm_plane*Field.PlaneCoord'/norm_plane(3); |
---|
[207] | 199 | z=Z0-norm_plane(1)*xy(1,1)/norm_plane(3)-norm_plane(2)*xy(1,2)/norm_plane(3); |
---|
| 200 | end |
---|
| 201 | end |
---|
[11] | 202 | end |
---|
[251] | 203 | if ~isempty(z) |
---|
| 204 | text_displ_1=[text_displ_1 ' z=' num2str(z,3)]; |
---|
| 205 | end |
---|
[388] | 206 | % case of PIV correlation display |
---|
[251] | 207 | if test_piv |
---|
[309] | 208 | par=read_GUI(hhciv.Civ1); |
---|
[251] | 209 | [dd,ind_pt]=min(abs(Field.X-xy(1,1))+abs(Field.Y-xy(1,2))); |
---|
| 210 | xround=Field.X(ind_pt); |
---|
| 211 | yround=Field.Y(ind_pt); |
---|
[413] | 212 | % par.Grid=[xround size(Field.A,1)-yround+1]; |
---|
| 213 | par.Grid=[xround yround]; |
---|
[150] | 214 | % mark the correlation box with a rectangle |
---|
[315] | 215 | par.ImageA=Field.A; |
---|
| 216 | par.ImageB=Field.B; |
---|
[388] | 217 | par.ImageHeight=size(par.ImageA,1); |
---|
| 218 | par.ImageWidth=size(par.ImageA,2); |
---|
[309] | 219 | Param.Civ1=par; |
---|
[441] | 220 | ibx2=floor((par.CorrBoxSize(1)-1)/2); |
---|
| 221 | iby2=floor((par.CorrBoxSize(2)-1)/2); |
---|
| 222 | isx2=floor((par.SearchBoxSize(1)-1)/2); |
---|
| 223 | isy2=floor((par.SearchBoxSize(2)-1)/2); |
---|
| 224 | shiftx=par.SearchBoxShift(1); |
---|
| 225 | shifty=par.SearchBoxShift(2); |
---|
[432] | 226 | hhh=findobj(CurrentAxes,'Tag','PIV_box_marker'); |
---|
| 227 | hhhh=findobj(CurrentAxes,'Tag','PIV_search_marker'); |
---|
[150] | 228 | if isempty(hhh) |
---|
[432] | 229 | set(0,'CurrentFigure',CurrentFig) |
---|
| 230 | set(CurrentFig,'CurrentAxes',CurrentAxes) |
---|
[150] | 231 | rectangle('Curvature',[0 0],... |
---|
| 232 | 'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2],'EdgeColor','m',... |
---|
| 233 | 'LineStyle','-','Tag','PIV_box_marker'); |
---|
| 234 | rectangle('Curvature',[0 0],... |
---|
[224] | 235 | 'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2],'EdgeColor','m',... |
---|
[150] | 236 | 'LineStyle','- -','Tag','PIV_search_marker'); |
---|
| 237 | else |
---|
| 238 | set(hhh,'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2]) |
---|
[224] | 239 | set(hhhh,'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2]) |
---|
[150] | 240 | end |
---|
[315] | 241 | [Data,errormsg,result_conv]= civ_matlab(Param); |
---|
[387] | 242 | if ~isempty(errormsg) |
---|
| 243 | text_displ_4=errormsg; |
---|
| 244 | else |
---|
| 245 | rangx(1)=-(isx2-ibx2)+shiftx; |
---|
| 246 | rangx(2)=isx2-ibx2+shiftx; |
---|
| 247 | rangy(1)=-(isy2-iby2)-shifty; |
---|
| 248 | rangy(2)=(isy2-iby2)-shifty; |
---|
| 249 | hcorr=[]; |
---|
| 250 | if isfield(AxeData,'CurrentCorrImage') |
---|
| 251 | hcorr=AxeData.CurrentCorrImage; |
---|
| 252 | if ~ishandle(hcorr) |
---|
| 253 | hcorr=[]; |
---|
| 254 | end |
---|
[150] | 255 | end |
---|
[387] | 256 | if isempty(hcorr) |
---|
| 257 | corrfig=findobj(allchild(0),'tag','corrfig'); |
---|
| 258 | if ~isempty(corrfig) |
---|
[413] | 259 | set(0,'CurrentFigure',corrfig(1)) |
---|
[387] | 260 | AxeData.CurrentCorrImage=imagesc(rangx,-rangy,result_conv,[0 1]); |
---|
| 261 | AxeData.CurrentVector=line([0 Data.Civ1_U],[0 Data.Civ1_V],'Tag','vector'); |
---|
[413] | 262 | AxeData.TitleHandle=title(num2str(par.Grid)); |
---|
[387] | 263 | colorbar |
---|
[432] | 264 | set(CurrentAxes,'UserData',AxeData) |
---|
[387] | 265 | set(get(AxeData.CurrentCorrImage,'parent'),'YDir','normal') |
---|
| 266 | end |
---|
| 267 | else |
---|
| 268 | set(AxeData.CurrentCorrImage,'CData',result_conv) |
---|
| 269 | set(AxeData.CurrentCorrImage,'XData',rangx) |
---|
| 270 | set(AxeData.CurrentCorrImage,'YData',-rangy) |
---|
| 271 | set(AxeData.CurrentVector,'XData',[0 Data.Civ1_U],'YData',[0 Data.Civ1_V]) |
---|
[413] | 272 | set(AxeData.TitleHandle,'String',num2str(par.Grid)) |
---|
[150] | 273 | end |
---|
[251] | 274 | end |
---|
[11] | 275 | end |
---|
| 276 | end |
---|
[251] | 277 | end |
---|
[11] | 278 | end |
---|
| 279 | end |
---|
| 280 | end |
---|
[292] | 281 | if ~isempty(text_displ_1) |
---|
| 282 | set(handles.text_display,'String',[{text_displ_1};{text_displ_2};{text_displ_3};{text_displ_4}]) |
---|
| 283 | else |
---|
| 284 | set(handles.text_display,'String',get(handles.text_display,'UserData')) |
---|
| 285 | end |
---|
[11] | 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'); |
---|
[432] | 301 | set(CurrentAxes,'UserData',AxeData) |
---|
[71] | 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 |
---|
[432] | 311 | UvData=get(huvmat,'UserData'); |
---|
[11] | 312 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
[432] | 313 | if ~isfield(PlotData,'IndexObj') |
---|
| 314 | return |
---|
| 315 | end |
---|
| 316 | ObjectData=UvData.Object{PlotData.IndexObj}; |
---|
| 317 | ProjObject=[];% object (plane) whose projection is represented on the current axes |
---|
| 318 | if isequal(hObject,huvmat)% if the mouse ifs over the GUI uvmat |
---|
| 319 | ProjObject=UvData.Object{get(hhuvmat.ListObject_1,'Value')}; |
---|
| 320 | else |
---|
| 321 | ProjObject=UvData.Object{get(hhuvmat.ListObject,'Value')}; |
---|
| 322 | end |
---|
| 323 | XYData=AxeData.CurrentOrigin; |
---|
| 324 | if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin) |
---|
| 325 | if strcmp(ObjectData.Type,'line')||strcmp(ObjectData.Type,'polyline')||strcmp(ObjectData.Type,'polygon')||strcmp(ObjectData.Type,'points') |
---|
| 326 | ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)]; |
---|
| 327 | % ObjectData.Coord(end,:)=xy(1,:); |
---|
| 328 | elseif strcmp(ObjectData.Type,'rectangle')||strcmp(ObjectData.Type,'ellipse')||strcmp(ObjectData.Type,'volume') |
---|
| 329 | ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate |
---|
| 330 | ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2; |
---|
| 331 | ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width |
---|
| 332 | ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height |
---|
| 333 | elseif isequal(ObjectData.Type,'plane') %case of 'plane' |
---|
| 334 | DX=(xy(1,1)-ObjectData.Coord(1,1)); |
---|
| 335 | DY=(xy(1,2)-ObjectData.Coord(1,2)); |
---|
| 336 | ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt |
---|
| 337 | if isfield(ObjectData,'RangeX') |
---|
| 338 | XMax=sqrt(DX*DX+DY*DY); |
---|
| 339 | if XMax>max(ObjectData.RangeX) |
---|
| 340 | ObjectData.RangeX=[min(ObjectData.RangeX) XMax]; |
---|
[11] | 341 | end |
---|
[432] | 342 | end |
---|
[11] | 343 | end |
---|
[432] | 344 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
| 345 | pointershape='crosshair'; |
---|
| 346 | elseif isequal(AxeData.Drawing,'translate') |
---|
| 347 | DX=xy(1,1)-XYData(1);%translation from initial position |
---|
| 348 | DY=xy(1,2)-XYData(2); |
---|
| 349 | ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX; |
---|
| 350 | ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY; |
---|
| 351 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
| 352 | pointershape='fleur'; |
---|
| 353 | elseif isequal(AxeData.Drawing,'deform') |
---|
| 354 | ind_move=AxeData.CurrentIndex; |
---|
| 355 | ObjectData.Coord(ind_move,1)=xy(1,1); |
---|
| 356 | ObjectData.Coord(ind_move,2)=xy(1,2); |
---|
| 357 | plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m'); |
---|
| 358 | pointershape='circle'; |
---|
[11] | 359 | end |
---|
[432] | 360 | end |
---|
[67] | 361 | |
---|
[150] | 362 | %% detect calibration points if the GUI geometry_calib is opened |
---|
[67] | 363 | h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI |
---|
[78] | 364 | if ~test_zoom && ~isempty(h_geometry_calib) |
---|
[67] | 365 | pointershape='crosshair';%default for geometry_calib: ready to create new points |
---|
| 366 | hh_geometry_calib=guidata(h_geometry_calib); |
---|
[156] | 367 | if ~isempty(xy) && isfield(hh_geometry_calib,'ListCoord') |
---|
[67] | 368 | h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); |
---|
| 369 | Coord=get(h_ListCoord,'String'); |
---|
| 370 | data=read_geometry_calib(Coord);%transform char cell to numbers |
---|
| 371 | if size(data.Coord,2)>=5 |
---|
| 372 | XCoord=(data.Coord(:,4)); |
---|
| 373 | YCoord=(data.Coord(:,5)); |
---|
[432] | 374 | xy=get(CurrentAxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
[67] | 375 | if ~isempty(xy) |
---|
[432] | 376 | xlim=get(CurrentAxes,'XLim'); |
---|
[78] | 377 | ind_range_x=abs((xlim(2)-xlim(1))/50); |
---|
[432] | 378 | ylim=get(CurrentAxes,'YLim'); |
---|
[78] | 379 | ind_range_y=abs((ylim(2)-ylim(1))/50); |
---|
| 380 | ind_range=sqrt(ind_range_x*ind_range_y); |
---|
[67] | 381 | 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 |
---|
| 382 | (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse |
---|
| 383 | if ~isempty(index_point) |
---|
| 384 | pointershape='arrow';% default pointer is an arrow |
---|
[78] | 385 | end |
---|
| 386 | hh=findobj('Tag','calib_points');%look for handle of calibration points |
---|
| 387 | if ~isempty(hh) && ~isempty(get(hh,'UserData')) && get(hh_geometry_calib.edit_append,'Value') |
---|
[173] | 388 | index_point=get(hh,'UserData'); |
---|
[78] | 389 | XCoord(index_point)=xy(1,1); |
---|
| 390 | YCoord(index_point)=xy(1,2); |
---|
| 391 | set(hh,'XData',XCoord) |
---|
| 392 | set(hh,'YData',YCoord) |
---|
| 393 | end |
---|
| 394 | if ~isempty(index_point) |
---|
| 395 | set(h_ListCoord,'Value',index_point)%mrk the point on the GUI geometry_calib |
---|
[67] | 396 | hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle) |
---|
| 397 | if ~isempty(hhh) |
---|
[71] | 398 | set(hhh,'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range]) |
---|
[67] | 399 | end |
---|
[78] | 400 | end |
---|
[67] | 401 | end |
---|
| 402 | end |
---|
| 403 | end |
---|
| 404 | end |
---|
| 405 | |
---|
[150] | 406 | %% draw ruler |
---|
[156] | 407 | if test_ruler && isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'ruler') |
---|
| 408 | if isfield(AxeData,'RulerHandle') |
---|
| 409 | pointershape='crosshair'; %give the mouse pointer a cross shape |
---|
| 410 | RulerCoord=[AxeData.RulerCoord ;xy(1,1:2)]; %coordinates defining the ruler segment |
---|
| 411 | set(AxeData.RulerHandle,'XData',RulerCoord(:,1));% updtate the x coordinates for the ruler graphic object |
---|
| 412 | set(AxeData.RulerHandle,'YData',RulerCoord(:,2));% updtate the y coordinates for the ruler graphic object |
---|
| 413 | end |
---|
[60] | 414 | end |
---|
[150] | 415 | |
---|
| 416 | %% update the mouse pointer |
---|
[432] | 417 | set(CurrentFig,'Pointer',pointershape); |
---|