Skip to content

Commit

Permalink
re #30: I updated the code to use settings for the save location and …
Browse files Browse the repository at this point in the history
…the model path
  • Loading branch information
16djm10 committed Jan 18, 2023
1 parent 9e7d36c commit 4c1fa15
Showing 1 changed file with 23 additions and 44 deletions.
67 changes: 23 additions & 44 deletions BroadbandSpecModule/BroadbandSpecModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,23 @@ def setup(self):
self.ui.patientNumberSelector.addItem("PatientA")
# self.ui.saveLocationSelector.connect('currentPathChanged(QString)', self.onSaveLocationSelectorChanged)
self.ui.saveDirectoryButton.connect('directorySelected(QString)', self.onSaveDirectoryButtonClicked)
# update the saveDirectory using parameter node to the self.logic.SAVE_LOCATION *** Change this to use settings
self.ui.saveDirectoryButton.directory = self._parameterNode.GetParameter(self.logic.SAVE_LOCATION)

self.ui.samplingDurationSlider.connect('valueChanged(double)', self.onSamplingDurationChanged)
self.ui.samplingRateSlider.connect('valueChanged(double)', self.onSamplingRateChanged)
self.ui.collectSampleButton.connect('clicked(bool)', self.onCollectSampleButtonClicked)
self.ui.continuousCollectionButton.connect('clicked(bool)', self.onContinuousCollectionButtonClicked)

self.initializeGUI()

def initializeGUI(self):
# get the paths saved in settings
# initailize the save directory using settings
settings = slicer.app.userSettings()
if settings.value(self.logic.SAVE_LOCATION): # if the settings exists
self.ui.saveDirectoryButton.directory = settings.value(self.logic.SAVE_LOCATION)
# initailize the path to current model
if settings.value(self.logic.MODEL_PATH):
self.ui.modelFileSelector.setCurrentPath(settings.value(self.logic.MODEL_PATH))

def initializeScene(self):
# NeedleModel
Expand Down Expand Up @@ -260,34 +269,26 @@ def onConnectButtonClicked(self):
pointList_NeedleTip.SetAndObserveTransformNodeID(transformNode.GetID())


def onSaveDirectoryButtonClicked(self):
self.updateParameterNodeFromGUI()
# get the path from the button
path = self.ui.saveDirectoryButton.directory
def onSaveDirectoryButtonClicked(self, directory):
# update settings with the new directory
settings = slicer.app.userSettings()
settings.setValue(self.logic.SAVE_LOCATION, directory)
# Print the save directory
print('Save directory: ' + path)
# Save that path to the parameter node
parameterNode = self.logic.getParameterNode()
parameterNode.SetParameter(self.logic.SAVE_LOCATION, path)
# pass
print('Save directory: ' + directory)

def onSpectrumImageChanged(self):
self.updateParameterNodeFromGUI()

def onOutputTableChanged(self):
self.updateParameterNodeFromGUI()

def onModelFileSelectorChanged(self):
# Update the parameter node from the GUI
self.updateParameterNodeFromGUI()
# get the file from the modelFileSelector
modelPath = self.ui.modelFileSelector.currentPath
# update the parameter node with the new model path
parameterNode = self.logic.getParameterNode()
parameterNode.SetParameter(self.logic.MODEL_PATH, modelPath)
print('Loading in model from path:', modelPath)
if not (modelPath == ''):
self.logic.model = load(modelPath)
def onModelFileSelectorChanged(self, path):
# update settings with the new model path
settings = slicer.app.userSettings()
settings.setValue(self.logic.MODEL_PATH, path)
print('Loading in model from path:', path)
if not (path == ''):
self.logic.model = load(path)

def onPlaceFiducialButtonClicked(self):
self.updateParameterNodeFromGUI()
Expand Down Expand Up @@ -383,14 +384,6 @@ def initializeParameterNode(self):
slicer.mrmlScene.AddNode(firstTableNode)
self._parameterNode.SetNodeReferenceID(self.logic.OUTPUT_TABLE, firstTableNode.GetID())

# If no model path is selected, select the default one
if self._parameterNode.GetNodeReference(self.logic.MODEL_PATH) is None:
self._parameterNode.SetParameter(self.logic.MODEL_PATH, self.logic.DEFAULT_MODEL_PATH)

# Add a default save location if none exists
if self._parameterNode.GetNodeReference(self.logic.SAVE_LOCATION) is None:
self._parameterNode.SetParameter(self.logic.SAVE_LOCATION, self.logic.DEFAULT_SAVE_LOCATION)

def updateGUIFromParameterNode(self, caller=None, event=None):
"""
This method is called whenever parameter node is changed.
Expand Down Expand Up @@ -419,11 +412,6 @@ def updateGUIFromParameterNode(self, caller=None, event=None):
else:
self.ui.connectButton.text = 'Disconnect'

# Update the model path to be the last selection
if self.ui.modelFileSelector.currentPath == '':
# set the current path to whatever is stored in the parameter node
self.ui.modelFileSelector.currentPath = self._parameterNode.GetParameter(self.logic.MODEL_PATH)

# All the GUI updates are done
self._updatingGUIFromParameterNode = False

Expand Down Expand Up @@ -533,9 +521,6 @@ class BroadbandSpecModuleLogic(ScriptedLoadableModuleLogic,VTKObservationMixin):
CLASS_LABEL_1 = "ClassLabel1" # The label of the second class
CLASS_LABEL_NONE = "WeakSignal" # The label of the class when the signal is too weak
DISTANCE_THRESHOLD = 1 # in mm
# DEFAULT_SAVE_LOCATION = os.path.join('C:\Spectroscopy_TrackedTissueSensing\data', 'Nov2022_skinTestData')
DEFAULT_MODEL_PATH = os.path.join('C:\Spectroscopy_TrackedTissueSensing\TrainedModels', 'KNN_WhiteVsBlue2.joblib')
DEFAULT_SAVE_LOCATION = os.path.join('C:\Spectroscopy_TrackedTissueSensing\data', 'SkinDataCollection')

def __init__(self):
"""
Expand All @@ -562,12 +547,6 @@ def setDefaultParameters(self, parameterNode):
"""
if not parameterNode.GetParameter(self.CLASSIFICATION):
parameterNode.SetParameter(self.CLASSIFICATION, '')
# if the self.model path is not set, grab it from the ctkPathLineEdit widget
if parameterNode.GetParameter(self.MODEL_PATH) == '':
parameterNode.SetParameter(self.MODEL_PATH, self.DEFAULT_MODEL_PATH)
if self.model == None:
modelPath = parameterNode.GetParameter(self.MODEL_PATH)
self.model = load(modelPath)

def process(self, inputVolume, outputTable, imageThreshold, invert=False, showResult=True):
"""
Expand Down

0 comments on commit 4c1fa15

Please sign in to comment.