1111from shapely .geometry import LineString
1212import geopandas as gp
1313from mapmanagercore .logger import logger
14+ from mapmanagercore .logger import logger
1415
1516pendingBackgroundRoiTranslation = None
1617
1718
1819class AnnotationsInteractions (AnnotationsSegments ):
20+
21+ # abb
22+ def getSpineDistance (self , segmentID : SegmentId ,
23+ point : Point ):
24+ """Add doc string
25+ """
26+ segment : LineString = self .segments [segmentID , "segment" ]
27+ # find the closest point on the segment to the `point`
28+ minProjection = segment .project (point )
29+ return minProjection
30+
31+ # abb added findBrightest=False, do not find brightest by default
1932 def nearestAnchor (self , segmentID : SegmentId ,
2033 point : Point ,
21- useBrightestPath = False ,
22- brightestPathDistance : int = None ,
23- channel : int = None ,
24- zSpread : int = None ):
25- """
26- Finds the nearest anchor point on a given line segment to a given point.
34+ findBrightest : bool = False ):
35+ """Finds the nearest anchor point on a given line segment to a given point.
2736
2837 Args:
2938 segmentID (SegmentId): The ID of the line segment.
3039 point (Point): The point to find the nearest anchor to.
31- brightestPathDistance (int): The distance to search for the brightest path. Defaults to None.
32- channel (int): The channel. Defaults to 0.
33- zSpread (int): The z spread. Defaults to 0.
40+ findBrightest (bool): Default False.
41+ If True then find the brightest anchor using image data.
3442
3543 Returns:
3644 Point: The nearest anchor point.
37- """
38-
45+ """
3946 segment : LineString = self .segments [segmentID , "segment" ]
4047 # find the closest point on the segment to the `point`
4148 minProjection = segment .project (point )
42-
43- if not useBrightestPath :
44- # Default to the closest path
49+
50+ if np .isnan (minProjection ):
51+ logger .warning (f'minProjection:{ minProjection } ' )
52+ logger .warning (f'segment:{ segment } ' )
53+ logger .warning (f'point:{ point } ' )
54+
55+ if not findBrightest :
56+ # Default to the closest point (not brightest)
4557 anchor = segment .interpolate (minProjection )
4658 anchor = roundPoint (anchor , 1 )
4759 return anchor
4860
49- # abb analysisparams
50- # if not specified, get defaults from AnalysisParams()
51- if brightestPathDistance is None :
52- brightestPathDistance = self .analysisParams .getValue (
53- 'brightestPathDistance' )
54- if channel is None :
55- channel = self .analysisParams .getValue ('channel' )
56- if zSpread is None :
57- zSpread = self .analysisParams .getValue ('zSpread' )
61+ brightestPathDistance = self .analysisParams .getValue ('brightestPathDistance' )
62+ channel = self .analysisParams .getValue ('channel' )
63+ zSpread = self .analysisParams .getValue ('zSpread' )
5864
5965 segmentLength = int (segment .length )
6066 minProjection = int (minProjection )
@@ -121,7 +127,10 @@ def addSpine(self, segmentId: SpineId, x: int, y: int, z: int) -> Union[SpineId,
121127 z (int): The z coordinate of the spine.
122128 """
123129 point = Point (x , y , z )
124- anchor = self .nearestAnchor (segmentId , point )
130+
131+ logger .error (f'1 FutureWarning: The `drop` keyword ...' )
132+ anchor = self .nearestAnchor (segmentId , point , findBrightest = True )
133+
125134 spineId = self .newUnassignedSpineId ()
126135
127136 self .updateSpine (spineId , Spine .withDefaults (
@@ -134,6 +143,7 @@ def addSpine(self, segmentId: SpineId, x: int, y: int, z: int) -> Union[SpineId,
134143 yBackgroundOffset = 0.0 ,
135144 ))
136145
146+ logger .error (f'4 FutureWarning: The `drop` keyword ...' )
137147 self .snapBackgroundOffset (spineId )
138148
139149 return spineId
@@ -169,7 +179,9 @@ def moveSpine(self, spineId: SpineId, x: int, y: int, z: int, state: DragState =
169179
170180 return True
171181
172- def moveAnchor (self , spineId : SpineId , x : int , y : int , z : int , state : DragState = DragState .MANUAL ) -> bool :
182+ def moveAnchor (self , spineId : SpineId ,
183+ x : int , y : int , z : int ,
184+ state : DragState = DragState .MANUAL ) -> bool :
173185 """
174186 Moves the anchor point of a spine to the given x and y coordinates.
175187
@@ -183,6 +195,9 @@ def moveAnchor(self, spineId: SpineId, x: int, y: int, z: int, state: DragState
183195 bool: True if the anchor point was successfully translated, False otherwise.
184196 """
185197 segmentId = self .points [spineId , "segmentID" ]
198+
199+ # abb
200+ # when moving, do not find brightest
186201 anchor = self .nearestAnchor (segmentId , Point (x , y , z ))
187202
188203 logger .info (f'segmentId:{ segmentId } anchor:{ anchor } ' )
@@ -310,9 +325,9 @@ def newSegment(self) -> Union[SegmentId, None]:
310325
311326 Returns:
312327 int: The ID of the new segment.
313- """
328+ """
314329 segmentId = self .newUnassignedSegmentId ()
315-
330+
316331 self .updateSegment (segmentId , Segment .withDefaults (
317332 segment = LineString ([]),
318333 roughTracing = LineString ([])
@@ -346,8 +361,7 @@ def injectSegmentPoint(self, segmentId: SegmentId, x: int, y: int, z: int):
346361 return idx
347362
348363 def appendSegmentPoint (self , segmentId : SegmentId , x : int , y : int , z : int , speculate : bool = False ) -> LineString :
349- """
350- Adds a point to a segment.
364+ """Adds a point to a segment.
351365
352366 Args:
353367 segmentId (str): The ID of the segment.
0 commit comments