Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class BeamAdapterActionController : public sofa::component::controller::Mechanic
Data <type::vector<int> > d_actions; ///< List of actions to import or export.
Data <type::vector<std::string> > d_actionString; ///< List of actions to import or export as string.
Data <type::vector<Real> > d_timeSteps; ///< List of key times corresponding to BeamActions in @sa d_actions or @sa d_actionString
Data < int > d_currentAction; ///< current action status for read only from outside of the component. Will be updated at each timestep.

/// Link to the InterventionalRadiologyController, controlling the Beam, to script.
SingleLink<BeamAdapterActionController<DataTypes>, InterventionalRadiologyController<DataTypes>, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_interventionController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ BeamAdapterActionController<DataTypes>::BeamAdapterActionController()
, d_actions(initData(&d_actions, "actions", "List of actions to script the BeamAdapter"))
, d_actionString(initData(&d_actionString, "actionString", "List of actions as string to script the BeamAdapter"))
, d_timeSteps(initData(&d_timeSteps, "timeSteps", "List of key times corresponding to the actions"))
, d_currentAction(initData(&d_currentAction, 0, "currentAction", "Current action applied to the BeamAdapter"))
, l_interventionController(initLink("interventionController", "Path to the InterventionalRadiologyController component on scene"))
{
d_currentAction.setReadOnly(true);
}

template <class DataTypes>
Expand Down Expand Up @@ -77,7 +78,8 @@ void BeamAdapterActionController<DataTypes>::onKeyPressedEvent(core::objectmodel

case 'E':
m_currAction = BeamAdapterAction::NO_ACTION;
m_exportActions = !m_exportActions;
std::cout << "timeSteps='" << d_timeSteps.getValue() << "'" << std::endl;
std::cout << "actions='" << d_actions.getValue() << "'" << std::endl;
break;
case 'D':
m_currAction = BeamAdapterAction::DROP_TOOL;
Expand All @@ -103,6 +105,12 @@ void BeamAdapterActionController<DataTypes>::onKeyPressedEvent(core::objectmodel
case 21: // bas = 21
m_currAction = BeamAdapterAction::MOVE_BACKWARD;
break;
case 'I':
m_currAction = BeamAdapterAction::ACTIVATE_TOOL;
break;
case 'O':
m_currAction = BeamAdapterAction::DEACTIVATE_TOOL;
break;
default:
m_currAction = BeamAdapterAction::NO_ACTION;
break;
Expand Down Expand Up @@ -133,16 +141,13 @@ void BeamAdapterActionController<DataTypes>::onBeginAnimationStep(const double /

ctrl->applyAction(m_currAction);

int currentActionInt = int(m_currAction);
d_currentAction.setValue(currentActionInt);

auto times = sofa::helper::WriteAccessor(d_timeSteps);
auto actions = sofa::helper::WriteAccessor(d_actions);
times.push_back(currentTime);
actions.push_back(int(m_currAction));

if (m_exportActions)
{
std::cout << "timeSteps='" << times.wref() << "'" << std::endl;
std::cout << "actions='" << actions.wref() << "'" << std::endl;
}
actions.push_back(currentActionInt);

m_lastAction = m_currAction;
}
Expand All @@ -155,10 +160,12 @@ void BeamAdapterActionController<DataTypes>::onBeginAnimationStep(const double /

if (currentTime >= time) // check if another key time has been reached and change action
{
m_currAction = BeamAdapterAction(d_actions.getValue()[m_readStep]);
int currentActionInt = d_actions.getValue()[m_readStep];
m_currAction = BeamAdapterAction(currentActionInt);
m_readStep++;

ctrl->applyAction(m_currAction);
d_currentAction.setValue(currentActionInt);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ void InterventionalRadiologyController<DataTypes>::onKeyPressedEvent(KeypressedE
case 'D':
applyAction(BeamAdapterAction::DROP_TOOL);
break;
case '2':
case '3':
applyAction(BeamAdapterAction::USE_TOOL_2);
break;
case '1':
case '2':
applyAction(BeamAdapterAction::USE_TOOL_1);
break;
case '0':
case '1':
applyAction(BeamAdapterAction::USE_TOOL_0);
break;
case 20: // droite = 20
Expand Down
7 changes: 6 additions & 1 deletion src/BeamAdapter/utils/BeamActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace beamadapter
USE_TOOL_0,
USE_TOOL_1,
USE_TOOL_2,
ACTIVATE_TOOL,
DEACTIVATE_TOOL
};

/// \brief map of action as string keyword instead of int for better clarity in scene scripting
Expand All @@ -49,12 +51,15 @@ namespace beamadapter
{"fwd", BeamAdapterAction::MOVE_FORWARD},
{"bwd", BeamAdapterAction::MOVE_BACKWARD},
{"right", BeamAdapterAction::SPIN_RIGHT},
{"left", BeamAdapterAction::SPIN_LEFT},
{"nextT", BeamAdapterAction::SWITCH_NEXT_TOOL},
{"prevT", BeamAdapterAction::SWITCH_PREVIOUS_TOOL},
{"dropT", BeamAdapterAction::DROP_TOOL},
{"tool0", BeamAdapterAction::USE_TOOL_0},
{"tool1", BeamAdapterAction::USE_TOOL_1},
{"tool2", BeamAdapterAction::USE_TOOL_2}
{"tool2", BeamAdapterAction::USE_TOOL_2},
{"activate", BeamAdapterAction::ACTIVATE_TOOL},
{"deactivate", BeamAdapterAction::DEACTIVATE_TOOL}
};

/// static method to convert an action as string into enum class using @sa beamActionNames
Expand Down
Loading