Skip to content

Commit

Permalink
STYLE: Migrate functionality to logic
Browse files Browse the repository at this point in the history
Cleanup commented out irrelevant lines and migrate functionality into logic class
  • Loading branch information
amymmorton committed Dec 13, 2024
1 parent cdfcd23 commit fcdf1e0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<item row="0" column="0">
<widget class="QLabel" name="inputModel_label">
<property name="text">
<string>Input model</string>
<string>Input: Model Directory</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -51,7 +51,7 @@
</property>
<layout class="QFormLayout" name="formLayout_4">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="modelROI_label">
<property name="text">
<string>Model ROI</string>
</property>
Expand All @@ -63,7 +63,7 @@
<bool>false</bool>
</property>
<property name="toolTip">
<string>Pick the output to the algorithm.</string>
<string>Computed model ROI list</string>
</property>
<property name="nodeTypes">
<stringlist>
Expand All @@ -88,7 +88,7 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<widget class="QLabel" name="croppedVol_label">
<property name="text">
<string>Cropped volume:</string>
</property>
Expand Down Expand Up @@ -125,7 +125,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="qMRMLNodeComboBox" name="inputVolSelector">
<widget class="qMRMLNodeComboBox" name="volumeSelector">
<property name="enabled">
<bool>true</bool>
</property>
Expand All @@ -141,7 +141,7 @@
<stringlist/>
</property>
<property name="noneEnabled">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="interactionNodeSingletonTag">
<string>Singleton</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
"""
For debugging in Slicer, use the folling to manipulate the module objects:
mWidget = slicer.modules.roifrommodelbounds.widgetRepresentation().self()
mLogic = mWidget.logic
mNode = mLogic.getParameterNode()
"""


import glob
import os
import pathlib
Expand Down Expand Up @@ -119,7 +128,6 @@ class roiFromModelBoundsParameterNode:
The parameters needed by module.
modelFile_path- load several stl inputModels from file
inputVolume- Voume for ROI crop
modelROI - The output volume that will contain the thresholded volume.
croppedVolume - The output volume that will be .
Expand Down Expand Up @@ -176,7 +184,6 @@ def setup(self) -> None:
self.addObserver(slicer.mrmlScene, slicer.mrmlScene.EndCloseEvent, self.onSceneEndClose)

# Buttons
# self.ui.applyButton.connect("clicked(bool)", self.onApplyButton)
self.ui.showBounds_pb.connect("clicked(bool)", self.onShowModelBoundsButton)

# Make sure parameter node is initialized (needed for module reload)
Expand Down Expand Up @@ -218,15 +225,15 @@ def initializeParameterNode(self) -> None:
self.setParameterNode(self.logic.getParameterNode())

# Select default input nodes if nothing is selected yet to save a few clicks for the user
# if not self._parameterNode.inputModel:
# firstModelNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLModelNode")
# if firstModelNode:
# self._parameterNode.inputModel = firstModelNode
if not self._parameterNode.modelROI:
firstModelNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLMarkupsROINode")
if firstModelNode:
self._parameterNode.modelROI = firstModelNode

# if not self._parameterNode.inputVolume:
# firstVolumeNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLScalarVolumeNode")
# if firstVolumeNode:
# self._parameterNode.inputVolume = firstVolumeNode
if not self._parameterNode.inputVolume:
firstVolumeNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLScalarVolumeNode")
if firstVolumeNode:
self._parameterNode.inputVolume = firstVolumeNode

def setParameterNode(self, inputParameterNode: Optional[roiFromModelBoundsParameterNode]) -> None:
"""
Expand All @@ -250,28 +257,12 @@ def _checkCanGenModelROI(self, _caller=None, _event=None) -> None:
self.ui.showBounds_pb.toolTip = _("Compute output volume")
self.ui.showBounds_pb.enabled = True
else:
self.ui.showBounds_pb.toolTip = _("Select input ModelPath and volume nodes")
self.ui.showBounds_pb.toolTip = _("Select input ModelPath and volume node")
self.ui.showBounds_pb.enabled = True

def onShowModelBoundsButton(self) -> None:
with slicer.util.tryWithErrorDisplay(_("Failed to compute results."), waitCursor=True):
# Compute output
volumeNode = self.ui.inputVolSelector.currentNode()
modelFileDir = self.ui.modelPath_lineEdit.currentPath

# TO DO write validatePaths logic function
# if not self.logic.validatePaths(modelFileDir=modelFileDir):
# raise ValueError("Invalid paths")
# return
modelFiles = glob.glob(os.path.join(modelFileDir, "*.*"))

for _indx, file in enumerate(modelFiles):
modelNode = slicer.util.loadNodeFromFile(file)
modelNode.CreateDefaultDisplayNodes()
self.logic.modelBounds(modelNode, volumeNode, self.ui.modelROISelector, self.ui.cropVolSelector)

# self.logic.modelBounds(self.ui.inputSelector.currentNode(),self.ui.inputVolumeSelector,
# self.ui.modelROISelector, self.ui.cropVolSelector)
"""Load Models from folder, compute bounds, assign to new roi"""
self.logic.loadModelsComputeBounds()


#
Expand All @@ -296,13 +287,22 @@ def __init__(self) -> None:
def getParameterNode(self):
return roiFromModelBoundsParameterNode(super().getParameterNode())

def modelBounds(
self,
inputModel: vtkMRMLModelNode,
inputVolume: vtkMRMLScalarVolumeNode, # noqa: ARG002
modelROI: vtkMRMLMarkupsROINode,
croppedVolume: vtkMRMLScalarVolumeNode, # noqa: ARG002
) -> None:
def loadModelsComputeBounds(self):
parameterNode = self.getParameterNode()
modelFileDir = parameterNode.modelFile_path

modelFiles = glob.glob(os.path.join(modelFileDir, "*.*"))
#return modelFiles

for _indx, file in enumerate(modelFiles):
modelNode = slicer.util.loadNodeFromFile(file)
modelNode.CreateDefaultDisplayNodes()
self.modelBounds(modelNode) #, volumeNode, self.ui.modelROISelector, self.ui.cropVolSelector)


def modelBounds(self, inputModel) -> None:

inputModel: vtkMRMLModelNode

tB = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
inputModel.GetBounds(tB)
Expand Down Expand Up @@ -333,10 +333,6 @@ def modelBounds(
roi_name = mname + "_roi"
modelROI.SetName(roi_name)

# populate in Model ROI Output..?

# print(modelROI)


#
# roiFromModelBoundsTest
Expand Down

0 comments on commit fcdf1e0

Please sign in to comment.