Skip to content

Commit

Permalink
ENH: ROI Generated from Model bounds
Browse files Browse the repository at this point in the history
TO DO: Use model bounds and input Volume to generate subvolume
  • Loading branch information
amymmorton committed Dec 11, 2024
1 parent f093d1d commit a9b751f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="inputModel_label">
<property name="text">
<string>Input model</string>
</property>
Expand Down Expand Up @@ -56,31 +56,25 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="inputVol_label">
<property name="text">
<string>Image threshold:</string>
<string>Input Volume</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="ctkSliderWidget" name="imageThresholdSliderWidget">
<property name="toolTip">
<string>Set threshold value for computing the output image. Voxels that have intensities lower than this value will set to zero.</string>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="minimum">
<double>-100.000000000000000</double>
<widget class="qMRMLNodeComboBox" name="inputVolumeSelector">
<property name="nodeTypes">
<stringlist notr="true"/>
</property>
<property name="maximum">
<double>500.000000000000000</double>
<property name="hideChildNodeTypes">
<stringlist notr="true"/>
</property>
<property name="value">
<double>0.500000000000000</double>
<property name="interactionNodeSingletonTag">
<string notr="true"/>
</property>
<property name="SlicerParameterName" stdset="0">
<string>imageThreshold</string>
<string>inputVolume</string>
</property>
</widget>
</item>
Expand All @@ -96,18 +90,18 @@
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Thresholded volume:</string>
<string>Model ROI</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="qMRMLNodeComboBox" name="outputSelector">
<widget class="qMRMLNodeComboBox" name="modelROISelector">
<property name="toolTip">
<string>Pick the output to the algorithm.</string>
</property>
<property name="nodeTypes">
<stringlist notr="true">
<string>vtkMRMLScalarVolumeNode</string>
<stringlist>
<string>vtkMRMLMarkupsROINode</string>
</stringlist>
</property>
<property name="showChildNodeTypes">
Expand All @@ -123,19 +117,19 @@
<bool>true</bool>
</property>
<property name="SlicerParameterName" stdset="0">
<string>thresholdedVolume</string>
<string>modelROI</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Inverted volume:</string>
<string>Cropped volume:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="qMRMLNodeComboBox" name="invertedOutputSelector">
<widget class="qMRMLNodeComboBox" name="cropVolSelector">
<property name="toolTip">
<string>Result with inverted threshold will be written into this volume</string>
</property>
Expand All @@ -157,39 +151,7 @@
<bool>true</bool>
</property>
<property name="SlicerParameterName" stdset="0">
<string>invertedVolume</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="ctkCollapsibleButton" name="advancedCollapsibleButton">
<property name="text">
<string>Advanced</string>
</property>
<property name="collapsed">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Invert threshold: </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="invertOutputCheckBox">
<property name="toolTip">
<string>If checked, values above threshold are set to 0. If unchecked, values below are set to 0.</string>
</property>
<property name="text">
<string/>
</property>
<property name="invertThreshold" stdset="0">
<string/>
<string>croppedVolume</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -231,11 +193,6 @@
<header>ctkCollapsibleButton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ctkSliderWidget</class>
<extends>QWidget</extends>
<header>ctkSliderWidget.h</header>
</customwidget>
<customwidget>
<class>qMRMLNodeComboBox</class>
<extends>QWidget</extends>
Expand Down Expand Up @@ -269,7 +226,7 @@
<connection>
<sender>roiFromModelBounds</sender>
<signal>mrmlSceneChanged(vtkMRMLScene*)</signal>
<receiver>outputSelector</receiver>
<receiver>modelROISelector</receiver>
<slot>setMRMLScene(vtkMRMLScene*)</slot>
<hints>
<hint type="sourcelabel">
Expand All @@ -285,7 +242,7 @@
<connection>
<sender>roiFromModelBounds</sender>
<signal>mrmlSceneChanged(vtkMRMLScene*)</signal>
<receiver>invertedOutputSelector</receiver>
<receiver>cropVolSelector</receiver>
<slot>setMRMLScene(vtkMRMLScene*)</slot>
<hints>
<hint type="sourcelabel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Annotated, Optional

import vtk
import numpy as np

import slicer
from slicer.i18n import tr as _
Expand All @@ -16,6 +17,7 @@

from slicer import vtkMRMLScalarVolumeNode
from slicer import vtkMRMLModelNode
from slicer import vtkMRMLMarkupsROINode


#
Expand All @@ -32,18 +34,18 @@ def __init__(self, parent):
ScriptedLoadableModule.__init__(self, parent)
self.parent.title = _("roiFromModelBounds") # TODO: make this more human readable by adding spaces
# TODO: set categories (folders where the module shows up in the module selector)
self.parent.categories = [translate("qSlicerAbstractCoreModule", "Examples")]
self.parent.categories = ["Tracking"]
self.parent.dependencies = [] # TODO: add here list of module names that this module requires
self.parent.contributors = ["John Doe (AnyWare Corp.)"] # TODO: replace with "Firstname Lastname (Organization)"
# TODO: update with short description of the module and a link to online module documentation
self.parent.contributors = ["Amy Morton (Brown University)"]

