Home > functions > tool_box > select3d_dir > select3dtool.m

select3dtool

PURPOSE ^

SELECT3DTOOL A simple tool for interactively obtaining 3-D coordinates

SYNOPSIS ^

function select3dtool(arg)

DESCRIPTION ^

SELECT3DTOOL A simple tool for interactively obtaining 3-D coordinates 

 SELECT3DTOOL(FIG) Specify figure handle

 Example:
   surf(peaks);
   select3dtool;
   % click on surface

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function select3dtool(arg)
0002 %SELECT3DTOOL A simple tool for interactively obtaining 3-D coordinates
0003 %
0004 % SELECT3DTOOL(FIG) Specify figure handle
0005 %
0006 % Example:
0007 %   surf(peaks);
0008 %   select3dtool;
0009 %   % click on surface
0010 
0011 if nargin<1
0012    arg = gcf;
0013 end
0014 
0015 if ~ishandle(arg)
0016    feval(arg);
0017    return;
0018 end
0019 
0020 %% initialize gui %%
0021 fig = arg;
0022 figure(fig);
0023 
0024 uistate = uiclearmode(fig);
0025 [tool, htext] = createUI;
0026 hmarker1 = line('marker','o','markersize',10,'markerfacecolor','k','erasemode','xor','visible','off');
0027 hmarker2 = line('marker','o','markersize',10,'markerfacecolor','r','erasemode','xor','visible','off');
0028 
0029 state.uistate = uistate;
0030 state.text = htext;
0031 state.tool = tool;
0032 state.fig = fig;
0033 state.marker1 = hmarker1;
0034 state.marker2 = hmarker2;
0035 setappdata(fig,'select3dtool',state);
0036 setappdata(state.tool,'select3dhost',fig);
0037 
0038 set(fig,'windowbuttondownfcn','select3dtool(''click'')');
0039 
0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0041 function off
0042 
0043 state = getappdata(gcbf,'select3dtool');
0044 
0045 if ~isempty(state)
0046     delete(state.tool);
0047 end
0048 
0049 fig = getappdata(gcbf,'select3dhost');
0050 
0051 if ~isempty(fig) & ishandle(fig)
0052     state = getappdata(fig,'select3dtool');     
0053     uirestore(state.uistate);
0054     delete(state.marker1);
0055     delete(state.marker2);
0056 end
0057 
0058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0059 function click
0060 
0061 [p v vi] = select3d;
0062 state = getappdata(gcbf,'select3dtool');
0063 
0064 if ~ishandle(state.text)
0065     state.text = createUI;
0066 end
0067 
0068 if ~ishandle(state.marker1)
0069     state.marker1 = [];
0070 end
0071 
0072 if ~ishandle(state.marker2)
0073     state.marker2 = [];
0074 end
0075 
0076 setappdata(state.fig,'select3dtool',state);
0077 
0078 if isempty(v)
0079     v = [nan nan nan];
0080     vi = nan;
0081     set(state.marker2,'visible','off');
0082 else
0083     set(state.marker2,'visible','on','xdata',v(1),'ydata',v(2),'zdata',v(3));
0084 end
0085 
0086 if isempty(p)
0087     p = [nan nan nan];
0088     set(state.marker1,'visible','off');
0089 else
0090     set(state.marker1,'visible','on','xdata',p(1),'ydata',p(2),'zdata',p(3));
0091 end
0092 
0093 % Update tool and markers
0094 set(state.text,'string',createString(p(1),p(2),p(3),v(1),v(2),v(3),vi));
0095 
0096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0097 function [fig, h] = createUI
0098 
0099 pos = [200 200 200 200];
0100 
0101 % Create selection tool %
0102 fig = figure('handlevisibility','off','menubar','none','resize','off',...
0103     'numbertitle','off','name','Select 3-D Tool','position',pos,'deletefcn','select3dtool(''off'')');
0104 
0105 h = uicontrol('style','text','parent',fig,'string',createString(0,0,0,0,0,0,0),...
0106     'units','norm','position',[0 0 1 1],'horizontalalignment','left');
0107 
0108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0109 function [str] = createString(px,py,pz,vx,vy,vz,vi)
0110 
0111 str = sprintf('  Position:\n  X  %f\n  Y:  %f\n  Z:  %f  \n\n  Vertex:\n  X:  %f\n  Y:  %f\n  Z:  %f  \n\n  Vertex Index:\n  %d',px,py,pz,vx,vy,vz,vi);

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005