Skip to content

Commit 0fe1f15

Browse files
authored
Merge branch 'master' into add-checks
2 parents 04a5255 + 9f40bff commit 0fe1f15

14 files changed

+219
-149
lines changed
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#include <sofa/collisionAlgorithm/CollisionPipeline.h>
22
#include <sofa/core/ObjectFactory.h>
33

4-
namespace sofa::collisionAlgorithm {
5-
6-
int CollisionLoopClass = core::RegisterObject("CollisionLoop")
7-
.add< CollisionLoop >();
8-
4+
namespace sofa::collisionAlgorithm
5+
{
6+
void registerCollisionLoop(sofa::core::ObjectFactory* factory)
7+
{
8+
factory->registerObjects(
9+
sofa::core::ObjectRegistrationData(
10+
"A collision pipeline customized for proximity detection during needle insertion")
11+
.add<CollisionLoop>());
912
}
13+
} // namespace sofa::collisionAlgorithm
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <sofa/collisionAlgorithm/algorithm/Find2DClosestProximityAlgorithm.h>
22
#include <sofa/core/ObjectFactory.h>
33

4-
namespace sofa::collisionAlgorithm {
5-
6-
int Find2DClosestProximityAlgorithmClass = core::RegisterObject("Find2DClosestProximityAlgorithm")
7-
.add< Find2DClosestProximityAlgorithm >();
8-
9-
4+
namespace sofa::collisionAlgorithm
5+
{
6+
void registerFind2DClosestProximityAlgorithm(sofa::core::ObjectFactory* factory)
7+
{
8+
factory->registerObjects(
9+
sofa::core::ObjectRegistrationData(
10+
"An algorithm to find the closest proximity between two BaseGeometry types in 2D")
11+
.add<Find2DClosestProximityAlgorithm>());
1012
}
11-
12-
13-
13+
} // namespace sofa::collisionAlgorithm
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <sofa/collisionAlgorithm/algorithm/FindClosestProximityAlgorithm.h>
22
#include <sofa/core/ObjectFactory.h>
33

4-
namespace sofa::collisionAlgorithm {
5-
6-
int FindClosestProximityAlgorithmClass = core::RegisterObject("FindClosestProximityAlgorithm")
7-
.add< FindClosestProximityAlgorithm >();
8-
9-
4+
namespace sofa::collisionAlgorithm
5+
{
6+
void registerFindClosestProximityAlgorithm(sofa::core::ObjectFactory* factory)
7+
{
8+
factory->registerObjects(
9+
sofa::core::ObjectRegistrationData(
10+
"An algorithm to find the closest proximity between two BaseGeometry types")
11+
.add<FindClosestProximityAlgorithm>());
1012
}
11-
12-
13-
13+
} // namespace sofa::collisionAlgorithm
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include <sofa/collisionAlgorithm/algorithm/InsertionAlgorithm.h>
22
#include <sofa/core/ObjectFactory.h>
33

4-
namespace sofa::collisionAlgorithm {
5-
6-
int InsertionAlgorithmClass = core::RegisterObject("InsertionAlgorithm")
7-
.add< InsertionAlgorithm >();
8-
9-
4+
namespace sofa::collisionAlgorithm
5+
{
6+
void registerInsertionAlgorithm(sofa::core::ObjectFactory* factory)
7+
{
8+
factory->registerObjects(sofa::core::ObjectRegistrationData(
9+
"A class implementing a customized needle insertion algorithm")
10+
.add<InsertionAlgorithm>());
1011
}
11-
12-
13-
12+
} // namespace sofa::collisionAlgorithm

src/sofa/collisionAlgorithm/algorithm/InsertionAlgorithm.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <sofa/collisionAlgorithm/operations/FindClosestProximity.h>
88
#include <sofa/collisionAlgorithm/operations/Project.h>
99
#include <sofa/collisionAlgorithm/proximity/EdgeProximity.h>
10+
#include <sofa/collisionAlgorithm/proximity/TetrahedronProximity.h>
1011
#include <sofa/component/constraint/lagrangian/solver/ConstraintSolverImpl.h>
1112
#include <sofa/component/statecontainer/MechanicalObject.h>
1213

@@ -15,7 +16,7 @@ namespace sofa::collisionAlgorithm
1516

1617
class InsertionAlgorithm : public BaseAlgorithm
1718
{
18-
public:
19+
public:
1920
SOFA_CLASS(InsertionAlgorithm, BaseAlgorithm);
2021

2122
typedef core::behavior::MechanicalState<defaulttype::Vec3Types> MechStateTipType;
@@ -223,10 +224,25 @@ class InsertionAlgorithm : public BaseAlgorithm
223224
auto projectOnVol = Operations::Project::Operation::get(l_volGeom);
224225
const BaseProximity::SPtr volProx =
225226
findClosestProxOnVol(tipProx, l_volGeom.get(), projectOnVol, getFilterFunc());
227+
// Proximity can be detected before the tip enters the tetra (e.g. near a boundary face)
228+
// Only accept proximities if the tip is inside the tetra during insertion
226229
if (volProx)
227230
{
228-
volProx->normalize();
229-
m_couplingPts.push_back(volProx);
231+
TetrahedronProximity::SPtr tetProx =
232+
dynamic_pointer_cast<TetrahedronProximity>(volProx);
233+
if (tetProx)
234+
{
235+
double f0(tetProx->f0()), f1(tetProx->f1()), f2(tetProx->f2()),
236+
f3(tetProx->f3());
237+
bool isInTetra = toolbox::TetrahedronToolBox::isInTetra(
238+
tipProx->getPosition(), tetProx->element()->getTetrahedronInfo(), f0,
239+
f1, f2, f3);
240+
if (isInTetra)
241+
{
242+
volProx->normalize();
243+
m_couplingPts.push_back(volProx);
244+
}
245+
}
230246
}
231247
}
232248
else // Don't bother with removing the point that was just added
@@ -245,6 +261,8 @@ class InsertionAlgorithm : public BaseAlgorithm
245261
const type::Vec3 normal = (edgeProx->element()->getP1()->getPosition() -
246262
edgeProx->element()->getP0()->getPosition())
247263
.normalized();
264+
// If the (last) coupling point lies ahead of the tip (positive dot product),
265+
// the needle is retreating. Thus, that point is removed.
248266
if (dot(tip2Pt, normal) > 0_sreal)
249267
{
250268
m_couplingPts.pop_back();
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#include <sofa/collisionAlgorithm/broadphase/AABBBroadPhase.h>
22
#include <sofa/core/ObjectFactory.h>
33

4-
namespace sofa::collisionAlgorithm {
5-
6-
int AABBBroadPhaseClass = core::RegisterObject(R"(
7-
**AABBBroadPhase** is a real-time collision detection component that uses the Axis-Aligned Bounding Box (AABB) approach for broad-phase collision handling.
8-
9-
It organizes elements into a 3D spatial grid, efficiently indexing and retrieving them to identify potential collisions, optimizing the process of narrowing down collision checks for more precise detection in 3D simulations.
10-
)")
11-
.add< AABBBroadPhase >();
4+
namespace sofa::collisionAlgorithm
5+
{
6+
void registerAABBBroadPhase(sofa::core::ObjectFactory* factory)
7+
{
8+
factory->registerObjects(sofa::core::ObjectRegistrationData(R"(
9+
**AABBBroadPhase** is a real-time collision detection component that uses the
10+
Axis-Aligned Bounding Box (AABB) approach for broad-phase collision handling.
1211
12+
It organizes elements into a 3D spatial grid, efficiently indexing and retrieving them
13+
to identify potential collisions, optimizing the process of narrowing down collision
14+
checks for more precise detection in 3D simulations.
15+
)")
16+
.add<AABBBroadPhase>());
1317
}
18+
} // namespace sofa::collisionAlgorithm
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include <sofa/collisionAlgorithm/broadphase/FullAABBBroadPhase.h>
22
#include <sofa/core/ObjectFactory.h>
33

4-
namespace sofa::collisionAlgorithm {
5-
6-
int FullAABBBroadPhaseClass = core::RegisterObject("FullAABBBroadPhase")
7-
.add< FullAABBBroadPhase >();
8-
4+
namespace sofa::collisionAlgorithm
5+
{
6+
void registerFullAABBBroadPhase(sofa::core::ObjectFactory* factory)
7+
{
8+
factory->registerObjects(sofa::core::ObjectRegistrationData("").add<FullAABBBroadPhase>());
99
}
10+
} // namespace sofa::collisionAlgorithm
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#include <sofa/collisionAlgorithm/filters/DistanceFilter.h>
22
#include <sofa/core/ObjectFactory.h>
33

4-
namespace sofa::collisionAlgorithm {
5-
6-
int DistanceFilterClass = core::RegisterObject("DistanceFilter")
7-
.add< DistanceFilter >();
8-
4+
namespace sofa::collisionAlgorithm
5+
{
6+
void registerDistanceFilter(sofa::core::ObjectFactory* factory)
7+
{
8+
factory->registerObjects(
9+
sofa::core::ObjectRegistrationData(
10+
"This class filters detected proximities based on their distance from source")
11+
.add<DistanceFilter>());
912
}
13+
} // namespace sofa::collisionAlgorithm
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <sofa/collisionAlgorithm/geometry/EdgeGeometry.h>
22
#include <sofa/core/ObjectFactory.h>
33

4-
namespace sofa {
5-
6-
namespace collisionAlgorithm {
7-
8-
int EdgeGeometryClass = core::RegisterObject("EdgeGeometry")
9-
.add< EdgeGeometry<sofa::defaulttype::Vec3dTypes> >();
10-
11-
}
12-
4+
namespace sofa::collisionAlgorithm
5+
{
6+
void registerEdgeGeometry(sofa::core::ObjectFactory* factory)
7+
{
8+
factory->registerObjects(
9+
sofa::core::ObjectRegistrationData(
10+
"A class bridging edge topological information with the proximity detection algorithm")
11+
.add<EdgeGeometry<sofa::defaulttype::Vec3dTypes> >());
1312
}
13+
} // namespace sofa::collisionAlgorithm
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#include <sofa/collisionAlgorithm/geometry/PointGeometry.h>
22
#include <sofa/core/ObjectFactory.h>
33

4-
namespace sofa {
5-
6-
namespace collisionAlgorithm {
7-
8-
int PointGeometryClass = core::RegisterObject("PointGeometry")
9-
.add< PointGeometry<sofa::defaulttype::Vec3dTypes> >();
10-
4+
namespace sofa::collisionAlgorithm
5+
{
6+
void registerPointGeometry(sofa::core::ObjectFactory* factory)
7+
{
8+
factory->registerObjects(
9+
sofa::core::ObjectRegistrationData(
10+
"A class bridging point topological information with the proximity detection algorithm")
11+
.add<PointGeometry<sofa::defaulttype::Vec3dTypes> >());
1112
}
12-
13-
}
14-
15-
13+
} // namespace sofa::collisionAlgorithm

0 commit comments

Comments
 (0)