This module implements classes and methods for handling geometric data.
vispy.geometry.
MeshData
(vertices=None, faces=None, edges=None, vertex_colors=None, face_colors=None, vertex_values=None)[source]¶Class for storing and operating on 3D mesh data.
Parameters: | vertices : ndarray, shape (Nv, 3)
faces : ndarray, shape (Nf, 3)
edges : None
vertex_colors : ndarray, shape (Nv, 4)
face_colors : ndarray, shape (Nf, 4)
vertex_values : ndarray, shape (Nv,)
|
---|
Notes
All arguments are optional.
The object may contain:
This class handles conversion between the standard [list of vertices, list of faces] format (suitable for use with glDrawElements) and ‘indexed’ [list of vertices] format (suitable for use with glDrawArrays). It will automatically compute face normal vectors as well as averaged vertex normal vectors.
The class attempts to be as efficient as possible in caching conversion results and avoiding unnecessary conversions.
get_edges
(indexed=None)[source]¶Edges of the mesh
Parameters: | indexed : str | None
|
---|---|
Returns: | edges : ndarray
|
get_face_colors
(indexed=None)[source]¶Get the face colors
Parameters: | indexed : str | None
|
---|---|
Returns: | colors : ndarray
|
get_face_normals
(indexed=None)[source]¶Get face normals
Parameters: | indexed : str | None
|
---|---|
Returns: | normals : ndarray
|
get_faces
()[source]¶Array (Nf, 3) of vertex indices, three per triangular face.
If faces have not been computed for this mesh, returns None.
get_vertex_colors
(indexed=None)[source]¶Get vertex colors
Parameters: | indexed : str | None
|
---|---|
Returns: | colors : ndarray
|
get_vertex_normals
(indexed=None)[source]¶Get vertex normals
Parameters: | indexed : str | None
|
---|---|
Returns: | normals : ndarray
|
get_vertex_values
(indexed=None)[source]¶Get vertex colors
Parameters: | indexed : str | None
|
---|---|
Returns: | values : ndarray
|
get_vertices
(indexed=None)[source]¶Get the vertices
Parameters: | indexed : str | None
|
---|---|
Returns: | vertices : ndarray
|
has_face_indexed_data
()[source]¶Return True if this object already has vertex positions indexed by face
n_faces
¶The number of faces in the mesh
n_vertices
¶The number of vertices in the mesh
restore
(state)[source]¶Restore the state of a mesh previously saved using save()
Parameters: | state : dict
|
---|
save
()[source]¶Serialize this mesh to a string appropriate for disk storage
Returns: | state : dict
|
---|
set_face_colors
(colors, indexed=None)[source]¶Set the face color array
Parameters: | colors : array
indexed : str | None
|
---|
set_faces
(faces)[source]¶Set the faces
Parameters: | faces : ndarray
|
---|
set_vertex_colors
(colors, indexed=None)[source]¶Set the vertex color array
Parameters: | colors : array
indexed : str | None
|
---|
set_vertex_values
(values, indexed=None)[source]¶Set the vertex value array
Parameters: | values : array
indexed : str | None
|
---|
set_vertices
(verts=None, indexed=None, reset_normals=True)[source]¶Set the mesh vertices
Parameters: | verts : ndarray | None
indexed : str | None
reset_normals : bool
|
---|
vispy.geometry.
PolygonData
(vertices=None, edges=None, faces=None)[source]¶Polygon class for data handling
Parameters: | vertices : (Nv, 3) array
edges : (Nv, 2) array
faces : (Nf, 3) array
|
---|
Notes
All arguments are optional.
add_vertex
(vertex)[source]¶Adds given vertex and retriangulates to generate new faces.
Parameters: | vertex : array-like
|
---|
convex_hull
¶Return an array of vertex indexes representing the convex hull.
If faces have not been computed for this mesh, the function computes them. If no vertices or faces are specified, the function returns None.
edges
¶Return an array (Nv, 2) of vertex indices.
If no vertices or faces are specified, the function returns None.
faces
¶Return an array (Nf, 3) of vertex indexes, three per triangular face in the mesh.
If faces have not been computed for this mesh, the function computes them. If no vertices or faces are specified, the function returns None.
triangulate
()[source]¶Triangulates the set of vertices and stores the triangles in faces and the convex hull in convex_hull.
vertices
¶Return an array (Nf, 3) of vertices.
If only faces exist, the function computes the vertices and returns them. If no vertices or faces are specified, the function returns None.
vispy.geometry.
Rect
(*args, **kwargs)[source]¶Representation of a rectangular area in a 2D coordinate system.
Parameters: | *args : arguments
|
---|
contains
(x, y)[source]¶Query if the rectangle contains points
Parameters: | x : float
y : float
|
---|---|
Returns: | contains : bool
|
flipped
(x=False, y=True)[source]¶Return a Rect with the same bounds but with axes inverted
Parameters: | x : bool
y : bool
|
---|---|
Returns: | rect : instance of Rect
|
vispy.geometry.
Triangulation
(pts, edges)[source]¶Constrained delaunay triangulation
Implementation based on [R1].
Parameters: | pts : array
edges : array
|
---|
Notes
References
[R1] | (1, 2) Domiter, V. and Žalik, B. Sweep‐line algorithm for constrained Delaunay triangulation |
vispy.geometry.
triangulate
(vertices)[source]¶Triangulate a set of vertices
Parameters: | vertices : array-like
|
---|---|
Returns: | vertices : array-like
tringles : array-like
|
vispy.geometry.
create_arrow
(rows, cols, radius=0.1, length=1.0, cone_radius=None, cone_length=None)[source]¶Create a 3D arrow using a cylinder plus cone
Parameters: | rows : int
cols : int
radius : float
length : float
cone_radius : float
cone_length : float
|
---|---|
Returns: | arrow : MeshData
|
vispy.geometry.
create_box
(width=1, height=1, depth=1, width_segments=1, height_segments=1, depth_segments=1, planes=None)[source]¶Generate vertices & indices for a filled and outlined box.
Parameters: | width : float
height : float
depth : float
width_segments : int
height_segments : float
depth_segments : float
planes: array_like
|
---|---|
Returns: | vertices : array
faces : array
outline : array
|
vispy.geometry.
create_cone
(cols, radius=1.0, length=1.0)[source]¶Create a cone
Parameters: | cols : int
radius : float
length : float
|
---|---|
Returns: | cone : MeshData
|
vispy.geometry.
create_cube
()[source]¶Generate vertices & indices for a filled and outlined cube
Returns: | vertices : array
filled : array
outline : array
|
---|
vispy.geometry.
create_cylinder
(rows, cols, radius=[1.0, 1.0], length=1.0, offset=False)[source]¶Create a cylinder
Parameters: | rows : int
cols : int
radius : tuple of float
length : float
offset : bool
|
---|---|
Returns: | cylinder : MeshData
|
vispy.geometry.
create_grid_mesh
(xs, ys, zs)[source]¶Generate vertices and indices for an implicitly connected mesh.
The intention is that this makes it simple to generate a mesh from meshgrid data.
Parameters: | xs : ndarray
ys : ndarray
zs : ndarray
|
---|---|
Returns: | vertices : ndarray
indices : ndarray
|
vispy.geometry.
create_plane
(width=1, height=1, width_segments=1, height_segments=1, direction='+z')[source]¶Generate vertices & indices for a filled and outlined plane.
Parameters: | width : float
height : float
width_segments : int
height_segments : float
direction: unicode
|
---|---|
Returns: | vertices : array
faces : array
outline : array
|
References
[R2] | Cabello, R. (n.d.). PlaneBufferGeometry.js. Retrieved May 12, 2015, from http://git.io/vU1Fh |
vispy.geometry.
create_sphere
(rows=10, cols=10, depth=10, radius=1.0, offset=True, subdivisions=3, method='latitude')[source]¶Create a sphere
Parameters: | rows : int
cols : int
depth : int
radius : float
offset : bool
subdivisions : int
method : str
|
---|---|
Returns: | sphere : MeshData
|