Skip to content

Commit 8b673eb

Browse files
authored
[src] Add new FracturePath structure using new PointToAdd classes (#67)
* Backup work on new fracture path * Backup work on new fracture path with new fracture structure * [src] Backup cleaning * Fix bad merge
1 parent fe848ed commit 8b673eb

6 files changed

Lines changed: 99 additions & 31 deletions

File tree

src/Tearing/BaseTearingEngine.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class BaseTearingEngine : public core::DataEngine
101101
Coord principalStressDirection;
102102
};
103103

104+
105+
106+
104107
/// Link to be set to the topology container in the component graph
105108
SingleLink<BaseTearingEngine<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;
106109

@@ -122,7 +125,7 @@ class BaseTearingEngine : public core::DataEngine
122125

123126
virtual void computeFracturePath() = 0;
124127

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

127130
/// <summary>
128131
/// compute extremities of fracture Pb and Pc from a start point Pa
@@ -169,6 +172,9 @@ class BaseTearingEngine : public core::DataEngine
169172
/// </summary>
170173
void calculate_inverse_distance_weights(std::vector<double>& result, const Index vertex, sofa::type::vector<TriangleID>& ValidTrianglesAround);
171174

175+
176+
void clearFracturePath();
177+
172178
/// Access to the topology for a drived class
173179
sofa::core::topology::BaseMeshTopology* getTopology() const {
174180
return m_topology;
@@ -194,10 +200,8 @@ class BaseTearingEngine : public core::DataEngine
194200
vector<TriangleTearingInformation> m_triangleInfoTearing; ///< vector of TriangleInfo from FEM
195201
int m_stepCounter = 0; ///< counter of doUpdate called by the simulation. Used to put gap between consecutives fractures
196202

197-
/// Fracture segment endpoints
198-
std::vector<Coord> fractureSegmentEndpoints;
199-
200-
203+
/// Vector of pointToAdd due to new fracture
204+
FracturePath m_fracturePath;
201205
};
202206

203207
}//namespace sofa::component::engine

src/Tearing/BaseTearingEngine.inl

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

330330

