geometry-central icon indicating copy to clipboard operation
geometry-central copied to clipboard

Question: Per Element Indices

Open afabri opened this issue 1 year ago • 7 comments

On the page on Elements you write "The routines in this section are valid only when the mesh is compressed"

I guess you mean that the indices are no longer a contiguous sequence. So if I have a large enough std::vector V can I still use the index of a vertex for storing something in V?

Which leads me to the next question: Do you offer a function to get the largest index of vertices, regardless of being marked as removed or not.

afabri avatar Sep 16 '24 08:09 afabri

Yes exactly! (And this is how the container types like VertexData<> are implemented under the hood, lazily resizing only occasionally as a mesh is updated).

Do you offer a function to get the largest index of vertices, regardless of being marked as removed or not.

There are these functions, which give an upper bound: https://github.com/nmwsharp/geometry-central/blob/master/include/geometrycentral/surface/surface_mesh.h#L203-L209 (they are used to set the size of the VertexData<> etc containers). The increase in powers-of-2, so they might be a bit larger than the largest index.

I believe the actual largest index comes from these internal members https://github.com/nmwsharp/geometry-central/blob/master/include/geometrycentral/surface/surface_mesh.h#L306-L323 . I don't believe there are any public-facing functions to access these, but I suppose it could be reasonable to expose them since we expose the raw element indices already. Let me know if that would be useful to you!

nmwsharp avatar Sep 19 '24 05:09 nmwsharp

I am interested in a function of SurfaceMesh that returns vHalfedgeArr.size(). And the same for the other elements. Concerning the doubling, that is the capacity, not the size, right? I mean, in your code, you call reserve() and not resize() to allocate more memory for vertices.

afabri avatar Sep 19 '24 06:09 afabri

It corresponds also to MeshDate<>::size(),

afabri avatar Sep 19 '24 07:09 afabri

I created a PR here that exposes these functions, let me know if I missed anything! https://github.com/nmwsharp/geometry-central/pull/196

nmwsharp avatar Oct 01 '24 06:10 nmwsharp

And regarding the reserve/resize, I believe it is a resize? Here, right? https://github.com/nmwsharp/geometry-central/blob/master/src/surface/surface_mesh.cpp#L1609

(I haven't thought much about this implementation in the last couple years, so I am paging it back into memory)

nmwsharp avatar Oct 01 '24 07:10 nmwsharp

A resize() makes that size() then returns that value. With reserve() the size changes when later you call push_back().

afabri avatar Oct 01 '24 07:10 afabri

I'm familiar with the difference, I was just responding to this comment

in your code, you call reserve() and not resize()

pointing out that at least in the linked location, it is indeed a resize() :smiley: But maybe you were referring to somewhere else.

And FYI I have merged that PR above exposing the max-index getters for SurfaceMesh. Note that for corners they behave slightly differently than might be expected, I also added a note about the differences with corner indexing to the docs.

nmwsharp avatar Oct 02 '24 01:10 nmwsharp