Skip to content

Commit

Permalink
Merge pull request #149 from InfinyTech3D/fix_BeamInterpolation
Browse files Browse the repository at this point in the history
[src] Use BaseBeamInterpolation in BeamMapping
  • Loading branch information
bakpaul authored Jun 3, 2024
2 parents a56bde0 + 9969630 commit 55fe7c2
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/BeamAdapter/component/BaseBeamInterpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class BaseBeamInterpolation : public virtual sofa::core::objectmodel::BaseObject
virtual void getInterpolationParam(unsigned int edgeInList, Real& _L, Real& _A, Real& _Iy, Real& _Iz,
Real& _Asy, Real& _Asz, Real& J) = 0;
virtual const BeamSection& getBeamSection(int edgeIndex) = 0;

virtual void getBeamAtCurvAbs(const Real& x_input, unsigned int& edgeInList_output, Real& baryCoord_output, unsigned int start = 0);

int computeTransform(const EdgeID edgeInList, Transform& global_H_local0, Transform& global_H_local1, const VecCoord& x);
int computeTransform(const EdgeID edgeInList, const PointID node0Idx, const PointID node1Idx, Transform& global_H_local0, Transform& global_H_local1, const VecCoord& x);
Expand Down
46 changes: 46 additions & 0 deletions src/BeamAdapter/component/BaseBeamInterpolation.inl
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,52 @@ int BaseBeamInterpolation<DataTypes>::computeTransform(const EdgeID edgeInList,
}


template<class DataTypes>
void BaseBeamInterpolation<DataTypes>::getBeamAtCurvAbs(const Real& x_input, unsigned int& edgeInList_output, Real& baryCoord_output, unsigned int start)
{
/// lTotalRest = total length of the
Real lTotalRest = getRestTotalLength();
/// LTotal = length sum of the beams that are "out"
Real LTotal = 0.0;

const unsigned int edgeListSize = this->d_edgeList.getValue().size();

/// we find the length of the beam that is "out"
for (unsigned int e = start; e < edgeListSize; e++)
{
LTotal += this->getLength(e);
}

/// x_i = abs_curv from the begining of the instrument
Real x_i = x_input + LTotal - lTotalRest;

if (x_i < 0.0)
{
edgeInList_output = start;
baryCoord_output = 0;
return;
}

/// we compute the x value of each node :the topology (stored in Edge_list) is supposed to be a regular seq of segment
Real x = 0;

for (unsigned int e = start; e < edgeListSize; e++)
{
x += this->getLength(e);
if (x > x_i)
{
edgeInList_output = e;
Real x0 = x - this->getLength(e);
baryCoord_output = (x_i - x0) / this->getLength(e);
return;
}
}

edgeInList_output = edgeListSize - 1;
baryCoord_output = 1.0;
}


template<class DataTypes>
int BaseBeamInterpolation<DataTypes>::computeTransform(const EdgeID edgeInList, const PointID node0Idx, const PointID node1Idx, Transform& global_H_local0, Transform& global_H_local1, const VecCoord& x)
{
Expand Down
3 changes: 0 additions & 3 deletions src/BeamAdapter/component/WireBeamInterpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ class WireBeamInterpolation : public BaseBeamInterpolation<DataTypes>
bool isControlled() { return m_isControlled; }
void setControlled(bool value) { m_isControlled = value; }

//TODO(dmarchal@cduriez) strange name... seems to be wire based...shouldn't it go to WireBeamInterpolation.
virtual void getBeamAtCurvAbs(const Real& x_input, unsigned int& edgeInList_output, Real& baryCoord_output, unsigned int start = 0);


SingleLink<WireBeamInterpolation<DataTypes>, sofa::component::engine::WireRestShape<DataTypes>,
BaseLink::FLAG_STOREPATH|BaseLink::FLAG_STRONGLINK> m_restShape; /*! link on an external rest-shape*/
Expand Down
45 changes: 0 additions & 45 deletions src/BeamAdapter/component/WireBeamInterpolation.inl
Original file line number Diff line number Diff line change
Expand Up @@ -292,51 +292,6 @@ typename T::SPtr WireBeamInterpolation<DataTypes>::create(T* tObj, core::object
}


template<class DataTypes>
void WireBeamInterpolation<DataTypes>::getBeamAtCurvAbs(const Real& x_input, unsigned int& edgeInList_output, Real& baryCoord_output, unsigned int start)
{
/// lTotalRest = total length of the
Real lTotalRest = getRestTotalLength();
/// LTotal = length sum of the beams that are "out"
Real LTotal = 0.0;

const unsigned int edgeListSize = this->d_edgeList.getValue().size();

/// we find the length of the beam that is "out"
for (unsigned int e = start; e < edgeListSize; e++)
{
LTotal += this->getLength(e);
}

/// x_i = abs_curv from the begining of the instrument
Real x_i = x_input + LTotal - lTotalRest;

if (x_i < 0.0)
{
edgeInList_output = start;
baryCoord_output = 0;
return;
}

/// we compute the x value of each node :the topology (stored in Edge_list) is supposed to be a regular seq of segment
Real x = 0;

for (unsigned int e = start; e < edgeListSize; e++)
{
x += this->getLength(e);
if (x > x_i)
{
edgeInList_output = e;
Real x0 = x - this->getLength(e);
baryCoord_output = (x_i - x0) / this->getLength(e);
return;
}
}

edgeInList_output = edgeListSize - 1;
baryCoord_output = 1.0;
}

} // namespace sofa::component::fem::_wirebeaminterpolation_


8 changes: 4 additions & 4 deletions src/BeamAdapter/component/mapping/AdaptiveBeamMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <sofa/component/topology/container/dynamic/EdgeSetTopologyModifier.h>

#include <BeamAdapter/config.h>
#include <BeamAdapter/component/WireBeamInterpolation.h>
#include <BeamAdapter/component/BaseBeamInterpolation.h>
#include <BeamAdapter/component/controller/AdaptiveBeamController.h>

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -74,7 +74,7 @@ using sofa::type::Vec;
using sofa::type::Mat;
using sofa::core::topology::BaseMeshTopology;
using defaulttype::SolidTypes;
using sofa::component::fem::WireBeamInterpolation;
using sofa::component::fem::BaseBeamInterpolation;
using core::MechanicalParams;
using core::ConstraintParams;
using core::visual::VisualParams;
Expand Down Expand Up @@ -126,7 +126,7 @@ class AdaptiveBeamMapping : public Mapping<TIn, TOut>
typedef Mat<12,3,Real> Mat12x3;
typedef Mat<6,12,Real> Mat6x12;
typedef Mat<12,6,Real> Mat12x6;
typedef WireBeamInterpolation<TIn> BInterpolation;
typedef BaseBeamInterpolation<TIn> BInterpolation;

typedef std::pair<unsigned int, Vec3> BeamIdAndBaryCoord;
struct PosPointDefinition
Expand Down Expand Up @@ -160,7 +160,7 @@ class AdaptiveBeamMapping : public Mapping<TIn, TOut>

AdaptiveBeamMapping(State< In >* from=nullptr,
State< Out >* to=nullptr,
WireBeamInterpolation< TIn >* interpolation=nullptr,
BaseBeamInterpolation< TIn >* interpolation=nullptr,
bool isSubMapping=false) ;

virtual ~AdaptiveBeamMapping() = default;
Expand Down
6 changes: 5 additions & 1 deletion src/BeamAdapter/component/mapping/AdaptiveBeamMapping.inl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ using core::MechanicalParams;

template <class TIn, class TOut>
AdaptiveBeamMapping<TIn,TOut>::AdaptiveBeamMapping(State< In >* from, State< Out >* to,
WireBeamInterpolation< TIn >* interpolation, bool isSubMapping)
BaseBeamInterpolation< TIn >* interpolation, bool isSubMapping)
: Inherit(from, to)
, d_useCurvAbs(initData(&d_useCurvAbs,true,"useCurvAbs","true if the curvilinear abscissa of the points remains the same during the simulation if not the curvilinear abscissa moves with adaptivity and the num of segment per beam is always the same"))
, d_points(initData(&d_points, "points", "defines the mapped points along the beam axis (in beam frame local coordinates)"))
Expand Down Expand Up @@ -95,6 +95,7 @@ void AdaptiveBeamMapping< TIn, TOut>::init()
msg_error() <<"No Beam Interpolation found, the component can not work.";

this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
return;
}

if (d_parallelMapping.getValue())
Expand Down Expand Up @@ -493,6 +494,9 @@ void AdaptiveBeamMapping< TIn, TOut>::applyJT(const core::ConstraintParams* cpar
template <class TIn, class TOut>
void AdaptiveBeamMapping< TIn, TOut>::bwdInit()
{
if (!this->isComponentStateValid())
return;

const auto& pts = d_points.getValue();
const auto ptsSize = pts.size();

Expand Down

0 comments on commit 55fe7c2

Please sign in to comment.