source: trunk/src/mouse_up.m @ 150

Last change on this file since 150 was 150, checked in by sommeria, 13 years ago

various corrections for plotting and using view_field and get_field. The current field of uvmat or view_field is now stored in the structure userdata.axes3. Introduction of live correlation to test PIV (civ1)

File size: 17.7 KB
Line 
1%'mouse_up': function  activated when the mouse button is released
2%------------------------------------------------------------------------
3% function mouse_up(hObject,eventdata,handles)
4% activated by the command:
5% set(hObject,'WindowButtonUpFcn',{'mouse_up'}),
6% where hObject is the handle of the figure
7
8%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
9%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
10%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
11%     This file is part of the toolbox UVMAT.
12%
13%     UVMAT is free software; you can redistribute it and/or modify
14%     it under the terms of the GNU General Public License as published by
15%     the Free Software Foundation; either version 2 of the License, or
16%     (at your option) any later version.
17%
18%     UVMAT is distributed in the hope that it will be useful,
19%     but WITHOUT ANY WARRANTY; without even the implied warranty of
20%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
22%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
23
24function mouse_up(hObject,eventdata,handles)
25MouseAction='none'; %default
26test_zoom=0;%default
27currentfig=hObject;
28hhcurrentfig=guidata(currentfig);
29test_zoom=get(hhcurrentfig.zoom,'Value');
30if ~exist('handles','var')
31   handles=get(gcbo,'UserData');
32end
33huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle
34if ~isempty(huvmat)
35    hhuvmat=guidata(huvmat);
36    UvData=get(huvmat,'UserData');
37    if isfield(UvData,'MouseAction')
38        MouseAction=UvData.MouseAction;% set the mouse action (edit, create objects...)
39    end
40%     test_zoom=get(hhuvmat.zoom,'Value');
41end
42currentfig=hObject;
43currentaxes=gca; %store the current axes handle
44AxeData=get(currentaxes,'UserData');
45
46test_drawing=0;%default
47
48%finalize the fabrication or the translation/deformation of an object and plot the corresponding projected field
49if ~isempty(huvmat) & isfield(AxeData,'Drawing') & ~isequal(AxeData.Drawing,'off') & isfield(AxeData,'CurrentObject')...
50           & ishandle(AxeData.CurrentObject)
51    xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
52    PlotData=get(AxeData.CurrentObject,'UserData');%get data attached to the current projection object 
53    IndexObj=PlotData.IndexObj;
54    ObjectData=UvData.Object{IndexObj};   
55    ObjectData.enable_plot=1;
56    if isequal(AxeData.Drawing,'translate')
57        XYData=AxeData.CurrentOrigin;
58        DX=xy(1,1)-XYData(1);%translation from initial position
59        DY=xy(1,2)-XYData(2);
60        ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX;
61        ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
62    elseif isequal(AxeData.Drawing,'deform')
63        ind_move=AxeData.CurrentIndex;
64        ObjectData.Coord(ind_move,1)=xy(1,1);
65        ObjectData.Coord(ind_move,2)=xy(1,2);
66    else   %creating object
67        if strcmp(ObjectData.Style,'line')||strcmp(ObjectData.Style,'polyline')||...
68                strcmp(ObjectData.Style,'polygon')||strcmp(ObjectData.Style,'points')
69            if isfield(AxeData,'ObjectCoord') && size(AxeData.ObjectCoord,2)==3
70              xy(1,3)=AxeData.ObjectCoord(1,3); % z coordinate of the mouse: to generalise ...
71            else
72                 xy(1,3)=0; % z coordinate set to 0 by default
73            end
74            if ~isequal(ObjectData.Coord,xy(1,:))
75                ObjectData.Coord=[ObjectData.Coord ;xy(1,:)];% append the coordiantes marked by the mouse to the eobject
76            end
77        elseif isequal(ObjectData.Style,'rectangle')||isequal(ObjectData.Style,'ellipse')||isequal(ObjectData.Style,'volume')
78            XYData=AxeData.CurrentOrigin;
79            ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
80            ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
81            ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
82            ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
83        elseif isequal(ObjectData.Style,'plane') %case of 'plane'
84            DX=(xy(1,1)-ObjectData.Coord(1,1));
85            DY=(xy(1,2)-ObjectData.Coord(1,2));
86            ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt
87            if isfield(ObjectData,'RangeX')
88                XMax=sqrt(DX*DX+DY*DY);
89                if XMax>max(ObjectData.RangeX)
90                    ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
91                end
92            end
93        end
94    end
95    %set(AxeData.CurrentObject,'UserData',ObjectData); %update the object properties
96    if strcmp(ObjectData.Style,'rectangle')||strcmp(ObjectData.Style,'ellipse')
97        NbDefPoint=1; 
98    elseif strcmp(ObjectData.Style,'line')|| strcmp(ObjectData.Style,'plane');
99        NbDefPoint=2;
100    else
101         NbDefPoint=3;
102    end
103   
104    %show object coordinates in the GUI set_object
105    h_set_object=findobj(allchild(0),'Tag','set_object');
106    hh_set_object=guidata(h_set_object);
107    set(hh_set_object.XObject,'String',num2str(ObjectData.Coord(:,1),4));
108    set(hh_set_object.YObject,'String',num2str(ObjectData.Coord(:,2),4));
109    set(hh_set_object.ZObject,'String',num2str(ObjectData.Coord(:,3),4));
110    if NbDefPoint<=2 || isequal(get(currentfig,'SelectionType'),'alt') ||...
111              strcmp(AxeData.Drawing,'translate') || strcmp(AxeData.Drawing,'deform');%stop drawing
112        AxeData.CurrentOrigin=[]; %suppress the current origin
113       if isequal(ObjectData.Style,'line') && size(ObjectData.Coord,1)<=1
114           AxeData.Drawing='off';
115           set(currentaxes,'UserData',AxeData);
116            return % line needs at leqst two points
117       end
118       if  ~isempty(ObjectData)
119             testmask=0;
120             hmask=findobj(huvmat,'Tag','makemask');
121             if ~isempty(hmask)
122                testmask=get(hmask,'Value');
123             end
124             if testmask
125                 PlotHandles=[];%do not project data on the object during mask creation
126             else
127                 PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
128             end
129            UvData.Object{IndexObj}=update_obj(UvData,IndexObj,ObjectData,PlotHandles);
130            if  isfield(UvData.Object{IndexObj},'PlotParam')
131                write_plot_param(PlotHandles,UvData.Object{IndexObj}.PlotParam); %update the display of plotting parameters for the current object
132            end   
133            set(hhuvmat.edit,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
134            set(hhuvmat.edit,'Value',1);%
135            set(hhuvmat.edit,'Enable','on');%
136            set(hhuvmat.MenuEditObject,'Enable','on');%
137            set(hhuvmat.MenuEdit,'Enable','on');%
138            UvData.MouseAction='edit_object'; % set the edit button to 'on'
139        end
140    else
141       AxeData.CurrentOrigin=[xy(1,1) xy(1,2)]; %the current point becomes the new current origin
142       test_drawing=1;%allow continuation of drawing object
143       UvData.Object{IndexObj}=ObjectData;
144    end
145    hother=findobj('Tag','deformpoint');%find all the deformpoints
146    set(hother,'Color','b');%reset all the deformpoints in 'blue'
147else
148    test_drawing=0;
149end
150%creation of a new zoom plot
151test_replot=0;
152if isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
153%         FigData=get(currentfig,'UserData');
154        hparentfig=currentfig;
155        %open or update a new zoom figure if a rectangle has been drawn
156        if ishandle(currentaxes);
157            if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom)
158                PosRect=get(AxeData.CurrentRectZoom,'Position');
159                if isfield(AxeData,'CurrentVec') & ishandle(AxeData.CurrentVec)
160                    delete(AxeData.CurrentVec)
161                end
162                hfig2=figure;%create new figure
163                set(hfig2,'name','zoom')
164                set(hfig2,'Units','normalized')
165                set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
166                map=colormap(currentaxes);
167                colormap(map);%transmit the current colormap to the zoom fig
168                get(handles.RootFile,'String')
169                set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
170                if test_replot==0
171                    set(hfig2,'Unit','normalized')
172                    set(hfig2,'KeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
173                    set(hfig2,'WindowButtonMotionFcn',{@mouse_motion,handles})%set mouse action function
174                    set(hfig2,'WindowButtonDownFcn',{@mouse_down})%set mouse click action function
175                    set(hfig2,'WindowButtonUpFcn',{@mouse_up,handles}) 
176                    set(hfig2,'DeleteFcn',{@close_fig,AxeData.CurrentRectZoom,'zoom'})
177                    set(hfig2,'UserData',AxeData.CurrentRectZoom)% record the parent object (zoom rectangle) in the new fig
178                    AxeData.ZoomAxes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure
179                    figure(hfig2)
180                    set(AxeData.ZoomAxes,'Position',[0.1300    0.1100    0.7750    0.8150])% standard axes position on a figure
181                    hcol=findobj(hparentfig,'Tag','Colorbar'); %look for colorbar axes
182                    if ~isempty(hcol)             
183                        hcol_new=colorbar;
184                        YTick=get(hcol,'YTick');
185                        YTicklabel=get(hcol,'Yticklabel'); 
186                        colbarlim=get(hcol,'YLim');
187                        newcolbarlim=get(hcol_new,'YLim');
188                        scale_bar=(newcolbarlim(2)-newcolbarlim(1))/(colbarlim(2)-colbarlim(1));               
189                        YTick_rescaled=newcolbarlim(1)+scale_bar*(YTick-colbarlim(1));
190                        set(hcol_new,'YTick',YTick_rescaled);
191                        set(hcol_new,'Yticklabel',YTicklabel);
192                    end
193                end
194                if ishandle(AxeData.ZoomAxes)
195                    hnew_rect=findobj(AxeData.ZoomAxes,'Tag','rect_zoom');
196                    if ~isempty(hnew_rect)
197                        delete(hnew_rect);
198                        ChildAxeData=get(AxeData.ZoomAxes,'UserData');
199                        ChildAxeData.CurrentRectZoom=[]; % no rect zoom in the new window
200                        ChildAxeData.Drawing='off';
201                        ChildAxeData.ParentRect=AxeData.CurrentRectZoom;%set the rectangle as a 'parent' associated to the new axes
202                        set(AxeData.ZoomAxes,'UserData',ChildAxeData);%update the AxeData of the new axes
203                        set(AxeData.ZoomAxes,'Xlim',[PosRect(1) PosRect(1)+PosRect(3)])
204                        set(AxeData.ZoomAxes,'Ylim',[PosRect(2) PosRect(2)+PosRect(4)])
205                    end
206                end
207            end
208        end
209end
210%zoom in by a factor 2 if no new figure is created
211if test_zoom
212    xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
213     if  isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
214        xlim=get(currentaxes,'XLim');
215        xlim_new(2)=0.5*xy(1,1)+0.5*xlim(2);
216        xlim_new(1)=0.5*xy(1,1)+0.5*xlim(1);
217        set(currentaxes,'XLim',xlim_new)
218        ylim=get(currentaxes,'YLim');
219        ylim_new(2)=0.5*xy(1,2)+0.5*ylim(2);
220        ylim_new(1)=0.5*xy(1,2)+0.5*ylim(1);
221        set(currentaxes,'YLim',ylim_new)
222        if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
223            hparentrect=AxeData.ParentRect;
224            xlim=get(currentaxes,'XLim');
225            ylim=get(currentaxes,'YLim');
226            rect([1 2])=[xlim(1) ylim(1)];
227            rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
228            set(hparentrect,'Position',rect)
229        end
230     %zoom out by a factor of 2 out when the right mouse button has been used
231     elseif isequal(get(currentfig,'SelectionType'),'alt'); %if right button has been pressed
232%             alpha=2; %zoom factor (zoom out by a factor 2)
233            xlim=get(currentaxes,'XLim');
234            xlim_new(1)=2*xlim(1)-xy(1,1);
235            xlim_new(2)=2*xlim(2)-xy(1,1);
236%             xlim_new(1)=(1+alpha)*xlim(1)/2+(1-alpha)*xlim(2)/2;
237%             xlim_new(2)=(1-alpha)*xlim(1)/2+(1+alpha)*xlim(2)/2;
238            ylim=get(currentaxes,'YLim');
239            ylim_new(1)=2*ylim(1)-xy(1,2);
240            ylim_new(2)=2*ylim(2)-xy(1,2);
241%             ylim_new(1)=(1+alpha)*ylim(1)/2+(1-alpha)*ylim(2)/2;
242%             ylim_new(2)=(1-alpha)*ylim(1)/2+(1+alpha)*ylim(2)/2;
243            if isfield(AxeData,'RangeX') && isfield(AxeData,'RangeY')
244                xlim_new(1)=max(AxeData.RangeX(1),xlim_new(1));
245                xlim_new(2)=min(AxeData.RangeX(2),xlim_new(2));
246                ylim_new(1)=max(AxeData.RangeY(1),ylim_new(1));
247                ylim_new(2)=min(AxeData.RangeY(2),ylim_new(2));
248                if isequal(xlim_new,AxeData.RangeX) && isequal(ylim_new,AxeData.RangeY)
249                    set(hhuvmat.zoom,'Value',0)
250                    set(hhuvmat.zoom,'BackgroundColor',[0.7 0.7 0.7])
251                    set(hhuvmat.FixedLimits,'Value',0)
252                    set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
253                end
254            end
255            set(currentaxes,'XLim',xlim_new)
256            set(currentaxes,'YLim',ylim_new)
257            %test whther zoom out is operating (to inactivate AxedAta
258            if ~isfield(AxeData,'CurrentXLim')|| ~isequal(xlim,AxeData.CurrentXLim)
259                AxeData.CurrentXLim=xlim;%
260            end
261            if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
262                hparentrect=AxeData.ParentRect;
263                xlim=get(currentaxes,'XLim');
264                ylim=get(currentaxes,'YLim');
265                rect([1 2])=[xlim(1) ylim(1)];
266                rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
267                set(hparentrect,'Position',rect)
268            end
269      end
270end
271
272% editing calibration point
273if ~test_zoom && strcmp(MouseAction,'calib')
274    h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
275    hh_geometry_calib=guidata(h_geometry_calib);
276    edit_test=get(hh_geometry_calib.edit_append,'Value');
277    hh=findobj(currentaxes,'Tag','calib_points');%look for handle of calibration points           
278    if ~isempty(hh) && edit_test
279        index_point=get(hh,'UserData');
280        set(hh,'UserData',[])%remove edit mode
281        h_ListCoord=hh_geometry_calib.ListCoord; %handles of the coordinate list
282        Coord=get(h_ListCoord,'String');
283%         val=get(h_ListCoord,'Value');
284        coord_str=Coord{index_point}; %current line (string)
285        k=findstr('|',coord_str);%find separator indices on the string
286        xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
287        if numel(k)>=3
288            coord_str=[coord_str(1:k(3)-1) '|    ' num2str(xy(1,1),4) '    |    ' num2str(xy(1,2),4)]; %update the pixel information while preserving phys coord
289        else
290            coord_str=[ '    |    '  '    |    '  '    |    ' num2str(xy(1,1),4) '    |    ' num2str(xy(1,2),4)];
291        end
292        Coord{index_point}=coord_str;       
293        set(h_ListCoord,'String',Coord)
294        data=read_geometry_calib(Coord);%transform char cell to numbers
295        set(hh,'XData',data.Coord(:,4))
296        set(hh,'YData',data.Coord(:,5))
297    end
298end
299
300% finalising ruler
301if strcmp(MouseAction,'ruler')
302    UvData.MouseAction='none';
303    UvData=rmfield(UvData,'RulerHandle');
304     xy=get(currentaxes,'CurrentPoint');
305    RulerCoord=[UvData.RulerCoord ;xy(1,1:2)];
306    set(huvmat,'UserData',UvData)
307    RulerCoord=diff(RulerCoord,1);
308    RulerCoord=RulerCoord(1)+i*RulerCoord(2);
309    distance=abs(RulerCoord);
310    azimuth=(180/pi)*angle(RulerCoord);
311    msgbox_uvmat('RULER','',['length: ' num2str(distance,3) ',  angle(degrees): ' num2str(azimuth,3)])
312    hruler=findobj(currentaxes,'Tag','ruler');
313    delete(hruler)
314    AxeData.Drawing='off';%stop current drawing a
315end
316
317
318%display the data of the current object selected with the mouse right click
319if isequal(get(currentfig,'SelectionType'),'alt') && ~test_zoom && (~isfield(AxeData,'Drawing')||~isequal(AxeData.Drawing,'create'))
320    hother=findobj('Tag','proj_object');%find all the proj objects
321    nbselect=0;
322    %test the existence of selected objects:
323    for iproj=1:length(hother);
324        iselect=isequal(get(hother(iproj),'Selected'),'on');%reset all the proj objects in 'blue' by default
325        nbselect=nbselect+iselect;
326    end
327    hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
328    set(hother,'Color','b');%reset all the proj objects in 'blue' by default
329    set(hother,'Selected','off')
330    hother=findobj('Tag','proj_object','Type','rectangle');
331    set(hother,'EdgeColor','b');
332    set(hother,'Selected','off')
333    hother=findobj('Tag','proj_object','Type','patch');
334    set(hother,'FaceColor','b');   
335    if isequal(get(gco,'Type'),'image')
336        currentobj=get(gco,'parent');%parent axes of the image
337    else
338        currentobj=gco;%default
339    end
340    if ((nbselect==0) && isequal(get(currentobj,'Type'),'axes')) || isequal(currentobj,huvmat)
341        currentfig=get(currentobj,'parent');
342        figname=get(currentfig,'name');
343        eval(['global Data_' figname])
344        eval(['Data_' figname '=get(currentobj,''UserData'')']);
345        evalin('base',['global Data_' figname])%make CurData global in the workspace
346        objtype=get(currentobj,'Type');
347        display(['UserData of ' objtype ':'])
348        evalin('base',['Data_' figname]) %display CurData in the workspace
349        commandwindow %brings the Matlab command window to the front
350    end
351end
352if test_drawing==0
353        AxeData.Drawing='off';%stop current drawing action
354end
355set(currentaxes,'UserData',AxeData);
356if ~isempty(huvmat)
357    set(huvmat,'UserData',UvData);
358end
359
360   
361
Note: See TracBrowser for help on using the repository browser.