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 % ------
0021 % Author: David Legland, oqilipo
0022 % e-mail: david.legland@inra.fr
0023 % Created: 2008-10-13,    using Matlab 7.4.0.287 (R2007a)
0024 % Copyright 2008 INRA - BIA Nantes - MIAJ Jouy-en-Josas.
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     % keep points inside the shape
0043     ind = find(LI);
0044 else
0045     % keep points outside the shape
0046     ind = find(~LI);
0047 end
0048 points = points(ind, :);
0049 
0050 % process output arguments
0051 varargout{1} = points;
0052 if nargout == 2
0053     varargout{2} = ind;
0054 end
0055 
0056     function LI = clipPointsByBox(points, box)
0057         % get bounding box limits
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         % compute indices of points inside visible area
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         % points inside and on the surface of the sphere
0075         LI = isBelowPlane(points, plane);
0076     end
0077 
0078     function LI = clipPointsBySphere(points, sphere)
0079         % points inside and on the surface of the sphere
0080         LI = distancePoints3d(points, sphere(1:3)) <= sphere(4);
0081     end
0082 
0083 end
0084

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019