mrdja.sampling.sampling_pcd_points
- mrdja.sampling.sampling_pcd_points(pcd: PointCloud, num_points: int = 1, seed: int | None = None)[source]
Sample points from a point cloud.
- Parameters:
pcd (o3d.geometry.PointCloud) – The point cloud to sample from.
num_points (int) – The number of points to sample. Default is 1.
seed (int) – The seed value for the random number generator. Default is None.
- Returns:
The sampled points.
- Return type:
np.ndarray
Examples
>>> import open3d as o3d >>> import mrdja.sampling as sampling >>> # Create a point cloud from random points sampled from a 3D parallelogram >>> n_samples = 1000 >>> normal1 = (1, 1, 0) >>> normal2 = (-2, 1, 1) >>> normal3 = (1, -1, 3) >>> center = (1, 2, 0) >>> length1 = 5 >>> length2 = 4 >>> length3 = 3 >>> samples = sampling.sampling_parallelogram_3d(n_samples=n_samples, normal1=normal1, normal2=normal2, normal3=normal3, center=center, length1=length1, length2=length2, length3=length3, seed=42) >>> samples[:5] [array([ 4.82213591, 1.47208906, -3.92469311]), array([-1.74561756, 1.03184009, 2.53618024]), array([ 6.03115264, 2.54288771, -2.35494829]), array([ 0.91594816, -1.49252787, -1.07725051]), array([ 1.49163196, -2.02162286, 0.14431054])] >>> pcd = o3d.geometry.PointCloud() >>> pcd.points = o3d.utility.Vector3dVector(samples) >>> # paint the point cloud in blue >>> pcd.paint_uniform_color([0, 0, 1]) >>> # Sample 300 random points from the point cloud >>> sampled_points = sampling.sampling_pcd_points(pcd, 300, seed=42) >>> sampled_points[:5] array([[-3.29369778, 2.38822478, 3.96820711], [-0.15203634, 3.14597455, 3.11019749], [ 2.41599518, -1.37126689, -3.70481201], [ 3.02922805, -2.15456602, -0.98563083], [ 0.75636732, 5.3772318 , -2.63251376]]) >>> # create a point cloud from the sampled points >>> sampled_pcd = o3d.geometry.PointCloud() >>> sampled_pcd.points = o3d.utility.Vector3dVector(sampled_points) >>> # paint the sampled points in red >>> sampled_pcd.paint_uniform_color([1, 0, 0]) >>> # visualize the point clouds >>> o3d.visualization.draw_geometries([pcd, sampled_pcd])
