From 9c228ef196f8c3f0934d59817c3da1528053b478 Mon Sep 17 00:00:00 2001 From: epernod Date: Thu, 20 Feb 2025 19:05:23 +0100 Subject: [PATCH 1/6] [src] Fix the logic when to start tearing --- src/Tearing/BaseTearingEngine.inl | 15 ++++++--------- src/Tearing/TearingEngine.inl | 4 +++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Tearing/BaseTearingEngine.inl b/src/Tearing/BaseTearingEngine.inl index eccb860..b404c99 100644 --- a/src/Tearing/BaseTearingEngine.inl +++ b/src/Tearing/BaseTearingEngine.inl @@ -162,7 +162,7 @@ void BaseTearingEngine::doUpdate() if (sofa::core::objectmodel::BaseObject::d_componentState.getValue() != sofa::core::objectmodel::ComponentState::Valid) return; - m_stepCounter++; + if (d_ignoreTriangles.getValue()) { @@ -215,7 +215,6 @@ void BaseTearingEngine::triangleOverThresholdPrincipalStress() candidate.clear(); maxStress = 0; helper::WriteAccessor< Data> >triangleToSkip(d_trianglesToIgnore); - m_maxStressTriangleIndex = InvalidID; for (unsigned int i = 0; i < triangleList.size(); i++) { @@ -639,6 +638,9 @@ void BaseTearingEngine::handleEvent(sofa::core::objectmodel::Event* e return; // We only launch computation at end of a simulation step } + if (m_tearingAlgo->getFractureNumber() > d_nbFractureMax.getValue()) + return; + computeFracturePath(); // Hack: we access one output value to force the engine to call doUpdate() @@ -647,14 +649,9 @@ void BaseTearingEngine::handleEvent(sofa::core::objectmodel::Event* e // Perform fracture every d_stepModulo int step = d_stepModulo.getValue(); - if (step == 0) // interactive version - { - if (m_stepCounter > 200 && (m_tearingAlgo->getFractureNumber() < d_nbFractureMax.getValue())){ - algoFracturePath(); - } - } - else if (((m_stepCounter % step) == 0) && (m_tearingAlgo->getFractureNumber() < d_nbFractureMax.getValue())) + if (m_stepCounter > step) { + m_stepCounter = 0; algoFracturePath(); } } diff --git a/src/Tearing/TearingEngine.inl b/src/Tearing/TearingEngine.inl index de1a724..b796469 100644 --- a/src/Tearing/TearingEngine.inl +++ b/src/Tearing/TearingEngine.inl @@ -168,7 +168,7 @@ void TearingEngine::algoFracturePath() template void TearingEngine::computeFracturePath() { - if (!this->d_fractureMaxLength.getValue() && m_maxStressTriangleIndex != InvalidID) + if (this->d_fractureMaxLength.getValue() != 0.0 && m_maxStressTriangleIndex != InvalidID) { //Recording the endpoints of the fracture segment helper::ReadAccessor< Data > x(d_input_positions); @@ -184,6 +184,8 @@ void TearingEngine::computeFracturePath() fractureSegmentEndpoints.push_back(Pb); fractureSegmentEndpoints.push_back(Pc); } + + this->m_stepCounter++; } } From c4d2fb3324283af4628f1d3956bf6dea0e49b684 Mon Sep 17 00:00:00 2001 From: epernod Date: Tue, 25 Feb 2025 00:40:59 +0100 Subject: [PATCH 2/6] Backup work on new fracture path --- .../SquareTissue_11_MiddlePressure .scn | 6 ++-- src/Tearing/TearingAlgorithms.h | 2 ++ src/Tearing/TearingAlgorithms.inl | 6 ++++ src/Tearing/TearingEngine.inl | 29 ++++++++++++------- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn b/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn index 814e03e..a2e0470 100644 --- a/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn +++ b/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn @@ -51,15 +51,15 @@ - + - + diff --git a/src/Tearing/TearingAlgorithms.h b/src/Tearing/TearingAlgorithms.h index 5fd775f..fb6b964 100644 --- a/src/Tearing/TearingAlgorithms.h +++ b/src/Tearing/TearingAlgorithms.h @@ -54,6 +54,8 @@ class TearingAlgorithms virtual ~TearingAlgorithms(); + void computeFracturePath(const Coord& Pa, TriangleID triId, Const Coord Pb, Const Coord Pc); + /// /// compute fracture path intersection point and cut through them /// diff --git a/src/Tearing/TearingAlgorithms.inl b/src/Tearing/TearingAlgorithms.inl index 6000a98..453d3aa 100644 --- a/src/Tearing/TearingAlgorithms.inl +++ b/src/Tearing/TearingAlgorithms.inl @@ -50,6 +50,12 @@ TearingAlgorithms::~TearingAlgorithms() } +template +void TearingAlgorithms::computeFracturePath(const Coord& Pa, Index triId, const Coord Pb, const Coord Pc) +{ + +} + template void TearingAlgorithms::algoFracturePath(Coord Pa, Index indexA, Coord Pb, Coord Pc, const Index indexTriangleMaxStress, const Coord principalStressDirection, const VecCoord& input_position) diff --git a/src/Tearing/TearingEngine.inl b/src/Tearing/TearingEngine.inl index b796469..76e5eb0 100644 --- a/src/Tearing/TearingEngine.inl +++ b/src/Tearing/TearingEngine.inl @@ -96,7 +96,7 @@ inline bool TearingEngine::computeIntersectionNeighborTriangle(Coord template inline bool TearingEngine::computeEndPointsNeighboringTriangles(Coord Pa, Coord direction, Coord& Pb, Coord& Pc) { - + std::cout << "computeEndPointsNeighboringTriangles" << std::endl; bool t_b_ok = false; bool t_c_ok = false; //compute fracture direction perpendicular to the principal stress direction @@ -151,13 +151,17 @@ void TearingEngine::algoFracturePath() Coord Pb; Coord Pc; - if (this->d_fractureMaxLength.getValue()) - this->computeEndPoints(Pa, principalStressDirection, Pb, Pc); - else if (!(computeEndPointsNeighboringTriangles(Pa, principalStressDirection, Pb, Pc))) - return; + std::cout << "length: " << this->d_fractureMaxLength.getValue() << std::endl; + //if (this->d_fractureMaxLength.getValue() != 0.0) { + // this->computeEndPoints(Pa, principalStressDirection, Pb, Pc); + //} + //else if (!(computeEndPointsNeighboringTriangles(Pa, principalStressDirection, Pb, Pc))) + //{ + // return; + //} - this->m_tearingAlgo->algoFracturePath(Pa, indexA, Pb, Pc, m_maxStressTriangleIndex, principalStressDirection, d_input_positions.getValue()); + //this->m_tearingAlgo->algoFracturePath(Pa, indexA, Pb, Pc, m_maxStressTriangleIndex, principalStressDirection, d_input_positions.getValue()); m_maxStressTriangleIndex = InvalidID; if (this->d_stepModulo.getValue() == 0) // reset to 0 @@ -168,7 +172,7 @@ void TearingEngine::algoFracturePath() template void TearingEngine::computeFracturePath() { - if (this->d_fractureMaxLength.getValue() != 0.0 && m_maxStressTriangleIndex != InvalidID) + if (m_maxStressTriangleIndex != InvalidID) { //Recording the endpoints of the fracture segment helper::ReadAccessor< Data > x(d_input_positions); @@ -179,12 +183,17 @@ void TearingEngine::computeFracturePath() Coord Pb, Pc; fractureSegmentEndpoints.clear(); - if (computeEndPointsNeighboringTriangles(Pa, principalStressDirection, Pb, Pc)) + if (this->d_fractureMaxLength.getValue() == 0.0) { + computeEndPointsNeighboringTriangles(Pa, principalStressDirection, Pb, Pc); + } + else { - fractureSegmentEndpoints.push_back(Pb); - fractureSegmentEndpoints.push_back(Pc); + this->computeEndPoints(Pa, principalStressDirection, Pb, Pc); } + fractureSegmentEndpoints.push_back(Pb); + fractureSegmentEndpoints.push_back(Pc); + this->m_stepCounter++; } } From c49bb2ff172e3e4485b47c64ee069d15e1466956 Mon Sep 17 00:00:00 2001 From: epernod Date: Wed, 19 Mar 2025 22:33:59 +0100 Subject: [PATCH 3/6] Backup work on new fracture path --- .../SquareTissue_11_MiddlePressure .scn | 6 +-- ...ssue_11_MiddlePressure .scn.qglviewer.view | 2 +- src/Tearing/TearingAlgorithms.h | 12 +++++- src/Tearing/TearingAlgorithms.inl | 40 ++++++++++++++++++- src/Tearing/TearingEngine.inl | 3 ++ 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn b/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn index a2e0470..20da601 100644 --- a/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn +++ b/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn @@ -39,9 +39,9 @@ - + - + @@ -59,7 +59,7 @@ + step="20" nbFractureMax="40" showFracturePath="1" showTearableCandidates="1" fractureMaxLength="1.0"/> diff --git a/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn.qglviewer.view b/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn.qglviewer.view index c0ee5b3..80c5b28 100644 --- a/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn.qglviewer.view +++ b/scenes/TearingEngine/SquareTissue_11_MiddlePressure .scn.qglviewer.view @@ -1,2 +1,2 @@ -2.39377 7.2768 19.272 +5.18732 3.91825 1.3 -0.0438528 -0.046858 0.00673547 0.997916 diff --git a/src/Tearing/TearingAlgorithms.h b/src/Tearing/TearingAlgorithms.h index fb6b964..f832b90 100644 --- a/src/Tearing/TearingAlgorithms.h +++ b/src/Tearing/TearingAlgorithms.h @@ -28,11 +28,14 @@ #include #include #include +#include + namespace sofa::component { using sofa::component::topology::container::dynamic::TriangleSetTopologyModifier; using sofa::component::topology::container::dynamic::TriangleSetGeometryAlgorithms; +using namespace sofa::component::topology::container::dynamic; template class TearingAlgorithms @@ -46,6 +49,7 @@ class TearingAlgorithms using Edge = sofa::core::topology::BaseMeshTopology::Edge; using Triangle = sofa::core::topology::BaseMeshTopology::Triangle; using VecIds = sofa::type::vector; + TearingAlgorithms(sofa::core::topology::BaseMeshTopology* _topology, TriangleSetTopologyModifier* _modifier, @@ -54,7 +58,9 @@ class TearingAlgorithms virtual ~TearingAlgorithms(); - void computeFracturePath(const Coord& Pa, TriangleID triId, Const Coord Pb, Const Coord Pc); + void computeEndPointsNeighboringTriangles(const Index ptAId, const Coord& ptA, const Coord& direction); + + void computeFracturePath(const Coord& pA, Index triId, const Coord pB, const Coord pC); /// /// compute fracture path intersection point and cut through them @@ -160,6 +166,10 @@ class TearingAlgorithms /// path created by algoFracturePath sofa::type::vector m_fracturePath; + + /// Vector of pointToAdd due to new fracture + type::vector< std::shared_ptr > m_pointsToAdd; + }; diff --git a/src/Tearing/TearingAlgorithms.inl b/src/Tearing/TearingAlgorithms.inl index 453d3aa..a5e4177 100644 --- a/src/Tearing/TearingAlgorithms.inl +++ b/src/Tearing/TearingAlgorithms.inl @@ -24,6 +24,7 @@ #pragma once #include + namespace sofa::component { @@ -49,9 +50,46 @@ TearingAlgorithms::~TearingAlgorithms() } +template +void TearingAlgorithms::computeEndPointsNeighboringTriangles(const Index ptAId, const Coord& ptA, const Coord& direction) +{ + //Index triId = m_triangleGeo->getTriangleInDirection(ptAId, direction); + //sofa::type::vector intersectedEdges; + //sofa::type::vector baryCoefs; + //if (triId != -1) + //{ + // const Triangle tri = m_topology->getTriangle(triId); + // type::Vec3 vA = type::Vec3(ptA[0], ptA[1], ptA[2]); + // type::Vec3 vB = vA + direction * 1000; + // const auto eInTri = m_topology->getEdgesInTriangle(triId); + // Index vIntri = m_topology->getVertexIndexInTriangle(tri, ptAId); + // Index nextEdgeId = eInTri[vIntri]; + // const Edge& theEdge = this->m_topology->getEdge(nextEdgeId); + + // getEdgeVertexCoordinates(const EdgeID i, Coord[2]) + + // type::Vec2 baryCoords(type::NOINIT); + // intersected = sofa::geometry::Edge::intersectionWithEdge(p0, p1, vA, vB, baryCoords); + // + // m_triangleGeo->computeEdgeSegmentIntersection(nextEdgeId, vA, vB) + // //m_triangleGeo->computeSegmentTriangleIntersectionInPlane(vA, vB, triId, intersectedEdges, baryCoefs); + // std::cout << "triId: " << triId << std::endl; + // std::cout << "intersectedEdges: " << intersectedEdges << " | " << baryCoefs << std::endl; + //} + + //Index triId2 = m_triangleGeo->getTriangleInDirection(ptAId, -direction); + //if (triId2 != -1) + //{ + // type::Vec3 vA = type::Vec3(ptA[0], ptA[1], ptA[2]); + // type::Vec3 vB = vA - direction * 1000; + // m_triangleGeo->computeSegmentTriangleIntersectionInPlane(vA, vB, triId2, intersectedEdges, baryCoefs); + // std::cout << "triId2: " << triId2 << std::endl; + // std::cout << "intersectedEdges: " << intersectedEdges << " | " << baryCoefs << std::endl; + //} +} template -void TearingAlgorithms::computeFracturePath(const Coord& Pa, Index triId, const Coord Pb, const Coord Pc) +void TearingAlgorithms::computeFracturePath(const Coord& pA, Index triId, const Coord pB, const Coord pC) { } diff --git a/src/Tearing/TearingEngine.inl b/src/Tearing/TearingEngine.inl index 76e5eb0..d66a4f6 100644 --- a/src/Tearing/TearingEngine.inl +++ b/src/Tearing/TearingEngine.inl @@ -103,6 +103,7 @@ inline bool TearingEngine::computeEndPointsNeighboringTriangles(Coord Coord fractureDirection; this->computeFractureDirection(direction, fractureDirection); + this->m_tearingAlgo->computeEndPointsNeighboringTriangles(m_maxStressVertexIndex, Pa, fractureDirection); Real norm_fractureDirection = fractureDirection.norm(); Coord dir_b = 1.0 / norm_fractureDirection * fractureDirection; @@ -195,6 +196,8 @@ void TearingEngine::computeFracturePath() fractureSegmentEndpoints.push_back(Pc); this->m_stepCounter++; + + this->m_tearingAlgo->computeFracturePath(Pa, m_maxStressTriangleIndex, Pb, Pc); } } From f037547655c484048afb23ed9184b4ca840d19c6 Mon Sep 17 00:00:00 2001 From: epernod Date: Wed, 19 Mar 2025 23:01:48 +0100 Subject: [PATCH 4/6] clean PR --- src/Tearing/TearingAlgorithms.h | 5 ---- src/Tearing/TearingAlgorithms.inl | 43 ------------------------------- src/Tearing/TearingEngine.inl | 13 +--------- 3 files changed, 1 insertion(+), 60 deletions(-) diff --git a/src/Tearing/TearingAlgorithms.h b/src/Tearing/TearingAlgorithms.h index f832b90..2436b73 100644 --- a/src/Tearing/TearingAlgorithms.h +++ b/src/Tearing/TearingAlgorithms.h @@ -57,11 +57,6 @@ class TearingAlgorithms virtual ~TearingAlgorithms(); - - void computeEndPointsNeighboringTriangles(const Index ptAId, const Coord& ptA, const Coord& direction); - - void computeFracturePath(const Coord& pA, Index triId, const Coord pB, const Coord pC); - /// /// compute fracture path intersection point and cut through them /// diff --git a/src/Tearing/TearingAlgorithms.inl b/src/Tearing/TearingAlgorithms.inl index a5e4177..f5673a7 100644 --- a/src/Tearing/TearingAlgorithms.inl +++ b/src/Tearing/TearingAlgorithms.inl @@ -50,49 +50,6 @@ TearingAlgorithms::~TearingAlgorithms() } -template -void TearingAlgorithms::computeEndPointsNeighboringTriangles(const Index ptAId, const Coord& ptA, const Coord& direction) -{ - //Index triId = m_triangleGeo->getTriangleInDirection(ptAId, direction); - //sofa::type::vector intersectedEdges; - //sofa::type::vector baryCoefs; - //if (triId != -1) - //{ - // const Triangle tri = m_topology->getTriangle(triId); - // type::Vec3 vA = type::Vec3(ptA[0], ptA[1], ptA[2]); - // type::Vec3 vB = vA + direction * 1000; - // const auto eInTri = m_topology->getEdgesInTriangle(triId); - // Index vIntri = m_topology->getVertexIndexInTriangle(tri, ptAId); - // Index nextEdgeId = eInTri[vIntri]; - // const Edge& theEdge = this->m_topology->getEdge(nextEdgeId); - - // getEdgeVertexCoordinates(const EdgeID i, Coord[2]) - - // type::Vec2 baryCoords(type::NOINIT); - // intersected = sofa::geometry::Edge::intersectionWithEdge(p0, p1, vA, vB, baryCoords); - // - // m_triangleGeo->computeEdgeSegmentIntersection(nextEdgeId, vA, vB) - // //m_triangleGeo->computeSegmentTriangleIntersectionInPlane(vA, vB, triId, intersectedEdges, baryCoefs); - // std::cout << "triId: " << triId << std::endl; - // std::cout << "intersectedEdges: " << intersectedEdges << " | " << baryCoefs << std::endl; - //} - - //Index triId2 = m_triangleGeo->getTriangleInDirection(ptAId, -direction); - //if (triId2 != -1) - //{ - // type::Vec3 vA = type::Vec3(ptA[0], ptA[1], ptA[2]); - // type::Vec3 vB = vA - direction * 1000; - // m_triangleGeo->computeSegmentTriangleIntersectionInPlane(vA, vB, triId2, intersectedEdges, baryCoefs); - // std::cout << "triId2: " << triId2 << std::endl; - // std::cout << "intersectedEdges: " << intersectedEdges << " | " << baryCoefs << std::endl; - //} -} - -template -void TearingAlgorithms::computeFracturePath(const Coord& pA, Index triId, const Coord pB, const Coord pC) -{ - -} template void TearingAlgorithms::algoFracturePath(Coord Pa, Index indexA, Coord Pb, Coord Pc, diff --git a/src/Tearing/TearingEngine.inl b/src/Tearing/TearingEngine.inl index d66a4f6..93b0e1c 100644 --- a/src/Tearing/TearingEngine.inl +++ b/src/Tearing/TearingEngine.inl @@ -96,7 +96,6 @@ inline bool TearingEngine::computeIntersectionNeighborTriangle(Coord template inline bool TearingEngine::computeEndPointsNeighboringTriangles(Coord Pa, Coord direction, Coord& Pb, Coord& Pc) { - std::cout << "computeEndPointsNeighboringTriangles" << std::endl; bool t_b_ok = false; bool t_c_ok = false; //compute fracture direction perpendicular to the principal stress direction @@ -152,17 +151,7 @@ void TearingEngine::algoFracturePath() Coord Pb; Coord Pc; - std::cout << "length: " << this->d_fractureMaxLength.getValue() << std::endl; - //if (this->d_fractureMaxLength.getValue() != 0.0) { - // this->computeEndPoints(Pa, principalStressDirection, Pb, Pc); - //} - //else if (!(computeEndPointsNeighboringTriangles(Pa, principalStressDirection, Pb, Pc))) - //{ - // return; - //} - - - //this->m_tearingAlgo->algoFracturePath(Pa, indexA, Pb, Pc, m_maxStressTriangleIndex, principalStressDirection, d_input_positions.getValue()); + this->m_tearingAlgo->algoFracturePath(Pa, indexA, Pb, Pc, m_maxStressTriangleIndex, principalStressDirection, d_input_positions.getValue()); m_maxStressTriangleIndex = InvalidID; if (this->d_stepModulo.getValue() == 0) // reset to 0 From bcd0e6e69c88def3b8fe5c307b6b2659052a69ec Mon Sep 17 00:00:00 2001 From: epernod Date: Wed, 19 Mar 2025 23:08:37 +0100 Subject: [PATCH 5/6] fix compilation --- src/Tearing/TearingEngine.inl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Tearing/TearingEngine.inl b/src/Tearing/TearingEngine.inl index 93b0e1c..cd2f619 100644 --- a/src/Tearing/TearingEngine.inl +++ b/src/Tearing/TearingEngine.inl @@ -102,8 +102,6 @@ inline bool TearingEngine::computeEndPointsNeighboringTriangles(Coord Coord fractureDirection; this->computeFractureDirection(direction, fractureDirection); - this->m_tearingAlgo->computeEndPointsNeighboringTriangles(m_maxStressVertexIndex, Pa, fractureDirection); - Real norm_fractureDirection = fractureDirection.norm(); Coord dir_b = 1.0 / norm_fractureDirection * fractureDirection; @@ -186,7 +184,7 @@ void TearingEngine::computeFracturePath() this->m_stepCounter++; - this->m_tearingAlgo->computeFracturePath(Pa, m_maxStressTriangleIndex, Pb, Pc); + //this->m_tearingAlgo->computeFracturePath(Pa, m_maxStressTriangleIndex, Pb, Pc); } } From a5e5b6406e8e21c2530a4278a10147963e0b768d Mon Sep 17 00:00:00 2001 From: epernod Date: Wed, 19 Mar 2025 23:14:06 +0100 Subject: [PATCH 6/6] clean PR --- src/Tearing/TearingAlgorithms.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Tearing/TearingAlgorithms.h b/src/Tearing/TearingAlgorithms.h index 2436b73..fdcda41 100644 --- a/src/Tearing/TearingAlgorithms.h +++ b/src/Tearing/TearingAlgorithms.h @@ -28,14 +28,12 @@ #include #include #include -#include namespace sofa::component { using sofa::component::topology::container::dynamic::TriangleSetTopologyModifier; using sofa::component::topology::container::dynamic::TriangleSetGeometryAlgorithms; -using namespace sofa::component::topology::container::dynamic; template class TearingAlgorithms @@ -162,9 +160,6 @@ class TearingAlgorithms /// path created by algoFracturePath sofa::type::vector m_fracturePath; - /// Vector of pointToAdd due to new fracture - type::vector< std::shared_ptr > m_pointsToAdd; - };