Surface meshes are one of the core structures in Polyscope. In addition to simply displaying the mesh, Polyscope can show any number of scalar, vector,color, and other kinds of quantities associated with the vertices/faces/edges/etc of the mesh.
Polyscope does not impose any requirements on the meshes visualized. They may be polygonal or nonmanifold. As always, try clicking on the vertices or faces of a mesh see the data associated with that mesh element.
Registering a surface mesh
Example: registering a surface mesh from libIGL
#include "polyscope/polyscope.h" #include "polyscope/surface_mesh.h" #include <igl/readOBJ.h> // Initialize Polyscope polyscope::init(); // Read the mesh Eigen::MatrixXd meshV; Eigen::MatrixXi meshF; igl::readOBJ(filename, meshV, meshF); // Register the mesh with Polyscope polyscope::registerSurfaceMesh("input mesh", meshV, meshF); // Show the GUI polyscope::show();
Surface meshes are registered with Polyscope by passing the location of each vertex in the mesh, as well as the vertex indices for each face.
polyscope::registerSurfaceMesh(std::string name, const V& vertexPositions, const F& faceIndices)
Add a new surface mesh structure to Polyscope.
vertexPositionsis the vector array of 3D vertex locations. The type should be adaptable to an array of
float-valued 3-vectors; this allows many common types to be used as input, including
std::vector<std::array<double, 3>>. The length will be the number of vertices.
faceIndicesis the nested array of vertex indices for each face. The type should be adaptable to a nested array of
size_t; this allows many common types to be used as input, including
std::vector<std::array<size_t, 3>>. The outer length will be the number of faces. All indices should be valid 0-based indices in to the vertex list.
General nested lists can be used to create polygonal meshes of varying face degree, such as
std::vector<std::vector<size_t>>. Also, passing a fixed-size 2D array of indices will work just fine, like
Fx3 dimensions for a triangle mesh, or
Fx4 for a quad mesh.
Note: the inner vector type of the vertex positions must be 3D dimensional, or you risk compiler errors, segfaults, or worse. If you want to register a 2D surface mesh,
registerSurfaceMesh2D exists with the same signature. See 2D data.
Polyscope quantities are ordered arrays of data, but not everyone can agree on the ordering of elements in a mesh. See indexing conventions.
The default ordering is probably the same as yours for data on vertices, faces, and corners. However, data on edges and halfedges is much more likely to require setting an ordering.
Updating a mesh
The locations of the vertices in a mesh can be updated with the member function
updateVertexPositions(newPositions). All quantities will be preserved. Changing the connectivity or element counts in a mesh is not supported, you will need to register a new mesh (perhaps with the same name to overwrite).
void SurfaceMesh::updateVertexPositions(const V& newPositions)
Update the vertex positions in a surface mesh structure.
newPositionsis the vector array of 3D vertex locations. The type should be adaptable to an array of
float-valued 3-vectors. The length must be equal to the current number of vertices.
updateVertexPositions2D exists with the same signature. See 2D data.
Back face policies
The faces of a mesh are implicitly given an outward orientation by the order in which the vertices are listed. The standard convention, which Polyscope respects, is that a counter-clockwise ordering of vertices defines the “outward” direction. Faces which are viewed from behind are referred to as back faces; they can arise when a surface is viewed from the inside, or if a mesh is not properly oriented. Polyscope offers several options for how back faces are displayed.
BackFacePolicy::Identicalall faces are always rendered identically, whether viewed from the front or back
BackFacePolicy::Differentback faces are shaded slightly darker, so they can be distinguished (this is the default)
BackFacePolicy::Customback faces are shaded with a configurable color
BackFacePolicy::Cullback faces are culled, and not rendered at all
The choice of these policies can be set as an option for each surface mesh structure, either in the GUI via
[Options] -> [Back Face Policy] or programmatically with the function below.
SurfaceMesh* SurfaceMesh::setBackFacePolicy(BackFacePolicy newPolicy)
Set the policy for rendering oppositely-oriented back faces.
newPolicyis an enum giving the new policy, one of
BackFacePolicy::Cullas described above
There is also a corresponding
SurfaceMesh* SurfaceMesh::setBackFaceColor(glm::vec3 val)
Set the color to be used for custom back face coloring. Has no effect unless the back face policy is
There is also a corresponding
See structure management for options common to all structures such as enabling/disabling, transforms, and transparency.
|shade smooth||use smooth shading along faces or simple flat faces||
|surface color||the color of the mesh||
|edge color||the color of the edges of the mesh||
|edge width||how thick to draw mesh edges, use
|material||what material to use||
|back face policy||what back face policy to use||
|back face color||back face color for the
(All setters return
this to support chaining. Structure options return a generic structure pointer, so chain them last.)