Skip to content

Commit 589fcb8

Browse files
committed
[src] Update methods signature of computeFractureDirection, computeEndPoints and computeEndPointsNeighboringTriangles to avoid multiple call to GetReadAccessor to the positions
1 parent 8b673eb commit 589fcb8

File tree

6 files changed

+48
-58
lines changed

6 files changed

+48
-58
lines changed

src/Tearing/BaseTearingEngine.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ class BaseTearingEngine : public core::DataEngine
125125

126126
virtual void computeFracturePath() = 0;
127127

128-
void computeFractureDirection(const Coord principleStressDirection, Coord& fracture_direction);
128+
Coord computeFractureDirection(const Coord& principleStressDirection);
129129

130130
/// <summary>
131131
/// compute extremities of fracture Pb and Pc from a start point Pa
132132
/// </summary>
133133
/// @param Pa - point with maxStress where fracture start
134-
/// @param direction - direction of maximum principal stress
134+
/// @param fractureDirection - direction of fracture
135135
/// @return Pb - one of the extremities of fracture
136136
/// @return Pc - one of the extremities of fracture
137-
virtual void computeEndPoints(Coord Pa, Coord direction, Coord& Pb, Coord& Pc);
137+
virtual void computeEndPoints(const Coord& Pa, const Coord& fractureDirection, Coord& Pb, Coord& Pc);
138138

139139
/// <summary>
140140
/// compute ignored triangle at start of the tearing algo

src/Tearing/BaseTearingEngine.inl

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -329,19 +329,20 @@ void BaseTearingEngine<DataTypes>::updateTriangleInformation()
329329

330330

