From df12190955e05f5bc15e71427ce8db6d860e3df3 Mon Sep 17 00:00:00 2001 From: Robin Christ Date: Mon, 3 Nov 2025 23:52:26 +0100 Subject: [PATCH 1/2] EmbeddedGeometryInterface: Add face centroids as managed quantity --- .../surface/embedded_geometry_interface.h | 8 ++++++++ src/surface/embedded_geometry_interface.cpp | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/geometrycentral/surface/embedded_geometry_interface.h b/include/geometrycentral/surface/embedded_geometry_interface.h index 64d2710d..fed68671 100644 --- a/include/geometrycentral/surface/embedded_geometry_interface.h +++ b/include/geometrycentral/surface/embedded_geometry_interface.h @@ -28,6 +28,11 @@ class EmbeddedGeometryInterface : public ExtrinsicGeometryInterface { void requireVertexPositions(); void unrequireVertexPositions(); + // Face centroids + FaceData faceCentroids; + void requireFaceCentroids(); + void unrequireFaceCentroids(); + // Face normal FaceData faceNormals; void requireFaceNormals(); @@ -116,6 +121,9 @@ class EmbeddedGeometryInterface : public ExtrinsicGeometryInterface { DependentQuantityD> vertexPositionsQ; virtual void computeVertexPositions() = 0; + DependentQuantityD> faceCentroidsQ; + virtual void computeFaceCentroids(); + DependentQuantityD> faceNormalsQ; virtual void computeFaceNormals(); diff --git a/src/surface/embedded_geometry_interface.cpp b/src/surface/embedded_geometry_interface.cpp index a32035b3..9b0dbd48 100644 --- a/src/surface/embedded_geometry_interface.cpp +++ b/src/surface/embedded_geometry_interface.cpp @@ -13,6 +13,7 @@ EmbeddedGeometryInterface::EmbeddedGeometryInterface(SurfaceMesh& mesh_) : ExtrinsicGeometryInterface(mesh_), vertexPositionsQ (&vertexPositions, std::bind(&EmbeddedGeometryInterface::computeVertexPositions, this), quantities), + faceCentroidsQ (&faceCentroids, std::bind(&EmbeddedGeometryInterface::computeFaceCentroids, this), quantities), faceNormalsQ (&faceNormals, std::bind(&EmbeddedGeometryInterface::computeFaceNormals, this), quantities), vertexNormalsQ (&vertexNormals, std::bind(&EmbeddedGeometryInterface::computeVertexNormals, this), quantities), faceTangentBasisQ (&faceTangentBasis, std::bind(&EmbeddedGeometryInterface::computeFaceTangentBasis, this), quantities), @@ -76,6 +77,25 @@ void EmbeddedGeometryInterface::computeEdgeDihedralAngles() { void EmbeddedGeometryInterface::requireVertexPositions() { vertexPositionsQ.require(); } void EmbeddedGeometryInterface::unrequireVertexPositions() { vertexPositionsQ.unrequire(); } +// Face centroids +void EmbeddedGeometryInterface::computeFaceCentroids() { + vertexPositionsQ.ensureHave(); + + faceCentroids = FaceData(mesh); + + for (Face f : mesh.faces()) { + Vector3 centroid = Vector3::zero(); + size_t n = 0; + for (Vertex v : f.adjacentVertices()) { + centroid += vertexPositions[v]; + n++; + } + centroid /= static_cast(n); + faceCentroids[f] = centroid; + } +} +void EmbeddedGeometryInterface::requireFaceCentroids() { faceCentroidsQ.require(); } +void EmbeddedGeometryInterface::unrequireFaceCentroids() { faceCentroidsQ.unrequire(); } void EmbeddedGeometryInterface::computeFaceNormals() { vertexPositionsQ.ensureHave(); From 4717575f5d94f1049ecc8e7785387211acdd1b94 Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Sun, 26 Apr 2026 12:35:03 -0700 Subject: [PATCH 2/2] add docs for face centroids --- docs/docs/surface/geometry/quantities.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/docs/surface/geometry/quantities.md b/docs/docs/surface/geometry/quantities.md index aeed7489..2557aa47 100644 --- a/docs/docs/surface/geometry/quantities.md +++ b/docs/docs/surface/geometry/quantities.md @@ -734,6 +734,16 @@ These quantities depend explicitly on an embedding in 3D space (better known as - **require:** `void EmbeddedGeometryInterface::requireVertexPositions()` +??? func "face centroid" + + ##### face centroid + + The centroid (geometric center) of each face, computed as the average of its adjacent vertex positions. Works for faces of any degree (triangles, quads, polygons, etc.). + + - **member:** `FaceData EmbeddedGeometryInterface::faceCentroids` + - **require:** `void EmbeddedGeometryInterface::requireFaceCentroids()` + + ??? func "face normal" ##### face normal