function [sV] = reduceByLayers(xyz, percent, alpha) % simplify a given structure by capturing and simplifying its surface mesh layer by layer. % xyz: input point set; percent: reduce rate; alpha: thresold of alphaShape. % Author: Guang Song sV = []; % sV: simplified point set while size(xyz, 1) > 100 % 100: lower bound if nargin == 2 shp = alphaShape(xyz); else shp = alphaShape(xyz, alpha); end [facets] = boundaryFacets(shp); % get surface mesh % simplify surface mesh using reducepatch [F, V] = reducepatch(facets, xyz, percent); % collect points from the reduced surface mesh sV = [sV; V]; internalNodes = setdiff(1:size(xyz,1), facets(:)); xyz = xyz(internalNodes,:); % remove surface layer end