Skip to content

Commit de5263e

Browse files
authored
Merge pull request #181 from fredroy/check_x_tip_rot
[IRC] Fix things about xTips
2 parents c1e1464 + 099f0f8 commit de5263e

7 files changed

Lines changed: 107 additions & 53 deletions

examples/SingleBeamDeployment.scn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
<WireBeamInterpolation name="BeamInterpolation" WireRestShape="@../EdgeTopology/BeamRestShape" />
3737
<AdaptiveBeamForceFieldAndMass name="BeamForceField" interpolation="@BeamInterpolation"/>
3838
<InterventionalRadiologyController name="DeployController" template="Rigid3d" instruments="BeamInterpolation"
39-
topology="@MeshLines" startingPos="0 0 0 0 0 0 1" xtip="0 0 0" printLog="1"
40-
rotationInstrument="0 0 0" step="0.5" speed="0.5"
39+
topology="@MeshLines" startingPos="0 0 0 0 0 0 1" xtip="0" printLog="1"
40+
rotationInstrument="0" step="0.5" speed="0.5"
4141
listening="1" controlledInstrument="0"/>
4242
<FixedProjectiveConstraint name="FixedConstraint" indices="0" />
4343
<RestShapeSpringsForceField name="RestSPForceField" points="@DeployController.indexFirstNode" angularStiffness="1e8" stiffness="1e8"/>

examples/SingleBeamDeploymentCollision.scn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
<WireBeamInterpolation name="BeamInterpolation" WireRestShape="@../EdgeTopology/BeamRestShape"/>
5555
<AdaptiveBeamForceFieldAndMass name="BeamForceField" interpolation="@BeamInterpolation"/>
5656
<InterventionalRadiologyController name="DeployController" template="Rigid3d" instruments="BeamInterpolation"
57-
topology="@MeshLines" startingPos="0 0 0 0 0 0 1" xtip="0 0 0" printLog="1"
58-
rotationInstrument="0 0 0" step="5" speed="5"
57+
topology="@MeshLines" startingPos="0 0 0 0 0 0 1" xtip="0" printLog="1"
58+
rotationInstrument="0" step="5" speed="5"
5959
listening="1" controlledInstrument="0"/>
6060
<LinearSolverConstraintCorrection wire_optimization="true" printLog="0" />
6161
<FixedProjectiveConstraint name="FixedConstraint" indices="0" />

examples/Tool_from_loader.scn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<InterventionalRadiologyController name="IRController" template="Rigid3d" listening="true" controlledInstrument="0"
5252
instruments="Interpol_GCatheter" printLog="0"
5353
speed="10" step="1" startingPos="0.0 0.0 0.0 0 0 0 1"
54-
rotationInstrument="0 0 0" xtip="0 0 0"
54+
rotationInstrument="0" xtip="0"
5555
mainDirection="1 0 0"
5656
/>
5757

examples/python3/SingleBeamDeployment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def createScene(rootNode):
4141
BeamMechanics.addObject('WireBeamInterpolation', name='BeamInterpolation', WireRestShape='@../EdgeTopology/BeamRestShape', printLog=False)
4242
BeamMechanics.addObject('AdaptiveBeamForceFieldAndMass', name='BeamForceField', massDensity=0.00000155, interpolation='@BeamInterpolation')
4343
BeamMechanics.addObject('InterventionalRadiologyController', name='DeployController', template='Rigid3d', instruments='BeamInterpolation',
44-
topology="@MeshLines", startingPos=[0, 0, 0, 0, 0, 0, 1], xtip=[0, 0, 0], printLog=True,
45-
rotationInstrument=[0, 0, 0], step=0.5, speed=0.5,
44+
topology="@MeshLines", startingPos=[0, 0, 0, 0, 0, 0, 1], xtip=[0], printLog=True,
45+
rotationInstrument=[0], step=0.5, speed=0.5,
4646
listening=True, controlledInstrument=0)
4747
BeamMechanics.addObject('FixedProjectiveConstraint', indices=0, name='FixedConstraint')
4848
BeamMechanics.addObject('RestShapeSpringsForceField', name="RestSPForceField", points='@DeployController.indexFirstNode', angularStiffness=1e8, stiffness=1e8)

examples/python3/SingleBeamDeploymentCollision.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def createScene(rootNode):
4949
BeamMechanics.addObject('WireBeamInterpolation', name='BeamInterpolation', WireRestShape='@../EdgeTopology/BeamRestShape', printLog=False)
5050
BeamMechanics.addObject('AdaptiveBeamForceFieldAndMass', name='BeamForceField', massDensity=0.00000155, interpolation='@BeamInterpolation')
5151
BeamMechanics.addObject('InterventionalRadiologyController', name='DeployController', template='Rigid3d', instruments='BeamInterpolation',
52-
topology="@MeshLines", startingPos=[0, 0, 0, 0, 0, 0, 1], xtip=[0, 0, 0], printLog=True,
53-
rotationInstrument=[0, 0, 0], step=5., speed=5.,
52+
topology="@MeshLines", startingPos=[0, 0, 0, 0, 0, 0, 1], xtip=[0], printLog=True,
53+
rotationInstrument=[0], step=5., speed=5.,
5454
listening=True, controlledInstrument=0)
5555
BeamMechanics.addObject('LinearSolverConstraintCorrection', wire_optimization='true', printLog=False)
5656
BeamMechanics.addObject('FixedProjectiveConstraint', indices=0, name='FixedConstraint')

src/BeamAdapter/component/controller/InterventionalRadiologyController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class InterventionalRadiologyController : public sofa::component::controller::Me
8686

8787
////////////////////// Inherited from BaseObject ///////////////////////////////////////////////
8888
virtual void init() override ;
89-
virtual void bwdInit() override ;
9089
////////////////////////////////////////////////////////////////////////////////////////////////
9190

9291

src/BeamAdapter/component/controller/InterventionalRadiologyController.inl

Lines changed: 98 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444

4545
#include <BeamAdapter/component/controller/InterventionalRadiologyController.h>
46+
#include <ranges>
4647

4748

4849
namespace beamadapter
@@ -128,6 +129,7 @@ void InterventionalRadiologyController<DataTypes>::init()
128129
{
129130
msg_info() << m_instrumentsList.size() << " instrument(s) found (WireBeamInterpolation)";
130131
}
132+
const auto numberOfInstruments = m_instrumentsList.size();
131133

132134
m_activatedPointsBuf.clear();
133135

@@ -143,15 +145,44 @@ void InterventionalRadiologyController<DataTypes>::init()
143145
loadMotionData(d_motionFilename.getValue());
144146
}
145147

146-
auto x_instr_tip = sofa::helper::getWriteOnlyAccessor(d_xTip);
147-
x_instr_tip.resize(m_instrumentsList.size());
148-
149-
auto angle_Instrument = sofa::helper::getWriteOnlyAccessor(d_rotationInstrument);
150-
angle_Instrument.resize(m_instrumentsList.size());
151-
152-
for(unsigned int i=0; i<m_instrumentsList.size(); i++)
153-
m_instrumentsList[i]->setControlled(true);
148+
auto checkData = [&](auto& data)
149+
{
150+
if(data.isSet())
151+
{
152+
const auto& values = data.getValue();
153+
const auto valueSize = values.size();
154+
155+
if(valueSize != numberOfInstruments)
156+
{
157+
msg_warning() << "Discrepancy for " << data.getName() << " value: it manages " << valueSize << " tools, but there are " << numberOfInstruments << " defined in instrumentPathList.";
158+
if(valueSize > numberOfInstruments)
159+
{
160+
msg_warning() << "The superfluous values will be ignored.";
161+
}
162+
else
163+
{
164+
msg_warning() << "The missing values will be set as zero.";
165+
}
166+
}
167+
}
168+
};
169+
170+
{
171+
checkData(d_xTip);
172+
auto xTip = sofa::helper::getWriteOnlyAccessor(d_xTip);
173+
xTip.resize(numberOfInstruments);
174+
}
175+
{
176+
checkData(d_rotationInstrument);
177+
auto angle_Instrument = sofa::helper::getWriteOnlyAccessor(d_rotationInstrument);
178+
angle_Instrument.resize(numberOfInstruments);
179+
}
154180

