TriangularMesh#

class TriangularMesh(mesh, repair=True)[source]#

Bases: Parametrization

Represent a point cloud as triangular mesh.

Parameters:
meshopen3d.cpu.pybind.geometry.TriangleMesh

Triangular mesh.

Attributes

TriangularMesh.triangles

TriangularMesh.vertices

Methods

TriangularMesh.add_projections(projections, ...)

Add projected points to the mesh by splitting triangles.

TriangularMesh.compute_curvature([...])

TriangularMesh.compute_distance(points[, ...])

Compute distance to mesh by ray-casting.

TriangularMesh.compute_normal(points)

Compute the normal vector at a given point on the surface.

TriangularMesh.compute_vertex_normals()

TriangularMesh.fit(positions, **kwargs)

Fit a parametrization to a point cloud.

TriangularMesh.from_file(file_path)

TriangularMesh.geodesic_distance(target_vertices)

Compute geodesic distance from target vertices to their k-nearest source vertices on the mesh.

TriangularMesh.points_per_sampling(...[, ...])

Computes the approximate number of random samples required to achieve a given spatial sampling_density.

TriangularMesh.sample(n_samples[, ...])

Samples points from the Triangular mesh.

TriangularMesh.subset(idx)

TriangularMesh.to_file(file_path)

add_projections(projections, triangle_indices, return_indices=False)[source]#

Add projected points to the mesh by splitting triangles.

Parameters:
projectionsnp.ndarray

Projections on the mesh surface to add to the mesh.

triangle_indicesnp.ndarray

Indices of triangles that each point projects onto.

return_indicesbool, optional

Whether to return the index of projections in the new mesh.

Returns:
meshTriangularMesh

New mesh with valid projections added

indicesnp.ndarray,

Array of vertex indices for the added points in the new mesh

compute_distance(points, normals=None, signed=False, return_projection=False, return_indices=False, return_triangles=False, **kwargs)[source]#

Compute distance to mesh by ray-casting.

Parameters:
pointsnp.ndarray

Points to compute distance from or project onto mesh

normalsnp.ndarray, optional

Normal vectors for projection direction. If None, computes shortest distance.

signedbool, optional

Return signed distances (positive outside, negative inside). Defaults to False.

return_projectionbool, optional

Return points projected onto mesh, defaults to False.

return_indicesbool, optional

Return vertex indices closest to projection, defaults to False.

return_trianglesbool, optional

Return triangles indices hit by raycasting.

Returns:
distancesnp.ndarray

Distance to mesh surface for each point.

projectionnp.ndarray, optional

Projection of each point onto mesh surface.

indicesnp.ndarray, optional

Closest vertex to projection.

trianglesnp.ndarray, optional

Triangle indices hit by projection.

compute_normal(points)[source]#

Compute the normal vector at a given point on the surface.

Parameters:
pointsnp.ndarray

Points on the surface with shape n x d

Returns:
np.ndarray

Normal vectors at the given points

classmethod fit(positions, **kwargs)[source]#

Fit a parametrization to a point cloud.

Parameters:
positionsnp.ndarray

Point coordinates with shape (n x 3)

*argsList

Additional arguments

**kwargsDict

Additional keywoard arguments.

Returns:
Parametrization

Parametrization instance.

geodesic_distance(target_vertices, source_vertices=None, k=1, return_indices=False)[source]#

Compute geodesic distance from target vertices to their k-nearest source vertices on the mesh.

Parameters:
target_verticesnp.ndarray

Target vertex indices for which to compute distances.

source_verticesnp.ndarray, optional

Source vertex indices to compute distances from. If None, uses all mesh vertices as sources.

kint, optional

Number of closest source vertices to find for each target vertex. Minimum and default value is 1 (nearest neighbor).

return_indicesbool, optional

Whether to also return an array of closest vertices in terms of geodesic distance. Defaults to False.

Returns:
distances: ndarray

Geodesic distances to k closest sources. Shape is (len(target_vertices), k).

indices: ndarray, optional

Corresponding source vertex indices. Shape is (len(target_vertices), k).

points_per_sampling(sampling_density, normal_offset=None)[source]#

Computes the approximate number of random samples required to achieve a given spatial sampling_density.

Parameters:
sampling_densityfloat

Average distance between points.

normal_offsetfloat, optional

Compute number of samples on offset parametrization, instead of current.

Returns:
int

Number of required random samples.

sample(n_samples, mesh_init_factor=None, normal_offset=0.0, **kwargs)[source]#

Samples points from the Triangular mesh.

Parameters:
n_samplesint

Number of samples to draw

normal_offsetfloat, optional

Offset points by normal_offset times their normal vector.

mesh_init_factorint, optional

Number of times the mesh should be initialized for Poisson sampling. Five appears to be a reasonable number. Higher values typically yield better sampling.

Returns:
np.ndarray

Point coordinates (n, 3).