Skip to content

Commit

Permalink
Fix linux compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
epernod committed Jun 6, 2024
1 parent 87a37b1 commit f996f27
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 60 deletions.
4 changes: 2 additions & 2 deletions src/Tearing/BaseTearingEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Authors: see Authors.txt *
* Further information: https://infinytech3d.com *
****************************************************************************/
#define SOFA_COMPONENT_ENGINE_TEARINGENGINE_CPP
#define SOFA_COMPONENT_ENGINE_BASETEARINGENGINE_CPP
#include <Tearing/BaseTearingEngine.inl>
#include <sofa/core/ObjectFactory.h>
#include <sofa/defaulttype/VecTypes.h>
Expand All @@ -34,4 +34,4 @@
//
//template class TEARING_API BaseTearingEngine<Vec3Types>;
//
//}//namespace sofa::component::engine
//}//namespace sofa::component::engine
4 changes: 0 additions & 4 deletions src/Tearing/BaseTearingEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,5 @@ class BaseTearingEngine : public core::DataEngine
int m_stepCounter = 0; ///< counter of doUpdate called by the simulation. Used to put gap between consecutives fractures

};

#if !defined(SOFA_COMPONENT_ENGINE_BASETEARINGENGINE_CPP)
extern template class TEARING_API BaseTearingEngine<defaulttype::Vec3Types>;
#endif

}//namespace sofa::component::engine
9 changes: 8 additions & 1 deletion src/Tearing/TearingEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,15 @@ class TearingEngine : public BaseTearingEngine<DataTypes>
typedef sofa::type::vector<TriangleFEMInformation> VecTriangleFEMInformation;

protected:
using BaseTearingEngine::BaseTearingEngine;
using BaseTearingEngine<DataTypes>::BaseTearingEngine;
//using BaseTearingEngine::~BaseTearingEngine;

using BaseTearingEngine<DataTypes>::m_maxStressVertexIndex;
using BaseTearingEngine<DataTypes>::m_maxStressTriangleIndex;
using BaseTearingEngine<DataTypes>::m_triangleInfoTearing;

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

public:
void draw(const core::visual::VisualParams* vparams) override;
Expand Down
41 changes: 21 additions & 20 deletions src/Tearing/TearingEngine.inl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
****************************************************************************/
#pragma once
#include <Tearing/TearingEngine.h>
#include <Tearing/BaseTearingEngine.inl>

