MmgTools / mmg

open source software for bidimensional and tridimensional remeshing
http://www.mmgtools.org
Other
369 stars 118 forks source link

Feature/fix incomplete check #228

Closed Algiane closed 11 months ago

Algiane commented 11 months ago

This PR aims to fix incomplete check of the consistency of edge tag inside tetra

Reminder of Mmg data structures

We don't store the edges in a "unique" way inside an edge array. Instead, each tetra is able to retrieve, for each of its edges, "geometrical" informations (is the edge a reference edge, a non-manifold one, a ridge one...). These informations are stored under the form of binary tags inside a MMG5_xTetra structure:

Thus, for an edge shared by multiple tetras, bugs may lead to inconsistencies (differences) between the tags stored by tetra, while tags should be identical in all the tetra that are sharing the edge as soon as the edge is marked as MG_BDY inside the tetra (boundary edge belonging to a boundary face).

For illustration, on the attached picture, if we suppose that the edge p-q is the $4^{th}$ edge of the tetra number $1$ and the $2^d$ edge of the tetra $2$, as soon as the edge belongs to a boundary face in both tetra (edge marked MG_BDY in both tetra) we should have:

mesh->xtetra[mesh->tetra[1]->xt]->tag[4] == mesh->xtetra[mesh->tetra[2]->xt]->tag[2] 

PR

Debug function MMG3D_chkmeshedgestags

The MMG3D_chkmeshedgestag function is provided for debugging purpose and called by the MMG3D_chkmsh function at the end of the remeshing process (during the mesh packing) when debug mode is enabled (-d command line option).

Incomplete implementation

Initial implementation calls the MMG5_hashEdgeTag function which cumulates the edge tags inside a hash table :

In consequence, if the edge p-q is processed first from the tetra 1 in which it has tag 16 (MG_BDY) then from the tetra 2 in which it has tag 17 (MG_REF & MG_BDY), the implementation in the develop branch fails to detect the lack of consistency. If tetra are processed in reverse order, the inconsistency is detected because we store first the tag 17 in the hash table, then we compare the tag stored inside the xtetra of tetra 2, which is 16 with the value stored in the hash table (17).

Fix

The current PR proposes to replace the call to the MMG5_hashEdgeTag function by a call to the MMG5_hGet function. This function:

It allows to detect inconsistencies independently of the order in which we process the tetra.