0001 function varargout = clipPoints3d(points, shape, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 parser = inputParser;
0027 validStrings = {'box', 'sphere', 'plane'};
0028 addParameter(parser, 'shape', 'box', @(x) any(validatestring(x, validStrings)));
0029 addParameter(parser, 'inside', true, @islogical);
0030 parse(parser,varargin{:});
0031
0032 switch parser.Results.shape
0033 case 'box'
0034 LI = clipPointsByBox(points, shape);
0035 case 'plane'
0036 LI = clipPointsByPlane(points, shape);
0037 case 'sphere'
0038 LI = clipPointsBySphere(points, shape);
0039 end
0040
0041 if parser.Results.inside
0042
0043 ind = find(LI);
0044 else
0045
0046 ind = find(~LI);
0047 end
0048 points = points(ind, :);
0049
0050
0051 varargout{1} = points;
0052 if nargout == 2
0053 varargout{2} = ind;
0054 end
0055
0056 function LI = clipPointsByBox(points, box)
0057
0058 xmin = box(1);
0059 xmax = box(2);
0060 ymin = box(3);
0061 ymax = box(4);
0062 zmin = box(5);
0063 zmax = box(6);
0064
0065
0066 xOk = points(:,1) >= xmin & points(:,1) <= xmax;
0067 yOk = points(:,2) >= ymin & points(:,2) <= ymax;
0068 zOk = points(:,3) >= zmin & points(:,3) <= zmax;
0069
0070 LI = xOk & yOk & zOk;
0071 end
0072
0073 function LI = clipPointsByPlane(points, plane)
0074
0075 LI = isBelowPlane(points, plane);
0076 end
0077
0078 function LI = clipPointsBySphere(points, sphere)
0079
0080 LI = distancePoints3d(points, sphere(1:3)) <= sphere(4);
0081 end
0082
0083 end
0084