1 %% Copyright (c) 2011, INRA
2 %% 2004-2011, David Legland <david.legland@grignon.inra.fr>
3 %% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
5 %% All rights reserved.
6 %% (simplified BSD License)
8 %% Redistribution and use in source and binary forms, with or without
9 %% modification, are permitted provided that the following conditions are met:
11 %% 1. Redistributions of source code must retain the above copyright notice, this
12 %% list of conditions and the following disclaimer.
14 %% 2. Redistributions in binary form must reproduce the above copyright notice,
15 %% this list of conditions and the following disclaimer in the documentation
16 %% and/or other materials provided with the distribution.
18 %% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 %% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 %% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 %% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 %% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 %% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 %% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 %% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 %% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 %% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 %% POSSIBILITY OF SUCH DAMAGE.
30 %% The views and conclusions contained in the software and documentation are
31 %% those of the authors and should not be interpreted as representing official
32 %% policies, either expressed or implied, of copyright holder.
35 %% @deftypefn {Function File} {@var{h} = } drawEdge (@var{x1}, @var{y1}, @var{x2}, @var{y2})
36 %% @deftypefnx {Function File} {@var{h} = } drawEdge ([@var{x1} @var{y1} @var{x2} @var{y2}])
37 %% @deftypefnx {Function File} {@var{h} = } drawEdge ([@var{x1} @var{y1}], [@var{x2} @var{y2}])
38 %% @deftypefnx {Function File} {@var{h} = } drawEdge (@var{x1}, @var{y1}, @var{z1}, @var{x2}, @var{y2}, @var{z2})
39 %% @deftypefnx {Function File} {@var{h} = } drawEdge ([@var{x1} @var{y1} @var{z1} @var{x2} @var{y2} @var{z2}])
40 %% @deftypefnx {Function File} {@var{h} = } drawEdge ([@var{x1} @var{y1} @var{z1}], [@var{x2} @var{y2} @var{z2}])
41 %% @deftypefnx {Function File} {@var{h} = } drawEdge (@dots{}, @var{opt})
42 %% Draw an edge given by 2 points.
44 %% Draw an edge between the points (x1 y1) and (x2 y2). Data can be bundled as an edge.
45 %% The function supports 3D edges.
46 %% Arguments can be single values or array of size [Nx1]. In this case,
47 %% the function draws multiple edges.
48 %% @var{opt}, being a set of pairwise options, can
49 %% specify color, line width and so on. These are passed to function @code{line}.
50 %% The function returns handle(s) to created edges(s).
52 %% @seealso{edges2d, drawCenteredEdge, drawLine, line}
55 function varargout = drawEdge(varargin)
57 % separate edge and optional arguments
58 [edge options] = parseInputArguments(varargin{:});
62 h = drawEdge_2d(edge, options);
64 h = drawEdge_3d(edge, options);
67 % eventually return handle to created edges
74 function h = drawEdge_2d(edge, options)
76 h = -1*ones(size(edge, 1), 1);
83 [edge(i, 1) edge(i, 3)], ...
84 [edge(i, 2) edge(i, 4)], options{:});
89 function h = drawEdge_3d(edge, options)
91 h = -1*ones(size(edge, 1), 1);
98 [edge(i, 1) edge(i, 4)], ...
99 [edge(i, 2) edge(i, 5)], ...
100 [edge(i, 3) edge(i, 6)], options{:});
105 function [edge options] = parseInputArguments(varargin)
107 % default values for parameters
110 % find the number of arguments defining edges
113 if isnumeric(varargin{i})
116 % stop at the first non-numeric value
121 % extract drawing options
122 options = varargin(nbVal+1:end);
124 % ensure drawing options have correct format
125 if length(options)==1
126 options = [{'color'}, options];
129 % extract edges characteristics
131 % all parameters in a single array
135 % parameters are two points, or two arrays of points, of size N*2.
141 % parameters are 4 parameters of the edge : x1 y1 x2 and y2
142 edge = [varargin{1} varargin{2} varargin{3} varargin{4}];
145 % parameters are 6 parameters of the edge : x1 y1 z1 x2 y2 and z2
146 edge = [varargin{1} varargin{2} varargin{3} varargin{4} varargin{5} varargin{6}];
153 %! points = rand(4,4);
154 %! colorstr = 'rgbm';
156 %! drawEdge (points(i,:),'color',colorstr(i),'linewidth',2);
162 %! drawEdge (rand(10,4),'linewidth',2);