1.随机采样=一个百分点的随机抽样
clc; clear; close all; % clear everything
% Import point cloud
pc = pointCloud('Lion.xyz');
% Plot all points
pc.plot; % points are colored by z coordinate
title('All Points', 'Color', 'w'); view(0,0); snapnow;
% Select randomly 5 percent of all points
pc.select('RandomSampling', 5);
% Plot only selected points
close; pc.plot;
title('After selection strategy ''RandomSampling''', 'Color', 'w'); view(0,0);
2.间隔采样=根据X中点的顺序选择每n个点
clc; clear; close all; % clear everything
% Import point cloud
pc = pointCloud('Lion.xyz');
% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;
% Select each 50-th point
pc.select('IntervalSampling', 50);
% Plot only selected points
close; pc.plot;
title('After selection strategy ''IntervalSampling''', 'Color', 'w'); view(0,0);
3. 均匀采样=对空间中的点进行均匀采样
clc; clear; close all; % clear everything
% Import point cloud
pc = pointCloud('Lion.xyz');
% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;
% Select points using a voxelSize of 3
pc.select('UniformSampling', 3);
% Plot only selected points
close; pc.plot;
title('After selection strategy ''UniformSampling''', 'Color', 'w'); view(0,0);
4.最大杠杆抽样=根据他们的“杠杆”选择点
clc; clear; close all; % clear everything
% Import point cloud
pc = pointCloud('Lion.xyz');
% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;
% First, let's select a subset of points with the UniformSampling strategy
pc.select('UniformSampling', 2);
% Calculate the normals of the selected points with a searchRadius of 1
pc.normals(1);
% Now, select 25 percent of the points with the MaxLeverageSampling strategy
pc.select('MaxLeverageSampling', 25);
% Plot only selected points
close; pc.plot('MarkerSize', 5);
title('After selection strategy ''MaxLeverageSampling''', 'Color', 'w'); view(0,0);
5.正态抽样=基于法向量的点选择
clc; clear; close all; % clear everything
% Import point cloud
pc = pointCloud('Lion.xyz');
% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;
% First, let's select a subset of points with the UniformSampling strategy
pc.select('UniformSampling', 2);
% Calculate the normals of the selected points with a search radius of 1
pc.normals(1);
% Now, select 25 percent of the points with the NormalSampling strategy
pc.select('NormalSampling', 25);
% Plot only selected points
close; pc.plot('MarkerSize', 5);
title('After selection strategy ''NormalSampling''', 'Color', 'w'); view(0,0);
6.属性=基于属性的点选择
The attribute has to be a field of the structure obj.A, e.g. obj.A.roughness.
clc; clear; close all; % clear everything
% Import point cloud WITH attributes (nx, ny, nz are the components of the normal vector)
pc = pointCloud('Lion.xyz', 'Attributes', {'nx' 'ny' 'nz' 'roughness'});
Note: the imported attributes are saved now as fields in the structure pc.A, e.g. the roughness in saved in pc.A.roughness.
% Plot all points
pc.plot('Color', 'A.roughness', 'CAxisLim', [0 1]); % colored by roughness; range of color bar from 0 to 1
title('All Points', 'Color', 'w'); view(0,0); snapnow;
% Select points with roughness in the specified range; in doing so, only the smooth parts of the point cloud are selected
roughnessRange = [0.01 0.3];
pc.select('Attribute', 'roughness', roughnessRange);
% Plot only selected points
close; pc.plot('Color', 'A.roughness', 'CAxisLim', [0 1]);
title('After selection strategy ''Attribute''', 'Color', 'w'); view(0,0);
7.限制=选择窗口内点的选择
clc; clear; close all; % clear everything
% Import point cloud
pc = pointCloud('Lion.xyz');
% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;
% Selection of the lions head
limitsMinMax = [-Inf -10
-30 20
-10 Inf];
pc.select('Limits', limitsMinMax);
% Plot only selected points
close; pc.plot;
title('After selection strategy ''Limits''', 'Color', 'w'); view(0,0);
8.InPolygon =选择二维多边形区域内的点
clc; clear; close all; % clear everything
% Import point cloud
pc = pointCloud('Lion.xyz');
% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;
% Selection of the lions tail within the specified polygon
polygon = [45 4
45 -7
56 -7
71 -2
71 4
63 6];
pc.select('InPolygon', polygon);
% Plot only selected points
close; pc.plot;
title('After selection strategy ''InPolygon''', 'Color', 'w'); view(0,0);
9.InVoxelHull =选择指定体素hull内部的点
clc; clear; close all; % clear everything
% Import the two point clouds
pcScan1 = pointCloud('LionScan1.xyz');
pcScan2 = pointCloud('LionScan2.xyz');
% Plot them in different colors
pcScan1.plot('Color', 'm'); % magenta
pcScan2.plot('Color', 'y'); % yellow
title('Both point clouds', 'Color', 'w'); view(0,0); snapnow;
% Select points of second point cloud which are inside of the voxel hull of the first point cloud
voxelSize = 2;
pcScan1.getVoxelHull(voxelSize); % get voxel hull of first point cloud
pcScan2.select('InVoxelHull', pcScan1.voxelHull, ...
pcScan1.voxelHullVoxelSize);
% Plot only selected points
close; pcScan2.plot('Color', 'y');
title('Only points of yellow pc which are overlapping with magenta pc', 'Color', 'w'); view(0,0);
10 RangeSearch =选择另一个点云范围内的点
clc; clear; close all; % clear everything
% Import point cloud
pc = pointCloud('Lion.xyz');
% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;
% First select a subset of points with uniform sampling, then search all points within the range of 1 from these points
pc.select('UniformSampling', 5);
points = pc.X(pc.act,:); % save selected points to matrix
pc.select('All'); % reselect all points
searchRadius = 1;
pc.select('RangeSearch', points, searchRadius);
% Plot only selected points
close; pc.plot;
title('After selection strategy ''RangeSearch''', 'Color', 'w'); view(0,0);
11. KnnSearch =为另一个点云的每个点选择K个最近邻
clc; clear; close all; % clear everything
% Import point cloud
pc = pointCloud('Lion.xyz');
% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;
% First select a subset of points with uniform sampling, then search the 500 nearest neighbors of these points
pc.select('UniformSampling', 10);
points = pc.X(pc.act,:); % save selected points to matrix
pc.select('All'); % reselect all points
pc.select('KnnSearch', points, 'K', 500);
% Plot only selected points
close; pc.plot;
title('After selection strategy ''KnnSearch''', 'Color', 'w'); view(0,0);
12.剖面=垂直剖面内点的选择
clc; clear; close all; % clear everything
% Import point cloud
pc = pointCloud('Lion.xyz');
% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;
% Select a crossection
lineStart = [ 100 0];
lineEnd = [-100 0];
lineWidth = 2;
az = pc.select('Profile', lineStart, lineEnd, lineWidth); % az contains the azimuth of cross section (to use with function view, see below)
% Plot only selected points
close; pc.plot;
title('After selection strategy ''Profile''', 'Color', 'w'); view(az,0);