Skip to content

[MeshRepulsionEngine] Add Sofa and cgal intersection detection methods#2

Merged
epernod merged 3 commits into
dev_IT3Dfrom
SOFA_CGAL_Intersection_Detection
Jul 7, 2026
Merged

[MeshRepulsionEngine] Add Sofa and cgal intersection detection methods#2
epernod merged 3 commits into
dev_IT3Dfrom
SOFA_CGAL_Intersection_Detection

Conversation

@FadiWahbeh

Copy link
Copy Markdown

Based on #1

PR 01 — SOFA → CGAL Detection Bridge

Goal

This PR validates the first bridge between SOFA and CGAL inside MeshRepulsionEngine.

The component now:

  • reads masterState, slaveState, masterTopology, and slaveTopology from SOFA;
  • builds a CGAL::Surface_mesh from the SOFA master surface;
  • builds a CGAL::Surface_mesh from the SOFA slave surface for validation/debug;
  • uses CGAL::Side_of_triangle_mesh to classify slave vertices as:
    • inside the master mesh;
    • on the boundary of the master mesh;
    • outside the master mesh;
  • prints diagnostic information in the terminal.

Modify Test Scene

scenes/MeshRepulsion.scn

The scene uses the OBJ files at the paths defined in the MeshOBJLoader components.

Example:

<MeshOBJLoader name="loader" filename="./data/mesh/liver_coarse.obj"/>
<MeshOBJLoader name="loader" filename="./data/mesh/diaphragm.obj"/>

Build

From the SOFA build environment, rebuild the plugin:

"/c/Program Files/CMake/bin/cmake.exe" --build /c/projects/sofa-build --config Release --target CGALPlugin

Run

From the SOFA binary directory:

cd /c/projects/sofa-build/bin/Release 

./runSofa.exe /c/projects/sofa-plugins/CGALPlugin/scenes/MeshRepulsion_PR01.scn

Expected Console Output

When the scene is loaded and/or when the simulation starts, the terminal should show a diagnostic line similar to:

[CGAL detection] step=1 masterVertices=600 masterTriangles=1200 slaveVertices=752 slaveTriangles=1500 inside=112 boundary=0 outside=640 slaveCgalFaces=1500

What This PR Proves

This PR proves that:

  • SOFA links are valid;
  • CGAL can be called from inside MeshRepulsionEngine;
  • the master obstacle can be converted from SOFA topology/positions to a CGAL surface mesh;
  • the slave mesh can also be converted to a CGAL surface mesh for validation/debug;
  • the current slave positions can be acquire from SOFA;
  • slave vertices can be classified as inside, boundary, or outside the master mesh.

Not Included Yet

This PR does not include:

  • vertex displacement;
  • face/edge/sphere collision detection;
  • volumetric .msh slave handling;
  • tetrahedral FEM scene;
  • OBJ export.

Next Step

The next PR will use the CGAL detection result to compute a small smooth displacement for slave vertices detected inside the master mesh.

The objective of PR 02 will be:

CGAL detects inside vertices → compute a small repulsion vector → update slave positions smoothly

@epernod epernod changed the base branch from master to dev_IT3D July 7, 2026 12:09

@epernod epernod left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, just a few small cleaning,
You can apply them in your next PR if you prefer

Comment thread src/CGALPlugin/MeshRepulsionEngine.h Outdated
Comment thread src/CGALPlugin/MeshRepulsionEngine.h Outdated
Comment thread src/CGALPlugin/MeshRepulsionEngine.cpp Outdated
Comment on lines +172 to +174
const auto a = static_cast<std::size_t>(tri[0]);
const auto b = static_cast<std::size_t>(tri[1]);
const auto c = static_cast<std::size_t>(tri[2]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cat are not needed here, Tri is already a triple of [sofa::index] which is similar ui like size_t

Co-authored-by: erik pernod <erik.pernod@gmail.com>
@epernod epernod changed the title [CGAL Intersection Detection] PR Sofa and cgal intersection detection [MeshRepulsionEngine] Add Sofa and cgal intersection detection methods Jul 7, 2026
@epernod epernod merged commit 09029f5 into dev_IT3D Jul 7, 2026
@epernod epernod deleted the SOFA_CGAL_Intersection_Detection branch July 7, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants