source: trunk/src/mouse_motion.m

Last change on this file was 1163, checked in by sommeria, 34 hours ago

SearchBoxSize? changed to SearchRange? in civ, possibility of a grid set by a netcdf file

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