Home > hiswa > extclabel.m

extclabel

PURPOSE ^

EXTCLABEL *Real* Contour labelling

SYNOPSIS ^

function H=extclabel(CS,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19);

DESCRIPTION ^

 EXTCLABEL *Real* Contour labelling
           EXTCLABEL(CS) draw the contours in contour structure CS
           adding real, rotated, line-broken labels.

           text and line property values are specified by the usual
           property/value pairs, for text properties (beginning 
           with 'Font...' or 'Rotation') or line properties (beginning 
           with 'line...' or 'color'),
           e.g., EXTCLABEL(...,'fontsize',8,'linewidth',3);

           The default rotation is aligned with the contours. Label
           intervals (in 'points') are set using a 'label' property.

           See also EXTCONTOUR

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function H=extclabel(CS,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,...
0002                          arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19);
0003 % EXTCLABEL *Real* Contour labelling
0004 %           EXTCLABEL(CS) draw the contours in contour structure CS
0005 %           adding real, rotated, line-broken labels.
0006 %
0007 %           text and line property values are specified by the usual
0008 %           property/value pairs, for text properties (beginning
0009 %           with 'Font...' or 'Rotation') or line properties (beginning
0010 %           with 'line...' or 'color'),
0011 %           e.g., EXTCLABEL(...,'fontsize',8,'linewidth',3);
0012 %
0013 %           The default rotation is aligned with the contours. Label
0014 %           intervals (in 'points') are set using a 'label' property.
0015 %
0016 %           See also EXTCONTOUR
0017 
0018 
0019 % Author: R. Pawlowicz IOS rich@ios.bc.ca
0020 %         12/12/94
0021 
0022 
0023 lab_int=72*2;  % label interval (points)
0024 
0025 linarg_for_call=[];
0026 textarg_for_call=[];
0027 
0028 ii=2;
0029 while (ii<=nargin),
0030  arg=eval(['arg' int2str(ii)]);
0031  if (lower(arg(1:3))=='lin' | lower(arg(1:3))=='col'),
0032    ii=ii+1;
0033    linarg_for_call=[linarg_for_call ',''' arg ''',arg' int2str(ii) ];
0034  elseif (lower(arg(1:3))=='fon' | lower(arg(1:3))=='rot'),
0035    ii=ii+1;
0036    textarg_for_call=[textarg_for_call ',''' arg ''',arg' int2str(ii) ];
0037  elseif (lower(arg(1:3))=='lab' ),
0038    ii=ii+1;
0039    lab_int=eval(['arg' int2str(ii) ]);
0040  else
0041   error(['Unknown option: ' arg ]);
0042  end;
0043  ii=ii+1;
0044 end;
0045 
0046 % Compute scaling to make sure printed output looks OK. We have to go via
0047 % the figure's 'paperposition', rather than the the absolute units of the
0048 % axes 'position' since those would be absolute only if we kept the 'units'
0049 % property in some absolute units (like 'points') rather than the default
0050 % 'normalized'.
0051 
0052 UN=get(gca,'units');
0053 if (UN(1:3)=='nor'),
0054   UN=get(gcf,'paperunits');
0055   set(gcf,'paperunits','points');
0056   PA=get(gcf,'paperpos');
0057   set(gcf,'paperunits',UN);
0058   PA=PA.*[get(gca,'position')];
0059 else
0060   set(gcf,'units','points');
0061   PA=get(gca,'pos');
0062   set(gca,'units',UN); 
0063 end;  
0064 
0065 % Find beginning of all lines
0066 
0067 lCS=size(CS,2);
0068 
0069 if (ishold),
0070  XL=get(gca,'xlim');
0071  YL=get(gca,'ylim');
0072 else
0073   iL=[];
0074   k=1;
0075   XL=[Inf -Inf];
0076   YL=[Inf -Inf];
0077   while (k<lCS),
0078    x=CS(1,k+[1:CS(2,k)]);
0079    y=CS(2,k+[1:CS(2,k)]);
0080    XL=[ min([XL(1),x]) max([XL(2),x]) ];
0081    YL=[ min([YL(1),y]) max([YL(2),y]) ]; 
0082    iL=[iL k];
0083    k=k+CS(2,k)+1;
0084   end;
0085   plot(XL(1),YL(1));
0086   set(gca,'xlim',XL,'ylim',YL);
0087 end;
0088 
0089 
0090 Aspx=PA(3)/diff(XL);  % To convert data coordinates to paper (we need to do this
0091 Aspy=PA(4)/diff(YL);  % to get the gaps for text the correct size)
0092 
0093 H=[];
0094 
0095 % Set up a dummy text object from which you can get text extent info
0096 eval(['H1=text(XL(1),YL(1),''dummyarg'',''units'',''points'' ' textarg_for_call ');']);
0097 
0098 ii=1;
0099 while (ii<lCS),
0100 
0101   l=CS(2,ii);
0102   x=CS(1,ii+[1:l]);
0103   y=CS(2,ii+[1:l]);
0104   
0105   lvl=CS(1,ii);
0106   lab=num2str(lvl);
0107 
0108   % Get the size of the label
0109   set(H1,'string',lab);
0110   EX=get(H1,'extent');
0111   len_lab=EX(3)/2;
0112   
0113   sx=x*Aspx;
0114   sy=y*Aspy;
0115   d=cumsum([0 sqrt(diff(sx).^2 +diff(sy).^2) ]);
0116   
0117   psn=[max(len_lab,lab_int+lab_int*(rand(1)-.5)):lab_int:d(l)-len_lab];
0118   lp=size(psn,2);
0119   
0120   if (lp>0 & finite(lvl) ),
0121   
0122     Ic=sum( d(ones(1,lp),:)' < psn(ones(1,l),:) );
0123     Il=sum( d(ones(1,lp),:)' < psn(ones(1,l),:)-len_lab );
0124     Ir=sum( d(ones(1,lp),:)' < psn(ones(1,l),:)+len_lab );
0125  
0126     % This is a fix to get around Matlabs sort-of-inconsistency with
0127     % what [1 1 1] indexing means...
0128     if ( ~any(Il~=1) & lp==l ),
0129      d=[d,d(l)];
0130      x=[x,x(l)];
0131      y=[y,y(l)];
0132     end;
0133     
0134     % Endpoints of text in data coordinates
0135     wl=(d(Il+1)-psn+len_lab)./(d(Il+1)-d(Il));
0136     wr=(psn-len_lab-d(Il)  )./(d(Il+1)-d(Il));
0137     xl=x(Il).*wl+x(Il+1).*wr;
0138     yl=y(Il).*wl+y(Il+1).*wr;
0139   
0140     wl=(d(Ir+1)-psn-len_lab)./(d(Ir+1)-d(Ir));
0141     wr=(psn+len_lab-d(Ir)  )./(d(Ir+1)-d(Ir));
0142     xr=x(Ir).*wl+x(Ir+1).*wr;
0143     yr=y(Ir).*wl+y(Ir+1).*wr;
0144    
0145     trot=atan2( (yr-yl)*Aspy, (xr-xl)*Aspx )*180/pi;
0146     backang=abs(trot)>90;
0147     trot(backang)=trot(backang)+180;
0148     
0149     % Text location in data coordinates
0150 
0151     wl=(d(Ic+1)-psn)./(d(Ic+1)-d(Ic));
0152     wr=(psn-d(Ic)  )./(d(Ic+1)-d(Ic));    
0153     xc=x(Ic).*wl+x(Ic+1).*wr;
0154     yc=y(Ic).*wl+y(Ic+1).*wr;
0155 
0156     % Shift label over a little if in a curvy area
0157     shiftfrac=.5;
0158     
0159     xc=xc*(1-shiftfrac)+(xr+xl)/2*shiftfrac;
0160     yc=yc*(1-shiftfrac)+(yr+yl)/2*shiftfrac;
0161     
0162  
0163     % Remove data points under the label...
0164     % First, find endpoint locations as distances along lines
0165   
0166     dr=d(Ir)+sqrt( ((xr-x(Ir))*Aspx).^2 + ((yr-y(Ir))*Aspy).^2 );
0167     dl=d(Il)+sqrt( ((xl-x(Il))*Aspx).^2 + ((yl-y(Il))*Aspy).^2 );
0168   
0169     % Now, remove the data points in those gaps using that
0170     % ole' Matlab magic
0171     
0172     f1=zeros(1,l); f1(Il)=ones(1,lp);
0173     f2=zeros(1,l); f2(Ir)=ones(1,lp);
0174     irem=find(cumsum(f1)-cumsum(f2))+1;
0175     x(irem)=[];
0176     y(irem)=[];
0177     d(irem)=[];
0178     l=l-size(irem,2);
0179     
0180     % Put the points in the correct order...
0181     
0182     xf=[x(1:l),xl,xc+NaN,xr];
0183     yf=[y(1:l),yl,yc,yr];
0184     [df,If]=sort([d(1:l),dl,psn,dr]);
0185   
0186     % ...and draw.
0187     
0188     eval(['H=[H;line(xf(If),yf(If)' linarg_for_call ')];']);
0189 
0190     for jj=1:lp,
0191      eval(['text(xc(jj),yc(jj),lab,''rotation'',trot(jj),' ...
0192         ' ''vertical'',''middle'',''clipping'',''on'',' ...
0193         ' ''horizo'',''center'' ' textarg_for_call ');']);
0194     end;
0195   else
0196     eval(['H=[H;line(x,y' linarg_for_call ')];']);
0197   end;
0198   
0199   ii=ii+1+CS(2,ii);
0200 end;
0201   
0202 % delete dummy string
0203 delete(H1);
0204 
0205

Generated on Wed 30-Nov-2005 15:36:39 by m2html © 2003