Skip to content

Add progress callback support to upstream MMG library #150

Description

@kmarchais

Summary

Currently, mmgpy's progress reporting only shows phase-level progress (0% at start, 100% at complete) because the underlying MMG library doesn't expose fine-grained progress callbacks. This issue tracks the work needed to propose and implement progress callbacks in the upstream MMG library.

Current Behavior

The progress bar jumps from 0% to 100% instantly when remeshing:

  • Init phase: 0% → 100%
  • Options phase: 0% → 100%
  • Remesh phase: 0% → 100% (entire remeshing happens here, could take minutes for large meshes)

Desired Behavior

Discrete progress updates during the remeshing phase, showing actual algorithm progress:

  • Iteration 1/10: 10%
  • Iteration 2/10: 20%
  • etc.

Technical Feasibility

Analysis of the MMG library source code (mmg3d1_delone.c) shows this is highly feasible:

  1. Main adaptation loop (MMG5_adpdel(), line 642-744) runs up to maxit=10 iterations
  2. Existing progress output at line 715-717 already tracks operations:
    fprintf(stdout,"     %8d filtered, %8d splitted, %8d collapsed,"
            " %8d swapped, %8d moved\n",ifilt,ns,nc,nf,nm);
  3. MMG5_Info structure (libmmgtypes.h, lines 523-564) could be extended to hold callback function pointers

Proposed Changes to MMG Library

  1. Add callback function pointer to MMG5_Info:

    typedef int (*MMG5_progressCallback)(int phase, int iteration, int max_iterations, void* user_data);
    MMG5_progressCallback progressCb;
    void* progressUserData;
  2. Add setter functions in the public API:

    int MMG3D_Set_progressCallback(MMG5_pMesh mesh, MMG5_progressCallback cb, void* user_data);
  3. Call the callback at key points:

    • Before each iteration in MMG5_adpdel()
    • At phase transitions (Analysis → Meshing → Packing)
  4. Allow cancellation via callback return value (non-zero = cancel)

Implementation Steps

  1. Fork/clone MMG repository
  2. Implement callback infrastructure in libmmgtypes.h
  3. Add callback invocations in mmg3d1_delone.c
  4. Create setter functions in libmmg3d.c
  5. Add corresponding functions for mmg2d and mmgs
  6. Test with a simple C program
  7. Submit PR to upstream MMG repository
  8. Update mmgpy bindings once upstream accepts the changes

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions