source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/vlutil/toolbox/click.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 3.0 KB
Line 
1function P = click(N,varargin) ;
2% CLICK  Click a point
3%  P=CLICK() let the user click a point in the current figure and
4%  returns its coordinates in P. The user can abort the operation
5%  by pressing any key, in which case the empty matrix is returned.
6%
7%  P=CLICK(N) lets the user select N points in a row. The user can
8%  stop inserting points by pressing any key, in which case the
9%  partial list is returned.
10%
11%  CLICK(V,N,'Opt',val,...) accepts the following options:
12%
13%    'PlotMarker' [0]
14%      Put a marker as points are selected. The markers are
15%      deleted on exiting the function.
16%
17%  See also CLICKPOINT().
18
19% AUTORIGHTS
20% Copyright (C) 2006 Andrea Vedaldi
21%       
22% This file is part of VLUtil.
23%
24% VLUtil is free software; you can redistribute it and/or modify
25% it under the terms of the GNU General Public License as published by
26% the Free Software Foundation; either version 2, or (at your option)
27% any later version.
28%
29% This program is distributed in the hope that it will be useful,
30% but WITHOUT ANY WARRANTY; without even the implied warranty of
31% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32% GNU General Public License for more details.
33%
34% You should have received a copy of the GNU General Public License
35% along with this program; if not, write to the Free Software Foundation,
36% Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
37
38plot_marker = 0 ;
39for k=1:2:length(varargin)
40  switch lower(varargin{k})
41    case 'plotmarker'
42      plot_marker = varargin{k+1} ;
43    otherwise
44      error(['Uknown option ''', varargin{k}, '''.']) ;
45  end
46end
47
48if nargin < 1
49  N=1;
50end
51
52% --------------------------------------------------------------------
53%                                                               Do job
54% --------------------------------------------------------------------
55
56fig = gcf ;
57
58is_hold = ishold ;
59hold on ;
60
61bhandler = get(fig,'WindowButtonDownFcn') ;
62khandler = get(fig,'KeyPressFcn') ;
63pointer  = get(fig,'Pointer') ;
64
65set(fig,'WindowButtonDownFcn',@click_handler) ;
66set(fig,'KeyPressFcn',@key_handler) ;
67set(fig,'Pointer','crosshair') ;
68
69P=[] ;
70h=[] ;
71data.exit=0;
72guidata(fig,data) ;
73while size(P,2) < N
74  uiwait(fig) ;
75  data = guidata(fig) ;
76  if(data.exit)
77    break ;
78  end
79  P = [P data.P] ;
80  if( plot_marker )
81    h=[h plot(data.P(1),data.P(2),'rx')] ;
82  end
83end
84 
85if ~is_hold
86  hold off ; 
87end
88
89if( plot_marker )
90  pause(.1);
91  delete(h) ;
92end
93
94set(fig,'WindowButtonDownFcn',bhandler) ;
95set(fig,'KeyPressFcn',khandler) ;
96set(fig,'Pointer',pointer) ;
97
98% ====================================================================
99function click_handler(obj,event)
100% --------------------------------------------------------------------
101data = guidata(gcbo) ;
102
103P = get(gca, 'CurrentPoint') ;
104P = [P(1,1); P(1,2)] ;
105
106data.P = P ;
107guidata(obj,data) ;
108uiresume(gcbo) ;
109
110% ====================================================================
111function key_handler(obj,event)
112% --------------------------------------------------------------------
113data = guidata(gcbo) ;
114data.exit = 1 ;
115guidata(obj,data) ;
116uiresume(gcbo) ;
Note: See TracBrowser for help on using the repository browser.