Skip to content

Commit

Permalink
New Improvements
Browse files Browse the repository at this point in the history
- Disabled corresponding tool tool bar options when certain plots are disabled
- Fixed slider slow update bug
- Restricted refreshing to only plots that are actually being shown
  • Loading branch information
jtle00 committed Jul 1, 2024
1 parent d29c2b7 commit fcd4a14
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 50 deletions.
3 changes: 2 additions & 1 deletion pymapmanager/interface2/runInterfaceJohnson.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def run():
# path ='\\Users\\johns\\Documents\\GitHub\\MapManagerCore\\sandbox\\data\\rr30a_s0.mmap'
# path = 'C:\\Users\\johns\\Documents\\GitHub\\MapManagerCore\\data\\rr30a_s0u.mmap'
path = '\\Users\\johns\\Documents\\GitHub\\MapManagerCore\\data\\rr30a_s0u.mmap'

# import mapmanagercore
# path = mapmanagercore.getSingleTimepointMap()
sw2 = app.loadStackWidget(path)

df = sw2.getStack().getPointAnnotations().getDataFrame()
Expand Down
63 changes: 35 additions & 28 deletions pymapmanager/interface2/stackWidgets/annotationPlotWidget2.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def hidShowLabels(self, labelIDs : List[str]):
def hideAllLabels(self, labelIDs : List[str]):
""" Hide all labels. Used when user unchecks labels within top tool bar
"""
# logger.info("HIDING ALL LABELS")
for k, v in self._labels.items():
if k in labelIDs:
v.hide()
Expand Down Expand Up @@ -243,6 +244,8 @@ def __init__(
# print('_colorMap:', self._colorMap)
self._colorMap = ['#f77189', '#dc8932', '#ae9d31', '#77ab31', '#33b07a', '#36ada4', '#38a9c5', '#6e9bf4', '#cc7af4', '#f565cc']

self.showScatter = True

def _getScatterConnect(self, df : pd.DataFrame):
return None

Expand Down Expand Up @@ -337,6 +340,8 @@ def toggleScatterPlot(self):
visible = not self._scatterUserSelection.isVisible()
self._scatterUserSelection.setVisible(visible)

self.showScatter = not self.showScatter

def _on_mouse_hover(self, points, event):
"""Respond to mouse hover over scatter plot.
Expand Down Expand Up @@ -569,9 +574,6 @@ def slot_setSlice(self, sliceNumber: int):
roiTypes = self._roiTypes

# logger.info(f'plotting roiTypes:{roiTypes} for {type(self)}')


# TODO: (6/19/24) Change this to be connected to top tool bar zSlider
zPlusMinus = self._displayOptions["zPlusMinus"]

# abb removed 042024
Expand Down Expand Up @@ -600,10 +602,11 @@ def slot_setSlice(self, sliceNumber: int):
_symbolBrush = self._getScatterColor()
_connect = self._getScatterConnect(dfPlot)

self._scatter.setData(x, y,
symbolBrush=_symbolBrush,
connect=_connect)

if self.showScatter:
self._scatter.setData(x, y,
symbolBrush=_symbolBrush,
connect=_connect)

# stopTime = time.time()
# logger.info(f'base annotation plot widget ... {self.getClassName()} Took {round(stopTime-startTime,4)} sec')

Expand Down Expand Up @@ -1056,7 +1059,7 @@ def slot_setSlice(self, sliceNumber: int):
#
# show and hide labels based on sliceNumber

# abj: check if we show label
# abj: only plot if we show labels
if self.showLabel:
self._pointLabels.hidShowLabels(_rows)

Expand Down Expand Up @@ -1281,6 +1284,7 @@ def __init__(
super().__init__(stackWidget, lineAnnotations, pgView, lineDisplayOptions)

# define the roi types we will display, see: slot_setDisplayTypes()
self.showRadiusLines = True
self._roiTypes = ["linePnt"]
self._buildUI()

Expand Down Expand Up @@ -1338,6 +1342,8 @@ def toggleRadiusLines(self):
visible = not self._rightRadiusLines.isVisible()
self._rightRadiusLines.setVisible(visible)

self.showRadiusLines = not self.showRadiusLines

def _getScatterColor(self):
logger.info(f'"{self.getClassName()}"')

Expand Down Expand Up @@ -1429,27 +1435,28 @@ def slot_setSlice(self, sliceNumber: int):
# logger.warning(f'{self.getClassName()} TODO: turn radius line back on !!!')
# logger.info(f'slot set left and right radius')

zPlusMinus = self._displayOptions["zPlusMinus"]
radiusOffset = self._displayOptions['radius']
dfLeft = self._annotations.getLeftRadiusPlot(None, sliceNumber, zPlusMinus, radiusOffset)
_lineConnect = self._getScatterConnect(dfLeft)

# logger.info(f'dfLeft["x"].to_numpy() {dfLeft["x"].to_numpy()}')
self._leftRadiusLines.setData(
dfLeft["x"].to_numpy(),
dfLeft["y"].to_numpy(),
connect=_lineConnect,
)
if self.showRadiusLines:
zPlusMinus = self._displayOptions["zPlusMinus"]
radiusOffset = self._displayOptions['radius']
dfLeft = self._annotations.getLeftRadiusPlot(None, sliceNumber, zPlusMinus, radiusOffset)
_lineConnect = self._getScatterConnect(dfLeft)

# logger.info(f'dfLeft["x"].to_numpy() {dfLeft["x"].to_numpy()}')
self._leftRadiusLines.setData(
dfLeft["x"].to_numpy(),
dfLeft["y"].to_numpy(),
connect=_lineConnect,
)

# dfRight = self._annotations.getRightRadiusPlot(None, sliceNumber, 1)

dfRight = self._annotations.getRightRadiusPlot(None, sliceNumber, zPlusMinus, radiusOffset)
_lineConnect = self._getScatterConnect(dfRight)
self._rightRadiusLines.setData(
dfRight["x"].to_numpy(),
dfRight["y"].to_numpy(),
connect=_lineConnect,
)
# dfRight = self._annotations.getRightRadiusPlot(None, sliceNumber, 1)
dfRight = self._annotations.getRightRadiusPlot(None, sliceNumber, zPlusMinus, radiusOffset)
_lineConnect = self._getScatterConnect(dfRight)
self._rightRadiusLines.setData(
dfRight["x"].to_numpy(),
dfRight["y"].to_numpy(),
connect=_lineConnect,
)

# stopSec = time.time()
# logger.info(f'{self.getClassName()} took {round(stopSec-startSec,4)} sec')
Expand Down
2 changes: 1 addition & 1 deletion pymapmanager/interface2/stackWidgets/imagePlotWidget2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ def __init__(self, numSlices):

# was this
self.sliderMoved.connect(self._updateSlice)
self.valueChanged.connect(self._updateSlice) # abb 20200829
# self.valueChanged.connect(self._updateSlice) # abb 20200829

#self.valueChanged.connect(self.sliceSliderValueChanged)

Expand Down
40 changes: 20 additions & 20 deletions pymapmanager/interface2/stackWidgets/stackToolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _buildUI(self):
_defaultChannel = self._displayOptionsDict['windowState']['defaultChannel']

# make ['1', '2', '3', 'rgb'] disjoint selections
channelActionGroup = QtWidgets.QActionGroup(self)
self.channelActionGroup = QtWidgets.QActionGroup(self)

self._actionList = []
_channelList = ['1', '2', '3', 'rgb']
Expand All @@ -179,7 +179,7 @@ def _buildUI(self):
# add action
self._actionList.append(theAction)
self.addAction(theAction)
channelActionGroup.addAction(theAction)
self.channelActionGroup.addAction(theAction)

#logger.info('TODO: implement slot_setStack(theStack) to show/hide based on channels')
# if toolIndex==1:
Expand All @@ -191,41 +191,30 @@ def _buildUI(self):
self.slidingCheckbox.stateChanged.connect(self._on_slidingz_checkbox)
self.addWidget(self.slidingCheckbox)

slidingUpDownLabel = QtWidgets.QLabel('+/-')
self.slidingUpDownLabel = QtWidgets.QLabel('+/-')
self.slidingUpDown = QtWidgets.QSpinBox()
self.slidingUpDown.setMaximum(self._myStack.numSlices)
self.slidingUpDown.setValue(3)
self.slidingUpDown.setEnabled(False)
self.slidingUpDown.valueChanged.connect(self._on_slidingz_value_changed)
self.addWidget(slidingUpDownLabel)
self.addWidget(self.slidingUpDownLabel)
self.addWidget(self.slidingUpDown)

# add radius
radiusLabel = QtWidgets.QLabel('radius')
self.radiusLabel = QtWidgets.QLabel('radius')
self._radiusSpinBox = QtWidgets.QSpinBox()
self._radiusSpinBox.setMaximum(10)
self._radiusSpinBox.setValue(3)
self._radiusSpinBox.setEnabled(True)
self._radiusSpinBox.valueChanged.connect(self._on_radius_value_changed)
self.addWidget(radiusLabel)
self.addWidget(self.radiusLabel)
self.addWidget(self._radiusSpinBox)

# Drop Box to hide different parts of plot
plotMenuButton = QtWidgets.QPushButton("Plots")
self.addWidget(plotMenuButton)
plotMenu = QtWidgets.QMenu()

# Need to get current state of plots (checked or unchecked)
# Can i get that here?
# Might be easier to do logic in annotationPlotWidget class?
# Easiest method. Have actions send signal
# Signal is sent to stackwidget -> imageplotwidget
# Image plot widget handles unchecking
# states can be kept in this class (by default start off showing)
# menu.addAction("Spines")
# menu.addAction("Center Line")
# menu.addAction("Radius Lines")
# menu.addAction("Labels")
plotMenuList = ["Spines", "Center Line", "Radius Lines", "Labels", "Image"]

for plotName in plotMenuList:
Expand All @@ -237,17 +226,28 @@ def _buildUI(self):

plotMenuButton.setMenu(plotMenu)
# menu.triggered.connect(lambda action: print(action.text()))
plotMenu.triggered.connect(lambda action: self.plotMenuChange(action.text()))
# plotMenu.triggered.connect(lambda action: self.plotMenuChange(action.text()))
plotMenu.triggered.connect(lambda action: self.plotMenuChange(action))

# colorList = ['Gray', 'Gray Inverted', 'Green', 'Red', 'Blue']
# self.colorPopup = QtWidgets.QComboBox()
# self.colorPopup.addItems(colorList)
# self.addWidget(self.colorPopup)

def plotMenuChange(self, plotName):
def plotMenuChange(self, action):

if action.text() == "Radius Lines":
self._radiusSpinBox.setEnabled(action.isChecked())
self.radiusLabel.setEnabled(action.isChecked())
elif action.text() == "Image":
self.channelActionGroup.setEnabled(action.isChecked())
# self.slidingUpDownLabel.setEnabled(action.isChecked())
# self.slidingUpDown.setEnabled(action.isChecked())
# self.slidingCheckbox.setEnabled(action.isChecked())

plotName = action.text()
self.signalPlotCheckBoxChanged.emit(plotName)


def _on_radius_value_changed(self, value):
"""
Value to change the radius of the left/ right points. When changed the points also change.
Expand Down

0 comments on commit fcd4a14

Please sign in to comment.