Skip to content

Point Sampling

sample_AABB(box, n_pts, mode='uniform', return_point_cloud=False)

Sample a point cloud uniformly at random inside an axis-aligned bounding box. Works by sampling the unit cube and applying an affine transformation.

Parameters:

Name Type Description Default
box AABB

the domain of sampling

required
n_pts int

number of points to sample. If mode is 'grid', the function may return a slightly smaller number of points (nearest perfect n-th root).

required
mode str

sampling mode. 'uniform' or 'grid'. Uniform takes points at random, while 'grid' generates a grid of regularly spaced points.

'uniform'
return_point_cloud bool

whether to compile the points in a PointCloud object or return the raw numpy array. Is ignored if the bounding box has dimension >3. Defaults to False.

False

Raises:

Type Description
Exception

fails if the bounding box is empty.

ValueError

fails if the dimension of the box is > 3 and return_point_cloud is set to True, so that no PointCloud object with dim > 3 is created.

Returns:

Type Description

PointCloud | np.ndarray: a sampled point cloud of n_pts points

sample_ball(center, radius, n_pts, return_point_cloud=False)

Samples points uniformly inside a 3D ball.

Parameters:

Name Type Description Default
center Vec

center of the ball

required
radius float

radius of the ball

required
n_pts int

number of points to sample

required
return_point_cloud bool

whether to compile the points in a PointCloud object or return the raw numpy array. Defaults to False.

False

Returns:

Type Description

PointCloud | np.ndarray: a sampled point cloud of n_pts points

sample_polyline(mesh, n_pts, return_point_cloud=False)

Sample a point cloud uniformly at random from a polyline

Parameters:

Name Type Description Default
mesh PolyLine

the input polyline

required
n_pts int

number of points to sample

required
return_point_cloud bool

whether to compile the points in a PointCloud object or return the raw numpy array. Defaults to False.

False

Returns:

Type Description

PointCloud | np.ndarray: a sampled point cloud of n_pts points

sample_sphere(center, radius, n_pts, return_point_cloud=False)

Samples points uniformly on the surface of a 3D sphere

Parameters:

Name Type Description Default
center Vec

center of the sphere

required
radius float

radius of the spheres

required
n_pts int

number of points to sample

required
return_point_cloud bool

whether to compile the points in a PointCloud object or return the raw numpy array. Defaults to False.

False

Returns:

Type Description

PointCloud | np.ndarray: a sampled point cloud of n_pts points

sample_surface(mesh, n_pts, return_point_cloud=False, return_normals=False)

Sample a point cloud uniformly at random from a surface mesh

Parameters:

Name Type Description Default
mesh SurfaceMesh

input mesh

required
n_pts int

number of points to sample

required
return_point_cloud bool

whether to compile the points in a PointCloud object or return the raw numpy array. Defaults to False.

False
return_normals bool

wether to assign the normal of the faces to sampled points. Only has effect if return_point_cloud is set to True. Defaults to False.

False

Raises:

Type Description
AssertionError

the mesh is not a triangular mesh

Returns:

Type Description

PointCloud | np.ndarray: a sampled point cloud of n_pts points

np.ndarray : the associated normals (if sample_normals was set to True)

sample_surface_barycentric(mesh, n_pts)

Sample a point cloud uniformly at random from a surface mesh, but computes face ids and barycentric coordinates instead of point coordinates.

This function returns two arrays F and B such that: F[i] = f and B[i] = a,b,c means that the i-th point is defined as apA + bpB + c*pC where (pA,pB,pC) are the vertices of face f.

Parameters:

Name Type Description Default
mesh SurfaceMesh

input mesh

required
n_pts int

number of points to sample

required

Raises:

Type Description
AssertionError

the mesh is not a triangular mesh

Returns:

Type Description

np.ndarray: the index of the face in which each point belong

np.ndarray: the associated barycentric coordinates of the vertex