@@ -223,17 +223,36 @@ void InterventionalRadiologyController<DataTypes>::bwdInit()
223223 stPos.getOrientation ().normalize ();
224224 d_startingPos.setValue (stPos);
225225
226- if (!this ->mState ) {
226+ if (!this ->mState )
227+ {
227228 msg_error () << " No MechanicalState found. The component can not work and will be set to Invalid." ;
228229 sofa::core::objectmodel::BaseObject::d_componentState.setValue (sofa::core::objectmodel::ComponentState::Invalid);
229230 return ;
230231 }
232+
233+ // check if the provided mechanical state and topology can manage our tools
234+ sofa::Size requiredNumberOfEdges = 0 ;
235+ for (const auto * instrument : m_instrumentsList)
236+ {
237+ requiredNumberOfEdges = std::max (instrument->getTotalNumberOfPossibleBeams (), requiredNumberOfEdges);
238+ }
239+
240+ if (requiredNumberOfEdges >= this ->mState ->getSize ())
241+ {
242+ msg_warning () << " The associated Mechanical Object does not contain enough nodes (" << this ->mState ->getSize ()
243+ << " ) whereas the provided tool(s) need(s) at least " << requiredNumberOfEdges + 1 << " nodes." ;
244+ }
245+ if (requiredNumberOfEdges >= this ->l_mechanicalTopology ->getNbEdges ())
246+ {
247+ msg_warning () << " The associated Topology does not contain enough edges (" << this ->l_mechanicalTopology ->getNbEdges ()
248+ << " ) whereas the provided tool(s) need(s) at least " << requiredNumberOfEdges << " edges." ;
249+ }
231250
232251 WriteAccessor<Data<VecCoord> > x = *this ->mState ->write (sofa::core::vec_id::write_access::position);
233252 for (unsigned int i=0 ; i<x.size (); i++)
234253 x[i] = d_startingPos.getValue ();
235254
236- sofa::Size nbrBeam = 0 ;
255+ [[maybe_unused]] sofa::Size nbrBeam = 0 ;
237256 for (unsigned int i = 0 ; i < m_instrumentsList.size (); i++)
238257 {
239258 type::vector<Real> xP_noticeable_I;
0 commit comments