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