Skip to content

Commit

Permalink
WIP: Consolidate UI and implement config file lists
Browse files Browse the repository at this point in the history
  • Loading branch information
sbelsk committed Nov 18, 2024
1 parent b0af7af commit a5201c9
Show file tree
Hide file tree
Showing 2 changed files with 468 additions and 339 deletions.
54 changes: 49 additions & 5 deletions AutoscoperM/AutoscoperM.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ def setup(self):
self.ui.configGenButton.connect("clicked(bool)", self.onGenerateConfig)
self.ui.segmentationButton.connect("clicked(bool)", self.onSegmentation)
self.ui.importModelsButton.connect("clicked(bool)", self.onImportModels)

self.ui.loadPVButton.connect("clicked(bool)", self.onLoadPV)
self.ui.populateTrialNameListButton.connect("clicked(bool)", self.onPopulateTrialNameList)
self.ui.populatePartialVolumeListButton.connect("clicked(bool)", self.onPopulatePartialVolumeList)
self.ui.populateCameraCalListButton.connect("clicked(bool)", self.onPopulateCameraCalList)

# Default output directory
self.ui.mainOutputSelector.setCurrentPath(
Expand Down Expand Up @@ -556,11 +558,10 @@ def onImportModels(self):
slicer.mrmlScene.RemoveNode(returnedNode)
self.ui.progressBar.setValue((idx + 1) / len(segmentationFiles) * 100)
else: # Should never happen but just in case
raise Exception("No segmentation method selected")
raise Exception("Please select the 'Segmentation From Model' option in order to import models")
return
slicer.util.messageBox("Success!")


def onSegmentation(self):
"""
Launches the automatic segmentation process
Expand Down Expand Up @@ -598,9 +599,8 @@ def onSegmentation(self):
segmentationSequenceNode.SetDataNodeAtValue(segmentationNode, str(i))
slicer.mrmlScene.RemoveNode(segmentationNode)
currentVolumeNode = self.logic.getNextItemInSequence(volumeNode)
#elif
else: # Should never happen but just in case
raise Exception("No segmentation method selected")
raise Exception("Please select the 'Automatic Segmentation' option in order to generate segmentations")
return
slicer.util.messageBox("Success!")

Expand Down Expand Up @@ -656,6 +656,50 @@ def onLoadPV(self):

slicer.util.messageBox("Success!")

def onPopulateTrialNameList(self):
"""
Populates trial name UI list using files from the selected radiograph directory
"""
radiographDir = os.path.join(self.ui.mainOutputSelector.currentPath, self.ui.vrgSubDir.text)
self.populateFileList(self.ui.trialList, radiographDir, itemType="dir")

def onPopulatePartialVolumeList(self):
"""
Populates partial volumes UI list using files from the selected PV directory
"""
radiographDir = os.path.join(self.ui.mainOutputSelector.currentPath, self.ui.tiffSubDir.text)
self.populateFileList(self.ui.partialVolumeList, radiographDir)

def onPopulateCameraCalList(self):
"""
Populates camera calibration UI list using files from the selected camera directory
"""
radiographDir = os.path.join(self.ui.mainOutputSelector.currentPath, self.ui.cameraSubDir.text)
self.populateFileList(self.ui.camCalList, radiographDir)

def populateFileList(self, listWidget, fileDir, itemType="file"):
"""
Populates trial name UI list using files from the selected radiograph directory
"""
listWidget.clear()
if not self.logic.validatePaths(
fileDir=fileDir,
):
raise ValueError("Invalid input: subdirectory does not exist")
return

if itemType == "file":
listFiles = [f.name for f in os.scandir(fileDir) if os.path.isfile(f)]
elif itemType == "dir":
listFiles = [f.name for f in os.scandir(fileDir) if os.path.isdir(f)]
else:
raise ValueError(f"Invalid input: can only search for either files or directories in specified path, but given itemType={itemType}")
return

for file in listFiles:
fileItem = qt.QListWidgetItem(file)
fileItem.setCheckState(qt.Qt.Unchecked)
listWidget.addItem(fileItem)

#
# AutoscoperMLogic
Expand Down
Loading

0 comments on commit a5201c9

Please sign in to comment.