samer@47: function handles=scatui(fig2,plotfn,X,varargin) samer@47: % scatui - scat with interactive point clicking ui samer@47: % samer@47: % scatui :: samer@47: % handle ~'figure to do secondary plot', samer@47: % (natural->unit) ~'function to do secondary plot', samer@47: % [[N,E]] ~'array of N points in E-space' samer@47: % -> action handle. samer@47: % samer@47: % This does several things: samer@47: % 1. Plots 3d scatter plot as stereo pairs in fig 1 samer@47: % 2. Sets up stereo 3D cursor. samer@47: % 3. Sets up button click callbacks so you can samer@47: % click to select one of the points samer@47: % 4. Starts the whole thing rotating so you can samer@47: % see what shape it is without going cross-eyed samer@47: samer@47: % transpose if it looks appropriate samer@47: if size(X,1)<5, X=X'; end samer@47: if size(X,2)>2 samer@47: pick=@(t,o)pick3d(t,get(o,'XData'),get(o,'YData'),get(o,'ZData')); samer@47: curf=@(t,varargin)cursor3d(t(1:3),varargin{:}); samer@47: else samer@47: pick=@(t,o)pick3d(t,get(o,'XData'),get(o,'YData'),zeros(size(X,1),1)); samer@47: curf=@(t,varargin)cursor2d(t(1:2),varargin{:}); samer@47: end samer@47: samer@47: % do scat in current figure samer@47: handles=scat(X,varargin{:}); fig1=gcf; samer@47: curs=[]; samer@47: samer@47: % get info about scatter plot samer@47: set(handles,'ButtonDownFcn',@btndown); samer@47: samer@47: function btndown(obj,dummy) samer@47: r=get(get(obj,'Parent'),'CurrentPoint'); % get clicked point from axes samer@47: [x,i]=pick(r,obj); % find nearest point samer@47: if isempty(curs) samer@47: curs=curf(x); samer@47: else samer@47: curf(x,curs); % move cursor samer@47: end samer@47: % title(sprintf('pick: %d',i)); samer@47: figure(fig2); plotfn(i); % do plot in other figure samer@47: figure(fig1); drawnow; % return to this figure samer@47: end samer@47: end samer@47: samer@47: samer@47: