-
Notifications
You must be signed in to change notification settings - Fork 27
[InterventionalRadiologyController] Fix various potential bugs #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fredroy
wants to merge
6
commits into
sofa-framework:master
Choose a base branch
from
fredroy:fix_various_bugs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2ae10b5
fix out-of-bounds when interpolating a node beyond the previous tip
fredroy 14f5e2f
guard against a negative controlledInstrument
fredroy f1cadb4
guard against an instrument with empty sampling parameters
fredroy 554de0e
fix segRemove sentinel dropping edge index 0
fredroy 00ec57b
bound the STEP 5 rigid-segment loop
fredroy 61a1c7f
Update src/BeamAdapter/component/controller/InterventionalRadiologyCo…
fredroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -372,7 +372,7 @@ void InterventionalRadiologyController<DataTypes>::onBeginAnimationStep(const do | |||||||
| if(m_FF || m_RW) | ||||||||
| { | ||||||||
| int id = d_controlledInstrument.getValue(); | ||||||||
| if (id >= (int)xInstrTip.size()) | ||||||||
| if (id < 0 || id >= (int)xInstrTip.size()) | ||||||||
| { | ||||||||
| msg_warning()<<"Controlled Instument num "<<id<<" does not exist (size ="<< xInstrTip.size() <<") use instrument 0 instead"; | ||||||||
| id=0; | ||||||||
|
|
@@ -406,7 +406,7 @@ template <class DataTypes> | |||||||
| void InterventionalRadiologyController<DataTypes>::applyAction(BeamAdapterAction action) | ||||||||
| { | ||||||||
| int id = d_controlledInstrument.getValue(); | ||||||||
| if (id >= int(m_instrumentsList.size())) | ||||||||
| if (id < 0 || id >= int(m_instrumentsList.size())) | ||||||||
| { | ||||||||
| msg_warning() << "Controlled Instrument num " << id << " does not exist (size =" << m_instrumentsList.size() << ")."; | ||||||||
| return; | ||||||||
|
|
@@ -500,6 +500,14 @@ void InterventionalRadiologyController<DataTypes>::computeInstrumentsCurvAbs(typ | |||||||
| type::vector<sofa::Size> density_I; | ||||||||
| m_instrumentsList[i]->getSamplingParameters(xP_noticeable_I, density_I); // sampling of the different section of this instrument | ||||||||
|
|
||||||||
| // an instrument must provide at least one noticeable point; otherwise the loop below and the | ||||||||
| // final key point access (xP_noticeable_I.size()-1) would read out of bounds. | ||||||||
| if (xP_noticeable_I.empty()) | ||||||||
| { | ||||||||
| msg_error() << "Instrument " << i << " provides no sampling parameters (no noticeable point). Skipping it."; | ||||||||
| continue; | ||||||||
| } | ||||||||
|
|
||||||||
| // check each interval of noticeable point to see if they go out (>0) and use corresponding density to sample the interval. | ||||||||
| for (int j=0; j<(int)(xP_noticeable_I.size()-1); j++) | ||||||||
| { | ||||||||
|
|
@@ -603,10 +611,8 @@ void InterventionalRadiologyController<DataTypes>::interventionalRadiologyCollis | |||||||
| Real xAbsCurv = m_nodeCurvAbs[node]; | ||||||||
| int firstInstruOnx = m_idInstrumentCurvAbsTable[node][0]; | ||||||||
|
|
||||||||
| type::vector<unsigned int> segRemove; | ||||||||
|
|
||||||||
| for (unsigned int it=0; it<m_instrumentsList.size(); it++) | ||||||||
| segRemove.push_back(0); | ||||||||
| // -1 means "nothing to remove" for that instrument | ||||||||
| type::vector<int> segRemove(m_instrumentsList.size(), -1); | ||||||||
|
|
||||||||
| for (int i = static_cast<int>(xPointList.size()) - 1; i>=0; i--) | ||||||||
| { | ||||||||
|
|
@@ -659,7 +665,7 @@ void InterventionalRadiologyController<DataTypes>::interventionalRadiologyCollis | |||||||
|
|
||||||||
| for (unsigned int it=0; it<m_instrumentsList.size(); it++) | ||||||||
| { | ||||||||
| if(segRemove[it]!=0) | ||||||||
| if(segRemove[it]!=-1) | ||||||||
| removeEdge.push_back(segRemove[it]); | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -850,6 +856,11 @@ void InterventionalRadiologyController<DataTypes>::applyInterventionalRadiologyC | |||||||
| break; | ||||||||
| } | ||||||||
|
|
||||||||
| // If no previous node was found beyond xCurvAbs (see the "Case 1" warning above), the loop | ||||||||
| // ends with prev_xId == m_nodeCurvAbs.size(): clamp to the last node to avoid out-of-bounds access. | ||||||||
|
Comment on lines
+859
to
+860
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| if (prev_xId >= m_nodeCurvAbs.size()) | ||||||||
| prev_xId = m_nodeCurvAbs.size() - 1; | ||||||||
|
|
||||||||
| sofa::Index prev_globalNodeId = prev_numberOfUnactiveNodes + prev_xId; | ||||||||
| const Real prev_xCurvAbs = m_nodeCurvAbs[prev_xId]; | ||||||||
|
|
||||||||
|
|
@@ -950,7 +961,8 @@ void InterventionalRadiologyController<DataTypes>::applyInterventionalRadiologyC | |||||||
| { | ||||||||
| RealConstIterator it = rigidCurvAbs->begin(); | ||||||||
|
|
||||||||
| for (unsigned int i=0; i<newCurvAbs.size(); i++) | ||||||||
| // firstSimulatedNode + i indexes into the dofs, so it must stay within [0, numberOfNodes-1] | ||||||||
| for (unsigned int i=0; i<newCurvAbs.size() && (firstSimulatedNode + i) < numberOfNodes; i++) | ||||||||
| { | ||||||||
| if (newCurvAbs[i] < ((*it)+ std::numeric_limits<float>::epsilon()) && newCurvAbs[i] > ((*it)- std::numeric_limits<float>::epsilon())) // node= border of the rigid segment | ||||||||
| { | ||||||||
|
|
||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.