source: trunk/src/mouse_down.m @ 65

Last change on this file since 65 was 65, checked in by sommeria, 14 years ago

name_generator: remove unneeded indices at output
civ.m: & introduced at the end of system command lines (beginning by !) to allow matlab operations during civ in run mode
uvmat.m: debugging in dealing with projections
prove image pair movies superposed to velocity vectors
mouse: put circles along detected vectors

File size: 16.9 KB
RevLine 
[11]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)
25testzoom=0;%default
26MouseAction='none'; %default
27huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle which controls theoption of  mouse action
[60]28if isempty(huvmat)
29    return
[11]30end
[60]31hhuvmat=guidata(huvmat);%handles of elements in uvmat
32UvData=get(huvmat,'UserData');
33testzoom=get(hhuvmat.zoom,'Value');% get the mouse action from the uvmat GUI: options:
34if isfield(UvData,'MouseAction')
35    MouseAction=UvData.MouseAction;% get the mouse action from the uvmat GUI: options:
36end
37
[11]38test_create=~testzoom && (isequal(MouseAction,'create_object') || isequal(MouseAction,'create_mask'));
39%test_cal=get(handles.cal,'Value');
[65]40test_cal=strcmp(MouseAction,'calib');
41test_ruler=strcmp(MouseAction,'ruler');
42% menu_coord=get(hhuvmat.transform_fct,'String');
43% coord_choice=get(hhuvmat.transform_fct,'Value');
44% coord_type=menu_coord{coord_choice};
45test_edit=strcmp(MouseAction,'edit_object');
46test_edit_vect=strcmp(MouseAction,'edit_vect');
[11]47xdisplay=[];%default
48ydisplay=[];%default
49haxes=[];
50AxeData=[];%default
51
52%edit an existing point or line if found
53hcurrentobject=gco;% current object handle (selected by the mouse)
54hcurrentfig=gcbo;% current figure handle
[62]55fig_tag=get(hcurrentfig,'Tag');
[11]56tag_obj=get(gco,'Tag');
57xy=[];%default
58xy_fig=get(hcurrentfig,'CurrentPoint');% current point of the current figure (gcbo)
59hchild=get(hcurrentfig,'Children');%handles of all objects in the current figure
60% loop on all the objects in the current figure (selected by the last mouse click)
61for ichild=1:length(hchild)
62    obj_pos=get(hchild(ichild),'Position');%position of the object
63    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);
64        htype=get(hchild(ichild),'Type');%type of object child of the current figure
65        %if the mouse is over an axis, look at the data
66        if isequal(htype,'axes')
67            haxes=hchild(ichild);
68            xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
69            AxeData=get(haxes,'UserData');% data attached to the axis
70            AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin
71            if ~isequal(tag_obj,'proj_object') & ~test_create
72                x_mouse=xy(1,1);%default
73                y_mouse=xy(1,2);%default
74                u_mouse=[];
75                v_mouse=[];
76                w_mouse=[];
77                A_mouse=[];
78                c_text=[];
79                f_text=[];
80                ff_text=[];     
81                ivec=[];   
82                if isfield(AxeData,'X') & isfield(AxeData,'Y') & isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis
83                    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
84                      (AxeData.Y<(xy(1,2)+AxeData.Mesh/4) & AxeData.Y>(xy(1,2)-AxeData.Mesh/4));%f
85                    ivec=find(flag_vec);% search the selected vector index ivec
86                    if length(ivec)>0
87                        ivec=ivec(1);%choice the first selected vector if several are selected                       
88                    end
89                end
90            end
[60]91%         elseif isequal(get(hchild(ichild),'Visible'),'on')& ~isequal(get(hchild(ichild),'Style'),'frame')
92%            %FAIRE UNE OPTION D'AIDE AVEC BOUTON SOURIS DROIT (ALT)??
[11]93        end
94    end
95end
96test2D=0;
97if isfield(AxeData,'NbDim')
98    if isequal(AxeData.NbDim,2)
99        test2D=1;
100    end
101end
102if ~test2D     %desable  object creation and vector editing if NbDim different from 2
103    test_create=0;
104    test_edit_vect=0;
105end
106%delete the current zoom rectangle
107if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom)
108    delete(AxeData.CurrentRectZoom)
109    AxeData.CurrentRectZoom=[];
110end   
111
112if testzoom %&& ~test_create && ~test_edit && ~test_edit_vect && exist('xy','var')
113     AxeData.Drawing='zoom'; %initiate drawing mode
114     AxeData.CurrentObject=[];%unselect objects
115elseif ~isempty(huvmat)
116    %selection of an existing projection object
117    if  test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint'))
118        if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create'))
119            userdata=get(hcurrentobject,'UserData');
120            if ishandle(userdata)%the selected line depends on a parent line
121                AxeData.CurrentObject=userdata;% the parent object becomes the current one
122            else
123                AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one
124            end
125            ObjectData=get(AxeData.CurrentObject,'UserData');
126            if test_edit & isfield(ObjectData,'IndexObj')
127                hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
128                set(hother,'Color','b');%reset all the proj objects in 'blue' by default
129                set(hother,'Selected','off')
130                hother=findobj('Tag','proj_object','Type','rectangle');
131                set(hother,'EdgeColor','b');
132                set(hother,'Selected','off');
133                hother=findobj('Tag','proj_object','Type','image');
134                for iobj=1:length(hother)
135                       Acolor=get(hother(iobj),'CData');
136                       Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
137                       set(hother(iobj),'CData',Acolor);
138                end
139                hother=findobj('Tag','DeformPoint');
140                set(hother,'Color','b');
141                set(hother,'Selected','off')   
142                if isequal(get(AxeData.CurrentObject,'Type'),'line')
143                    set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color
144                elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle')
145                     set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color
146                end
147                if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject)
148                    for iobj=1:length(ObjectData.SubObject)
149                        hsub=ObjectData.SubObject(iobj);
150                        if isequal(get(hsub,'Type'),'rectangle')
151                            set(hsub,'EdgeColor','m'); %set the selected object to magenta color
152                        elseif isequal(get(hsub,'Type'),'image')
153                           Acolor=get(hsub,'CData');
154                           Acolor(:,:,1)=Acolor(:,:,3);
155                           set(hsub,'CData',Acolor);
156                        else
157                            set(hsub,'Color','m')
158                        end
159                    end
160                end
161                if isequal(tag_obj,'DeformPoint')
162                     set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color
163                end
164                IndexObj=ObjectData.IndexObj;
[61]165                set(hhuvmat.list_object_1,'Value',IndexObj);
166                set(hhuvmat.list_object_2,'Value',IndexObj);
[11]167                testdeform=0;
168                set(gcbo,'Pointer','circle');
169                AxeData.Drawing='deform';
170                if isequal(tag_obj,'DeformPoint')       
171                   if isfield(ObjectData,'DeformPoint')
172                       set(hcurrentobject,'Selected','on')
173                       for ipt=1:length(ObjectData.DeformPoint)
174                           if isequal(ObjectData.DeformPoint(ipt),hcurrentobject)
175                                AxeData.CurrentIndex=ipt;
176                                testdeform=1;
177                           end
178                       end
179                   end
180                end
181                if testdeform==0
182                    AxeData.Drawing='translate';
183                    set(AxeData.CurrentObject,'Selected','on')
184                    set(gcbo,'Pointer','fleur');
185                end
186            end
187        end
188    end
189    %  create new projection  object
190    if  test_create && ~isempty(xy) && ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create'))
191            ObjectData=read_set_object(UvData.sethandles);
192            ObjectData.Coord=[]; %reset previous object coordinates
193            ObjectData.Coord(1,1)=xy(1,1);
194            ObjectData.Coord(1,2)=xy(1,2);
195            ObjectData.Coord(1,3)=0;
196            if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3
197                 ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle
198            end
199            AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject
200            if isfield(UvData,'Object')
201                IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface
202            else
203                IndexObj=2;
204            end 
205            UvData.Object{IndexObj}=ObjectData;
206            UvData.Object{IndexObj}.HandlesDisplay(1)=AxeData.CurrentObject;
207            set(huvmat,'UserData',UvData)
[61]208            list_str=get(hhuvmat.list_object_1,'String');
[46]209            list_str{IndexObj}=[num2str(IndexObj) '-' ObjectData.Style];
[11]210            if ~isequal(list_str{end},'...')
211                 list_str{end+1}='...';
212            end
[61]213            set(hhuvmat.list_object_1,'String',list_str)
214            set(hhuvmat.list_object_2,'String',list_str)
[62]215            if strcmp(fig_tag,'view_field')%we are in view_field plot
216                  set(hhuvmat.list_object_1,'Value',IndexObj)
217            else%we are in uvmat plot
218                set(hhuvmat.list_object_2,'Value',IndexObj)
219            end
[11]220            PlotData=get(AxeData.CurrentObject,'UserData');
221            PlotData.IndexObj=IndexObj;
222            set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph
223            AxeData.Drawing='create';
224    end
225
226    % create calibration points if the GUI geometry_calib is opened
227    if test_cal & ~isempty(xy)
228        h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
229        hh_geometry_calib=guidata(h_geometry_calib);
230        h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
231        h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append');
232        if isequal(get(h_edit_append,'Value'),1)
[60]233            coord_value=get(hhuvmat.transform_fct,'Value');
234            if ~(isequal(coord_value,1)||isequal(coord_value,3)); %active only with no transform or px (no phys)
235                set(hhuvmat.transform_fct,'Value',1)
[11]236                set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off'
237                set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
238                uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
[60]239                return
[11]240            end
241%             if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates
242                strline=[ '    |    '  '    |    '  '    |    ' num2str(xy(1,1),4) '    |    ' num2str(xy(1,2),4)];
243%             else %phys cordinates
244%                 strline=[ num2str(xy(1,1),4) '    |    '  num2str(xy(1,2),4) '    |    0      |    '  '    |    ' ];
245%             end
246            Coord=get(h_ListCoord,'String');
247            val=get(h_ListCoord,'Value');
248            if isequal(Coord,{''})
249                val=0;
250            end
251            if length(Coord)>val
252                Coord(val+2:length(Coord)+1)=Coord(val+1:length(Coord));% push the list forward beyond the current point
253            end
254            Coord{val+1}=strline;
255            set(h_ListCoord,'String',Coord)
256            set(h_ListCoord,'Value',val+1)
257            geometry_calib('ListCoord_Callback',hObject,eventdata,hh_geometry_calib)
258            data=read_geometry_calib(Coord);
[65]259%             if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates
[11]260                XCoord=data.Coord(:,4);
261                YCoord=data.Coord(:,5);
[65]262%             else %phys cordinates
263%                 XCoord=data.Coord(:,1);
264%                 YCoord=data.Coord(:,2);
265%             end
[40]266            hh=findobj('Tag','calib_points');           
[11]267            if isempty(hh)
268                line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
269            else
270                set(hh,'XData',XCoord)
271                set(hh,'YData',YCoord)
272            end
273            hhh=findobj('Tag','calib_marker');
274            if ~isempty(hhh)
275                set(hhh,'XData',xy(1,1))
276                set(hhh,'YData',xy(1,2))
277            else
278                line(xy(1,1),xy(1,2),'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',20);
279            end
280            %uistack(h_geometry_calib,'top')
281        end
282    end
283
284    % edit vectors
285    if test_edit_vect & ~isempty(ivec)
286    %     FF_100=FF-100*double(uint(abs(FF)/100); %value of FF without units and dizaines
[35]287        if ~(isfield(AxeData,'FF')&& ~isempty(AxeData.FF))
[11]288            AxeData.FF=zeros(size(AxeData.X));
289        end
290        if isequal(AxeData.FF(ivec),0)
291            AxeData.FF(ivec)=100; %mark vector #ivec as false
292        else
293            AxeData.FF(ivec)=0;
294        end
[35]295        PlotParam=read_plot_param(hhuvmat);
296        [PlotType,ScalOut]= plot_field(AxeData,haxes,PlotParam,1);
[11]297    end   
[60]298   
299    %create ruler
300    if test_ruler
301        UvData.RulerCoord(1,1)=xy(1,1);
302        UvData.RulerCoord(1,2)=xy(1,2);
[61]303        UvData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler');
[60]304        set(huvmat,'UserData',UvData)
305    end
[11]306end
307set(haxes,'UserData',AxeData);
308
309%------------------------------------------------------
[35]310function update_plot(AxeData,haxes)
[11]311%--------------------------------------------
312
313
[35]314% %determine the axes of action of the set_edit interface
315% % haxes= findobj(huvmat,'Tag','axes3'); %main plotting axes as default
316% % AxeData=get(haxes,'UserData')
317% %For vector field representation
318% PlotHandles.auto_xy=findobj(huvmat,'Tag','auto_xy');
319% PlotHandles.VecScale=findobj(huvmat,'Tag','VecScale');
320% PlotHandles.AutoVec=findobj(huvmat,'Tag','AutoVec');
321% PlotHandles.checkyellow=findobj(huvmat,'Tag','checkyellow');
322% PlotHandles.checkblack=findobj(huvmat,'Tag','checkblack');
323% PlotHandles.col_vec=findobj(huvmat,'Tag','col_vec');
324% PlotHandles.colcode1=findobj(huvmat,'Tag','colcode1');
325% PlotHandles.colcode2=findobj(huvmat,'Tag','colcode2');
326% PlotHandles.vec_col_bar=findobj(huvmat,'Tag','vec_col_bar');
327% PlotHandles.slider1=findobj(huvmat,'Tag','slider1');
328% PlotHandles.slider2=findobj(huvmat,'Tag','slider2');
329% PlotHandles.max_vec=findobj(huvmat,'Tag','max_vec');
330% PlotHandles.min_vec=findobj(huvmat,'Tag','min_vec');
331% PlotHandles.AutoVecColor=findobj(huvmat,'Tag','AutoVecColor');
332% PlotHandles.decimate4=findobj(huvmat,'Tag','decimate4');
333%
334% %vectors
335% Vectors.VecScale=str2num(get(PlotHandles.VecScale,'String'));
336% Vectors.AutoVec=get(PlotHandles.AutoVec,'Value');%automatic vector length
337% Vectors.checkyellow=get(PlotHandles.checkyellow,'Value');
338% Vectors.checkblack=get(PlotHandles.checkblack,'Value');
339% Vectors.decimate4=get(PlotHandles.decimate4,'Value');% =1; for reducing the nbre of vectors
340% menu_col=get(PlotHandles.col_vec,'String');
341% menu_val=get(PlotHandles.col_vec,'Value');
342% Vectors.CName=menu_col{menu_val}; %'ima_cor','black','white',...
343% Vectors.colcode1=str2num(get(PlotHandles.colcode1,'String'));% first threshold for rgb, first value for'continuous'
344% Vectors.colcode2=str2num(get(PlotHandles.colcode2,'String'));% second threshold for rgb, last value (saturation) for 'continuous'
345% Vectors.option=get(PlotHandles.vec_col_bar,'Value'); % =1 (64 colors), =0 (3 colors)
346% Vectors.min=get(PlotHandles.slider1,'Min');
347% Vectors.max=get(PlotHandles.slider1,'Max');
348% Vectors.auto=get(PlotHandles.AutoVecColor,'Value');% =1; thresholds scaling relative to min and max, =0 fixed thresholds
349% PlotParam.Vectors=Vectors;
350
Note: See TracBrowser for help on using the repository browser.