sofa-framework / sofa

Real-time multi-physics simulation with an emphasis on medical simulation.
https://www.sofa-framework.org
GNU Lesser General Public License v2.1
871 stars 297 forks source link

[Collision.Detection] Give current intersection methods as parameter to intersection functions #4583

Closed fredroy closed 1 month ago

fredroy commented 2 months ago

The design of Intersection/Intersector is really "special" in the sense that:

And it was made such as one could add more intersect() method for new primitives for an existing "Intersection", e.g MinProximityIntersection and MeshMinProximityIntersection, which add triangles, etc methods to MinProximityIntersection. Note that even if it is called "Intersection" it is not a "Intersection" 🤪 There is kind of mechanism with a IntersectorCreator/IntersectorFactory which does the "plugin" automatically. The problem is that the intersector gets a pointer to its intersection at the load-time (when the dll is loaded). The intersector needs the intersection to get alarm/contact distance (defined for all Intersection) or custom parameters (useSurfaceNormal for MinProximityIntersection)

Consequence: if there are multiple simulation (in multiple thread) in the same time, a different thread will get a pointer to an other Intersection while doing its intersect code.

In the end, this PR modifies all the intersect/canIntersect functions to get the intersection method (as if they were static functions in reality) and avoid race conditions. The pipeline needs also to be modified.

[The first version of this branch was using a IntersectionParameters storing alarm, contact distance and given as const ref, but it could not handle custom parameters]

Still need to be done:


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

fredroy commented 2 months ago

[ci-build][with-all-tests]

fredroy commented 2 months ago

[ci-build][with-all-tests]

fredroy commented 1 month ago

[ci-build][with-all-tests][force-full-build]