331331
template<class DataTypes>
332-
inline void BaseTearingEngine<DataTypes>::computeFractureDirection(const Coord principleStressDirection,Coord & fracture_direction)
332+
typename DataTypes::Coord BaseTearingEngine<DataTypes>::computeFractureDirection(const Coord& principleStressDirection)
333333
{
334+
Coord fracture_direction = { 0.0, 0.0, 0.0 };
335+
334336
if (m_maxStressTriangleIndex == InvalidID) {
335-
fracture_direction = { 0.0, 0.0, 0.0 };
336-
return;
337+
return fracture_direction;
337338
}
338339

339340
const Triangle& VertexIndicies = m_topology->getTriangle(m_maxStressTriangleIndex);
340-
constexpr size_t numVertices = 3;
341341

342-
Index B_id = -1, C_id = -1;
342+
Index B_id = sofa::InvalidID;
343+
Index C_id = sofa::InvalidID;
343344

344-
for (unsigned int vertex_id = 0; vertex_id < numVertices; vertex_id++)
345+
for (sofa::Index vertex_id = 0; vertex_id < 3; vertex_id++)
345346
{
346347
if (VertexIndicies[vertex_id] == m_maxStressVertexIndex)
347348
{
@@ -356,27 +357,22 @@ inline void BaseTearingEngine<DataTypes>::computeFractureDirection(const Coord p
356357
Coord B = x[B_id];
357358
Coord C = x[C_id];
358359

359-
Coord AB = B - A;
360-
Coord AC = C - A;
361-
362-
Coord triangleNormal = sofa::type::cross(AB,AC);
360+
Coord triangleNormal = sofa::type::cross(B - A, C - A);
363361
fracture_direction = sofa::type::cross(triangleNormal, principleStressDirection);
362+
363+
return fracture_direction;
364364
}
365365

366366

367367
template <class DataTypes>
368-
void BaseTearingEngine<DataTypes>::computeEndPoints(
369-
Coord Pa,
370-
Coord direction,
371-
Coord& Pb, Coord& Pc)
368+
void BaseTearingEngine<DataTypes>::computeEndPoints(const Coord& Pa, const Coord& fractureDirection, Coord& Pb, Coord& Pc)
372369
{
373-
Coord fractureDirection;
374-
computeFractureDirection(direction, fractureDirection);
375370
Real norm_fractureDirection = fractureDirection.norm();
376371
Pb = Pa + d_fractureMaxLength.getValue() / norm_fractureDirection * fractureDirection;
377372
Pc = Pa - d_fractureMaxLength.getValue() / norm_fractureDirection * fractureDirection;
378373
}
379374

375+
380376
template <class DataTypes>
381377
void BaseTearingEngine<DataTypes>::computeTriangleToSkip()
382378
{

src/Tearing/TearingEngine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ class TearingEngine : public BaseTearingEngine<DataTypes>
8181
/// computes the extremities of fracture Pb and Pc on the edge of neighboring triangles
8282
/// </summary>
8383
/// @param Pa - the point where the fracture starts
84-
/// @param direction - principle stress direction
84+
/// @param fractureDirection - fracture direction
8585
/// @return Pb - one of the extremities of fracture
8686
/// @return Pc - one of the extremities of fracture
87-
bool computeEndPointsNeighboringTriangles(Coord Pa, Coord direction, Coord& Pb, Coord& Pc);
87+
bool computeEndPointsNeighboringTriangles(const Coord& Pa, const Coord& fractureDirection, Coord& Pb, Coord& Pc);
8888

8989
/// <summary>
9090
/// computes the extremities of the (normalized) fracture PbPa on the edge of the triangle

src/Tearing/TearingEngine.inl

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,13 @@ inline bool TearingEngine<DataTypes>::computeIntersectionNeighborTriangle(Coord
9494
}
9595

9696
template<class DataTypes>
97-
inline bool TearingEngine<DataTypes>::computeEndPointsNeighboringTriangles(Coord Pa, Coord direction, Coord& Pb, Coord& Pc)
97+
inline bool TearingEngine<DataTypes>::computeEndPointsNeighboringTriangles(const Coord& Pa, const Coord& fractureDirection, Coord& Pb, Coord& Pc)
9898
{
9999
bool t_b_ok = false;
100100
bool t_c_ok = false;
101-
//compute fracture direction perpendicular to the principal stress direction
102-
Coord fractureDirection;
103-
this->computeFractureDirection(direction, fractureDirection);
104101

105-
Real norm_fractureDirection = fractureDirection.norm();
106-
Coord dir_b = 1.0 / norm_fractureDirection * fractureDirection;
107-
102+
Coord dir_b = fractureDirection / fractureDirection.norm();
103+
108104
Real t_b;
109105
if (computeIntersectionNeighborTriangle(dir_b,Pa, Pb, t_b))
110106
t_b_ok = true;
@@ -163,33 +159,34 @@ void TearingEngine<DataTypes>::computeFracturePath()
163159
// frist clear ereything
164160
this->clearFracturePath();
165161

166-
if (m_maxStressTriangleIndex != InvalidID) // we have triangle to start and also a vertex id
167-
{
168-
//Recording the endpoints of the fracture segment
169-
helper::ReadAccessor< Data<VecCoord> > x(d_input_positions);
170-
171-
Coord principalStressDirection = m_triangleInfoTearing[m_maxStressTriangleIndex].principalStressDirection;
172-
Coord Pa = x[m_maxStressVertexIndex];
173-
Coord Pb, Pc;
162+
if (m_maxStressTriangleIndex == InvalidID) // no candidate to start fracture
163+
return;
174164

175-
if (this->d_fractureMaxLength.getValue() == 0.0) {
176-
computeEndPointsNeighboringTriangles(Pa, principalStressDirection, Pb, Pc);
177-
}
178-
else
179-
{
180-
this->computeEndPoints(Pa, principalStressDirection, Pb, Pc);
181-
}
165+
//Recording the endpoints of the fracture segment
166+
helper::ReadAccessor< Data<VecCoord> > x(d_input_positions);
182167

183-
this->m_fracturePath.ptA = type::Vec3(Pa[0], Pa[1], Pa[2]);
184-
this->m_fracturePath.ptB = type::Vec3(Pb[0], Pb[1], Pb[2]);
185-
this->m_fracturePath.ptC = type::Vec3(Pc[0], Pc[1], Pc[2]);
186-
this->m_fracturePath.triIdA = m_maxStressTriangleIndex;
168+
const Coord fractureDirection = this->computeFractureDirection(m_triangleInfoTearing[m_maxStressTriangleIndex].principalStressDirection);
187169

188-
this->m_tearingAlgo->computeFracturePath(this->m_fracturePath);
189-
this->m_stepCounter++;
170+
const Coord Pa = x[m_maxStressVertexIndex];
171+
Coord Pb, Pc;
190172

191-
//this->m_tearingAlgo->computeFracturePath(Pa, m_maxStressTriangleIndex, Pb, Pc);
173+
if (this->d_fractureMaxLength.getValue() == 0.0)
174+
{
175+
this->computeEndPointsNeighboringTriangles(Pa, fractureDirection, Pb, Pc);
176+
}
177+
else
178+
{
179+
this->computeEndPoints(Pa, fractureDirection, Pb, Pc); // compute orthogonal fracture using d_fractureMaxLength
192180
}
181+
182+
183+
this->m_fracturePath.ptA = type::Vec3(DataTypes::getCPos(Pa));
184+
this->m_fracturePath.ptB = type::Vec3(DataTypes::getCPos(Pb));
185+
this->m_fracturePath.ptC = type::Vec3(DataTypes::getCPos(Pc));
186+
this->m_fracturePath.triIdA = m_maxStressTriangleIndex;
187+
188+
this->m_tearingAlgo->computeFracturePath(this->m_fracturePath);
189+
this->m_stepCounter++;
193190
}
194191

195192

src/Tearing/TearingScenarioEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class TearingScenarioEngine : public BaseTearingEngine<DataTypes>
7777
void algoFracturePath() override;
7878
void computeFracturePath() override {};
7979

80-
void computeEndPoints(Coord Pa, Coord direction, Coord& Pb, Coord& Pc) override;
80+
void computeEndPoints(const Coord& Pa, const Coord& fractureDirection, Coord& Pb, Coord& Pc) override;
8181

8282
/// Value to store scenario fracture path
8383
Coord m_Pa, m_Pb, m_Pc;

src/Tearing/TearingScenarioEngine.inl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,14 @@ inline void TearingScenarioEngine<DataTypes>::computePerpendicular(Coord dir, Co
106106
}
107107

108108
template <class DataTypes>
109-
void TearingScenarioEngine<DataTypes>::computeEndPoints(
110-
Coord Pa,
111-
Coord dir,
112-
Coord& Pb, Coord& Pc)
109+
void TearingScenarioEngine<DataTypes>::computeEndPoints(const Coord& Pa, const Coord& fractureDirection, Coord& Pb, Coord& Pc)
113110
{
114111
const Real& alpha = d_startLength.getValue();
115112

116-
Real norm_dir = dir.norm();
113+
Real norm_dir = fractureDirection.norm();
117114

118-
Pb = Pa + alpha/norm_dir * dir;
119-
Pc = Pa - alpha /norm_dir * dir;
115+
Pb = Pa + alpha/norm_dir * fractureDirection;
116+
Pc = Pa - alpha /norm_dir * fractureDirection;
120117
}
121118

122119
template <class DataTypes>

0 commit comments

Comments
 (0)