source: trunk/src/mouse_down.m @ 72

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

civ3D updated: introduction of image size
imadoc2struct: reding of image size from the xml file
set_object, view_field and related functions: improvement of projection object editing
mouse: possibility of adjusting the calibrations points with the mouse

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