Skip to content

Commit aba6c42

Browse files
committed
[algorithm] Add a proximity and then check for puncture + small clean & rework
1 parent 9423090 commit aba6c42

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

src/sofa/collisionAlgorithm/algorithm/InsertionAlgorithm.h

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -122,37 +122,11 @@ class InsertionAlgorithm : public BaseAlgorithm
122122
auto& insertionOutput = *d_insertionOutput.beginEdit();
123123

124124
insertionOutput.clear();
125+
collisionOutput.clear();
125126

126127
if (m_couplingPts.empty())
127128
{
128-
const MechStateTipType::SPtr mstate = l_tipGeom->getContext()->get<MechStateTipType>();
129-
if (m_constraintSolver)
130-
{
131-
const auto& lambda =
132-
m_constraintSolver->getLambda()[mstate.get()].read()->getValue();
133-
SReal norm{0.};
134-
for (const auto& l : lambda) norm += l.norm();
135-
if (norm > d_punctureForceThreshold.getValue())
136-
{
137-
auto findClosestProxOnShaft =
138-
Operations::FindClosestProximity::Operation::get(l_shaftGeom);
139-
auto projectOnShaft = Operations::Project::Operation::get(l_shaftGeom);
140-
for (const auto& dpair : collisionOutput)
141-
{
142-
// Reproject onto the needle to create an EdgeProximity - the
143-
// EdgeNormalHandler in the Constraint classes will need this
144-
const BaseProximity::SPtr shaftProx = findClosestProxOnShaft(
145-
dpair.second, l_shaftGeom.get(), projectOnShaft, getFilterFunc());
146-
m_couplingPts.push_back(dpair.second);
147-
insertionOutput.add(shaftProx, dpair.second);
148-
}
149-
collisionOutput.clear();
150-
return;
151-
}
152-
}
153-
154-
collisionOutput.clear();
155-
129+
// 1. Puncture algorithm
156130
auto createTipProximity =
157131
Operations::CreateCenterProximity::Operation::get(l_tipGeom->getTypeInfo());
158132
auto findClosestProxOnSurf =
@@ -169,6 +143,24 @@ class InsertionAlgorithm : public BaseAlgorithm
169143
if (surfProx)
170144
{
171145
surfProx->normalize();
146+
147+
// 1.1 Check whether puncture is happening - if so, create coupling point
148+
if (m_constraintSolver)
149+
{
150+
const MechStateTipType::SPtr mstate =
151+
l_tipGeom->getContext()->get<MechStateTipType>();
152+
const auto& lambda =
153+
m_constraintSolver->getLambda()[mstate.get()].read()->getValue();
154+
SReal norm{0.};
155+
for (const auto& l : lambda) norm += l.norm();
156+
if (norm > d_punctureForceThreshold.getValue())
157+
{
158+
m_couplingPts.push_back(surfProx);
159+
continue;
160+
}
161+
}
162+
163+
// 1.2 If not, create a proximity pair for the tip-surface collision
172164
if (d_projective.getValue())
173165
{
174166
tipProx = projectOnTip(surfProx->getPosition(), itTip.element()).prox;
@@ -181,11 +173,13 @@ class InsertionAlgorithm : public BaseAlgorithm
181173
}
182174
else
183175
{
176+
// 2. Needle insertion algorithm
184177
ElementIterator::SPtr itTip = l_tipGeom->begin();
185178
auto createTipProximity =
186179
Operations::CreateCenterProximity::Operation::get(itTip->getTypeInfo());
187180
const BaseProximity::SPtr tipProx = createTipProximity(itTip->element());
188181

182+
// 2.1 Check whether coupling point should be added
189183
const type::Vec3 tip2Pt = m_couplingPts.back()->getPosition() - tipProx->getPosition();
190184
if (tip2Pt.norm() > d_tipDistThreshold.getValue())
191185
{
@@ -202,6 +196,7 @@ class InsertionAlgorithm : public BaseAlgorithm
202196
}
203197
else // Don't bother with removing the point that was just added
204198
{
199+
// 2.2. Check whether coupling point should be removed
205200
ElementIterator::SPtr itShaft = l_shaftGeom->begin(l_shaftGeom->getSize() - 2);
206201
auto createShaftProximity =
207202
Operations::CreateCenterProximity::Operation::get(itShaft->getTypeInfo());
@@ -212,7 +207,11 @@ class InsertionAlgorithm : public BaseAlgorithm
212207
.normalized();
213208
if (dot(tip2Pt, normal) > 0.0) m_couplingPts.pop_back();
214209
}
210+
}
215211

212+
if (!m_couplingPts.empty())
213+
{
214+
// 3. Re-project proximities on the shaft geometry
216215
auto findClosestProxOnShaft =
217216
Operations::FindClosestProximity::Operation::get(l_shaftGeom);
218217
auto projectOnShaft = Operations::Project::Operation::get(l_shaftGeom);

0 commit comments

Comments
 (0)