181+
for(auto* instrument : m_instrumentsList)
182+
{
183+
instrument->setControlled(true);
184+
}
185+
155186
if (!l_fixedConstraint)
156187
{
157188
typename FixedProjectiveConstraint<DataTypes>::SPtr fixedConstraint{};
@@ -176,49 +207,49 @@ void InterventionalRadiologyController<DataTypes>::init()
176207

177208
m_nodeCurvAbs.clear();
178209
m_idInstrumentCurvAbsTable.clear();
210+
211+
// initiliaze current curvAbs
212+
// if there are to be deployed at start (xtip set) then it should reflect that.
213+
// it should always start with zero (origin)
179214
m_nodeCurvAbs.push_back(0.0);
180-
type::vector<int> listInit;
181-
182-
for(unsigned int i=0; i<m_instrumentsList.size(); i++)
183-
listInit.push_back(int(i));
184-
185-
m_idInstrumentCurvAbsTable.push_back(listInit);
186-
187-
Inherit::init();
188-
189-
sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
190-
}
191-
192-
template<class DataTypes>
193-
void InterventionalRadiologyController<DataTypes>::loadMotionData(std::string filename)
194-
{
195-
if (!helper::system::DataRepository.findFile(filename))
215+
const auto& xTips = d_xTip.getValue();
216+
for(const auto xTip : xTips | std::views::reverse)
196217
{
197-
msg_error() << "File " << filename << " not found.";
198-
return;
218+
if(xTip > 0.0)
219+
{
220+
m_nodeCurvAbs.push_back(xTip);
221+
}
199222
}
200-
std::ifstream file(filename.c_str());
201-
202-
std::string line;
203-
Vec3 result;
204-
while( std::getline(file,line) )
223+
224+
// initialize curvAbsNode <-> instrument ID table
225+
// i,e identify for each "simulated" node the corresponding tool(s)
226+
// if xtip not initialized then only the 0 (origin) node is considered, and has all the tools
227+
// and as before, if they are deployed at start (xtip set), then we need to take it into account
228+
for(sofa::Index i = 0 ; i < m_nodeCurvAbs.size(); i++)
205229
{
206-
if (line.empty())
207-
continue;
208-
std::istringstream values(line);
209-
values >> result[0] >> result[1] >> result[2];
210-
result[0] /= 1000;
211-
m_sensorMotionData.push_back(result);
230+
type::vector<int> listTool;
231+
for(sofa::Index id = 0 ; id < numberOfInstruments ; id++)
232+
{
233+
const auto xTip = xTips[id];
234+
235+
if(xTip >= m_nodeCurvAbs[i])
236+
{
237+
listTool.push_back(id);
238+
}
239+
}
240+
241+
m_idInstrumentCurvAbsTable.push_back(listTool);
212242
}
213243

214-
file.close();
215-
}
244+
245+
type::vector<int> listInit;
246+
for(unsigned int i=0; i<numberOfInstruments; i++)
247+
listInit.push_back(int(i));
216248

249+
m_idInstrumentCurvAbsTable.push_back(listInit);
217250

218-
template <class DataTypes>
219-
void InterventionalRadiologyController<DataTypes>::bwdInit()
220-
{
221-
// assign the starting pos to each point of the Mechanical State
251+
Inherit::init();
252+
222253
Coord stPos =d_startingPos.getValue();
223254
stPos.getOrientation().normalize();
224255
d_startingPos.setValue(stPos);
@@ -257,6 +288,30 @@ void InterventionalRadiologyController<DataTypes>::bwdInit()
257288
sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
258289
}
259290

291+
template<class DataTypes>
292+
void InterventionalRadiologyController<DataTypes>::loadMotionData(std::string filename)
293+
{
294+
if (!helper::system::DataRepository.findFile(filename))
295+
{
296+
msg_error() << "File " << filename << " not found.";
297+
return;
298+
}
299+
std::ifstream file(filename.c_str());
300+
301+
std::string line;
302+
Vec3 result;
303+
while( std::getline(file,line) )
304+
{
305+
if (line.empty())
306+
continue;
307+
std::istringstream values(line);
308+
values >> result[0] >> result[1] >> result[2];
309+
result[0] /= 1000;
310+
m_sensorMotionData.push_back(result);
311+
}
312+
313+
file.close();
314+
}
260315

261316
/*!
262317
* \todo fix the mouse event with better controls

0 commit comments

Comments
 (0)