Skip to content

Commit

Permalink
fixup! Rework point highlighting to consider src and trans
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentebolea committed Mar 12, 2024
1 parent 1d000cf commit bd9ea08
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
21 changes: 11 additions & 10 deletions nrtk_explorer/app/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

import asyncio
import json
import math
import os
import sys

from trame.widgets import quasar, html
from trame.ui.quasar import QLayout
Expand Down Expand Up @@ -186,15 +184,18 @@ def on_hover(self, point):
if self._on_hover_fn:
self._on_hover_fn(image_id)

def on_image_hovered(self, point):
natural_point = abs(point)
sign = math.copysign(1, point)

if natural_point in self.state.images_ids:
self.state.highlighted_point = sign * self.state.images_ids.index(natural_point)
def on_image_hovered(self, id_, is_transformation):
# If the point is in the list of selected points, we set it as the highlighted point
if id_ in self.state.images_ids:
index = self.state.images_ids.index(id_)
if is_transformation:
index_selected = self.state.user_selected_points_indices.index(index)
self.state.highlighted_point = len(self.state.points_sources) + index_selected
else:
self.state.highlighted_point = index
else:
# If the point is not in the list of selected points, we set it to the maximum value
self.state.highlighted_point = sys.maxsize
# If the point is not in the list of selected points, we set it to a negative point
self.state.highlighted_point = -1

def visualization_widget(self):
ScatterPlot(
Expand Down
9 changes: 5 additions & 4 deletions nrtk_explorer/app/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,12 @@ def on_image_hovered(self, index):
def set_on_hover(self, fn):
self._on_hover_fn = fn

def on_hover(self, point):
natural_point = abs(point)
self.on_image_hovered(natural_point)
def on_hover(self, hover_event):
id_ = int(hover_event["id"])
is_transformation = bool(hover_event["isTransformation"])
self.on_image_hovered(id_)
if self._on_hover_fn:
self._on_hover_fn(point)
self._on_hover_fn(id_, is_transformation)

def settings_widget(self):
with html.Div(trame_server=self.server):
Expand Down
13 changes: 9 additions & 4 deletions vue-components/src/components/ImageDetection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ interface Props {
isTransformation: boolean
}
interface HoverEvent {
id: number
isTransformation: boolean
}
type Events = {
hover: [point: number | null]
hover: [HoverEvent]
}
const emit = defineEmits<Events>()
Expand Down Expand Up @@ -172,9 +177,9 @@ function displayToPixel(x: number, y: number, canvas: HTMLCanvasElement): [numbe
function mouseEnter() {
borderSize.value = '2'
if (props.isTransformation) {
emit('hover', -Number(props.identifier))
emit('hover', { id: Number(props.identifier), isTransformation: true })
} else {
emit('hover', Number(props.identifier))
emit('hover', { id: Number(props.identifier), isTransformation: false })
}
}
Expand Down Expand Up @@ -240,7 +245,7 @@ function mouseMove(e: MouseEvent) {
function mouseLeave() {
showLabelContainer.value = false
borderSize.value = '0'
emit('hover', Number.MAX_SAFE_INTEGER)
emit('hover', { id: -1, isTransformation: false })
}
const borderSize = ref('0')
Expand Down
16 changes: 5 additions & 11 deletions vue-components/src/components/ScatterPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,17 @@ watch(
drawLines()
}
)
watch(
() => props.highlightedPoint,
(newValue) => {
if (scatterPlot) {
if (newValue) {
const transformationIdx = props.selectedPoints.indexOf(Math.abs(newValue))
// Negative values are used to indicate that the point is a transformed point
if (transformationIdx != -1 && newValue < 0) {
currenthighlightedPoint = props.points.length + transformationIdx
scatterPlot.setHoverPointIndex(props.points.length + transformationIdx)
} else {
currenthighlightedPoint = newValue
scatterPlot.setHoverPointIndex(Math.abs(newValue))
}
} else {
if (newValue == -1) {
currenthighlightedPoint = -1
scatterPlot.setHoverPointIndex(-1)
} else {
currenthighlightedPoint = newValue
scatterPlot.setHoverPointIndex(newValue)
}
}
}
Expand Down

0 comments on commit bd9ea08

Please sign in to comment.