Changeset 251 for trunk/src/mouse_motion.m
- Timestamp:
- May 13, 2011, 11:05:49 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mouse_motion.m
r248 r251 107 107 if isfield(Field,'ListVarName') 108 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 115 if NbDim(icell)>=2 % select 2D field 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 125 if ~test_object && ~test_edit_object && ~test_ruler 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 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 ivec=[]; 115 xName=''; 116 z=[]; 117 for icell=1:numel(CellVarIndex)%look for all physical fields 118 if NbDim(icell)>=2 % select 2D field 119 if isfield(Field,'Mesh') && ~isempty(Field.Mesh)&& ~isempty(VarType{icell}.coord_x) && ~isempty(VarType{icell}.coord_y)%case of unstructured data 120 eval(['X=Field.' Field.ListVarName{VarType{icell}.coord_x} ';']) 121 eval(['Y=Field.' Field.ListVarName{VarType{icell}.coord_y} ';']) 122 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 123 (Y<(xy(1,2)+Field.Mesh/3) & Y>(xy(1,2)-Field.Mesh/3));%f 124 ivec=find(flag_vec,1);% search the (first) selected vector index ivec 125 hhh=findobj(haxes,'Tag','vector_marker'); 126 if ~isempty(ivec) 127 % mark the vectors with a circle in the absence of other operations 128 if ~test_object && ~test_edit_object && ~test_ruler 129 pointershape='arrow'; %mouse indicates the detection of a vector 130 if isempty(hhh) 131 set(0,'CurrentFigure',currentfig) 132 set(currentfig,'CurrentAxes',haxes) 133 rectangle('Curvature',[1 1],... 134 'Position',[X(ivec)-Field.Mesh/2 Y(ivec)-Field.Mesh/2 Field.Mesh Field.Mesh],'EdgeColor','m',... 135 'LineStyle','-','Tag','vector_marker'); 136 else 137 set(hhh,'Visible','on') 138 set(hhh,'Position',[X(ivec)-Field.Mesh/2 Y(ivec)-Field.Mesh/2 Field.Mesh Field.Mesh]) 137 139 end 138 %display the field values 140 end 141 %display the field values 142 for ivar=1:numel(CellVarIndex{icell}) 143 VarName=Field.ListVarName{CellVarIndex{icell}(ivar)}; 144 eval(['VarVal=Field.' VarName '(ivec);']) 145 var_text=[VarName '=' num2str(VarVal,3) ',']; 146 if isequal(ivar,VarType{icell}.coord_x)||isequal(ivar,VarType{icell}.coord_y)||isequal(ivar,VarType{icell}.coord_z) 147 text_displ_1=[text_displ_1 var_text]; 148 elseif isequal(ivar,VarType{icell}.vector_x)||isequal(ivar,VarType{icell}.vector_y)||isequal(ivar,VarType{icell}.vector_z) 149 text_displ_3=[text_displ_3 var_text]; 150 else 151 text_displ_4=[text_displ_4 var_text]; 152 end 153 end 154 else 155 if ~isempty(hhh) 156 set(hhh,'Visible','off') 157 end 158 end 159 elseif numel(VarType{icell}.coord) >=2 %structured coordinates 160 yName=Field.ListVarName{VarType{icell}.coord(1)}; 161 xName=Field.ListVarName{VarType{icell}.coord(2)}; 162 eval(['y=Field.' yName ';']) 163 eval(['x=Field.' xName ';']) 164 VarName=Field.ListVarName{CellVarIndex{icell}(1)}; 165 eval(['nxy=size(Field.' VarName ');']); 166 MaxAY=max(y(1),y(end)); %#ok<COLND> 167 MinAY=min(y(1),y(end)); %#ok<COLND> 168 if (xy(1,1)>x(1))&(xy(1,1)<x(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY) %#ok<COLND> 169 indx0=1+round((nxy(2)-1)*(xy(1,1)-x(1))/(x(end)-x(1)));%#ok<COLND> % index x of pixel 170 indy0=1+round((nxy(1)-1)*(xy(1,2)-y(1))/(y(end)-y(1)));%#ok<COLND> % index y of pixel 171 if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1) 172 text_displ_2=['i=' num2str(indx0) ',j=' num2str(indy0) ',']; 139 173 for ivar=1:numel(CellVarIndex{icell}) 140 174 VarName=Field.ListVarName{CellVarIndex{icell}(ivar)}; 141 eval(['VarVal=Field.' VarName '(ivec);']) 142 var_text=[VarName '=' num2str(VarVal,3) ',']; 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 150 end 151 else 152 if ~isempty(hhh) 153 set(hhh,'Visible','off') 154 end 155 end 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 ');']); 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 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 175 eval(['VarVal=Field.' VarName '(indy0,indx0,:);']) 176 var_text=[VarName '=' num2str(VarVal) ',']; 177 text_displ_2=[text_displ_2 var_text]; 174 178 end 175 179 end … … 177 181 end 178 182 end 179 % end 180 if strcmp(text_displ_1,'') 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); 183 end 184 % display the current x,y coordinates in the absence of detected vector 185 if isempty(ivec) 186 if isempty(xName) 187 xName='x'; 188 yName='y'; 189 end 190 text_displ_1=[xName '=' num2str(xy(1,1),3) ', ' yName '=' num2str(xy(1,2),3) ',']; 191 end 192 %display the z coordinate if defined by the projection plane 193 if isfield(Field,'PlaneCoord') 194 % ZIndex=Field.ZIndex; 195 if size(Field.PlaneCoord)>=[1 3] 196 z=Field.PlaneCoord(1,3); 187 197 if isfield(Field,'PlaneAngle')&&~isequal(Field.PlaneAngle,[0 0 0]) 188 om=norm(Field.PlaneAngle (ZIndex,:));%norm of rotation angle in radians189 OmAxis=Field.PlaneAngle (ZIndex,:)/om; %unit vector marking the rotation axis198 om=norm(Field.PlaneAngle);%norm of rotation angle in radians 199 OmAxis=Field.PlaneAngle/om; %unit vector marking the rotation axis 190 200 cos_om=cos(pi*om/180); 191 201 sin_om=sin(pi*om/180); … … 194 204 norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om; 195 205 norm_plane(3)=OmAxis(3)*coeff+cos_om; 196 Z0=norm_plane*Field.PlaneCoord (ZIndex,:)'/norm_plane(3);206 Z0=norm_plane*Field.PlaneCoord'/norm_plane(3); 197 207 z=Z0-norm_plane(1)*xy(1,1)/norm_plane(3)-norm_plane(2)*xy(1,2)/norm_plane(3); 198 208 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 209 end 210 end 211 if ~isempty(z) 212 text_displ_1=[text_displ_1 ' z=' num2str(z,3)]; 204 213 end 205 214 %coordinate transform if proj_coord differs from menu_coord A REVOIR 206 if isfield(Field,'CoordUnit')207 mouse.CoordUnit=Field.CoordUnit;208 end209 215 % if isfield(Field,'CoordUnit') 210 216 % mouse.CoordUnit=Field.CoordUnit; 211 217 % 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 219 if test_piv 220 par=civ('read_param_civ1',hhciv); 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 % dx=str2double(par.dx); 227 % dy=str2double(par.dy); 228 % xround=x(1)+dx*round((xy(1,1)-x(1))/dx);% index x of pixel 229 % yround=y(1)+dy*round((xy(1,2)-y(1))/dy);% index y of pixel 230 % end 218 % case of PIV correlation display 219 if test_piv 220 par=civ('read_param_civ1',hhciv); 221 [dd,ind_pt]=min(abs(Field.X-xy(1,1))+abs(Field.Y-xy(1,2))); 222 xround=Field.X(ind_pt); 223 yround=Field.Y(ind_pt); 231 224 % mark the correlation box with a rectangle 232 225 ibx2=floor((str2double(par.ibx)-1)/2); … … 248 241 'LineStyle','- -','Tag','PIV_search_marker'); 249 242 else 250 % set(hhh,'Visible','on')251 243 set(hhh,'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2]) 252 244 set(hhhh,'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2]) 253 245 end 254 246 [xtable ytable utable vtable ctable typevector result_conv] = pivlab (Field.A,Field.B,ibx2,iby2,isx2,isy2,shiftx,shifty,[xround size(Field.A,1)-yround+1], 1, []); 255 % Asub=Field.A(yround-iby2:yround+iby2,xround-ibx2:xround+ibx2);%first sub-image 256 % Asub=reshape(Asub,[],1);%first sub-image reshaped as matlab vector 257 rangx(1)=-(isx2-ibx2)+shiftx; 258 rangx(2)=isx2-ibx2+shiftx; 259 rangy(1)=-(isy2-iby2)-shifty; 260 rangy(2)=(isy2-iby2)-shifty; 261 % correl=zeros(rangy(2)-rangy(1)+1,rangx(2)-rangx(1)+1); 262 % for id=rangx(1):rangx(2) 263 % for jd=rangy(1):rangy(2) 264 % Bsub=Field.B(yround-iby2+jd:yround+iby2+jd,xround-ibx2+id:xround+ibx2+id); 265 % Bsub=reshape(Bsub,[],1); 266 % correl(jd-rangy(1)+1,id-rangx(1)+1)=corr(double(Asub),double(Bsub)); 267 % end 268 % end 269 %correl=uint8(63.5*correl+63.5); 247 rangx(1)=-(isx2-ibx2)+shiftx; 248 rangx(2)=isx2-ibx2+shiftx; 249 rangy(1)=-(isy2-iby2)-shifty; 250 rangy(2)=(isy2-iby2)-shifty; 270 251 hcorr=[]; 271 if isfield(AxeData,'CurrentCorrImage') 252 if isfield(AxeData,'CurrentCorrImage') 272 253 hcorr=AxeData.CurrentCorrImage; 273 254 if ~ishandle(hcorr) … … 287 268 end 288 269 else 289 % set(AxeData.CurrentCorrImage,'CData',correl)290 270 set(AxeData.CurrentCorrImage,'CData',result_conv) 291 271 set(AxeData.CurrentCorrImage,'XData',rangx) 292 272 set(AxeData.CurrentCorrImage,'YData',-rangy) 293 273 set(AxeData.CurrentVector,'XData',[0 utable],'YData',[0 -vtable]) 294 end 274 end 295 275 end 296 276 end 297 end 277 end 298 278 end 299 279 end
Note: See TracChangeset
for help on using the changeset viewer.