Skip to content

Commit

Permalink
Merge branch 'master' into BeamMaterial
Browse files Browse the repository at this point in the history
  • Loading branch information
epernod committed Oct 19, 2023
2 parents 24530c4 + bc63e7a commit 10e2988
Show file tree
Hide file tree
Showing 20 changed files with 522 additions and 1,242 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ jobs:
with:
name: ${{ github.ref_name }}
tag_name: release-${{ github.ref_name }}
fail_on_unmatched_files: true
fail_on_unmatched_files: false
target_commitish: ${{ github.ref_name }}
files: |
artifacts/BeamAdapter_*_Linux.zip
artifacts/BeamAdapter_*_Windows.zip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ template <typename DataTypes>
struct AdaptiveBeamSlidingConstraintTest : public sofa::testing::BaseSimulationTest, AdaptiveBeamSlidingConstraint<DataTypes>
{
void normalBehavior(){
Simulation* simu;
setSimulation(simu = new DAGSimulation());
simulation::Simulation* simu = sofa::simulation::getSimulation();
assert(simu);

typename AdaptiveBeamSlidingConstraint<DataTypes>::SPtr thisObject = New<AdaptiveBeamSlidingConstraint<DataTypes>>();
thisObject->setName("myname");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ class InterventionalRadiologyController_test : public BaseTest
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Dynamic");
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Grid");
sofa::simpleapi::importPlugin("Sofa.Component.Constraint.Projective");

m_simu = sofa::simpleapi::createSimulation("DAG");
sofa::simulation::setSimulation(m_simu.get());
m_root = sofa::simpleapi::createRootNode(m_simu, "root");

m_root = sofa::simpleapi::createRootNode(sofa::simulation::getSimulation(), "root");
}

/// Unload the scene
void onTearDown() override
{
if (m_simu != nullptr && m_root != nullptr) {
m_simu->unload(m_root);
if (m_root != nullptr) {
sofa::simulation::node::unload(m_root);
}
}

Expand Down Expand Up @@ -92,8 +90,6 @@ class InterventionalRadiologyController_test : public BaseTest
*/

private:
/// Pointer to SOFA simulation
sofa::simulation::Simulation::SPtr m_simu = nullptr;
/// Pointer to root Node
sofa::simulation::Node::SPtr m_root = nullptr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct AdaptiveBeamForceFieldAndMassTest : public sofa::testing::BaseSimulationT
"</Node> ";

Node::SPtr root = SceneLoaderXML::loadFromMemory("singleBeam", scene.c_str());
sofa::simulation::getSimulation()->init(root.get());
sofa::simulation::node::initRoot(root.get());

return root;
}
Expand Down Expand Up @@ -162,7 +162,7 @@ struct AdaptiveBeamForceFieldAndMassTest : public sofa::testing::BaseSimulationT
auto simulation = sofa::simulation::getSimulation();
for (int i = 0; i < nbrStep; i++)
{
simulation->animate(root.get(), 0.01);
sofa::simulation::node::animate(root.get(), 0.01);
}

// Check position after simulation
Expand All @@ -182,13 +182,12 @@ struct AdaptiveBeamForceFieldAndMassTest : public sofa::testing::BaseSimulationT
double timeMin = std::numeric_limits<double>::max();
double timeMax = std::numeric_limits<double>::min();

auto simulation = sofa::simulation::getSimulation();
for (int i = 0; i < nbrTest; ++i)
{
ctime_t startTime = sofa::helper::system::thread::CTime::getRefTime();
for (int i = 0; i < nbrStep; i++)
{
simulation->animate(root.get(), 0.01);
sofa::simulation::node::animate(root.get(), 0.01);
}

ctime_t diffTime = sofa::helper::system::thread::CTime::getRefTime() - startTime;
Expand All @@ -199,7 +198,7 @@ struct AdaptiveBeamForceFieldAndMassTest : public sofa::testing::BaseSimulationT
if (timeMax < diffTimed)
timeMax = diffTimed;

simulation->reset(root.get());
sofa::simulation::node::reset(root.get());
}
}
};
Expand Down
10 changes: 3 additions & 7 deletions BeamAdapter_test/component/model/WireRestShape_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ class WireRestShape_test : public BaseTest

