Skip to content

Commit

Permalink
Fixing Auto Connect Spine Functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jtle00 committed Jul 30, 2024
1 parent 7ff5090 commit d675fb5
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 30 deletions.
16 changes: 15 additions & 1 deletion pymapmanager/annotations/baseAnnotationsCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ def manualConnectSpine(self, spineID : int, x, y, z):
# rebuild df from mutated full map
self._buildDataFrame()

#abj
def autoResetBrightestIndex(self, spineID, segmentID, point, findBrightest : bool = True):

if not isinstance(spineID, int):
logger.error(f'got bad spineID:{spineID}, expecting int')
return

# Update brightest path
brightestIdx = self._fullMap.autoConnectBrightestIndex(spineID, segmentID, point, findBrightest)
logger.info(f"brightestIdx {brightestIdx}")

# refreshDataFrame
self._buildDataFrame()

def setValue(self, colName : str, row : int, value):
"""Set a single value in a row and column.
Expand Down Expand Up @@ -541,7 +555,7 @@ def getLeftRadiusPlot(self, segmentID,
_stopSlice = zSlice + zPlusMinus

# logger.info(f"self._fullMap.segments['segment']:{self._fullMap.segments['segment']}")
logger.info(f"self._fullMap.segments:{self._fullMap.segments[:]}")
# logger.info(f"self._fullMap.segments:{self._fullMap.segments[:]}")

segmentLines = clipLines(self._fullMap.segments['segment'], zRange = (_startSlice, _stopSlice))
xyLeft = shapely.offset_curve(segmentLines, radiusOffset * -1)
Expand Down
4 changes: 2 additions & 2 deletions pymapmanager/interface2/runInterfaceJohnson.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ def run2():
sys.exit(app.exec_())

if __name__ == '__main__':
# run()
run2()
run()
# run2()
13 changes: 13 additions & 0 deletions pymapmanager/interface2/stackWidgets/annotationPlotWidget2.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,19 @@ def manualConnectSpineEvent(self, event : pmmEvent):

self._refreshSlice()

def autoConnectSpineEvent(self, event : pmmEvent):
"""Update plots on auto connect spine event.
"""
for spine in event:
# update label
spineID = spine['spineID']
self._pointLabels.updateLabel(spineID)

# remake all spine lines
self._bMakeSpineLines()

self._refreshSlice()

def undoEvent(self, event : UndoSpineEvent):
"""
"""
Expand Down
18 changes: 17 additions & 1 deletion pymapmanager/interface2/stackWidgets/event/spineEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,20 @@ def _getItem(self, item : SpineEdit):
col=item['col'],
value=item['value'])
return item


#abj
class AutoConnectSpineEvent(_EditSpine):
"""Used Auto Connect Spine to its brightest point on a line segment
"""
def __init__(self,
mmWidget : mmWidget2,
spineID : int = None):
super().__init__(pmmEventType.autoConnectSpine, mmWidget)
if spineID is not None:
self.addEdit(spineID=spineID)

def _getItem(self, item : SpineEdit):
"""Get the meaningful keys for this edit type.
"""
item = SpineEdit(spineID=item['spineID'])
return item
24 changes: 17 additions & 7 deletions pymapmanager/interface2/stackWidgets/imagePlotWidget2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
EditSpinePropertyEvent,
AddSpineEvent,
MoveSpineEvent,
ManualConnectSpineEvent)
ManualConnectSpineEvent,
AutoConnectSpineEvent #abj
)

from pymapmanager.interface2.stackWidgets.event.segmentEvent import (
AddSegmentPoint
Expand Down Expand Up @@ -240,12 +242,20 @@ def contextMenuEvent(self, event : QtGui.QContextMenuEvent):

elif action == autoConnectAction:
logger.warning('Auto Connecting Spine')
# Dont need to acquire any new data,
#everything should be known because of the current selection
eventType = pmmEventType.autoConnectSpine
event = pmmEvent(eventType, self)
event.setSliceNumber(self._currentSlice)
self.emitEvent(event, blockSlots=True)

# pass in ID
# possible x,y,z to simplify stackwidget function
acs = AutoConnectSpineEvent(self, firstPointSelection)
self.emitEvent(acs)

# eventType = pmmEventType.autoConnectSpine
# event = pmmEvent(eventType, self)
# event.setSliceNumber(self._currentSlice)
# self.emitEvent(event)

# event = pmmEvent(pmmEventType.stateChange, self)
# # event.setStateChange(pmmStates.autoConnectSpine)
# self.emitEvent(event, blockSlots=True)

elif action == deleteAction:
logger.warning('deleting the selected annotation')
Expand Down
5 changes: 4 additions & 1 deletion pymapmanager/interface2/stackWidgets/mmWidget2.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def getState(self):
def setState(self, state : pmmStates):
self._dict['state'] = state

# ABJ
#abj
def getCurrentPointSlice(self):
pointSelections = self.getPointSelection()

Expand Down Expand Up @@ -183,6 +183,9 @@ def hasPointSelection(self) -> bool:
return len(self.getPointSelection()) > 0

def firstPointSelection(self) -> Optional[int]:
"""
returns index of first point selection
"""
_points = self.getPointSelection()
if len(_points) > 0:
return _points[0]
Expand Down
36 changes: 18 additions & 18 deletions pymapmanager/interface2/stackWidgets/stackWidget2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import os
from typing import TYPE_CHECKING

from shapely import Point

import pymapmanager.interface2
import pymapmanager.interface2.stackWidgets
import pymapmanager.interface2.stackWidgets.histogramWidget2
Expand Down Expand Up @@ -693,6 +695,7 @@ def _afterEdit2(self, event):

# reselect spine
spines = event.getSpines() # [int]
# logger.info(f"afterEdit2 spines: {spines}")
self.zoomToPointAnnotation(spines)

self.slot_setStatus('Ready')
Expand Down Expand Up @@ -782,29 +785,26 @@ def autoConnectSpineEvent(self, event):
logger.warning('=== === STACK WIDGET PERFORMING AUTO CONNECT === ===')
logger.error('TODO (Cudmore) need to implement auto connect')

# set backend
segmentID = _stackSelection.firstSegmentSelection()

_pointAnnotations = self.getStack().getPointAnnotations()
x = _pointAnnotations.getValue('x', spineIndex)
y = _pointAnnotations.getValue('y', spineIndex)
z = _pointAnnotations.getValue('z', spineIndex)
# point = _pointAnnotations.getValue("point", spineIndex)

# Getting channel and img from stack
# channel = self.getStack().getImageChannel()
point = Point(x, y, z)
# logger.info(f"point {point}")

# TODO: Need to get color channel from stack
channel = 2
# channel = event.getColorChannel()
logger.info(f"channel {channel}")
z = _stackSelection.getCurrentPointSlice() # this might need to be checked, currently getting slice point selected
img = self.getStack().getImageSlice(z, channel=channel)
_pointAnnotations = self.getStack().getPointAnnotations()
_lineAnnotations = self.getStack().getLineAnnotations()
autoBrightestIndex = _pointAnnotations.calculateSingleBrightestIndex(channel, spineIndex, _lineAnnotations, img)
_pointAnnotations.setValue('brightestIndex', spineIndex, autoBrightestIndex)
_pointAnnotations.updateSpineInt2(spineIndex, self.getStack())
_pointAnnotations.autoResetBrightestIndex(spineIndex, segmentID, point, True)

#abj TODO: Check if spine intensity is being updated
# _pointAnnotations.updateSpineInt2(spineIndex, self.getStack())

newEvent = pmmEvent(pmmEventType.selection, self)
newEvent.getStackSelection().setPointSelection(items)
sliceNum = event.getSliceNumber()
logger.info(f"autoConnect sliceNum {sliceNum}")
newEvent.setSliceNumber(sliceNum)
self._afterEdit(newEvent)
self.getUndoRedo().addUndo(event)
self._afterEdit2(event)

def setSliceEvent(self, event):
# logger.info(event)
Expand Down

0 comments on commit d675fb5

Please sign in to comment.