#include <sofa/simulation/AnimateBeginEvent.h>
#include <sofa/simulation/AnimateEndEvent.h>
Expand All @@ -48,7 +49,7 @@ inline bool TearingEngine<DataTypes>::computeIntersectionNeighborTriangle(Coord

// Get Geometry Algorithm
TriangleSetGeometryAlgorithms<DataTypes>* _triangleGeo = nullptr;
m_topology->getContext()->get(_triangleGeo);
this->m_topology->getContext()->get(_triangleGeo);
if (!_triangleGeo)
{
msg_error() << "Missing component: Unable to get TriangleSetGeometryAlgorithms from the current context.";
Expand All @@ -58,11 +59,11 @@ inline bool TearingEngine<DataTypes>::computeIntersectionNeighborTriangle(Coord


Index triangle_id = _triangleGeo->getTriangleInDirection(m_maxStressVertexIndex, normalizedFractureDirection);
if (triangle_id > m_topology->getNbTriangles() - 1)
if (triangle_id > this->m_topology->getNbTriangles() - 1)
return false;


const Triangle& VertexIndicies = m_topology->getTriangle(triangle_id);
const Triangle& VertexIndicies = this->m_topology->getTriangle(triangle_id);

constexpr size_t numVertices = 3;
Index B_id = -1, C_id = -1;
Expand Down Expand Up @@ -148,17 +149,17 @@ void TearingEngine<DataTypes>::algoFracturePath()
Coord Pb;
Coord Pc;

if (d_fractureMaxLength.getValue())
if (this->d_fractureMaxLength.getValue())
this->computeEndPoints(Pa, principalStressDirection, Pb, Pc);
else if (!(computeEndPointsNeighboringTriangles(Pa, principalStressDirection, Pb, Pc)))
return;


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 (d_stepModulo.getValue() == 0) // reset to 0
m_stepCounter = 0;
if (this->d_stepModulo.getValue() == 0) // reset to 0
this->m_stepCounter = 0;
}

template<class DataTypes>
Expand Down Expand Up @@ -227,7 +228,7 @@ void TearingEngine<DataTypes>::handleEvent(sofa::core::objectmodel::Event* event
}

// Compute the current fracture path
if (!d_fractureMaxLength.getValue() && m_maxStressTriangleIndex != InvalidID)
if (!this->d_fractureMaxLength.getValue() && m_maxStressTriangleIndex != InvalidID)
{
//Recording the endpoints of the fracture segment
helper::ReadAccessor< Data<VecCoord> > x(d_input_positions);
Expand All @@ -246,14 +247,14 @@ void TearingEngine<DataTypes>::handleEvent(sofa::core::objectmodel::Event* event
}


// Perform fracture every d_stepModulo
int step = d_stepModulo.getValue();
// Perform fracture every this->d_stepModulo
int step = this->d_stepModulo.getValue();
if (step == 0) // interactive version
{
if (m_stepCounter > 200 && (m_tearingAlgo->getFractureNumber() < d_nbFractureMax.getValue()))
if (this->m_stepCounter > 200 && (this->m_tearingAlgo->getFractureNumber() < this->d_nbFractureMax.getValue()))
algoFracturePath();
}
else if (((m_stepCounter % step) == 0) && (m_tearingAlgo->getFractureNumber() < d_nbFractureMax.getValue()))
else if (((this->m_stepCounter % step) == 0) && (this->m_tearingAlgo->getFractureNumber() < this->d_nbFractureMax.getValue()))
{
algoFracturePath();
}
Expand All @@ -267,9 +268,9 @@ void TearingEngine<DataTypes>::draw(const core::visual::VisualParams* vparams)
if (vparams->displayFlags().getShowWireFrame())
vparams->drawTool()->setPolygonMode(0, true);

if (d_showTearableCandidates.getValue())
if (this->d_showTearableCandidates.getValue())
{
const VecTriangles& triangleList = m_topology->getTriangles();
const VecTriangles& triangleList = this->m_topology->getTriangles();
helper::ReadAccessor< Data<vector<Index>> > candidate(d_triangleIdsOverThreshold);
helper::ReadAccessor< Data<VecCoord> > x(d_input_positions);

Expand Down Expand Up @@ -306,7 +307,7 @@ void TearingEngine<DataTypes>::draw(const core::visual::VisualParams* vparams)
}

// draw triangles ignored in red
const VecIDs& triIds = d_trianglesToIgnore.getValue();
const VecIDs& triIds = this->d_trianglesToIgnore.getValue();
std::vector<Vec3> verticesIgnore;
sofa::type::RGBAColor colorIgnore(1.0f, 0.0f, 0.0f, 1.0f);

Expand All @@ -323,7 +324,7 @@ void TearingEngine<DataTypes>::draw(const core::visual::VisualParams* vparams)
}


if (d_showFracturePath.getValue())
if (this->d_showFracturePath.getValue())
{
if (m_maxStressTriangleIndex != InvalidID)
{
Expand All @@ -336,13 +337,13 @@ void TearingEngine<DataTypes>::draw(const core::visual::VisualParams* vparams)

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;
Coord Pb = Pa + this->d_fractureMaxLength.getValue() / norm_fractureDirection * fractureDirection;
Coord Pc = Pa - this->d_fractureMaxLength.getValue() / norm_fractureDirection * fractureDirection;
points.push_back(Pb);
points.push_back(Pa);
points.push_back(Pa);
points.push_back(Pc);
// Blue == computed fracture path using d_fractureMaxLength
// Blue == computed fracture path using this->d_fractureMaxLength
vparams->drawTool()->drawPoints(points, 10, sofa::type::RGBAColor(0, 0.2, 1, 1));
vparams->drawTool()->drawLines(points, 1, sofa::type::RGBAColor(0, 0.5, 1, 1));

Expand All @@ -365,7 +366,7 @@ void TearingEngine<DataTypes>::draw(const core::visual::VisualParams* vparams)

points.clear();

const vector<Coord>& path = m_tearingAlgo->getFracturePath();
const vector<Coord>& path = this->m_tearingAlgo->getFracturePath();
if (!path.empty())
vparams->drawTool()->drawPoints(path, 10, sofa::type::RGBAColor(0, 0.8, 0.2, 1));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Tearing/TearingScenarioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Authors: see Authors.txt *
* Further information: https://infinytech3d.com *
****************************************************************************/
#define SOFA_COMPONENT_ENGINE_TEARINGENGINE_CPP
#define SOFA_COMPONENT_ENGINE_TEARINGSCENARIOENGINE_CPP
#include <Tearing/TearingScenarioEngine.inl>
#include <sofa/core/ObjectFactory.h>
#include <sofa/defaulttype/VecTypes.h>
Expand All @@ -34,4 +34,4 @@ namespace sofa::component::engine

template class TEARING_API TearingScenarioEngine<Vec3Types>;

}//namespace sofa::component::engine
}//namespace sofa::component::engine
15 changes: 10 additions & 5 deletions src/Tearing/TearingScenarioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace sofa::component::engine
SOFA_CLASS(SOFA_TEMPLATE(TearingScenarioEngine, DataTypes), SOFA_TEMPLATE(BaseTearingEngine, DataTypes));
typedef typename DataTypes::Real Real;
typedef typename DataTypes::Coord Coord;
typedef typename DataTypes::VecCoord VecCoord;
using Vec3 = sofa::type::Vec3;
using VecTriangles = sofa::core::topology::BaseMeshTopology::SeqTriangles;
using Triangle = sofa::core::topology::BaseMeshTopology::Triangle;
Expand All @@ -34,16 +35,14 @@ namespace sofa::component::engine
Data<Real> d_startLength; ///< length of first fracture to start algofracture (scenario case)


protected:
protected:
TearingScenarioEngine();
~TearingScenarioEngine() override {}

using BaseTearingEngine<DataTypes>::addInput;

public:
void init() override;
void reinit() override;

void draw(const core::visual::VisualParams* vparams) override;
void handleEvent(sofa::core::objectmodel::Event* event) override;

protected:

Expand All @@ -52,6 +51,12 @@ namespace sofa::component::engine
void computeEndPoints(Coord Pa, Coord direction, Coord& Pb, Coord& Pc) override;

};


#if !defined(SOFA_COMPONENT_ENGINE_TEARINGSCENARIOENGINE_CPP)
extern template class TEARING_API TearingScenarioEngine<defaulttype::Vec3Types>;
#endif

}//namespace sofa::component::engine


