source: trunk/src/mouse_motion.m @ 827

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