Changeset 150 for trunk/src/mouse_motion.m
- Timestamp:
- Dec 3, 2010, 12:16:51 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mouse_motion.m
r105 r150 28 28 return 29 29 end 30 test_draw=0; 31 test_create=0;%default 32 test_object=0; %default 30 currentfig=hObject; 31 hhcurrentfig=guidata(currentfig); 32 test_zoom=get(hhcurrentfig.zoom,'Value');%test for zoom activated on the current figure 33 test_draw=0;%test for mouse drawing of object, =0 by default 34 test_object=0; %test for object editing or creation 33 35 test_edit=isfield(handles,'edit') && get(handles.edit,'Value');% edit test for mouse shap: an arrow 34 test_zoom_draw=0; %default 35 test_ruler=0; 36 huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle 37 hhuvmat=guidata(huvmat); 38 test_zoom=get(hhuvmat.zoom,'Value'); 36 test_zoom_draw=0; % test for zoom drawing 37 test_ruler=0;%test for active ruler 38 test_piv=0;% test for PIV correlation display 39 huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle 40 if ~isempty(huvmat) 41 hhuvmat=guidata(huvmat); 42 end 39 43 if ~isempty(huvmat) 40 44 UvData=get(huvmat,'UserData'); 41 45 test_ruler=isfield(UvData,'MouseAction') && isequal(UvData.MouseAction,'ruler'); 42 46 end 43 47 hciv=findobj(allchild(0),'tag','civ');%find the uvmat interface handle 48 if ~isempty(hciv) && strcmp(get(currentfig,'tag'),'view_field') 49 hhciv=guidata(hciv); 50 test_piv =get(hhciv.TestCiv1,'Value'); 51 end 44 52 45 53 %find the current axe 'haxes' and display the current mouse position or uicontrol tag … … 54 62 55 63 pointershape='arrow';% default pointer is an arrow 56 currentfig=hObject; 64 57 65 xy_fig=get(currentfig,'CurrentPoint');% current point of the current figure (gcbo) 58 66 hchild=get(currentfig,'Children');%handles of all objects in the current figure 59 67 60 % loop on all the objects in the current figure and detect whether the mouse is over a plot axes68 %% loop on all the objects in the current figure and detect whether the mouse is over a plot axes 61 69 haxes=[]; 62 70 for ichild=1:length(hchild) … … 65 73 continue 66 74 end%position of the object 67 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);75 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); 68 76 htype=get(hchild(ichild),'Type');%type of the crrent child 69 77 %if the mouse is over an axis, look at the data … … 73 81 AxeData=get(haxes,'UserData');% data attached to the axis 74 82 if isfield(AxeData,'Drawing')&& ~isempty(AxeData.Drawing) 75 test_draw=~isequal(AxeData.Drawing,'off'); 83 test_draw=~isequal(AxeData.Drawing,'off');%=1 if mouse drawing of object is active 76 84 end 77 85 test_zoom_draw=test_draw && isequal(AxeData.Drawing,'zoom')&& isfield(AxeData,'CurrentOrigin') && isequal(get(gcf,'SelectionType'),'normal'); … … 80 88 pointershape='crosshair';%set pointer with cross shape (default when mouse is over an axis) 81 89 end 82 if isfield(AxeData,'ListVarName') 83 [CellVarIndex,NbDim,VarType]=find_field_indices(AxeData); 84 if isfield(AxeData,'Mesh') && ~isempty(AxeData.Mesh) 85 text_displ_1=''; 86 text_displ_2=''; 87 text_displ_3=''; 88 text_displ_4=''; 89 for icell=1:numel(CellVarIndex)%look for all physical fields 90 if NbDim(icell)==2 % select 2D field 91 if ~isempty(VarType{icell}.coord_x) && ~isempty(VarType{icell}.coord_y)%case of unstructured data 92 eval(['X=AxeData.' AxeData.ListVarName{VarType{icell}.coord_x} ';']) 93 eval(['Y=AxeData.' AxeData.ListVarName{VarType{icell}.coord_y} ';']) 94 flag_vec=(X<(xy(1,1)+AxeData.Mesh/3) & X>(xy(1,1)-AxeData.Mesh/3)) & ...%flagx=1 for the vectors with x position selected by the mouse 95 (Y<(xy(1,2)+AxeData.Mesh/3) & Y>(xy(1,2)-AxeData.Mesh/3));%f 96 ivec=find(flag_vec,1);% search the (first) selected vector index ivec 97 hhh=findobj(haxes,'Tag','vector_marker'); 98 if ~isempty(ivec) 99 if ~test_object && ~test_create && ~test_edit && ~test_ruler% mark the vectors with a circle in the absence of other operations 100 pointershape='arrow'; %mouse indicates the detection of a vector 101 if isempty(hhh) 102 hstack=findobj(allchild(0),'Type','figure');%current stack order of figures in matlab 103 axes(haxes) 104 rectangle('Curvature',[1 1],... 105 'Position',[X(ivec)-AxeData.Mesh/2 Y(ivec)-AxeData.Mesh/2 AxeData.Mesh AxeData.Mesh],'EdgeColor','m',... 106 'LineStyle','-','Tag','vector_marker'); 107 set(0,'Children',hstack);%put back the initial figure stack after plot creation 108 else 109 set(hhh,'Visible','on') 110 set(hhh,'Position',[X(ivec)-AxeData.Mesh/2 Y(ivec)-AxeData.Mesh/2 AxeData.Mesh AxeData.Mesh]) 90 FigData=get(currentfig,'UserData'); 91 tagaxes=get(haxes,'tag'); 92 if isfield(FigData,tagaxes) 93 eval(['Field=FigData.' tagaxes ';']) 94 if isfield(Field,'ListVarName') 95 [CellVarIndex,NbDim,VarType]=find_field_indices(Field);%analyse the physical fields contained in Field 96 % if isfield(Field,'Mesh') && ~isempty(Field.Mesh) 97 text_displ_1=''; 98 text_displ_2=''; 99 text_displ_3=''; 100 text_displ_4=''; 101 for icell=1:numel(CellVarIndex)%look for all physical fields 102 if NbDim(icell)==2 % select 2D field 103 if isfield(Field,'Mesh') && ~isempty(Field.Mesh)&& ~isempty(VarType{icell}.coord_x) && ~isempty(VarType{icell}.coord_y)%case of unstructured data 104 eval(['X=Field.' Field.ListVarName{VarType{icell}.coord_x} ';']) 105 eval(['Y=Field.' Field.ListVarName{VarType{icell}.coord_y} ';']) 106 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 107 (Y<(xy(1,2)+Field.Mesh/3) & Y>(xy(1,2)-Field.Mesh/3));%f 108 ivec=find(flag_vec,1);% search the (first) selected vector index ivec 109 hhh=findobj(haxes,'Tag','vector_marker'); 110 if ~isempty(ivec) 111 % mark the vectors with a circle in the absence of other operations 112 if ~test_object && ~test_edit && ~test_ruler 113 pointershape='arrow'; %mouse indicates the detection of a vector 114 if isempty(hhh) 115 set(0,'CurrentFigure',currentfig) 116 set(currentfig,'CurrentAxes',haxes) 117 rectangle('Curvature',[1 1],... 118 'Position',[X(ivec)-Field.Mesh/2 Y(ivec)-Field.Mesh/2 Field.Mesh Field.Mesh],'EdgeColor','m',... 119 'LineStyle','-','Tag','vector_marker'); 120 else 121 set(hhh,'Visible','on') 122 set(hhh,'Position',[X(ivec)-Field.Mesh/2 Y(ivec)-Field.Mesh/2 Field.Mesh Field.Mesh]) 123 end 124 end 125 %display the field values 126 for ivar=1:numel(CellVarIndex{icell}) 127 VarName=Field.ListVarName{CellVarIndex{icell}(ivar)}; 128 eval(['VarVal=Field.' VarName '(ivec);']) 129 var_text=[VarName '=' num2str(VarVal,3) ',']; 130 if isequal(ivar,VarType{icell}.coord_x)||isequal(ivar,VarType{icell}.coord_y)||isequal(ivar,VarType{icell}.coord_z) 131 text_displ_1=[text_displ_1 var_text]; 132 elseif isequal(ivar,VarType{icell}.vector_x)||isequal(ivar,VarType{icell}.vector_y)||isequal(ivar,VarType{icell}.vector_z) 133 text_displ_3=[text_displ_3 var_text]; 134 else 135 text_displ_4=[text_displ_4 var_text]; 136 end 137 end 138 else 139 if ~isempty(hhh) 140 set(hhh,'Visible','off') 111 141 end 112 142 end 113 for ivar=1:numel(CellVarIndex{icell}) 114 VarName=AxeData.ListVarName{CellVarIndex{icell}(ivar)}; 115 eval(['VarVal=AxeData.' VarName '(ivec);']) 116 var_text=[VarName '=' num2str(VarVal,3) ',']; 117 if isequal(ivar,VarType{icell}.coord_x)||isequal(ivar,VarType{icell}.coord_y)||isequal(ivar,VarType{icell}.coord_z) 118 text_displ_1=[text_displ_1 var_text]; 119 elseif isequal(ivar,VarType{icell}.vector_x)||isequal(ivar,VarType{icell}.vector_y)||isequal(ivar,VarType{icell}.vector_z) 120 text_displ_3=[text_displ_3 var_text]; 121 else 122 text_displ_4=[text_displ_4 var_text]; 123 end 124 end 125 else 126 if ~isempty(hhh) 127 set(hhh,'Visible','off') 128 end 129 end 130 elseif numel(VarType{icell}.coord) >=2 %structured coordinates 131 eval(['y=AxeData.' AxeData.ListVarName{VarType{icell}.coord(1)} ';']) 132 eval(['x=AxeData.' AxeData.ListVarName{VarType{icell}.coord(2)} ';']) 133 nxy(1)=numel(y); 134 nxy(2)=numel(x); 135 MaxAY=max(y(1),y(end)); 136 MinAY=min(y(1),y(end)); 137 if (xy(1,1)>x(1))&(xy(1,1)<x(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY) 138 indx0=1+round((nxy(2)-1)*(xy(1,1)-x(1))/(x(end)-x(1)));% index x of pixel 139 indy0=1+round((nxy(1)-1)*(xy(1,2)-y(1))/(y(end)-y(1)));% index y of pixel 140 if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1) 141 text_displ_2=['i=' num2str(indx0) ',j=' num2str(indy0) ',']; 142 for ivar=1:numel(CellVarIndex{icell}) 143 VarName=AxeData.ListVarName{CellVarIndex{icell}(ivar)}; 144 eval(['VarVal=AxeData.' VarName '(indy0,indx0);']) 145 var_text=[VarName '=' num2str(VarVal,3) ',']; 146 text_displ_2=[text_displ_2 var_text]; 143 elseif numel(VarType{icell}.coord) >=2 %structured coordinates 144 eval(['y=Field.' Field.ListVarName{VarType{icell}.coord(1)} ';']) 145 eval(['x=Field.' Field.ListVarName{VarType{icell}.coord(2)} ';']) 146 VarName=Field.ListVarName{CellVarIndex{icell}(1)}; 147 eval(['nxy=size(Field.' VarName ');']); 148 % nxy(1)=numel(y); 149 % nxy(2)=numel(x); 150 MaxAY=max(y(1),y(end)); 151 MinAY=min(y(1),y(end)); 152 if (xy(1,1)>x(1))&(xy(1,1)<x(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY) 153 indx0=1+round((nxy(2)-1)*(xy(1,1)-x(1))/(x(end)-x(1)));% index x of pixel 154 indy0=1+round((nxy(1)-1)*(xy(1,2)-y(1))/(y(end)-y(1)));% index y of pixel 155 if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1) 156 text_displ_2=['i=' num2str(indx0) ',j=' num2str(indy0) ',']; 157 for ivar=1:numel(CellVarIndex{icell}) 158 VarName=Field.ListVarName{CellVarIndex{icell}(ivar)}; 159 eval(['VarVal=Field.' VarName '(indy0,indx0,:);']) 160 var_text=[VarName '=' num2str(VarVal) ',']; 161 text_displ_2=[text_displ_2 var_text]; 162 end 147 163 end 148 164 end … … 150 166 end 151 167 end 168 % end 169 if strcmp(text_displ_1,'') 170 text_displ_1=['x=' num2str(xy(1,1),3) ',y=' num2str(xy(1,2),3) ',']; 171 end 172 if isfield(Field,'PlaneCoord') && isfield(Field,'ZIndex') 173 text_displ_1=[text_displ_1 ' z=' num2str(Field.PlaneCoord(Field.ZIndex,3))]; %TODO: generaliser au cas avec angle 174 end 175 %coordinate transform if proj_coord differs from menu_coord A REVOIR 176 if isfield(Field,'CoordType') 177 mouse.CoordType=Field.CoordType; 178 end 179 if isfield(Field,'CoordUnit') 180 mouse.CoordUnit=Field.CoordUnit; 181 end 182 if isfield(mouse,'CoordType') 183 if isequal(mouse.CoordType,'px') 184 mouse.CoordUnit='px'; 185 end 186 else 187 mouse.CoordUnit='';%default 188 end 189 if test_piv 190 par=civ('read_param_civ1',hhciv); 191 if isfield(Field,'A') 192 dx=str2double(par.dx); 193 dy=str2double(par.dy); 194 xround=x(1)+dx*round((xy(1,1)-x(1))/dx);% index x of pixel 195 yround=y(1)+dy*round((xy(1,2)-y(1))/dy);% index y of pixel 196 end 197 % mark the correlation box with a rectangle 198 ibx2=floor((str2double(par.ibx)-1)/2); 199 iby2=floor((str2double(par.iby)-1)/2); 200 isx2=floor((str2double(par.isx)-1)/2); 201 isy2=floor((str2double(par.isy)-1)/2); 202 hhh=findobj(haxes,'Tag','PIV_box_marker'); 203 hhhh=findobj(haxes,'Tag','PIV_search_marker'); 204 if isempty(hhh) 205 %hstack=findobj(allchild(0),'Type','figure');%current stack order of figures in matlab 206 set(0,'CurrentFigure',currentfig) 207 set(currentfig,'CurrentAxes',haxes) 208 rectangle('Curvature',[0 0],... 209 'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2],'EdgeColor','m',... 210 'LineStyle','-','Tag','PIV_box_marker'); 211 rectangle('Curvature',[0 0],... 212 'Position',[xround-isx2 yround-isy2 2*isx 2*isy],'EdgeColor','m',... 213 'LineStyle','- -','Tag','PIV_search_marker'); 214 % set(0,'Children',hstack);%put back the initial figure stack after plot creation 215 else 216 % set(hhh,'Visible','on') 217 set(hhh,'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2]) 218 set(hhhh,'Position',[xround-isx2 yround-isy2 2*isx2 2*isy2]) 219 end 220 Asub=Field.A(xround-ibx2:xround+ibx2,yround-iby2:yround+iby2); 221 Asub=reshape(Asub,[],1); 222 rangx(1)=-(isx2-ibx2); 223 rangx(2)=isx2-ibx2; 224 rangy(1)=isy2-iby2; 225 rangy(2)=-(isy2-iby2); 226 for id=rangx(1):rangx(2) 227 for jd=rangy(2):rangy(1) 228 Bsub=Field.B(xround-ibx2+id:xround+ibx2+id,yround-iby2+jd:yround+iby2+jd); 229 Bsub=reshape(Bsub,[],1); 230 correl(jd-rangy(2)+1,id-rangx(1)+1)=corr(double(Asub),double(Bsub)); 231 end 232 end 233 %correl=uint8(63.5*correl+63.5); 234 hcorr=[]; 235 if isfield(AxeData,'CurrentCorrImage') 236 hcorr=AxeData.CurrentCorrImage; 237 if ~ishandle(hcorr) 238 hcorr=[]; 239 end 240 end 241 if isempty(hcorr) 242 coorfig=findobj(allchild(0),'tag','corrfig'); 243 if isempty(coorfig) 244 corrfig=figure; 245 set(corrfig,'tag','corrfig') 246 end 247 set(0,'CurrentFigure',corrfig) 248 AxeData.CurrentCorrImage=imagesc(rangx,rangy,correl,[0 1]); 249 colorbar 250 % map_r=ones(42,1)*[1 0 0]; 251 % map_g=ones(11,1)*[0 1 0]; 252 % map_b=ones(11,1)*[0 0 1]; 253 % map=[map_r;map_g;map_b]; 254 % set(corrfig,'colormap',map) 255 set(haxes,'UserData',AxeData) 256 else 257 set(AxeData.CurrentCorrImage,'CData',correl) 258 end 152 259 end 153 260 end 154 if strcmp(text_displ_1,'') 155 text_displ_1=['x=' num2str(xy(1,1)) ',y=' num2str(xy(1,2))]; 156 end 157 if isfield(AxeData,'Z') 158 text_displ_1=[text_displ_1 num2str(AxeData.Z)]; %generaliser au cas avec angle 159 end 160 if isfield(AxeData,'ObjectCoord') && size(AxeData.ObjectCoord,2)==3 161 text_displ_1=[text_displ_1 num2str(AxeData.ObjectCoord(1,3))]; %generaliser au cas avec angle 162 end 163 %images 164 if strcmp(text_displ_2,'')&&isfield(AxeData,'A')&&isfield(AxeData,'AX')&&isfield(AxeData,'AY') 165 y=AxeData.AY; 166 x=AxeData.AX; 167 nxy=size(AxeData.A); 168 MaxAY=max(y(1),y(end)); 169 MinAY=min(y(1),y(end)); 170 if (xy(1,1)>x(1))&(xy(1,1)<x(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY) 171 indx0=1+round((nxy(2)-1)*(xy(1,1)-x(1))/(x(end)-x(1)));% index x of pixel 172 indy0=1+round((nxy(1)-1)*(xy(1,2)-y(1))/(y(end)-y(1)));% index y of pixel 173 if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1) 174 text_displ_2=['i=' num2str(indx0) ',j=' num2str(indy0) ',A=' num2str(AxeData.A(indy0,indx0,:))]; 175 end 176 end 177 end 178 %coordinate transform if proj_coord differs from menu_coord A REVOIR 179 if isfield(AxeData,'CoordType') 180 mouse.CoordType=AxeData.CoordType; 181 end 182 if isfield(AxeData,'CoordUnit') 183 mouse.CoordUnit=AxeData.CoordUnit; 184 end 185 if isfield(mouse,'CoordType') 186 if isequal(mouse.CoordType,'px') 187 mouse.CoordUnit='px'; 188 end 189 else 190 mouse.CoordUnit='';%default 191 end 192 end 261 end 193 262 end 194 263 end … … 200 269 201 270 %%%%%%%%%%%%% 202 % draw a zoom rectangle if no object creation is selected271 %% draw a zoom rectangle if no object creation is selected 203 272 if test_zoom_draw 204 273 xy_rect=AxeData.CurrentOrigin; … … 221 290 222 291 %%%%%%%%%%%%%%%%% 223 % create or modify an object292 %% create or modify an object 224 293 225 294 if ~isempty(huvmat) && test_object … … 234 303 XYData=AxeData.CurrentOrigin; 235 304 if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin) 236 if isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')|isequal(ObjectData.Style,'polygon')|isequal(ObjectData.Style,'points')305 if strcmp(ObjectData.Style,'line')||strcmp(ObjectData.Style,'polyline')||strcmp(ObjectData.Style,'polygon')||strcmp(ObjectData.Style,'points') 237 306 xy(1,3)=0; 238 307 ObjectData.Coord=[ObjectData.Coord ;xy(1,:)]; 239 308 % ObjectData.Coord(end,:)=xy(1,:); 240 elseif isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')|isequal(ObjectData.Style,'volume')309 elseif strcmp(ObjectData.Style,'rectangle')||strcmp(ObjectData.Style,'ellipse')||strcmp(ObjectData.Style,'volume') 241 310 ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate 242 311 ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2; … … 273 342 end 274 343 275 % detect calibration points if the GUI geometry_calib is opened344 %% detect calibration points if the GUI geometry_calib is opened 276 345 h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI 277 346 if ~test_zoom && ~isempty(h_geometry_calib) … … 317 386 end 318 387 319 % draw ruler388 %% draw ruler 320 389 if test_ruler && isequal(AxeData.Drawing,'ruler') 321 390 if isfield(UvData,'RulerHandle') … … 326 395 end 327 396 end 397 398 %% update the mouse pointer 328 399 set(currentfig,'Pointer',pointershape);
Note: See TracChangeset
for help on using the changeset viewer.