Home > matGeom > geom3d > clipPoints3d.m

clipPoints3d

PURPOSE ^

CLIPPOINTS3D Clip a set of points by a box or other 3d shapes.

SYNOPSIS ^

function varargout = clipPoints3d(points, shape, varargin)

DESCRIPTION ^

CLIPPOINTS3D Clip a set of points by a box or other 3d shapes.

   CLIP = clipPoints3d(POINTS, BOX);
   Returns the set of points which are located inside of the box BOX.

   [CLIP, IND] = clipPoints3d(POINTS, BOX);
   Also returns the indices of clipped points.
   
   ... = clipPoints3d(..., 'shape', 'sphere') Specify the shape.
   Default is 'box'. But it is also possible to use 'sphere' or 'plane'.
   
   ... = clipPoints3d(..., 'inside', false) returns the set of  
   points outside the shape instead of inside.

   See also
   points3d, boxes3d, spheres

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = clipPoints3d(points, shape, varargin)
0002 %CLIPPOINTS3D Clip a set of points by a box or other 3d shapes.
0003 %
0004 %   CLIP = clipPoints3d(POINTS, BOX);
0005 %   Returns the set of points which are located inside of the box BOX.
0006 %
0007 %   [CLIP, IND] = clipPoints3d(POINTS, BOX);
0008 %   Also returns the indices of clipped points.
0009 %
0010 %   ... = clipPoints3d(..., 'shape', 'sphere') Specify the shape.
0011 %   Default is 'box'. But it is also possible to use 'sphere' or 'plane'.
0012 %
0013 %   ... = clipPoints3d(..., 'inside', false) returns the set of
0014 %   points outside the shape instead of inside.
0015 %
0016 %   See also
0017 %   points3d, boxes3d, spheres
0018 
0019 % ------
0020 % Author: David Legland, oqilipo
0021 % E-mail: david.legland@inrae.fr
0022 % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a)
0023 % Copyright 2008-2024 INRA - BIA Nantes - MIAJ Jouy-en-Josas
0024 
0025 parser = inputParser;
0026 validStrings = {'box', 'sphere', 'plane'};
0027 addParameter(parser, 'shape', 'box', @(x) any(validatestring(x, validStrings)));
0028 addParameter(parser, 'inside', true, @islogical);
0029 parse(parser,varargin{:});
0030 
0031 switch parser.Results.shape
0032     case 'box'
0033         LI = clipPointsByBox(points, shape);
0034     case 'plane'
0035         LI = clipPointsByPlane(points, shape);
0036     case 'sphere'
0037         LI = clipPointsBySphere(points, shape);
0038 end
0039 
0040 if parser.Results.inside
0041     % keep points inside the shape
0042     ind = find(LI);
0043 else
0044     % keep points outside the shape
0045     ind = find(~LI);
0046 end
0047 points = points(ind, :);
0048 
0049 % process output arguments
0050 varargout{1} = points;
0051 if nargout == 2
0052     varargout{2} = ind;
0053 end
0054 
0055     function LI = clipPointsByBox(points, box)
0056         % get bounding box limits
0057         xmin = box(1);
0058         xmax = box(2);
0059         ymin = box(3);
0060         ymax = box(4);
0061         zmin = box(5);
0062         zmax = box(6);
0063         
0064         % compute indices of points inside visible area
0065         xOk = points(:,1) >= xmin & points(:,1) <= xmax;
0066         yOk = points(:,2) >= ymin & points(:,2) <= ymax;
0067         zOk = points(:,3) >= zmin & points(:,3) <= zmax;
0068         
0069         LI = xOk & yOk & zOk;
0070     end
0071 
0072     function LI = clipPointsByPlane(points, plane)
0073         % points inside and on the surface of the sphere
0074         LI = isBelowPlane(points, plane);
0075     end
0076 
0077     function LI = clipPointsBySphere(points, sphere)
0078         % points inside and on the surface of the sphere
0079         LI = distancePoints3d(points, sphere(1:3)) <= sphere(4);
0080     end
0081 
0082 end
0083

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022