@@ -223,27 +223,35 @@ 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 += instrument->getTotalNumberOfPossibleBeams ();
238+ }
239+
240+ if (requiredNumberOfEdges + 1 > 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 ;
237- for (unsigned int i = 0 ; i < m_instrumentsList.size (); i++)
238- {
239- type::vector<Real> xP_noticeable_I;
240- type::vector<sofa::Size> density_I;
241- m_instrumentsList[i]->getSamplingParameters (xP_noticeable_I, density_I);
242-
243- for (auto nb : density_I)
244- nbrBeam += nb;
245- }
246-
247255 applyInterventionalRadiologyController ();
248256
249257 sofa::core::objectmodel::BaseObject::d_componentState.setValue (sofa::core::objectmodel::ComponentState::Valid);
0 commit comments