From 9969630957532eeb26f3314db8aaec1769e14c6a Mon Sep 17 00:00:00 2001 From: epernod Date: Fri, 31 May 2024 14:30:21 +0200 Subject: [PATCH] [src] Use BaseBeamInterpolation in BeamMapping and move one remaingin method from wire to BaseBeamInterpolation --- .../component/BaseBeamInterpolation.h | 2 +- .../component/BaseBeamInterpolation.inl | 46 +++++++++++++++++++ .../component/WireBeamInterpolation.h | 3 -- .../component/WireBeamInterpolation.inl | 45 ------------------ .../component/mapping/AdaptiveBeamMapping.h | 8 ++-- .../component/mapping/AdaptiveBeamMapping.inl | 6 ++- 6 files changed, 56 insertions(+), 54 deletions(-) diff --git a/src/BeamAdapter/component/BaseBeamInterpolation.h b/src/BeamAdapter/component/BaseBeamInterpolation.h index 6bdc87ff..3f4fe97d 100644 --- a/src/BeamAdapter/component/BaseBeamInterpolation.h +++ b/src/BeamAdapter/component/BaseBeamInterpolation.h @@ -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); diff --git a/src/BeamAdapter/component/BaseBeamInterpolation.inl b/src/BeamAdapter/component/BaseBeamInterpolation.inl index ba5f99a6..a66ac288 100644 --- a/src/BeamAdapter/component/BaseBeamInterpolation.inl +++ b/src/BeamAdapter/component/BaseBeamInterpolation.inl @@ -257,6 +257,52 @@ int BaseBeamInterpolation::computeTransform(const EdgeID edgeInList, } +template +void BaseBeamInterpolation::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 int BaseBeamInterpolation::computeTransform(const EdgeID edgeInList, const PointID node0Idx, const PointID node1Idx, Transform& global_H_local0, Transform& global_H_local1, const VecCoord& x) { diff --git a/src/BeamAdapter/component/WireBeamInterpolation.h b/src/BeamAdapter/component/WireBeamInterpolation.h index 8c0f3c8d..a875a269 100644 --- a/src/BeamAdapter/component/WireBeamInterpolation.h +++ b/src/BeamAdapter/component/WireBeamInterpolation.h @@ -168,9 +168,6 @@ class WireBeamInterpolation : public BaseBeamInterpolation 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, sofa::component::engine::WireRestShape, BaseLink::FLAG_STOREPATH|BaseLink::FLAG_STRONGLINK> m_restShape; /*! link on an external rest-shape*/ diff --git a/src/BeamAdapter/component/WireBeamInterpolation.inl b/src/BeamAdapter/component/WireBeamInterpolation.inl index 4ce352ab..13751a48 100644 --- a/src/BeamAdapter/component/WireBeamInterpolation.inl +++ b/src/BeamAdapter/component/WireBeamInterpolation.inl @@ -292,51 +292,6 @@ typename T::SPtr WireBeamInterpolation::create(T* tObj, core::object } -template -void WireBeamInterpolation::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_ diff --git a/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.h b/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.h index b87e29f4..939a4f1a 100644 --- a/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.h +++ b/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.h @@ -45,7 +45,7 @@ #include #include -#include +#include #include //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -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; @@ -126,7 +126,7 @@ class AdaptiveBeamMapping : public Mapping typedef Mat<12,3,Real> Mat12x3; typedef Mat<6,12,Real> Mat6x12; typedef Mat<12,6,Real> Mat12x6; - typedef WireBeamInterpolation BInterpolation; + typedef BaseBeamInterpolation BInterpolation; typedef std::pair BeamIdAndBaryCoord; struct PosPointDefinition @@ -160,7 +160,7 @@ class AdaptiveBeamMapping : public Mapping AdaptiveBeamMapping(State< In >* from=nullptr, State< Out >* to=nullptr, - WireBeamInterpolation< TIn >* interpolation=nullptr, + BaseBeamInterpolation< TIn >* interpolation=nullptr, bool isSubMapping=false) ; virtual ~AdaptiveBeamMapping() = default; diff --git a/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.inl b/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.inl index 6d797062..b555475b 100644 --- a/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.inl +++ b/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.inl @@ -66,7 +66,7 @@ using core::MechanicalParams; template AdaptiveBeamMapping::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)")) @@ -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()) @@ -493,6 +494,9 @@ void AdaptiveBeamMapping< TIn, TOut>::applyJT(const core::ConstraintParams* cpar template void AdaptiveBeamMapping< TIn, TOut>::bwdInit() { + if (!this->isComponentStateValid()) + return; + const auto& pts = d_points.getValue(); const auto ptsSize = pts.size();