@@ -96,8 +96,9 @@ void BaseBeamInterpolation<DataTypes>::RotateFrameForAlignNormalizedX(const Quat
9696
9797
9898template <class DataTypes >
99- BaseBeamInterpolation<DataTypes>::BaseBeamInterpolation(/* sofa::component::engine::WireRestShape<DataTypes> *_restShape*/ )
100- : m_StateNodes(sofa::core::objectmodel::New< sofa::component::statecontainer::MechanicalObject<StateDataTypes> >())
99+ BaseBeamInterpolation<DataTypes>::BaseBeamInterpolation()
100+ : Inherit()
101+ , m_StateNodes(sofa::core::objectmodel::New< sofa::component::statecontainer::MechanicalObject<StateDataTypes> >())
101102 , d_edgeList(initData(&d_edgeList, " edgeList" , " list of the edge in the topology that are concerned by the Interpolation" ))
102103 , d_lengthList(initData(&d_lengthList, " lengthList" , " list of the length of each beam" ))
103104 , d_DOF0TransformNode0(initData(&d_DOF0TransformNode0, " DOF0TransformNode0" , " Optional rigid transformation between the degree of Freedom and the first node of the beam" ))
@@ -106,49 +107,43 @@ BaseBeamInterpolation<DataTypes>::BaseBeamInterpolation(/*sofa::component::engin
106107 , d_beamCollision(initData(&d_beamCollision, " beamCollision" , " list of beam (in edgeList) that needs to be considered for collision" ))
107108 , d_dofsAndBeamsAligned(initData(&d_dofsAndBeamsAligned, true , " dofsAndBeamsAligned" ,
108109 " if false, a transformation for each beam is computed between the DOF and the beam nodes" ))
109- , m_topology(nullptr )
110- , m_mstate(nullptr )
110+ , l_topology(initLink(" topology" , " link to the topology (must contain edges)" ))
111111{
112112
113-
114113 m_StateNodes->setName (" bezierNodes" );
115- addSlave (m_StateNodes);
114+ this -> addSlave (m_StateNodes);
116115}
117116
118117
119118template <class DataTypes >
120119void BaseBeamInterpolation<DataTypes>::init()
121120{
122121 Inherit::init ();
123-
124- BaseContext* context = getContext ();
125-
126- m_mstate = dynamic_cast <sofa::core::behavior::MechanicalState<DataTypes> *> (context->getMechanicalState ());
127- if (m_mstate == nullptr )
122+
123+ if (!l_topology)
128124 {
129- msg_error () << " No MechanicalState found. Component is de-activated." ;
130- d_componentState.setValue (ComponentState::Invalid);
131- return ;
125+ l_topology.set (this ->getMState ()->getContext ()->getMeshTopologyLink ());
132126 }
133127
134- // / Get the topology from context and check if it is valid.
135- m_topology = context->getMeshTopology ();
136- if (!m_topology)
128+ if (l_topology)
129+ {
130+ msg_info () << " Found topology named " << l_topology->getName () ;
131+ }
132+ else
137133 {
138- msg_error () << " No Topology found. Component is de-activated ." ;
139- d_componentState.setValue (ComponentState::Invalid);
134+ msg_error () << " Cannot find a topology container. Please specify the link to the topology or insert one in the same node ." ;
135+ this -> d_componentState .setValue (ComponentState::Invalid);
140136 return ;
141137 }
142-
143- // / Check the topology properties
144- if (m_topology->getNbEdges () == 0 )
138+
139+ if (l_topology->getNbEdges () == 0 )
145140 {
146- msg_error () << " Found a topology but it is empty. Component is de-activated" ;
147- d_componentState.setValue (ComponentState::Invalid);
141+ msg_error () << " Found a topology but it is empty (no edges) . Component is de-activated" ;
142+ this -> d_componentState .setValue (ComponentState::Invalid);
148143 return ;
149144 }
150-
151- m_topologyEdges = &m_topology-> getEdges ( );
145+
146+ this -> d_componentState . setValue (sofa::core::objectmodel::ComponentState::Valid );
152147}
153148
154149
@@ -266,7 +261,7 @@ void BaseBeamInterpolation<DataTypes>::getBeamAtCurvAbs(const Real x_input, unsi
266261 // / LTotal = length sum of the beams that are "out"
267262 Real LTotal = 0.0 ;
268263
269- const unsigned int edgeListSize = this ->d_edgeList .getValue ().size ();
264+ const sofa::Size edgeListSize = static_cast <sofa::Size>( this ->d_edgeList .getValue ().size () );
270265
271266 // / we find the length of the beam that is "out"
272267 for (unsigned int e = start; e < edgeListSize; e++)
@@ -360,7 +355,7 @@ void BaseBeamInterpolation<DataTypes>::getDOFtoLocalTransformInGlobalFrame(const
360355template <class DataTypes >
361356void BaseBeamInterpolation<DataTypes>::setTransformBetweenDofAndNode(const sofa::Index beam, const Transform& DOF_H_Node, unsigned int zeroORone)
362357{
363- if (beam > int (d_DOF0TransformNode0.getValue ().size () - 1 ) || beam > int (d_DOF1TransformNode1.getValue ().size () - 1 ))
358+ if (beam > (d_DOF0TransformNode0.getValue ().size () - 1 ) || beam > (d_DOF1TransformNode1.getValue ().size () - 1 ))
364359 {
365360 msg_error () << " WARNING setTransformBetweenDofAndNode on non existing beam" ;
366361 return ;
@@ -402,15 +397,15 @@ int BaseBeamInterpolation<DataTypes>::getNodeIndices(const EdgeID edgeInList,
402397 unsigned int & node0Idx,
403398 unsigned int & node1Idx)
404399{
405- if (m_topologyEdges == nullptr )
400+ if (! this -> isComponentStateValid () )
406401 {
407- msg_error () << " This object does not have edge topology defined (computation halted) . " ;
402+ msg_error () << " (getNodeIndices) This component is invalid, check the other error messages . " ;
408403 return -1 ;
409404 }
410405
411406 // / 1. Get the indices of element and nodes
412407 const EdgeID& e = d_edgeList.getValue ()[edgeInList];
413- const BaseMeshTopology::Edge& edge = (*m_topologyEdges)[e] ;
408+ const BaseMeshTopology::Edge& edge = l_topology-> getEdge (e) ;
414409 node0Idx = edge[0 ];
415410 node1Idx = edge[1 ];
416411
@@ -437,14 +432,14 @@ void BaseBeamInterpolation<DataTypes>::getSplinePoints(const EdgeID edgeInList,
437432template <class DataTypes >
438433unsigned int BaseBeamInterpolation<DataTypes>::getStateSize() const
439434{
440- if (m_mstate == nullptr )
435+ if (! this -> isComponentStateValid () )
441436 {
442- msg_error () << " No _mstate found (Aborting) " ;
437+ msg_error () << " (getStateSize) This component is invalid, check the other error messages. " ;
443438 return 0 ;
444439 }
445440 else
446441 {
447- return m_mstate ->getSize ();
442+ return this -> getMState () ->getSize ();
448443 }
449444}
450445
@@ -582,22 +577,24 @@ void BaseBeamInterpolation<DataTypes>::computeStrechAndTwist(const EdgeID edgeIn
582577
583578// /vId_Out provides the id of the multiVecId which stores the position of the Bezier Points
584579template <class DataTypes >
585- void BaseBeamInterpolation<DataTypes>::updateBezierPoints(const VecCoord& x, sofa::core::VecCoordId& vId_Out) {
580+ void BaseBeamInterpolation<DataTypes>::updateBezierPoints(const VecCoord& x, sofa::core::VecCoordId& vId_Out)
581+ {
582+ const sofa::Size edgeListSize = static_cast <sofa::Size>(d_edgeList.getValue ().size ());
586583 // /Mechanical Object to stock Bezier points.
587- m_StateNodes->resize (d_edgeList. getValue (). size () * 4 );
584+ m_StateNodes->resize (edgeListSize * 4 );
588585 auto bezierPosVec = sofa::helper::getWriteOnlyAccessor (*m_StateNodes->write (vId_Out));
589- bezierPosVec.resize (d_edgeList. getValue (). size () * 4 );
586+ bezierPosVec.resize (edgeListSize * 4 );
590587
591- for (unsigned int i = 0 ; i < d_edgeList. getValue (). size () ; i++) {
588+ for (unsigned int i = 0 ; i < edgeListSize ; i++) {
592589 updateBezierPoints (x, i, bezierPosVec.wref ());
593590
594591 }
595592}
596593
597594template <class DataTypes >
598595void BaseBeamInterpolation<DataTypes>::updateBezierPoints(const VecCoord& x, unsigned int index,
599- VectorVec3& bezierPosVec) {
600- // / <<" interpolatePointUsingSpline : "<< edgeInList<<" xbary="<<baryCoord<<" localPos"<<localPos<<std::endl;
596+ VectorVec3& bezierPosVec)
597+ {
601598 const Real _L = d_lengthList.getValue ()[index];
602599
603600 // / \todo remove call to
0 commit comments