Skip to content

Commit a3ad75d

Browse files
authored
[IRC] Add checks/warnings at init stage (#178)
* fetch total number of potential beams * add warnings
1 parent efacdc8 commit a3ad75d

7 files changed

Lines changed: 41 additions & 15 deletions

File tree

src/BeamAdapter/component/BeamInterpolation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class BeamInterpolation : public BaseBeamInterpolation<DataTypes>
202202
void getMechanicalSampling(Real& dx, const Real x_localcurv_abs) override;
203203
void getCollisionSampling(Real &dx, const Real x_localcurv_abs) override;
204204
void getNumberOfCollisionSegment(Real &dx, unsigned int &numLines) override;
205-
205+
206206
void setTransformBetweenDofAndNode(const sofa::Index beam, const Transform &DOF_H_Node, unsigned int zeroORone );
207207
void getSplineRestTransform(const EdgeID edgeInList, Transform &local_H_local0_rest, Transform &local_H_local1_rest) override;
208208

src/BeamAdapter/component/BeamInterpolation.inl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ void BeamInterpolation<DataTypes>::getNumberOfCollisionSegment(Real &dx, unsigne
446446
dx = getRestTotalLength()/numLines;
447447
}
448448

449-
450449
template<class DataTypes>
451450
void BeamInterpolation<DataTypes>::getInterpolationParameters(sofa::Index beamId, Real& _L, Real& _A, Real& _Iy,
452451
Real& _Iz, Real& _Asy, Real& _Asz, Real& _J)

src/BeamAdapter/component/WireBeamInterpolation.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ class WireBeamInterpolation : public BaseBeamInterpolation<DataTypes>
131131
{
132132
this->m_restShape->getNumberOfCollisionSegment(dx,numLines);
133133
}
134+
135+
// this is the number of beams which can be simulated according to the rest shape (and its sections)
136+
sofa::Size getTotalNumberOfPossibleBeams() const
137+
{
138+
return this->m_restShape->getTotalNumberOfBeams();
139+
}
134140

135141

136142
virtual void getRestTransform(const EdgeID edgeInList, Transform &local0_H_local1_rest);

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ 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() const;
115+
114116

115117
/////////////////////////// Deprecated Methods //////////////////////////////////////////
116118

src/BeamAdapter/component/engine/WireRestShape.inl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ void WireRestShape<DataTypes>::getNumberOfCollisionSegment(Real &dx, sofa::Size&
289289
dx = getLength() / numLines;
290290
}
291291

292+
template <class DataTypes>
293+
sofa::Size WireRestShape<DataTypes>::getTotalNumberOfBeams() const
294+
{
295+
sofa::Size numBeams = 0;
296+
for (sofa::Size i = 0; i < l_sectionMaterials.size(); ++i)
297+
{
298+
numBeams += l_sectionMaterials.get(i)->getNbBeams();
299+
}
300+
301+
return numBeams;
302+
}
292303

293304
template <class DataTypes>
294305
void WireRestShape<DataTypes>::getRestTransformOnX(Transform &global_H_local, const Real x)

0 commit comments

Comments
 (0)