void onSetUp() override
{
m_simu = sofa::simpleapi::createSimulation("DAG");
sofa::simulation::setSimulation(m_simu.get());
m_root = sofa::simpleapi::createRootNode(m_simu, "root");
m_root = sofa::simpleapi::createRootNode(sofa::simulation::getSimulation(), "root");

sofa::simpleapi::importPlugin("BeamAdapter");
sofa::simpleapi::importPlugin("Sofa.Component.Topology.Container.Dynamic");
Expand All @@ -59,8 +57,8 @@ class WireRestShape_test : public BaseTest
/// Unload the scene
void onTearDown() override
{
if (m_simu != nullptr && m_root != nullptr) {
m_simu->unload(m_root);
if (m_root != nullptr) {
sofa::simulation::node::unload(m_root);
}
}

Expand Down Expand Up @@ -91,8 +89,6 @@ class WireRestShape_test : public BaseTest
void testTransformMethods();

private:
/// Pointer to SOFA simulation
sofa::simulation::Simulation::SPtr m_simu = nullptr;
/// Pointer to root Node
sofa::simulation::Node::SPtr m_root = nullptr;

Expand Down
20 changes: 12 additions & 8 deletions src/BeamAdapter/component/BeamInterpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class BeamInterpolation : public virtual sofa::core::objectmodel::BaseObject
using Transform = typename sofa::defaulttype::SolidTypes<Real>::Transform;
using SpatialVector = typename sofa::defaulttype::SolidTypes<Real>::SpatialVector;

using PointID = BaseMeshTopology::PointID;
using ElementID = BaseMeshTopology::EdgeID;
using VecElementID = type::vector<BaseMeshTopology::EdgeID>;
using VecEdges = type::vector<BaseMeshTopology::Edge>;
Expand Down Expand Up @@ -138,7 +139,6 @@ class BeamInterpolation : public virtual sofa::core::objectmodel::BaseObject
bool verifyTopology();
void computeCrossSectionInertiaMatrix();

unsigned int getNumBeamsNotUnderControl(){return this->m_numBeamsNotUnderControl;}
unsigned int getNumBeams(){return this->d_edgeList.getValue().size();}

void getAbsCurvXFromBeam(int beam, Real& x_curv);
Expand All @@ -154,12 +154,11 @@ class BeamInterpolation : public virtual sofa::core::objectmodel::BaseObject
void getDOFtoLocalTransform(unsigned int edgeInList,Transform &DOF0_H_local0, Transform &DOF1_H_local1);
void getDOFtoLocalTransformInGlobalFrame(unsigned int edgeInList, Transform &DOF0Global_H_local0, Transform &DOF1Global_H_local1, const VecCoord &x);


int computeTransform(const ElementID edgeInList, Transform &global_H_local0, Transform &global_H_local1, const VecCoord &x);
int computeTransform(const ElementID edgeInList, const PointID node0Idx, const PointID node1Idx, Transform& global_H_local0, Transform& global_H_local1, const VecCoord& x);

int computeTransform(unsigned int edgeInList, Transform &global_H0_local, Transform &global_H1_local,
Transform &local0_H_local1, Quat& local_R_local0, const VecCoord &x);

int computeTransform2(unsigned int edgeInList,
Transform &global_H_local0, Transform &global_H_local1, const VecCoord &x);


void getTangent(Vec3& t, const Real& baryCoord,
const Transform &global_H_local0, const Transform &global_H_local1,const Real &L);
Expand Down Expand Up @@ -277,6 +276,13 @@ class BeamInterpolation : public virtual sofa::core::objectmodel::BaseObject
void addCollisionOnBeam(unsigned int b) ;
void clearCollisionOnBeam() ;

/////////////////////////// Deprecated Methods //////////////////////////////////////////
[[deprecated("Releasing catheter or brokenIn2 mode is not anymore supported. Feature has been removed after release v23.06")]]
unsigned int getNumBeamsNotUnderControl() {
msg_warning() << "Releasing catheter or brokenIn2 mode is not anymore supported. Feature has been removed after release v23.06";
return 0;
}

protected :
/// DATA INPUT (that could change in real-time)
using StateDataTypes = sofa::defaulttype::StdVectorTypes< sofa::type::Vec<DataTypes::spatial_dimensions, Real>, sofa::type::Vec<DataTypes::spatial_dimensions, Real>, Real >;
Expand Down Expand Up @@ -324,8 +330,6 @@ protected :

/// this->brokenInTwo = if true, the wire is in two separate parts
bool m_isControlled {false} ;
bool m_brokenInTwo {false} ;
unsigned int m_numBeamsNotUnderControl {0} ;
};

#if !defined(SOFA_PLUGIN_BEAMADAPTER_BEAMINTERPOLATION_CPP)
Expand Down
115 changes: 29 additions & 86 deletions src/BeamAdapter/component/BeamInterpolation.inl
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ BeamInterpolation<DataTypes>::BeamInterpolation() :
, m_topology(nullptr)
, m_mstate(nullptr)
{
m_brokenInTwo=false;
m_isControlled=false;
m_numBeamsNotUnderControl = 0;
m_StateNodes->setName("bezierNodes");
addSlave(m_StateNodes);
}
Expand Down Expand Up @@ -315,7 +313,7 @@ void BeamInterpolation<DataTypes>::bwdInit()
// this transforamtion is given by global_H_local0 for node 0 (and dof0)
// and global_H_local1 for node 1 (and dof1)
Transform global_H_local0, global_H_local1;
computeTransform2(i, global_H_local0, global_H_local1, statePos.ref()) ;
computeTransform(i, nd0Id, nd1Id, global_H_local0, global_H_local1, statePos.ref());
Vec3 beam_segment = global_H_local1.getOrigin() - global_H_local0.getOrigin();
lengthList.push_back(beam_segment.norm());

Expand Down Expand Up @@ -368,8 +366,7 @@ void BeamInterpolation<DataTypes>::reset()
if(d_componentState.getValue()==ComponentState::Invalid)
return ;

bwdInit();
m_numBeamsNotUnderControl=0;
bwdInit();
}

