Issues with CurrentPoint in R2021b

14 Ansichten (letzte 30 Tage)
Matt Butts
Matt Butts am 15 Dez. 2021
Kommentiert: Stephane Lagace am 12 Jul. 2023
I am trying to track some user clicks within an axes that lives within a uifigure.
I was originally using CurrentPoint from the axes object, but I started to notice that in certain scenarios, the coordinates of CurrentPoint did not seem to be correct for where the mouse event happened. I did as much investigating as I could and found a possible solution in looking at the event IntersectionPoint property.
I can effectively use the IntersectionPoint property of the event for mouse down and up events and I get coordiantes that very closely match where I was trying to click.
I need something like IntersectionPoint that can be used withn mouse motion callbacks because CurrentPoint is off by a significant amount.
Here is what I have in all of my callbacks:
cp = get(obj.Axes,'CurrentPoint');
ip = evt.IntersectionPoint;
fprintf('Current Point: (%g,%g)\nIntersection Point: (%g,%g)\n\n',cp(1,1),cp(1,2),ip(1,1),ip(1,2));
Then when I execute clicks, attempting to click near (11,1200) on the axes, I get the follwing:
Current Point: (10.9365,1376.74)
Intersection Point: (10.9782,1196.9)
  8 Kommentare
Bruno Luong
Bruno Luong am 16 Dez. 2021
What if you call drawnow on top of your callback function? Also make sure the axes handle is the one you see on the screen, and not some hidden axes.
Matt Butts
Matt Butts am 16 Dez. 2021
I tried sprinkling drawnows everywhere, including at the beginning of the callback and there were no differences.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Benjamin Kraus
Benjamin Kraus am 16 Dez. 2021
We've seen issues in the past with CurrentPoint being slightly off, and we are investigating them. Can you provide a little more information about your particular setup and I'll add it to our internal report about this issue? Specifically:
  1. You said "CurrentPoint is off by a significant amount" but your reproduction steps show off by ~1 pixel. Have you experienced errors that are larger than 1 pixel before?
  2. In the code you posted you have an axes directly in a uifigure. Are you using anything else in the figure, like tabs, panels, uigridlayout, etc.? Is the axes always directly in the uifigure, or is it in another container inside the uifigure?
  3. Any reproduction code you have, with as much detail as you can include, will be helpful.
  4. Are you using the "Scrollable" feature of the uifigures?
  5. What platform are you using? Windows? Mac? Linux?
  6. What is the output from rendererinfo run on your axes?
  7. What is your screen resolution and pixel density?
  7 Kommentare
Bruno Luong
Bruno Luong am 17 Dez. 2021
Bearbeitet: Bruno Luong am 17 Dez. 2021
FWIW, I test to plot both coordinates returned by CurrentPoint and IntersectionPoint on the same axes and in all the cases CurrentPoint can correctly follow the mouse and IntersectionPoint cannnot. That is fine with me as I use CurrentPoint currently. I'm in the opposite situation than you Matt.
Here is the function with plot. In my case the difference is 3 pixels for uifigure and 0.7 pixel for figure. CurrentPoint returns correct values as stated ealier.
function checkcperror(uiflag)
% uiflag: true to check uifigure; false old figure
if nargin < 1
uiflag = true;
end
close all
if uiflag
name = 'uifigure';
fig = uifigure('Name', name);
ax = uiaxes('Parent',fig);
else
name = 'figure';
fig = figure('Name', name);
ax = axes('Parent',fig);
end
fprintf('*** Check for %s ***\n', name)
h = plot(ax,nan(3,2),nan(3,2));
legend(h, 'IntersectionPoint', 'CurrentPoint');
axis(ax,[0 1 0 1]);
set(ax, 'Units','normalize', 'innerposition',[0 0 1 1]);
set(ax,'ButtonDownFcn',@(ax,event) chekerrorcb(ax,event,h));
text(ax,0.5,0.5,sprintf('%s click on the axes', name), ...
'HorizontalAlignment','center');
end
function chekerrorcb(ax, event, h)
drawnow
ip = event.IntersectionPoint(1,1:2);
cp = ax.CurrentPoint(1,1:2);
d = ip-cp;
ax.Units = 'pixel';
pos = get(ax,'innerposition');
dx = pos(3);
dy = pos(4);
dpxl = d.*[dx dy];
fprintf('error = %g pixel\n',norm(dpxl));
set(h(1),'XData',[get(h(1),'XData') ip(1)]);
set(h(1),'YData',[get(h(1),'YData') ip(2)]);
set(h(2),'XData',[get(h(2),'XData') cp(1)]);
set(h(2),'YData',[get(h(2),'YData') cp(2)]);
set(ax, 'Units','normalize', 'innerposition', [0 0 1 1]);
axis(ax,[0 1 0 1]);
drawnow
end
Stephane Lagace
Stephane Lagace am 12 Jul. 2023
Hello I have the same problem only when the uiaxes is in a couple nested gridlayouts

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by