# _() function marks text as translatable to other languages
self.parent.helpText = _("""
This is an example of scripted loadable module bundled in an extension.
See more information in <a href="https://github.com/organization/projectname#roiFromModelBounds">module documentation</a>.
WIP modeule part of SlicerAutoscoperM
Intended to act as foundation fro subvolume 3d-3d volume registration
""")
# TODO: replace with organization, grant and thanks
self.parent.acknowledgementText = _("""
This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc., Andras Lasso, PerkLab,
Template for this file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc., Andras Lasso, PerkLab,
and Steve Pieper, Isomics, Inc. and was partially funded by NIH grant 3P41RR013218-12S1.
""")

Expand Down Expand Up @@ -112,17 +114,16 @@ class roiFromModelBoundsParameterNode:
The parameters needed by module.
inputModel- The vtk poly model to compute bounds.
imageThreshold - The value at which to threshold the input volume.
invertThreshold - If true, will invert the threshold.
thresholdedVolume - The output volume that will contain the thresholded volume.
invertedVolume - The output volume that will contain the inverted thresholded volume.
inputVolume- Voume for ROI crop
modelROI - The output volume that will contain the thresholded volume.
croppedVolume - The output volume that will be .
"""

inputModel: vtkMRMLModelNode
imageThreshold: Annotated[float, WithinRange(-100, 500)] = 100
invertThreshold: bool = False
thresholdedVolume: vtkMRMLScalarVolumeNode
invertedVolume: vtkMRMLScalarVolumeNode
inputVolume: vtkMRMLScalarVolumeNode
modelBounds: float
modelROI: vtkMRMLMarkupsROINode
croppedVolume: vtkMRMLScalarVolumeNode


#
Expand Down Expand Up @@ -234,7 +235,7 @@ def setParameterNode(self, inputParameterNode: Optional[roiFromModelBoundsParame
self._checkCanApply()

def _checkCanApply(self, caller=None, event=None) -> None:
if self._parameterNode and self._parameterNode.inputModel and self._parameterNode.thresholdedVolume:
if self._parameterNode and self._parameterNode.inputModel and self._parameterNode.modelROI:
self.ui.applyButton.toolTip = _("Compute output volume")
self.ui.applyButton.enabled = True
else:
Expand All @@ -257,8 +258,9 @@ def onApplyButton(self) -> None:
def onShowModelBoundsButton(self) -> None:
with slicer.util.tryWithErrorDisplay(_("Failed to compute results."), waitCursor=True):
# Compute output
tabRas = [0.0,0.0,0.0,0.0,0.0,0.0]
self.logic.modelBounds(self.ui.inputSelector.currentNode(),tabRas)

self.logic.modelBounds(self.ui.inputSelector.currentNode(),self.ui.inputVolumeSelector,
self.ui.modelROISelector, self.ui.cropVolSelector)

#
# roiFromModelBoundsLogic
Expand All @@ -283,11 +285,43 @@ def getParameterNode(self):
return roiFromModelBoundsParameterNode(super().getParameterNode())

def modelBounds(self,
inputModel:vtkMRMLModelNode,
tB: float ) -> None:

inputModel.GetRASBounds(tB)
print(tB)
inputModel:vtkMRMLModelNode,
inputVolume: vtkMRMLScalarVolumeNode,
modelROI: vtkMRMLMarkupsROINode,
croppedVolume: vtkMRMLScalarVolumeNode) -> None:

tB = [0.0,0.0,0.0,0.0,0.0,0.0]
inputModel.GetBounds(tB)
#print(tB)
modelC = [0.0]*3
modelSize = [0.0]*3
#strange that the model nodes have a getBounds- but no center and size..
#and the roi has bno.. set Bounds- just center and size

#numpy for array operatots:
tnp_min = np.array([tB[0],tB[2],tB[4]])
tnp_max = np.array([tB[1],tB[3],tB[5]])

tnp_C = (tnp_min+tnp_max)/2
tnpS = (tnp_min-tnp_max)

#inputModel.GetCenter(modelC)
#inputModel.GetSize(modelSize)
mname = inputModel.GetName()

#use tB lims to size roi
#Create ROI node
modelROI = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsROINode")
modelROI.SetCenter(tnp_C.tolist())
modelROI.SetSize(tnpS.tolist())
modelROI.CreateDefaultDisplayNodes() # only needed for display

roi_name =mname+"_roi"
modelROI.SetName(roi_name)

#populate in Model ROI Output

#print(modelROI)



Expand Down

0 comments on commit a9b751f

Please sign in to comment.