Scalar Quantities
Visualize scalar (real or integer)-valued data at the elements of a surface mesh.
Example:
import numpy as np
import polyscope as ps
ps.init()
N_vert = 100
N_face = 250
vertices = np.random.rand(N_vert, 3) # (V,3) vertex position array
faces = np.random.randint(0, N_vert, size=(N_face,3)) # (F,3) array of indices
# for triangular faces
ps_mesh = ps.register_surface_mesh("my mesh", vertices, faces)
# visualize some random data per-vertex
vals_vert = np.random.rand(N_vert)
ps_mesh.add_scalar_quantity("rand vals", vals_vert, enabled=True)
# visualize some random data per-face
vals_face = np.random.rand(N_face)
ps_mesh.add_scalar_quantity("rand vals2", vals_face, defined_on='faces')
# visualize some random data per-edge (halfedges are also supported)
vals_edge = np.random.rand(ps_mesh.n_edges())
ps_mesh.add_scalar_quantity("rand vals3", vals_edge, defined_on='edges')
# as always, we can customize the initial appearance
ps_mesh.add_scalar_quantity("rand vals3 opt", vals_edge, defined_on='edges',
enabled=True, vminmax=(-3., 3.), cmap='reds')
# view the mesh with all of these quantities
ps.show()
SurfaceMesh.add_scalar_quantity(name, values, defined_on='vertices', enabled=None, datatype="standard", vminmax=None, cmap=None)
Add a scalar quantity to the mesh.
name
string, a name for the quantityvalues
a lengthN
numpy array, scalars at vertices/faces/etcdefined_on
one of'vertices','faces','edges','halfedges'
, is this data a value per vertex or a value per face, etc?
Additional optional keyword arguments:
enabled
boolean, whether the quantity is initially enabled (note that generally only one quantity can be shown at a time; the most recent will be used)datatype
one ofstandard
,symmetric
, ormagnitude
, affects default colormap and map rangevminmax
a 2-tuple of floats, specifying the min and max range to colormap in tocmap
string, which colormap to use
if not specified, these optional parameters will assume a reasonable default value, or a persistent value if previously set.