source: trunk/src/mouse_motion.m @ 752

Last change on this file since 752 was 741, checked in by sommeria, 11 years ago

bugs corrected in browse_data and mouse_motion (z display)

File size: 24.9 KB
RevLine 
[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
25function mouse_motion(hObject,eventdata,handles)
[78]26
[187]27FigData=get(hObject,'UserData');
28if 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
[625]29    hCurrentFig=get(get(FigData,'parent'),'parent');
[187]30else
[625]31    hCurrentFig=hObject;%usual plot
[187]32end
[714]33if strcmp(get(hCurrentFig,'Pointer'),'watch')
34    return % no action if a calculation is running
35end
[625]36hhCurrentFig=guidata(hCurrentFig);%handles of the elements in the GUI containing the current figure (uvmat or view_field)
[622]37CheckZoom=get(hhCurrentFig.CheckZoom,'Value');% check for zoom on mode
38CheckZoomFig=get(hhCurrentFig.CheckZoomFig,'Value');% check for zoom sub fig creation mode
[625]39hPlotAxes=hhCurrentFig.PlotAxes';% handles of the main plot axes
40AxeData=get(hPlotAxes,'UserData');% data attached to the axis
[627]41htext_display(1)=handles.text_display;
42if isfield(AxeData,'htext_display')&&ishandle(AxeData.htext_display)
43    htext_display(2)=AxeData.htext_display;
44end
[625]45test_draw=0;%test for mouse drawing of object, =0 by default
46if isfield(AxeData,'Drawing')&& ~isempty(AxeData.Drawing)
47    test_draw=~isequal(AxeData.Drawing,'off');%=1 if mouse drawing of object is active
48end
[622]49test_zoom_draw=0;
[150]50test_object=0; %test for object editing or creation
[701]51test_create_object=0;
[681]52test_edit_object=0;% edit test for mouse shape: an arrow
[150]53test_ruler=0;%test for active ruler
[663]54test_transform=0;
[150]55huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle
[71]56if ~isempty(huvmat)
[432]57    hhuvmat=guidata(huvmat);%handles of the elements in uvma
[701]58    test_create_object=strcmp(get(hhuvmat.MenuObject,'checked'),'on');
[650]59    test_edit_object=get(hhuvmat.CheckEditObject,'Value');
[156]60    test_ruler=isequal(get(hhuvmat.MenuRuler,'checked'),'on');
[664]61    test_transform=~isequal(get(hhuvmat.TransformName,'Value'),1);
[150]62end
[231]63test_piv=0;
64if isfield(FigData,'CivHandle')
65    if ~ishandle(FigData.CivHandle)
66        delete(hObject)
[682]67        set(hCurrentFig,'Pointer','arrow');
[231]68        return
69    end
70    hhciv=guidata(FigData.CivHandle);
71    test_piv=1;
[150]72end
[11]73
[432]74%find the current axe 'CurrentAxes' and display the current mouse position or uicontrol tag
[11]75text_displ_1='';
76text_displ_2='';
77text_displ_3='';
78text_displ_4='';
79
[625]80% AxeData=[];%default
[67]81xy=[];%default
[741]82set(hCurrentFig,'Units','normalized')
[622]83xy_fig=get(hObject,'CurrentPoint');% current point of the current figure (gcbo)
[11]84pointershape='arrow';% default pointer is an arrow
[150]85
[432]86%% loop on all the objects in the current figure, detect whether the mouse is over a plot  axes
[622]87hchildren=get(hObject,'Children');%handles of all objects in the current figure
88check_visible=strcmp(get(hchildren,'Visible'),'on');% if visible='on', =0 otherwise
89hchildren=hchildren(check_visible); %kkep only the visible children
90PosChildren=get(hchildren,'Position');% set of object positions
91if iscell(PosChildren)% only one child
92    PosLength=cellfun('length',PosChildren);% set of vector lengths for object positions
93    hchildren=hchildren(PosLength==4);% keep only objects with position defined by a 4 element vector
94    PosChildren=cell2mat(PosChildren(PosLength==4));% convert cells to matrix of positions
95end
96if size(PosChildren,2)~=4
[682]97    set(hCurrentFig,'Pointer','arrow');
[622]98    return
99end
100xy_fig_mat=ones(size(PosChildren,1),1)*xy_fig;% mouse position set to a matrix
101check_pos=xy_fig_mat >= PosChildren(:,1:2) & xy_fig_mat <= PosChildren(:,1:2)+PosChildren(:,3:4);% compare object to mouse position
102ind_object=find(check_pos(:,1) & check_pos(:,2),1);% select the index of the (first) object under the mouse
103hchild=hchildren(ind_object);% corresponding object handle
[432]104CurrentAxes=[];
[622]105
106%if the mouse is over an axis, look at the data
[682]107htype=get(hchild,'Type');
108if strcmp(htype,'axes')
[622]109    CurrentAxes=hchild;
110    xy=get(CurrentAxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
111    test_zoom_draw=test_draw && isequal(AxeData.Drawing,'zoom')&& isfield(AxeData,'CurrentOrigin') && isequal(get(gcf,'SelectionType'),'normal');
112    test_object=test_draw && isfield(AxeData,'CurrentObject') && ~isempty(AxeData.CurrentObject) && ishandle(AxeData.CurrentObject);
[701]113    if CheckZoom
114           pointershape='zoom';
115    elseif CheckZoomFig
116            pointershape='zoomfig';
117    elseif ~test_edit_object  && ~test_ruler
[699]118        if CheckZoom
119           pointershape='zoom';
[701]120        elseif test_draw|| test_create_object
121            pointershape='crosshair';%set pointer with cross shape
[699]122        else
[701]123        pointershape='fullcross';%set pointer with large cross (default when mouse is over an axis)
[699]124        end
[622]125    end
[625]126    FigData=get(hCurrentFig,'UserData');
[622]127    tagaxes=get(CurrentAxes,'tag');
128    if isfield(FigData,tagaxes)
129        Field=FigData.(tagaxes);
130        if isfield(Field,'ListVarName')
131            [CellInfo,NbDimArray]=find_field_cells(Field);%analyse the physical fields contained in Field
132            text_displ_1='';
133            text_displ_2='';
134            text_displ_3='';
135            text_displ_4='';
136            text_displ_5='';
137            ivec=[];
138            xName='';
139            z=[];
140            for icell=1:numel(CellInfo)%look for all physical fields
141                if NbDimArray(icell)>=2 % select 2D field
142                    if  isfield(Field,'CoordMesh') && ~isempty(Field.CoordMesh)&& strcmp(CellInfo{icell}.CoordType,'scattered')%case of unstructured data
143                        X=Field.(Field.ListVarName{CellInfo{icell}.CoordIndex(end)});
144                        Y=Field.(Field.ListVarName{CellInfo{icell}.CoordIndex(end-1)});
145                        flag_vec=(X<(xy(1,1)+Field.CoordMesh/3) & X>(xy(1,1)-Field.CoordMesh/3)) & ...%flagx=1 for the vectors with x position selected by the mouse
146                            (Y<(xy(1,2)+Field.CoordMesh/3) & Y>(xy(1,2)-Field.CoordMesh/3));%f
147                        ivec=find(flag_vec,1);% search the (first) selected vector index ivec
148                        hhh=findobj(CurrentAxes,'Tag','vector_marker');
149                        if ~isempty(ivec)
150                            % mark the vectors with a circle in the absence of other operations
151                            if ~test_object && ~test_edit_object && ~test_ruler && ~CheckZoomFig
152                                pointershape='arrow'; %mouse indicates  the detection of a vector
153                                if isempty(hhh)
[625]154                                    set(0,'CurrentFigure',hCurrentFig)
155                                    set(hCurrentFig,'CurrentAxes',CurrentAxes)
[622]156                                    rectangle('Curvature',[1 1],...
157                                        'Position',[X(ivec)-Field.CoordMesh/2 Y(ivec)-Field.CoordMesh/2 Field.CoordMesh Field.CoordMesh],'EdgeColor','m',...
158                                        'LineStyle','-','Tag','vector_marker');
[251]159                                else
[622]160                                    set(hhh,'Visible','on')
161                                    set(hhh,'Position',[X(ivec)-Field.CoordMesh/2 Y(ivec)-Field.CoordMesh/2 Field.CoordMesh Field.CoordMesh])
[251]162                                end
[622]163                            end
164                            %display the field values
165                            for ivar=1:numel(CellInfo{icell}.VarIndex)
166                                VarName=Field.ListVarName{CellInfo{icell}.VarIndex(ivar)};
167                                VarVal=Field.(VarName)(ivec);
168                                var_text=[VarName '=' num2str(VarVal,4) ','];
169                                if isequal(ivar,CellInfo{icell}.CoordIndex(end))||isequal(ivar,CellInfo{icell}.CoordIndex(end-1))||isequal(ivar,CellInfo{icell}.CoordIndex(1))
170                                    text_displ_1=[text_displ_1 var_text];
171                                elseif (isfield(CellInfo{icell},'VarIndex_vector_x') && isequal(ivar,CellInfo{icell}.VarIndex_vector_x))||isequal(ivar,CellInfo{icell}.VarIndex_vector_y)||...
172                                        (isfield(CellInfo{icell},'VarIndex_vector_z') && isequal(ivar,CellInfo{icell}.VarIndex_vector_z))
173                                    text_displ_4=[text_displ_4 var_text];
174                                else
175                                    text_displ_5=[text_displ_5 var_text];
[105]176                                end
[61]177                            end
[622]178                        else
179                            if ~isempty(hhh)
180                                set(hhh,'Visible','off')
181                            end
[71]182                        end
[622]183                    elseif strcmp(CellInfo{icell}.CoordType,'grid') %structured coordinates
184                        yName=Field.ListVarName{CellInfo{icell}.CoordIndex(1)};
185                        xName=Field.ListVarName{CellInfo{icell}.CoordIndex(2)};
186                        y=Field.(yName);
187                        x=Field.(xName);
188                        VarName=Field.ListVarName{CellInfo{icell}.VarIndex(1)};
189                        nxy=size(Field.(VarName));
190                        MaxAY=max(y(1),y(end));
191                        MinAY=min(y(1),y(end));
192                        if (xy(1,1)>x(1))&(xy(1,1)<x(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY)
193                            indx0=1+round((nxy(2)-1)*(xy(1,1)-x(1))/(x(end)-x(1))); % index x of pixel
194                            indy0=1+round((nxy(1)-1)*(xy(1,2)-y(1))/(y(end)-y(1))); % index y of pixel
195                            if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1)
196                                text_displ_2=['i='  num2str(indx0) ',j=' num2str(indy0) ','];
197                                for ivar=1:numel(CellInfo{icell}.VarIndex)
198                                    VarName=Field.ListVarName{CellInfo{icell}.VarIndex(ivar)};
199                                    VarVal=Field.(VarName)(indy0,indx0,:);
200                                    var_text=[VarName '=' num2str(VarVal) ','];
201                                    text_displ_4=[text_displ_4 var_text];
202                                end
203                            end
[251]204                        end
205                    end
[622]206                end
207            end
208            % display the current x,y plot coordinates in the absence of detected vector
209            if isempty(ivec)
210                if isempty(xName)
211                    xName='x';
212                    yName='y';
213                end
214                text_displ_1=[xName '=' num2str(xy(1,1),4) ', ' yName '=' num2str(xy(1,2),4) ','];
215            end
216            %display the z coordinate if defined by the projection plane
[741]217            if isfield(Field,'ProjObjectType') && strcmp(Field.ProjObjectType,'plane') && isfield(Field,'ProjObjectCoord') && length(Field.ProjObjectCoord)>=3
[622]218                pos=[xy(1,1) xy(1,2) 0];
[741]219                if isfield(Field,'ProjObjectAngle')&&~isequal(Field.ProjObjectAngle,[0 0 0])
220                    om=norm(Field.ProjObjectAngle);%norm of rotation angle in radians
221                    OmAxis=Field.ProjObjectAngle/om; %unit vector marking the rotation axis
[622]222                    cos_om=cos(pi*om/180);
223                    sin_om=sin(pi*om/180);
224                    pos=[xy(1,1) xy(1,2) 0];
225                    pos=cos_om*pos+sin_om*cross(OmAxis,pos)+(1-cos_om)*(OmAxis*pos')*OmAxis;
226                end
[741]227               % pos=pos+[Field.ProjObjectCoord 0];
228               pos=pos+Field.ProjObjectCoord;
[622]229                text_displ_3=[text_displ_3 'x,y,z=' num2str(pos,4)];
230            end
231            %                     if ~isempty(z)
232            %                         text_displ_1=[text_displ_1 ' z=' num2str(z,4)];
233            %                     end
234            % case of PIV correlation display
235            if test_piv
236                par=read_GUI(hhciv.Civ1);
237                [dd,ind_pt]=min(abs(Field.X-xy(1,1))+abs(Field.Y-xy(1,2)));
238                xround=Field.X(ind_pt);
239                yround=Field.Y(ind_pt);
240                %                         par.Grid=[xround size(Field.A,1)-yround+1];
241                par.Grid=[xround yround];
242                % mark the correlation box with a rectangle
243                par.ImageA=Field.A;
244                par.ImageB=Field.B;
245                par.ImageHeight=size(par.ImageA,1);
246                par.ImageWidth=size(par.ImageA,2);
247                Param.Civ1=par;
248                ibx2=floor((par.CorrBoxSize(1)-1)/2);
249                iby2=floor((par.CorrBoxSize(2)-1)/2);
250                isx2=floor((par.SearchBoxSize(1)-1)/2);
251                isy2=floor((par.SearchBoxSize(2)-1)/2);
252                shiftx=par.SearchBoxShift(1);
253                shifty=par.SearchBoxShift(2);
254                hhh=findobj(CurrentAxes,'Tag','PIV_box_marker');
255                hhhh=findobj(CurrentAxes,'Tag','PIV_search_marker');
256                if isempty(hhh)
[625]257                    set(0,'CurrentFigure',hCurrentFig)
258                    set(hCurrentFig,'CurrentAxes',CurrentAxes)
[622]259                    rectangle('Curvature',[0 0],...
260                        'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2],'EdgeColor','m',...
261                        'LineStyle','-','Tag','PIV_box_marker');
262                    rectangle('Curvature',[0 0],...
263                        'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2],'EdgeColor','m',...
264                        'LineStyle','- -','Tag','PIV_search_marker');
265                else
266                    set(hhh,'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2])
267                    set(hhhh,'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2])
268                end
269                [Data,errormsg,result_conv]= civ_matlab(Param);
270                if ~isempty(errormsg)
271                    text_displ_5=errormsg;
272                else
273                    rangx(1)=-(isx2-ibx2)+shiftx;
274                    rangx(2)=isx2-ibx2+shiftx;
275                    rangy(1)=-(isy2-iby2)-shifty;
276                    rangy(2)=(isy2-iby2)-shifty;
277                    hcorr=[];
278                    if isfield(AxeData,'CurrentCorrImage')
279                        hcorr=AxeData.CurrentCorrImage;
280                        if ~ishandle(hcorr)
281                            hcorr=[];
[207]282                        end
[11]283                    end
[622]284                    if isempty(hcorr)
285                        corrfig=findobj(allchild(0),'tag','corrfig');
286                        if ~isempty(corrfig)
287                            set(0,'CurrentFigure',corrfig(1))
288                            AxeData.CurrentCorrImage=imagesc(rangx,-rangy,result_conv,[0 1]);
289                            AxeData.CurrentVector=line([0 Data.Civ1_U],[0 Data.Civ1_V],'Tag','vector');
290                            AxeData.TitleHandle=title(num2str(par.Grid));
291                            colorbar
292                            set(CurrentAxes,'UserData',AxeData)
293                            set(get(AxeData.CurrentCorrImage,'parent'),'YDir','normal')
[150]294                        end
[622]295                    else
296                        set(AxeData.CurrentCorrImage,'CData',result_conv)
297                        set(AxeData.CurrentCorrImage,'XData',rangx)
298                        set(AxeData.CurrentCorrImage,'YData',-rangy)
299                        set(AxeData.CurrentVector,'XData',[0 Data.Civ1_U],'YData',[0 Data.Civ1_V])
300                        set(AxeData.TitleHandle,'String',num2str(par.Grid))
[11]301                    end
302                end
[251]303            end
[11]304        end
305    end
306end
[292]307if ~isempty(text_displ_1)
[542]308    text_displ=[{text_displ_1};{text_displ_2};{text_displ_3};{text_displ_4};{text_displ_5}];
309    ind_blank=find(strcmp('',text_displ));
310    if ~isempty(ind_blank)
311        text_displ(ind_blank)=[];
312    end
[627]313    %set(handles.text_display,'String',text_displ)
314    set(htext_display,'String',text_displ)
[292]315else
[627]316   %set(handles.text_display,'String',get(handles.text_display,'UserData'))
317   set(htext_display,'String',get(handles.text_display,'UserData'))
[292]318end
[11]319
[71]320%%%%%%%%%%%%%
[622]321%% draw a zoom rectangle if checkZoomFig has been selected
[71]322if test_zoom_draw
[622]323   xy_rect=AxeData.CurrentOrigin;% mark the previous position from mouse down
[71]324   if ~isempty(xy_rect)
325        rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate
326        rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate
327        rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width
328        rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height
[622]329        if rect(3)>0 && rect(4)>0
330            if isfield(AxeData,'CurrentRectZoom')&& ~isempty(AxeData.CurrentRectZoom) && ishandle(AxeData.CurrentRectZoom)
[71]331                set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position
332            else
[622]333                AxeData.CurrentRectZoom=rectangle('Position',rect,'Tag','rect_zoom','EdgeColor','b');
[432]334                set(CurrentAxes,'UserData',AxeData)
[71]335            end
336        end
337   end
338end
339
[11]340%%%%%%%%%%%%%%%%%
[150]341%% create or modify an object
[682]342if strcmp(htype,'axes') && ~isempty(huvmat) && test_object
[432]343    UvData=get(huvmat,'UserData');
[11]344    PlotData=get(AxeData.CurrentObject,'UserData');
[432]345    if ~isfield(PlotData,'IndexObj')
[682]346        set(hCurrentFig,'Pointer','arrow');
[432]347        return
348    end
[622]349    ObjectData=UvData.ProjObject{PlotData.IndexObj};
[432]350    if isequal(hObject,huvmat)% if the mouse ifs over the GUI uvmat
[622]351        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')};
[432]352    else
[622]353        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject,'Value')};
[432]354    end
355    XYData=AxeData.CurrentOrigin;
356    if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin)
357        if strcmp(ObjectData.Type,'line')||strcmp(ObjectData.Type,'polyline')||strcmp(ObjectData.Type,'polygon')||strcmp(ObjectData.Type,'points')
358            ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];
359            % ObjectData.Coord(end,:)=xy(1,:);
360        elseif strcmp(ObjectData.Type,'rectangle')||strcmp(ObjectData.Type,'ellipse')||strcmp(ObjectData.Type,'volume')
[622]361                ObjectData.Coord=(AxeData.CurrentOrigin+xy(1,1:2))/2;% keep only the first point coordinate     
362                ObjectData.RangeX=abs(ObjectData.Coord(1,1)-xy(1,1));%rectangle width
363                ObjectData.RangeY=abs(ObjectData.Coord(1,2)-xy(1,2));%rectangle height
[432]364        elseif isequal(ObjectData.Type,'plane') %case of 'plane'
365            DX=(xy(1,1)-ObjectData.Coord(1,1));
366            DY=(xy(1,2)-ObjectData.Coord(1,2));
367            ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt
368            if isfield(ObjectData,'RangeX')
369                XMax=sqrt(DX*DX+DY*DY);
370                if XMax>max(ObjectData.RangeX)
371                    ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
[11]372                end
[432]373            end
[11]374        end
[432]375        plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m');
376        pointershape='crosshair';
[681]377    elseif test_edit_object && isequal(AxeData.Drawing,'translate')
[432]378        DX=xy(1,1)-XYData(1);%translation from initial position
379        DY=xy(1,2)-XYData(2);
380        ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX;
381        ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
382        plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m');
383        pointershape='fleur';
[681]384    elseif test_edit_object && isequal(AxeData.Drawing,'deform')
[432]385        ind_move=AxeData.CurrentIndex;
386        ObjectData.Coord(ind_move,1)=xy(1,1);
387        ObjectData.Coord(ind_move,2)=xy(1,2);
388        plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m');
389        pointershape='circle';
[11]390    end
[432]391end
[67]392
[150]393%% detect calibration points if the GUI geometry_calib is opened
[67]394h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
[682]395if strcmp(htype,'axes') && ~CheckZoom && ~isempty(h_geometry_calib)
[67]396    pointershape='crosshair';%default for geometry_calib: ready to create new points
397    hh_geometry_calib=guidata(h_geometry_calib);
[156]398    if  ~isempty(xy) && isfield(hh_geometry_calib,'ListCoord')
[67]399        h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
[657]400        data.Coord=get(h_ListCoord,'Data');
401        if isnumeric(data.Coord)&&~isempty(data.Coord)
[663]402            if test_transform
[738]403                XCoord=(data.Coord(:,1));
404                YCoord=(data.Coord(:,2));
[663]405            else
[738]406                XCoord=(data.Coord(:,4));
407                YCoord=(data.Coord(:,5));
[663]408            end
[432]409            xy=get(CurrentAxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
[67]410            if ~isempty(xy)
[432]411                xlim=get(CurrentAxes,'XLim');
[738]412%                 ind_range_x=abs((xlim(2)-xlim(1))/50);
[432]413                ylim=get(CurrentAxes,'YLim');
[738]414                ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/25;%defines the size of the circle marker
415%                 ind_range_y=abs((ylim(2)-ylim(1))/50);
416%                 ind_range=sqrt(ind_range_x*ind_range_y);
417                index_point=find((XCoord<xy(1,1)+ind_range/2) & (XCoord>xy(1,1)-ind_range/2) & ...%flagx=1 for the vectors with x position selected by the mouse
418                    (YCoord<xy(1,2)+ind_range/2) & (YCoord>xy(1,2)-ind_range/2),1);%find the first calibration point in the neighborhood of the mouse
[67]419                if ~isempty(index_point)
[738]420                    pointershape='arrow';% default pointer is an arrow
[78]421                end
422                hh=findobj('Tag','calib_points');%look for handle of calibration points
[738]423                if ~isempty(hh) && ~isempty(get(hh,'UserData')) %&& get(hh_geometry_calib.CheckEnableMouse,'Value')
424                    %set(hh,'UserData',index_point)
[173]425                    index_point=get(hh,'UserData');
[78]426                    XCoord(index_point)=xy(1,1);
427                    YCoord(index_point)=xy(1,2);
428                    set(hh,'XData',XCoord)
429                    set(hh,'YData',YCoord)
[738]430                end
[78]431                if ~isempty(index_point)
[738]432                    set(hh_geometry_calib.CoordLine,'String',num2str(index_point))
433                   % Data=get(h_ListCoord,'Data');
434%                     Data(:,6)=zeros(size(Data,1),1);
435%                     Data(index_point,6)=-1;%mrk the point on the GUI geometry_calib
436%                     set(h_ListCoord,'Data',Data);
[67]437                    hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle)
438                    if ~isempty(hhh)
[71]439                        set(hhh,'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range])
[657]440                    else
[738]441                        rectangle('Curvature',[1 1],...
442                            'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range],'EdgeColor','m',...
443                            'LineStyle','-','Tag','calib_marker');
[67]444                    end
[78]445                end
[67]446            end
447        end
448    end
449end
450
[150]451%% draw ruler
[156]452if test_ruler && isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'ruler')
453    if isfield(AxeData,'RulerHandle')
454        pointershape='crosshair'; %give  the mouse pointer a cross shape
455        RulerCoord=[AxeData.RulerCoord ;xy(1,1:2)]; %coordinates defining the ruler segment
456        set(AxeData.RulerHandle,'XData',RulerCoord(:,1));% updtate the x coordinates for the ruler graphic object
457        set(AxeData.RulerHandle,'YData',RulerCoord(:,2));% updtate the y coordinates for the ruler graphic object
458    end
[60]459end
[150]460
461%% update the mouse pointer
[699]462if strcmp(pointershape,'zoom')||strcmp(pointershape,'zoomfig')
463    CData=set_pointershape(pointershape);
464    set(hCurrentFig,'Pointer','custom','PointerShapeCData',CData,'PointerShapeHotSpot',[9 9])
465else
[625]466set(hCurrentFig,'Pointer',pointershape);
[699]467end
468
469function CData=set_pointershape(pointershape)
470        CData=ones(16,16);
471        [ind_x,ind_y]=meshgrid([1:16],[1:16]);
472        if strcmp(pointershape,'zoom')
473        radius=(ind_x-9).*(ind_x-9)+(ind_y-8.5).*(ind_y-9);
474        CData(radius<25 & radius>16)=2; %make white circle
475        CData(radius<16 | radius>40)=NaN; %make the centre transparent
476        CData(16,16)=1; CData(15,16)=2;
477        CData(15,15)=1; CData(14,15)=2;
478        CData(14,14)=1; CData(13,14)=2;
479        CData(13,13)=1; CData(12,13)=2;
480        elseif strcmp(pointershape,'zoomfig')
481            CData(:,1:3)=2;
482            CData(:,14:16)=2;
483                        CData(1:3,:)=2;
484            CData(14:16,:)=2;
485            CData(CData==1)=NaN;
486        end
Note: See TracBrowser for help on using the repository browser.