Skip to content

Commit aa9b355

Browse files
committed
add warnings
1 parent 29f94cb commit aa9b355

5 files changed

Lines changed: 24 additions & 16 deletions

File tree

src/BeamAdapter/component/WireBeamInterpolation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class WireBeamInterpolation : public BaseBeamInterpolation<DataTypes>
133133
}
134134

135135
// this is the number of beams which can be simulated according to the rest shape (and its sections)
136-
sofa::Size getTotalNumberOfPossibleBeams()
136+
sofa::Size getTotalNumberOfPossibleBeams() const
137137
{
138138
return this->m_restShape->getTotalNumberOfBeams();
139139
}

src/BeamAdapter/component/WireBeamInterpolation.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void WireBeamInterpolation<DataTypes>::init()
5757
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
5858
return;
5959
}
60-
60+
6161
type::vector<Real> xP_noticeable;
6262
type::vector<sofa::Size> nbP_density;
6363

src/BeamAdapter/component/controller/InterventionalRadiologyController.inl

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/BeamAdapter/component/engine/WireRestShape.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class WireRestShape : public core::objectmodel::BaseObject
111111
void getMechanicalSampling(Real& dx, const Real x_localcurv_abs);
112112
void getCollisionSampling(Real &dx, const Real x_curv);
113113
void getNumberOfCollisionSegment(Real &dx, sofa::Size& numLines);
114-
sofa::Size getTotalNumberOfBeams();
114+
sofa::Size getTotalNumberOfBeams() const;
115115

116116
/////////////////////////// Deprecated Methods //////////////////////////////////////////
117117

src/BeamAdapter/component/engine/WireRestShape.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void WireRestShape<DataTypes>::getNumberOfCollisionSegment(Real &dx, sofa::Size&
290290
}
291291

292292
template <class DataTypes>
293-
sofa::Size WireRestShape<DataTypes>::getTotalNumberOfBeams()
293+
sofa::Size WireRestShape<DataTypes>::getTotalNumberOfBeams() const
294294
{
295295
sofa::Size numBeams = 0;
296296
for (sofa::Size i = 0; i < l_sectionMaterials.size(); ++i)

0 commit comments

Comments
 (0)