Skip to content

Add progress callback support for all remeshing modules#324

Open
kmarchais wants to merge 2 commits intoMmgTools:developfrom
kmarchais:feature/progress-callback
Open

Add progress callback support for all remeshing modules#324
kmarchais wants to merge 2 commits intoMmgTools:developfrom
kmarchais:feature/progress-callback

Conversation

@kmarchais
Copy link
Copy Markdown

@kmarchais kmarchais commented Apr 5, 2026

Summary

Add an optional progress callback that allows callers to monitor iteration-level progress during remeshing and to request cooperative cancellation. When no callback is set (the default), there is zero overhead.

API

  • MMG5_progressPhase enum: GEOMETRIC_MESH, COMPUTATIONAL_MESH, ADAPTATION, OPTIMIZATION
  • MMG5_progressCallback typedef: receives phase, iteration index, max iterations, operation counts (splits, collapses, swaps, moves), and user data. Returns 1 to continue, 0 to cancel.
  • Setter functions: MMG3D_Set_progressCallback, MMG2D_Set_progressCallback, MMGS_Set_progressCallback

The callback is instrumented across all three modules (mmg3d, mmg2d, mmgs). Geometric mesh and computational mesh phases use the existing anatet/anatri iterative loops. Adaptation and optimization use their respective loops. All four phases fire in mmg3d and mmgs; mmg2d has no separate optimization phase so only the first three apply.

Note: the MMG5_optbad return value in MMG5_adpdel was previously discarded (pre-existing in develop). Since this PR adds a cancellation path inside MMG5_optbad, the return value is now checked to ensure cancellation propagates immediately.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 5, 2026

CLA assistant check
All committers have signed the CLA.

Add an optional progress callback mechanism that reports iteration-level
progress during mesh adaptation and optimization phases. The callback
enables:

- Two-level progress reporting: phase-level (adaptation vs optimization)
  and iteration-level within each phase
- Per-iteration operation counts: splits, collapses, swaps, and moves
- Cooperative cancellation: return 0 from callback to gracefully abort

API additions:
- MMG5_progressCallback typedef in libmmgtypes.h
- MMG5_progressPhase enum (GEOMETRIC_MESH, COMPUTATIONAL_MESH,
  ADAPTATION, OPTIMIZATION)
- MMG3D_Set_progressCallback(), MMG2D_Set_progressCallback(),
  MMGS_Set_progressCallback() setter functions

Design principles:
- Zero overhead when no callback is set (single NULL pointer check)
- No changes to existing data structures layout or control flow
- Callback is invoked after each iteration, alongside existing fprintf
  progress output
- Non-invasive: all changes are additive, no existing code is modified

Instrumented loops:
- mmg3d: MMG5_adpdel (Delone adaptation), MMG5_adptet (pattern
  adaptation), MMG5_optet/MMG5_optbad/MMG5_optetLES (optimization)
- mmg2d: MMG2D_adptri (adaptation)
- mmgs: adptri (adaptation + optimization)

Includes example programs for all three modules demonstrating progress
display and cancellation.
…urn, cleanup

- Add progress callback invocations in anatet/anatri loops for
  geometric mesh (typchk=1) and computational mesh (typchk=2)
  phases across mmg3d, mmg2d, and mmgs
- Check MMG5_optbad return value in MMG5_adpdel to propagate
  cancellation immediately
- Remove undeclared BUILD_EXAMPLES from CMakeLists.txt
- Remove dead total_max_iterations field from progress_3d example
- Fix MMG3D_Set_progressCallback doc comment
@kmarchais kmarchais force-pushed the feature/progress-callback branch from bd75c98 to 282c297 Compare April 5, 2026 15:46
@kmarchais kmarchais changed the base branch from master to develop April 5, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants