Skip to content

Commit 190f21a

Browse files
committed
[algorithm] Leave some space in code lines
1 parent 3c9cd8a commit 190f21a

File tree

1 file changed

+55
-27
lines changed

1 file changed

+55
-27
lines changed

src/CollisionAlgorithm/algorithm/InsertionAlgorithm.cpp

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,34 @@ void InsertionAlgorithm::doDetection()
113113
{
114114
// Puncture sequence
115115
sofa::helper::AdvancedTimer::stepBegin("Puncture detection - " + this->getName());
116+
116117
if (d_enablePuncture.getValue()) collisionOutput = puncturePhase();
118+
117119
sofa::helper::AdvancedTimer::stepEnd("Puncture detection - " + this->getName());
118120

119121
// Shaft collision sequence - Disable if coupling points have been added
120122
sofa::helper::AdvancedTimer::stepBegin("Shaft collision - " + this->getName());
123+
121124
if (d_enableShaftCollision.getValue() && m_couplingPts.empty())
122125
collisionOutput.add(shaftCollisionPhase());
126+
123127
sofa::helper::AdvancedTimer::stepEnd("Shaft collision - " + this->getName());
124128
}
125129
else
126130
{
127131
// Insertion sequence
128132
sofa::helper::AdvancedTimer::stepBegin("Needle insertion - " + this->getName());
133+
129134
if (d_enableInsertion.getValue()) insertionPhase();
135+
130136
sofa::helper::AdvancedTimer::stepEnd("Needle insertion - " + this->getName());
131137
}
132138

139+
// Reprojection phase
133140
sofa::helper::AdvancedTimer::stepBegin("Reproject coupling points - " + this->getName());
141+
134142
if (d_enableInsertion.getValue()) insertionOutput = reprojectCouplingPoints();
143+
135144
sofa::helper::AdvancedTimer::stepEnd("Reproject coupling points - " + this->getName());
136145

137146
d_collisionOutput.endEdit();
@@ -144,9 +153,9 @@ InsertionAlgorithm::AlgorithmOutput InsertionAlgorithm::puncturePhase()
144153

145154
AlgorithmOutput punctureCollisionOutput;
146155