Expand Down
34 changes: 8 additions & 26 deletions src/Tearing/TearingScenarioEngine.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <Tearing/TearingScenarioEngine.h>
#include <Tearing/BaseTearingEngine.inl>
#include <sofa/simulation/AnimateBeginEvent.h>
#include <sofa/simulation/AnimateEndEvent.h>
#include <sofa/core/objectmodel/KeypressedEvent.h>
Expand All @@ -11,41 +12,22 @@ namespace sofa::component::engine
{

using sofa::type::Vec3;
using namespace sofa::core;

template <class DataTypes>
TearingScenarioEngine<DataTypes>::TearingScenarioEngine()
: d_startVertexId(initData(&d_startVertexId, int(-1), "startVertexId", "Vertex ID to start a given tearing scenario, -1 if none"))
: BaseTearingEngine<DataTypes> ()
, d_startVertexId(initData(&d_startVertexId, int(-1), "startVertexId", "Vertex ID to start a given tearing scenario, -1 if none"))
, d_startTriId(initData(&d_startTriId, int(-1), "startTriangleId", "Triangle ID from which the starting point is chosen, -1 if none"))
, d_startDirection(initData(&d_startDirection, Vec3(1.0, 0.0, 0.0), "startDirection", "If startVertexId is set, define the direction of the tearing scenario. x direction by default"))
, d_startLength(initData(&d_startLength, Real(1.0), "startLength", "If startVertexId is set, define the length of the tearing, to be combined with startDirection"))
{


addInput(&d_startVertexId);
addInput(&d_startTriId);
addInput(&d_startDirection);
addInput(&d_startLength);
}

template <class DataTypes>
void TearingScenarioEngine<DataTypes>::init()
{
BaseTearingEngine<DataTypes>::init();

}

template <class DataTypes>
void TearingScenarioEngine<DataTypes>::reinit()
{
BaseTearingEngine<DataTypes>::update();
}

template <class DataTypes>
void TearingScenarioEngine<DataTypes>::handleEvent(sofa::core::objectmodel::Event* event)
{
BaseTearingEngine<DataTypes>::handleEvent(event);
}


// --------------------------------------------------------------------------------------
// --- Computation methods
Expand Down Expand Up @@ -76,7 +58,7 @@ TearingScenarioEngine<DataTypes>::TearingScenarioEngine()
}
}

helper::ReadAccessor< Data<VecCoord> > x(d_input_positions);
helper::ReadAccessor< Data<VecCoord> > x(this->d_input_positions);
Coord A = x[triID];
Coord B = x[B_id];
Coord C = x[C_id];
Expand Down Expand Up @@ -116,7 +98,7 @@ TearingScenarioEngine<DataTypes>::TearingScenarioEngine()
const Vec3& dir = d_startDirection.getValue();
const Real& alpha = d_startLength.getValue();

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

Coord Pb, Pc;
Expand Down Expand Up @@ -153,7 +135,7 @@ TearingScenarioEngine<DataTypes>::TearingScenarioEngine()

const Triangle& tri = triangleList[triID]; // Is this correct?

helper::ReadAccessor< Data<VecCoord> > x(d_input_positions);
helper::ReadAccessor< Data<VecCoord> > x(this->d_input_positions);

Coord Pa = x[tri[0]];
Coord Pb = x[tri[1]];
Expand All @@ -166,7 +148,7 @@ TearingScenarioEngine<DataTypes>::TearingScenarioEngine()

vparams->drawTool()->drawTriangles(Tri, color2);

if (d_showFracturePath.getValue())
if (this->d_showFracturePath.getValue())
{
const Vec3& dir = d_startDirection.getValue();
const Real& alpha = d_startLength.getValue();
Expand Down

0 comments on commit f996f27

Please sign in to comment.