template<class DataTypes>
Expand Down Expand Up @@ -426,22 +423,11 @@ void BeamInterpolation<DataTypes>::clear()
auto DOF1TransformNode1 = sofa::helper::getWriteOnlyAccessor(d_DOF1TransformNode1);
auto curvAbsList = sofa::helper::getWriteOnlyAccessor(d_curvAbsList);

if(m_brokenInTwo)
{
edgeList.resize(m_numBeamsNotUnderControl);
lengthList.resize(m_numBeamsNotUnderControl);
DOF0TransformNode0.resize(m_numBeamsNotUnderControl);
DOF1TransformNode1.resize(m_numBeamsNotUnderControl);
curvAbsList.resize(m_numBeamsNotUnderControl);
}
else
{
edgeList.clear();
lengthList.clear();
DOF0TransformNode0.clear();
DOF1TransformNode1.clear();
curvAbsList.clear();
}
edgeList.clear();
lengthList.clear();
DOF0TransformNode0.clear();
DOF1TransformNode1.clear();
curvAbsList.clear();
}


Expand Down Expand Up @@ -639,82 +625,39 @@ void BeamInterpolation<DataTypes>::getDOFtoLocalTransformInGlobalFrame(unsigned
}



template<class DataTypes>
int BeamInterpolation<DataTypes>::computeTransform(unsigned int edgeInList,
Transform &global_H0_local,
Transform &global_H1_local,
Transform &local0_H_local1,
Quat &local_R_local0,
const VecCoord &x)
int BeamInterpolation<DataTypes>::computeTransform(const ElementID edgeInList,
Transform &global_H_local0,
Transform &global_H_local1,
const VecCoord &x)
{
/// 1. Get the indices of element and nodes
unsigned int node0Idx, node1Idx;
if (getNodeIndices( edgeInList, node0Idx, node1Idx ) == -1)
if ( getNodeIndices( edgeInList, node0Idx, node1Idx ) == -1)
{
dmsg_error() << "[computeTransform2] Error in getNodeIndices(). (Aborting)" ;
dmsg_error() << "[computeTransform] Error in getNodeIndices(). (Aborting)" ;
return -1;
}

/// 2. Computes the optional rigid transformation of DOF0_Transform_node0 and DOF1_Transform_node1
Transform DOF0_H_local0, DOF1_H_local1;
getDOFtoLocalTransform(edgeInList, DOF0_H_local0, DOF1_H_local1);


/// 3. Computes the transformation global To local for both nodes
Transform global_H_DOF0(x[node0Idx].getCenter(), x[node0Idx].getOrientation());
Transform global_H_DOF1(x[node1Idx].getCenter(), x[node1Idx].getOrientation());

/// - add a optional transformation
Transform global_H_local0 = global_H_DOF0*DOF0_H_local0;
Transform global_H_local1 = global_H_DOF1*DOF1_H_local1;


/// 4. Compute the local frame
/// SIMPLIFICATION: local = local0:
local_R_local0.clear();

global_H_DOF0.set(Vec3(0,0,0), x[node0Idx].getOrientation());
global_H_DOF1.set(Vec3(0,0,0), x[node1Idx].getOrientation());

/// - rotation due to the optional transformation
global_H_local0 = global_H_DOF0*DOF0_H_local0;
global_H_local1 = global_H_DOF1*DOF1_H_local1;

global_H0_local = global_H_local0;
Quat local0_R_local1 = local0_H_local1.getOrientation();
Transform local0_HR_local1(Vec3(0,0,0), local0_R_local1);

global_H1_local = global_H_local1 * local0_HR_local1.inversed();

return 1;

return computeTransform(edgeInList, node0Idx, node1Idx, global_H_local0, global_H_local1, x);
}


