Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Tearing/BaseTearingEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class BaseTearingEngine : public core::DataEngine
Coord principalStressDirection;
};




/// Link to be set to the topology container in the component graph
SingleLink<BaseTearingEngine<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;

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

virtual void computeFracturePath() = 0;

void computeFractureDirection(Coord principleStressDirection, Coord& fracture_direction);
void computeFractureDirection(const Coord principleStressDirection, Coord& fracture_direction);

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


void clearFracturePath();

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

/// Fracture segment endpoints
std::vector<Coord> fractureSegmentEndpoints;


/// Vector of pointToAdd due to new fracture
FracturePath m_fracturePath;
};

}//namespace sofa::component::engine
58 changes: 39 additions & 19 deletions src/Tearing/BaseTearingEngine.inl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void BaseTearingEngine<DataTypes>::updateTriangleInformation()


template<class DataTypes>
inline void BaseTearingEngine<DataTypes>::computeFractureDirection(Coord principleStressDirection,Coord & fracture_direction)
inline void BaseTearingEngine<DataTypes>::computeFractureDirection(const Coord principleStressDirection,Coord & fracture_direction)
{
if (m_maxStressTriangleIndex == InvalidID) {
fracture_direction = { 0.0, 0.0, 0.0 };
Expand Down Expand Up @@ -621,6 +621,22 @@ inline void BaseTearingEngine<DataTypes>::calculate_inverse_distance_weights(std



template <class DataTypes>
void BaseTearingEngine<DataTypes>::clearFracturePath()
{
m_fracturePath.ptA = Vec3();
m_fracturePath.ptB = Vec3();
m_fracturePath.ptC = Vec3();

m_fracturePath.triIdA = InvalidID;
m_fracturePath.triIdB = InvalidID;
m_fracturePath.triIdC = InvalidID;

m_fracturePath.pointsToAdd.clear();
m_fracturePath.pathOk = false;
}


template <class DataTypes>
void BaseTearingEngine<DataTypes>::handleEvent(sofa::core::objectmodel::Event* event)
{
Expand All @@ -638,15 +654,17 @@ void BaseTearingEngine<DataTypes>::handleEvent(sofa::core::objectmodel::Event* e
return; // We only launch computation at end of a simulation step
}

if (m_tearingAlgo->getFractureNumber() > d_nbFractureMax.getValue())
if (m_tearingAlgo->getFractureNumber() > d_nbFractureMax.getValue()) // reach the end of the engine behavior
return;

computeFracturePath();

// Hack: we access one output value to force the engine to call doUpdate()
if (d_maxStress.getValue() == Real(0.0))
return;

// main method to compute the possible fracture if a triangle has reached threshold
computeFracturePath();


// Perform fracture every d_stepModulo
int step = d_stepModulo.getValue();
if (m_stepCounter > step)
Expand Down Expand Up @@ -721,25 +739,18 @@ void BaseTearingEngine<DataTypes>::draw(const core::visual::VisualParams* vparam
}





if (d_showFracturePath.getValue())
{
if (m_maxStressTriangleIndex != InvalidID && fractureSegmentEndpoints.size() == 2)
if (m_maxStressTriangleIndex != InvalidID && m_fracturePath.pathOk)
{
helper::ReadAccessor< Data<VecCoord> > x(d_input_positions);

Coord principalStressDirection = m_triangleInfoTearing[m_maxStressTriangleIndex].principalStressDirection;
Coord Pa = x[m_maxStressVertexIndex];
//Coord fractureDirection;
//computeFractureDirection(principalStressDirection, fractureDirection);
Coord Pb = fractureSegmentEndpoints[0];
Coord Pc = fractureSegmentEndpoints[1];
Coord Pb = m_fracturePath.ptB;
Coord Pc = m_fracturePath.ptC;

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

points.clear();
std::vector<Vec3> pointsPath;
for (auto ptA : m_fracturePath.pointsToAdd)
{
sofa::type::Vec3 vecG = sofa::type::Vec3(0.0, 0.0, 0.0);
sofa::Size nbr = ptA->m_ancestors.size();
for (int i = 0; i < nbr; ++i)
{

vecG += x[ptA->m_ancestors[i]] * ptA->m_coefs[i];
}
pointsPath.push_back(vecG);
}
vparams->drawTool()->drawSpheres(pointsPath, 0.01, sofa::type::RGBAColor::red());

const vector<Coord>& path = m_tearingAlgo->getFracturePath();
if (!path.empty())
vparams->drawTool()->drawPoints(path, 10, sofa::type::RGBAColor(0, 0.8, 0.2, 1));
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/Tearing/TearingAlgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,29 @@
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyContainer.h>
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyModifier.h>
#include <sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h>
#include <sofa/component/topology/container/dynamic/TriangleSubdividers.h>



namespace sofa::component
{
using sofa::component::topology::container::dynamic::TriangleSetTopologyModifier;
using sofa::component::topology::container::dynamic::TriangleSetGeometryAlgorithms;
using namespace sofa::component::topology::container::dynamic;

struct FracturePath
{
TriangleID triIdA = InvalidID;
TriangleID triIdB = InvalidID;
TriangleID triIdC = InvalidID;
sofa::type::Vec3 ptA, ptB, ptC;

// full point to add vector
type::vector< std::shared_ptr<PointToAdd> > pointsToAdd;

bool pathOk = false;
};


template <class DataTypes>
class TearingAlgorithms
Expand All @@ -55,6 +72,10 @@ class TearingAlgorithms

virtual ~TearingAlgorithms();

void computeFracturePath(FracturePath& my_fracturePath);

void computeFracturePath(const Coord& pA, Index triId, const Coord pB, const Coord pC);

/// <summary>
/// compute fracture path intersection point and cut through them
/// </summary>
Expand Down Expand Up @@ -160,6 +181,9 @@ class TearingAlgorithms
/// path created by algoFracturePath
sofa::type::vector<Coord> m_fracturePath;

/// Vector of pointToAdd due to new fracture
type::vector< std::shared_ptr<PointToAdd> > m_pointsToAdd;

};


Expand Down
16 changes: 16 additions & 0 deletions src/Tearing/TearingAlgorithms.inl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ TearingAlgorithms<DataTypes>::~TearingAlgorithms()
}


template <class DataTypes>
void TearingAlgorithms<DataTypes>::computeFracturePath(const Coord& pA, Index triId, const Coord pB, const Coord pC)
{

}



template <class DataTypes>
void TearingAlgorithms<DataTypes>::computeFracturePath(FracturePath& my_fracturePath)
{

}



template <class DataTypes>
void TearingAlgorithms<DataTypes>::algoFracturePath(Coord Pa, Index indexA, Coord Pb, Coord Pc,
const Index indexTriangleMaxStress, const Coord principalStressDirection, const VecCoord& input_position)
Expand Down
2 changes: 1 addition & 1 deletion src/Tearing/TearingEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TearingEngine : public BaseTearingEngine<DataTypes>

using BaseTearingEngine<DataTypes>::d_input_positions;
using BaseTearingEngine<DataTypes>::d_triangleIdsOverThreshold;
using BaseTearingEngine<DataTypes>::fractureSegmentEndpoints;
using BaseTearingEngine<DataTypes>::m_fracturePath;

public:

Expand Down
16 changes: 10 additions & 6 deletions src/Tearing/TearingEngine.inl
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,17 @@ void TearingEngine<DataTypes>::algoFracturePath()
template <class DataTypes>
void TearingEngine<DataTypes>::computeFracturePath()
{
if (m_maxStressTriangleIndex != InvalidID)
// frist clear ereything
this->clearFracturePath();

if (m_maxStressTriangleIndex != InvalidID) // we have triangle to start and also a vertex id
{
//Recording the endpoints of the fracture segment
helper::ReadAccessor< Data<VecCoord> > x(d_input_positions);

Coord principalStressDirection = m_triangleInfoTearing[m_maxStressTriangleIndex].principalStressDirection;
Coord Pa = x[m_maxStressVertexIndex];

Coord Pa = x[m_maxStressVertexIndex];
Coord Pb, Pc;
fractureSegmentEndpoints.clear();

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

fractureSegmentEndpoints.push_back(Pb);
fractureSegmentEndpoints.push_back(Pc);
this->m_fracturePath.ptA = type::Vec3(Pa[0], Pa[1], Pa[2]);
this->m_fracturePath.ptB = type::Vec3(Pb[0], Pb[1], Pb[2]);
this->m_fracturePath.ptC = type::Vec3(Pc[0], Pc[1], Pc[2]);
this->m_fracturePath.triIdA = m_maxStressTriangleIndex;

this->m_tearingAlgo->computeFracturePath(this->m_fracturePath);
this->m_stepCounter++;

//this->m_tearingAlgo->computeFracturePath(Pa, m_maxStressTriangleIndex, Pb, Pc);
Expand Down
Loading