source: trunk/src/mouse_motion.m @ 1200

Last change on this file since 1200 was 1200, checked in by sommeria, 26 hours ago

bug repaired for civ image rescale

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