FatemehT commited on
Commit
aabc413
·
1 Parent(s): c224f9b

link artery profile hover to contour highlight

Browse files
Files changed (1) hide show
  1. angioPySegmentation.py +53 -1
angioPySegmentation.py CHANGED
@@ -613,7 +613,17 @@ else:
613
  st.caption(calibration_message)
614
 
615
 
616
- selected_points = plotly_events(fig)
 
 
 
 
 
 
 
 
 
 
617
 
618
 
619
 
@@ -631,6 +641,23 @@ else:
631
  angioPyFunctions.colourTableList[selectedArtery][0],
632
  255]
633
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
634
  fig2 = px.imshow(selectedFrameRGBA)
635
 
636
 
@@ -646,4 +673,29 @@ else:
646
 
647
  fig2.add_trace(go.Scatter(x=splinePointsX[clippingLength:-clippingLength], y=splinePointsY[clippingLength:-clippingLength], line=dict(width=1)))
648
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
649
  st.plotly_chart(fig2, use_container_width=True)
 
613
  st.caption(calibration_message)
614
 
615
 
616
+ selected_points = plotly_events(
617
+ fig,
618
+ hover_event=True,
619
+ click_event=True,
620
+ )
621
+
622
+ if selected_points:
623
+ # Persist the latest hover/click event so the highlight remains visible
624
+ st.session_state["artery_profile_hover"] = selected_points[0]
625
+
626
+ hover_event_data = st.session_state.get("artery_profile_hover")
627
 
628
 
629
 
 
641
  angioPyFunctions.colourTableList[selectedArtery][0],
642
  255]
643
 
644
+ highlight_center = None
645
+ highlight_radius = None
646
+
647
+ if hover_event_data and "pointNumber" in hover_event_data:
648
+ hover_index = hover_event_data.get("pointNumber")
649
+ if isinstance(hover_index, (int, numpy.integer)) and 0 <= hover_index < len(vesselThicknesses):
650
+ spline_index = clippingLength + hover_index
651
+ highlight_center = (
652
+ float(splinePointsX[spline_index]),
653
+ float(splinePointsY[spline_index]),
654
+ )
655
+ highlight_radius = float(vesselThicknesses[hover_index] / 2.0)
656
+ else:
657
+ # Clear stale hover data if it no longer matches the current profile length
658
+ st.session_state.pop("artery_profile_hover", None)
659
+ hover_event_data = None
660
+
661
  fig2 = px.imshow(selectedFrameRGBA)
662
 
663
 
 
673
 
674
  fig2.add_trace(go.Scatter(x=splinePointsX[clippingLength:-clippingLength], y=splinePointsY[clippingLength:-clippingLength], line=dict(width=1)))
675
 
676
+ if highlight_center:
677
+ fig2.add_trace(
678
+ go.Scatter(
679
+ x=[highlight_center[0]],
680
+ y=[highlight_center[1]],
681
+ mode="markers",
682
+ marker=dict(size=12, color="yellow", symbol="circle"),
683
+ name="Selected location",
684
+ showlegend=False,
685
+ hoverinfo="skip",
686
+ )
687
+ )
688
+
689
+ if highlight_radius and highlight_radius > 0:
690
+ fig2.add_shape(
691
+ type="circle",
692
+ xref="x",
693
+ yref="y",
694
+ x0=highlight_center[0] - highlight_radius,
695
+ x1=highlight_center[0] + highlight_radius,
696
+ y0=highlight_center[1] - highlight_radius,
697
+ y1=highlight_center[1] + highlight_radius,
698
+ line=dict(color="yellow", width=2),
699
+ )
700
+
701
  st.plotly_chart(fig2, use_container_width=True)