Skip to content

Commit

Permalink
Merge branch 'master' into dev_LnRobotics
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/BeamAdapter/component/controller/AdaptiveBeamController.inl
  • Loading branch information
epernod committed Jul 28, 2023
2 parents a424fa8 + dcb2f74 commit e0897a7
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 114 deletions.
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
8 changes: 2 additions & 6 deletions src/BeamAdapter/component/BeamInterpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,8 @@ 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(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);

int computeTransform(ElementID 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
79 changes: 14 additions & 65 deletions src/BeamAdapter/component/BeamInterpolation.inl
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,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, 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 @@ -639,69 +639,18 @@ 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)
{
/// 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);


/// 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;

}


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(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)
{
dmsg_error() << "[computeTransform2] Error in getNodeIndices(). (Aborting)" ;
dmsg_error() << "[computeTransform] Error in getNodeIndices(). (Aborting)" ;
return -1;
}

Expand Down Expand Up @@ -839,9 +788,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 +957,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 +1072,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 +1141,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 +1298,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
4 changes: 2 additions & 2 deletions src/BeamAdapter/component/WireBeamInterpolation.inl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ bool WireBeamInterpolation<DataTypes>::getApproximateCurvAbs(const Vec3& x_input

// Initialize with the first vertex
Transform globalHlocal0, globalHlocal1;
this->computeTransform2(0, globalHlocal0, globalHlocal1, x);
this->computeTransform(0, globalHlocal0, globalHlocal1, x);
Real closestDist = (x_input-globalHlocal0.getOrigin()).norm2();
Real beamBary = 0.0;
bool projected = false;
Expand All @@ -230,7 +230,7 @@ bool WireBeamInterpolation<DataTypes>::getApproximateCurvAbs(const Vec3& x_input
unsigned int nb = this->getNumBeams();
for(unsigned int i=0; i<nb; i++) // Check each segment and each vertex
{
this->computeTransform2(i, globalHlocal0, globalHlocal1, x);
this->computeTransform(i, globalHlocal0, globalHlocal1, x);
Vec3 A = globalHlocal0.getOrigin(), B = globalHlocal1.getOrigin();
Real r = ((x_input-A) * (B-A)) / (B-A).norm2();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void AdaptiveBeamLengthConstraint<DataTypes>::detectElongation(const VecCoord& x

/// 2. compute the bending angle
Transform Tnode0, Tnode1;
interpolation->computeTransform2(b,Tnode0,Tnode1,x);
interpolation->computeTransform(b,Tnode0,Tnode1,x);
Real angleBeam = interpolation->ComputeTotalBendingRotationAngle(rest_length/10.0, Tnode0, Tnode1,rest_length , 0.0, 1.0);

/// 3. treatment of the different case..
Expand Down Expand Up @@ -164,7 +164,7 @@ void AdaptiveBeamLengthConstraint<DataTypes>::detectElongation(const VecCoord& x
interpolation->getSplinePoints(b,xfree,P0,P1,P2,P3);

Transform global_H_local0_free, global_H_local1_free;
interpolation->computeTransform2(b, global_H_local0_free, global_H_local1_free, xfree);
interpolation->computeTransform(b, global_H_local0_free, global_H_local1_free, xfree);
intervalDef.posFreeEnd = global_H_local0_free.getOrigin(); /// store the free position

intervalDef.rest_length=rest_length_interval; /// store the rest_length
Expand Down Expand Up @@ -231,10 +231,10 @@ void AdaptiveBeamLengthConstraint<DataTypes>::detectElongation(const VecCoord& x
interpolation->getDOFtoLocalTransform(b, DOF0_H_local0, DOF1_H_local1);

Transform global_H_local0, global_H_local1;
interpolation->computeTransform2(b, global_H_local0, global_H_local1, x);
interpolation->computeTransform(b, global_H_local0, global_H_local1, x);

Transform global_H_local0_free, global_H_local1_free;
interpolation->computeTransform2(b, global_H_local0_free, global_H_local1_free, xfree);
interpolation->computeTransform(b, global_H_local0_free, global_H_local1_free, xfree);

intervalDef.dof_H_begin = DOF0_H_local0;
intervalDef.IdxBegin = n0;
Expand Down Expand Up @@ -262,11 +262,11 @@ void AdaptiveBeamLengthConstraint<DataTypes>::detectElongation(const VecCoord& x

Transform global_H_local0, global_H_local1;

interpolation->computeTransform2(b, global_H_local0, global_H_local1, x);
interpolation->computeTransform(b, global_H_local0, global_H_local1, x);


Transform global_H_local0_free, global_H_local1_free;
interpolation->computeTransform2(b, global_H_local0_free, global_H_local1_free, xfree);
interpolation->computeTransform(b, global_H_local0_free, global_H_local1_free, xfree);


intervalDef.dof_H_end = DOF1_H_local1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void AdaptiveBeamSlidingConstraint<DataTypes>::buildConstraintMatrix(const Const

// Position and frame on the curve
interpolation->getBeamAtCurvAbs(m_previousPositions[i], beam, baryCoord);
interpolation->computeTransform2(beam, Tnode0, Tnode1, x1free.ref());
interpolation->computeTransform(beam, Tnode0, Tnode1, x1free.ref());
interpolation->InterpolateTransformUsingSpline(Tresult, baryCoord, Tnode0, Tnode1, interpolation->getLength(beam));
Pos p = Tresult.getOrigin();
Pos dir0, dir1, dir2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void AdaptiveBeamController<DataTypes>::onMouseEvent(MouseEvent *mev)
auto x_instr_tip = sofa::helper::getWriteOnlyAccessor(d_xtip);

if (id >= (int)(x_instr_tip.size())){
msg_warning() << "The instrument number " << id << " do not exist (size =" << x_instr_tip.size() << ") exiting mouse event.";
msg_warning() << "The instrument number " << id << " does not exist (size =" << x_instr_tip.size() << ") exiting mouse event.";
return;
}

Expand Down
Loading

0 comments on commit e0897a7

Please sign in to comment.