Skip to content
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

Thresholding of isosurface without creating a new one #31

Conversation

chinmaychinara91
Copy link
Collaborator

@chinmaychinara91 chinmaychinara91 commented Aug 9, 2024

  • remove the threshold isosurface slider feature from Surface tab
  • add a pop up UI or maybe a menu item to change isosurface mesh in the figure window itself
  • remove deleting and regeneration of isosurface file rather just update the surface data in the already present file
  • add keyboard shortcut (Shift+uparrow/downarrow) for isovalue change; menu option on popup for fine tuning isovalue
  • verify working with >=R2016b (R2017a used at USC BCI for Polhemus work)

Other related issues:

  • for SEEG implantation, prevent loading multiple instances of the same figure (isosurface+MRI Viewer)

@tmedani

@chinmaychinara91
Copy link
Collaborator Author

chinmaychinara91 commented Aug 9, 2024

@rcassani I have added something like this: keyboard shortcut (Shift+uparrow/downarrow) for coarse isovalue change; menu option on popup for fine isovalue change:

It is ready for review. Might need some more code and GUI cleanups. But if you can test the basic functionalities and let me know I can go forward with cleaning up.

@tmedani

@chinmaychinara91 chinmaychinara91 marked this pull request as ready for review August 9, 2024 22:18
jPanel.add(jButtonSet, BorderLayout.EAST);
java_setcb(spinmodel, 'StateChangedCallback', @(h,ev)tess_isosurface(CtFile, jSpinner.getValue()));
jPanel.add(jSpinner, BorderLayout.EAST);
% jButtonSet = gui_component('button', [], '', 'Set', [], [], @(h,ev)tess_isosurface(CtFile, jSpinner.getValue()));
Copy link
Collaborator Author

@chinmaychinara91 chinmaychinara91 Aug 12, 2024

Choose a reason for hiding this comment

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

for commit 1b99a59 also removed the need to another button click

@rcassani
Copy link
Owner

This crashes if there is already a isoSurface in the Subject's anatomy and CT segmentation is started from CT volume with right-click > CT segmentation > Generate threshold mesh from CT

@chinmaychinara91, @tmedani, Did you use the proposed changes to search for the ideal threshold value from a CT where the ideal threshold is not known?

I did, and I found quite cumbersome to search for the desired threshold value. While the changes in this PR remove the slider from the Surface, the proposed input in the context menu does not accept an arbitrary number just pre-defined +-50 steps with the up/down arrows; similar to the key shortcuts, but for some reason there the steps are +-100.

Let's keep the slider in the Surface tab for now.
What do you think?

@chinmaychinara91
Copy link
Collaborator Author

chinmaychinara91 commented Aug 21, 2024

This crashes if there is already a isoSurface in the Subject's anatomy and CT segmentation is started from CT volume with right-click > CT segmentation > Generate threshold mesh from CT

Fixed. check dc3ccce

@chinmaychinara91, @tmedani, Did you use the proposed changes to search for the ideal threshold value from a CT where the ideal threshold is not known? I did, and I found quite cumbersome to search for the desired threshold value.

So from the feedback from Johnson on how the isoValue threshold is used when doing manual labelling is there is no one isoValue that we can say is the best. There could be some ideal cases but in reality the isovalue threshold might need adjustment while localizing every contact. He has been using 3D slicer to do the same thing and it does something similar but they have a slider feature for threshold and the mesh generation is faster/almost real time there probably because of C++. Maybe we can adjust the numbers from 50/100 to something better.

the proposed input in the context menu does not accept an arbitrary number just pre-defined +-50 steps with the up/down arrows; similar to the key shortcuts, but for some reason there the steps are +-100.

Yes this is not an editable text field rather it reads the current isoValue from the comment and updates it as the initial value. Discussed this with @tmedani, the up down arrows in the context menu can then be used is for fine tuning by +-50. The shortcut keys (shift+up/down) is for a coarser tuning +-100. Just chose these values arbitrarily but we can come up with a better number. Do you think we should have it as an editable field so that people can enter values into it directly?

Let's keep the slider in the Surface tab for now.

I feel we should test and debug this approach and remove the slider option from Surface tab.

Let me know what you think.

@tmedani
Copy link

tmedani commented Aug 21, 2024

Hey guys @chinmaychinara91 @rcassani
Sorry for not being so active here!

From user perspective (and from what we have previously discussed), it is better to have this shortcut active.
(If its implementation is not hurting any other part of the code)

The CTs do not have fixed threshold, each electrode or even each contact may need a different threshold to be visible. Using the shift+up/down is faster for visual inspection and then contact editing, also this is inline with what 3D slicer uses,
and what some clinicians are expecting: just shortcuts and less-click and menus.

As @chinmaychinara91 proposed, we can increase the steps [+/-100] and keep the menu for fine tuning if required.

I will double check with Chinmay later today about the values.

@rcassani
Copy link
Owner

@chinmaychinara91, @tmedani
If you have tested and think that's a good usability, that's ok for me.
Then let me know when the code is read to be reviewed.

