Skip to content

Commit

Permalink
Fix TearingScenario draw and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
epernod committed Jun 6, 2024
1 parent 0e632f6 commit 3c82536
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Tearing_test/TearingEngine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ struct TearingEngine_Case1 : public TearingEngine_test
m_instance.simulate(0.05);
}

EXPECT_EQ(topoCon->getNbTriangles(), 1454);
EXPECT_EQ(topoCon->getNbEdges(), 2235);
EXPECT_EQ(topoCon->getNbPoints(), 781);
EXPECT_EQ(topoCon->getNbTriangles(), 1505);
EXPECT_EQ(topoCon->getNbEdges(), 2334);
EXPECT_EQ(topoCon->getNbPoints(), 830);

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions scenes/Benchmarks/Scenario-01_squareTissue_horizontal-cut.scn
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
<TriangularBendingSprings name="FEM-Bend" stiffness="300" damping="1.0" />
<TriangleCollisionModel />

<TearingScenarioEngine name="TearingScenarioEngine" input_position="@Mo.position" showTearableTriangle="0" showFracturePath="0"
startVertexId="421" startDirection="1.0 0.0 0.0" startLength="5" />
<TearingScenarioEngine name="TearingScenarioEngine" input_position="@Mo.position" showTearableTriangle="0" showFracturePath="1"
startVertexId="421" startDirection="1.0 0.0 0.0" startLength="3" />

<Node >
<OglModel name="Visual" color="red" />
Expand Down
4 changes: 4 additions & 0 deletions src/Tearing/TearingScenarioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ namespace sofa::component::engine
void algoFracturePath() override;
void computeEndPoints(Coord Pa, Coord direction, Coord& Pb, Coord& Pc) override;

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

bool m_fractureDone = false;
};


Expand Down
65 changes: 28 additions & 37 deletions src/Tearing/TearingScenarioEngine.inl
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,14 @@ TearingScenarioEngine<DataTypes>::TearingScenarioEngine()
Coord dir,
Coord& Pb, Coord& Pc)
{

int triID = d_startTriId.getValue();

const Real& alpha = d_startLength.getValue();


Real norm_dir = dir.norm();

Pb = Pa + alpha/norm_dir * dir;
Pc = Pa - alpha /norm_dir * dir;
Pb = Pa + alpha/norm_dir * dir;
Pc = Pa - alpha /norm_dir * dir;
}

template <class DataTypes>
Expand All @@ -108,10 +106,10 @@ TearingScenarioEngine<DataTypes>::TearingScenarioEngine()
const Real& alpha = d_startLength.getValue();

helper::ReadAccessor< Data<VecCoord> > x(this->d_input_positions);
Coord Pa = x[indexA];
m_Pa = x[indexA];

Coord Pb, Pc;
computeEndPoints(Pa, dir, Pb, Pc);
//Coord Pb, Pc;
computeEndPoints(m_Pa, dir, m_Pb, m_Pc);


Coord normal;
Expand All @@ -122,10 +120,11 @@ TearingScenarioEngine<DataTypes>::TearingScenarioEngine()
if (tearingAlgo == nullptr)
return;

tearingAlgo->algoFracturePath(Pa, indexA, Pb, Pc, triID, normal, (this->d_input_positions).getValue());


tearingAlgo->algoFracturePath(m_Pa, indexA, m_Pb, m_Pc, triID, normal, (this->d_input_positions).getValue());
m_fractureDone = true;
}


template <class DataTypes>
void TearingScenarioEngine<DataTypes>::draw(const core::visual::VisualParams* vparams)
{
Expand All @@ -135,43 +134,35 @@ TearingScenarioEngine<DataTypes>::TearingScenarioEngine()
if (vparams->displayFlags().getShowWireFrame())
vparams->drawTool()->setPolygonMode(0, true);

sofa::type::RGBAColor color2(0.0f, 1.0f, 0.0f, 1.0f);

int triID = d_startTriId.getValue();// This most be index variable
if (triID == -1)
if (!m_fractureDone)
return;

sofa::core::topology::BaseMeshTopology* topo = this->getTopology();
const VecTriangles& triangleList = topo->getTriangles();
const Triangle& tri = triangleList[triID]; // Is this correct?

helper::ReadAccessor< Data<VecCoord> > x(this->d_input_positions);
Coord Pa = x[tri[0]];
Coord Pb = x[tri[1]];
Coord Pc = x[tri[2]];
sofa::type::RGBAColor color2(0.0f, 1.0f, 0.0f, 1.0f);

std::vector<Vec3> Tri;
Tri.push_back(Pa);
Tri.push_back(Pb);
Tri.push_back(Pc);
int triID = d_startTriId.getValue();// This most be index variable
if (triID != -1 && this->d_showTearableCandidates.getValue())
{
sofa::core::topology::BaseMeshTopology* topo = this->getTopology();
const VecTriangles& triangleList = topo->getTriangles();
const Triangle& tri = triangleList[triID]; // Is this correct?

std::vector<Vec3> Tri;
Tri.push_back(m_Pa);
Tri.push_back(m_Pb);
Tri.push_back(m_Pc);
vparams->drawTool()->drawTriangles(Tri, color2);
}

vparams->drawTool()->drawTriangles(Tri, color2);
if (this->d_showFracturePath.getValue())
{
const Vec3& dir = d_startDirection.getValue();
const Real& alpha = d_startLength.getValue();

int indexA = d_startVertexId.getValue();
Coord A = x[indexA];

Coord B = A + alpha * dir;
Coord C = A - alpha * dir;

vector<Coord> points;
points.push_back(B);
points.push_back(A);
points.push_back(A);
points.push_back(C);
points.push_back(m_Pb);
points.push_back(m_Pa);
points.push_back(m_Pa);
points.push_back(m_Pc);

// Blue == draw fracture path
vparams->drawTool()->drawPoints(points, 10, sofa::type::RGBAColor(0, 0.2, 1, 1));
Expand Down

0 comments on commit 3c82536

Please sign in to comment.