Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in passing Click Coordinates in OSD #2485

Open
abhinav2712 opened this issue Feb 28, 2024 · 1 comment
Open

Issue in passing Click Coordinates in OSD #2485

abhinav2712 opened this issue Feb 28, 2024 · 1 comment
Labels

Comments

@abhinav2712
Copy link

I am building one functionality where there are two things, one normal image and one OSD viewer, i need to pass click coordinates whenever image or OSD is clicked, here is this function which gets this done:

const handleMouseClick = ( viewerRef: React.RefObject<OpenSeadragon.Viewer>,
    e: any,  click_target: string = ""
  ) => {  let el = e.target;
    console.log(viewerRef.current);
    if (el) { let x, y;
      // Check if the click was on the OpenSeadragon viewer
      if (click_target === "osd" && viewerRef.current) {
        console.log("click on osd");
        // Get the click coordinates relative to the viewer
        const rect = viewerRef.current.element.getBoundingClientRect();
        x = e.clientX - rect.left;    y = e.clientY - rect.top;
        // Convert the click coordinates from viewport coordinates to image coordinates
        const viewportPoint = new OpenSeadragon.Point(x, y);
        const imagePoint =
          viewerRef.current.viewport.viewportToImageCoordinates(viewportPoint);
        x = imagePoint.x;
        y = imagePoint.y;
        // Adjust for zoom level and pan
        const zoom = viewerRef.current.viewport.getZoom(true);
        x /= zoom;
        y /= zoom;
        console.log("x: ", x, "y: ", y);
      } else {
        console.log("click on image");
        // Handle click on the image (as before)
        const rect = el.getBoundingClientRect();
        x = e.clientX - rect.left;
        y = e.clientY - rect.top;
        console.log("x: ", x, "y: ", y); }
      const imageScale = image ? image.width / el.offsetWidth : 1;
      x *= imageScale;
      y *= imageScale;
      console.log("x: ", x, "y: ", y);
      const click = getClick(x, y);
      if (click) setClicks([click]);
    }
  };

here the else statement which is when normal image is pressed, that works with my model as I am implementing SAM model and it needs click coordinates, however click on OSD which is in else statement gives weird output which means i am passing wrong coordiantes, can someone help me to fix it?

@abhinav2712 abhinav2712 changed the title Issue in Passing click coordinates in OSD Issue in passing Click Coordinates in OSD Feb 28, 2024
@iangilman
Copy link
Member

Looks like you got an answer on Discord: https://discord.com/channels/888321246431969280/888820630865186876/1212308519278215189

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants