This module implements classes and methods for handling geometric data.
vispy.geometry.
MeshData
Bases: object
object
Class for storing and operating on 3D mesh data.
Vertex coordinates. If faces is not specified, then this will instead be interpreted as (Nf, 3, 3) array of coordinates.
Indices into the vertex array.
[not available yet]
Vertex colors. If faces is not specified, this will be interpreted as (Nf, 3, 4) array of colors.
Face colors.
Vertex values.
Notes
All arguments are optional.
The object may contain:
list of vertex locations
list of edges
list of triangles
colors per vertex, edge, or tri
normals per vertex or tri
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_bounds
Get the mesh bounds
A list of tuples of mesh bounds.
get_edge_colors
get_edges
Edges of the mesh
If indexed is None, return (Nf, 3) array of vertex indices, two per edge in the mesh. If indexed is ‘faces’, then return (Nf, 3, 2) array of vertex indices with 3 edges per face, and two vertices per edge.
The edges.
get_face_colors
Get the face colors
If indexed is None, return (Nf, 4) array of face colors. If indexed==’faces’, then instead return an indexed array (Nf, 3, 4) (note this is just the same array with each color repeated three times).
The colors.
get_face_normals
Get face normals
If None, return an array (Nf, 3) of normal vectors for each face. If ‘faces’, then instead return an indexed array (Nf, 3, 3) (this is just the same array with each vector copied three times).
The normals.
get_faces
Array (Nf, 3) of vertex indices, three per triangular face.
If faces have not been computed for this mesh, returns None.
get_vertex_colors
Get vertex colors
If None, return an array (Nv, 4) of vertex colors. If indexed==’faces’, then instead return an indexed array (Nf, 3, 4).
The vertex colors.
get_vertex_faces
List mapping each vertex index to a list of face indices that use it.
get_vertex_normals
Get vertex normals
If None, return an (N, 3) array of normal vectors with one entry per unique vertex in the mesh. If indexed is ‘faces’, then the array will contain three normal vectors per face (and some vertices may be repeated).
get_vertex_values
If None, return an array (Nv,) of vertex values. If indexed==’faces’, then instead return an indexed array (Nf, 3).
The vertex values.
get_vertices
Get the vertices
If Note, return an array (N,3) of the positions of vertices in the mesh. By default, each unique vertex appears only once. If indexed is ‘faces’, then the array will instead contain three vertices per face in the mesh (and a single vertex may appear more than once in the array).
The vertices.
has_edge_indexed_data
has_face_color
Return True if this data set has face color information
has_face_indexed_data
Return True if this object already has vertex positions indexed by face
has_vertex_color
Return True if this data set has vertex color information
has_vertex_value
Return True if this data set has vertex value information
n_faces
The number of faces in the mesh
n_vertices
The number of vertices in the mesh
reset_normals
restore
Restore the state of a mesh previously saved using save()
The previous state.
save
Serialize this mesh to a string appropriate for disk storage
The state.
set_face_colors
Set the face color array
Array of colors. Must have shape (Nf, 4) (indexed by face), or shape (Nf, 3, 4) (face colors indexed by faces).
Should be ‘faces’ if colors are indexed by faces.
set_faces
Set the faces
(Nf, 3) array of faces. Each row in the array contains three indices into the vertex array, specifying the three corners of a triangular face.
set_vertex_colors
Set the vertex color array
Array of colors. Must have shape (Nv, 4) (indexing by vertex) or shape (Nf, 3, 4) (vertices indexed by face).
set_vertex_values
Set the vertex value array
Array of values. Must have shape (Nv,) (indexing by vertex) or shape (Nf, 3) (vertices indexed by face).
set_vertices
Set the mesh vertices
The array (Nv, 3) of vertex coordinates.
If indexed==’faces’, then the data must have shape (Nf, 3, 3) and is assumed to be already indexed as a list of faces. This will cause any pre-existing normal vectors to be cleared unless reset_normals=False.
If True, reset the normals.
PolygonData
Polygon class for data handling
Constraining edges specified by vertex indices.
Indexes into the vertex array.
add_vertex
Adds given vertex and retriangulates to generate new faces.
The vertex to add.
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.
triangulate
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.
Rect
Representation of a rectangular area in a 2D coordinate system.
Can be in the form Rect(x, y, w, h), Rect(pos, size), or Rect(Rect).
bottom
center
contains
Query if the rectangle contains points
X coordinate.
Y coordinate.
True if the point is within the rectangle.
flipped
Return a Rect with the same bounds but with axes inverted
Flip the X axis.
Flip the Y axis.
The flipped rectangle.
height
left
normalized
Return a Rect covering the same area, but with height and width guaranteed to be positive.
padded
Return a new Rect padded (smaller) by padding on all sides
The padding.
The padded rectangle.
pos
right
size
top
width
Triangulation
Constrained delaunay triangulation
Implementation based on [1].
Nx2 array of points.
Nx2 array of edges (dtype=int).
Delaunay legalization is not yet implemented. This produces a proper triangulation, but adding legalisation would produce fewer thin triangles.
The pts and edges arrays may be modified.
References
Domiter, V. and Žalik, B. Sweep‐line algorithm for constrained Delaunay triangulation
Do the triangulation.
create_arrow
Create a 3D arrow using a cylinder plus cone
Number of rows.
Number of columns.
Base cylinder radius.
Length of the arrow.
If None, then this defaults to 2x the cylinder radius.
If None, then this defaults to 1/3 of the arrow length.
Vertices and faces computed for a cone surface.
create_box
Generate vertices & indices for a filled and outlined box.
Box width.
Box height.
Box depth.
Box segments count along the width.
Box segments count along the height.
Box segments count along the depth.
Any combination of {'-x', '+x', '-y', '+y', '-z', '+z'} Included planes in the box construction.
{'-x', '+x', '-y', '+y', '-z', '+z'}
Array of vertices suitable for use as a VertexBuffer.
Indices to use to produce a filled box.
Indices to use to produce an outline of the box.
create_cone
Create a cone
Number of faces.
Base cone radius.
Length of the cone.
create_cube
Generate vertices & indices for a filled and outlined cube
Indices to use to produce a filled cube.
Indices to use to produce an outline of the cube.
create_cylinder
Create a cylinder
Cylinder radii.
Length of the cylinder.
Rotate each row by half a column.
Vertices and faces computed for a cylindrical surface.
create_grid_mesh
Generate vertices and indices for an implicitly connected mesh.
The intention is that this makes it simple to generate a mesh from meshgrid data.
A 2d array of x coordinates for the vertices of the mesh. Must have the same dimensions as ys and zs.
A 2d array of y coordinates for the vertices of the mesh. Must have the same dimensions as xs and zs.
A 2d array of z coordinates for the vertices of the mesh. Must have the same dimensions as xs and ys.
The array of vertices in the mesh.
The array of indices for the mesh.
create_plane
Generate vertices & indices for a filled and outlined plane.
Plane width.
Plane height.
Plane segments count along the width.
Plane segments count along the height.
{'-x', '+x', '-y', '+y', '-z', '+z'} Direction the plane will be facing.
Indices to use to produce a filled plane.
Indices to use to produce an outline of the plane.
Cabello, R. (n.d.). PlaneBufferGeometry.js. Retrieved May 12, 2015, from http://git.io/vU1Fh
create_sphere
Create a sphere
Number of rows (for method=’latitude’ and ‘cube’).
Number of columns (for method=’latitude’ and ‘cube’).
Number of depth segments (for method=’cube’).
Sphere radius.
Rotate each row by half a column (for method=’latitude’).
Number of subdivisions to perform (for method=’ico’)
Method for generating sphere. Accepts ‘latitude’ for latitude- longitude, ‘ico’ for icosahedron, and ‘cube’ for cube based tessellation.
Vertices and faces computed for a spherical surface.
resize
Resize an image
Array of shape (N, M, …).
2-element shape.
Interpolation, either “linear” or “nearest”.
New image, will have dtype np.float64.
Triangulate a set of vertices
The triangles.