BrunoLevy / geogram

a programming library with geometric algorithms
Other
1.87k stars 128 forks source link

Improve the halfedges API #116

Open sebmestrallet opened 1 year ago

sebmestrallet commented 1 year ago

Summary

This PR extends the halfedges API without breaking existing functions. The only modified files are src/lib/geogram/mesh/mesh_halfedges.h/.cpp.

Motivation

I need to move on surface meshes and the halfedges API of Geogram allowed me to implement the operators I wanted. But I had several issues:

Because my code relies more and more on halfedges, I plunge into the original class to understand what was already done and to add what I needed. I found that 'next' and 'prev' don't seem to follow the same convention around facets and vertices...

Notes on existing functions

Could be helpful in the wiki

image

image

image

image

image

image

New functions

I hope those modifications are in line with your vision for Geogram.

sebmestrallet commented 1 year ago

Let me know if something should be tweaked. I particular in-code documentation about 'next' and 'prev' whose meaning I must have missed.

I can share the Excalidraw file if it is useful.

sebmestrallet commented 1 year ago

halfedge_movements.webm

Here is a small app (can be appended to the PR) that showcase this behavior:

Maybe prev/next make more sense around facets, but I think (counter)clockwise makes more sense around vertices.

sebmestrallet commented 1 year ago

PLOT TWIST : I still don't understand everything but it seems like I was wrong about the halfedges representation.

image

image

image

image

image

image

Incoming fix

sebmestrallet commented 1 year ago

@BrunoLevy my modifications are now ready for review

Addition:

sebmestrallet commented 12 months ago

There were inconsistencies in the facet normals direction of the meshes I tested (some inward, some outward).

This leads us to a design choice:

BrunoLevy commented 11 months ago

Hi there ! Wow, impressive work and documentation ! It's fantastic ! (sorry for beeing not reactive at all, I was completely swamped in many projects + administrative tasks). About the names of the things, we do not trust orientation, this is why the names of the functions are not "clockwise" and "counterclockwise" because depending on the input mesh, they may be swapped ! And also, consider a non-closed surface, then it depends from which side you look at the surface. Anyway, at any moment if you want to discuss we can plan a videochat (will be easier than exchanging written messages, especially if we need to draw things).

sebmestrallet commented 10 months ago

Now this PR doesn't assume any orientation (3rd design choice of my last message). No more move_(counter)clockwise_around_facet(), move_(counter)clockwise_around_vertex().

In-code documentation

Allow to check if facet regions are defined

🆕 is_using_facet_region()

To be asserted at the beginning of functions receiving a MeshHalfedges and expecting facet regions

Allow to ignore borders when facet regions are used

with a new argument for move_to_*_around_vertex()

Useful when we need to keep track of all the facets between two border segments

Allow sub-classes to access class attributes

privateprotected

Getters for the index of the halfedge's origin/extremity vertices

Currently we can have their 3D coordinates (halfedge_vertex_from() and halfedge_vertex_to()) but not their index.

Because I'm used to the "point" naming from mesh.vertices.point() for coordinates, I wanted to rename existing functions:

But inside, the coordinates getters use Geom::mesh_vertex() from mesh_geometry.h, so it seems "vertex" sometimes means the index, sometimes the coordinates. So, I've chosen:

Getters for both facets

Getters for facet corners