Daniel@0: function [h,yy,zz] = arrow(varargin) Daniel@0: % ARROW Draw a line with an arrowhead. Daniel@0: % Daniel@0: % ARROW(Start,Stop) draws a line with an arrow from Start to Stop (points Daniel@0: % should be vectors of length 2 or 3, or matrices with 2 or 3 Daniel@0: % columns), and returns the graphics handle of the arrow(s). Daniel@0: % Daniel@0: % ARROW uses the mouse (click-drag) to create an arrow. Daniel@0: % Daniel@0: % ARROW DEMO & ARROW DEMO2 show 3-D & 2-D demos of the capabilities of ARROW. Daniel@0: % Daniel@0: % ARROW may be called with a normal argument list or a property-based list. Daniel@0: % ARROW(Start,Stop,Length,BaseAngle,TipAngle,Width,Page,CrossDir) is Daniel@0: % the full normal argument list, where all but the Start and Stop Daniel@0: % points are optional. If you need to specify a later argument (e.g., Daniel@0: % Page) but want default values of earlier ones (e.g., TipAngle), Daniel@0: % pass an empty matrix for the earlier ones (e.g., TipAngle=[]). Daniel@0: % Daniel@0: % ARROW('Property1',PropVal1,'Property2',PropVal2,...) creates arrows with the Daniel@0: % given properties, using default values for any unspecified or given as Daniel@0: % 'default' or NaN. Some properties used for line and patch objects are Daniel@0: % used in a modified fashion, others are passed directly to LINE, PATCH, Daniel@0: % or SET. For a detailed properties explanation, call ARROW PROPERTIES. Daniel@0: % Daniel@0: % Start The starting points. B Daniel@0: % Stop The end points. /|\ ^ Daniel@0: % Length Length of the arrowhead in pixels. /|||\ | Daniel@0: % BaseAngle Base angle in degrees (ADE). //|||\\ L| Daniel@0: % TipAngle Tip angle in degrees (ABC). ///|||\\\ e| Daniel@0: % Width Width of the base in pixels. ////|||\\\\ n| Daniel@0: % Page Use hardcopy proportions. /////|D|\\\\\ g| Daniel@0: % CrossDir Vector || to arrowhead plane. //// ||| \\\\ t| Daniel@0: % NormalDir Vector out of arrowhead plane. /// ||| \\\ h| Daniel@0: % Ends Which end has an arrowhead. //<----->|| \\ | Daniel@0: % ObjectHandles Vector of handles to update. / base ||| \ V Daniel@0: % E angle||<-------->C Daniel@0: % ARROW(H,'Prop1',PropVal1,...), where H is a |||tipangle Daniel@0: % vector of handles to previously-created arrows ||| Daniel@0: % and/or line objects, will update the previously- ||| Daniel@0: % created arrows according to the current view -->|A|<-- width Daniel@0: % and any specified properties, and will convert Daniel@0: % two-point line objects to corresponding arrows. ARROW(H) will update Daniel@0: % the arrows if the current view has changed. Root, figure, or axes Daniel@0: % handles included in H are replaced by all descendant Arrow objects. Daniel@0: % Daniel@0: % A property list can follow any specified normal argument list, e.g., Daniel@0: % ARROW([1 2 3],[0 0 0],36,'BaseAngle',60) creates an arrow from (1,2,3) to Daniel@0: % the origin, with an arrowhead of length 36 pixels and 60-degree base angle. Daniel@0: % Daniel@0: % The basic arguments or properties can generally be vectorized to create Daniel@0: % multiple arrows with the same call. This is done by passing a property Daniel@0: % with one row per arrow, or, if all arrows are to have the same property Daniel@0: % value, just one row may be specified. Daniel@0: % Daniel@0: % You may want to execute AXIS(AXIS) before calling ARROW so it doesn't change Daniel@0: % the axes on you; ARROW determines the sizes of arrow components BEFORE the Daniel@0: % arrow is plotted, so if ARROW changes axis limits, arrows may be malformed. Daniel@0: % Daniel@0: % This version of ARROW uses features of MATLAB 5 and is incompatible with Daniel@0: % earlier MATLAB versions (ARROW for MATLAB 4.2c is available separately); Daniel@0: % some problems with perspective plots still exist. Daniel@0: Daniel@0: % Copyright (c)1995-1997, Erik A. Johnson , 8/14/97 Daniel@0: Daniel@0: % Revision history: Daniel@0: % 8/14/97 EAJ Added workaround for MATLAB 5.1 scalar logical transpose bug. Daniel@0: % 7/21/97 EAJ Fixed a few misc bugs. Daniel@0: % 7/14/97 EAJ Make arrow([],'Prop',...) do nothing (no old handles) Daniel@0: % 6/23/97 EAJ MATLAB 5 compatible version, release. Daniel@0: % 5/27/97 EAJ Added Line Arrows back in. Corrected a few bugs. Daniel@0: % 5/26/97 EAJ Changed missing Start/Stop to mouse-selected arrows. Daniel@0: % 5/19/97 EAJ MATLAB 5 compatible version, beta. Daniel@0: % 4/13/97 EAJ MATLAB 5 compatible version, alpha. Daniel@0: % 1/31/97 EAJ Fixed bug with multiple arrows and unspecified Z coords. Daniel@0: % 12/05/96 EAJ Fixed one more bug with log plots and NormalDir specified Daniel@0: % 10/24/96 EAJ Fixed bug with log plots and NormalDir specified Daniel@0: % 11/13/95 EAJ Corrected handling for 'reverse' axis directions Daniel@0: % 10/06/95 EAJ Corrected occasional conflict with SUBPLOT Daniel@0: % 4/24/95 EAJ A major rewrite. Daniel@0: % Fall 94 EAJ Original code. Daniel@0: Daniel@0: % Things to be done: Daniel@0: % - segment parsing, computing, and plotting into separate subfunctions Daniel@0: % - change computing from Xform to Camera paradigms Daniel@0: % + this will help especially with 3-D perspective plots Daniel@0: % + if the WarpToFill section works right, remove warning code Daniel@0: % + when perpsective works properly, remove perspective warning code Daniel@0: % - add cell property values and struct property name/values (like get/set) Daniel@0: % - get rid of NaN as the "default" data label Daniel@0: % + perhaps change userdata to a struct and don't include (or leave Daniel@0: % empty) the values specified as default; or use a cell containing Daniel@0: % an empty matrix for a default value Daniel@0: % - add functionality of GET to retrieve current values of ARROW properties Daniel@0: Daniel@0: % Many thanks to Keith Rogers for his many excellent Daniel@0: % suggestions and beta testing. Check out his shareware package MATDRAW. Daniel@0: % He has permission to distribute ARROW with MATDRAW. Daniel@0: Daniel@0: % global variable initialization Daniel@0: global ARROW_PERSP_WARN ARROW_STRETCH_WARN ARROW_AXLIMITS Daniel@0: if isempty(ARROW_PERSP_WARN ), ARROW_PERSP_WARN =1; end; Daniel@0: if isempty(ARROW_STRETCH_WARN), ARROW_STRETCH_WARN=1; end; Daniel@0: Daniel@0: % Handle callbacks Daniel@0: if (nargin>0 & isstr(varargin{1}) & strcmp(lower(varargin{1}),'callback')), Daniel@0: arrow_callback(varargin{2:end}); return; Daniel@0: end; Daniel@0: Daniel@0: % Are we doing the demo? Daniel@0: c = sprintf('\n'); Daniel@0: if (nargin==1 & isstr(varargin{1})), Daniel@0: arg1 = lower(varargin{1}); Daniel@0: if strncmp(arg1,'prop',4), arrow_props; Daniel@0: elseif strncmp(arg1,'demo',4) Daniel@0: clf reset Daniel@0: demo_info = arrow_demo; Daniel@0: if ~strncmp(arg1,'demo2',5), Daniel@0: hh=arrow_demo3(demo_info); Daniel@0: else, Daniel@0: hh=arrow_demo2(demo_info); Daniel@0: end; Daniel@0: if (nargout>=1), h=hh; end; Daniel@0: elseif strncmp(arg1,'fixlimits',3), Daniel@0: arrow_fixlimits(ARROW_AXLIMITS); Daniel@0: ARROW_AXLIMITS=[]; Daniel@0: elseif strncmp(arg1,'help',4), Daniel@0: disp(help(mfilename)); Daniel@0: else, Daniel@0: error([upper(mfilename) ' got an unknown single-argument string ''' deblank(arg1) '''.']); Daniel@0: end; Daniel@0: return; Daniel@0: end; Daniel@0: Daniel@0: % Check # of arguments Daniel@0: if (nargout>3), error([upper(mfilename) ' produces at most 3 output arguments.']); end; Daniel@0: Daniel@0: % find first property number Daniel@0: firstprop = nargin+1; Daniel@0: for k=1:length(varargin), if ~isnumeric(varargin{k}), firstprop=k; break; end; end; Daniel@0: lastnumeric = firstprop-1; Daniel@0: Daniel@0: % check property list Daniel@0: if (firstprop<=nargin), Daniel@0: for k=firstprop:2:nargin, Daniel@0: curarg = varargin{k}; Daniel@0: if ~isstr(curarg) | sum(size(curarg)>1)>1, Daniel@0: error([upper(mfilename) ' requires that a property name be a single string.']); Daniel@0: end; Daniel@0: end; Daniel@0: if (rem(nargin-firstprop,2)~=1), Daniel@0: error([upper(mfilename) ' requires that the property ''' ... Daniel@0: varargin{nargin} ''' be paired with a property value.']); Daniel@0: end; Daniel@0: end; Daniel@0: Daniel@0: % default output Daniel@0: if (nargout>0), h=[]; end; Daniel@0: if (nargout>1), yy=[]; end; Daniel@0: if (nargout>2), zz=[]; end; Daniel@0: Daniel@0: % set values to empty matrices Daniel@0: start = []; Daniel@0: stop = []; Daniel@0: len = []; Daniel@0: baseangle = []; Daniel@0: tipangle = []; Daniel@0: wid = []; Daniel@0: page = []; Daniel@0: crossdir = []; Daniel@0: ends = []; Daniel@0: ax = []; Daniel@0: oldh = []; Daniel@0: ispatch = []; Daniel@0: defstart = [NaN NaN NaN]; Daniel@0: defstop = [NaN NaN NaN]; Daniel@0: deflen = 16; Daniel@0: defbaseangle = 90; Daniel@0: deftipangle = 16; Daniel@0: defwid = 0; Daniel@0: defpage = 0; Daniel@0: defcrossdir = [NaN NaN NaN]; Daniel@0: defends = 1; Daniel@0: defoldh = []; Daniel@0: defispatch = 1; Daniel@0: Daniel@0: % The 'Tag' we'll put on our arrows Daniel@0: ArrowTag = 'Arrow'; Daniel@0: Daniel@0: % check for oldstyle arguments Daniel@0: if (firstprop==2), Daniel@0: % assume arg1 is a set of handles Daniel@0: oldh = varargin{1}(:); Daniel@0: if isempty(oldh), return; end; Daniel@0: elseif (firstprop>9), Daniel@0: error([upper(mfilename) ' takes at most 8 non-property arguments.']); Daniel@0: elseif (firstprop>2), Daniel@0: s = str2mat('start','stop','len','baseangle','tipangle','wid','page','crossdir'); Daniel@0: for k=1:firstprop-1, eval([deblank(s(k,:)) '=varargin{k};']); end; Daniel@0: end; Daniel@0: Daniel@0: % parse property pairs Daniel@0: extraprops={}; Daniel@0: for k=firstprop:2:nargin, Daniel@0: prop = varargin{k}; Daniel@0: val = varargin{k+1}; Daniel@0: prop = [lower(prop(:)') ' ']; Daniel@0: if strncmp(prop,'start' ,5), start = val; Daniel@0: elseif strncmp(prop,'stop' ,4), stop = val; Daniel@0: elseif strncmp(prop,'len' ,3), len = val(:); Daniel@0: elseif strncmp(prop,'base' ,4), baseangle = val(:); Daniel@0: elseif strncmp(prop,'tip' ,3), tipangle = val(:); Daniel@0: elseif strncmp(prop,'wid' ,3), wid = val(:); Daniel@0: elseif strncmp(prop,'page' ,4), page = val; Daniel@0: elseif strncmp(prop,'cross' ,5), crossdir = val; Daniel@0: elseif strncmp(prop,'norm' ,4), if (isstr(val)), crossdir=val; else, crossdir=val*sqrt(-1); end; Daniel@0: elseif strncmp(prop,'end' ,3), ends = val; Daniel@0: elseif strncmp(prop,'object',6), oldh = val(:); Daniel@0: elseif strncmp(prop,'handle',6), oldh = val(:); Daniel@0: elseif strncmp(prop,'type' ,4), ispatch = val; Daniel@0: elseif strncmp(prop,'userd' ,5), %ignore it Daniel@0: else, Daniel@0: % make sure it is a valid patch or line property Daniel@0: eval('get(0,[''DefaultPatch'' varargin{k}]);err=0;','err=1;'); errstr=lasterr; Daniel@0: if (err), eval('get(0,[''DefaultLine'' varargin{k}]);err=0;','err=1;'); end; Daniel@0: if (err), Daniel@0: errstr(1:max(find(errstr==setstr(13)|errstr==setstr(10)))) = ''; Daniel@0: error([upper(mfilename) ' got ' errstr]); Daniel@0: end; Daniel@0: extraprops={extraprops{:},varargin{k},val}; Daniel@0: end; Daniel@0: end; Daniel@0: Daniel@0: % Check if we got 'default' values Daniel@0: start = arrow_defcheck(start ,defstart ,'Start' ); Daniel@0: stop = arrow_defcheck(stop ,defstop ,'Stop' ); Daniel@0: len = arrow_defcheck(len ,deflen ,'Length' ); Daniel@0: baseangle = arrow_defcheck(baseangle,defbaseangle,'BaseAngle' ); Daniel@0: tipangle = arrow_defcheck(tipangle ,deftipangle ,'TipAngle' ); Daniel@0: wid = arrow_defcheck(wid ,defwid ,'Width' ); Daniel@0: crossdir = arrow_defcheck(crossdir ,defcrossdir ,'CrossDir' ); Daniel@0: page = arrow_defcheck(page ,defpage ,'Page' ); Daniel@0: ends = arrow_defcheck(ends ,defends ,'' ); Daniel@0: oldh = arrow_defcheck(oldh ,[] ,'ObjectHandles'); Daniel@0: ispatch = arrow_defcheck(ispatch ,defispatch ,'' ); Daniel@0: Daniel@0: % check transpose on arguments Daniel@0: [m,n]=size(start ); if any(m==[2 3])&(n==1|n>3), start = start'; end; Daniel@0: [m,n]=size(stop ); if any(m==[2 3])&(n==1|n>3), stop = stop'; end; Daniel@0: [m,n]=size(crossdir); if any(m==[2 3])&(n==1|n>3), crossdir = crossdir'; end; Daniel@0: Daniel@0: % convert strings to numbers Daniel@0: if ~isempty(ends) & isstr(ends), Daniel@0: endsorig = ends; Daniel@0: [m,n] = size(ends); Daniel@0: col = lower([ends(:,1:min(3,n)) ones(m,max(0,3-n))*' ']); Daniel@0: ends = NaN*ones(m,1); Daniel@0: oo = ones(1,m); Daniel@0: ii=find(all(col'==['non']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*0; end; Daniel@0: ii=find(all(col'==['sto']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*1; end; Daniel@0: ii=find(all(col'==['sta']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*2; end; Daniel@0: ii=find(all(col'==['bot']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*3; end; Daniel@0: if any(isnan(ends)), Daniel@0: ii = min(find(isnan(ends))); Daniel@0: error([upper(mfilename) ' does not recognize ' deblank(endsorig(ii,:)) ' as a valid Ends value.']); Daniel@0: end; Daniel@0: else, Daniel@0: ends = ends(:); Daniel@0: end; Daniel@0: if ~isempty(ispatch) & isstr(ispatch), Daniel@0: col = lower(ispatch(:,1)); Daniel@0: patchchar='p'; linechar='l'; defchar=' '; Daniel@0: mask = col~=patchchar & col~=linechar & col~=defchar; Daniel@0: if any(mask) Daniel@0: error([upper(mfilename) ' does not recognize ' deblank(ispatch(min(find(mask)),:)) ' as a valid Type value.']); Daniel@0: end; Daniel@0: ispatch = (col==patchchar)*1 + (col==linechar)*0 + (col==defchar)*defispatch; Daniel@0: else, Daniel@0: ispatch = ispatch(:); Daniel@0: end; Daniel@0: oldh = oldh(:); Daniel@0: Daniel@0: % check object handles Daniel@0: if ~all(ishandle(oldh)), error([upper(mfilename) ' got invalid object handles.']); end; Daniel@0: Daniel@0: % expand root, figure, and axes handles Daniel@0: if ~isempty(oldh), Daniel@0: ohtype = get(oldh,'Type'); Daniel@0: mask = strcmp(ohtype,'root') | strcmp(ohtype,'figure') | strcmp(ohtype,'axes'); Daniel@0: if any(mask), Daniel@0: oldh = num2cell(oldh); Daniel@0: for ii=find(mask)', Daniel@0: oldh(ii) = {findobj(oldh{ii},'Tag',ArrowTag)}; Daniel@0: end; Daniel@0: oldh = cat(1,oldh{:}); Daniel@0: if isempty(oldh), return; end; % no arrows to modify, so just leave Daniel@0: end; Daniel@0: end; Daniel@0: Daniel@0: % largest argument length Daniel@0: [mstart,junk]=size(start); [mstop,junk]=size(stop); [mcrossdir,junk]=size(crossdir); Daniel@0: argsizes = [length(oldh) mstart mstop ... Daniel@0: length(len) length(baseangle) length(tipangle) ... Daniel@0: length(wid) length(page) mcrossdir length(ends) ]; Daniel@0: args=['length(ObjectHandle) '; ... Daniel@0: '#rows(Start) '; ... Daniel@0: '#rows(Stop) '; ... Daniel@0: 'length(Length) '; ... Daniel@0: 'length(BaseAngle) '; ... Daniel@0: 'length(TipAngle) '; ... Daniel@0: 'length(Width) '; ... Daniel@0: 'length(Page) '; ... Daniel@0: '#rows(CrossDir) '; ... Daniel@0: '#rows(Ends) ']; Daniel@0: if (any(imag(crossdir(:))~=0)), Daniel@0: args(9,:) = '#rows(NormalDir) '; Daniel@0: end; Daniel@0: if isempty(oldh), Daniel@0: narrows = max(argsizes); Daniel@0: else, Daniel@0: narrows = length(oldh); Daniel@0: end; Daniel@0: if (narrows<=0), narrows=1; end; Daniel@0: Daniel@0: % Check size of arguments Daniel@0: ii = find((argsizes~=0)&(argsizes~=1)&(argsizes~=narrows)); Daniel@0: if ~isempty(ii), Daniel@0: s = args(ii',:); Daniel@0: while ((size(s,2)>1)&((abs(s(:,size(s,2)))==0)|(abs(s(:,size(s,2)))==abs(' ')))), Daniel@0: s = s(:,1:size(s,2)-1); Daniel@0: end; Daniel@0: s = [ones(length(ii),1)*[upper(mfilename) ' requires that '] s ... Daniel@0: ones(length(ii),1)*[' equal the # of arrows (' num2str(narrows) ').' c]]; Daniel@0: s = s'; Daniel@0: s = s(:)'; Daniel@0: s = s(1:length(s)-1); Daniel@0: error(setstr(s)); Daniel@0: end; Daniel@0: Daniel@0: % check element length in Start, Stop, and CrossDir Daniel@0: if ~isempty(start), Daniel@0: [m,n] = size(start); Daniel@0: if (n==2), Daniel@0: start = [start NaN*ones(m,1)]; Daniel@0: elseif (n~=3), Daniel@0: error([upper(mfilename) ' requires 2- or 3-element Start points.']); Daniel@0: end; Daniel@0: end; Daniel@0: if ~isempty(stop), Daniel@0: [m,n] = size(stop); Daniel@0: if (n==2), Daniel@0: stop = [stop NaN*ones(m,1)]; Daniel@0: elseif (n~=3), Daniel@0: error([upper(mfilename) ' requires 2- or 3-element Stop points.']); Daniel@0: end; Daniel@0: end; Daniel@0: if ~isempty(crossdir), Daniel@0: [m,n] = size(crossdir); Daniel@0: if (n<3), Daniel@0: crossdir = [crossdir NaN*ones(m,3-n)]; Daniel@0: elseif (n~=3), Daniel@0: if (all(imag(crossdir(:))==0)), Daniel@0: error([upper(mfilename) ' requires 2- or 3-element CrossDir vectors.']); Daniel@0: else, Daniel@0: error([upper(mfilename) ' requires 2- or 3-element NormalDir vectors.']); Daniel@0: end; Daniel@0: end; Daniel@0: end; Daniel@0: Daniel@0: % fill empty arguments Daniel@0: if isempty(start ), start = [Inf Inf Inf]; end; Daniel@0: if isempty(stop ), stop = [Inf Inf Inf]; end; Daniel@0: if isempty(len ), len = Inf; end; Daniel@0: if isempty(baseangle ), baseangle = Inf; end; Daniel@0: if isempty(tipangle ), tipangle = Inf; end; Daniel@0: if isempty(wid ), wid = Inf; end; Daniel@0: if isempty(page ), page = Inf; end; Daniel@0: if isempty(crossdir ), crossdir = [Inf Inf Inf]; end; Daniel@0: if isempty(ends ), ends = Inf; end; Daniel@0: if isempty(ispatch ), ispatch = Inf; end; Daniel@0: Daniel@0: % expand single-column arguments Daniel@0: o = ones(narrows,1); Daniel@0: if (size(start ,1)==1), start = o * start ; end; Daniel@0: if (size(stop ,1)==1), stop = o * stop ; end; Daniel@0: if (length(len )==1), len = o * len ; end; Daniel@0: if (length(baseangle )==1), baseangle = o * baseangle ; end; Daniel@0: if (length(tipangle )==1), tipangle = o * tipangle ; end; Daniel@0: if (length(wid )==1), wid = o * wid ; end; Daniel@0: if (length(page )==1), page = o * page ; end; Daniel@0: if (size(crossdir ,1)==1), crossdir = o * crossdir ; end; Daniel@0: if (length(ends )==1), ends = o * ends ; end; Daniel@0: if (length(ispatch )==1), ispatch = o * ispatch ; end; Daniel@0: ax = o * gca; Daniel@0: Daniel@0: % if we've got handles, get the defaults from the handles Daniel@0: if ~isempty(oldh), Daniel@0: for k=1:narrows, Daniel@0: oh = oldh(k); Daniel@0: ud = get(oh,'UserData'); Daniel@0: ax(k) = get(oh,'Parent'); Daniel@0: ohtype = get(oh,'Type'); Daniel@0: if strcmp(get(oh,'Tag'),ArrowTag), % if it's an arrow already Daniel@0: if isinf(ispatch(k)), ispatch(k)=strcmp(ohtype,'patch'); end; Daniel@0: % arrow UserData format: [start' stop' len base tip wid page crossdir' ends] Daniel@0: start0 = ud(1:3); Daniel@0: stop0 = ud(4:6); Daniel@0: if (isinf(len(k))), len(k) = ud( 7); end; Daniel@0: if (isinf(baseangle(k))), baseangle(k) = ud( 8); end; Daniel@0: if (isinf(tipangle(k))), tipangle(k) = ud( 9); end; Daniel@0: if (isinf(wid(k))), wid(k) = ud(10); end; Daniel@0: if (isinf(page(k))), page(k) = ud(11); end; Daniel@0: if (isinf(crossdir(k,1))), crossdir(k,1) = ud(12); end; Daniel@0: if (isinf(crossdir(k,2))), crossdir(k,2) = ud(13); end; Daniel@0: if (isinf(crossdir(k,3))), crossdir(k,3) = ud(14); end; Daniel@0: if (isinf(ends(k))), ends(k) = ud(15); end; Daniel@0: elseif strcmp(ohtype,'line')|strcmp(ohtype,'patch'), % it's a non-arrow line or patch Daniel@0: convLineToPatch = 1; %set to make arrow patches when converting from lines. Daniel@0: if isinf(ispatch(k)), ispatch(k)=convLineToPatch|strcmp(ohtype,'patch'); end; Daniel@0: x=get(oh,'XData'); x=x(~isnan(x(:))); if isempty(x), x=NaN; end; Daniel@0: y=get(oh,'YData'); y=y(~isnan(y(:))); if isempty(y), y=NaN; end; Daniel@0: z=get(oh,'ZData'); z=z(~isnan(z(:))); if isempty(z), z=NaN; end; Daniel@0: start0 = [x(1) y(1) z(1) ]; Daniel@0: stop0 = [x(end) y(end) z(end)]; Daniel@0: else, Daniel@0: error([upper(mfilename) ' cannot convert ' ohtype ' objects.']); Daniel@0: end; Daniel@0: ii=find(isinf(start(k,:))); if ~isempty(ii), start(k,ii)=start0(ii); end; Daniel@0: ii=find(isinf(stop( k,:))); if ~isempty(ii), stop( k,ii)=stop0( ii); end; Daniel@0: end; Daniel@0: end; Daniel@0: Daniel@0: % convert Inf's to NaN's Daniel@0: start( isinf(start )) = NaN; Daniel@0: stop( isinf(stop )) = NaN; Daniel@0: len( isinf(len )) = NaN; Daniel@0: baseangle( isinf(baseangle)) = NaN; Daniel@0: tipangle( isinf(tipangle )) = NaN; Daniel@0: wid( isinf(wid )) = NaN; Daniel@0: page( isinf(page )) = NaN; Daniel@0: crossdir( isinf(crossdir )) = NaN; Daniel@0: ends( isinf(ends )) = NaN; Daniel@0: ispatch( isinf(ispatch )) = NaN; Daniel@0: Daniel@0: % set up the UserData data (here so not corrupted by log10's and such) Daniel@0: ud = [start stop len baseangle tipangle wid page crossdir ends]; Daniel@0: Daniel@0: % Set Page defaults Daniel@0: %page = (~isnan(page))&(page); Daniel@0: if isnan(page) Daniel@0: page = 0; Daniel@0: end Daniel@0: Daniel@0: % Get axes limits, range, min; correct for aspect ratio and log scale Daniel@0: axm = zeros(3,narrows); Daniel@0: axr = zeros(3,narrows); Daniel@0: axrev = zeros(3,narrows); Daniel@0: ap = zeros(2,narrows); Daniel@0: xyzlog = zeros(3,narrows); Daniel@0: limmin = zeros(2,narrows); Daniel@0: limrange = zeros(2,narrows); Daniel@0: oldaxlims = zeros(narrows,7); Daniel@0: oneax = all(ax==ax(1)); Daniel@0: if (oneax), Daniel@0: T = zeros(4,4); Daniel@0: invT = zeros(4,4); Daniel@0: else, Daniel@0: T = zeros(16,narrows); Daniel@0: invT = zeros(16,narrows); Daniel@0: end; Daniel@0: axnotdone = logical(ones(size(ax))); Daniel@0: while (any(axnotdone)), Daniel@0: ii = min(find(axnotdone)); Daniel@0: curax = ax(ii); Daniel@0: curpage = page(ii); Daniel@0: % get axes limits and aspect ratio Daniel@0: axl = [get(curax,'XLim'); get(curax,'YLim'); get(curax,'ZLim')]; Daniel@0: oldaxlims(min(find(oldaxlims(:,1)==0)),:) = [curax reshape(axl',1,6)]; Daniel@0: % get axes size in pixels (points) Daniel@0: u = get(curax,'Units'); Daniel@0: axposoldunits = get(curax,'Position'); Daniel@0: really_curpage = curpage & strcmp(u,'normalized'); Daniel@0: if (really_curpage), Daniel@0: curfig = get(curax,'Parent'); Daniel@0: pu = get(curfig,'PaperUnits'); Daniel@0: set(curfig,'PaperUnits','points'); Daniel@0: pp = get(curfig,'PaperPosition'); Daniel@0: set(curfig,'PaperUnits',pu); Daniel@0: set(curax,'Units','pixels'); Daniel@0: curapscreen = get(curax,'Position'); Daniel@0: set(curax,'Units','normalized'); Daniel@0: curap = pp.*get(curax,'Position'); Daniel@0: else, Daniel@0: set(curax,'Units','pixels'); Daniel@0: curapscreen = get(curax,'Position'); Daniel@0: curap = curapscreen; Daniel@0: end; Daniel@0: set(curax,'Units',u); Daniel@0: set(curax,'Position',axposoldunits); Daniel@0: % handle non-stretched axes position Daniel@0: str_stretch = { 'DataAspectRatioMode' ; ... Daniel@0: 'PlotBoxAspectRatioMode' ; ... Daniel@0: 'CameraViewAngleMode' }; Daniel@0: str_camera = { 'CameraPositionMode' ; ... Daniel@0: 'CameraTargetMode' ; ... Daniel@0: 'CameraViewAngleMode' ; ... Daniel@0: 'CameraUpVectorMode' }; Daniel@0: notstretched = strcmp(get(curax,str_stretch),'manual'); Daniel@0: manualcamera = strcmp(get(curax,str_camera),'manual'); Daniel@0: if ~arrow_WarpToFill(notstretched,manualcamera,curax), Daniel@0: % give a warning that this has not been thoroughly tested Daniel@0: if 0 & ARROW_STRETCH_WARN, Daniel@0: ARROW_STRETCH_WARN = 0; Daniel@0: strs = {str_stretch{1:2},str_camera{:}}; Daniel@0: strs = [char(ones(length(strs),1)*sprintf('\n ')) char(strs)]'; Daniel@0: warning([upper(mfilename) ' may not yet work quite right ' ... Daniel@0: 'if any of the following are ''manual'':' strs(:).']); Daniel@0: end; Daniel@0: % find the true pixel size of the actual axes Daniel@0: texttmp = text(axl(1,[1 2 2 1 1 2 2 1]), ... Daniel@0: axl(2,[1 1 2 2 1 1 2 2]), ... Daniel@0: axl(3,[1 1 1 1 2 2 2 2]),''); Daniel@0: set(texttmp,'Units','points'); Daniel@0: textpos = get(texttmp,'Position'); Daniel@0: delete(texttmp); Daniel@0: textpos = cat(1,textpos{:}); Daniel@0: textpos = max(textpos(:,1:2)) - min(textpos(:,1:2)); Daniel@0: % adjust the axes position Daniel@0: if (really_curpage), Daniel@0: % adjust to printed size Daniel@0: textpos = textpos * min(curap(3:4)./textpos); Daniel@0: curap = [curap(1:2)+(curap(3:4)-textpos)/2 textpos]; Daniel@0: else, Daniel@0: % adjust for pixel roundoff Daniel@0: textpos = textpos * min(curapscreen(3:4)./textpos); Daniel@0: curap = [curap(1:2)+(curap(3:4)-textpos)/2 textpos]; Daniel@0: end; Daniel@0: end; Daniel@0: if ARROW_PERSP_WARN & ~strcmp(get(curax,'Projection'),'orthographic'), Daniel@0: ARROW_PERSP_WARN = 0; Daniel@0: warning([upper(mfilename) ' does not yet work right for 3-D perspective projection.']); Daniel@0: end; Daniel@0: % adjust limits for log scale on axes Daniel@0: curxyzlog = [strcmp(get(curax,'XScale'),'log'); ... Daniel@0: strcmp(get(curax,'YScale'),'log'); ... Daniel@0: strcmp(get(curax,'ZScale'),'log')]; Daniel@0: if (any(curxyzlog)), Daniel@0: ii = find([curxyzlog;curxyzlog]); Daniel@0: if (any(axl(ii)<=0)), Daniel@0: error([upper(mfilename) ' does not support non-positive limits on log-scaled axes.']); Daniel@0: else, Daniel@0: axl(ii) = log10(axl(ii)); Daniel@0: end; Daniel@0: end; Daniel@0: % correct for 'reverse' direction on axes; Daniel@0: curreverse = [strcmp(get(curax,'XDir'),'reverse'); ... Daniel@0: strcmp(get(curax,'YDir'),'reverse'); ... Daniel@0: strcmp(get(curax,'ZDir'),'reverse')]; Daniel@0: ii = find(curreverse); Daniel@0: if ~isempty(ii), Daniel@0: axl(ii,[1 2])=-axl(ii,[2 1]); Daniel@0: end; Daniel@0: % compute the range of 2-D values Daniel@0: curT = get(curax,'Xform'); Daniel@0: lim = curT*[0 1 0 1 0 1 0 1;0 0 1 1 0 0 1 1;0 0 0 0 1 1 1 1;1 1 1 1 1 1 1 1]; Daniel@0: lim = lim(1:2,:)./([1;1]*lim(4,:)); Daniel@0: curlimmin = min(lim')'; Daniel@0: curlimrange = max(lim')' - curlimmin; Daniel@0: curinvT = inv(curT); Daniel@0: if (~oneax), Daniel@0: curT = curT.'; Daniel@0: curinvT = curinvT.'; Daniel@0: curT = curT(:); Daniel@0: curinvT = curinvT(:); Daniel@0: end; Daniel@0: % check which arrows to which cur corresponds Daniel@0: ii = find((ax==curax)&(page==curpage)); Daniel@0: oo = ones(1,length(ii)); Daniel@0: axr(:,ii) = diff(axl')' * oo; Daniel@0: axm(:,ii) = axl(:,1) * oo; Daniel@0: axrev(:,ii) = curreverse * oo; Daniel@0: ap(:,ii) = curap(3:4)' * oo; Daniel@0: xyzlog(:,ii) = curxyzlog * oo; Daniel@0: limmin(:,ii) = curlimmin * oo; Daniel@0: limrange(:,ii) = curlimrange * oo; Daniel@0: if (oneax), Daniel@0: T = curT; Daniel@0: invT = curinvT; Daniel@0: else, Daniel@0: T(:,ii) = curT * oo; Daniel@0: invT(:,ii) = curinvT * oo; Daniel@0: end; Daniel@0: axnotdone(ii) = zeros(1,length(ii)); Daniel@0: end; Daniel@0: oldaxlims(oldaxlims(:,1)==0,:)=[]; Daniel@0: Daniel@0: % correct for log scales Daniel@0: curxyzlog = xyzlog.'; Daniel@0: ii = find(curxyzlog(:)); Daniel@0: if ~isempty(ii), Daniel@0: start( ii) = real(log10(start( ii))); Daniel@0: stop( ii) = real(log10(stop( ii))); Daniel@0: if (all(imag(crossdir)==0)), % pulled (ii) subscript on crossdir, 12/5/96 eaj Daniel@0: crossdir(ii) = real(log10(crossdir(ii))); Daniel@0: end; Daniel@0: end; Daniel@0: Daniel@0: % correct for reverse directions Daniel@0: ii = find(axrev.'); Daniel@0: if ~isempty(ii), Daniel@0: start( ii) = -start( ii); Daniel@0: stop( ii) = -stop( ii); Daniel@0: crossdir(ii) = -crossdir(ii); Daniel@0: end; Daniel@0: Daniel@0: % transpose start/stop values Daniel@0: start = start.'; Daniel@0: stop = stop.'; Daniel@0: Daniel@0: % take care of defaults, page was done above Daniel@0: ii=find(isnan(start(:) )); if ~isempty(ii), start(ii) = axm(ii)+axr(ii)/2; end; Daniel@0: ii=find(isnan(stop(:) )); if ~isempty(ii), stop(ii) = axm(ii)+axr(ii)/2; end; Daniel@0: ii=find(isnan(crossdir(:) )); if ~isempty(ii), crossdir(ii) = zeros(length(ii),1); end; Daniel@0: ii=find(isnan(len )); if ~isempty(ii), len(ii) = ones(length(ii),1)*deflen; end; Daniel@0: ii=find(isnan(baseangle )); if ~isempty(ii), baseangle(ii) = ones(length(ii),1)*defbaseangle; end; Daniel@0: ii=find(isnan(tipangle )); if ~isempty(ii), tipangle(ii) = ones(length(ii),1)*deftipangle; end; Daniel@0: ii=find(isnan(wid )); if ~isempty(ii), wid(ii) = ones(length(ii),1)*defwid; end; Daniel@0: ii=find(isnan(ends )); if ~isempty(ii), ends(ii) = ones(length(ii),1)*defends; end; Daniel@0: Daniel@0: % transpose rest of values Daniel@0: len = len.'; Daniel@0: baseangle = baseangle.'; Daniel@0: tipangle = tipangle.'; Daniel@0: wid = wid.'; Daniel@0: page = page.'; Daniel@0: crossdir = crossdir.'; Daniel@0: ends = ends.'; Daniel@0: ax = ax.'; Daniel@0: Daniel@0: % given x, a 3xN matrix of points in 3-space; Daniel@0: % want to convert to X, the corresponding 4xN 2-space matrix Daniel@0: % Daniel@0: % tmp1=[(x-axm)./axr; ones(1,size(x,1))]; Daniel@0: % if (oneax), X=T*tmp1; Daniel@0: % else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1; Daniel@0: % tmp2=zeros(4,4*N); tmp2(:)=tmp1(:); Daniel@0: % X=zeros(4,N); X(:)=sum(tmp2)'; end; Daniel@0: % X = X ./ (ones(4,1)*X(4,:)); Daniel@0: Daniel@0: % for all points with start==stop, start=stop-(verysmallvalue)*(up-direction); Daniel@0: ii = find(all(start==stop)); Daniel@0: if ~isempty(ii), Daniel@0: % find an arrowdir vertical on screen and perpendicular to viewer Daniel@0: % transform to 2-D Daniel@0: tmp1 = [(stop(:,ii)-axm(:,ii))./axr(:,ii);ones(1,length(ii))]; Daniel@0: if (oneax), twoD=T*tmp1; Daniel@0: else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T(:,ii).*tmp1; Daniel@0: tmp2=zeros(4,4*length(ii)); tmp2(:)=tmp1(:); Daniel@0: twoD=zeros(4,length(ii)); twoD(:)=sum(tmp2)'; end; Daniel@0: twoD=twoD./(ones(4,1)*twoD(4,:)); Daniel@0: % move the start point down just slightly Daniel@0: tmp1 = twoD + [0;-1/1000;0;0]*(limrange(2,ii)./ap(2,ii)); Daniel@0: % transform back to 3-D Daniel@0: if (oneax), threeD=invT*tmp1; Daniel@0: else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT(:,ii).*tmp1; Daniel@0: tmp2=zeros(4,4*length(ii)); tmp2(:)=tmp1(:); Daniel@0: threeD=zeros(4,length(ii)); threeD(:)=sum(tmp2)'; end; Daniel@0: start(:,ii) = (threeD(1:3,:)./(ones(3,1)*threeD(4,:))).*axr(:,ii)+axm(:,ii); Daniel@0: end; Daniel@0: Daniel@0: % compute along-arrow points Daniel@0: % transform Start points Daniel@0: tmp1=[(start-axm)./axr;ones(1,narrows)]; Daniel@0: if (oneax), X0=T*tmp1; Daniel@0: else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1; Daniel@0: tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:); Daniel@0: X0=zeros(4,narrows); X0(:)=sum(tmp2)'; end; Daniel@0: X0=X0./(ones(4,1)*X0(4,:)); Daniel@0: % transform Stop points Daniel@0: tmp1=[(stop-axm)./axr;ones(1,narrows)]; Daniel@0: if (oneax), Xf=T*tmp1; Daniel@0: else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1; Daniel@0: tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:); Daniel@0: Xf=zeros(4,narrows); Xf(:)=sum(tmp2)'; end; Daniel@0: Xf=Xf./(ones(4,1)*Xf(4,:)); Daniel@0: % compute pixel distance between points Daniel@0: D = sqrt(sum(((Xf(1:2,:)-X0(1:2,:)).*(ap./limrange)).^2)); Daniel@0: % compute and modify along-arrow distances Daniel@0: len1 = len; Daniel@0: len2 = len - (len.*tan(tipangle/180*pi)-wid/2).*tan((90-baseangle)/180*pi); Daniel@0: slen0 = zeros(1,narrows); Daniel@0: slen1 = len1 .* ((ends==2)|(ends==3)); Daniel@0: slen2 = len2 .* ((ends==2)|(ends==3)); Daniel@0: len0 = zeros(1,narrows); Daniel@0: len1 = len1 .* ((ends==1)|(ends==3)); Daniel@0: len2 = len2 .* ((ends==1)|(ends==3)); Daniel@0: % for no start arrowhead Daniel@0: ii=find((ends==1)&(D0), set(H,extraprops{:}); end; Daniel@0: % handle choosing arrow Start and/or Stop locations if unspecified Daniel@0: [H,oldaxlims,errstr] = arrow_clicks(H,ud,x,y,z,ax,oldaxlims); Daniel@0: if ~isempty(errstr), error([upper(mfilename) ' got ' errstr]); end; Daniel@0: % set the output Daniel@0: if (nargout>0), h=H; end; Daniel@0: % make sure the axis limits did not change Daniel@0: if isempty(oldaxlims), Daniel@0: ARROW_AXLIMITS = []; Daniel@0: else, Daniel@0: lims = get(oldaxlims(:,1),{'XLim','YLim','ZLim'})'; Daniel@0: lims = reshape(cat(2,lims{:}),6,size(lims,2)); Daniel@0: %mask = arrow_is2DXY(oldaxlims(:,1)); Daniel@0: %oldaxlims(mask,6:7) = lims(5:6,mask)'; Daniel@0: ARROW_AXLIMITS = oldaxlims(find(any(oldaxlims(:,2:7)'~=lims)),:); Daniel@0: if ~isempty(ARROW_AXLIMITS), Daniel@0: warning(arrow_warnlimits(ARROW_AXLIMITS,narrows)); Daniel@0: end; Daniel@0: end; Daniel@0: else, Daniel@0: % don't create the patch, just return the data Daniel@0: h=x; Daniel@0: yy=y; Daniel@0: zz=z; Daniel@0: end; Daniel@0: Daniel@0: Daniel@0: Daniel@0: function out = arrow_defcheck(in,def,prop) Daniel@0: % check if we got 'default' values Daniel@0: out = in; Daniel@0: if ~isstr(in), return; end; Daniel@0: if size(in,1)==1 & strncmp(lower(in),'def',3), Daniel@0: out = def; Daniel@0: elseif ~isempty(prop), Daniel@0: error([upper(mfilename) ' does not recognize ''' in(:)' ''' as a valid ''' prop ''' string.']); Daniel@0: end; Daniel@0: Daniel@0: Daniel@0: Daniel@0: function [H,oldaxlims,errstr] = arrow_clicks(H,ud,x,y,z,ax,oldaxlims) Daniel@0: % handle choosing arrow Start and/or Stop locations if necessary Daniel@0: errstr = ''; Daniel@0: if isempty(H)|isempty(ud)|isempty(x), return; end; Daniel@0: % determine which (if any) need Start and/or Stop Daniel@0: needStart = all(isnan(ud(:,1:3)'))'; Daniel@0: needStop = all(isnan(ud(:,4:6)'))'; Daniel@0: mask = any(needStart|needStop); Daniel@0: if ~any(mask), return; end; Daniel@0: ud(~mask,:)=[]; ax(:,~mask)=[]; Daniel@0: x(:,~mask)=[]; y(:,~mask)=[]; z(:,~mask)=[]; Daniel@0: % make them invisible for the time being Daniel@0: set(H,'Visible','off'); Daniel@0: % save the current axes and limits modes; set to manual for the time being Daniel@0: oldAx = gca; Daniel@0: limModes=get(ax(:),{'XLimMode','YLimMode','ZLimMode'}); Daniel@0: set(ax(:),{'XLimMode','YLimMode','ZLimMode'},{'manual','manual','manual'}); Daniel@0: % loop over each arrow that requires attention Daniel@0: jj = find(mask); Daniel@0: for ii=1:length(jj), Daniel@0: h = H(jj(ii)); Daniel@0: axes(ax(ii)); Daniel@0: % figure out correct call Daniel@0: if needStart(ii), prop='Start'; else, prop='Stop'; end; Daniel@0: [wasInterrupted,errstr] = arrow_click(needStart(ii)&needStop(ii),h,prop,ax(ii)); Daniel@0: % handle errors and control-C Daniel@0: if wasInterrupted, Daniel@0: delete(H(jj(ii:end))); Daniel@0: H(jj(ii:end))=[]; Daniel@0: oldaxlims(jj(ii:end),:)=[]; Daniel@0: break; Daniel@0: end; Daniel@0: end; Daniel@0: % restore the axes and limit modes Daniel@0: axes(oldAx); Daniel@0: set(ax(:),{'XLimMode','YLimMode','ZLimMode'},limModes); Daniel@0: Daniel@0: function [wasInterrupted,errstr] = arrow_click(lockStart,H,prop,ax) Daniel@0: % handle the clicks for one arrow Daniel@0: fig = get(ax,'Parent'); Daniel@0: % save some things Daniel@0: oldFigProps = {'Pointer','WindowButtonMotionFcn','WindowButtonUpFcn'}; Daniel@0: oldFigValue = get(fig,oldFigProps); Daniel@0: oldArrowProps = {'EraseMode'}; Daniel@0: oldArrowValue = get(H,oldArrowProps); Daniel@0: set(H,'EraseMode','background'); %because 'xor' makes shaft invisible unless Width>1 Daniel@0: global ARROW_CLICK_H ARROW_CLICK_PROP ARROW_CLICK_AX ARROW_CLICK_USE_Z Daniel@0: ARROW_CLICK_H=H; ARROW_CLICK_PROP=prop; ARROW_CLICK_AX=ax; Daniel@0: ARROW_CLICK_USE_Z=~arrow_is2DXY(ax)|~arrow_planarkids(ax); Daniel@0: set(fig,'Pointer','crosshair'); Daniel@0: % set up the WindowButtonMotion so we can see the arrow while moving around Daniel@0: set(fig,'WindowButtonUpFcn','set(gcf,''WindowButtonUpFcn'','''')', ... Daniel@0: 'WindowButtonMotionFcn',''); Daniel@0: if ~lockStart, Daniel@0: set(H,'Visible','on'); Daniel@0: set(fig,'WindowButtonMotionFcn',[mfilename '(''callback'',''motion'');']); Daniel@0: end; Daniel@0: % wait for the button to be pressed Daniel@0: [wasKeyPress,wasInterrupted,errstr] = arrow_wfbdown(fig); Daniel@0: % if we wanted to click-drag, set the Start point Daniel@0: if lockStart & ~wasInterrupted, Daniel@0: pt = arrow_point(ARROW_CLICK_AX,ARROW_CLICK_USE_Z); Daniel@0: feval(mfilename,H,'Start',pt,'Stop',pt); Daniel@0: set(H,'Visible','on'); Daniel@0: ARROW_CLICK_PROP='Stop'; Daniel@0: set(fig,'WindowButtonMotionFcn',[mfilename '(''callback'',''motion'');']); Daniel@0: % wait for the mouse button to be released Daniel@0: eval('waitfor(fig,''WindowButtonUpFcn'','''');','wasInterrupted=1;'); Daniel@0: if wasInterrupted, errstr=lasterr; end; Daniel@0: end; Daniel@0: if ~wasInterrupted, feval(mfilename,'callback','motion'); end; Daniel@0: % restore some things Daniel@0: set(gcf,oldFigProps,oldFigValue); Daniel@0: set(H,oldArrowProps,oldArrowValue); Daniel@0: Daniel@0: function arrow_callback(varargin) Daniel@0: % handle redrawing callbacks Daniel@0: if nargin==0, return; end; Daniel@0: str = varargin{1}; Daniel@0: if ~isstr(str), error([upper(mfilename) ' got an invalid Callback command.']); end; Daniel@0: s = lower(str); Daniel@0: if strcmp(s,'motion'), Daniel@0: % motion callback Daniel@0: global ARROW_CLICK_H ARROW_CLICK_PROP ARROW_CLICK_AX ARROW_CLICK_USE_Z Daniel@0: feval(mfilename,ARROW_CLICK_H,ARROW_CLICK_PROP,arrow_point(ARROW_CLICK_AX,ARROW_CLICK_USE_Z)); Daniel@0: drawnow; Daniel@0: else, Daniel@0: error([upper(mfilename) ' does not recognize ''' str(:).' ''' as a valid Callback option.']); Daniel@0: end; Daniel@0: Daniel@0: function out = arrow_point(ax,use_z) Daniel@0: % return the point on the given axes Daniel@0: if nargin==0, ax=gca; end; Daniel@0: if nargin<2, use_z=~arrow_is2DXY(ax)|~arrow_planarkids(ax); end; Daniel@0: out = get(ax,'CurrentPoint'); Daniel@0: out = out(1,:); Daniel@0: if ~use_z, out=out(1:2); end; Daniel@0: Daniel@0: function [wasKeyPress,wasInterrupted,errstr] = arrow_wfbdown(fig) Daniel@0: % wait for button down ignoring object ButtonDownFcn's Daniel@0: if nargin==0, fig=gcf; end; Daniel@0: errstr = ''; Daniel@0: % save ButtonDownFcn values Daniel@0: objs = findobj(fig); Daniel@0: buttonDownFcns = get(objs,'ButtonDownFcn'); Daniel@0: mask=~strcmp(buttonDownFcns,''); objs=objs(mask); buttonDownFcns=buttonDownFcns(mask); Daniel@0: set(objs,'ButtonDownFcn',''); Daniel@0: % save other figure values Daniel@0: figProps = {'KeyPressFcn','WindowButtonDownFcn'}; Daniel@0: figValue = get(fig,figProps); Daniel@0: % do the real work Daniel@0: set(fig,'KeyPressFcn','set(gcf,''KeyPressFcn'','''',''WindowButtonDownFcn'','''');', ... Daniel@0: 'WindowButtonDownFcn','set(gcf,''WindowButtonDownFcn'','''')'); Daniel@0: lasterr(''); Daniel@0: wasInterrupted=0; eval('waitfor(fig,''WindowButtonDownFcn'','''');','wasInterrupted=1;'); Daniel@0: wasKeyPress = ~wasInterrupted & strcmp(get(fig,'KeyPressFcn'),''); Daniel@0: if wasInterrupted, errstr=lasterr; end; Daniel@0: % restore ButtonDownFcn and other figure values Daniel@0: set(objs,'ButtonDownFcn',buttonDownFcns); Daniel@0: set(fig,figProps,figValue); Daniel@0: Daniel@0: Daniel@0: Daniel@0: function [out,is2D] = arrow_is2DXY(ax) Daniel@0: % check if axes are 2-D X-Y plots Daniel@0: % may not work for modified camera angles, etc. Daniel@0: out = zeros(size(ax)); % 2-D X-Y plots Daniel@0: is2D = out; % any 2-D plots Daniel@0: views = get(ax(:),{'View'}); Daniel@0: views = cat(1,views{:}); Daniel@0: out(:) = abs(views(:,2))==90; Daniel@0: is2D(:) = out(:) | all(rem(views',90)==0)'; Daniel@0: Daniel@0: function out = arrow_planarkids(ax) Daniel@0: % check if axes descendents all have empty ZData (lines,patches,surfaces) Daniel@0: out = logical(ones(size(ax))); Daniel@0: allkids = get(ax(:),{'Children'}); Daniel@0: for k=1:length(allkids), Daniel@0: kids = get([findobj(allkids{k},'flat','Type','line') Daniel@0: findobj(allkids{k},'flat','Type','patch') Daniel@0: findobj(allkids{k},'flat','Type','surface')],{'ZData'}); Daniel@0: for j=1:length(kids), Daniel@0: if ~isempty(kids{j}), out(k)=logical(0); break; end; Daniel@0: end; Daniel@0: end; Daniel@0: Daniel@0: Daniel@0: Daniel@0: function arrow_fixlimits(axlimits) Daniel@0: % reset the axis limits as necessary Daniel@0: if isempty(axlimits), disp([upper(mfilename) ' does not remember any axis limits to reset.']); end; Daniel@0: for k=1:size(axlimits,1), Daniel@0: if any(get(axlimits(k,1),'XLim')~=axlimits(k,2:3)), set(axlimits(k,1),'XLim',axlimits(k,2:3)); end; Daniel@0: if any(get(axlimits(k,1),'YLim')~=axlimits(k,4:5)), set(axlimits(k,1),'YLim',axlimits(k,4:5)); end; Daniel@0: if any(get(axlimits(k,1),'ZLim')~=axlimits(k,6:7)), set(axlimits(k,1),'ZLim',axlimits(k,6:7)); end; Daniel@0: end; Daniel@0: Daniel@0: Daniel@0: Daniel@0: function out = arrow_WarpToFill(notstretched,manualcamera,curax) Daniel@0: % check if we are in "WarpToFill" mode. Daniel@0: out = strcmp(get(curax,'WarpToFill'),'on'); Daniel@0: % 'WarpToFill' is undocumented, so may need to replace this by Daniel@0: % out = ~( any(notstretched) & any(manualcamera) ); Daniel@0: Daniel@0: Daniel@0: Daniel@0: function out = arrow_warnlimits(axlimits,narrows) Daniel@0: % create a warning message if we've changed the axis limits Daniel@0: msg = ''; Daniel@0: switch (size(axlimits,1)==1) Daniel@0: case 1, msg=''; Daniel@0: case 2, msg='on two axes '; Daniel@0: otherwise, msg='on several axes '; Daniel@0: end; Daniel@0: msg = [upper(mfilename) ' changed the axis limits ' msg ... Daniel@0: 'when adding the arrow']; Daniel@0: if (narrows>1), msg=[msg 's']; end; Daniel@0: out = [msg '.' sprintf('\n') ' Call ' upper(mfilename) ... Daniel@0: ' FIXLIMITS to reset them now.']; Daniel@0: Daniel@0: Daniel@0: Daniel@0: function arrow_copyprops(fm,to) Daniel@0: % copy line properties to patches Daniel@0: props = {'EraseMode','LineStyle','LineWidth','Marker','MarkerSize',... Daniel@0: 'MarkerEdgeColor','MarkerFaceColor','ButtonDownFcn', ... Daniel@0: 'Clipping','DeleteFcn','BusyAction','HandleVisibility', ... Daniel@0: 'Selected','SelectionHighlight','Visible'}; Daniel@0: lineprops = {'Color', props{:}}; Daniel@0: patchprops = {'EdgeColor',props{:}}; Daniel@0: patch2props = {'FaceColor',patchprops{:}}; Daniel@0: fmpatch = strcmp(get(fm,'Type'),'patch'); Daniel@0: topatch = strcmp(get(to,'Type'),'patch'); Daniel@0: set(to( fmpatch& topatch),patch2props,get(fm( fmpatch& topatch),patch2props)); %p->p Daniel@0: set(to(~fmpatch&~topatch),lineprops, get(fm(~fmpatch&~topatch),lineprops )); %l->l Daniel@0: set(to( fmpatch&~topatch),lineprops, get(fm( fmpatch&~topatch),patchprops )); %p->l Daniel@0: set(to(~fmpatch& topatch),patchprops, get(fm(~fmpatch& topatch),lineprops) ,'FaceColor','none'); %l->p Daniel@0: Daniel@0: Daniel@0: Daniel@0: function arrow_props Daniel@0: % display further help info about ARROW properties Daniel@0: c = sprintf('\n'); Daniel@0: disp([c ... Daniel@0: 'ARROW Properties: Default values are given in [square brackets], and other' c ... Daniel@0: ' acceptable equivalent property names are in (parenthesis).' c c ... Daniel@0: ' Start The starting points. For N arrows, B' c ... Daniel@0: ' this should be a Nx2 or Nx3 matrix. /|\ ^' c ... Daniel@0: ' Stop The end points. For N arrows, this /|||\ |' c ... Daniel@0: ' should be a Nx2 or Nx3 matrix. //|||\\ L|' c ... Daniel@0: ' Length Length of the arrowhead (in pixels on ///|||\\\ e|' c ... Daniel@0: ' screen, points on a page). [16] (Len) ////|||\\\\ n|' c ... Daniel@0: ' BaseAngle Angle (degrees) of the base angle /////|D|\\\\\ g|' c ... Daniel@0: ' ADE. For a simple stick arrow, use //// ||| \\\\ t|' c ... Daniel@0: ' BaseAngle=TipAngle. [90] (Base) /// ||| \\\ h|' c ... Daniel@0: ' TipAngle Angle (degrees) of tip angle ABC. //<----->|| \\ |' c ... Daniel@0: ' [16] (Tip) / base ||| \ V' c ... Daniel@0: ' Width Width of the base in pixels. Not E angle ||<-------->C' c ... Daniel@0: ' the ''LineWidth'' prop. [0] (Wid) |||tipangle' c ... Daniel@0: ' Page If provided, non-empty, and not NaN, |||' c ... Daniel@0: ' this causes ARROW to use hardcopy |||' c ... Daniel@0: ' rather than onscreen proportions. A' c ... Daniel@0: ' This is important if screen aspect --> <-- width' c ... Daniel@0: ' ratio and hardcopy aspect ratio are ----CrossDir---->' c ... Daniel@0: ' vastly different. []' c... Daniel@0: ' CrossDir A vector giving the direction towards which the fletches' c ... Daniel@0: ' on the arrow should go. [computed such that it is perpen-' c ... Daniel@0: ' dicular to both the arrow direction and the view direction' c ... Daniel@0: ' (i.e., as if it was pasted on a normal 2-D graph)] (Note' c ... Daniel@0: ' that CrossDir is a vector. Also note that if an axis is' c ... Daniel@0: ' plotted on a log scale, then the corresponding component' c ... Daniel@0: ' of CrossDir must also be set appropriately, i.e., to 1 for' c ... Daniel@0: ' no change in that direction, >1 for a positive change, >0' c ... Daniel@0: ' and <1 for negative change.)' c ... Daniel@0: ' NormalDir A vector normal to the fletch direction (CrossDir is then' c ... Daniel@0: ' computed by the vector cross product [Line]x[NormalDir]). []' c ... Daniel@0: ' (Note that NormalDir is a vector. Unlike CrossDir,' c ... Daniel@0: ' NormalDir is used as is regardless of log-scaled axes.)' c ... Daniel@0: ' Ends Set which end has an arrowhead. Valid values are ''none'',' c ... Daniel@0: ' ''stop'', ''start'', and ''both''. [''stop''] (End)' c... Daniel@0: ' ObjectHandles Vector of handles to previously-created arrows to be' c ... Daniel@0: ' updated or line objects to be converted to arrows.' c ... Daniel@0: ' [] (Object,Handle)' c ]); Daniel@0: Daniel@0: Daniel@0: Daniel@0: function out = arrow_demo Daniel@0: % demo Daniel@0: % create the data Daniel@0: [x,y,z] = peaks; Daniel@0: [ddd,out.iii]=max(z(:)); Daniel@0: out.axlim = [min(x(:)) max(x(:)) min(y(:)) max(y(:)) min(z(:)) max(z(:))]; Daniel@0: Daniel@0: % modify it by inserting some NaN's Daniel@0: [m,n] = size(z); Daniel@0: m = floor(m/2); Daniel@0: n = floor(n/2); Daniel@0: z(1:m,1:n) = NaN*ones(m,n); Daniel@0: Daniel@0: % graph it Daniel@0: clf('reset'); Daniel@0: out.hs=surf(x,y,z); Daniel@0: out.x=x; out.y=y; out.z=z; Daniel@0: xlabel('x'); ylabel('y'); Daniel@0: Daniel@0: function h = arrow_demo3(in) Daniel@0: % set the view Daniel@0: axlim = in.axlim; Daniel@0: axis(axlim); Daniel@0: zlabel('z'); Daniel@0: %set(in.hs,'FaceColor','interp'); Daniel@0: view(viewmtx(-37.5,30,20)); Daniel@0: title(['Demo of the capabilities of the ARROW function in 3-D']); Daniel@0: Daniel@0: % Normal blue arrow Daniel@0: h1 = feval(mfilename,[axlim(1) axlim(4) 4],[-.8 1.2 4], ... Daniel@0: 'EdgeColor','b','FaceColor','b'); Daniel@0: Daniel@0: % Normal white arrow, clipped by the surface Daniel@0: h2 = feval(mfilename,axlim([1 4 6]),[0 2 4]); Daniel@0: t=text(-2.4,2.7,7.7,'arrow clipped by surf'); Daniel@0: Daniel@0: % Baseangle<90 Daniel@0: h3 = feval(mfilename,[3 .125 3.5],[1.375 0.125 3.5],30,50); Daniel@0: t2=text(3.1,.125,3.5,'local maximum'); Daniel@0: Daniel@0: % Baseangle<90, fill and edge colors different Daniel@0: h4 = feval(mfilename,axlim(1:2:5)*.5,[0 0 0],36,60,25, ... Daniel@0: 'EdgeColor','b','FaceColor','c'); Daniel@0: t3=text(axlim(1)*.5,axlim(3)*.5,axlim(5)*.5-.75,'origin'); Daniel@0: set(t3,'HorizontalAlignment','center'); Daniel@0: Daniel@0: % Baseangle>90, black fill Daniel@0: h5 = feval(mfilename,[-2.9 2.9 3],[-1.3 .4 3.2],30,120,[],6, ... Daniel@0: 'EdgeColor','r','FaceColor','k','LineWidth',2); Daniel@0: Daniel@0: % Baseangle>90, no fill Daniel@0: h6 = feval(mfilename,[-2.9 2.9 1.3],[-1.3 .4 1.5],30,120,[],6, ... Daniel@0: 'EdgeColor','r','FaceColor','none','LineWidth',2); Daniel@0: Daniel@0: % Stick arrow Daniel@0: h7 = feval(mfilename,[-1.6 -1.65 -6.5],[0 -1.65 -6.5],[],16,16); Daniel@0: t4=text(-1.5,-1.65,-7.25,'global mininum'); Daniel@0: set(t4,'HorizontalAlignment','center'); Daniel@0: Daniel@0: % Normal, black fill Daniel@0: h8 = feval(mfilename,[-1.4 0 -7.2],[-1.4 0 -3],'FaceColor','k'); Daniel@0: t5=text(-1.5,0,-7.75,'local minimum'); Daniel@0: set(t5,'HorizontalAlignment','center'); Daniel@0: Daniel@0: % Gray fill, crossdir specified, 'LineStyle' -- Daniel@0: h9 = feval(mfilename,[-3 2.2 -6],[-3 2.2 -.05],36,[],27,6,[],[0 -1 0], ... Daniel@0: 'EdgeColor','k','FaceColor',.75*[1 1 1],'LineStyle','--'); Daniel@0: Daniel@0: % a series of normal arrows, linearly spaced, crossdir specified Daniel@0: h10y=(0:4)'/3; Daniel@0: h10 = feval(mfilename,[-3*ones(size(h10y)) h10y -6.5*ones(size(h10y))], ... Daniel@0: [-3*ones(size(h10y)) h10y -.05*ones(size(h10y))], ... Daniel@0: 12,[],[],[],[],[0 -1 0]); Daniel@0: Daniel@0: % a series of normal arrows, linearly spaced Daniel@0: h11x=(1:.33:2.8)'; Daniel@0: h11 = feval(mfilename,[h11x -3*ones(size(h11x)) 6.5*ones(size(h11x))], ... Daniel@0: [h11x -3*ones(size(h11x)) -.05*ones(size(h11x))]); Daniel@0: Daniel@0: % series of magenta arrows, radially oriented, crossdir specified Daniel@0: h12x=2; h12y=-3; h12z=axlim(5)/2; h12xr=1; h12zr=h12z; ir=.15;or=.81; Daniel@0: h12t=(0:11)'/6*pi; Daniel@0: h12 = feval(mfilename, ... Daniel@0: [h12x+h12xr*cos(h12t)*ir h12y*ones(size(h12t)) ... Daniel@0: h12z+h12zr*sin(h12t)*ir],[h12x+h12xr*cos(h12t)*or ... Daniel@0: h12y*ones(size(h12t)) h12z+h12zr*sin(h12t)*or], ... Daniel@0: 10,[],[],[],[], ... Daniel@0: [-h12xr*sin(h12t) zeros(size(h12t)) h12zr*cos(h12t)],... Daniel@0: 'FaceColor','none','EdgeColor','m'); Daniel@0: Daniel@0: % series of normal arrows, tangentially oriented, crossdir specified Daniel@0: or13=.91; h13t=(0:.5:12)'/6*pi; Daniel@0: locs = [h12x+h12xr*cos(h13t)*or13 h12y*ones(size(h13t)) h12z+h12zr*sin(h13t)*or13]; Daniel@0: h13 = feval(mfilename,locs(1:end-1,:),locs(2:end,:),6); Daniel@0: Daniel@0: % arrow with no line ==> oriented downwards Daniel@0: h14 = feval(mfilename,[3 3 .100001],[3 3 .1],30); Daniel@0: t6=text(3,3,3.6,'no line'); set(t6,'HorizontalAlignment','center'); Daniel@0: Daniel@0: % arrow with arrowheads at both ends Daniel@0: h15 = feval(mfilename,[-.5 -3 -3],[1 -3 -3],'Ends','both','FaceColor','g', ... Daniel@0: 'Length',20,'Width',3,'CrossDir',[0 0 1],'TipAngle',25); Daniel@0: Daniel@0: h=[h1;h2;h3;h4;h5;h6;h7;h8;h9;h10;h11;h12;h13;h14;h15]; Daniel@0: Daniel@0: function h = arrow_demo2(in) Daniel@0: axlim = in.axlim; Daniel@0: dolog = 1; Daniel@0: if (dolog), set(in.hs,'YData',10.^get(in.hs,'YData')); end; Daniel@0: shading('interp'); Daniel@0: view(2); Daniel@0: title(['Demo of the capabilities of the ARROW function in 2-D']); Daniel@0: hold on; [C,H]=contour(in.x,in.y,in.z,20,'-'); hold off; Daniel@0: for k=H', Daniel@0: set(k,'ZData',(axlim(6)+1)*ones(size(get(k,'XData'))),'Color','k'); Daniel@0: if (dolog), set(k,'YData',10.^get(k,'YData')); end; Daniel@0: end; Daniel@0: if (dolog), axis([axlim(1:2) 10.^axlim(3:4)]); set(gca,'YScale','log'); Daniel@0: else, axis(axlim(1:4)); end; Daniel@0: Daniel@0: % Normal blue arrow Daniel@0: start = [axlim(1) axlim(4) axlim(6)+2]; Daniel@0: stop = [in.x(in.iii) in.y(in.iii) axlim(6)+2]; Daniel@0: if (dolog), start(:,2)=10.^start(:,2); stop(:,2)=10.^stop(:,2); end; Daniel@0: h1 = feval(mfilename,start,stop,'EdgeColor','b','FaceColor','b'); Daniel@0: Daniel@0: % three arrows with varying fill, width, and baseangle Daniel@0: start = [-3 -3 10; -3 -1.5 10; -1.5 -3 10]; Daniel@0: stop = [-.03 -.03 10; -.03 -1.5 10; -1.5 -.03 10]; Daniel@0: if (dolog), start(:,2)=10.^start(:,2); stop(:,2)=10.^stop(:,2); end; Daniel@0: h2 = feval(mfilename,start,stop,24,[90;60;120],[],[0;0;4],'Ends',str2mat('both','stop','stop')); Daniel@0: set(h2(2),'EdgeColor',[0 .35 0],'FaceColor',[0 .85 .85]); Daniel@0: set(h2(3),'EdgeColor','r','FaceColor',[1 .5 1]); Daniel@0: h=[h1;h2];