331331
template<class DataTypes>
332-
inline void BaseTearingEngine<DataTypes>::computeFractureDirection(Coord principleStressDirection,Coord & fracture_direction)
332+
inline void BaseTearingEngine<DataTypes>::computeFractureDirection(const Coord principleStressDirection,Coord & fracture_direction)
333333
{
334334
if (m_maxStressTriangleIndex == InvalidID) {
335335
fracture_direction = { 0.0, 0.0, 0.0 };
@@ -621,6 +621,22 @@ inline void BaseTearingEngine<DataTypes>::calculate_inverse_distance_weights(std
621621

622622

623623

624+
template <class DataTypes>
625+
void BaseTearingEngine<DataTypes>::clearFracturePath()
626+
{
627+
m_fracturePath.ptA = Vec3();
628+
m_fracturePath.ptB = Vec3();
629+
m_fracturePath.ptC = Vec3();
630+
631+
m_fracturePath.triIdA = InvalidID;
632+
m_fracturePath.triIdB = InvalidID;
633+
m_fracturePath.triIdC = InvalidID;
634+
635+
m_fracturePath.pointsToAdd.clear();
636+
m_fracturePath.pathOk = false;
637+
}
638+
639+
624640
template <class DataTypes>
625641
void BaseTearingEngine<DataTypes>::handleEvent(sofa::core::objectmodel::Event* event)
626642
{
@@ -638,15 +654,17 @@ void BaseTearingEngine<DataTypes>::handleEvent(sofa::core::objectmodel::Event* e
638654
return; // We only launch computation at end of a simulation step
639655
}
640656

641-
if (m_tearingAlgo->getFractureNumber() > d_nbFractureMax.getValue())
657+
if (m_tearingAlgo->getFractureNumber() > d_nbFractureMax.getValue()) // reach the end of the engine behavior
642658
return;
643659

644-
computeFracturePath();
645-
646660
// Hack: we access one output value to force the engine to call doUpdate()
647661
if (d_maxStress.getValue() == Real(0.0))
648662
return;
649663

664+
// main method to compute the possible fracture if a triangle has reached threshold
665+
computeFracturePath();
666+
667+
650668
// Perform fracture every d_stepModulo
651669
int step = d_stepModulo.getValue();
652670
if (m_stepCounter > step)
@@ -721,25 +739,18 @@ void BaseTearingEngine<DataTypes>::draw(const core::visual::VisualParams* vparam
721739
}
722740

723741

724-
725-
726-
727742
if (d_showFracturePath.getValue())
728743
{
729-
if (m_maxStressTriangleIndex != InvalidID && fractureSegmentEndpoints.size() == 2)
744+
if (m_maxStressTriangleIndex != InvalidID && m_fracturePath.pathOk)
730745
{
731746
helper::ReadAccessor< Data<VecCoord> > x(d_input_positions);
747+
732748
Coord principalStressDirection = m_triangleInfoTearing[m_maxStressTriangleIndex].principalStressDirection;
733749
Coord Pa = x[m_maxStressVertexIndex];
734-
//Coord fractureDirection;
735-
//computeFractureDirection(principalStressDirection, fractureDirection);
736-
Coord Pb = fractureSegmentEndpoints[0];
737-
Coord Pc = fractureSegmentEndpoints[1];
750+
Coord Pb = m_fracturePath.ptB;
751+
Coord Pc = m_fracturePath.ptC;
738752

739753
vector<Coord> points;
740-
//Real norm_fractureDirection = fractureDirection.norm();
741-
//Coord Pb = Pa + d_fractureMaxLength.getValue() / norm_fractureDirection * fractureDirection;
742-
//Coord Pc = Pa - d_fractureMaxLength.getValue() / norm_fractureDirection * fractureDirection;
743754
points.push_back(Pb);
744755
points.push_back(Pa);
745756
points.push_back(Pa);
@@ -757,11 +768,20 @@ void BaseTearingEngine<DataTypes>::draw(const core::visual::VisualParams* vparam
757768
vparams->drawTool()->drawPoints(pointsDir, 10, sofa::type::RGBAColor(0, 1, 0.2, 1));
758769
vparams->drawTool()->drawLines(pointsDir, 1, sofa::type::RGBAColor(0, 1, 0.5, 1));
759770

760-
points.clear();
771+
std::vector<Vec3> pointsPath;
772+
for (auto ptA : m_fracturePath.pointsToAdd)
773+
{
774+
sofa::type::Vec3 vecG = sofa::type::Vec3(0.0, 0.0, 0.0);
775+
sofa::Size nbr = ptA->m_ancestors.size();
776+
for (int i = 0; i < nbr; ++i)
777+
{
778+
779+
vecG += x[ptA->m_ancestors[i]] * ptA->m_coefs[i];
780+
}
781+
pointsPath.push_back(vecG);
782+
}
783+
vparams->drawTool()->drawSpheres(pointsPath, 0.01, sofa::type::RGBAColor::red());
761784

762-
const vector<Coord>& path = m_tearingAlgo->getFracturePath();
763-
if (!path.empty())
764-
vparams->drawTool()->drawPoints(path, 10, sofa::type::RGBAColor(0, 0.8, 0.2, 1));
765785
}
766786
}
767787
}

src/Tearing/TearingAlgorithms.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,29 @@
2828
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyContainer.h>
2929
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyModifier.h>
3030
#include <sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h>
31+
#include <sofa/component/topology/container/dynamic/TriangleSubdividers.h>
32+
3133

3234

3335
namespace sofa::component
3436
{
3537
using sofa::component::topology::container::dynamic::TriangleSetTopologyModifier;
3638
using sofa::component::topology::container::dynamic::TriangleSetGeometryAlgorithms;
39+
using namespace sofa::component::topology::container::dynamic;
40+
41+
struct FracturePath
42+
{
43+
TriangleID triIdA = InvalidID;
44+
TriangleID triIdB = InvalidID;
45+
TriangleID triIdC = InvalidID;
46+
sofa::type::Vec3 ptA, ptB, ptC;
47+
48+
// full point to add vector
49+
type::vector< std::shared_ptr<PointToAdd> > pointsToAdd;
50+
51+
bool pathOk = false;
52+
};
53+
3754

3855
template <class DataTypes>
3956
class TearingAlgorithms
@@ -55,6 +72,10 @@ class TearingAlgorithms
5572

5673
virtual ~TearingAlgorithms();
5774

75+
void computeFracturePath(FracturePath& my_fracturePath);
76+
77+
void computeFracturePath(const Coord& pA, Index triId, const Coord pB, const Coord pC);
78+
5879
/// <summary>
5980
/// compute fracture path intersection point and cut through them
6081
/// </summary>
@@ -160,6 +181,9 @@ class TearingAlgorithms
160181
/// path created by algoFracturePath
161182
sofa::type::vector<Coord> m_fracturePath;
162183

184+
/// Vector of pointToAdd due to new fracture
185+
type::vector< std::shared_ptr<PointToAdd> > m_pointsToAdd;
186+
163187
};
164188

165189

src/Tearing/TearingAlgorithms.inl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ TearingAlgorithms<DataTypes>::~TearingAlgorithms()
5151
}
5252

5353

54+
template <class DataTypes>
55+
void TearingAlgorithms<DataTypes>::computeFracturePath(const Coord& pA, Index triId, const Coord pB, const Coord pC)
56+
{
57+
58+
}
59+
60+
61+
62+
template <class DataTypes>
63+
void TearingAlgorithms<DataTypes>::computeFracturePath(FracturePath& my_fracturePath)
64+
{
65+
66+
}
67+
68+
69+
5470
template <class DataTypes>
5571
void TearingAlgorithms<DataTypes>::algoFracturePath(Coord Pa, Index indexA, Coord Pb, Coord Pc,
5672
const Index indexTriangleMaxStress, const Coord principalStressDirection, const VecCoord& input_position)

src/Tearing/TearingEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class TearingEngine : public BaseTearingEngine<DataTypes>
7171

7272
using BaseTearingEngine<DataTypes>::d_input_positions;
7373
using BaseTearingEngine<DataTypes>::d_triangleIdsOverThreshold;
74-
using BaseTearingEngine<DataTypes>::fractureSegmentEndpoints;
74+
using BaseTearingEngine<DataTypes>::m_fracturePath;
7575

7676
public:
7777

src/Tearing/TearingEngine.inl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,17 @@ void TearingEngine<DataTypes>::algoFracturePath()
160160
template <class DataTypes>
161161
void TearingEngine<DataTypes>::computeFracturePath()
162162
{
163-
if (m_maxStressTriangleIndex != InvalidID)
163+
// frist clear ereything
164+
this->clearFracturePath();
165+
166+
if (m_maxStressTriangleIndex != InvalidID) // we have triangle to start and also a vertex id
164167
{
165168
//Recording the endpoints of the fracture segment
166169
helper::ReadAccessor< Data<VecCoord> > x(d_input_positions);
167170

168171
Coord principalStressDirection = m_triangleInfoTearing[m_maxStressTriangleIndex].principalStressDirection;
169-
Coord Pa = x[m_maxStressVertexIndex];
170-
172+
Coord Pa = x[m_maxStressVertexIndex];
171173
Coord Pb, Pc;
172-
fractureSegmentEndpoints.clear();
173174

174175
if (this->d_fractureMaxLength.getValue() == 0.0) {
175176
computeEndPointsNeighboringTriangles(Pa, principalStressDirection, Pb, Pc);
@@ -179,9 +180,12 @@ void TearingEngine<DataTypes>::computeFracturePath()
179180
this->computeEndPoints(Pa, principalStressDirection, Pb, Pc);
180181
}
181182

182-
fractureSegmentEndpoints.push_back(Pb);
183-
fractureSegmentEndpoints.push_back(Pc);
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;
184187

188+
this->m_tearingAlgo->computeFracturePath(this->m_fracturePath);
185189
this->m_stepCounter++;
186190

187191
//this->m_tearingAlgo->computeFracturePath(Pa, m_maxStressTriangleIndex, Pb, Pc);

0 commit comments

Comments
 (0)