View in #help on Slack
@Matthis: Hi!
What would be the best way to determine if a point is currently visible on the viewport?
I have some annotations that are displayed on a StackViewport, I zoomed and paned and I want to determine in my code if a point is still visible in the viewport or not.
Thanks for your help
@Bill_Wallace: viewport.worldToCanvas works if you have world coordinates
If you have image index coordinates (unlikely if you have an annotation), then you can use:
viewport.getDefaultImageData().indexToWorld
At some point I plan on updating getViewPresentation to take a set of points and provide an appropriate pan/zoom transform which will display said points. That will be implemented for whole slide imaging as well as volume and stack viewports.
@Matthis: For the viewport.worldToCanvas
to what should I then compare?
@Bill_Wallace: viewport.canvas.offsetWidth and offsetHeight - visible coordinates are 0…offsetWidth, 0…offsetHeight
That is inclusive/exclusive (eg you cannot see offsetWidth/height, but you can see 0,0)
@Matthis: Great!
I will try this. Thanks a lot!
But, how do you know the visible coordinates?
@Bill_Wallace: That is the canvas offsetWidth/offsetHeight
@Matthis: My bad, I misread it.
Thanks! It helped me a lot!