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

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

Added original make3d

File size: 2.5 KB
Line 
1function sel = clickpoint(V,N,varargin)
2% CLICKPOINT  Select a point by clicking
3%   SEL = CLICKPOINT(V) let the user click a point in the current
4%   figure and returns the index v of the closest point (in Euclidean
5%   norm) in the collection V. The 2xK matrix V has a a column for
6%   each point.
7%
8%   The user can abort the operation by pressing any key. In this case
9%   the function returns the empty matrix.
10%
11%   CLICKPOINT(V,N) selects N points in a row. The user can stop the
12%   selection at any time by pressing any key. In this case the
13%   partial selection is returned. This can be used in combination
14%   with N=inf to get an arbitrary number of points.
15%
16%   CLICKPOINT(V,N,'Opt',val,...) accepts the following options:
17%
18%     'PlotMarker' [0]
19%       Put a marker as points are selected. The markers are
20%       deleted on exiting the function.
21%
22%   See also CLICK().
23
24% AUTORIGHTS
25% Copyright (C) 2006 Andrea Vedaldi
26%       
27% This file is part of VLUtil.
28%
29% VLUtil is free software; you can redistribute it and/or modify
30% it under the terms of the GNU General Public License as published by
31% the Free Software Foundation; either version 2, or (at your option)
32% any later version.
33%
34% This program is distributed in the hope that it will be useful,
35% but WITHOUT ANY WARRANTY; without even the implied warranty of
36% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37% GNU General Public License for more details.
38%
39% You should have received a copy of the GNU General Public License
40% along with this program; if not, write to the Free Software Foundation,
41% Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
42
43plot_marker = 0 ;
44for k=1:2:length(varargin)
45  switch lower(varargin{k})
46    case 'plotmarker'
47      plot_marker = varargin{k+1} ;
48    otherwise
49      error(['Uknown option ''', varargin{k}, '''.']) ;
50  end
51end
52
53if nargin < 2
54  N=1;
55end
56
57if size(V,1) ~= 2
58  error('Array V should be 2xK') ;
59end
60
61% --------------------------------------------------------------------
62%                                                               Do job
63% --------------------------------------------------------------------
64
65fig = gcf ;
66is_hold = ishold(fig) ;
67hold on ;
68
69sel = [] ;
70h = [] ;
71for n=1:N
72  P=click
73  if ~isempty( P )
74    d = (V(1,:)-P(1)).^2 + (V(2,:)-P(2)).^2;
75    [drop,v]=min(d(:)) ;   
76    if(plot_marker)
77      h=[h plot(V(1,v),V(2,v),'go')] ;
78    end
79    sel = [sel v] ;
80  else
81    return ;
82  end
83end
84
85if ~is_hold
86  hold off ; 
87end
88
89if( plot_marker )
90  pause(.1);
91  delete(h) ;
92end
93
94
95
Note: See TracBrowser for help on using the repository browser.