www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgtabgradconstraint/private/pConvHullGridFilter.m
function map = pConvHullGridFilter(axisbp, pts) %PCONVHULLGRIDFILTER Filter the grid points using a convex hull % % MAP = PCONVHULLGRIDFILTER(AXISBP, PTS) returns a boolean map which % indicates whether each grid point is inside the boundary of the data. % The grid points are specified by the 1-by-NAXIS cell array of axis % breakpoints, AXISBP. % % For 2-d tables, the boundary is determined using a convex hull. For 1-d % tables, the boundary is determined by taking the range of PTS. % % See also PIDENTITYGRIDFILTER % Copyright 2006 The MathWorks, Inc. % If there are no axis variables then just return empty NAXES = length(axisbp); if NAXES < 1 map = []; return end % If no data is specified, then return an empty map if isempty(pts) map = []; return end % Switch on table type switch NAXES case 1 % Just use range map = i_filter1dTable(axisbp, pts); case 2 % Use convex hull map = i_filter2dTable(axisbp, pts); otherwise error(message('mbc:cgtabgradconstraint:InvalidState1')); end %-------------------------------------------------------------------------- function map = i_filter1dTable(axisbp, pts) %-------------------------------------------------------------------------- % Keep the grid points that are in the range of the data map = (axisbp{1} >= min(pts)) & ... (axisbp{1} <= max(pts)); % Ensure a column vector is returned map = map(:); %-------------------------------------------------------------------------- function map = i_filter2dTable(axisbp, pts) %-------------------------------------------------------------------------- % Generate the coninputfactor object inpNames = {'RowAxis', 'ColAxis'}; mn = cellfun(@min, axisbp); ma = cellfun(@max, axisbp); cif = coninputfactor(inpNames, [], [], mn, ma); % Determine the convex hull con = conconvexhull(cif); con = findBoundaryPoints(con, getBoundaryPointOptions(con), pts); % Evaluate the convex hull on the grid and return the boolean map [xx, yy] = ndgrid(axisbp{:}); chd = constraintDistance(con, [xx(:), yy(:)]); chd = chd < 1e-4; % Add a tolerance so boundary points are included map = reshape(chd, size(xx));