-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from oqilipo/master
Fix of fillPolygon.m
- Loading branch information
Showing
2 changed files
with
37 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,80 +11,58 @@ | |
% fillPolygon(PX, PY); | ||
% Specifies coordinates of the polygon in separate arrays. | ||
% | ||
% | ||
% H = fillPolygon(...); | ||
% Also returns a handle to the created patch | ||
% | ||
% Example | ||
% oRectangle = [0 0;10 0;10 10;0 10]; | ||
% iRectangle = flipud(0.5*oRectangle+1); | ||
% pol = {oRectangle, iRectangle}; | ||
% figure('color','w') | ||
% fillPolygon(pol,'g') | ||
% drawPolygon(pol,'r') | ||
% | ||
% | ||
% See also | ||
% polygons2d, drawCurve, drawPolygon | ||
|
||
% ------ | ||
% Author: David Legland | ||
% Author: David Legland, oqilipo | ||
% E-mail: [email protected] | ||
% Created: 2005-04-07 | ||
% Copyright 2005-2023 INRA - TPV URPOI - BIA IMASTE | ||
|
||
% check input | ||
% Check input | ||
if isempty(varargin) | ||
error('need to specify a polygon'); | ||
end | ||
|
||
% case of a set of polygons stored in a cell array | ||
var = varargin{1}; | ||
if iscell(var) | ||
N = length(var); | ||
h = zeros(N, 1); | ||
for i = 1:N | ||
% check for empty polygons | ||
if ~isempty(var{i}) | ||
h(i) = fillPolygon(var{i}, varargin{2:end}); | ||
end | ||
end | ||
|
||
% setup output values | ||
if nargout > 0 | ||
varargout{1} = h; | ||
end | ||
return; | ||
error('Not enough input arguments.'); | ||
end | ||
|
||
% Extract coordinates of polygon vertices | ||
if size(var, 2) > 1 | ||
% first argument is a polygon array | ||
px = var(:, 1); | ||
py = var(:, 2); | ||
varargin(1) = []; | ||
else | ||
% arguments 1 and 2 correspond to x and y coordinate respectively | ||
if length(varargin) < 2 | ||
error('should specify either a N*2 array, or 2 N*1 vectors'); | ||
% Check if the polygon is given in two separate arrays. | ||
if numel(varargin) > 1 | ||
if isnumeric(varargin{2}) | ||
varargin{2} = [varargin{1}, varargin{2}]; | ||
varargin(1)=[]; | ||
end | ||
|
||
px = varargin{1}; | ||
py = varargin{2}; | ||
varargin(1:2) = []; | ||
end | ||
|
||
% Convert into a polyShape | ||
polyShape = parsePolygon(varargin{1}, 'polyshape'); | ||
varargin(1)=[]; | ||
|
||
% Find position of breaks, and copies first point of each loop at the end | ||
inds = find(isnan(px(:))); | ||
i1 = [inds ; length(px)+1]; | ||
i0 = [1 ; inds+1]; | ||
px(i1, :) = px(i0, :); | ||
py(i1, :) = py(i0, :); | ||
|
||
|
||
% set default line format | ||
% Set default color format if no color is given. | ||
if isempty(varargin) | ||
varargin = {'b'}; | ||
varargin = {'FaceColor', 'b'}; | ||
end | ||
|
||
if ~mod(numel(varargin), 2) == 0 | ||
% Assume only the color was given. | ||
varargin = ['FaceColor', varargin]; | ||
end | ||
|
||
% fill the polygon with desired style | ||
h = fill(px, py, varargin{:}, 'lineStyle', 'none'); | ||
% Fill the polygon with desired style. | ||
h = plot(polyShape, varargin{:}, 'LineStyle', 'none'); | ||
|
||
% output | ||
% Output | ||
if nargout > 0 | ||
varargout{1} = h; | ||
end |