Home > matGeom > geom3d > drawLabels3d.m

drawLabels3d

PURPOSE ^

DRAWLABELS3D Draw text labels at specified 3D positions.

SYNOPSIS ^

function varargout = drawLabels3d(varargin)

DESCRIPTION ^

DRAWLABELS3D Draw text labels at specified 3D positions.
   
   drawLabels3d(X, Y, Z, LBL) draw labels LBL at position X and Y.
   LBL can be either a string array, or a number array. In this case,
   string are created by using sprintf function, with '%.2f' mask.

   drawLabels3d(POS, LBL) draw labels LBL at position specified by POS,
   where POS is a N-by-3 int array.

   drawLabels3d(..., NUMBERS, FORMAT) create labels using sprintf function,
   with the mask given by FORMAT (e. g. '%03d' or '5.3f'), and the
   corresponding values.

   See also
     drawLabels

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = drawLabels3d(varargin)
0002 %DRAWLABELS3D Draw text labels at specified 3D positions.
0003 %
0004 %   drawLabels3d(X, Y, Z, LBL) draw labels LBL at position X and Y.
0005 %   LBL can be either a string array, or a number array. In this case,
0006 %   string are created by using sprintf function, with '%.2f' mask.
0007 %
0008 %   drawLabels3d(POS, LBL) draw labels LBL at position specified by POS,
0009 %   where POS is a N-by-3 int array.
0010 %
0011 %   drawLabels3d(..., NUMBERS, FORMAT) create labels using sprintf function,
0012 %   with the mask given by FORMAT (e. g. '%03d' or '5.3f'), and the
0013 %   corresponding values.
0014 %
0015 %   See also
0016 %     drawLabels
0017 %
0018 
0019 %   ---------
0020 %   author : David Legland
0021 %   INRA - TPV URPOI - BIA IMASTE
0022 %   created the 31/01/2019.
0023 %
0024 
0025 %   HISTORY
0026 %   2019-01-31 write 3D version from drawLabels
0027 
0028 
0029 %% Parse input arguments
0030 
0031 % check if enough inputs are given
0032 if isempty(varargin)
0033     error('wrong number of arguments in drawLabels3d');
0034 end
0035 
0036 % extract handle of axis to draw on
0037 if isAxisHandle(varargin{1})
0038     axH = varargin{1};
0039     varargin(1) = [];
0040 else
0041     axH = gca;
0042 end
0043 
0044 % process input parameters
0045 var = varargin{1};
0046 if size(var, 2) == 1
0047     % coordinates given as separate arguments
0048     if length(varargin) < 4
0049         error('wrong number of arguments in drawLabels');
0050     end
0051     px  = var;
0052     py  = varargin{2};
0053     pz  = varargin{3};
0054     lbl = varargin{4};
0055     varargin(1:4) = [];
0056 else
0057     % parameters given as a packed array
0058     if length(varargin) < 2
0059         error('wrong number of arguments in drawLabels');
0060     end
0061     if size(var, 2) < 3
0062         error('Requires coordinates array to have at least three columns');
0063     end
0064     px  = var(:,1);
0065     py  = var(:,2);
0066     pz  = var(:,3);
0067     lbl = varargin{2};
0068     varargin(1:2) = [];
0069 end
0070 
0071 % parse format for displaying numeric values
0072 format = '%.2f';
0073 if ~isempty(varargin)
0074     if varargin{1}(1) == '%'
0075         format = varargin{1};
0076         varargin(1)=[];
0077     end
0078 end
0079 if size(format, 1) == 1 && size(px, 1) > 1
0080     format = repmat(format, size(px, 1), 1);
0081 end
0082 
0083 
0084 %% compute the strings that have to be displayed
0085 labels = cell(length(px), 1);
0086 if isnumeric(lbl)
0087     for i = 1:length(px)
0088         labels{i} = sprintf(format(i,:), lbl(i));
0089     end
0090 elseif ischar(lbl)
0091     for i = 1:length(px)
0092         labels{i} = lbl(i,:);
0093     end
0094 elseif iscell(lbl)
0095     labels = lbl;
0096 end
0097 labels = char(labels);
0098 
0099 
0100 %% display the text
0101 h = text(axH, px, py, pz, labels, varargin{:});
0102 
0103 
0104 %% format output
0105 if nargout > 0
0106     varargout = {h};
0107 end
0108

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019