Skip to content

Scalar Quantities

Visualize scalar (real or integer)-valued data at the elements of a surface mesh.

Example: visualizing cotangent weights at edges with geometry-central

#include "geometrycentral/surface/vertex_position_geometry.h"
#include "polyscope/polyscope.h"
#include "polyscope/surface_mesh.h"

polyscope::init();

// Load mesh
std::unique_ptr<HalfedgeMesh> mesh;
std::unique_ptr<VertexPositionGeometry> geom;

std::tie(mesh, geom) = loadMesh(args::get(inputFilename));
geom->requireVertexPositions();


// Register the geometry-central mesh
auto psMesh = polyscope::registerSurfaceMesh("input mesh", 
                                             geom->vertexPositions, 
                                             mesh->getFaceVertexList());
psMesh->setAllPermutations(polyscopePermutations(*mesh)); // set permutations, 
                                                          // so edge data is meaningful

// Build cotan weights for the mesh
geom->requireEdgeCotanWeights();

// Visualize cotan weights
psMesh->addEdgeScalarQuantity("edge cotan weights", geom->edgeCotanWeights);
polyscope::show();

Add scalars to elements

SurfaceMesh::addVertexScalarQuantity(std::string name, const T& values, DataType type = DataType::STANDARD)

Add a scalar quantity defined at the vertices of the mesh.

  • values is the array of scalars at vertices. The type should be adaptable to a float scalar array. The length should be the number of vertices in the mesh.
SurfaceMesh::addFaceScalarQuantity(std::string name, const T& values, DataType type = DataType::STANDARD)

Add a scalar quantity defined at the faces of the mesh.

  • values is the array of scalars at faces. The type should be adaptable to a float scalar array. The length should be the number of faces in the mesh.
SurfaceMesh::addEdgeScalarQuantity(std::string name, const T& values, DataType type = DataType::STANDARD)

Add a scalar quantity defined at the edges of the mesh.

  • values is the array of scalars at edges. The type should be adaptable to a float scalar array. The length should be the number of edges in the mesh.

Remember, before passing edge-valued data, be sure your indexing convention matches what Polyscope expects.

SurfaceMesh::addHalfedgeScalarQuantity(std::string name, const T& values, DataType type = DataType::STANDARD)

Add a scalar quantity defined at the halfedges of the mesh.

  • values is the array of scalars at halfedges. The type should be adaptable to a float scalar array. The length should be the number of halfedges in the mesh.

Remember, before passing halfedge-valued data, be sure your indexing convention matches what Polyscope expects.

Options

Parameter Meaning Getter Setter Persistent?
enabled is the quantity enabled? bool isEnabled() setEnabled(bool newVal) yes
color map the color map to use gl::ColorMapID getColorMap() setColorMap(gl::ColorMapID newMap) yes
map range the lower and upper limits used when mapping the data in to the color map std::pair<double,double> getMapRange() setMapRange(std::pair<double,double>) and resetMapRange() no

(all setters return this to support chaining. setEnabled() returns generic quantity, so chain it last)