Mesh1D¶
from mcot.surface.mesh import Mesh1D
-
class
mcot.surface.mesh.
Mesh1D
(vertices, faces='open')[source]¶ 1-dimensional mesh object consisting of vertices and lines connecting these vertices.
Attributes: vertices: (M, N) array with the vertices of the curve in M-dimensional space. faces: (2, K) index array with all the line segments.
-
__init__
(vertices, faces='open')[source]¶ Creates a new curve.
- Parameters
vertices – (M, N) array with N vertices on a one-dimensional curve in M-dimensional space
faces –
(2, K) array with integers of which lines are connected. Can also be one of:
’open’: defaults to connecting all vertices in order
’closed’: defaults to connecting all vertices in order and connect the last point to the first
Inheritance diagram
Methods
as_lines
([as_indices])Return the connected vertices as a list of curves.
closed
()Check if the mesh is closed (i.e.
closest_vertex
(points)Finds the closest vertices on the surface for a bunch of vertices.
Returns a tuple with (number of connected components, labeling of connected components).
find_intersections
(position, orientation[, …])Finds out which faces intersection with position + a * hemisphere.
graph_connection_connection
([weight, dtype])Converts the mesh into a graph, where the nodes are the faces and the edges are between those faces sharing vertices.
graph_connection_point
([dtype])Returns the interactions between vertices and faces as a sparse matrix.
graph_point_point
([weight, dtype, …])Converts the mesh into a graph describing the edges between the individual vertices (nodes).
normal
()Calculates the normal of every face.
Computes the length of the line segments connecting the vertices.
Attributes the size of the faces to the vertices they connect.
surface_edge_distance
([use, method, …])Returns a matrix of the shortest distances across the edges connecting the vertices.
Attributes
faces
ndim
Dimensionality of the embedding space.
nfaces
Number of surface elements connecting the vertices.
nvertices
Number of vertices on the mesh.
tree
A KD tree used to compute the distance between the vertices defining the surface and any other vertices.
vertices
-
as_lines¶
-
Mesh1D.
as_lines
(as_indices=False)[source]¶ Return the connected vertices as a list of curves.
- Parameters
as_indices – Returns the indices of the vertices rather than the vertices themselves
- Returns
List[Array], where the array is a (L, ) array of indices if as_indices is True or (L, 2) array of vertices otherwise
closed¶
closest_vertex¶
-
Mesh1D.
closest_vertex
(points)¶ Finds the closest vertices on the surface for a bunch of vertices.
- Parameters
points – (ndim, nvertices) array with the reference vertices
- Returns
tuple with
(nvertices, ) distance array
(nvertices, ) index array
connected_components¶
-
Mesh1D.
connected_components
()¶ Returns a tuple with (number of connected components, labeling of connected components).
find_intersections¶
-
Mesh1D.
find_intersections
(position, orientation, return_position=False)[source]¶ Finds out which faces intersection with position + a * hemisphere.
- Parameters
position – origin of the ray
orientation – propagation direction of the ray
return_position – if True also return the coordinates of the intersection
- Returns
(K, ) boolean array with the intercepted faces
graph_connection_connection¶
-
Mesh1D.
graph_connection_connection
(weight=None, dtype='bool')¶ Converts the mesh into a graph, where the nodes are the faces and the edges are between those faces sharing vertices.
- Parameters
weight – Weights the boundaries by the distance between the connection centers if set to “distance”
dtype – datatype of the resulting sparse matrix (only used if weight is None)
- Returns
(N, N) sparse matrix for N faces, which is one (or the value set by weight) if the faces share a vertex.
graph_connection_point¶
-
Mesh1D.
graph_connection_point
(dtype='bool')¶ Returns the interactions between vertices and faces as a sparse matrix.
The resulting matrix can be used to multiply a vector of size M faces to get a vector of size N vertices.
The result of this method is cached in _graph (set _graph to None to re-compute the graph).
- Parameters
dtype – data type of the resulting sparse matrix
- Returns
(N, M) sparse matrix for N vertices and M faces, which is one if connection M interacts with N.
graph_point_point¶
-
Mesh1D.
graph_point_point
(weight=None, dtype='bool', include_diagonal=True)¶ Converts the mesh into a graph describing the edges between the individual vertices (nodes).
- Parameters
weight – Weights the boundaries by the distance between the vertices if set to “distance”
dtype – datatype of the resulting sparse matrix (only used if weight is None)
include_diagonal – if set to False exclude the diagonal from the sparse matrix
- Returns
(N, N) sparse matrix for N vertices, which is one (or the value set by weight) if the vertices are connected.
normal¶
size_faces¶
size_vertices¶
-
Mesh1D.
size_vertices
()¶ Attributes the size of the faces to the vertices they connect.
surface_edge_distance¶
-
Mesh1D.
surface_edge_distance
(use=None, method='auto', return_predecessors=False, use_connections=False)¶ Returns a matrix of the shortest distances across the edges connecting the vertices.
This is an upper limit to the true distance across the surface, because the path is limited to following the edges of the triangular mesh.
This is a wrapper around scipy.sparse.csgraph.shortest_path.
- Parameters
use – boolean array indicating which vertices or faces to use (default: use all)
method – method used by scipy.sparse.csgraph.shortest_path.
return_predecessors – whether to return the (N, N) predecessor matrix
use_connections – compute the shortest distance between the faces rather than the vertices.
- Returns
(N, N) matrix of shortest distances across the graph