Skip to content

Add motion replay controller component to the INFINYTOOLKIT#41

Open
rmolazem wants to merge 15 commits intoInfinyTech3D:mainfrom
rmolazem:add_motion_replay
Open

Add motion replay controller component to the INFINYTOOLKIT#41
rmolazem wants to merge 15 commits intoInfinyTech3D:mainfrom
rmolazem:add_motion_replay

Conversation

@rmolazem
Copy link

This controller inherits from MechanicalStateController, allowing easy access to the mechanical object’s states after loading all frames at initialization from a CSV file.

The class introduces two new functions:

loadMotion() – Loads all frames from the CSV and stores them in a vector.

handleEvent() – Updates the mechanical object’s positions (grids) according to the loaded frames at each animation step.

However, while compiling SOFA (which includes the infiny toolkit), there is a linking issue: It seems it

cannot inherit from MechanicalStateController and the plugin does not compile. I might have missed some steps to properly register this component inside the InfinyToolkit.

infinyToolkit_linking_Error

P.S. I have updated SOFA from the master branch.



template<class DataTypes>
class MotionReplayController
: public sofa::component::controller::MechanicalStateController<DataTypes>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to inherit directly from sofa::component::controller::Controller or BaseController
MechanicalStateController is already a very complexe specialisation of a simple controller and add a lot of unuseful methods in this case

@rmolazem rmolazem closed this Feb 11, 2026
@epernod
Copy link
Contributor

epernod commented Feb 11, 2026

I guess the closing is a wrong manipulation?

@rmolazem
Copy link
Author

Since the PR was open, and I made some modifications, including changing the base class. I thought it might be cleaner to open a clean PR. Except if you want to follow the history of the changes.
I am going to test the component today with an example scene, then push the final version. I can either re-open this or make a new PR, as you wish.

@epernod
Copy link
Contributor

epernod commented Feb 12, 2026

You can keep the same PR as in any case we only review the change in files which is the final diff between your branch and master: https://github.com/InfinyTech3D/InfinyToolkit/pull/41/changes
And at the end we squash and merge the PR, so after the merge only 1 commit will be visible in the history even if the PR was done with 10 commits

@rmolazem rmolazem reopened this Feb 12, 2026
@rmolazem
Copy link
Author

I conclude that using the SOFA controller slightly increases the FPS.

I compared Scenario 2 for Asan#2 at three stages:

  • When the Judkins is in the middle of the vessel toward the aorta

  • When the guidewire is close to the aorta

  • When the guidewire is inside the right coronary arteries

--> The approximate FPS values are:

Python controller: 66, 37, 22

SOFA controller: 70, 39, 25

private:

sofa::core::objectmodel::DataFileName d_motionFile; /// CSV file containing the frames
sofa::core::objectmodel::Data<double> d_dt; /// Simulation time-step
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this one is useful.
If not you can remove it.

sofa::core::objectmodel::DataFileName d_motionFile; /// CSV file containing the frames
sofa::core::objectmodel::Data<double> d_dt; /// Simulation time-step

sofa::core::behavior::MechanicalState<sofa::defaulttype::Vec3dTypes>* mGridState{nullptr}; ///Controlled grid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to store a link that can be set in the scene file. For example:

SingleLink<ArticulatedToolManager, sofa::core::behavior::BaseMechanicalState, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_targetModel;

and then access it in the init method to check if link is valid. You can keep a pointer and make it equal to the link target.

if (l_targetModel.get() == nullptr)
{
msg_error() << "Error no target mechanical state found";
sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
return;
}


void MotionReplayController::init()
{
mGridState = this->getContext()->get<sofa::core::behavior::MechanicalState<sofa::defaulttype::Vec3dTypes>>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one can be dangerous if the components are not in the same node or if several mechanical objects are present in the same context. This way using link make it safer.

#include <sofa/core/ObjectFactory.h>

#include <InfinyToolkit/MotionReplayController/MotionReplayController.h>
#include <InfinyToolkit/MotionReplayController/MotionReplayController.inl>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the class is not templated anymore, you don't need to put all the methods inline.
The inline methods are only necessary for templated classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments