Skip to content

Commit 03f1987

Browse files
committed
add indexsize functions
1 parent 0c8576d commit 03f1987

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

include/geometrycentral/surface/surface_mesh.h

+15
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,26 @@ class SurfaceMesh {
203203
// Check capacity. Needed when implementing expandable containers for mutable meshes to ensure the contain can
204204
// hold a sufficient number of elements before the next resize event.
205205
size_t nHalfedgesCapacity() const;
206+
size_t nCornersCapacity() const;
206207
size_t nVerticesCapacity() const;
207208
size_t nEdgesCapacity() const;
208209
size_t nFacesCapacity() const;
209210
size_t nBoundaryLoopsCapacity() const;
210211

212+
// Return the size corresponding to the largest raw index in the mesh (except corners, see below). That is, the
213+
// maximum value of he.getIndex()+1 for all halfedges, etc. This may differ from `nHalfedges()` or
214+
// `nHalfedgesCapacity()` for non-compressed meshes. It also may differ for corners even in the case of a compressed
215+
// mesh. These values may change after any mutation, not just on resize events.
216+
//
217+
// Due to implementaiton constraints, for corners the guarantee is slightly weaker: this value may be one greater than
218+
// the largest index of any corner.
219+
size_t halfedgeIndexSize() const;
220+
size_t cornerIndexSize() const; // NOTE: this one is not tight like the others
221+
size_t vertexIndexSize() const;
222+
size_t edgeIndexSize() const;
223+
size_t faceIndexSize() const;
224+
size_t boundaryLoopIndexSize() const;
225+
211226
// == Debugging, etc
212227

213228
// Performs a sanity checks on halfedge structure; throws on fail

include/geometrycentral/surface/surface_mesh.ipp

+9
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@ inline size_t SurfaceMesh::nBoundaryLoops() const { return nBoundaryLoopsCou
1919

2020
// Capacities
2121
inline size_t SurfaceMesh::nHalfedgesCapacity() const { return nHalfedgesCapacityCount; }
22+
inline size_t SurfaceMesh::nCornersCapacity() const { return nHalfedgesCapacityCount; }
2223
inline size_t SurfaceMesh::nVerticesCapacity() const { return nVerticesCapacityCount; }
2324
inline size_t SurfaceMesh::nEdgesCapacity() const { return nEdgesCapacityCount; }
2425
inline size_t SurfaceMesh::nFacesCapacity() const { return nFacesCapacityCount - nBoundaryLoopsFillCount; }
2526
inline size_t SurfaceMesh::nBoundaryLoopsCapacity() const { return nFacesCapacityCount - nFacesFillCount; }
2627

28+
// Index size
29+
inline size_t SurfaceMesh::halfedgeIndexSize() const { return nHalfedgesFillCount; }
30+
inline size_t SurfaceMesh::cornerIndexSize() const { return nHalfedgesFillCount; }
31+
inline size_t SurfaceMesh::vertexIndexSize() const { return nVerticesFillCount; }
32+
inline size_t SurfaceMesh::edgeIndexSize() const { return nEdgesFillCount; }
33+
inline size_t SurfaceMesh::faceIndexSize() const { return nFacesFillCount; }
34+
inline size_t SurfaceMesh::boundaryLoopIndexSize() const { return nBoundaryLoopsFillCount; }
35+
2736
// Connectivity
2837
inline size_t SurfaceMesh::heNext(size_t iHe) const { return heNextArr[iHe]; }
2938
inline size_t SurfaceMesh::heTwin(size_t iHe) const { if(usesImplicitTwin()) return heTwinImplicit(iHe);

test/src/halfedge_mesh_test.cpp

+60-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include "geometrycentral/surface/manifold_surface_mesh.h"
32
#include "geometrycentral/surface/meshio.h"
43
#include "geometrycentral/surface/rich_surface_mesh_data.h"
@@ -237,6 +236,66 @@ TEST_F(HalfedgeMeshSuite, IterateBoundaryLoopsTest) {
237236
}
238237

239238

239+
// ============================================================
240+
// =============== Counts and internals
241+
// ============================================================
242+
243+
TEST_F(HalfedgeMeshSuite, IndexCountTest) {
244+
for (MeshAsset& a : allMeshes()) {
245+
a.printThyName();
246+
247+
{ // Vertices
248+
bool maxSeen = false;
249+
for (Vertex v : a.mesh->vertices()) {
250+
EXPECT_LT(v.getIndex(), a.mesh->vertexIndexSize());
251+
if ((v.getIndex() + 1) == a.mesh->vertexIndexSize()) maxSeen = true;
252+
}
253+
EXPECT_TRUE(maxSeen);
254+
}
255+
256+
{ // Halfedges
257+
bool maxSeen = false;
258+
for (Halfedge he : a.mesh->halfedges()) {
259+
EXPECT_LT(he.getIndex(), a.mesh->halfedgeIndexSize());
260+
if ((he.getIndex() + 1) == a.mesh->halfedgeIndexSize()) maxSeen = true;
261+
}
262+
EXPECT_TRUE(maxSeen);
263+
}
264+
265+
{ // Corners
266+
bool maxSeen = false;
267+
for (Corner c : a.mesh->corners()) {
268+
EXPECT_LT(c.getIndex(), a.mesh->cornerIndexSize());
269+
270+
// special case for corners, they have a weaker guarantee and
271+
// cornerIndexSize() may be not-tight by 1
272+
if ((c.getIndex() + 1) == a.mesh->cornerIndexSize()) maxSeen = true;
273+
if ((c.getIndex() + 2) == a.mesh->cornerIndexSize()) maxSeen = true;
274+
}
275+
EXPECT_TRUE(maxSeen);
276+
}
277+
278+
{ // Edges
279+
bool maxSeen = false;
280+
for (Edge e : a.mesh->edges()) {
281+
EXPECT_LT(e.getIndex(), a.mesh->edgeIndexSize());
282+
if ((e.getIndex() + 1) == a.mesh->edgeIndexSize()) maxSeen = true;
283+
}
284+
EXPECT_TRUE(maxSeen);
285+
}
286+
287+
{ // Faces
288+
bool maxSeen = false;
289+
for (Face f : a.mesh->faces()) {
290+
EXPECT_LT(f.getIndex(), a.mesh->faceIndexSize());
291+
if ((f.getIndex() + 1) == a.mesh->faceIndexSize()) maxSeen = true;
292+
}
293+
EXPECT_TRUE(maxSeen);
294+
}
295+
}
296+
}
297+
298+
240299
// ============================================================
241300
// =============== Utility and status functions
242301
// ============================================================
@@ -764,7 +823,6 @@ TEST_F(HalfedgeMeshSuite, EdgeDiamondNavigator) {
764823
}
765824
}
766825

767-
768826
// ============================================================
769827
// =============== Utilities
770828
// ============================================================

0 commit comments

Comments
 (0)