@@ -109,60 +109,17 @@ void InsertionAlgorithm::doDetection()
109109 insertionOutput.clear ();
110110 collisionOutput.clear ();
111111
112- if (m_couplingPts.empty () && l_surfGeom )
112+ if (m_couplingPts.empty ())
113113 {
114- // Operations on surface geometry
115- sofa::helper::AdvancedTimer::stepBegin (" Puncture detection - " + this ->getName ());
116-
117- auto findClosestProxOnSurf = Operations::FindClosestProximity::Operation::get (l_surfGeom);
118- auto projectOnSurf = Operations::Project::Operation::get (l_surfGeom);
119-
120114 // Puncture sequence
121- if (d_enablePuncture.getValue () && l_tipGeom)
122- {
123- auto createTipProximity =
124- Operations::CreateCenterProximity::Operation::get (l_tipGeom->getTypeInfo ());
125- auto projectOnTip = Operations::Project::Operation::get (l_tipGeom);
126-
127- const SReal punctureForceThreshold = d_punctureForceThreshold.getValue ();
128- for (auto itTip = l_tipGeom->begin (); itTip != l_tipGeom->end (); itTip++)
129- {
130- BaseProximity::SPtr tipProx = createTipProximity (itTip->element ());
131- if (!tipProx) continue ;
132- const BaseProximity::SPtr surfProx = findClosestProxOnSurf (
133- tipProx, l_surfGeom.get (), projectOnSurf, getFilterFunc ());
134- if (surfProx)
135- {
136- surfProx->normalize ();
137-
138- // Check whether puncture is happening - if so, create coupling point ...
139- if (m_constraintSolver)
140- {
141- const MechStateTipType::SPtr mstate =
142- l_tipGeom->getContext ()->get <MechStateTipType>();
143- const auto & lambda =
144- m_constraintSolver->getLambda ()[mstate.get ()].read ()->getValue ();
145- SReal norm{0_sreal};
146- for (const auto & l : lambda)
147- {
148- norm += l.norm ();
149- }
150- if (norm > punctureForceThreshold)
151- {
152- m_couplingPts.push_back (surfProx);
153- continue ;
154- }
155- }
156-
157- // ... if not, create a proximity pair for the tip-surface collision
158- collisionOutput.add (tipProx, surfProx);
159- }
160- }
161- }
115+ sofa::helper::AdvancedTimer::stepBegin (" Puncture detection - " + this ->getName ());
116+ if (d_enablePuncture.getValue ()) collisionOutput = puncturePhase ();
162117 sofa::helper::AdvancedTimer::stepEnd (" Puncture detection - " + this ->getName ());
163118
164119 // Shaft collision sequence - Disable if coupling points have been added
165120 sofa::helper::AdvancedTimer::stepBegin (" Shaft collision - " + this ->getName ());
121+ auto findClosestProxOnSurf = Operations::FindClosestProximity::Operation::get (l_surfGeom);
122+ auto projectOnSurf = Operations::Project::Operation::get (l_surfGeom);
166123 if (d_enableShaftCollision.getValue () && m_couplingPts.empty () && l_shaftGeom)
167124 {
168125 auto createShaftProximity =
@@ -326,4 +283,54 @@ void InsertionAlgorithm::doDetection()
326283 d_insertionOutput.endEdit ();
327284}
328285
286+ InsertionAlgorithm::AlgorithmOutput InsertionAlgorithm::puncturePhase ()
287+ {
288+ if (!l_tipGeom || !l_surfGeom) return AlgorithmOutput ();
289+
290+ AlgorithmOutput punctureCollisionOutput;
291+
292+ auto findClosestProxOnSurf = Operations::FindClosestProximity::Operation::get (l_surfGeom);
293+ auto projectOnSurf = Operations::Project::Operation::get (l_surfGeom);
294+
295+ auto createTipProximity =
296+ Operations::CreateCenterProximity::Operation::get (l_tipGeom->getTypeInfo ());
297+ auto projectOnTip = Operations::Project::Operation::get (l_tipGeom);
298+
299+ const SReal punctureForceThreshold = d_punctureForceThreshold.getValue ();
300+ for (auto itTip = l_tipGeom->begin (); itTip != l_tipGeom->end (); itTip++)
301+ {
302+ BaseProximity::SPtr tipProx = createTipProximity (itTip->element ());
303+ if (!tipProx) continue ;
304+ const BaseProximity::SPtr surfProx =
305+ findClosestProxOnSurf (tipProx, l_surfGeom.get (), projectOnSurf, getFilterFunc ());
306+ if (surfProx)
307+ {
308+ surfProx->normalize ();
309+
310+ // Check whether puncture is happening - if so, create coupling point ...
311+ if (m_constraintSolver)
312+ {
313+ const MechStateTipType::SPtr mstate =
314+ l_tipGeom->getContext ()->get <MechStateTipType>();
315+ const auto & lambda =
316+ m_constraintSolver->getLambda ()[mstate.get ()].read ()->getValue ();
317+ SReal norm{0_sreal};
318+ for (const auto & l : lambda)
319+ {
320+ norm += l.norm ();
321+ }
322+ if (norm > punctureForceThreshold)
323+ {
324+ m_couplingPts.push_back (surfProx);
325+ continue ;
326+ }
327+ }
328+
329+ // ... if not, create a proximity pair for the tip-surface collision
330+ punctureCollisionOutput.add (tipProx, surfProx);
331+ }
332+ }
333+ return punctureCollisionOutput;
334+ }
335+
329336} // namespace sofa::collisionalgorithm
0 commit comments