156+
// Prepare operations before entering loop
147157
auto findClosestProxOnSurf = Operations::FindClosestProximity::Operation::get(l_surfGeom);
148158
auto projectOnSurf = Operations::Project::Operation::get(l_surfGeom);
149-
150159
auto createTipProximity =
151160
Operations::CreateCenterProximity::Operation::get(l_tipGeom->getTypeInfo());
152161
auto projectOnTip = Operations::Project::Operation::get(l_tipGeom);
@@ -155,7 +164,9 @@ InsertionAlgorithm::AlgorithmOutput InsertionAlgorithm::puncturePhase()
155164
for (auto itTip = l_tipGeom->begin(); itTip != l_tipGeom->end(); itTip++)
156165
{
157166
BaseProximity::SPtr tipProx = createTipProximity(itTip->element());
167+
158168
if (!tipProx) continue;
169+
159170
const BaseProximity::SPtr surfProx =
160171
findClosestProxOnSurf(tipProx, l_surfGeom.get(), projectOnSurf, getFilterFunc());
161172
if (surfProx)
@@ -170,10 +181,12 @@ InsertionAlgorithm::AlgorithmOutput InsertionAlgorithm::puncturePhase()
170181
const auto& lambda =
171182
m_constraintSolver->getLambda()[mstate.get()].read()->getValue();
172183
SReal norm{0_sreal};
184+
173185
for (const auto& l : lambda)
174186
{
175187
norm += l.norm();
176188
}
189+
177190
if (norm > punctureForceThreshold)
178191
{
179192
m_couplingPts.push_back(surfProx);
@@ -194,38 +207,44 @@ InsertionAlgorithm::AlgorithmOutput InsertionAlgorithm::shaftCollisionPhase()
194207

195208
AlgorithmOutput shaftCollisionOutput;
196209

210+
// Prepare operations before entering loop
197211
auto findClosestProxOnSurf = Operations::FindClosestProximity::Operation::get(l_surfGeom);
198212
auto projectOnSurf = Operations::Project::Operation::get(l_surfGeom);
213+
auto createShaftProximity =
214+
Operations::CreateCenterProximity::Operation::get(l_shaftGeom->getTypeInfo());
215+
auto projectOnShaft = Operations::Project::Operation::get(l_shaftGeom);
216+
217+
for (auto itShaft = l_shaftGeom->begin(); itShaft != l_shaftGeom->end(); itShaft++)
199218
{
200-
auto createShaftProximity =
201-
Operations::CreateCenterProximity::Operation::get(l_shaftGeom->getTypeInfo());
202-
auto projectOnShaft = Operations::Project::Operation::get(l_shaftGeom);
203-
for (auto itShaft = l_shaftGeom->begin(); itShaft != l_shaftGeom->end(); itShaft++)
219+
BaseProximity::SPtr shaftProx = createShaftProximity(itShaft->element());
220+
221+
if (!shaftProx) continue;
222+
223+
const BaseProximity::SPtr surfProx =
224+
findClosestProxOnSurf(shaftProx, l_surfGeom.get(), projectOnSurf, getFilterFunc());
225+
226+
if (surfProx)
204227
{
205-
BaseProximity::SPtr shaftProx = createShaftProximity(itShaft->element());
206-
if (!shaftProx) continue;
207-
const BaseProximity::SPtr surfProx =
208-
findClosestProxOnSurf(shaftProx, l_surfGeom.get(), projectOnSurf, getFilterFunc());
209-
if (surfProx)
228+
surfProx->normalize();
229+
230+
if (d_projective.getValue())
210231
{
211-
surfProx->normalize();
232+
// shaftProx =
233+
// projectOnShaft(surfProx->getPosition(), itShaft->element()).prox;
234+
// if (!shaftProx) continue;
235+
// shaftProx->normalize();
212236

213-
if (d_projective.getValue())
214-
{
215-
// shaftProx =
216-
// projectOnShaft(surfProx->getPosition(), itShaft->element()).prox;
217-
// if (!shaftProx) continue;
218-
// shaftProx->normalize();
219-
// Experimental - This enables projection anywhere on the edge
220-
auto findClosestProxOnShaft =
221-
Operations::FindClosestProximity::Operation::get(l_shaftGeom);
222-
shaftProx = findClosestProxOnShaft(surfProx, l_shaftGeom, projectOnShaft,
223-
getFilterFunc());
224-
if (!shaftProx) continue;
225-
shaftProx->normalize();
226-
}
227-
shaftCollisionOutput.add(shaftProx, surfProx);
237+
// Experimental - This enables projection anywhere on the edge
238+
auto findClosestProxOnShaft =
239+
Operations::FindClosestProximity::Operation::get(l_shaftGeom);
240+
shaftProx =
241+
findClosestProxOnShaft(surfProx, l_shaftGeom, projectOnShaft, getFilterFunc());
242+
243+
if (!shaftProx) continue;
244+
245+
shaftProx->normalize();
228246
}
247+
shaftCollisionOutput.add(shaftProx, surfProx);
229248
}
230249
}
231250
return shaftCollisionOutput;
@@ -239,6 +258,7 @@ void InsertionAlgorithm::insertionPhase()
239258
auto createTipProximity =
240259
Operations::CreateCenterProximity::Operation::get(itTip->getTypeInfo());
241260
const BaseProximity::SPtr tipProx = createTipProximity(itTip->element());
261+
242262
if (!tipProx) return;
243263

244264
// Remove coupling points that are ahead of the tip in the insertion direction
@@ -258,7 +278,7 @@ void InsertionAlgorithm::insertionPhase()
258278
// Only add a new coupling point if the needle tip has advanced far enough
259279
if (tipToLastCP.norm() > tipDistThreshold)
260280
{
261-
// Prepare the operations before entering the loop
281+
// Prepare operations before entering loop
262282
auto createShaftProximity =
263283
Operations::CreateCenterProximity::Operation::get(l_shaftGeom->getTypeInfo());
264284
auto projectOnShaft = Operations::Project::Operation::get(l_shaftGeom);
@@ -270,9 +290,11 @@ void InsertionAlgorithm::insertionPhase()
270290
for (auto itShaft = l_shaftGeom->begin(); itShaft != l_shaftGeom->end(); itShaft++)
271291
{
272292
BaseProximity::SPtr shaftProx = createShaftProximity(itShaft->element());
293+
273294
if (!shaftProx) continue;
274295

275296
const EdgeProximity::SPtr edgeProx = dynamic_pointer_cast<EdgeProximity>(shaftProx);
297+
276298
if (!edgeProx) continue;
277299

278300
const type::Vec3 p0 = edgeProx->element()->getP0()->getPosition();
@@ -301,11 +323,13 @@ void InsertionAlgorithm::insertionPhase()
301323

302324
// Project candidate CP onto shaft geometry ...
303325
shaftProx = projectOnShaft(candidateCP, itShaft->element()).prox;
326+
304327
if (!shaftProx) continue;
305328

306329
// ... then find nearest volume proximity
307330
const BaseProximity::SPtr volProx =
308331
findClosestProxOnVol(shaftProx, l_volGeom.get(), projectOnVol, getFilterFunc());
332+
309333
if (!volProx) continue;
310334

311335
// Proximity can be detected before the tip enters the tetra (e.g. near a
@@ -339,14 +363,18 @@ InsertionAlgorithm::AlgorithmOutput InsertionAlgorithm::reprojectCouplingPoints(
339363
// Reprojection on shaft geometry sequence
340364
auto findClosestProxOnShaft = Operations::FindClosestProximity::Operation::get(l_shaftGeom);
341365
auto projectOnShaft = Operations::Project::Operation::get(l_shaftGeom);
366+
342367
for (const auto& cp : m_couplingPts)
343368
{
344369
const BaseProximity::SPtr shaftProx =
345370
findClosestProxOnShaft(cp, l_shaftGeom.get(), projectOnShaft, getFilterFunc());
371+
346372
if (!shaftProx) continue;
373+
347374
shaftProx->normalize();
348375
reprojectionOutput.add(shaftProx, cp);
349376
}
377+
350378
// This is a final-frontier check: If there are coupling points stored, but the
351379
// findClosestProxOnShaf operation yields no proximities on the shaft, it could be
352380
// because the needle has exited abruptly. Thus, we clear the coupling points.

0 commit comments

Comments
 (0)