Skip to content

Commit 34151a2

Browse files
authored
[algorithm] Fix bug concerning coupling point removal during retraction (#90)
* [operations] Added a namespace for NeedleOperations and a function to remove points ahead of the tip * [operations] Implemented a custom function for removing points based on edge direction * [algorithm] Use custom operation for point removal - avoid dynamic casts to edge element types * [operations] Message warning for empty element pointer or empty coupling points vector * [operations] Wrongly defined return statements in point removal operation * [operations] Fix operation removing only one coupling point per time step * [algorithm] update algorithm logic * [algorithm] Fix crash in case coupling points are all removed and vector is emptied * [operations] Fail-proof while loop with safety counter * [operations] Remove safety counter
1 parent 834531e commit 34151a2

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/CollisionAlgorithm/algorithm/InsertionAlgorithm.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ class InsertionAlgorithm : public BaseAlgorithm
216216
const BaseProximity::SPtr tipProx = createTipProximity(itTip->element());
217217
if (!tipProx) return;
218218

219+
// Remove coupling points that are ahead of the tip in the insertion direction
220+
ElementIterator::SPtr itShaft = l_shaftGeom->begin(l_shaftGeom->getSize() - 2);
221+
auto prunePointsAheadOfTip =
222+
Operations::Needle::PrunePointsAheadOfTip::get(itShaft->getTypeInfo());
223+
prunePointsAheadOfTip(m_couplingPts, itShaft->element());
224+
225+
if (m_couplingPts.empty()) return;
226+
219227
type::Vec3 lastCP = m_couplingPts.back()->getPosition();
220228
const SReal tipDistThreshold = this->d_tipDistThreshold.getValue();
221229

@@ -290,14 +298,6 @@ class InsertionAlgorithm : public BaseAlgorithm
290298
}
291299
}
292300
}
293-
else // Don't bother with removing the point that was just added
294-
{
295-
// Remove coupling points that are ahead of the tip in the insertion direction
296-
ElementIterator::SPtr itShaft = l_shaftGeom->begin(l_shaftGeom->getSize() - 2);
297-
auto prunePointsAheadOfTip =
298-
Operations::Needle::PrunePointsAheadOfTip::get(itShaft->getTypeInfo());
299-
prunePointsAheadOfTip(m_couplingPts, itShaft->element());
300-
}
301301
}
302302

303303
if (!m_couplingPts.empty())

src/CollisionAlgorithm/operations/NeedleOperations.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
1414
}
1515
const type::Vec3 edgeBase(edge->getP0()->getPosition());
1616
const type::Vec3 tip(edge->getP1()->getPosition());
17-
1817
const type::Vec3 edgeDirection = tip - edgeBase;
1918

20-
if (couplingPts.empty()) return true;
21-
const type::Vec3 tip2Pt = couplingPts.back()->getPosition() - tip;
19+
const int initSize = couplingPts.size();
2220

23-
// Positive dot product means the point is ahead of the tip
24-
if (dot(tip2Pt, edgeDirection) > 0_sreal) couplingPts.pop_back();
21+
while(!couplingPts.empty())
22+
{
23+
const type::Vec3 tip2Pt = couplingPts.back()->getPosition() - tip;
2524

26-
return true;
25+
// Negative dot product means the point is behind the tip
26+
if(dot(tip2Pt, edgeDirection) < 0_sreal) break;
27+
couplingPts.pop_back();
28+
}
29+
return (initSize == couplingPts.size());
2730
}
2831

2932
int register_PrunePointsAheadOfTip_Edge =

0 commit comments

Comments
 (0)