From ceb0ca741f10639cbb2f43f3e711356ec3602a53 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 10 Jul 2024 10:03:10 +0900 Subject: [PATCH 1/3] Change ptr to fixedConstraint to Link and Avoid crashing if no FixedConstraint is set for IRC --- .../InterventionalRadiologyController.h | 7 +++- .../InterventionalRadiologyController.inl | 39 ++++++++++++++----- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/BeamAdapter/component/controller/InterventionalRadiologyController.h b/src/BeamAdapter/component/controller/InterventionalRadiologyController.h index 17bf4d0c8..c1a107187 100644 --- a/src/BeamAdapter/component/controller/InterventionalRadiologyController.h +++ b/src/BeamAdapter/component/controller/InterventionalRadiologyController.h @@ -179,7 +179,12 @@ class InterventionalRadiologyController : public MechanicalStateController * m_fixedConstraint; + + SingleLink< + InterventionalRadiologyController, FixedProjectiveConstraint, + BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_fixedConstraint; + DeprecatedAndRemoved m_fixedConstraint; + type::vector m_sensorMotionData; unsigned int m_currentSensorData; type::vector m_nodeCurvAbs; diff --git a/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl b/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl index 221e40a94..cac286cd0 100644 --- a/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl +++ b/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl @@ -70,8 +70,8 @@ InterventionalRadiologyController::InterventionalRadiologyController( , d_rigidCurvAbs(initData(&d_rigidCurvAbs, "rigidCurvAbs", "pairs of curv abs for beams we want to rigidify")) , d_motionFilename(initData(&d_motionFilename, "motionFilename", "text file that includes tracked motion from optical sensor")) , d_indexFirstNode(initData(&d_indexFirstNode, (unsigned int) 0, "indexFirstNode", "first node (should be fixed with restshape)")) +, l_fixedConstraint(initLink("fixedConstraint", "Path to the FixedConstraint")) { - m_fixedConstraint = nullptr; m_sensored =false; } @@ -134,9 +134,29 @@ void InterventionalRadiologyController::init() for(unsigned int i=0; isetControlled(true); - context->get(m_fixedConstraint); - if(m_fixedConstraint==nullptr) - msg_error()<<"No fixedConstraint found."; + if (!l_fixedConstraint) + { + typename FixedProjectiveConstraint::SPtr fixedConstraint{}; + context->get(fixedConstraint); + if (fixedConstraint) + { + l_fixedConstraint.set(fixedConstraint); + } + else + { + msg_error() << "No FixedConstraint found. One will be created on the spot but most likely it will not behave as attended."; + + fixedConstraint = sofa::core::objectmodel::New>(); + context->addObject(fixedConstraint); + fixedConstraint->addConstraint(0); + + l_fixedConstraint.set(fixedConstraint); + + //Instead of create one, it may be more correct to set this component to Invalid + //but the component state is almost never tested.... + //this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); + } + } // the controller must listen to the event (in particular BeginAnimationStep event) if (!f_listening.isSet()) @@ -703,7 +723,6 @@ void InterventionalRadiologyController::applyInterventionalRadiologyC { const Real& threshold = d_threshold.getValue(); - // Create vectors with the CurvAbs of the noticiable points and the id of the corresponding instrument type::vector newCurvAbs; type::vector> idInstrumentTable; @@ -907,11 +926,11 @@ void InterventionalRadiologyController::applyInterventionalRadiologyC if (!rigid) { rigid=true; - m_fixedConstraint->addConstraint(firstSimulatedNode+i); + l_fixedConstraint->addConstraint(firstSimulatedNode+i); } else { - m_fixedConstraint->addConstraint(firstSimulatedNode+i); + l_fixedConstraint->addConstraint(firstSimulatedNode+i); rigid=false; } it++; @@ -922,7 +941,7 @@ void InterventionalRadiologyController::applyInterventionalRadiologyC else { if(rigid) - m_fixedConstraint->addConstraint(firstSimulatedNode+i); + l_fixedConstraint->addConstraint(firstSimulatedNode+i); } } } @@ -1030,12 +1049,12 @@ void InterventionalRadiologyController::fixFirstNodesWithUntil(unsign // set the position to startingPos for all the nodes that are not simulated // and add a fixedConstraint - m_fixedConstraint->clearConstraints(); + l_fixedConstraint->clearConstraints(); for(unsigned int i=0; iaddConstraint(i); + l_fixedConstraint->addConstraint(i); } d_indexFirstNode = firstSimulatedNode-1 ; } From 1726ebad0d865abec06685e1e05ef65040e3748c Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Fri, 12 Jul 2024 17:05:51 +0900 Subject: [PATCH 2/3] Apply suggestions from code review (renaming with FixedProjectiveConstraint) Co-authored-by: Alex Bilger --- .../controller/InterventionalRadiologyController.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl b/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl index cac286cd0..76234a698 100644 --- a/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl +++ b/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl @@ -70,7 +70,7 @@ InterventionalRadiologyController::InterventionalRadiologyController( , d_rigidCurvAbs(initData(&d_rigidCurvAbs, "rigidCurvAbs", "pairs of curv abs for beams we want to rigidify")) , d_motionFilename(initData(&d_motionFilename, "motionFilename", "text file that includes tracked motion from optical sensor")) , d_indexFirstNode(initData(&d_indexFirstNode, (unsigned int) 0, "indexFirstNode", "first node (should be fixed with restshape)")) -, l_fixedConstraint(initLink("fixedConstraint", "Path to the FixedConstraint")) +, l_fixedConstraint(initLink("fixedConstraint", "Path to the FixedProjectiveConstraint")) { m_sensored =false; } @@ -144,7 +144,7 @@ void InterventionalRadiologyController::init() } else { - msg_error() << "No FixedConstraint found. One will be created on the spot but most likely it will not behave as attended."; + msg_error() << "No FixedProjectiveConstraint found. One will be created on the spot but most likely it will not behave as attended."; fixedConstraint = sofa::core::objectmodel::New>(); context->addObject(fixedConstraint); From 67c30876592a3c3cb9e422d526c1b8d2a381c48f Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Thu, 18 Jul 2024 13:57:42 +0900 Subject: [PATCH 3/3] remove creation of fixedconstraint --- .../controller/InterventionalRadiologyController.inl | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl b/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl index 76234a698..7839c8d88 100644 --- a/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl +++ b/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl @@ -144,17 +144,9 @@ void InterventionalRadiologyController::init() } else { - msg_error() << "No FixedProjectiveConstraint found. One will be created on the spot but most likely it will not behave as attended."; + msg_error() << "No FixedProjectiveConstraint found or set. It will most likely lead to a crash."; - fixedConstraint = sofa::core::objectmodel::New>(); - context->addObject(fixedConstraint); - fixedConstraint->addConstraint(0); - - l_fixedConstraint.set(fixedConstraint); - - //Instead of create one, it may be more correct to set this component to Invalid - //but the component state is almost never tested.... - //this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); + this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); } }