Skip to content

Commit

Permalink
ENH #78: added setting to save needle length offset
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscyyeung committed Nov 23, 2022
1 parent 26a589f commit 9549cf9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
37 changes: 29 additions & 8 deletions LumpNav2/LumpNav2.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ def setup(self):
self.eventFilter = LumpNavEventFilter(self)
slicer.util.mainWindow().installEventFilter(self.eventFilter)

# Check settings and set default values if settings not found
cauteryCalibrationThresholdMm = slicer.util.settingsValue(self.CAUTERY_CALIBRATION_THRESHOLD_SETTING, str(self.CAUTERY_CALIBRATION_THRESHOLD_DEFAULT))
needleCalibrationThresholdMm = slicer.util.settingsValue(self.NEEDLE_CALIBRATION_THRESHOLD_SETTING, str(self.NEEDLE_CALIBRATION_THRESHOLD_DEFAULT))

# Set state of custom UI button
self.setCustomStyle(not self.getSlicerInterfaceVisible())

Expand Down Expand Up @@ -341,6 +337,12 @@ def setup(self):
configFilepath = slicer.util.settingsValue(self.logic.CONFIG_FILE_SETTING, self.logic.resourcePath(self.logic.CONFIG_FILE_DEFAULT))
self.ui.plusConfigFileSelector.currentPath = configFilepath
self.ui.plusConfigFileSelector.connect('currentPathChanged(const QString)', self.onPlusConfigFileChanged)
needleLengthOffset = slicer.util.settingsValue(
self.logic.NEEDLE_LENGTH_OFFSET_SETTING, self.logic.NEEDLE_LENGTH_OFFSET_DEFAULT, converter=lambda x: float(x)
)
if needleLengthOffset:
self.ui.needleLengthOffsetSpinBox.value = needleLengthOffset
self.ui.needleLengthOffsetSpinBox.connect('valueChanged(double)', self.onNeedleLengthOffsetChanged)

# Add custom layouts
self.logic.addCustomLayouts()
Expand Down Expand Up @@ -455,6 +457,12 @@ def onNeedlePlusFiveClicked(self):
self.logic.changeNeedleLength(5)
self.updateGUIFromParameterNode()

def onNeedleLengthOffsetChanged(self, value):
logging.info(f"onNeedleLengthOffsetChanged({value})")
settings = qt.QSettings()
settings.setValue(self.logic.NEEDLE_LENGTH_OFFSET_SETTING, value)
self.updateGUIFromParameterNode()

def onExitButtonClicked(self):
mainwindow = slicer.util.mainWindow()
mainwindow.close()
Expand Down Expand Up @@ -1191,9 +1199,12 @@ def updateGUIFromParameterNode(self, caller=None, event=None):

needleTipToNeedle = self._parameterNode.GetNodeReference(self.logic.NEEDLETIP_TO_NEEDLE)
if needleTipToNeedle:
needleLengthOffset = slicer.util.settingsValue(
self.logic.NEEDLE_LENGTH_OFFSET_SETTING, self.logic.NEEDLE_LENGTH_OFFSET_DEFAULT, converter=lambda x: float(x)
)
needleTipToNeedleMatrix = needleTipToNeedle.GetMatrixTransformToParent()
needleTipToNeedleLength = needleTipToNeedleMatrix.GetElement(2, 3)
needleLength = needleTipToNeedleLength - self.logic.NEEDLE_CLIP_LENGTH_MM
needleLength = needleTipToNeedleLength - needleLengthOffset
self.ui.needleLengthLabel.text = f"Needle length: {needleLength:.0f}mm"

plusServerLauncherNode = self._parameterNode.GetNodeReference(self.logic.PLUS_SERVER_LAUNCHER_NODE)
Expand Down Expand Up @@ -1317,7 +1328,8 @@ class LumpNav2Logic(ScriptedLoadableModuleLogic, VTKObservationMixin):
NEEDLE_MODEL = "NeedleModel"
NEEDLE_VISIBILITY_SETTING = "LumpNav2/NeedleVisible"
NEEDLETIP_TO_NEEDLE_SETTING = "NeedleTipToNeedleSetting"
NEEDLE_CLIP_LENGTH_MM = 17
NEEDLE_LENGTH_OFFSET_SETTING = "LumpNav2/NeedleLengthOffset"
NEEDLE_LENGTH_OFFSET_DEFAULT = 17
CAUTERY_MODEL = "CauteryModel"
CAUTERY_VISIBILITY_SETTING = "LumpNav2/CauteryVisible"
CAUTERY_MODEL_FILENAME = "CauteryModel.stl"
Expand Down Expand Up @@ -2131,8 +2143,17 @@ def setMarkPointCauteryTipClicked(self):
cauteryTipToCautery = parameterNode.GetNodeReference(self.CAUTERYTIP_TO_CAUTERY)
cauteryTipToCautery.GetMatrixTransformToNode(needleToReference, cauteryTipToNeedle)
tumorMarkups_Needle = parameterNode.GetNodeReference(self.TUMOR_MARKUPS_NEEDLE)
tumorMarkups_Needle.AddControlPoint(cauteryTipToNeedle.GetElement(0,3), cauteryTipToNeedle.GetElement(1,3), cauteryTipToNeedle.GetElement(2,3))
logging.info("Tumor point placed at cautery tip, (%s, %s, %s)", cauteryTipToNeedle.GetElement(0,3), cauteryTipToNeedle.GetElement(1,3), cauteryTipToNeedle.GetElement(2,3))
tumorMarkups_Needle.AddControlPoint(
cauteryTipToNeedle.GetElement(0, 3),
cauteryTipToNeedle.GetElement(1, 3),
cauteryTipToNeedle.GetElement(2, 3)
)
logging.info(
"Tumor point placed at cautery tip, (%s, %s, %s)",
cauteryTipToNeedle.GetElement(0, 3),
cauteryTipToNeedle.GetElement(1, 3),
cauteryTipToNeedle.GetElement(2, 3)
)

def setFreezeUltrasoundClicked(self, toggled):
parameterNode = self.getParameterNode()
Expand Down
14 changes: 14 additions & 0 deletions LumpNav2/Resources/UI/LumpNav2.ui
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,20 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_19">
<item>
<widget class="QLabel" name="needleLengthOffsetLabel">
<property name="text">
<string>Needle length offset:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needleLengthOffsetSpinBox"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 9549cf9

Please sign in to comment.