annotate toolboxes/FullBNT-1.0.7/GraphViz/arrow.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [h,yy,zz] = arrow(varargin)
wolffd@0 2 % ARROW Draw a line with an arrowhead.
wolffd@0 3 %
wolffd@0 4 % ARROW(Start,Stop) draws a line with an arrow from Start to Stop (points
wolffd@0 5 % should be vectors of length 2 or 3, or matrices with 2 or 3
wolffd@0 6 % columns), and returns the graphics handle of the arrow(s).
wolffd@0 7 %
wolffd@0 8 % ARROW uses the mouse (click-drag) to create an arrow.
wolffd@0 9 %
wolffd@0 10 % ARROW DEMO & ARROW DEMO2 show 3-D & 2-D demos of the capabilities of ARROW.
wolffd@0 11 %
wolffd@0 12 % ARROW may be called with a normal argument list or a property-based list.
wolffd@0 13 % ARROW(Start,Stop,Length,BaseAngle,TipAngle,Width,Page,CrossDir) is
wolffd@0 14 % the full normal argument list, where all but the Start and Stop
wolffd@0 15 % points are optional. If you need to specify a later argument (e.g.,
wolffd@0 16 % Page) but want default values of earlier ones (e.g., TipAngle),
wolffd@0 17 % pass an empty matrix for the earlier ones (e.g., TipAngle=[]).
wolffd@0 18 %
wolffd@0 19 % ARROW('Property1',PropVal1,'Property2',PropVal2,...) creates arrows with the
wolffd@0 20 % given properties, using default values for any unspecified or given as
wolffd@0 21 % 'default' or NaN. Some properties used for line and patch objects are
wolffd@0 22 % used in a modified fashion, others are passed directly to LINE, PATCH,
wolffd@0 23 % or SET. For a detailed properties explanation, call ARROW PROPERTIES.
wolffd@0 24 %
wolffd@0 25 % Start The starting points. B
wolffd@0 26 % Stop The end points. /|\ ^
wolffd@0 27 % Length Length of the arrowhead in pixels. /|||\ |
wolffd@0 28 % BaseAngle Base angle in degrees (ADE). //|||\\ L|
wolffd@0 29 % TipAngle Tip angle in degrees (ABC). ///|||\\\ e|
wolffd@0 30 % Width Width of the base in pixels. ////|||\\\\ n|
wolffd@0 31 % Page Use hardcopy proportions. /////|D|\\\\\ g|
wolffd@0 32 % CrossDir Vector || to arrowhead plane. //// ||| \\\\ t|
wolffd@0 33 % NormalDir Vector out of arrowhead plane. /// ||| \\\ h|
wolffd@0 34 % Ends Which end has an arrowhead. //<----->|| \\ |
wolffd@0 35 % ObjectHandles Vector of handles to update. / base ||| \ V
wolffd@0 36 % E angle||<-------->C
wolffd@0 37 % ARROW(H,'Prop1',PropVal1,...), where H is a |||tipangle
wolffd@0 38 % vector of handles to previously-created arrows |||
wolffd@0 39 % and/or line objects, will update the previously- |||
wolffd@0 40 % created arrows according to the current view -->|A|<-- width
wolffd@0 41 % and any specified properties, and will convert
wolffd@0 42 % two-point line objects to corresponding arrows. ARROW(H) will update
wolffd@0 43 % the arrows if the current view has changed. Root, figure, or axes
wolffd@0 44 % handles included in H are replaced by all descendant Arrow objects.
wolffd@0 45 %
wolffd@0 46 % A property list can follow any specified normal argument list, e.g.,
wolffd@0 47 % ARROW([1 2 3],[0 0 0],36,'BaseAngle',60) creates an arrow from (1,2,3) to
wolffd@0 48 % the origin, with an arrowhead of length 36 pixels and 60-degree base angle.
wolffd@0 49 %
wolffd@0 50 % The basic arguments or properties can generally be vectorized to create
wolffd@0 51 % multiple arrows with the same call. This is done by passing a property
wolffd@0 52 % with one row per arrow, or, if all arrows are to have the same property
wolffd@0 53 % value, just one row may be specified.
wolffd@0 54 %
wolffd@0 55 % You may want to execute AXIS(AXIS) before calling ARROW so it doesn't change
wolffd@0 56 % the axes on you; ARROW determines the sizes of arrow components BEFORE the
wolffd@0 57 % arrow is plotted, so if ARROW changes axis limits, arrows may be malformed.
wolffd@0 58 %
wolffd@0 59 % This version of ARROW uses features of MATLAB 5 and is incompatible with
wolffd@0 60 % earlier MATLAB versions (ARROW for MATLAB 4.2c is available separately);
wolffd@0 61 % some problems with perspective plots still exist.
wolffd@0 62
wolffd@0 63 % Copyright (c)1995-1997, Erik A. Johnson <johnsone@uiuc.edu>, 8/14/97
wolffd@0 64
wolffd@0 65 % Revision history:
wolffd@0 66 % 8/14/97 EAJ Added workaround for MATLAB 5.1 scalar logical transpose bug.
wolffd@0 67 % 7/21/97 EAJ Fixed a few misc bugs.
wolffd@0 68 % 7/14/97 EAJ Make arrow([],'Prop',...) do nothing (no old handles)
wolffd@0 69 % 6/23/97 EAJ MATLAB 5 compatible version, release.
wolffd@0 70 % 5/27/97 EAJ Added Line Arrows back in. Corrected a few bugs.
wolffd@0 71 % 5/26/97 EAJ Changed missing Start/Stop to mouse-selected arrows.
wolffd@0 72 % 5/19/97 EAJ MATLAB 5 compatible version, beta.
wolffd@0 73 % 4/13/97 EAJ MATLAB 5 compatible version, alpha.
wolffd@0 74 % 1/31/97 EAJ Fixed bug with multiple arrows and unspecified Z coords.
wolffd@0 75 % 12/05/96 EAJ Fixed one more bug with log plots and NormalDir specified
wolffd@0 76 % 10/24/96 EAJ Fixed bug with log plots and NormalDir specified
wolffd@0 77 % 11/13/95 EAJ Corrected handling for 'reverse' axis directions
wolffd@0 78 % 10/06/95 EAJ Corrected occasional conflict with SUBPLOT
wolffd@0 79 % 4/24/95 EAJ A major rewrite.
wolffd@0 80 % Fall 94 EAJ Original code.
wolffd@0 81
wolffd@0 82 % Things to be done:
wolffd@0 83 % - segment parsing, computing, and plotting into separate subfunctions
wolffd@0 84 % - change computing from Xform to Camera paradigms
wolffd@0 85 % + this will help especially with 3-D perspective plots
wolffd@0 86 % + if the WarpToFill section works right, remove warning code
wolffd@0 87 % + when perpsective works properly, remove perspective warning code
wolffd@0 88 % - add cell property values and struct property name/values (like get/set)
wolffd@0 89 % - get rid of NaN as the "default" data label
wolffd@0 90 % + perhaps change userdata to a struct and don't include (or leave
wolffd@0 91 % empty) the values specified as default; or use a cell containing
wolffd@0 92 % an empty matrix for a default value
wolffd@0 93 % - add functionality of GET to retrieve current values of ARROW properties
wolffd@0 94
wolffd@0 95 % Many thanks to Keith Rogers <kerog@ai.mit.edu> for his many excellent
wolffd@0 96 % suggestions and beta testing. Check out his shareware package MATDRAW.
wolffd@0 97 % He has permission to distribute ARROW with MATDRAW.
wolffd@0 98
wolffd@0 99 % global variable initialization
wolffd@0 100 global ARROW_PERSP_WARN ARROW_STRETCH_WARN ARROW_AXLIMITS
wolffd@0 101 if isempty(ARROW_PERSP_WARN ), ARROW_PERSP_WARN =1; end;
wolffd@0 102 if isempty(ARROW_STRETCH_WARN), ARROW_STRETCH_WARN=1; end;
wolffd@0 103
wolffd@0 104 % Handle callbacks
wolffd@0 105 if (nargin>0 & isstr(varargin{1}) & strcmp(lower(varargin{1}),'callback')),
wolffd@0 106 arrow_callback(varargin{2:end}); return;
wolffd@0 107 end;
wolffd@0 108
wolffd@0 109 % Are we doing the demo?
wolffd@0 110 c = sprintf('\n');
wolffd@0 111 if (nargin==1 & isstr(varargin{1})),
wolffd@0 112 arg1 = lower(varargin{1});
wolffd@0 113 if strncmp(arg1,'prop',4), arrow_props;
wolffd@0 114 elseif strncmp(arg1,'demo',4)
wolffd@0 115 clf reset
wolffd@0 116 demo_info = arrow_demo;
wolffd@0 117 if ~strncmp(arg1,'demo2',5),
wolffd@0 118 hh=arrow_demo3(demo_info);
wolffd@0 119 else,
wolffd@0 120 hh=arrow_demo2(demo_info);
wolffd@0 121 end;
wolffd@0 122 if (nargout>=1), h=hh; end;
wolffd@0 123 elseif strncmp(arg1,'fixlimits',3),
wolffd@0 124 arrow_fixlimits(ARROW_AXLIMITS);
wolffd@0 125 ARROW_AXLIMITS=[];
wolffd@0 126 elseif strncmp(arg1,'help',4),
wolffd@0 127 disp(help(mfilename));
wolffd@0 128 else,
wolffd@0 129 error([upper(mfilename) ' got an unknown single-argument string ''' deblank(arg1) '''.']);
wolffd@0 130 end;
wolffd@0 131 return;
wolffd@0 132 end;
wolffd@0 133
wolffd@0 134 % Check # of arguments
wolffd@0 135 if (nargout>3), error([upper(mfilename) ' produces at most 3 output arguments.']); end;
wolffd@0 136
wolffd@0 137 % find first property number
wolffd@0 138 firstprop = nargin+1;
wolffd@0 139 for k=1:length(varargin), if ~isnumeric(varargin{k}), firstprop=k; break; end; end;
wolffd@0 140 lastnumeric = firstprop-1;
wolffd@0 141
wolffd@0 142 % check property list
wolffd@0 143 if (firstprop<=nargin),
wolffd@0 144 for k=firstprop:2:nargin,
wolffd@0 145 curarg = varargin{k};
wolffd@0 146 if ~isstr(curarg) | sum(size(curarg)>1)>1,
wolffd@0 147 error([upper(mfilename) ' requires that a property name be a single string.']);
wolffd@0 148 end;
wolffd@0 149 end;
wolffd@0 150 if (rem(nargin-firstprop,2)~=1),
wolffd@0 151 error([upper(mfilename) ' requires that the property ''' ...
wolffd@0 152 varargin{nargin} ''' be paired with a property value.']);
wolffd@0 153 end;
wolffd@0 154 end;
wolffd@0 155
wolffd@0 156 % default output
wolffd@0 157 if (nargout>0), h=[]; end;
wolffd@0 158 if (nargout>1), yy=[]; end;
wolffd@0 159 if (nargout>2), zz=[]; end;
wolffd@0 160
wolffd@0 161 % set values to empty matrices
wolffd@0 162 start = [];
wolffd@0 163 stop = [];
wolffd@0 164 len = [];
wolffd@0 165 baseangle = [];
wolffd@0 166 tipangle = [];
wolffd@0 167 wid = [];
wolffd@0 168 page = [];
wolffd@0 169 crossdir = [];
wolffd@0 170 ends = [];
wolffd@0 171 ax = [];
wolffd@0 172 oldh = [];
wolffd@0 173 ispatch = [];
wolffd@0 174 defstart = [NaN NaN NaN];
wolffd@0 175 defstop = [NaN NaN NaN];
wolffd@0 176 deflen = 16;
wolffd@0 177 defbaseangle = 90;
wolffd@0 178 deftipangle = 16;
wolffd@0 179 defwid = 0;
wolffd@0 180 defpage = 0;
wolffd@0 181 defcrossdir = [NaN NaN NaN];
wolffd@0 182 defends = 1;
wolffd@0 183 defoldh = [];
wolffd@0 184 defispatch = 1;
wolffd@0 185
wolffd@0 186 % The 'Tag' we'll put on our arrows
wolffd@0 187 ArrowTag = 'Arrow';
wolffd@0 188
wolffd@0 189 % check for oldstyle arguments
wolffd@0 190 if (firstprop==2),
wolffd@0 191 % assume arg1 is a set of handles
wolffd@0 192 oldh = varargin{1}(:);
wolffd@0 193 if isempty(oldh), return; end;
wolffd@0 194 elseif (firstprop>9),
wolffd@0 195 error([upper(mfilename) ' takes at most 8 non-property arguments.']);
wolffd@0 196 elseif (firstprop>2),
wolffd@0 197 s = str2mat('start','stop','len','baseangle','tipangle','wid','page','crossdir');
wolffd@0 198 for k=1:firstprop-1, eval([deblank(s(k,:)) '=varargin{k};']); end;
wolffd@0 199 end;
wolffd@0 200
wolffd@0 201 % parse property pairs
wolffd@0 202 extraprops={};
wolffd@0 203 for k=firstprop:2:nargin,
wolffd@0 204 prop = varargin{k};
wolffd@0 205 val = varargin{k+1};
wolffd@0 206 prop = [lower(prop(:)') ' '];
wolffd@0 207 if strncmp(prop,'start' ,5), start = val;
wolffd@0 208 elseif strncmp(prop,'stop' ,4), stop = val;
wolffd@0 209 elseif strncmp(prop,'len' ,3), len = val(:);
wolffd@0 210 elseif strncmp(prop,'base' ,4), baseangle = val(:);
wolffd@0 211 elseif strncmp(prop,'tip' ,3), tipangle = val(:);
wolffd@0 212 elseif strncmp(prop,'wid' ,3), wid = val(:);
wolffd@0 213 elseif strncmp(prop,'page' ,4), page = val;
wolffd@0 214 elseif strncmp(prop,'cross' ,5), crossdir = val;
wolffd@0 215 elseif strncmp(prop,'norm' ,4), if (isstr(val)), crossdir=val; else, crossdir=val*sqrt(-1); end;
wolffd@0 216 elseif strncmp(prop,'end' ,3), ends = val;
wolffd@0 217 elseif strncmp(prop,'object',6), oldh = val(:);
wolffd@0 218 elseif strncmp(prop,'handle',6), oldh = val(:);
wolffd@0 219 elseif strncmp(prop,'type' ,4), ispatch = val;
wolffd@0 220 elseif strncmp(prop,'userd' ,5), %ignore it
wolffd@0 221 else,
wolffd@0 222 % make sure it is a valid patch or line property
wolffd@0 223 eval('get(0,[''DefaultPatch'' varargin{k}]);err=0;','err=1;'); errstr=lasterr;
wolffd@0 224 if (err), eval('get(0,[''DefaultLine'' varargin{k}]);err=0;','err=1;'); end;
wolffd@0 225 if (err),
wolffd@0 226 errstr(1:max(find(errstr==setstr(13)|errstr==setstr(10)))) = '';
wolffd@0 227 error([upper(mfilename) ' got ' errstr]);
wolffd@0 228 end;
wolffd@0 229 extraprops={extraprops{:},varargin{k},val};
wolffd@0 230 end;
wolffd@0 231 end;
wolffd@0 232
wolffd@0 233 % Check if we got 'default' values
wolffd@0 234 start = arrow_defcheck(start ,defstart ,'Start' );
wolffd@0 235 stop = arrow_defcheck(stop ,defstop ,'Stop' );
wolffd@0 236 len = arrow_defcheck(len ,deflen ,'Length' );
wolffd@0 237 baseangle = arrow_defcheck(baseangle,defbaseangle,'BaseAngle' );
wolffd@0 238 tipangle = arrow_defcheck(tipangle ,deftipangle ,'TipAngle' );
wolffd@0 239 wid = arrow_defcheck(wid ,defwid ,'Width' );
wolffd@0 240 crossdir = arrow_defcheck(crossdir ,defcrossdir ,'CrossDir' );
wolffd@0 241 page = arrow_defcheck(page ,defpage ,'Page' );
wolffd@0 242 ends = arrow_defcheck(ends ,defends ,'' );
wolffd@0 243 oldh = arrow_defcheck(oldh ,[] ,'ObjectHandles');
wolffd@0 244 ispatch = arrow_defcheck(ispatch ,defispatch ,'' );
wolffd@0 245
wolffd@0 246 % check transpose on arguments
wolffd@0 247 [m,n]=size(start ); if any(m==[2 3])&(n==1|n>3), start = start'; end;
wolffd@0 248 [m,n]=size(stop ); if any(m==[2 3])&(n==1|n>3), stop = stop'; end;
wolffd@0 249 [m,n]=size(crossdir); if any(m==[2 3])&(n==1|n>3), crossdir = crossdir'; end;
wolffd@0 250
wolffd@0 251 % convert strings to numbers
wolffd@0 252 if ~isempty(ends) & isstr(ends),
wolffd@0 253 endsorig = ends;
wolffd@0 254 [m,n] = size(ends);
wolffd@0 255 col = lower([ends(:,1:min(3,n)) ones(m,max(0,3-n))*' ']);
wolffd@0 256 ends = NaN*ones(m,1);
wolffd@0 257 oo = ones(1,m);
wolffd@0 258 ii=find(all(col'==['non']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*0; end;
wolffd@0 259 ii=find(all(col'==['sto']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*1; end;
wolffd@0 260 ii=find(all(col'==['sta']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*2; end;
wolffd@0 261 ii=find(all(col'==['bot']'*oo)'); if ~isempty(ii), ends(ii)=ones(length(ii),1)*3; end;
wolffd@0 262 if any(isnan(ends)),
wolffd@0 263 ii = min(find(isnan(ends)));
wolffd@0 264 error([upper(mfilename) ' does not recognize ' deblank(endsorig(ii,:)) ' as a valid Ends value.']);
wolffd@0 265 end;
wolffd@0 266 else,
wolffd@0 267 ends = ends(:);
wolffd@0 268 end;
wolffd@0 269 if ~isempty(ispatch) & isstr(ispatch),
wolffd@0 270 col = lower(ispatch(:,1));
wolffd@0 271 patchchar='p'; linechar='l'; defchar=' ';
wolffd@0 272 mask = col~=patchchar & col~=linechar & col~=defchar;
wolffd@0 273 if any(mask)
wolffd@0 274 error([upper(mfilename) ' does not recognize ' deblank(ispatch(min(find(mask)),:)) ' as a valid Type value.']);
wolffd@0 275 end;
wolffd@0 276 ispatch = (col==patchchar)*1 + (col==linechar)*0 + (col==defchar)*defispatch;
wolffd@0 277 else,
wolffd@0 278 ispatch = ispatch(:);
wolffd@0 279 end;
wolffd@0 280 oldh = oldh(:);
wolffd@0 281
wolffd@0 282 % check object handles
wolffd@0 283 if ~all(ishandle(oldh)), error([upper(mfilename) ' got invalid object handles.']); end;
wolffd@0 284
wolffd@0 285 % expand root, figure, and axes handles
wolffd@0 286 if ~isempty(oldh),
wolffd@0 287 ohtype = get(oldh,'Type');
wolffd@0 288 mask = strcmp(ohtype,'root') | strcmp(ohtype,'figure') | strcmp(ohtype,'axes');
wolffd@0 289 if any(mask),
wolffd@0 290 oldh = num2cell(oldh);
wolffd@0 291 for ii=find(mask)',
wolffd@0 292 oldh(ii) = {findobj(oldh{ii},'Tag',ArrowTag)};
wolffd@0 293 end;
wolffd@0 294 oldh = cat(1,oldh{:});
wolffd@0 295 if isempty(oldh), return; end; % no arrows to modify, so just leave
wolffd@0 296 end;
wolffd@0 297 end;
wolffd@0 298
wolffd@0 299 % largest argument length
wolffd@0 300 [mstart,junk]=size(start); [mstop,junk]=size(stop); [mcrossdir,junk]=size(crossdir);
wolffd@0 301 argsizes = [length(oldh) mstart mstop ...
wolffd@0 302 length(len) length(baseangle) length(tipangle) ...
wolffd@0 303 length(wid) length(page) mcrossdir length(ends) ];
wolffd@0 304 args=['length(ObjectHandle) '; ...
wolffd@0 305 '#rows(Start) '; ...
wolffd@0 306 '#rows(Stop) '; ...
wolffd@0 307 'length(Length) '; ...
wolffd@0 308 'length(BaseAngle) '; ...
wolffd@0 309 'length(TipAngle) '; ...
wolffd@0 310 'length(Width) '; ...
wolffd@0 311 'length(Page) '; ...
wolffd@0 312 '#rows(CrossDir) '; ...
wolffd@0 313 '#rows(Ends) '];
wolffd@0 314 if (any(imag(crossdir(:))~=0)),
wolffd@0 315 args(9,:) = '#rows(NormalDir) ';
wolffd@0 316 end;
wolffd@0 317 if isempty(oldh),
wolffd@0 318 narrows = max(argsizes);
wolffd@0 319 else,
wolffd@0 320 narrows = length(oldh);
wolffd@0 321 end;
wolffd@0 322 if (narrows<=0), narrows=1; end;
wolffd@0 323
wolffd@0 324 % Check size of arguments
wolffd@0 325 ii = find((argsizes~=0)&(argsizes~=1)&(argsizes~=narrows));
wolffd@0 326 if ~isempty(ii),
wolffd@0 327 s = args(ii',:);
wolffd@0 328 while ((size(s,2)>1)&((abs(s(:,size(s,2)))==0)|(abs(s(:,size(s,2)))==abs(' ')))),
wolffd@0 329 s = s(:,1:size(s,2)-1);
wolffd@0 330 end;
wolffd@0 331 s = [ones(length(ii),1)*[upper(mfilename) ' requires that '] s ...
wolffd@0 332 ones(length(ii),1)*[' equal the # of arrows (' num2str(narrows) ').' c]];
wolffd@0 333 s = s';
wolffd@0 334 s = s(:)';
wolffd@0 335 s = s(1:length(s)-1);
wolffd@0 336 error(setstr(s));
wolffd@0 337 end;
wolffd@0 338
wolffd@0 339 % check element length in Start, Stop, and CrossDir
wolffd@0 340 if ~isempty(start),
wolffd@0 341 [m,n] = size(start);
wolffd@0 342 if (n==2),
wolffd@0 343 start = [start NaN*ones(m,1)];
wolffd@0 344 elseif (n~=3),
wolffd@0 345 error([upper(mfilename) ' requires 2- or 3-element Start points.']);
wolffd@0 346 end;
wolffd@0 347 end;
wolffd@0 348 if ~isempty(stop),
wolffd@0 349 [m,n] = size(stop);
wolffd@0 350 if (n==2),
wolffd@0 351 stop = [stop NaN*ones(m,1)];
wolffd@0 352 elseif (n~=3),
wolffd@0 353 error([upper(mfilename) ' requires 2- or 3-element Stop points.']);
wolffd@0 354 end;
wolffd@0 355 end;
wolffd@0 356 if ~isempty(crossdir),
wolffd@0 357 [m,n] = size(crossdir);
wolffd@0 358 if (n<3),
wolffd@0 359 crossdir = [crossdir NaN*ones(m,3-n)];
wolffd@0 360 elseif (n~=3),
wolffd@0 361 if (all(imag(crossdir(:))==0)),
wolffd@0 362 error([upper(mfilename) ' requires 2- or 3-element CrossDir vectors.']);
wolffd@0 363 else,
wolffd@0 364 error([upper(mfilename) ' requires 2- or 3-element NormalDir vectors.']);
wolffd@0 365 end;
wolffd@0 366 end;
wolffd@0 367 end;
wolffd@0 368
wolffd@0 369 % fill empty arguments
wolffd@0 370 if isempty(start ), start = [Inf Inf Inf]; end;
wolffd@0 371 if isempty(stop ), stop = [Inf Inf Inf]; end;
wolffd@0 372 if isempty(len ), len = Inf; end;
wolffd@0 373 if isempty(baseangle ), baseangle = Inf; end;
wolffd@0 374 if isempty(tipangle ), tipangle = Inf; end;
wolffd@0 375 if isempty(wid ), wid = Inf; end;
wolffd@0 376 if isempty(page ), page = Inf; end;
wolffd@0 377 if isempty(crossdir ), crossdir = [Inf Inf Inf]; end;
wolffd@0 378 if isempty(ends ), ends = Inf; end;
wolffd@0 379 if isempty(ispatch ), ispatch = Inf; end;
wolffd@0 380
wolffd@0 381 % expand single-column arguments
wolffd@0 382 o = ones(narrows,1);
wolffd@0 383 if (size(start ,1)==1), start = o * start ; end;
wolffd@0 384 if (size(stop ,1)==1), stop = o * stop ; end;
wolffd@0 385 if (length(len )==1), len = o * len ; end;
wolffd@0 386 if (length(baseangle )==1), baseangle = o * baseangle ; end;
wolffd@0 387 if (length(tipangle )==1), tipangle = o * tipangle ; end;
wolffd@0 388 if (length(wid )==1), wid = o * wid ; end;
wolffd@0 389 if (length(page )==1), page = o * page ; end;
wolffd@0 390 if (size(crossdir ,1)==1), crossdir = o * crossdir ; end;
wolffd@0 391 if (length(ends )==1), ends = o * ends ; end;
wolffd@0 392 if (length(ispatch )==1), ispatch = o * ispatch ; end;
wolffd@0 393 ax = o * gca;
wolffd@0 394
wolffd@0 395 % if we've got handles, get the defaults from the handles
wolffd@0 396 if ~isempty(oldh),
wolffd@0 397 for k=1:narrows,
wolffd@0 398 oh = oldh(k);
wolffd@0 399 ud = get(oh,'UserData');
wolffd@0 400 ax(k) = get(oh,'Parent');
wolffd@0 401 ohtype = get(oh,'Type');
wolffd@0 402 if strcmp(get(oh,'Tag'),ArrowTag), % if it's an arrow already
wolffd@0 403 if isinf(ispatch(k)), ispatch(k)=strcmp(ohtype,'patch'); end;
wolffd@0 404 % arrow UserData format: [start' stop' len base tip wid page crossdir' ends]
wolffd@0 405 start0 = ud(1:3);
wolffd@0 406 stop0 = ud(4:6);
wolffd@0 407 if (isinf(len(k))), len(k) = ud( 7); end;
wolffd@0 408 if (isinf(baseangle(k))), baseangle(k) = ud( 8); end;
wolffd@0 409 if (isinf(tipangle(k))), tipangle(k) = ud( 9); end;
wolffd@0 410 if (isinf(wid(k))), wid(k) = ud(10); end;
wolffd@0 411 if (isinf(page(k))), page(k) = ud(11); end;
wolffd@0 412 if (isinf(crossdir(k,1))), crossdir(k,1) = ud(12); end;
wolffd@0 413 if (isinf(crossdir(k,2))), crossdir(k,2) = ud(13); end;
wolffd@0 414 if (isinf(crossdir(k,3))), crossdir(k,3) = ud(14); end;
wolffd@0 415 if (isinf(ends(k))), ends(k) = ud(15); end;
wolffd@0 416 elseif strcmp(ohtype,'line')|strcmp(ohtype,'patch'), % it's a non-arrow line or patch
wolffd@0 417 convLineToPatch = 1; %set to make arrow patches when converting from lines.
wolffd@0 418 if isinf(ispatch(k)), ispatch(k)=convLineToPatch|strcmp(ohtype,'patch'); end;
wolffd@0 419 x=get(oh,'XData'); x=x(~isnan(x(:))); if isempty(x), x=NaN; end;
wolffd@0 420 y=get(oh,'YData'); y=y(~isnan(y(:))); if isempty(y), y=NaN; end;
wolffd@0 421 z=get(oh,'ZData'); z=z(~isnan(z(:))); if isempty(z), z=NaN; end;
wolffd@0 422 start0 = [x(1) y(1) z(1) ];
wolffd@0 423 stop0 = [x(end) y(end) z(end)];
wolffd@0 424 else,
wolffd@0 425 error([upper(mfilename) ' cannot convert ' ohtype ' objects.']);
wolffd@0 426 end;
wolffd@0 427 ii=find(isinf(start(k,:))); if ~isempty(ii), start(k,ii)=start0(ii); end;
wolffd@0 428 ii=find(isinf(stop( k,:))); if ~isempty(ii), stop( k,ii)=stop0( ii); end;
wolffd@0 429 end;
wolffd@0 430 end;
wolffd@0 431
wolffd@0 432 % convert Inf's to NaN's
wolffd@0 433 start( isinf(start )) = NaN;
wolffd@0 434 stop( isinf(stop )) = NaN;
wolffd@0 435 len( isinf(len )) = NaN;
wolffd@0 436 baseangle( isinf(baseangle)) = NaN;
wolffd@0 437 tipangle( isinf(tipangle )) = NaN;
wolffd@0 438 wid( isinf(wid )) = NaN;
wolffd@0 439 page( isinf(page )) = NaN;
wolffd@0 440 crossdir( isinf(crossdir )) = NaN;
wolffd@0 441 ends( isinf(ends )) = NaN;
wolffd@0 442 ispatch( isinf(ispatch )) = NaN;
wolffd@0 443
wolffd@0 444 % set up the UserData data (here so not corrupted by log10's and such)
wolffd@0 445 ud = [start stop len baseangle tipangle wid page crossdir ends];
wolffd@0 446
wolffd@0 447 % Set Page defaults
wolffd@0 448 %page = (~isnan(page))&(page);
wolffd@0 449 if isnan(page)
wolffd@0 450 page = 0;
wolffd@0 451 end
wolffd@0 452
wolffd@0 453 % Get axes limits, range, min; correct for aspect ratio and log scale
wolffd@0 454 axm = zeros(3,narrows);
wolffd@0 455 axr = zeros(3,narrows);
wolffd@0 456 axrev = zeros(3,narrows);
wolffd@0 457 ap = zeros(2,narrows);
wolffd@0 458 xyzlog = zeros(3,narrows);
wolffd@0 459 limmin = zeros(2,narrows);
wolffd@0 460 limrange = zeros(2,narrows);
wolffd@0 461 oldaxlims = zeros(narrows,7);
wolffd@0 462 oneax = all(ax==ax(1));
wolffd@0 463 if (oneax),
wolffd@0 464 T = zeros(4,4);
wolffd@0 465 invT = zeros(4,4);
wolffd@0 466 else,
wolffd@0 467 T = zeros(16,narrows);
wolffd@0 468 invT = zeros(16,narrows);
wolffd@0 469 end;
wolffd@0 470 axnotdone = logical(ones(size(ax)));
wolffd@0 471 while (any(axnotdone)),
wolffd@0 472 ii = min(find(axnotdone));
wolffd@0 473 curax = ax(ii);
wolffd@0 474 curpage = page(ii);
wolffd@0 475 % get axes limits and aspect ratio
wolffd@0 476 axl = [get(curax,'XLim'); get(curax,'YLim'); get(curax,'ZLim')];
wolffd@0 477 oldaxlims(min(find(oldaxlims(:,1)==0)),:) = [curax reshape(axl',1,6)];
wolffd@0 478 % get axes size in pixels (points)
wolffd@0 479 u = get(curax,'Units');
wolffd@0 480 axposoldunits = get(curax,'Position');
wolffd@0 481 really_curpage = curpage & strcmp(u,'normalized');
wolffd@0 482 if (really_curpage),
wolffd@0 483 curfig = get(curax,'Parent');
wolffd@0 484 pu = get(curfig,'PaperUnits');
wolffd@0 485 set(curfig,'PaperUnits','points');
wolffd@0 486 pp = get(curfig,'PaperPosition');
wolffd@0 487 set(curfig,'PaperUnits',pu);
wolffd@0 488 set(curax,'Units','pixels');
wolffd@0 489 curapscreen = get(curax,'Position');
wolffd@0 490 set(curax,'Units','normalized');
wolffd@0 491 curap = pp.*get(curax,'Position');
wolffd@0 492 else,
wolffd@0 493 set(curax,'Units','pixels');
wolffd@0 494 curapscreen = get(curax,'Position');
wolffd@0 495 curap = curapscreen;
wolffd@0 496 end;
wolffd@0 497 set(curax,'Units',u);
wolffd@0 498 set(curax,'Position',axposoldunits);
wolffd@0 499 % handle non-stretched axes position
wolffd@0 500 str_stretch = { 'DataAspectRatioMode' ; ...
wolffd@0 501 'PlotBoxAspectRatioMode' ; ...
wolffd@0 502 'CameraViewAngleMode' };
wolffd@0 503 str_camera = { 'CameraPositionMode' ; ...
wolffd@0 504 'CameraTargetMode' ; ...
wolffd@0 505 'CameraViewAngleMode' ; ...
wolffd@0 506 'CameraUpVectorMode' };
wolffd@0 507 notstretched = strcmp(get(curax,str_stretch),'manual');
wolffd@0 508 manualcamera = strcmp(get(curax,str_camera),'manual');
wolffd@0 509 if ~arrow_WarpToFill(notstretched,manualcamera,curax),
wolffd@0 510 % give a warning that this has not been thoroughly tested
wolffd@0 511 if 0 & ARROW_STRETCH_WARN,
wolffd@0 512 ARROW_STRETCH_WARN = 0;
wolffd@0 513 strs = {str_stretch{1:2},str_camera{:}};
wolffd@0 514 strs = [char(ones(length(strs),1)*sprintf('\n ')) char(strs)]';
wolffd@0 515 warning([upper(mfilename) ' may not yet work quite right ' ...
wolffd@0 516 'if any of the following are ''manual'':' strs(:).']);
wolffd@0 517 end;
wolffd@0 518 % find the true pixel size of the actual axes
wolffd@0 519 texttmp = text(axl(1,[1 2 2 1 1 2 2 1]), ...
wolffd@0 520 axl(2,[1 1 2 2 1 1 2 2]), ...
wolffd@0 521 axl(3,[1 1 1 1 2 2 2 2]),'');
wolffd@0 522 set(texttmp,'Units','points');
wolffd@0 523 textpos = get(texttmp,'Position');
wolffd@0 524 delete(texttmp);
wolffd@0 525 textpos = cat(1,textpos{:});
wolffd@0 526 textpos = max(textpos(:,1:2)) - min(textpos(:,1:2));
wolffd@0 527 % adjust the axes position
wolffd@0 528 if (really_curpage),
wolffd@0 529 % adjust to printed size
wolffd@0 530 textpos = textpos * min(curap(3:4)./textpos);
wolffd@0 531 curap = [curap(1:2)+(curap(3:4)-textpos)/2 textpos];
wolffd@0 532 else,
wolffd@0 533 % adjust for pixel roundoff
wolffd@0 534 textpos = textpos * min(curapscreen(3:4)./textpos);
wolffd@0 535 curap = [curap(1:2)+(curap(3:4)-textpos)/2 textpos];
wolffd@0 536 end;
wolffd@0 537 end;
wolffd@0 538 if ARROW_PERSP_WARN & ~strcmp(get(curax,'Projection'),'orthographic'),
wolffd@0 539 ARROW_PERSP_WARN = 0;
wolffd@0 540 warning([upper(mfilename) ' does not yet work right for 3-D perspective projection.']);
wolffd@0 541 end;
wolffd@0 542 % adjust limits for log scale on axes
wolffd@0 543 curxyzlog = [strcmp(get(curax,'XScale'),'log'); ...
wolffd@0 544 strcmp(get(curax,'YScale'),'log'); ...
wolffd@0 545 strcmp(get(curax,'ZScale'),'log')];
wolffd@0 546 if (any(curxyzlog)),
wolffd@0 547 ii = find([curxyzlog;curxyzlog]);
wolffd@0 548 if (any(axl(ii)<=0)),
wolffd@0 549 error([upper(mfilename) ' does not support non-positive limits on log-scaled axes.']);
wolffd@0 550 else,
wolffd@0 551 axl(ii) = log10(axl(ii));
wolffd@0 552 end;
wolffd@0 553 end;
wolffd@0 554 % correct for 'reverse' direction on axes;
wolffd@0 555 curreverse = [strcmp(get(curax,'XDir'),'reverse'); ...
wolffd@0 556 strcmp(get(curax,'YDir'),'reverse'); ...
wolffd@0 557 strcmp(get(curax,'ZDir'),'reverse')];
wolffd@0 558 ii = find(curreverse);
wolffd@0 559 if ~isempty(ii),
wolffd@0 560 axl(ii,[1 2])=-axl(ii,[2 1]);
wolffd@0 561 end;
wolffd@0 562 % compute the range of 2-D values
wolffd@0 563 curT = get(curax,'Xform');
wolffd@0 564 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 565 lim = lim(1:2,:)./([1;1]*lim(4,:));
wolffd@0 566 curlimmin = min(lim')';
wolffd@0 567 curlimrange = max(lim')' - curlimmin;
wolffd@0 568 curinvT = inv(curT);
wolffd@0 569 if (~oneax),
wolffd@0 570 curT = curT.';
wolffd@0 571 curinvT = curinvT.';
wolffd@0 572 curT = curT(:);
wolffd@0 573 curinvT = curinvT(:);
wolffd@0 574 end;
wolffd@0 575 % check which arrows to which cur corresponds
wolffd@0 576 ii = find((ax==curax)&(page==curpage));
wolffd@0 577 oo = ones(1,length(ii));
wolffd@0 578 axr(:,ii) = diff(axl')' * oo;
wolffd@0 579 axm(:,ii) = axl(:,1) * oo;
wolffd@0 580 axrev(:,ii) = curreverse * oo;
wolffd@0 581 ap(:,ii) = curap(3:4)' * oo;
wolffd@0 582 xyzlog(:,ii) = curxyzlog * oo;
wolffd@0 583 limmin(:,ii) = curlimmin * oo;
wolffd@0 584 limrange(:,ii) = curlimrange * oo;
wolffd@0 585 if (oneax),
wolffd@0 586 T = curT;
wolffd@0 587 invT = curinvT;
wolffd@0 588 else,
wolffd@0 589 T(:,ii) = curT * oo;
wolffd@0 590 invT(:,ii) = curinvT * oo;
wolffd@0 591 end;
wolffd@0 592 axnotdone(ii) = zeros(1,length(ii));
wolffd@0 593 end;
wolffd@0 594 oldaxlims(oldaxlims(:,1)==0,:)=[];
wolffd@0 595
wolffd@0 596 % correct for log scales
wolffd@0 597 curxyzlog = xyzlog.';
wolffd@0 598 ii = find(curxyzlog(:));
wolffd@0 599 if ~isempty(ii),
wolffd@0 600 start( ii) = real(log10(start( ii)));
wolffd@0 601 stop( ii) = real(log10(stop( ii)));
wolffd@0 602 if (all(imag(crossdir)==0)), % pulled (ii) subscript on crossdir, 12/5/96 eaj
wolffd@0 603 crossdir(ii) = real(log10(crossdir(ii)));
wolffd@0 604 end;
wolffd@0 605 end;
wolffd@0 606
wolffd@0 607 % correct for reverse directions
wolffd@0 608 ii = find(axrev.');
wolffd@0 609 if ~isempty(ii),
wolffd@0 610 start( ii) = -start( ii);
wolffd@0 611 stop( ii) = -stop( ii);
wolffd@0 612 crossdir(ii) = -crossdir(ii);
wolffd@0 613 end;
wolffd@0 614
wolffd@0 615 % transpose start/stop values
wolffd@0 616 start = start.';
wolffd@0 617 stop = stop.';
wolffd@0 618
wolffd@0 619 % take care of defaults, page was done above
wolffd@0 620 ii=find(isnan(start(:) )); if ~isempty(ii), start(ii) = axm(ii)+axr(ii)/2; end;
wolffd@0 621 ii=find(isnan(stop(:) )); if ~isempty(ii), stop(ii) = axm(ii)+axr(ii)/2; end;
wolffd@0 622 ii=find(isnan(crossdir(:) )); if ~isempty(ii), crossdir(ii) = zeros(length(ii),1); end;
wolffd@0 623 ii=find(isnan(len )); if ~isempty(ii), len(ii) = ones(length(ii),1)*deflen; end;
wolffd@0 624 ii=find(isnan(baseangle )); if ~isempty(ii), baseangle(ii) = ones(length(ii),1)*defbaseangle; end;
wolffd@0 625 ii=find(isnan(tipangle )); if ~isempty(ii), tipangle(ii) = ones(length(ii),1)*deftipangle; end;
wolffd@0 626 ii=find(isnan(wid )); if ~isempty(ii), wid(ii) = ones(length(ii),1)*defwid; end;
wolffd@0 627 ii=find(isnan(ends )); if ~isempty(ii), ends(ii) = ones(length(ii),1)*defends; end;
wolffd@0 628
wolffd@0 629 % transpose rest of values
wolffd@0 630 len = len.';
wolffd@0 631 baseangle = baseangle.';
wolffd@0 632 tipangle = tipangle.';
wolffd@0 633 wid = wid.';
wolffd@0 634 page = page.';
wolffd@0 635 crossdir = crossdir.';
wolffd@0 636 ends = ends.';
wolffd@0 637 ax = ax.';
wolffd@0 638
wolffd@0 639 % given x, a 3xN matrix of points in 3-space;
wolffd@0 640 % want to convert to X, the corresponding 4xN 2-space matrix
wolffd@0 641 %
wolffd@0 642 % tmp1=[(x-axm)./axr; ones(1,size(x,1))];
wolffd@0 643 % if (oneax), X=T*tmp1;
wolffd@0 644 % else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1;
wolffd@0 645 % tmp2=zeros(4,4*N); tmp2(:)=tmp1(:);
wolffd@0 646 % X=zeros(4,N); X(:)=sum(tmp2)'; end;
wolffd@0 647 % X = X ./ (ones(4,1)*X(4,:));
wolffd@0 648
wolffd@0 649 % for all points with start==stop, start=stop-(verysmallvalue)*(up-direction);
wolffd@0 650 ii = find(all(start==stop));
wolffd@0 651 if ~isempty(ii),
wolffd@0 652 % find an arrowdir vertical on screen and perpendicular to viewer
wolffd@0 653 % transform to 2-D
wolffd@0 654 tmp1 = [(stop(:,ii)-axm(:,ii))./axr(:,ii);ones(1,length(ii))];
wolffd@0 655 if (oneax), twoD=T*tmp1;
wolffd@0 656 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T(:,ii).*tmp1;
wolffd@0 657 tmp2=zeros(4,4*length(ii)); tmp2(:)=tmp1(:);
wolffd@0 658 twoD=zeros(4,length(ii)); twoD(:)=sum(tmp2)'; end;
wolffd@0 659 twoD=twoD./(ones(4,1)*twoD(4,:));
wolffd@0 660 % move the start point down just slightly
wolffd@0 661 tmp1 = twoD + [0;-1/1000;0;0]*(limrange(2,ii)./ap(2,ii));
wolffd@0 662 % transform back to 3-D
wolffd@0 663 if (oneax), threeD=invT*tmp1;
wolffd@0 664 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT(:,ii).*tmp1;
wolffd@0 665 tmp2=zeros(4,4*length(ii)); tmp2(:)=tmp1(:);
wolffd@0 666 threeD=zeros(4,length(ii)); threeD(:)=sum(tmp2)'; end;
wolffd@0 667 start(:,ii) = (threeD(1:3,:)./(ones(3,1)*threeD(4,:))).*axr(:,ii)+axm(:,ii);
wolffd@0 668 end;
wolffd@0 669
wolffd@0 670 % compute along-arrow points
wolffd@0 671 % transform Start points
wolffd@0 672 tmp1=[(start-axm)./axr;ones(1,narrows)];
wolffd@0 673 if (oneax), X0=T*tmp1;
wolffd@0 674 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1;
wolffd@0 675 tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
wolffd@0 676 X0=zeros(4,narrows); X0(:)=sum(tmp2)'; end;
wolffd@0 677 X0=X0./(ones(4,1)*X0(4,:));
wolffd@0 678 % transform Stop points
wolffd@0 679 tmp1=[(stop-axm)./axr;ones(1,narrows)];
wolffd@0 680 if (oneax), Xf=T*tmp1;
wolffd@0 681 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T.*tmp1;
wolffd@0 682 tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
wolffd@0 683 Xf=zeros(4,narrows); Xf(:)=sum(tmp2)'; end;
wolffd@0 684 Xf=Xf./(ones(4,1)*Xf(4,:));
wolffd@0 685 % compute pixel distance between points
wolffd@0 686 D = sqrt(sum(((Xf(1:2,:)-X0(1:2,:)).*(ap./limrange)).^2));
wolffd@0 687 % compute and modify along-arrow distances
wolffd@0 688 len1 = len;
wolffd@0 689 len2 = len - (len.*tan(tipangle/180*pi)-wid/2).*tan((90-baseangle)/180*pi);
wolffd@0 690 slen0 = zeros(1,narrows);
wolffd@0 691 slen1 = len1 .* ((ends==2)|(ends==3));
wolffd@0 692 slen2 = len2 .* ((ends==2)|(ends==3));
wolffd@0 693 len0 = zeros(1,narrows);
wolffd@0 694 len1 = len1 .* ((ends==1)|(ends==3));
wolffd@0 695 len2 = len2 .* ((ends==1)|(ends==3));
wolffd@0 696 % for no start arrowhead
wolffd@0 697 ii=find((ends==1)&(D<len2));
wolffd@0 698 if ~isempty(ii),
wolffd@0 699 slen0(ii) = D(ii)-len2(ii);
wolffd@0 700 end;
wolffd@0 701 % for no end arrowhead
wolffd@0 702 ii=find((ends==2)&(D<slen2));
wolffd@0 703 if ~isempty(ii),
wolffd@0 704 len0(ii) = D(ii)-slen2(ii);
wolffd@0 705 end;
wolffd@0 706 len1 = len1 + len0;
wolffd@0 707 len2 = len2 + len0;
wolffd@0 708 slen1 = slen1 + slen0;
wolffd@0 709 slen2 = slen2 + slen0;
wolffd@0 710 % note: the division by D below will probably not be accurate if both
wolffd@0 711 % of the following are true:
wolffd@0 712 % 1. the ratio of the line length to the arrowhead
wolffd@0 713 % length is large
wolffd@0 714 % 2. the view is highly perspective.
wolffd@0 715 % compute stoppoints
wolffd@0 716 tmp1=X0.*(ones(4,1)*(len0./D))+Xf.*(ones(4,1)*(1-len0./D));
wolffd@0 717 if (oneax), tmp3=invT*tmp1;
wolffd@0 718 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
wolffd@0 719 tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
wolffd@0 720 tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
wolffd@0 721 stoppoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
wolffd@0 722 % compute tippoints
wolffd@0 723 tmp1=X0.*(ones(4,1)*(len1./D))+Xf.*(ones(4,1)*(1-len1./D));
wolffd@0 724 if (oneax), tmp3=invT*tmp1;
wolffd@0 725 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
wolffd@0 726 tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
wolffd@0 727 tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
wolffd@0 728 tippoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
wolffd@0 729 % compute basepoints
wolffd@0 730 tmp1=X0.*(ones(4,1)*(len2./D))+Xf.*(ones(4,1)*(1-len2./D));
wolffd@0 731 if (oneax), tmp3=invT*tmp1;
wolffd@0 732 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
wolffd@0 733 tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
wolffd@0 734 tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
wolffd@0 735 basepoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
wolffd@0 736 % compute startpoints
wolffd@0 737 tmp1=X0.*(ones(4,1)*(1-slen0./D))+Xf.*(ones(4,1)*(slen0./D));
wolffd@0 738 if (oneax), tmp3=invT*tmp1;
wolffd@0 739 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
wolffd@0 740 tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
wolffd@0 741 tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
wolffd@0 742 startpoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
wolffd@0 743 % compute stippoints
wolffd@0 744 tmp1=X0.*(ones(4,1)*(1-slen1./D))+Xf.*(ones(4,1)*(slen1./D));
wolffd@0 745 if (oneax), tmp3=invT*tmp1;
wolffd@0 746 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
wolffd@0 747 tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
wolffd@0 748 tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
wolffd@0 749 stippoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
wolffd@0 750 % compute sbasepoints
wolffd@0 751 tmp1=X0.*(ones(4,1)*(1-slen2./D))+Xf.*(ones(4,1)*(slen2./D));
wolffd@0 752 if (oneax), tmp3=invT*tmp1;
wolffd@0 753 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=invT.*tmp1;
wolffd@0 754 tmp2=zeros(4,4*narrows); tmp2(:)=tmp1(:);
wolffd@0 755 tmp3=zeros(4,narrows); tmp3(:)=sum(tmp2)'; end;
wolffd@0 756 sbasepoint = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)).*axr+axm;
wolffd@0 757
wolffd@0 758 % compute cross-arrow directions for arrows with NormalDir specified
wolffd@0 759 if (any(imag(crossdir(:))~=0)),
wolffd@0 760 ii = find(any(imag(crossdir)~=0));
wolffd@0 761 crossdir(:,ii) = cross((stop(:,ii)-start(:,ii))./axr(:,ii), ...
wolffd@0 762 imag(crossdir(:,ii))).*axr(:,ii);
wolffd@0 763 end;
wolffd@0 764
wolffd@0 765 % compute cross-arrow directions
wolffd@0 766 basecross = crossdir + basepoint;
wolffd@0 767 tipcross = crossdir + tippoint;
wolffd@0 768 sbasecross = crossdir + sbasepoint;
wolffd@0 769 stipcross = crossdir + stippoint;
wolffd@0 770 ii = find(all(crossdir==0)|any(isnan(crossdir)));
wolffd@0 771 if ~isempty(ii),
wolffd@0 772 numii = length(ii);
wolffd@0 773 % transform start points
wolffd@0 774 tmp1 = [basepoint(:,ii) tippoint(:,ii) sbasepoint(:,ii) stippoint(:,ii)];
wolffd@0 775 tmp1 = (tmp1-axm(:,[ii ii ii ii])) ./ axr(:,[ii ii ii ii]);
wolffd@0 776 tmp1 = [tmp1; ones(1,4*numii)];
wolffd@0 777 if (oneax), X0=T*tmp1;
wolffd@0 778 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T(:,[ii ii ii ii]).*tmp1;
wolffd@0 779 tmp2=zeros(4,16*numii); tmp2(:)=tmp1(:);
wolffd@0 780 X0=zeros(4,4*numii); X0(:)=sum(tmp2)'; end;
wolffd@0 781 X0=X0./(ones(4,1)*X0(4,:));
wolffd@0 782 % transform stop points
wolffd@0 783 tmp1 = [(2*stop(:,ii)-start(:,ii)-axm(:,ii))./axr(:,ii);ones(1,numii)];
wolffd@0 784 tmp1 = [tmp1 tmp1 tmp1 tmp1];
wolffd@0 785 if (oneax), Xf=T*tmp1;
wolffd@0 786 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=T(:,[ii ii ii ii]).*tmp1;
wolffd@0 787 tmp2=zeros(4,16*numii); tmp2(:)=tmp1(:);
wolffd@0 788 Xf=zeros(4,4*numii); Xf(:)=sum(tmp2)'; end;
wolffd@0 789 Xf=Xf./(ones(4,1)*Xf(4,:));
wolffd@0 790 % compute perpendicular directions
wolffd@0 791 pixfact = ((limrange(1,ii)./limrange(2,ii)).*(ap(2,ii)./ap(1,ii))).^2;
wolffd@0 792 pixfact = [pixfact pixfact pixfact pixfact];
wolffd@0 793 pixfact = [pixfact;1./pixfact];
wolffd@0 794 [dummyval,jj] = max(abs(Xf(1:2,:)-X0(1:2,:)));
wolffd@0 795 jj1 = ((1:4)'*ones(1,length(jj))==ones(4,1)*jj);
wolffd@0 796 jj2 = ((1:4)'*ones(1,length(jj))==ones(4,1)*(3-jj));
wolffd@0 797 jj3 = jj1(1:2,:);
wolffd@0 798 Xp = X0;
wolffd@0 799 Xp(jj2) = X0(jj2) + ones(sum(jj2(:)),1);
wolffd@0 800 Xp(jj1) = X0(jj1) - (Xf(jj2)-X0(jj2))./(Xf(jj1)-X0(jj1)) .* pixfact(jj3);
wolffd@0 801 % inverse transform the cross points
wolffd@0 802 if (oneax), Xp=invT*Xp;
wolffd@0 803 else, tmp1=[Xp;Xp;Xp;Xp]; tmp1=invT(:,[ii ii ii ii]).*tmp1;
wolffd@0 804 tmp2=zeros(4,16*numii); tmp2(:)=tmp1(:);
wolffd@0 805 Xp=zeros(4,4*numii); Xp(:)=sum(tmp2)'; end;
wolffd@0 806 Xp=(Xp(1:3,:)./(ones(3,1)*Xp(4,:))).*axr(:,[ii ii ii ii])+axm(:,[ii ii ii ii]);
wolffd@0 807 basecross(:,ii) = Xp(:,0*numii+(1:numii));
wolffd@0 808 tipcross(:,ii) = Xp(:,1*numii+(1:numii));
wolffd@0 809 sbasecross(:,ii) = Xp(:,2*numii+(1:numii));
wolffd@0 810 stipcross(:,ii) = Xp(:,3*numii+(1:numii));
wolffd@0 811 end;
wolffd@0 812
wolffd@0 813 % compute all points
wolffd@0 814 % compute start points
wolffd@0 815 axm11 = [axm axm axm axm axm axm axm axm axm axm axm];
wolffd@0 816 axr11 = [axr axr axr axr axr axr axr axr axr axr axr];
wolffd@0 817 st = [stoppoint tippoint basepoint sbasepoint stippoint startpoint stippoint sbasepoint basepoint tippoint stoppoint];
wolffd@0 818 tmp1 = (st - axm11) ./ axr11;
wolffd@0 819 tmp1 = [tmp1; ones(1,size(tmp1,2))];
wolffd@0 820 if (oneax), X0=T*tmp1;
wolffd@0 821 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=[T T T T T T T T T T T].*tmp1;
wolffd@0 822 tmp2=zeros(4,44*narrows); tmp2(:)=tmp1(:);
wolffd@0 823 X0=zeros(4,11*narrows); X0(:)=sum(tmp2)'; end;
wolffd@0 824 X0=X0./(ones(4,1)*X0(4,:));
wolffd@0 825 % compute stop points
wolffd@0 826 tmp1 = ([start tipcross basecross sbasecross stipcross stop stipcross sbasecross basecross tipcross start] ...
wolffd@0 827 - axm11) ./ axr11;
wolffd@0 828 tmp1 = [tmp1; ones(1,size(tmp1,2))];
wolffd@0 829 if (oneax), Xf=T*tmp1;
wolffd@0 830 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=[T T T T T T T T T T T].*tmp1;
wolffd@0 831 tmp2=zeros(4,44*narrows); tmp2(:)=tmp1(:);
wolffd@0 832 Xf=zeros(4,11*narrows); Xf(:)=sum(tmp2)'; end;
wolffd@0 833 Xf=Xf./(ones(4,1)*Xf(4,:));
wolffd@0 834 % compute lengths
wolffd@0 835 len0 = len.*((ends==1)|(ends==3)).*tan(tipangle/180*pi);
wolffd@0 836 slen0 = len.*((ends==2)|(ends==3)).*tan(tipangle/180*pi);
wolffd@0 837 le = [zeros(1,narrows) len0 wid/2 wid/2 slen0 zeros(1,narrows) -slen0 -wid/2 -wid/2 -len0 zeros(1,narrows)];
wolffd@0 838 aprange = ap./limrange;
wolffd@0 839 aprange = [aprange aprange aprange aprange aprange aprange aprange aprange aprange aprange aprange];
wolffd@0 840 D = sqrt(sum(((Xf(1:2,:)-X0(1:2,:)).*aprange).^2));
wolffd@0 841 Dii=find(D==0); if ~isempty(Dii), D=D+(D==0); le(Dii)=zeros(1,length(Dii)); end; %should fix DivideByZero warnings
wolffd@0 842 tmp1 = X0.*(ones(4,1)*(1-le./D)) + Xf.*(ones(4,1)*(le./D));
wolffd@0 843 % inverse transform
wolffd@0 844 if (oneax), tmp3=invT*tmp1;
wolffd@0 845 else, tmp1=[tmp1;tmp1;tmp1;tmp1]; tmp1=[invT invT invT invT invT invT invT invT invT invT invT].*tmp1;
wolffd@0 846 tmp2=zeros(4,44*narrows); tmp2(:)=tmp1(:);
wolffd@0 847 tmp3=zeros(4,11*narrows); tmp3(:)=sum(tmp2)'; end;
wolffd@0 848 pts = tmp3(1:3,:)./(ones(3,1)*tmp3(4,:)) .* axr11 + axm11;
wolffd@0 849
wolffd@0 850 % correct for ones where the crossdir was specified
wolffd@0 851 ii = find(~(all(crossdir==0)|any(isnan(crossdir))));
wolffd@0 852 if ~isempty(ii),
wolffd@0 853 D1 = [pts(:,1*narrows+ii)-pts(:,9*narrows+ii) ...
wolffd@0 854 pts(:,2*narrows+ii)-pts(:,8*narrows+ii) ...
wolffd@0 855 pts(:,3*narrows+ii)-pts(:,7*narrows+ii) ...
wolffd@0 856 pts(:,4*narrows+ii)-pts(:,6*narrows+ii) ...
wolffd@0 857 pts(:,6*narrows+ii)-pts(:,4*narrows+ii) ...
wolffd@0 858 pts(:,7*narrows+ii)-pts(:,3*narrows+ii) ...
wolffd@0 859 pts(:,8*narrows+ii)-pts(:,2*narrows+ii) ...
wolffd@0 860 pts(:,9*narrows+ii)-pts(:,1*narrows+ii)]/2;
wolffd@0 861 ii = ii'*ones(1,8) + ones(length(ii),1)*[1:4 6:9]*narrows;
wolffd@0 862 ii = ii(:)';
wolffd@0 863 pts(:,ii) = st(:,ii) + D1;
wolffd@0 864 end;
wolffd@0 865
wolffd@0 866
wolffd@0 867 % readjust for reverse directions
wolffd@0 868 iicols=(1:narrows)'; iicols=iicols(:,ones(1,11)); iicols=iicols(:).';
wolffd@0 869 tmp1=axrev(:,iicols);
wolffd@0 870 ii = find(tmp1(:)); if ~isempty(ii), pts(ii)=-pts(ii); end;
wolffd@0 871
wolffd@0 872 % readjust for log scale on axes
wolffd@0 873 tmp1=xyzlog(:,iicols);
wolffd@0 874 ii = find(tmp1(:)); if ~isempty(ii), pts(ii)=10.^pts(ii); end;
wolffd@0 875
wolffd@0 876 % compute the x,y,z coordinates of the patches;
wolffd@0 877 ii = narrows*(0:10)'*ones(1,narrows) + ones(11,1)*(1:narrows);
wolffd@0 878 ii = ii(:)';
wolffd@0 879 x = zeros(11,narrows);
wolffd@0 880 y = zeros(11,narrows);
wolffd@0 881 z = zeros(11,narrows);
wolffd@0 882 x(:) = pts(1,ii)';
wolffd@0 883 y(:) = pts(2,ii)';
wolffd@0 884 z(:) = pts(3,ii)';
wolffd@0 885
wolffd@0 886 % do the output
wolffd@0 887 if (nargout<=1)
wolffd@0 888 % % create or modify the patches
wolffd@0 889 if isnan(ispatch), ispatch =0; end
wolffd@0 890 newpatch = ispatch & (isempty(oldh)|~strcmp(get(oldh,'Type'),'patch'));
wolffd@0 891 newline = ~ispatch & (isempty(oldh)|~strcmp(get(oldh,'Type'),'line'));
wolffd@0 892 if isempty(oldh), H=zeros(narrows,1); else, H=oldh; end;
wolffd@0 893 % % make or modify the arrows
wolffd@0 894 for k=1:narrows,
wolffd@0 895 if all(isnan(ud(k,[3 6])))&arrow_is2DXY(ax(k)), zz=[]; else, zz=z(:,k); end;
wolffd@0 896 xyz = {'XData',x(:,k),'YData',y(:,k),'ZData',zz,'Tag',ArrowTag};
wolffd@0 897 if newpatch(k)|newline(k),
wolffd@0 898 if newpatch(k),
wolffd@0 899 H(k) = patch(xyz{:});
wolffd@0 900 else,
wolffd@0 901 H(k) = line(xyz{:});
wolffd@0 902 end;
wolffd@0 903 if ~isempty(oldh), arrow_copyprops(oldh(k),H(k)); end;
wolffd@0 904 else,
wolffd@0 905 if ispatch(k), xyz={xyz{:},'CData',[]}; end;
wolffd@0 906 set(H(k),xyz{:});
wolffd@0 907 end;
wolffd@0 908 end;
wolffd@0 909 if ~isempty(oldh), delete(oldh(oldh~=H)); end;
wolffd@0 910 % % additional properties
wolffd@0 911 set(H,'Clipping','off');
wolffd@0 912 set(H,{'UserData'},num2cell(ud,2));
wolffd@0 913 if (length(extraprops)>0), set(H,extraprops{:}); end;
wolffd@0 914 % handle choosing arrow Start and/or Stop locations if unspecified
wolffd@0 915 [H,oldaxlims,errstr] = arrow_clicks(H,ud,x,y,z,ax,oldaxlims);
wolffd@0 916 if ~isempty(errstr), error([upper(mfilename) ' got ' errstr]); end;
wolffd@0 917 % set the output
wolffd@0 918 if (nargout>0), h=H; end;
wolffd@0 919 % make sure the axis limits did not change
wolffd@0 920 if isempty(oldaxlims),
wolffd@0 921 ARROW_AXLIMITS = [];
wolffd@0 922 else,
wolffd@0 923 lims = get(oldaxlims(:,1),{'XLim','YLim','ZLim'})';
wolffd@0 924 lims = reshape(cat(2,lims{:}),6,size(lims,2));
wolffd@0 925 %mask = arrow_is2DXY(oldaxlims(:,1));
wolffd@0 926 %oldaxlims(mask,6:7) = lims(5:6,mask)';
wolffd@0 927 ARROW_AXLIMITS = oldaxlims(find(any(oldaxlims(:,2:7)'~=lims)),:);
wolffd@0 928 if ~isempty(ARROW_AXLIMITS),
wolffd@0 929 warning(arrow_warnlimits(ARROW_AXLIMITS,narrows));
wolffd@0 930 end;
wolffd@0 931 end;
wolffd@0 932 else,
wolffd@0 933 % don't create the patch, just return the data
wolffd@0 934 h=x;
wolffd@0 935 yy=y;
wolffd@0 936 zz=z;
wolffd@0 937 end;
wolffd@0 938
wolffd@0 939
wolffd@0 940
wolffd@0 941 function out = arrow_defcheck(in,def,prop)
wolffd@0 942 % check if we got 'default' values
wolffd@0 943 out = in;
wolffd@0 944 if ~isstr(in), return; end;
wolffd@0 945 if size(in,1)==1 & strncmp(lower(in),'def',3),
wolffd@0 946 out = def;
wolffd@0 947 elseif ~isempty(prop),
wolffd@0 948 error([upper(mfilename) ' does not recognize ''' in(:)' ''' as a valid ''' prop ''' string.']);
wolffd@0 949 end;
wolffd@0 950
wolffd@0 951
wolffd@0 952
wolffd@0 953 function [H,oldaxlims,errstr] = arrow_clicks(H,ud,x,y,z,ax,oldaxlims)
wolffd@0 954 % handle choosing arrow Start and/or Stop locations if necessary
wolffd@0 955 errstr = '';
wolffd@0 956 if isempty(H)|isempty(ud)|isempty(x), return; end;
wolffd@0 957 % determine which (if any) need Start and/or Stop
wolffd@0 958 needStart = all(isnan(ud(:,1:3)'))';
wolffd@0 959 needStop = all(isnan(ud(:,4:6)'))';
wolffd@0 960 mask = any(needStart|needStop);
wolffd@0 961 if ~any(mask), return; end;
wolffd@0 962 ud(~mask,:)=[]; ax(:,~mask)=[];
wolffd@0 963 x(:,~mask)=[]; y(:,~mask)=[]; z(:,~mask)=[];
wolffd@0 964 % make them invisible for the time being
wolffd@0 965 set(H,'Visible','off');
wolffd@0 966 % save the current axes and limits modes; set to manual for the time being
wolffd@0 967 oldAx = gca;
wolffd@0 968 limModes=get(ax(:),{'XLimMode','YLimMode','ZLimMode'});
wolffd@0 969 set(ax(:),{'XLimMode','YLimMode','ZLimMode'},{'manual','manual','manual'});
wolffd@0 970 % loop over each arrow that requires attention
wolffd@0 971 jj = find(mask);
wolffd@0 972 for ii=1:length(jj),
wolffd@0 973 h = H(jj(ii));
wolffd@0 974 axes(ax(ii));
wolffd@0 975 % figure out correct call
wolffd@0 976 if needStart(ii), prop='Start'; else, prop='Stop'; end;
wolffd@0 977 [wasInterrupted,errstr] = arrow_click(needStart(ii)&needStop(ii),h,prop,ax(ii));
wolffd@0 978 % handle errors and control-C
wolffd@0 979 if wasInterrupted,
wolffd@0 980 delete(H(jj(ii:end)));
wolffd@0 981 H(jj(ii:end))=[];
wolffd@0 982 oldaxlims(jj(ii:end),:)=[];
wolffd@0 983 break;
wolffd@0 984 end;
wolffd@0 985 end;
wolffd@0 986 % restore the axes and limit modes
wolffd@0 987 axes(oldAx);
wolffd@0 988 set(ax(:),{'XLimMode','YLimMode','ZLimMode'},limModes);
wolffd@0 989
wolffd@0 990 function [wasInterrupted,errstr] = arrow_click(lockStart,H,prop,ax)
wolffd@0 991 % handle the clicks for one arrow
wolffd@0 992 fig = get(ax,'Parent');
wolffd@0 993 % save some things
wolffd@0 994 oldFigProps = {'Pointer','WindowButtonMotionFcn','WindowButtonUpFcn'};
wolffd@0 995 oldFigValue = get(fig,oldFigProps);
wolffd@0 996 oldArrowProps = {'EraseMode'};
wolffd@0 997 oldArrowValue = get(H,oldArrowProps);
wolffd@0 998 set(H,'EraseMode','background'); %because 'xor' makes shaft invisible unless Width>1
wolffd@0 999 global ARROW_CLICK_H ARROW_CLICK_PROP ARROW_CLICK_AX ARROW_CLICK_USE_Z
wolffd@0 1000 ARROW_CLICK_H=H; ARROW_CLICK_PROP=prop; ARROW_CLICK_AX=ax;
wolffd@0 1001 ARROW_CLICK_USE_Z=~arrow_is2DXY(ax)|~arrow_planarkids(ax);
wolffd@0 1002 set(fig,'Pointer','crosshair');
wolffd@0 1003 % set up the WindowButtonMotion so we can see the arrow while moving around
wolffd@0 1004 set(fig,'WindowButtonUpFcn','set(gcf,''WindowButtonUpFcn'','''')', ...
wolffd@0 1005 'WindowButtonMotionFcn','');
wolffd@0 1006 if ~lockStart,
wolffd@0 1007 set(H,'Visible','on');
wolffd@0 1008 set(fig,'WindowButtonMotionFcn',[mfilename '(''callback'',''motion'');']);
wolffd@0 1009 end;
wolffd@0 1010 % wait for the button to be pressed
wolffd@0 1011 [wasKeyPress,wasInterrupted,errstr] = arrow_wfbdown(fig);
wolffd@0 1012 % if we wanted to click-drag, set the Start point
wolffd@0 1013 if lockStart & ~wasInterrupted,
wolffd@0 1014 pt = arrow_point(ARROW_CLICK_AX,ARROW_CLICK_USE_Z);
wolffd@0 1015 feval(mfilename,H,'Start',pt,'Stop',pt);
wolffd@0 1016 set(H,'Visible','on');
wolffd@0 1017 ARROW_CLICK_PROP='Stop';
wolffd@0 1018 set(fig,'WindowButtonMotionFcn',[mfilename '(''callback'',''motion'');']);
wolffd@0 1019 % wait for the mouse button to be released
wolffd@0 1020 eval('waitfor(fig,''WindowButtonUpFcn'','''');','wasInterrupted=1;');
wolffd@0 1021 if wasInterrupted, errstr=lasterr; end;
wolffd@0 1022 end;
wolffd@0 1023 if ~wasInterrupted, feval(mfilename,'callback','motion'); end;
wolffd@0 1024 % restore some things
wolffd@0 1025 set(gcf,oldFigProps,oldFigValue);
wolffd@0 1026 set(H,oldArrowProps,oldArrowValue);
wolffd@0 1027
wolffd@0 1028 function arrow_callback(varargin)
wolffd@0 1029 % handle redrawing callbacks
wolffd@0 1030 if nargin==0, return; end;
wolffd@0 1031 str = varargin{1};
wolffd@0 1032 if ~isstr(str), error([upper(mfilename) ' got an invalid Callback command.']); end;
wolffd@0 1033 s = lower(str);
wolffd@0 1034 if strcmp(s,'motion'),
wolffd@0 1035 % motion callback
wolffd@0 1036 global ARROW_CLICK_H ARROW_CLICK_PROP ARROW_CLICK_AX ARROW_CLICK_USE_Z
wolffd@0 1037 feval(mfilename,ARROW_CLICK_H,ARROW_CLICK_PROP,arrow_point(ARROW_CLICK_AX,ARROW_CLICK_USE_Z));
wolffd@0 1038 drawnow;
wolffd@0 1039 else,
wolffd@0 1040 error([upper(mfilename) ' does not recognize ''' str(:).' ''' as a valid Callback option.']);
wolffd@0 1041 end;
wolffd@0 1042
wolffd@0 1043 function out = arrow_point(ax,use_z)
wolffd@0 1044 % return the point on the given axes
wolffd@0 1045 if nargin==0, ax=gca; end;
wolffd@0 1046 if nargin<2, use_z=~arrow_is2DXY(ax)|~arrow_planarkids(ax); end;
wolffd@0 1047 out = get(ax,'CurrentPoint');
wolffd@0 1048 out = out(1,:);
wolffd@0 1049 if ~use_z, out=out(1:2); end;
wolffd@0 1050
wolffd@0 1051 function [wasKeyPress,wasInterrupted,errstr] = arrow_wfbdown(fig)
wolffd@0 1052 % wait for button down ignoring object ButtonDownFcn's
wolffd@0 1053 if nargin==0, fig=gcf; end;
wolffd@0 1054 errstr = '';
wolffd@0 1055 % save ButtonDownFcn values
wolffd@0 1056 objs = findobj(fig);
wolffd@0 1057 buttonDownFcns = get(objs,'ButtonDownFcn');
wolffd@0 1058 mask=~strcmp(buttonDownFcns,''); objs=objs(mask); buttonDownFcns=buttonDownFcns(mask);
wolffd@0 1059 set(objs,'ButtonDownFcn','');
wolffd@0 1060 % save other figure values
wolffd@0 1061 figProps = {'KeyPressFcn','WindowButtonDownFcn'};
wolffd@0 1062 figValue = get(fig,figProps);
wolffd@0 1063 % do the real work
wolffd@0 1064 set(fig,'KeyPressFcn','set(gcf,''KeyPressFcn'','''',''WindowButtonDownFcn'','''');', ...
wolffd@0 1065 'WindowButtonDownFcn','set(gcf,''WindowButtonDownFcn'','''')');
wolffd@0 1066 lasterr('');
wolffd@0 1067 wasInterrupted=0; eval('waitfor(fig,''WindowButtonDownFcn'','''');','wasInterrupted=1;');
wolffd@0 1068 wasKeyPress = ~wasInterrupted & strcmp(get(fig,'KeyPressFcn'),'');
wolffd@0 1069 if wasInterrupted, errstr=lasterr; end;
wolffd@0 1070 % restore ButtonDownFcn and other figure values
wolffd@0 1071 set(objs,'ButtonDownFcn',buttonDownFcns);
wolffd@0 1072 set(fig,figProps,figValue);
wolffd@0 1073
wolffd@0 1074
wolffd@0 1075
wolffd@0 1076 function [out,is2D] = arrow_is2DXY(ax)
wolffd@0 1077 % check if axes are 2-D X-Y plots
wolffd@0 1078 % may not work for modified camera angles, etc.
wolffd@0 1079 out = zeros(size(ax)); % 2-D X-Y plots
wolffd@0 1080 is2D = out; % any 2-D plots
wolffd@0 1081 views = get(ax(:),{'View'});
wolffd@0 1082 views = cat(1,views{:});
wolffd@0 1083 out(:) = abs(views(:,2))==90;
wolffd@0 1084 is2D(:) = out(:) | all(rem(views',90)==0)';
wolffd@0 1085
wolffd@0 1086 function out = arrow_planarkids(ax)
wolffd@0 1087 % check if axes descendents all have empty ZData (lines,patches,surfaces)
wolffd@0 1088 out = logical(ones(size(ax)));
wolffd@0 1089 allkids = get(ax(:),{'Children'});
wolffd@0 1090 for k=1:length(allkids),
wolffd@0 1091 kids = get([findobj(allkids{k},'flat','Type','line')
wolffd@0 1092 findobj(allkids{k},'flat','Type','patch')
wolffd@0 1093 findobj(allkids{k},'flat','Type','surface')],{'ZData'});
wolffd@0 1094 for j=1:length(kids),
wolffd@0 1095 if ~isempty(kids{j}), out(k)=logical(0); break; end;
wolffd@0 1096 end;
wolffd@0 1097 end;
wolffd@0 1098
wolffd@0 1099
wolffd@0 1100
wolffd@0 1101 function arrow_fixlimits(axlimits)
wolffd@0 1102 % reset the axis limits as necessary
wolffd@0 1103 if isempty(axlimits), disp([upper(mfilename) ' does not remember any axis limits to reset.']); end;
wolffd@0 1104 for k=1:size(axlimits,1),
wolffd@0 1105 if any(get(axlimits(k,1),'XLim')~=axlimits(k,2:3)), set(axlimits(k,1),'XLim',axlimits(k,2:3)); end;
wolffd@0 1106 if any(get(axlimits(k,1),'YLim')~=axlimits(k,4:5)), set(axlimits(k,1),'YLim',axlimits(k,4:5)); end;
wolffd@0 1107 if any(get(axlimits(k,1),'ZLim')~=axlimits(k,6:7)), set(axlimits(k,1),'ZLim',axlimits(k,6:7)); end;
wolffd@0 1108 end;
wolffd@0 1109
wolffd@0 1110
wolffd@0 1111
wolffd@0 1112 function out = arrow_WarpToFill(notstretched,manualcamera,curax)
wolffd@0 1113 % check if we are in "WarpToFill" mode.
wolffd@0 1114 out = strcmp(get(curax,'WarpToFill'),'on');
wolffd@0 1115 % 'WarpToFill' is undocumented, so may need to replace this by
wolffd@0 1116 % out = ~( any(notstretched) & any(manualcamera) );
wolffd@0 1117
wolffd@0 1118
wolffd@0 1119
wolffd@0 1120 function out = arrow_warnlimits(axlimits,narrows)
wolffd@0 1121 % create a warning message if we've changed the axis limits
wolffd@0 1122 msg = '';
wolffd@0 1123 switch (size(axlimits,1)==1)
wolffd@0 1124 case 1, msg='';
wolffd@0 1125 case 2, msg='on two axes ';
wolffd@0 1126 otherwise, msg='on several axes ';
wolffd@0 1127 end;
wolffd@0 1128 msg = [upper(mfilename) ' changed the axis limits ' msg ...
wolffd@0 1129 'when adding the arrow'];
wolffd@0 1130 if (narrows>1), msg=[msg 's']; end;
wolffd@0 1131 out = [msg '.' sprintf('\n') ' Call ' upper(mfilename) ...
wolffd@0 1132 ' FIXLIMITS to reset them now.'];
wolffd@0 1133
wolffd@0 1134
wolffd@0 1135
wolffd@0 1136 function arrow_copyprops(fm,to)
wolffd@0 1137 % copy line properties to patches
wolffd@0 1138 props = {'EraseMode','LineStyle','LineWidth','Marker','MarkerSize',...
wolffd@0 1139 'MarkerEdgeColor','MarkerFaceColor','ButtonDownFcn', ...
wolffd@0 1140 'Clipping','DeleteFcn','BusyAction','HandleVisibility', ...
wolffd@0 1141 'Selected','SelectionHighlight','Visible'};
wolffd@0 1142 lineprops = {'Color', props{:}};
wolffd@0 1143 patchprops = {'EdgeColor',props{:}};
wolffd@0 1144 patch2props = {'FaceColor',patchprops{:}};
wolffd@0 1145 fmpatch = strcmp(get(fm,'Type'),'patch');
wolffd@0 1146 topatch = strcmp(get(to,'Type'),'patch');
wolffd@0 1147 set(to( fmpatch& topatch),patch2props,get(fm( fmpatch& topatch),patch2props)); %p->p
wolffd@0 1148 set(to(~fmpatch&~topatch),lineprops, get(fm(~fmpatch&~topatch),lineprops )); %l->l
wolffd@0 1149 set(to( fmpatch&~topatch),lineprops, get(fm( fmpatch&~topatch),patchprops )); %p->l
wolffd@0 1150 set(to(~fmpatch& topatch),patchprops, get(fm(~fmpatch& topatch),lineprops) ,'FaceColor','none'); %l->p
wolffd@0 1151
wolffd@0 1152
wolffd@0 1153
wolffd@0 1154 function arrow_props
wolffd@0 1155 % display further help info about ARROW properties
wolffd@0 1156 c = sprintf('\n');
wolffd@0 1157 disp([c ...
wolffd@0 1158 'ARROW Properties: Default values are given in [square brackets], and other' c ...
wolffd@0 1159 ' acceptable equivalent property names are in (parenthesis).' c c ...
wolffd@0 1160 ' Start The starting points. For N arrows, B' c ...
wolffd@0 1161 ' this should be a Nx2 or Nx3 matrix. /|\ ^' c ...
wolffd@0 1162 ' Stop The end points. For N arrows, this /|||\ |' c ...
wolffd@0 1163 ' should be a Nx2 or Nx3 matrix. //|||\\ L|' c ...
wolffd@0 1164 ' Length Length of the arrowhead (in pixels on ///|||\\\ e|' c ...
wolffd@0 1165 ' screen, points on a page). [16] (Len) ////|||\\\\ n|' c ...
wolffd@0 1166 ' BaseAngle Angle (degrees) of the base angle /////|D|\\\\\ g|' c ...
wolffd@0 1167 ' ADE. For a simple stick arrow, use //// ||| \\\\ t|' c ...
wolffd@0 1168 ' BaseAngle=TipAngle. [90] (Base) /// ||| \\\ h|' c ...
wolffd@0 1169 ' TipAngle Angle (degrees) of tip angle ABC. //<----->|| \\ |' c ...
wolffd@0 1170 ' [16] (Tip) / base ||| \ V' c ...
wolffd@0 1171 ' Width Width of the base in pixels. Not E angle ||<-------->C' c ...
wolffd@0 1172 ' the ''LineWidth'' prop. [0] (Wid) |||tipangle' c ...
wolffd@0 1173 ' Page If provided, non-empty, and not NaN, |||' c ...
wolffd@0 1174 ' this causes ARROW to use hardcopy |||' c ...
wolffd@0 1175 ' rather than onscreen proportions. A' c ...
wolffd@0 1176 ' This is important if screen aspect --> <-- width' c ...
wolffd@0 1177 ' ratio and hardcopy aspect ratio are ----CrossDir---->' c ...
wolffd@0 1178 ' vastly different. []' c...
wolffd@0 1179 ' CrossDir A vector giving the direction towards which the fletches' c ...
wolffd@0 1180 ' on the arrow should go. [computed such that it is perpen-' c ...
wolffd@0 1181 ' dicular to both the arrow direction and the view direction' c ...
wolffd@0 1182 ' (i.e., as if it was pasted on a normal 2-D graph)] (Note' c ...
wolffd@0 1183 ' that CrossDir is a vector. Also note that if an axis is' c ...
wolffd@0 1184 ' plotted on a log scale, then the corresponding component' c ...
wolffd@0 1185 ' of CrossDir must also be set appropriately, i.e., to 1 for' c ...
wolffd@0 1186 ' no change in that direction, >1 for a positive change, >0' c ...
wolffd@0 1187 ' and <1 for negative change.)' c ...
wolffd@0 1188 ' NormalDir A vector normal to the fletch direction (CrossDir is then' c ...
wolffd@0 1189 ' computed by the vector cross product [Line]x[NormalDir]). []' c ...
wolffd@0 1190 ' (Note that NormalDir is a vector. Unlike CrossDir,' c ...
wolffd@0 1191 ' NormalDir is used as is regardless of log-scaled axes.)' c ...
wolffd@0 1192 ' Ends Set which end has an arrowhead. Valid values are ''none'',' c ...
wolffd@0 1193 ' ''stop'', ''start'', and ''both''. [''stop''] (End)' c...
wolffd@0 1194 ' ObjectHandles Vector of handles to previously-created arrows to be' c ...
wolffd@0 1195 ' updated or line objects to be converted to arrows.' c ...
wolffd@0 1196 ' [] (Object,Handle)' c ]);
wolffd@0 1197
wolffd@0 1198
wolffd@0 1199
wolffd@0 1200 function out = arrow_demo
wolffd@0 1201 % demo
wolffd@0 1202 % create the data
wolffd@0 1203 [x,y,z] = peaks;
wolffd@0 1204 [ddd,out.iii]=max(z(:));
wolffd@0 1205 out.axlim = [min(x(:)) max(x(:)) min(y(:)) max(y(:)) min(z(:)) max(z(:))];
wolffd@0 1206
wolffd@0 1207 % modify it by inserting some NaN's
wolffd@0 1208 [m,n] = size(z);
wolffd@0 1209 m = floor(m/2);
wolffd@0 1210 n = floor(n/2);
wolffd@0 1211 z(1:m,1:n) = NaN*ones(m,n);
wolffd@0 1212
wolffd@0 1213 % graph it
wolffd@0 1214 clf('reset');
wolffd@0 1215 out.hs=surf(x,y,z);
wolffd@0 1216 out.x=x; out.y=y; out.z=z;
wolffd@0 1217 xlabel('x'); ylabel('y');
wolffd@0 1218
wolffd@0 1219 function h = arrow_demo3(in)
wolffd@0 1220 % set the view
wolffd@0 1221 axlim = in.axlim;
wolffd@0 1222 axis(axlim);
wolffd@0 1223 zlabel('z');
wolffd@0 1224 %set(in.hs,'FaceColor','interp');
wolffd@0 1225 view(viewmtx(-37.5,30,20));
wolffd@0 1226 title(['Demo of the capabilities of the ARROW function in 3-D']);
wolffd@0 1227
wolffd@0 1228 % Normal blue arrow
wolffd@0 1229 h1 = feval(mfilename,[axlim(1) axlim(4) 4],[-.8 1.2 4], ...
wolffd@0 1230 'EdgeColor','b','FaceColor','b');
wolffd@0 1231
wolffd@0 1232 % Normal white arrow, clipped by the surface
wolffd@0 1233 h2 = feval(mfilename,axlim([1 4 6]),[0 2 4]);
wolffd@0 1234 t=text(-2.4,2.7,7.7,'arrow clipped by surf');
wolffd@0 1235
wolffd@0 1236 % Baseangle<90
wolffd@0 1237 h3 = feval(mfilename,[3 .125 3.5],[1.375 0.125 3.5],30,50);
wolffd@0 1238 t2=text(3.1,.125,3.5,'local maximum');
wolffd@0 1239
wolffd@0 1240 % Baseangle<90, fill and edge colors different
wolffd@0 1241 h4 = feval(mfilename,axlim(1:2:5)*.5,[0 0 0],36,60,25, ...
wolffd@0 1242 'EdgeColor','b','FaceColor','c');
wolffd@0 1243 t3=text(axlim(1)*.5,axlim(3)*.5,axlim(5)*.5-.75,'origin');
wolffd@0 1244 set(t3,'HorizontalAlignment','center');
wolffd@0 1245
wolffd@0 1246 % Baseangle>90, black fill
wolffd@0 1247 h5 = feval(mfilename,[-2.9 2.9 3],[-1.3 .4 3.2],30,120,[],6, ...
wolffd@0 1248 'EdgeColor','r','FaceColor','k','LineWidth',2);
wolffd@0 1249
wolffd@0 1250 % Baseangle>90, no fill
wolffd@0 1251 h6 = feval(mfilename,[-2.9 2.9 1.3],[-1.3 .4 1.5],30,120,[],6, ...
wolffd@0 1252 'EdgeColor','r','FaceColor','none','LineWidth',2);
wolffd@0 1253
wolffd@0 1254 % Stick arrow
wolffd@0 1255 h7 = feval(mfilename,[-1.6 -1.65 -6.5],[0 -1.65 -6.5],[],16,16);
wolffd@0 1256 t4=text(-1.5,-1.65,-7.25,'global mininum');
wolffd@0 1257 set(t4,'HorizontalAlignment','center');
wolffd@0 1258
wolffd@0 1259 % Normal, black fill
wolffd@0 1260 h8 = feval(mfilename,[-1.4 0 -7.2],[-1.4 0 -3],'FaceColor','k');
wolffd@0 1261 t5=text(-1.5,0,-7.75,'local minimum');
wolffd@0 1262 set(t5,'HorizontalAlignment','center');
wolffd@0 1263
wolffd@0 1264 % Gray fill, crossdir specified, 'LineStyle' --
wolffd@0 1265 h9 = feval(mfilename,[-3 2.2 -6],[-3 2.2 -.05],36,[],27,6,[],[0 -1 0], ...
wolffd@0 1266 'EdgeColor','k','FaceColor',.75*[1 1 1],'LineStyle','--');
wolffd@0 1267
wolffd@0 1268 % a series of normal arrows, linearly spaced, crossdir specified
wolffd@0 1269 h10y=(0:4)'/3;
wolffd@0 1270 h10 = feval(mfilename,[-3*ones(size(h10y)) h10y -6.5*ones(size(h10y))], ...
wolffd@0 1271 [-3*ones(size(h10y)) h10y -.05*ones(size(h10y))], ...
wolffd@0 1272 12,[],[],[],[],[0 -1 0]);
wolffd@0 1273
wolffd@0 1274 % a series of normal arrows, linearly spaced
wolffd@0 1275 h11x=(1:.33:2.8)';
wolffd@0 1276 h11 = feval(mfilename,[h11x -3*ones(size(h11x)) 6.5*ones(size(h11x))], ...
wolffd@0 1277 [h11x -3*ones(size(h11x)) -.05*ones(size(h11x))]);
wolffd@0 1278
wolffd@0 1279 % series of magenta arrows, radially oriented, crossdir specified
wolffd@0 1280 h12x=2; h12y=-3; h12z=axlim(5)/2; h12xr=1; h12zr=h12z; ir=.15;or=.81;
wolffd@0 1281 h12t=(0:11)'/6*pi;
wolffd@0 1282 h12 = feval(mfilename, ...
wolffd@0 1283 [h12x+h12xr*cos(h12t)*ir h12y*ones(size(h12t)) ...
wolffd@0 1284 h12z+h12zr*sin(h12t)*ir],[h12x+h12xr*cos(h12t)*or ...
wolffd@0 1285 h12y*ones(size(h12t)) h12z+h12zr*sin(h12t)*or], ...
wolffd@0 1286 10,[],[],[],[], ...
wolffd@0 1287 [-h12xr*sin(h12t) zeros(size(h12t)) h12zr*cos(h12t)],...
wolffd@0 1288 'FaceColor','none','EdgeColor','m');
wolffd@0 1289
wolffd@0 1290 % series of normal arrows, tangentially oriented, crossdir specified
wolffd@0 1291 or13=.91; h13t=(0:.5:12)'/6*pi;
wolffd@0 1292 locs = [h12x+h12xr*cos(h13t)*or13 h12y*ones(size(h13t)) h12z+h12zr*sin(h13t)*or13];
wolffd@0 1293 h13 = feval(mfilename,locs(1:end-1,:),locs(2:end,:),6);
wolffd@0 1294
wolffd@0 1295 % arrow with no line ==> oriented downwards
wolffd@0 1296 h14 = feval(mfilename,[3 3 .100001],[3 3 .1],30);
wolffd@0 1297 t6=text(3,3,3.6,'no line'); set(t6,'HorizontalAlignment','center');
wolffd@0 1298
wolffd@0 1299 % arrow with arrowheads at both ends
wolffd@0 1300 h15 = feval(mfilename,[-.5 -3 -3],[1 -3 -3],'Ends','both','FaceColor','g', ...
wolffd@0 1301 'Length',20,'Width',3,'CrossDir',[0 0 1],'TipAngle',25);
wolffd@0 1302
wolffd@0 1303 h=[h1;h2;h3;h4;h5;h6;h7;h8;h9;h10;h11;h12;h13;h14;h15];
wolffd@0 1304
wolffd@0 1305 function h = arrow_demo2(in)
wolffd@0 1306 axlim = in.axlim;
wolffd@0 1307 dolog = 1;
wolffd@0 1308 if (dolog), set(in.hs,'YData',10.^get(in.hs,'YData')); end;
wolffd@0 1309 shading('interp');
wolffd@0 1310 view(2);
wolffd@0 1311 title(['Demo of the capabilities of the ARROW function in 2-D']);
wolffd@0 1312 hold on; [C,H]=contour(in.x,in.y,in.z,20,'-'); hold off;
wolffd@0 1313 for k=H',
wolffd@0 1314 set(k,'ZData',(axlim(6)+1)*ones(size(get(k,'XData'))),'Color','k');
wolffd@0 1315 if (dolog), set(k,'YData',10.^get(k,'YData')); end;
wolffd@0 1316 end;
wolffd@0 1317 if (dolog), axis([axlim(1:2) 10.^axlim(3:4)]); set(gca,'YScale','log');
wolffd@0 1318 else, axis(axlim(1:4)); end;
wolffd@0 1319
wolffd@0 1320 % Normal blue arrow
wolffd@0 1321 start = [axlim(1) axlim(4) axlim(6)+2];
wolffd@0 1322 stop = [in.x(in.iii) in.y(in.iii) axlim(6)+2];
wolffd@0 1323 if (dolog), start(:,2)=10.^start(:,2); stop(:,2)=10.^stop(:,2); end;
wolffd@0 1324 h1 = feval(mfilename,start,stop,'EdgeColor','b','FaceColor','b');
wolffd@0 1325
wolffd@0 1326 % three arrows with varying fill, width, and baseangle
wolffd@0 1327 start = [-3 -3 10; -3 -1.5 10; -1.5 -3 10];
wolffd@0 1328 stop = [-.03 -.03 10; -.03 -1.5 10; -1.5 -.03 10];
wolffd@0 1329 if (dolog), start(:,2)=10.^start(:,2); stop(:,2)=10.^stop(:,2); end;
wolffd@0 1330 h2 = feval(mfilename,start,stop,24,[90;60;120],[],[0;0;4],'Ends',str2mat('both','stop','stop'));
wolffd@0 1331 set(h2(2),'EdgeColor',[0 .35 0],'FaceColor',[0 .85 .85]);
wolffd@0 1332 set(h2(3),'EdgeColor','r','FaceColor',[1 .5 1]);
wolffd@0 1333 h=[h1;h2];