Skip to content

Surface Meshes

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

// 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

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.

  • vertexPositions is the vector array of 3D vertex locations. The type should be adaptable to an array of float-valued 3-vectors. The length will be the number of vertices.

  • faceIndices is the nested array of vertex indices for each face. The type should be adaptable to a nested array of size_t. The outer length will be the number of faces. All indices should be valid 0-based indices in to the vertex list.

Fortunately, although Polyscope accepts a general nested list of face vertex indices to support Polygonal meshes, passing a fixed-size Nx3 array for a triangle will work just fine, like Eigen::MatrixXi.

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.

Element ordering

Polyscope quantities are ordered arrays of data, but not everone 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.

  • newPositions is 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.

Note: updateVertexPositions2D exists with the same signature. See 2D data.


Parameter Meaning Getter Setter Persistent?
enabled is the structure enabled? bool isEnabled() setEnabled(bool newVal) yes
transparency transparency alpha for this structure in [0,1] double getTransparency() setTransparency(double val) yes
shade smooth use smooth shading along faces or simple flat faces bool isSmoothShade() setSmoothShade(bool isSmooth) yes
surface color the color of the mesh glm::vec3 getSurfaceColor() setSurfaceColor(glm::vec3 val) yes
edge color the color of the edges of the mesh glm::vec3 getEdgeColor() setEdgeColor(glm::vec3 val) yes
edge width how thick to draw mesh edges, use 0. to disable and 1. for reasonable edges double getEdgeWidth() setEdgeWidth(double val) yes
material what material to use std::string getMaterial() setMaterial(std::string name) yes

(all setters return this to support chaining. setEnabled()/setTransparency() return generic setter, so chain them last)