[37] | 1 | function 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 | |
---|
| 43 | plot_marker = 0 ; |
---|
| 44 | for 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 |
---|
| 51 | end |
---|
| 52 | |
---|
| 53 | if nargin < 2 |
---|
| 54 | N=1; |
---|
| 55 | end |
---|
| 56 | |
---|
| 57 | if size(V,1) ~= 2 |
---|
| 58 | error('Array V should be 2xK') ; |
---|
| 59 | end |
---|
| 60 | |
---|
| 61 | % -------------------------------------------------------------------- |
---|
| 62 | % Do job |
---|
| 63 | % -------------------------------------------------------------------- |
---|
| 64 | |
---|
| 65 | fig = gcf ; |
---|
| 66 | is_hold = ishold(fig) ; |
---|
| 67 | hold on ; |
---|
| 68 | |
---|
| 69 | sel = [] ; |
---|
| 70 | h = [] ; |
---|
| 71 | for 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 |
---|
| 83 | end |
---|
| 84 | |
---|
| 85 | if ~is_hold |
---|
| 86 | hold off ; |
---|
| 87 | end |
---|
| 88 | |
---|
| 89 | if( plot_marker ) |
---|
| 90 | pause(.1); |
---|
| 91 | delete(h) ; |
---|
| 92 | end |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | |
---|