@chinmaychinara91 chinmaychinara91 marked this pull request as draft August 23, 2024 23:18
@chinmaychinara91 chinmaychinara91 marked this pull request as ready for review August 23, 2024 23:19
@chinmaychinara91
Copy link
Collaborator Author

@rcassani this is ready for review.

Copy link
Owner

@rcassani rcassani left a comment

Choose a reason for hiding this comment

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

It works as it should. There is a bug with the wrong selection of CT file, this is one of the items reported in the PR (brainstorm-tools#732) and needs to be solved.

While the code does not delete and create a new isosurface file. If does rewrite the content at every change. Is there a value on doing this?

Personally, I found more useful the slider implementation, it allows to do big jumps in the threshold to do binary search of thresholds for identify contacts.

@chinmaychinara91, Did you take a look to the GUI of the "Edit MRI registration" as I asked you before doing these changes?
https://neuroimage.usc.edu/brainstorm/Tutorials/Yokogawa#Refine_the_MRI_registration

We can do this kind of GUI, to provide tools to manipulate the isosurface to locate electrodes, just to mention some:

  • threshold slider
  • presets to thresholds, so once user identifies them
  • turn on/off the centroid option
  • the get coordinates cross (since the iEEG can be open without 3D figures)
  • and others

Also, all the manipulations would not need to save any change in disk, as the relevant information is the electrode positions, not the changes in the isosurface.

(Proof of concept)
image

@tmedani, any thoughts?

Comment on lines +1081 to +1082
% update isoValue threshold (Shift + Up/Down)
elseif ismember('shift', keyEvent.Modifier) && ~isempty(iIsoSurf)
Copy link
Owner

Choose a reason for hiding this comment

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

Simplify to elseif ismember('shift', keyEvent.Modifier), inside that condition, then check if there is CT isosurface, otherwise do nothing.
This leave the option of other shift actions in the future.

Handles = bst_figures('GetFigureHandles', hFig);
% Check if there is SEEG isosurface displayed on the figure
Copy link
Owner

Choose a reason for hiding this comment

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

This will be check in the shift condtion.
See: comment for line 1081

Comment on lines +996 to +997
% Get Surface
TessInfo = getappdata(hFig, 'Surface');
Copy link
Owner

Choose a reason for hiding this comment

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

This will be check in the shift condtion.
See: comment for line 1081

Comment on lines +1083 to +1087
% get the CT file and structure
SubjectFile = getappdata(hFig, 'SubjectFile');
sSubject = bst_get('Subject', SubjectFile);
iCt = find(cellfun(@(x) ~isempty(regexp(x, '_volct', 'match')), {sSubject.Anatomy.FileName}));
CtFile = sSubject.Anatomy(iCt(1)).FileName;
Copy link
Owner

Choose a reason for hiding this comment

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

This is a bug reported in the PR2

Wrong CT volume can be selected thresholding CT with slider
This can happen if there are more than one CT in the Subject. For example is isosurface is create from popmenu on the 2nd CT (in the image below) using the arrows or the popmenu to change the threshold will do it for the 1st CT.

image

A better way to fix this would be to add the filename of the CT that gave origin to the isosurface in the isosurface structure. Maybe in the history

Comment on lines +1698 to +1702
% get the CT file and its structure
SubjectFile = getappdata(hFig, 'SubjectFile');
sSubject = bst_get('Subject', SubjectFile);
iCt = find(cellfun(@(x)(~isempty(regexp(x, '_volct', 'match'))), {sSubject.Anatomy.FileName}));
CtFile = sSubject.Anatomy(iCt(1)).FileName;
Copy link
Owner

Choose a reason for hiding this comment

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

Same potential problem on getting the wrong CT

@chinmaychinara91
Copy link
Collaborator Author

@rcassani thank you for the detailed feedback. I will discuss these with @tmedani and get back to you.

@chinmaychinara91
Copy link
Collaborator Author

chinmaychinara91 commented Sep 11, 2024

@chinmaychinara91, Did you take a look to the GUI of the "Edit MRI registration" as I asked you before doing these changes? https://neuroimage.usc.edu/brainstorm/Tutorials/Yokogawa#Refine_the_MRI_registration

We can do this kind of GUI, to provide tools to manipulate the isosurface to locate electrodes, just to mention some:

  • threshold slider
  • presets to thresholds, so once user identifies them
  • turn on/off the centroid option
  • the get coordinates cross (since the iEEG can be open without 3D figures)
  • and others

Also, all the manipulations would not need to save any change in disk, as the relevant information is the electrode positions, not the changes in the isosurface.

We agree with your proposal. Let me work on it. This sounds more user friendly as well.

@chinmaychinara91
Copy link
Collaborator Author

https://neuroimage.usc.edu/brainstorm/Tutorials/Yokogawa#Refine_the_MRI_registration

We can do this kind of GUI, to provide tools to manipulate the isosurface to locate electrodes

closing this PR. Will start a separate PR based on the above recommendation

@chinmaychinara91 chinmaychinara91 deleted the refactor-updated-ieeg-2 branch November 4, 2024 19:45
@chinmaychinara91 chinmaychinara91 restored the refactor-updated-ieeg-2 branch November 4, 2024 20:08
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.

3 participants