From ffe64d129d194d5052433bd8a1e4c06277d1fe00 Mon Sep 17 00:00:00 2001 From: Shelly Belsky Date: Fri, 22 Nov 2024 10:46:53 -0500 Subject: [PATCH] STYLE: Cleanup UI file and logging statements --- AutoscoperM/AutoscoperM.py | 27 +++--- AutoscoperM/AutoscoperMLib/IO.py | 3 - AutoscoperM/Resources/UI/AutoscoperM.ui | 122 ++++++++++++------------ 3 files changed, 75 insertions(+), 77 deletions(-) diff --git a/AutoscoperM/AutoscoperM.py b/AutoscoperM/AutoscoperM.py index c697882..9a7b206 100644 --- a/AutoscoperM/AutoscoperM.py +++ b/AutoscoperM/AutoscoperM.py @@ -214,8 +214,8 @@ def setup(self): self.ui.volumeSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onCurrentNodeChanged) self.ui.tiffGenButton.connect("clicked(bool)", self.onGeneratePartialVolumes) 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.segGen_segmentationButton.connect("clicked(bool)", self.onSegmentation) + self.ui.segSTL_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) @@ -489,7 +489,7 @@ def onGenerateConfig(self): configPath = os.path.join(mainOutputDir, f"{configFileName}.cfg") tiffSubDir = self.ui.tiffSubDir.text - vrgSubDir = self.ui.vrgSubDir.text + radiographSubDir = self.ui.radiographSubDir.text calibrationSubDir = self.ui.cameraSubDir.text trialList = self.ui.trialList @@ -502,7 +502,7 @@ def onGenerateConfig(self): mainOutputDir=mainOutputDir, configFileName=configFileName, tiffSubDir=tiffSubDir, - vrgSubDir=vrgSubDir, + radiographSubDir=radiographSubDir, calibrationSubDir=calibrationSubDir, trialList=trialList, partialVolumeList=partialVolumeList, @@ -513,7 +513,7 @@ def onGenerateConfig(self): if not self.logic.validatePaths( mainOutputDir=mainOutputDir, tiffDir=os.path.join(mainOutputDir, tiffSubDir), - vrgDir=os.path.join(mainOutputDir, vrgSubDir), + vrgDir=os.path.join(mainOutputDir, radiographSubDir), calibDir=os.path.join(mainOutputDir, calibrationSubDir), ): raise ValueError("Invalid paths") @@ -530,7 +530,7 @@ def get_checked_items(listWidget): # extract filenames from UI lists, and use them to construct the paths relative to mainOutputDir # FIXME: don't assume the list of camera files is given in the same order as the list of radiograph root dir! camCalFiles = [os.path.join(calibrationSubDir, item) for item in get_checked_items(camCalList)] - trialDirs = [os.path.join(vrgSubDir, item) for item in get_checked_items(trialList)] + trialDirs = [os.path.join(radiographSubDir, item) for item in get_checked_items(trialList)] if not len(camCalFiles) == len(trialDirs): raise ValueError( @@ -614,8 +614,8 @@ def onImportModels(self): raise ValueError("Invalid inputs") return - if self.ui.segGen_fileRadioButton.isChecked(): - segmentationFileDir = self.ui.segGen_lineEdit.currentPath + if self.ui.segSTL_loadRadioButton.isChecked(): + segmentationFileDir = self.ui.segSTL_modelsDir.currentPath if not self.logic.validatePaths(segmentationFileDir=segmentationFileDir): raise ValueError("Invalid paths") return @@ -662,7 +662,7 @@ def onSegmentation(self): self.logic.cleanFilename(currentVolumeNode.GetName(), i) segmentationNode = SubVolumeExtraction.automaticSegmentation( currentVolumeNode, - self.ui.segGen_ThresholdSpinBox.value, + self.ui.segGen_thresholdSpinBox.value, self.ui.segGen_marginSizeSpin.value, progressCallback=self.updateProgressBar, ) @@ -748,7 +748,7 @@ 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) + radiographDir = os.path.join(self.ui.mainOutputSelector.currentPath, self.ui.radiographSubDir.text) try: self.populateFileList(self.ui.trialList, radiographDir, itemType="dir") except ValueError as errMsg: @@ -779,9 +779,10 @@ def populateFileList(self, listWidget, fileDir, itemType="file"): Populates input UI list with files/directories that exist in the given input directory """ listWidget.clear() - if not self.logic.validatePaths( - fileDir=fileDir, - ): + if not self.logic.validateInputs(listWidget=listWidget): + raise ValueError(f"Invalid input: list widget to be populated is None.") + return + if not self.logic.validatePaths(fileDir=fileDir,): raise ValueError(f"Invalid input: subdirectory '{fileDir}' does not exist.") return diff --git a/AutoscoperM/AutoscoperMLib/IO.py b/AutoscoperM/AutoscoperMLib/IO.py index 6cceef0..f440c77 100644 --- a/AutoscoperM/AutoscoperMLib/IO.py +++ b/AutoscoperM/AutoscoperMLib/IO.py @@ -61,7 +61,6 @@ def generateConfigFile( """ import datetime - logging.info(f"generateConfigFile: writing to '{outputConfigPath}'") with open(outputConfigPath, "w+") as f: # Trial Name as comment f.write(f"# {trialName} configuration file\n") @@ -104,8 +103,6 @@ def generateConfigFile( f.write("OptimizationOffsets " + " ".join([str(x) for x in optimizationOffsets]) + "\n") f.write("\n") - return True - def writeVolume(volumeNode: slicer.vtkMRMLVolumeNode, filename: str): """ diff --git a/AutoscoperM/Resources/UI/AutoscoperM.ui b/AutoscoperM/Resources/UI/AutoscoperM.ui index dd0eca6..a380b3e 100644 --- a/AutoscoperM/Resources/UI/AutoscoperM.ui +++ b/AutoscoperM/Resources/UI/AutoscoperM.ui @@ -147,7 +147,7 @@ - + Output Directory: @@ -161,7 +161,7 @@ - + Volume Node: @@ -211,14 +211,14 @@ - + Threshold Value: - + 10000 @@ -227,8 +227,15 @@ + + + + Generate Segmentations + + + - + Margin Size: @@ -241,29 +248,22 @@ - - - - Generate Segmentations - - - - + OR - + Segmentation from Model - + false @@ -273,7 +273,7 @@ - + false @@ -283,7 +283,7 @@ - + false @@ -307,14 +307,14 @@ false - - + + Segmentation Node: - + true @@ -332,14 +332,14 @@ - + Generate Partial Volumes - + Load Partial Volumes @@ -368,7 +368,7 @@ - + Partial Volume Subdirectory: @@ -382,7 +382,7 @@ - + Partial Volume Transforms Subdirectory: @@ -396,7 +396,7 @@ - + 75 @@ -409,7 +409,7 @@ - + 75 @@ -422,7 +422,7 @@ - + 75 @@ -451,7 +451,7 @@ - + Tracking Subdirectory: @@ -465,7 +465,7 @@ - + Model Subdirectory: @@ -499,7 +499,7 @@ - + true @@ -508,18 +508,11 @@ - - - - Populate From Radiographs Subdirectory - - - - + and enter : @@ -533,19 +526,29 @@ - + .cfg + + + + Populate From Radiographs Subdirectory + + + - + Select Partial Volumes: + + + @@ -553,16 +556,16 @@ - - - - + Select Camera Calibrations: + + + @@ -570,15 +573,12 @@ - - - - + Optimization Offsets: @@ -645,7 +645,7 @@ - + Volume Flip: @@ -679,7 +679,7 @@ - + Render Resolution: (width,height) @@ -706,7 +706,7 @@ - + Voxel Size: @@ -821,7 +821,7 @@ segGen_autoRadioButton toggled(bool) - segGen_ThresholdSpinBox + segGen_thresholdSpinBox setEnabled(bool) @@ -835,9 +835,9 @@ - segGen_fileRadioButton + segSTL_loadRadioButton toggled(bool) - segGen_lineEdit + segSTL_modelsDir setEnabled(bool) @@ -883,9 +883,9 @@ - segGen_fileRadioButton + segSTL_loadRadioButton toggled(bool) - importModelsButton + segSTL_importModelsButton setEnabled(bool) @@ -901,7 +901,7 @@ segGen_autoRadioButton toggled(bool) - segmentationButton + segGen_segmentationButton setEnabled(bool) @@ -915,9 +915,9 @@ - segGen_fileRadioButton + segSTL_loadRadioButton toggled(bool) - segSTLModelsDirLabel + segSTL_modelsDirLabel setEnabled(bool) @@ -933,7 +933,7 @@ segGen_autoRadioButton toggled(bool) - segThresholdLabel + segGen_thresholdLabel setEnabled(bool) @@ -949,7 +949,7 @@ segGen_autoRadioButton toggled(bool) - segMarginSizeLabel + segGen_marginSizeLabel setEnabled(bool)