Collision Mesh

class ipctk.CollisionMesh

Bases: pybind11_object

Public Data Attributes:

num_vertices

Get the number of vertices in the collision mesh.

num_codim_vertices

Get the number of codimensional vertices in the collision mesh.

num_codim_edges

Get the number of codimensional edges in the collision mesh.

num_edges

Get the number of edges in the collision mesh.

num_faces

Get the number of faces in the collision mesh.

dim

Get the dimension of the mesh.

ndof

Get the number of degrees of freedom in the collision mesh.

full_num_vertices

Get the number of vertices in the full mesh.

full_ndof

Get the number of degrees of freedom in the full mesh.

rest_positions

Get the vertices of the collision mesh at rest (#V × dim).

codim_vertices

Get the indices of codimensional vertices of the collision mesh (#CV x 1).

codim_edges

Get the indices of codimensional edges of the collision mesh (#CE x 1).

edges

Get the edges of the collision mesh (#E × 2).

faces

Get the faces of the collision mesh (#F × 3).

faces_to_edges

Get the mapping from faces to edges of the collision mesh (#F × 3).

vertex_vertex_adjacencies

Get the vertex-vertex adjacency matrix.

vertex_edge_adjacencies

Get the vertex-edge adjacency matrix.

edge_vertex_adjacencies

Get the edge-vertex adjacency matrix.

vertex_areas

Get the barycentric area of the vertices.

can_collide

A function that takes two vertex IDs and returns true if the vertices (and faces or edges containing the vertices) can collide.

Public Methods:

__init__(*args, **kwargs)

Overloaded function.

build_from_full_mesh(full_rest_positions, edges)

Helper function that automatically builds include_vertex using construct_is_on_surface.

init_adjacencies(self)

Initialize vertex-vertex and edge-vertex adjacencies.

init_area_jacobians(self)

Initialize vertex and edge areas.

vertices(self, full_positions)

Compute the vertex positions from the positions of the full mesh.

displace_vertices(self, full_displacements)

Compute the vertex positions from vertex displacements on the full mesh.

map_displacements(self, full_displacements)

Map vertex displacements on the full mesh to vertex displacements on the collision mesh.

to_full_vertex_id(self, id)

Map a vertex ID to the corresponding vertex ID in the full mesh.

to_full_dof(*args, **kwargs)

Overloaded function.

are_adjacencies_initialized(self)

Determine if the adjacencies have been initialized by calling init_adjacencies().

is_vertex_on_boundary(self, vi)

Is a vertex on the boundary of the collision mesh?

vertex_area(self, vi)

Get the barycentric area of a vertex.

vertex_area_gradient(self, vi)

Get the gradient of the barycentric area of a vertex wrt the rest positions of all points.

edge_area(self, ei)

Get the barycentric area of an edge.

edge_areas(self)

Get the barycentric area of the edges.

edge_area_gradient(self, ei)

Get the gradient of the barycentric area of an edge wrt the rest positions of all points.

are_area_jacobians_initialized(self)

Determine if the area Jacobians have been initialized by calling init_area_jacobians().

construct_is_on_surface(num_vertices, edges)

Construct a vector of bools indicating whether each vertex is on the surface.

construct_faces_to_edges(faces, edges)

Construct a matrix that maps from the faces' edges to rows in the edges matrix.

Inherited from pybind11_object

__annotations__ = {}
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: ipctk.CollisionMesh, rest_positions: numpy.ndarray[numpy.float64[m, n]], edges: numpy.ndarray[numpy.int32[m, n]] = array([], shape=(0, 0), dtype=int32), faces: numpy.ndarray[numpy.int32[m, n]] = array([], shape=(0, 0), dtype=int32), displacement_map: scipy.sparse.csc_matrix[numpy.float64] = <Compressed Sparse Column sparse matrix of dtype ‘float64’ with 0 stored elements and shape (0, 0)>) -> None

    Construct a new Collision Mesh object directly from the collision mesh vertices.

    Parameters:

    rest_positions: The vertices of the collision mesh at rest (#V × dim). edges: The edges of the collision mesh (#E × 2). faces: The faces of the collision mesh (#F × 3). displacement_map: The displacement mapping from displacements on the full mesh to the collision mesh.

  2. __init__(self: ipctk.CollisionMesh, include_vertex: list[bool], full_rest_positions: numpy.ndarray[numpy.float64[m, n]], edges: numpy.ndarray[numpy.int32[m, n]] = array([], shape=(0, 0), dtype=int32), faces: numpy.ndarray[numpy.int32[m, n]] = array([], shape=(0, 0), dtype=int32), displacement_map: scipy.sparse.csc_matrix[numpy.float64] = <Compressed Sparse Column sparse matrix of dtype ‘float64’ with 0 stored elements and shape (0, 0)>) -> None

    Construct a new Collision Mesh object from a full mesh vertices.

    Parameters:

    include_vertex: Vector of bools indicating whether each vertex should be included in the collision mesh. full_rest_positions: The vertices of the full mesh at rest (#V × dim). edges: The edges of the collision mesh indexed into the full mesh vertices (#E × 2). faces: The faces of the collision mesh indexed into the full mesh vertices (#F × 3). displacement_map: The displacement mapping from displacements on the full mesh to the collision mesh.

__module__ = 'ipctk'
are_adjacencies_initialized(self) bool

Determine if the adjacencies have been initialized by calling init_adjacencies().

are_area_jacobians_initialized(self) bool

Determine if the area Jacobians have been initialized by calling init_area_jacobians().

static build_from_full_mesh(full_rest_positions: numpy.ndarray[numpy.float64[m, n]], edges: numpy.ndarray[numpy.int32[m, n]], faces: numpy.ndarray[numpy.int32[m, n]] = array([], shape=(0, 0), dtype=int32)) ipctk.CollisionMesh

Helper function that automatically builds include_vertex using construct_is_on_surface.

Parameters:
full_rest_positions: numpy.ndarray[numpy.float64[m, n]]

The full vertices at rest (#FV × dim).

edges: numpy.ndarray[numpy.int32[m, n]]

The edge matrix of mesh (#E × 2).

faces: numpy.ndarray[numpy.int32[m, n]] = array([], shape=(0, 0), dtype=int32)

The face matrix of mesh (#F × 3).

Returns:

Constructed CollisionMesh.

property can_collide : collections.abc.Callable[[int, int], bool]

A function that takes two vertex IDs and returns true if the vertices (and faces or edges containing the vertices) can collide.

By default all primitives can collide with all other primitives.

property codim_edges : numpy.ndarray[numpy.int32[m, 1]]

Get the indices of codimensional edges of the collision mesh (#CE x 1).

property codim_vertices : numpy.ndarray[numpy.int32[m, 1]]

Get the indices of codimensional vertices of the collision mesh (#CV x 1).

static construct_faces_to_edges(faces: numpy.ndarray[numpy.int32[m, n]], edges: numpy.ndarray[numpy.int32[m, n]]) numpy.ndarray[numpy.int32[m, n]]

Construct a matrix that maps from the faces’ edges to rows in the edges matrix.

Parameters:
faces: numpy.ndarray[numpy.int32[m, n]]

The face matrix of mesh (#F × 3).

edges: numpy.ndarray[numpy.int32[m, n]]

The edge matrix of mesh (#E × 2).

Returns:

Matrix that maps from the faces’ edges to rows in the edges matrix.

static construct_is_on_surface(num_vertices: int, edges: numpy.ndarray[numpy.int32[m, n]], codim_vertices: numpy.ndarray[numpy.int32[m, 1]] = array([], dtype=int32)) list[bool]

Construct a vector of bools indicating whether each vertex is on the surface.

Parameters:
num_vertices: int

The number of vertices in the mesh.

edges: numpy.ndarray[numpy.int32[m, n]]

The surface edges of the mesh (#E × 2).

codim_vertices: numpy.ndarray[numpy.int32[m, 1]] = array([], dtype=int32)

The indices of codimensional vertices (#CV x 1).

Returns:

A vector of bools indicating whether each vertex is on the surface.

property dim : int

Get the dimension of the mesh.

displace_vertices(self, full_displacements: numpy.ndarray[numpy.float64[m, n]]) numpy.ndarray[numpy.float64[m, n]]

Compute the vertex positions from vertex displacements on the full mesh.

Parameters:
full_displacements: numpy.ndarray[numpy.float64[m, n]]

The vertex displacements on the full mesh (#FV × dim).

Returns:

The vertex positions of the collision mesh (#V × dim).

edge_area(self, ei: int) float

Get the barycentric area of an edge.

Parameters:
ei: int

Edge ID.

Returns:

Barycentric area of edge ei.

edge_area_gradient(self, ei: int) scipy.sparse.csc_matrix[numpy.float64]

Get the gradient of the barycentric area of an edge wrt the rest positions of all points.

Parameters:
ei: int

Edge ID.

Returns:

Gradient of the barycentric area of edge ei wrt the rest positions of all points.

edge_areas(self) numpy.ndarray[numpy.float64[m, 1]]

Get the barycentric area of the edges.

property edge_vertex_adjacencies : list[tsl::robin_set<int, absl::lts_20230125::hash_internal::Hash<int>, std::equal_to<int>, std::allocator<int>, false, tsl::rh::power_of_two_growth_policy<2ul> >]

Get the edge-vertex adjacency matrix.

property edges : numpy.ndarray[numpy.int32[m, n]]

Get the edges of the collision mesh (#E × 2).

property faces : numpy.ndarray[numpy.int32[m, n]]

Get the faces of the collision mesh (#F × 3).

property faces_to_edges : numpy.ndarray[numpy.int32[m, n]]

Get the mapping from faces to edges of the collision mesh (#F × 3).

property full_ndof : int

Get the number of degrees of freedom in the full mesh.

property full_num_vertices : int

Get the number of vertices in the full mesh.

init_adjacencies(self) None

Initialize vertex-vertex and edge-vertex adjacencies.

init_area_jacobians(self) None

Initialize vertex and edge areas.

is_vertex_on_boundary(self, vi: int) bool

Is a vertex on the boundary of the collision mesh?

Parameters:
vi: int

Vertex ID.

Returns:

True if the vertex is on the boundary of the collision mesh.

map_displacements(self, full_displacements: numpy.ndarray[numpy.float64[m, n]]) numpy.ndarray[numpy.float64[m, n]]

Map vertex displacements on the full mesh to vertex displacements on the collision mesh.

Parameters:
full_displacements: numpy.ndarray[numpy.float64[m, n]]

The vertex displacements on the full mesh (#FV × dim).

Returns:

The vertex displacements on the collision mesh (#V × dim).

property ndof : int

Get the number of degrees of freedom in the collision mesh.

property num_codim_edges : int

Get the number of codimensional edges in the collision mesh.

property num_codim_vertices : int

Get the number of codimensional vertices in the collision mesh.

property num_edges : int

Get the number of edges in the collision mesh.

property num_faces : int

Get the number of faces in the collision mesh.

property num_vertices : int

Get the number of vertices in the collision mesh.

property rest_positions : numpy.ndarray[numpy.float64[m, n]]

Get the vertices of the collision mesh at rest (#V × dim).

to_full_dof(*args, **kwargs)

Overloaded function.

  1. to_full_dof(self: ipctk.CollisionMesh, x: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 1]]

    Map a vector quantity on the collision mesh to the full mesh.

    This is useful for mapping gradients from the collision mesh to the full mesh (i.e., applies the chain-rule).

    Parameters:

    x: Vector quantity on the collision mesh with size equal to ndof().

    Returns:

    Vector quantity on the full mesh with size equal to full_ndof().

  2. to_full_dof(self: ipctk.CollisionMesh, X: scipy.sparse.csc_matrix[numpy.float64]) -> scipy.sparse.csc_matrix[numpy.float64]

    Map a matrix quantity on the collision mesh to the full mesh.

    This is useful for mapping Hessians from the collision mesh to the full mesh (i.e., applies the chain-rule).

    Parameters:

    X: Matrix quantity on the collision mesh with size equal to ndof() × ndof().

    Returns:

    Matrix quantity on the full mesh with size equal to full_ndof() × full_ndof().

to_full_vertex_id(self, id: int) int

Map a vertex ID to the corresponding vertex ID in the full mesh.

Parameters:
id: int

Vertex ID in the collision mesh.

Returns:

Vertex ID in the full mesh.

vertex_area(self, vi: int) float

Get the barycentric area of a vertex.

Parameters:
vi: int

Vertex ID.

Returns:

Barycentric area of vertex vi.

vertex_area_gradient(self, vi: int) scipy.sparse.csc_matrix[numpy.float64]

Get the gradient of the barycentric area of a vertex wrt the rest positions of all points.

Parameters:
vi: int

Vertex ID.

Returns:

Gradient of the barycentric area of vertex vi wrt the rest positions of all points.

property vertex_areas : numpy.ndarray[numpy.float64[m, 1]]

Get the barycentric area of the vertices.

property vertex_edge_adjacencies : list[tsl::robin_set<int, absl::lts_20230125::hash_internal::Hash<int>, std::equal_to<int>, std::allocator<int>, false, tsl::rh::power_of_two_growth_policy<2ul> >]

Get the vertex-edge adjacency matrix.

property vertex_vertex_adjacencies : list[tsl::robin_set<int, absl::lts_20230125::hash_internal::Hash<int>, std::equal_to<int>, std::allocator<int>, false, tsl::rh::power_of_two_growth_policy<2ul> >]

Get the vertex-vertex adjacency matrix.

vertices(self, full_positions: numpy.ndarray[numpy.float64[m, n]]) numpy.ndarray[numpy.float64[m, n]]

Compute the vertex positions from the positions of the full mesh.

Parameters:
full_positions: numpy.ndarray[numpy.float64[m, n]]

The vertex positions of the full mesh (#FV × dim).

Returns:

The vertex positions of the collision mesh (#V × dim).


Last update: Nov 16, 2024