@@ -118,40 +118,10 @@ void InsertionAlgorithm::doDetection()
118118
119119 // Shaft collision sequence - Disable if coupling points have been added
120120 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);
123- if (d_enableShaftCollision.getValue () && m_couplingPts.empty () && l_shaftGeom)
121+ if (d_enableShaftCollision.getValue () && m_couplingPts.empty ())
124122 {
125- auto createShaftProximity =
126- Operations::CreateCenterProximity::Operation::get (l_shaftGeom->getTypeInfo ());
127- auto projectOnShaft = Operations::Project::Operation::get (l_shaftGeom);
128- for (auto itShaft = l_shaftGeom->begin (); itShaft != l_shaftGeom->end (); itShaft++)
129- {
130- BaseProximity::SPtr shaftProx = createShaftProximity (itShaft->element ());
131- if (!shaftProx) continue ;
132- const BaseProximity::SPtr surfProx = findClosestProxOnSurf (
133- shaftProx, l_surfGeom.get (), projectOnSurf, getFilterFunc ());
134- if (surfProx)
135- {
136- surfProx->normalize ();
137-
138- if (d_projective.getValue ())
139- {
140- // shaftProx =
141- // projectOnShaft(surfProx->getPosition(), itShaft->element()).prox;
142- // if (!shaftProx) continue;
143- // shaftProx->normalize();
144- // Experimental - This enables projection anywhere on the edge
145- auto findClosestProxOnShaft =
146- Operations::FindClosestProximity::Operation::get (l_shaftGeom);
147- shaftProx = findClosestProxOnShaft (surfProx, l_shaftGeom, projectOnShaft,
148- getFilterFunc ());
149- if (!shaftProx) continue ;
150- shaftProx->normalize ();
151- }
152- collisionOutput.add (shaftProx, surfProx);
153- }
154- }
123+ AlgorithmOutput shaftCollisions = shaftCollisionPhase ();
124+ for (auto & it : shaftCollisions) collisionOutput.add (it.first , it.second );
155125 }
156126 sofa::helper::AdvancedTimer::stepEnd (" Shaft collision - " + this ->getName ());
157127 }
@@ -333,4 +303,47 @@ InsertionAlgorithm::AlgorithmOutput InsertionAlgorithm::puncturePhase()
333303 return punctureCollisionOutput;
334304}
335305
306+ InsertionAlgorithm::AlgorithmOutput InsertionAlgorithm::shaftCollisionPhase ()
307+ {
308+ if (!l_shaftGeom || !l_surfGeom) return AlgorithmOutput ();
309+
310+ AlgorithmOutput shaftCollisionOutput;
311+
312+ auto findClosestProxOnSurf = Operations::FindClosestProximity::Operation::get (l_surfGeom);
313+ auto projectOnSurf = Operations::Project::Operation::get (l_surfGeom);
314+ {
315+ auto createShaftProximity =
316+ Operations::CreateCenterProximity::Operation::get (l_shaftGeom->getTypeInfo ());
317+ auto projectOnShaft = Operations::Project::Operation::get (l_shaftGeom);
318+ for (auto itShaft = l_shaftGeom->begin (); itShaft != l_shaftGeom->end (); itShaft++)
319+ {
320+ BaseProximity::SPtr shaftProx = createShaftProximity (itShaft->element ());
321+ if (!shaftProx) continue ;
322+ const BaseProximity::SPtr surfProx =
323+ findClosestProxOnSurf (shaftProx, l_surfGeom.get (), projectOnSurf, getFilterFunc ());
324+ if (surfProx)
325+ {
326+ surfProx->normalize ();
327+
328+ if (d_projective.getValue ())
329+ {
330+ // shaftProx =
331+ // projectOnShaft(surfProx->getPosition(), itShaft->element()).prox;
332+ // if (!shaftProx) continue;
333+ // shaftProx->normalize();
334+ // Experimental - This enables projection anywhere on the edge
335+ auto findClosestProxOnShaft =
336+ Operations::FindClosestProximity::Operation::get (l_shaftGeom);
337+ shaftProx = findClosestProxOnShaft (surfProx, l_shaftGeom, projectOnShaft,
338+ getFilterFunc ());
339+ if (!shaftProx) continue ;
340+ shaftProx->normalize ();
341+ }
342+ shaftCollisionOutput.add (shaftProx, surfProx);
343+ }
344+ }
345+ }
346+ return shaftCollisionOutput;
347+ }
348+
336349} // namespace sofa::collisionalgorithm
0 commit comments