template<class DataTypes>
int BeamInterpolation<DataTypes>::computeTransform2(unsigned int edgeInList,
Transform &global_H_local0,
Transform &global_H_local1,
const VecCoord &x)
int BeamInterpolation<DataTypes>::computeTransform(const ElementID edgeInList, const PointID node0Idx, const PointID node1Idx, Transform& global_H_local0, Transform& global_H_local1, const VecCoord& x)
{
/// 1. Get the indices of element and nodes
unsigned int node0Idx, node1Idx;
if ( getNodeIndices( edgeInList, node0Idx, node1Idx ) == -1)
{
dmsg_error() << "[computeTransform2] Error in getNodeIndices(). (Aborting)" ;
return -1;
}

/// 2. Computes the optional rigid transformation of DOF0_Transform_node0 and DOF1_Transform_node1
Transform DOF0_H_local0, DOF1_H_local1;
getDOFtoLocalTransform(edgeInList, DOF0_H_local0, DOF1_H_local1);
getDOFtoLocalTransform(edgeInList, DOF0_H_local0, DOF1_H_local1);

/// 3. Computes the transformation global To local for both nodes
Transform global_H_DOF0(x[node0Idx].getCenter(),x[node0Idx].getOrientation());
Transform global_H_DOF1(x[node1Idx].getCenter(),x[node1Idx].getOrientation());
Transform global_H_DOF0(x[node0Idx].getCenter(), x[node0Idx].getOrientation());
Transform global_H_DOF1(x[node1Idx].getCenter(), x[node1Idx].getOrientation());
/// - add a optional transformation
global_H_local0 = global_H_DOF0*DOF0_H_local0;
global_H_local1 = global_H_DOF1*DOF1_H_local1;
global_H_local0 = global_H_DOF0 * DOF0_H_local0;
global_H_local1 = global_H_DOF1 * DOF1_H_local1;

return 1; /// no error
}
Expand Down Expand Up @@ -839,9 +782,9 @@ template<class DataTypes>
void BeamInterpolation<DataTypes>::getSplinePoints(unsigned int edgeInList, const VecCoord &x, Vec3& P0, Vec3& P1, Vec3& P2, Vec3 &P3)
{
Transform global_H_local0, global_H_local1;
if (computeTransform2(edgeInList, global_H_local0, global_H_local1, x) == -1)
if (computeTransform(edgeInList, global_H_local0, global_H_local1, x) == -1)
{
dmsg_error() << "[getSplinePoints] error with computeTransform2. (Aborting)" ;
dmsg_error() << "[getSplinePoints] error with computeTransform. (Aborting)" ;
return;
}

Expand Down Expand Up @@ -1008,9 +951,9 @@ void BeamInterpolation<DataTypes>::interpolatePointUsingSpline(unsigned int edge
}
else
{
/// \todo remove call to computeTransform2 => make something faster !
/// \todo remove call to computeTransform => make something faster !
Transform global_H_local0, global_H_local1;
computeTransform2(edgeInList, global_H_local0, global_H_local1, x);
computeTransform(edgeInList, global_H_local0, global_H_local1, x);
Vec3 DP=global_H_local0.getOrigin() - global_H_local1.getOrigin();

if( DP.norm()< _L*0.01 )
Expand Down Expand Up @@ -1123,7 +1066,7 @@ void BeamInterpolation<DataTypes>::updateBezierPoints( const VecCoord &x,unsigne
/// \todo remove call to
/// nsform2 => make something faster !
Transform global_H_local0, global_H_local1;
computeTransform2(index, global_H_local0, global_H_local1, x);
computeTransform(index, global_H_local0, global_H_local1, x);

///Mechanical Object to stock Bezier points
bezierPosVec[index*4] =global_H_local0.getOrigin(); //P0
Expand Down Expand Up @@ -1192,7 +1135,7 @@ void BeamInterpolation<DataTypes>::updateInterpolation(){

/// convert position (RigidTypes) in Transform
Transform global_H_local0, global_H_local1;
computeTransform2(numBeam, global_H_local0, global_H_local1, x->getValue() );
computeTransform(numBeam, global_H_local0, global_H_local1, x->getValue() );

/// compute the length of the spline
Vec3 P0,P1,P2,P3;
Expand Down Expand Up @@ -1349,9 +1292,9 @@ void BeamInterpolation<DataTypes>::InterpolateTransformUsingSpline(unsigned int
Transform &global_H_localInterpol)
{
Transform global_H_local0, global_H_local1;
if (computeTransform2(edgeInList, global_H_local0, global_H_local1, x) == -1)
if (computeTransform(edgeInList, global_H_local0, global_H_local1, x) == -1)
{
msg_error() << "[InterpolateTransformUsingSpline] error with computeTransform2. (Aborting). " ;
msg_error() << "[InterpolateTransformUsingSpline] error with computeTransform. (Aborting). " ;
return;
}

Expand Down
Loading

0 comments on commit 10e2988

Please sign in to comment.