1

I am working on a program that can display an image on a SceneCanvas and also allow users to click on an image to get an intensity of the point. My question is if there exist a way to get the coordinate X, Y of a point of an image in SceneCanvas. The canvas camera I am using is PanZoomCamera.

Thank you

Loc Tran
  • 11
  • 1
  • I'm not sure if we have any examples of it, but you can use mouse events to accept the click event, get the canvas position of that event, and use the image visual's `.transforms.get_transform().map(x, y)` to get the pixel location of that mouse event. I don't remember offhand what parameters need to be passed to `get_transform` for this to work properly. It could also be `imap` (for inverse) instead of `map`. If you can't figure it out, update your question with a simple example of what you have so far and I'll try to provide a full solution later. – djhoese Dec 02 '21 at 15:25

1 Answers1

1

You can attach an event handler to one or more mouse events like this:

def my_handler(event):
    # some stuff

canvas.events.mouse_release.connect(my_handler)

There are other ways to connect a function like this, but we'll stick with this way. Inside this function you'll want to convert your mouse click position in canvas space to visual space:

def my_handler(event):
    if event.button == 1:
        # left click
        transform = your_image_visual.transforms.get_transform(map_to="canvas")
        img_x, img_y = transform.imap(event.pos)[:2]
        # optionally do the below to tell other handlers not to look at this event:
        event.handled = True
Dharman
  • 30,962
  • 25
  • 85
  • 135
djhoese
  • 3,567
  • 1
  • 27
  • 45