source: trunk/src/mouse_down.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: 16.1 KB
Line 
1%'mouse_down': function activated when the mouse button is pressed on a figure (callback for 'WindowButtonDownFcn'
2%--------------------------------------------------------------
3% xy=mouse_down(hObject,eventdata)
4% activated by the command:
5% set(hObject,'WindowButtonDownFcn',{'mouse_down'}),
6% where hObject is the handle of the figure
7%
8%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
9%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
10%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
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%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
23
24function xy=mouse_down(hObject,eventdata)
25
26MouseAction='none'; %default
27huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle which controls theoption of  mouse action
28if isempty(huvmat)
29    return
30end
31hhuvmat=guidata(huvmat);%handles of elements in uvmat
32guihandles=guidata(hObject);
33UvData=get(huvmat,'UserData');
34MouseAction='none'; %default
35currentfig=hObject;
36hhcurrentfig=guidata(currentfig);
37test_zoom=get(hhcurrentfig.zoom,'Value')
38%test_zoom=get(guihandles.zoom,'Value');% get the mouse action from the uvmat GUI: options:
39if isfield(UvData,'MouseAction')
40    MouseAction=UvData.MouseAction;% get the mouse action from the uvmat GUI: options:
41end
42
43test_create=~test_zoom && (isequal(MouseAction,'create_object') || isequal(MouseAction,'create_mask'));
44%test_cal=get(handles.cal,'Value');
45test_cal=strcmp(MouseAction,'calib');
46test_ruler=strcmp(MouseAction,'ruler');
47test_edit=strcmp(MouseAction,'edit_object');
48test_edit_vect=strcmp(MouseAction,'edit_vect');
49xdisplay=[];%default
50ydisplay=[];%default
51AxeData=[];%default
52
53%edit an existing point or line if found
54hcurrentobject=gco;% current object handle (selected by the mouse)
55hcurrentfig=hObject;% current figure handle
56fig_tag=get(hcurrentfig,'Tag');
57tag_obj=get(gco,'Tag');
58xy=[];%default
59xy_fig=get(hcurrentfig,'CurrentPoint');% current point of the current figure (gcbo)
60hchild=get(hcurrentfig,'Children');%handles of all objects in the current figure
61haxes=[];
62% loop on all the objects in the current figure (selected by the last mouse click)
63for ichild=1:length(hchild)
64    obj_pos=get(hchild(ichild),'Position');%position of the object
65    if xy_fig(1) >=obj_pos(1) & xy_fig(2) >= obj_pos(2)& xy_fig(1) <=obj_pos(1)+obj_pos(3) & xy_fig(2) <= obj_pos(2)+obj_pos(4);
66        htype=get(hchild(ichild),'Type');%type of object child of the current figure
67        %if the mouse is over an axis, look at the data
68        if isequal(htype,'axes')
69            y_lim=get(hchild(ichild),'YLim');
70            x_lim=get(hchild(ichild),'XLim');
71            haxes=hchild(ichild);
72            xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
73            if xy(1,1)>x_lim(1) && xy(1,1)<x_lim(2) && xy(1,2)>y_lim(1) && xy(1,2)<y_lim(2)
74                AxeData=get(haxes,'UserData');% data attached to the axis
75                AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin
76                if ~isequal(tag_obj,'proj_object') & ~test_create
77                    x_mouse=xy(1,1);%default
78                    y_mouse=xy(1,2);%default
79                    u_mouse=[];
80                    v_mouse=[];
81                    w_mouse=[];
82                    A_mouse=[];
83                    c_text=[];
84                    f_text=[];
85                    ff_text=[];     
86                    ivec=[];   
87                    if isfield(AxeData,'X') & isfield(AxeData,'Y') & isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis
88                        flag_vec=(AxeData.X<(xy(1,1)+AxeData.Mesh/4) & AxeData.X>(xy(1,1)-AxeData.Mesh/4)) & ...%flagx=1 for the vectors with x position selected by the mouse
89                          (AxeData.Y<(xy(1,2)+AxeData.Mesh/4) & AxeData.Y>(xy(1,2)-AxeData.Mesh/4));%f
90                        ivec=find(flag_vec,1);% search the (first) selected vector index ivec
91                    end
92                end
93            else
94                haxes=[];%mouse out of axes
95            end
96        end
97    end
98end
99test2D=0;
100if isfield(AxeData,'NbDim')
101    if isequal(AxeData.NbDim,2)
102        test2D=1;
103    end
104end
105if ~test2D     %desable  object creation and vector editing if NbDim different from 2
106    test_create=0;
107    test_edit_vect=0;
108end
109%delete the current zoom rectangle
110if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom)
111    delete(AxeData.CurrentRectZoom)
112    AxeData.CurrentRectZoom=[];
113end   
114
115% zoom has first priority
116if test_zoom %&& ~test_create && ~test_edit && ~test_edit_vect && exist('xy','var')
117     AxeData.Drawing='zoom'; %initiate drawing mode
118     AxeData.CurrentObject=[];%unselect objects
119     set(haxes,'UserData',AxeData);
120     return
121end
122if isempty(huvmat)
123    return
124end
125
126%ruler has second priority
127if test_ruler
128    UvData.RulerCoord(1,1)=xy(1,1);
129    UvData.RulerCoord(1,2)=xy(1,2);
130    UvData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler');
131    set(huvmat,'UserData',UvData)
132    AxeData.Drawing='ruler';
133    set(haxes,'UserData',AxeData);
134    return
135end
136
137%selection of an existing projection object
138if  test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint'))
139    if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create'))
140        userdata=get(hcurrentobject,'UserData');
141        if ishandle(userdata)%the selected line depends on a parent line
142            AxeData.CurrentObject=userdata;% the parent object becomes the current one
143        else
144            AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one
145        end
146        ObjectData=get(AxeData.CurrentObject,'UserData');
147        if test_edit && isfield(ObjectData,'IndexObj')
148            hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
149            set(hother,'Color','b');%reset all the proj objects in 'blue' by default
150            set(hother,'Selected','off')
151            hother=findobj('Tag','proj_object','Type','rectangle');
152            set(hother,'EdgeColor','b');
153            set(hother,'Selected','off');
154            hother=findobj('Tag','proj_object','Type','image');
155            for iobj=1:length(hother)
156                   Acolor=get(hother(iobj),'CData');
157                   Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
158                   set(hother(iobj),'CData',Acolor);
159            end
160            hother=findobj('Tag','DeformPoint');
161            set(hother,'Color','b');
162            set(hother,'Selected','off')   
163            if isequal(get(AxeData.CurrentObject,'Type'),'line')
164                set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color
165            elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle')
166                 set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color
167            end
168            if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject)
169                for iobj=1:length(ObjectData.SubObject)
170                    hsub=ObjectData.SubObject(iobj);
171                    if isequal(get(hsub,'Type'),'rectangle')
172                        set(hsub,'EdgeColor','m'); %set the selected object to magenta color
173                    elseif isequal(get(hsub,'Type'),'image')
174                       Acolor=get(hsub,'CData');
175                       Acolor(:,:,1)=Acolor(:,:,3);
176                       set(hsub,'CData',Acolor);
177                    else
178                        set(hsub,'Color','m')
179                    end
180                end
181            end
182            if isequal(tag_obj,'DeformPoint')
183                 set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color
184            end
185            IndexObj=ObjectData.IndexObj;
186                    %indicate on the list of the GUI uvmat which object has been selected
187            if strcmp(get(hcurrentfig,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field
188                set(hhuvmat.list_object_2,'Value',IndexObj);
189                list_str=get(hhuvmat.list_object_2,'String');
190                UvData.Object{IndexObj}.Name=list_str{IndexObj};
191            else
192                set(hhuvmat.list_object_1,'Value',IndexObj);
193                list_str=get(hhuvmat.list_object_1,'String');
194                UvData.Object{IndexObj}.Name=list_str{IndexObj};
195            end
196            h_set_object=findobj(allchild(0),'Tag','set_object');
197            if ~isempty(h_set_object)
198                delete(h_set_object)
199            end
200            set_object(UvData.Object{IndexObj})
201            axes(haxes);%set back the current axes haxes
202            testdeform=0;
203            set(gcbo,'Pointer','circle');
204            AxeData.Drawing='deform';
205            if isequal(tag_obj,'DeformPoint')       
206               if isfield(ObjectData,'DeformPoint')
207                   set(hcurrentobject,'Selected','on')
208                   for ipt=1:length(ObjectData.DeformPoint)
209                       if isequal(ObjectData.DeformPoint(ipt),hcurrentobject)
210                            AxeData.CurrentIndex=ipt;
211                            testdeform=1;
212                       end
213                   end
214               end
215            end
216            if testdeform==0
217                AxeData.Drawing='translate';
218                set(AxeData.CurrentObject,'Selected','on')
219                set(gcbo,'Pointer','fleur');
220            end
221        end
222    end
223end
224%  create new projection  object
225if  test_create && ~isempty(xy) && ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create'))
226        ObjectData=read_set_object(UvData.sethandles);
227        ObjectData.Coord=[]; %reset previous object coordinates
228        ObjectData.Coord(1,1)=xy(1,1);
229        ObjectData.Coord(1,2)=xy(1,2);
230        ObjectData.Coord(1,3)=0;
231        if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3
232             ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle
233        end
234        AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject
235        if isfield(UvData,'Object')
236            IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface
237        else
238            IndexObj=2;
239        end 
240        UvData.Object{IndexObj}=ObjectData;
241        UvData.Object{IndexObj}.HandlesDisplay(1)=AxeData.CurrentObject;
242        set(huvmat,'UserData',UvData)
243        list_str=get(hhuvmat.list_object_1,'String');
244        object_name=get(UvData.sethandles.TITLE,'String')
245        if isempty(object_name)|| strcmp(object_name,'')
246            list_str{IndexObj}=[num2str(IndexObj) '-' ObjectData.Style];
247            set(UvData.sethandles.TITLE,'String',list_str{IndexObj})
248        else
249           list_str{IndexObj}=object_name;
250        end
251        set(hhuvmat.list_object_1,'String',list_str)
252        list_str{end+1}='...';
253        set(hhuvmat.list_object_2,'String',list_str)
254        if strcmp(fig_tag,'view_field')%we are in view_field plot
255              set(hhuvmat.list_object_1,'Value',IndexObj)% the projection field will be plotted in uvmat frame
256        else%we are in uvmat plot
257            set(hhuvmat.list_object_2,'Value',IndexObj)
258        end
259        PlotData=get(AxeData.CurrentObject,'UserData');
260        PlotData.IndexObj=IndexObj;
261        set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph
262        AxeData.Drawing='create';
263end
264
265% create calibration points if the GUI geometry_calib is opened, if the main axes axes3 of uvmat has ben selected
266if ~test_zoom && test_cal && ~isempty(haxes) && strcmp(get(haxes,'tag'),'axes3')
267    h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
268    hh_geometry_calib=guidata(h_geometry_calib);
269    h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
270    h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append');
271    if isequal(get(h_edit_append,'Value'),1) && ~isempty(haxes)
272        coord_value=get(hhuvmat.transform_fct,'Value');% set uvmat to pixel coordinates, run it again if not
273        if ~(isequal(coord_value,1)||isequal(coord_value,3)); %active only with no transform or px (no phys)
274            set(hhuvmat.transform_fct,'Value',1)
275            uvmat('transform_fct_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
276            set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off'
277            set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
278            return
279        end
280        Coord=get(h_ListCoord,'String');
281        data=read_geometry_calib(Coord);%transform char cell to numbers
282        xlim=get(haxes,'XLim');
283        ind_range_x=abs((xlim(2)-xlim(1))/50);
284        ylim=get(haxes,'YLim');
285        ind_range_y=abs((ylim(2)-ylim(1))/50);
286        ind_range=sqrt(ind_range_x*ind_range_y);
287        test_newpoint=1;
288        if size(data.Coord,2)>=5 %if calibration points already exist
289            XCoord=(data.Coord(:,4));
290            YCoord=(data.Coord(:,5));
291            index_point=find((XCoord<xy(1,1)+ind_range) & (XCoord>xy(1,1)-ind_range) & ...%flagx=1 for the vectors with x position selected by the mouse
292                          (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse
293            test_newpoint=isempty(index_point);%test for no existing calibration point near the mouse position
294        end
295        val=get(h_ListCoord,'Value');
296        %create a new calib point if we are not close to an existing one
297        if test_newpoint                 
298             strline=[ '    |    '  '    |    '  '    |    ' num2str(xy(1,1),4) '    |    ' num2str(xy(1,2),4)];
299           
300             if length(Coord)>=val
301                 Coord(val+1:length(Coord)+1)=Coord(val:length(Coord));% push the list forward beyond the current point
302             end
303             Coord{val}=strline;
304             set(h_ListCoord,'String',Coord)
305            % set(h_ListCoord,'Value',val+1)
306             data=read_geometry_calib(Coord);%transform char cell to numbers
307             XCoord=data.Coord(:,4);
308             YCoord=data.Coord(:,5);
309        end
310        hh=findobj('Tag','calib_points');%look for handle of calibration points           
311        if isempty(hh)
312            hh=line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
313        else
314            set(hh,'XData',XCoord)
315            set(hh,'YData',YCoord)
316        end
317        set(hh,'UserData',val)% flag the points to edit mode
318        hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle)
319        if ~isempty(hhh)
320            set(hhh,'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range])
321        else
322            rectangle('Curvature',[1 1],...
323                  'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range],'EdgeColor','m',...
324                  'LineStyle','-','Tag','calib_marker');
325           % line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',ind_range);
326        end
327        AxeData.Drawing='calibration';
328    end
329end
330
331% edit vectors
332if test_edit_vect & ~isempty(ivec)
333    if ~(isfield(AxeData,'FF')&& ~isempty(AxeData.FF))
334        AxeData.FF=zeros(size(AxeData.X));
335    end
336    if isequal(AxeData.FF(ivec),0)
337        AxeData.FF(ivec)=100; %mark vector #ivec as false
338    else
339        AxeData.FF(ivec)=0;
340    end
341    PlotParam=read_plot_param(hhuvmat);
342    [PlotType,ScalOut]= plot_field(AxeData,haxes,PlotParam,1);
343end   
344set(haxes,'UserData',AxeData);
345
Note: See TracBrowser for help on using the repository browser.