Skip to content

[Topology.Mapping] Refactor Hexa2TetraTopologicalMapping to improve readability and add unit tests#5981

Open
alxbilger wants to merge 7 commits intosofa-framework:masterfrom
alxbilger:testhexa2tetra
Open

[Topology.Mapping] Refactor Hexa2TetraTopologicalMapping to improve readability and add unit tests#5981
alxbilger wants to merge 7 commits intosofa-framework:masterfrom
alxbilger:testhexa2tetra

Conversation

@alxbilger
Copy link
Contributor

@alxbilger alxbilger commented Mar 2, 2026

Based on #5947

This PR refactors the Hexa2TetraTopologicalMapping to improve its readability and maintainability. It introduces static arrays for defining tetrahedron patterns and uses loops with these patterns for creating tetrahedra, replacing explicit individual calls. The commit also adds comprehensive unit tests to ensure the correct functionality of the mapping, including edge swapping logic and various grid configurations. These changes aim to make the code more robust and easier to understand.

Here's a list of the main changes:

  • Refactoring of :Hexa2TetraTopologicalMapping.cpp The code has been cleaned up by replacing explicit vertex swapping for X, Y, and Z edges with loops iterating over sofa::geometry::Hexahedron::xEdges, yEdges, and zEdges. The direct addition of tetrahedra has also been refactored to use predefined patterns, improving readability.

  • Introduction of Test Cases: New unit tests have been added in Hexa2TetraTopologicalMapping_test.cpp to cover various aspects of the mapping, including:

    • Handling of invalid inputs.
    • Verification of tetrahedron counts for different grid sizes.
    • Consistency of vertex counts between input hexahedra and output tetrahedra.
    • Testing the swapping parameter.
    • Ensuring tetrahedron vertex indices are valid.
    • Consistency of local-to-global mapping.
    • Specific output verification for single hexahedra with and without swapping.
    • Verification that all tetrahedron vertices belong to their source hexahedron.
    • Checking for degenerate tetrahedra.
  • Enhancements to :Hexahedron.h Static constant arrays (xEdges, yEdges, zEdges) have been added to Hexahedron.h to define the edges along each axis, which are then used in the mapping logic.

[with-all-tests]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@alxbilger alxbilger added pr: status to review To notify reviewers to review this pull-request pr: clean Cleaning the code pr: test PR adding test(s) in SOFA labels Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: clean Cleaning the code pr: status to review To notify reviewers to review this pull-request pr: test PR adding test(s) in SOFA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant